コード例 #1
0
ファイル: sites.py プロジェクト: esnet/enos
    def __init__(self, intent):
        """
        Generic constructor. Translate the intent
        :param intent: SiteIntent
        :return:
        """
        ScopeOwner.__init__(self,name=intent.name)
        self.intent = intent
        self.site = self.intent.site
        self.siteRouter = self.intent.siteRouter
        self.borderRouter = self.intent.borderRouter
        graph = intent.graph
        self.macs = {}
        self.active = False
        self.activePorts = {} # [portname] = TestbedPort
        self.lock = threading.Lock()
        self.props['lanVlanIndex'] = {} # [siteVlan] = lanVlan
        self.props['siteVlanIndex'] = {} # [lanVlan] = siteVlan
        self.props['portsIndex'] = {} # [lanVlan] = list of TestbedPort that allows lanVlan to pass
        self.props['portIndex'] = {} # [str(mac)] = TestbedPort that links to the MAC
        self.props['scopeIndex'] = {} # [switch.name] = L2SwitchScope
        self.props['borderToSitePort'] = None # the port linking siteRouter and borderRouter
        self.props['borderToSDNPort'] = None # the port linking borderRouter and hwSwitch

        # cheating by awaring all the hosts to avoid any possible missed packet
        for host in self.site.props['hosts']:
            port = host.props['ports'][1].props['links'][0].props['portIndex'][self.siteRouter.name]
            self.props['portIndex'][str(host.props['mac'])] = port.props['enosPort']

        # Create scope for the site router
        siteScope = L2SwitchScope(name=intent.name,switch=self.siteRouter,owner=self)
        siteScope.props['intent'] = self.intent
        self.props['scopeIndex'][self.siteRouter.name] = siteScope
        for port in self.siteRouter.getPorts():
            self.activePorts[port.name] = port
            port.props['scope'] = siteScope
        siteScope.addEndpoint(self.siteRouter.props['toWanPort'])
        self.siteRouter.props['controller'].addScope(siteScope)
        # Create scope for the border router
        wanScope = L2SwitchScope(name="%s.wan" % intent.name,switch=self.borderRouter,owner=self)
        wanScope.props['intent'] = self.intent
        self.props['scopeIndex'][self.borderRouter.name] = wanScope
        borderToSitePort = self.borderRouter.props['sitePortIndex'][self.site.name].props['enosPort']
        self.activePorts[borderToSitePort.name] = borderToSitePort
        borderToSitePort.props['scope'] = wanScope
        wanScope.addEndpoint(borderToSitePort)
        borderToSDNPort = self.borderRouter.props['stitchedPortIndex'][borderToSitePort.name]
        self.activePorts[borderToSDNPort.name] = borderToSDNPort
        borderToSDNPort.props['scope'] = wanScope
        """
        The reason we comment out this line is:
        Since we'd like to support multiple sites, borderToSDNPort could be shared.
        Therefore, we can not occupy it alone.
        The scope should be added later while 'vpn addsite'.
        """
        # wanScope.addEndpoint(borderToSDNPort)
        self.props['borderToSitePort'] = borderToSitePort
        self.props['borderToSDNPort'] = borderToSDNPort
        self.borderRouter.props['controller'].addScope(wanScope)
コード例 #2
0
ファイル: wan.py プロジェクト: cygmris/enos
    def __init__(self, intent):
        """
        Create renderer object and initialize a bunch of stuff
        :param intent:
        """
        ScopeOwner.__init__(self, name=intent.name)
