示例#1
0
    def __init__(self, config, init=True):
        '''config is a dict'''
        LookingGlassLocalLogger.__init__(self)

        assert(issubclass(self.dataplaneInstanceClass, VPNInstanceDataplane))

        self.config = config

        self.local_address = None
        try:
            self.local_address = self.config["dataplane_local_address"]
            socket.inet_pton(socket.AF_INET, self.local_address)
            self.log.info("Will use %s as local_address", self.local_address)
        except KeyError:
            self.log.info("Will use BGP address as dataplane_local_address")
            self.local_address = None
        except socket.error:
            raise Exception("malformed local_address: '%s'" %
                            self.local_address)

        # skipped if instantiated with init=False, to be used for cleanup
        if init:
            self._initReal(config)

        # Flag to trigger cleanup all dataplane states on first call to
        # vifPlugged
        self.firstInit = True
示例#2
0
    def __init__(self, bgpManager, name, peerAddress):
        # call super
        Thread.__init__(self)
        self.setDaemon(True)
        self.name = "BGP-%s" % peerAddress
        Worker.__init__(self, bgpManager, self.name)

        self.bgpManager = bgpManager
        self.peerAddress = peerAddress

        # its up to subclasses to call setHoldTime again to set holdtime based
        # on value advertized by peer
        self._setHoldTime(DEFAULT_HOLDTIME)

        # used to stop receiveThread
        self._stopLoops = Event()
        # used to track that we've been told to stop:
        self.shouldStop = False

        self.sendKATimer = None
        self.KAReceptionTimer = None

        LookingGlassLocalLogger.__init__(
            self, self.peerAddress.replace(".", "-"))

        self.fsm = FSM(self)

        self.log.debug("Init %s", self.name)
        self.enqueue(Init)
示例#3
0
    def __init__(self, config, init=True):
        LookingGlassLocalLogger.__init__(self, __name__)

        self.log.info("Initializing %s", self.__class__.__name__)

        self.vxlanDestPort = config.get("vxlan_dst_port", None)

        DataplaneDriver.__init__(self, config, init)
示例#4
0
 def __init__(self, dataplaneDriver, instanceId, externalInstanceId,
              gatewayIP, mask, instanceLabel=None):
     LookingGlassLocalLogger.__init__(self, repr(instanceId))
     self.driver = dataplaneDriver
     self.config = dataplaneDriver.config
     self.instanceId = instanceId
     self.externalInstanceId = externalInstanceId
     self.gatewayIP = gatewayIP
     self.mask = mask
     self.instanceLabel = instanceLabel
示例#5
0
    def __init__(self, bgpManager, workerName, compareRoutes=compareNoECMP):
        Worker.__init__(self, bgpManager, workerName)
        LookingGlassLocalLogger.__init__(self)

        # dict: entry -> list of routes:
        self.trackedEntry2routes = dict()
        # dict: entry -> set of bestRoutes:
        self.trackedEntry2bestRoutes = dict()

        self._compareRoutes = compareRoutes
示例#6
0
    def __init__(self, bgpManager, workerName, compareRoutes=compareNoECMP):
        Worker.__init__(self, bgpManager, workerName)
        LookingGlassLocalLogger.__init__(self)

        # dict: entry -> list of routes:
        self.trackedEntry2routes = dict()
        # dict: entry -> set of bestRoutes:
        self.trackedEntry2bestRoutes = dict()

        self._compareRoutes = compareRoutes
示例#7
0
    def __init__(self, config, init=True):
        LookingGlassLocalLogger.__init__(self, __name__)

        self.log.info("Initializing %s", self.__class__.__name__)

        try:
            self.vxlanDestPort = int(config.get("vxlan_dst_port", 0)) or None
        except ValueError:
            raise Exception("Could not parse specified vxlan_dst_port: %s" %
                            config["vxlan_dst_port"])

        DataplaneDriver.__init__(self, config, init)