#        ProvisioningRenderer.__init__(self, name=intent.name)
        self.intent=intent
        self.wan=intent.wan
        # add hwSwitch (in addition to coreRouter only)
        self.nodes = []
        self.links = []
        for pop in self.wan.props['pops']:
            coreRouter = pop.props['coreRouter'].props['enosNode']
            self.nodes.append(coreRouter)
            hwSwitch = pop.props['hwSwitch'].props['enosNode']
            self.nodes.append(hwSwitch)
        for link in self.intent.links:
            self.links.append(link)
            (wanPort1, wanPort2) = link.props['endpoints']
            coreRouter1 = wanPort1.props['node']
            corePort1 = coreRouter1.props['stitchedPortIndex.WAN'][wanPort1.name]
            link1 = corePort1.props['links'][0].props['enosLink'] # assume only one link in the port
            self.links.append(link1)
            coreRouter2 = wanPort2.props['node']
            corePort2 = coreRouter2.props['stitchedPortIndex.WAN'][wanPort2.name]
            link2 = corePort2.props['links'][0].props['enosLink'] # assume only one link in the port
            self.links.append(link2)
        self.intentGraph=intent.graph
        self.graph=self.buildGraph()

        self.active=False
        self.activePorts={}
        self.props['scopeIndex'] = {} # [coreRouter.name] = L2SwitchScope

        # Create scopes for all of the places that we need to touch anything
        for pop in self.wan.props['pops']:
            if self.debug:
                print "WanRenderer: " + pop.name

            # Find the hardware router and core switch in both the topobuilder and base ENOS layers
            coreRouter = pop.props['coreRouter'].props['enosNode']
            # Create and add the scope
            scope=L2SwitchScope(name=intent.name+'-'+coreRouter.name, switch=coreRouter, owner=self,endpoints={})
            scope.props['intent'] = self.intent
            for port in coreRouter.getPorts():
                if port.props['type'] in ['CoreToHw.WAN', 'CoreToCore.WAN']:
                    for link in port.props['links']:
                        scope.addEndpoint(port, link.props['vlan'])
            if self.debug:
                print coreRouter.name + ' scope', scope
            if not coreRouter.props['controller'].addScope(scope):
                print "Cannot add " + str(scope)
            self.props['scopeIndex'][coreRouter.name] = scope
        return
コード例 #3
0
    def __init__(self, intent):
        """
        Generic constructor. Translate the intent
        :param intent: SiteIntent
        :return:
        """
        ScopeOwner.__init__(self, name=intent.name)
        self.intent = intent
        self.site = self.intent.site
        self.siteRouter = self.intent.siteRouter
        self.borderRouter = self.intent.borderRouter
        graph = intent.graph
        self.macs = {}
        self.active = False
        self.activePorts = {}  # [portname] = TestbedPort
        self.lock = threading.Lock()
        self.props['lanVlanIndex'] = {}  # [siteVlan] = lanVlan
        self.props['siteVlanIndex'] = {}  # [lanVlan] = siteVlan
        self.props['portsIndex'] = {
        }  # [lanVlan] = list of TestbedPort that allows lanVlan to pass
        self.props['portIndex'] = {
        }  # [str(mac)] = TestbedPort that links to the MAC
        self.props['scopeIndex'] = {}  # [switch.name] = L2SwitchScope
        self.props[
            'borderToSitePort'] = None  # the port linking siteRouter and borderRouter
        self.props[
            'borderToSDNPort'] = None  # the port linking borderRouter and hwSwitch

        # cheating by awaring all the hosts to avoid any possible missed packet
        for host in self.site.props['hosts']:
            port = host.props['ports'][1].props['links'][0].props['portIndex'][
                self.siteRouter.name]
            self.props['portIndex'][str(
                host.props['mac'])] = port.props['enosPort']

        # Create scope for the site router
        siteScope = L2SwitchScope(name=intent.name,
                                  switch=self.siteRouter,
                                  owner=self)
        siteScope.props['intent'] = self.intent
        self.props['scopeIndex'][self.siteRouter.name] = siteScope
        for port in self.siteRouter.getPorts():
            self.activePorts[port.name] = port
            port.props['scope'] = siteScope
        siteScope.addEndpoint(self.siteRouter.props['toWanPort'])
        self.siteRouter.props['controller'].addScope(siteScope)
        # Create scope for the border router
        wanScope = L2SwitchScope(name="%s.wan" % intent.name,
                                 switch=self.borderRouter,
                                 owner=self)
        wanScope.props['intent'] = self.intent
        self.props['scopeIndex'][self.borderRouter.name] = wanScope
        borderToSitePort = self.borderRouter.props['sitePortIndex'][
            self.site.name].props['enosPort']
        self.activePorts[borderToSitePort.name] = borderToSitePort
        borderToSitePort.props['scope'] = wanScope
        wanScope.addEndpoint(borderToSitePort)
        borderToSDNPort = self.borderRouter.props['stitchedPortIndex'][
            borderToSitePort.name]
        self.activePorts[borderToSDNPort.name] = borderToSDNPort
        borderToSDNPort.props['scope'] = wanScope
        """
        The reason we comment out this line is:
        Since we'd like to support multiple sites, borderToSDNPort could be shared.
        Therefore, we can not occupy it alone.
        The scope should be added later while 'vpn addsite'.
        """
        # wanScope.addEndpoint(borderToSDNPort)
        self.props['borderToSitePort'] = borderToSitePort
        self.props['borderToSDNPort'] = borderToSDNPort
        self.borderRouter.props['controller'].addScope(wanScope)