示例#8
0
    def __init__(self, bgpManager, labelAllocator, dataplaneDriver,
                 externalInstanceId, instanceId, importRTs, exportRTs,
                 gatewayIP, mask, readvertise, **kwargs):

        self.instanceType = self.__class__.__name__
        self.instanceId = instanceId

        Thread.__init__(self)
        self.setDaemon(True)

        if dataplaneDriver.ecmpSupport:
            compareRoutes = compareECMP
        else:
            compareRoutes = compareNoECMP

        TrackerWorker.__init__(self, bgpManager,
                               "%s %d" % (self.instanceType, self.instanceId),
                               compareRoutes)

        LookingGlassLocalLogger.__init__(
            self, "%s-%d" % (self.instanceType, self.instanceId))
        self.lock = Lock()

        self.importRTs = importRTs
        self.exportRTs = exportRTs
        self.externalInstanceId = externalInstanceId
        self.gatewayIP = gatewayIP
        self.mask = mask

        self.afi = self.__class__.afi
        self.safi = self.__class__.safi
        assert (isinstance(self.afi, AFI))
        assert (isinstance(self.safi, SAFI))

        self.dataplaneDriver = dataplaneDriver
        self.labelAllocator = labelAllocator

        self.instanceLabel = self.labelAllocator.getNewLabel(
            "Incoming traffic for %s %d" %
            (self.instanceType, self.instanceId))

        self.localPortData = dict()

        # One local port -> List of endpoints (MAC and IP addresses tuple)
        self.localPort2Endpoints = dict()
        # One MAC address -> One local port
        self.macAddress2LocalPortData = dict()
        # One IP address ->  One MAC address
        self.ipAddress2MacAddress = dict()

        self.dataplane = self.dataplaneDriver.initializeDataplaneInstance(
            self.instanceId, self.externalInstanceId, self.gatewayIP,
            self.mask, self.instanceLabel, **kwargs)

        for rt in self.importRTs:
            self._subscribe(self.afi, self.safi, rt)

        if readvertise:
            self.readvertise = True
            try:
                self.readvertiseToRTs = readvertise['to_rt']
            except KeyError:
                raise APIException("'readvertise' specified with no 'to_rt'")
            self.readvertiseFromRTs = readvertise.get('from_rt', [])
            self.log.debug("readvertise enabled, from RT:%s, to %s",
                           self.readvertiseFromRTs, self.readvertiseToRTs)
            for rt in self.readvertiseFromRTs:
                self._subscribe(self.afi, self.safi, rt)
        else:
            self.log.debug("readvertise not enabled")
            self.readvertise = False
    def __init__(self, bgpManager, labelAllocator, vnid, dataplaneDriver,
                 externalInstanceId, instanceId, importRTs, exportRTs,
                 gatewayIP, mask, readvertise, **kwargs):

        self.instanceType = self.__class__.__name__
        self.instanceId = instanceId

        Thread.__init__(self)
        self.setDaemon(True)

        if dataplaneDriver.ecmpSupport:
            compareRoutes = compareECMP
        else:
            compareRoutes = compareNoECMP

        TrackerWorker.__init__(self, bgpManager, "%s %d" %
                               (self.instanceType, self.instanceId),
                               compareRoutes)

        LookingGlassLocalLogger.__init__(self,
                                         "%s-%d" % (self.instanceType,
                                                    self.instanceId))
        self.lock = Lock()

        self.importRTs = importRTs
        self.exportRTs = exportRTs
        self.externalInstanceId = externalInstanceId
        self.gatewayIP = gatewayIP
        self.mask = mask
 	self.vnid = vnid	

        self.afi = self.__class__.afi
        self.safi = self.__class__.safi
        assert(isinstance(self.afi, AFI))
        assert(isinstance(self.safi, SAFI))

        self.dataplaneDriver = dataplaneDriver
	if vnid is None:
	        self.labelAllocator = labelAllocator
        	self.instanceLabel = self.labelAllocator.getNewLabel(
	            "Incoming traffic for %s %d" % (self.instanceType,
        	                                    self.instanceId))
	else:
		self.instanceLabel = int(vnid)

        self.localPortData = dict()

        # One local port -> List of endpoints (MAC and IP addresses tuple)
        self.localPort2Endpoints = dict()
        # One MAC address -> One local port
        self.macAddress2LocalPortData = dict()
        # One IP address ->  One MAC address
        self.ipAddress2MacAddress = dict()

        self.dataplane = self.dataplaneDriver.initializeDataplaneInstance(
            self.instanceId, self.externalInstanceId,
            self.gatewayIP, self.mask, self.instanceLabel, **kwargs)

        for rt in self.importRTs:
            self._subscribe(self.afi, self.safi, rt)

        if readvertise:
            self.readvertise = True
            try:
                self.readvertiseToRTs = readvertise['to_rt']
            except KeyError:
                raise APIException("'readvertise' specified with no 'to_rt'")
            self.readvertiseFromRTs = readvertise.get('from_rt', [])
            self.log.debug("readvertise enabled, from RT:%s, to %s",
                           self.readvertiseFromRTs, self.readvertiseToRTs)
            for rt in self.readvertiseFromRTs:
                self._subscribe(self.afi, self.safi, rt)
        else:
            self.log.debug("readvertise not enabled")
            self.readvertise = False
示例#10
0
    def __init__(self, config, init=True):
        LookingGlassLocalLogger.__init__(self)
        self.log.info("Initializing MPLSOVSVRFDataplane")

        try:
            (o, _) = self._runCommand("ovs-ofctl -V | head -1 |"
                                      " awk '{print $4}'")
            self.ovsRelease = o[0]
            self.log.info("OVS release: %s", self.ovsRelease)
        except:
            self.log.warning("Could not determine OVS release")
            self.ovsRelease = None

        self.config = config

        self.mpls_interface = config.get("mpls_interface", None)

        try:
            self.useGRE = getBoolean(config["mpls_over_gre"])
        except KeyError:
            self.useGRE = not (self.mpls_interface
                               and self.mpls_interface != "*gre*")

        if not self.mpls_interface:
            if not self.useGRE:
                raise Exception("mpls_over_gre force-disabled, but no "
                                "mpls_interface specified")
            else:
                self.useGRE = True
                self.log.info("Defaulting to use of MPLS-over-GRE (no "
                              "mpls_interface specified)")
        elif self.mpls_interface == "*gre*":
            if not self.useGRE:
                raise Exception("mpls_over_gre force-disabled, but "
                                "mpls_interface set to '*gre', cannot "
                                "use bare MPLS")
            else:
                self.log.info("mpls_interface is '*gre*', will thus use "
                              "MPLS-over-GRE")
                self.useGRE = True
                self.mpls_interface = None
        else:
            if self.useGRE:
                self.log.warning("mpls_over_gre set to True, "
                                 "ignoring mpls_interface parameter")
                self.mpls_interface = None
            else:
                self.log.info("Will use bare MPLS on interface %s",
                              self.mpls_interface)

        self.bridge = DEFAULT_OVS_BRIDGE
        try:
            self.bridge = config["ovs_bridge"]
        except KeyError:
            self.log.warning("No bridge configured, will use default: %s",
                             DEFAULT_OVS_BRIDGE)

        self.ovs_table_incoming = DEFAULT_OVS_TABLE
        try:
            self.ovs_table_incoming = int(config["ovs_table_incoming"])
        except KeyError:
            self.log.debug(
                "No ovs_table_incoming configured, "
                "will use default table %s", DEFAULT_OVS_TABLE)

        self.ovs_table_vrfs = DEFAULT_OVS_TABLE
        try:
            self.ovs_table_vrfs = int(config["ovs_table_vrfs"])
        except KeyError:
            self.log.debug(
                "No ovs_table_vrfs configured, will use default"
                " table %s", DEFAULT_OVS_TABLE)

        self.vxlanEncap = getBoolean(config.get("vxlan_encap", "False"))

        self.proxy_arp = getBoolean(config.get("proxy_arp", "True"))

        # unless useGRE is enabled, check that fping is installed
        if not self.useGRE:
            self._runCommand("fping -v", raiseExceptionOnError=True)

        if (not self.vxlanEncap
                and StrictVersion(self.ovsRelease) < StrictVersion("2.4.0")):
            self.log.warning(
                "%s requires at least OVS 2.4.0 (you are running %s)",
                self.__class__.__name__, self.ovsRelease)

        DataplaneDriver.__init__(self, config, init)
示例#11
0
    def __init__(self, config, init=True):
        LookingGlassLocalLogger.__init__(self)
        self.log.info("Initializing MPLSOVSVRFDataplane")

        try:
            (o, _) = self._runCommand("ovs-ofctl -V | head -1 |"
                                      " awk '{print $4}'")
            self.ovsRelease = o[0]
            self.log.info("OVS kernel module %s", self.ovsRelease)
        except:
            self.log.warning("Could not determine OVS release")
            self.ovsRelease = None

        self.config = config

        self.mpls_interface = config.get("mpls_interface", None)

        try:
            self.useGRE = getBoolean(config["mpls_over_gre"])
        except KeyError:
            self.useGRE = not (self.mpls_interface and
                               self.mpls_interface != "*gre*")

        if not self.mpls_interface:
            if not self.useGRE:
                raise Exception("mpls_over_gre force-disabled, but no "
                                "mpls_interface specified")
            else:
                self.useGRE = True
                self.log.info("Defaulting to use of MPLS-over-GRE (no "
                              "mpls_interface specified)")
        elif self.mpls_interface == "*gre*":
            if not self.useGRE:
                raise Exception("mpls_over_gre force-disabled, but "
                                "mpls_interface set to '*gre', cannot "
                                "use bare MPLS")
            else:
                self.log.info("mpls_interface is '*gre*', will thus use "
                              "MPLS-over-GRE")
                self.useGRE = True
                self.mpls_interface = None
        else:
            if self.useGRE:
                self.log.warning("mpls_over_gre set to True, "
                                 "ignoring mpls_interface parameter")
                self.mpls_interface = None
            else:
                self.log.info("Will use bare MPLS on interface %s",
                              self.mpls_interface)

        self.bridge = DEFAULT_OVS_BRIDGE
        try:
            self.bridge = config["ovs_bridge"]
        except KeyError:
            self.log.warning("No bridge configured, will use default: %s",
                             DEFAULT_OVS_BRIDGE)

        self.ovs_table_incoming = DEFAULT_OVS_TABLE
        try:
            self.ovs_table_incoming = int(config["ovs_table_incoming"])
        except KeyError:
            self.log.debug("No ovs_table_incoming configured, "
                           "will use default table %s", DEFAULT_OVS_TABLE)

        self.ovs_table_vrfs = DEFAULT_OVS_TABLE
        try:
            self.ovs_table_vrfs = int(config["ovs_table_vrfs"])
        except KeyError:
            self.log.debug("No ovs_table_vrfs configured, will use default"
                           " table %s", DEFAULT_OVS_TABLE)

        self.vxlanEncap = getBoolean(config.get("vxlan_encap", "False"))

        # check that fping is installed
        if not self.useGRE:
            self._runCommand("fping -v", raiseExceptionOnError=True)

        if (not self.vxlanEncap and
                StrictVersion(self.ovsRelease) < StrictVersion("2.4.0")):
            self.log.warning(
                "%s requires at least OVS 2.4.0 (you are running %s)",
                self.__class__.__name__, self.ovsRelease)

        DataplaneDriver.__init__(self, config, init)
 def __init__(self, config, init=True):
     LookingGlassLocalLogger.__init__(self)
     DataplaneDriver.__init__(self, config, init)
 def __init__(self, config, init=True):
     LookingGlassLocalLogger.__init__(self)
     DataplaneDriver.__init__(self, config, init)