Example #1
0
    def switchFeature(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'switchFeature'
        domainId = jsonMsg[DOMAINID]

        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        # domain object
        dpid = jsonMsg[DPID]

        if not domainInstance.isSwitchIn(dpid):
            domainInstance.addSwitch(dpid)

        switchFeaturs = SwitchInfo(dpid)  #switch object
        features = jsonMsg[SWITCHFEATURE]
        name = features['name']
        switchFeaturs.setName(name)

        ports = switchFeaturs.getPorts()

        portsInfo = features['ports']
        for portNo in portsInfo:
            assert portNo in portsInfo
            portInfo = portsInfo[portNo]
            port = PortInfo(portNo)
            port.setFieldsfromDict(portInfo)

            if portNo not in ports:
                ports[portNo] = port

        domainInstance.addSwitchFeature(dpid, switchFeaturs)
Example #2
0
    def linkAdd(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'linkAdd'

        domainId = jsonMsg[DOMAINID]
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        srcSwitch = jsonMsg[SRC_SWITCH]
        dstSwitch = jsonMsg[DST_SWITCH]
        srcPort = jsonMsg[SRC_PORT]
        dstPort = jsonMsg[DST_PORT]
        virTopo = SC.virualTopo

        if type(dstSwitch) is str:
            dstSwitch = int(dstSwitch)
            virTopo.updateWeight([(srcSwitch, dstSwitch, {
                'weight': 1
            }), (dstSwitch, srcSwitch, {
                'weight': 1
            })])
            self.logger.info(
                "Virual topo link add:src %16x port_no %8d-> dst %16x %8d" %
                (srcSwitch, srcPort, dstSwitch, dstPort))
            print "first time test topo :", virTopo.edges()
        else:
            item = (srcSwitch, srcPort, dstSwitch, dstPort)
            if not domainInstance.isLinkPortIn(item):
                domainInstance.addLink(srcSwitch, srcPort, dstSwitch, dstPort)

            topo = SC.topo

            if (srcSwitch, dstSwitch) not in topo.edges():
                topo.addEdge(srcSwitch, srcPort, dstSwitch, dstPort)
                self.logger.info(
                    "Global topo link add:src %16x port_no %8d-> dst %16x %8d"
                    % (srcSwitch, srcPort, dstSwitch, dstPort))
Example #3
0
    def linkAdd(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'linkAdd'

        domainId = jsonMsg[DOMAINID]
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        srcSwitch = jsonMsg[SRC_SWITCH]
        dstSwitch = jsonMsg[DST_SWITCH]
        srcPort = jsonMsg[SRC_PORT]
        dstPort = jsonMsg[DST_PORT]

        item = (srcSwitch, srcPort, dstSwitch, dstPort)
        if not domainInstance.isLinkPortIn(item):
            domainInstance.addLink(srcSwitch, srcPort, dstSwitch, dstPort)

        topo = SC.topo
        #gqz
        virTopo = SC.virualTopo()
        if topo.nodeToDomainId[srcSwitch] != topo.nodeToDomainId[dstSwitch]:
            virTopo.updateWeight([srcSwitch, dstSwitch, {'weight': 1}])
            self.logger.info(
                "Virual topo link add:src %16x port_no %8d-> dst %16x %8d" %
                (srcSwitch, srcPort, dstSwitch, dstPort))
        #gqz
        if (srcSwitch, dstSwitch) not in topo.edges():
            topo.addEdge(srcSwitch, srcPort, dstSwitch, dstPort)
            self.logger.info(
                "Global topo link add:src %16x port_no %8d-> dst %16x %8d" %
                (srcSwitch, srcPort, dstSwitch, dstPort))
Example #4
0
    def switchEnter(self, jsonMsg, SC):

        assert jsonMsg[TYPE] == 'switchEnter'
        domainId = jsonMsg.get(DOMAINID)
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        node = jsonMsg[DPID]  #node is dpid
        domainInstance.addSwitch(node)
        #topo = SC.topo
        SC.topo.addNode(node, domainId)  #add nodes to topo!!!

        self.logger.info("Switch %016x enter in global topo" % node)
Example #5
0
    def keepAlive(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'keepAlive'

        domainId = jsonMsg[DOMAINID]
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        domainWsgiIp = jsonMsg[DOMAINWSGIIP]
        domainWsgiPort = jsonMsg[DOMAINWSGIPORT]
        lastEchoTime = time.time()

        domainInstance.setDomainFields(domainWsgiIp, domainWsgiPort,
                                       lastEchoTime)
Example #6
0
    def linkAdd(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'linkAdd'
        # print jsonMsg
        domainId = jsonMsg[DOMAINID]
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        srcSwitch = jsonMsg[SRC_SWITCH]
        dstSwitch = jsonMsg[DST_SWITCH]
        srcPort = jsonMsg[SRC_PORT]
        dstPort = jsonMsg[DST_PORT]
        virTopo = SC.virualTopo

        if type(dstSwitch) is str:
            #print 11111111111111111111111
            dstSwitch = int(dstSwitch)

            virTopo.updateWeight([(srcSwitch, dstSwitch, {
                'weight': 1
            }), (dstSwitch, srcSwitch, {
                'weight': 1
            })])
            # self.logger.info("Virual topo link add:src %16x port_no %8d-> dst %16x %8d" % (srcSwitch, srcPort,
            #                                                                                dstSwitch, dstPort))
            # print "first time test topo :",virTopo.edges()
        # else:
        item = (srcSwitch, srcPort, dstSwitch, dstPort)
        if not domainInstance.isLinkPortIn(item):
            domainInstance.addLink(srcSwitch, srcPort, dstSwitch, dstPort)

        topo = SC.topo
        #print 'topo.nodeToDomainId: ', topo.nodeToDomainId
        #topo.nodeToDomainId:
        #{513: 1, 514: 1, 515: 1, 516: 1, 517: 1, 518: 1, 769: 2, 770: 2, 774: 2, 771: 2, 772: 2, 773: 2}

        #     virTopo = SC.virualTopo
        #
        # if topo.nodeToDomainId[srcSwitch] != topo.nodeToDomainId[dstSwitch]:
        #         virTopo.updateWeight([(srcSwitch, dstSwitch, {'weight': 1})])
        #         self.logger.info("Virual topo link add:src %16x port_no %8d-> dst %16x %8d" % (srcSwitch, srcPort,
        #                                                                                    dstSwitch, dstPort))

        if (srcSwitch, dstSwitch) not in topo.edges():
            topo.addEdge(srcSwitch, srcPort, dstSwitch, dstPort)
            self.logger.info(
                "Global topo link add:src( %d, %2d)-> dst( %d, %2d)" %
                (srcSwitch, srcPort, dstSwitch, dstPort))
Example #7
0
    def linkAdd(self, jsonMsg, SC):
        assert jsonMsg[TYPE] == 'linkAdd'

        domainId = jsonMsg[DOMAINID]
        domainInstance = SC.domains.setdefault(domainId, DomainInfo(domainId))
        srcSwitch = jsonMsg[SRC_SWITCH]
        dstSwitch = jsonMsg[DST_SWITCH]
        srcPort = jsonMsg[SRC_PORT]
        dstPort = jsonMsg[DST_PORT]

        item = (srcSwitch, srcPort, dstSwitch, dstPort)
        if not domainInstance.isLinkPortIn(item):
            domainInstance.addLink(srcSwitch, srcPort, dstSwitch, dstPort)

        topo = SC.topo

        if (srcSwitch, dstSwitch) not in topo.edges():
            topo.addEdge(srcSwitch, srcPort, dstSwitch, dstPort)
            self.logger.info(
                "Global topo link add:src %16x port_no %8d-> dst %16x %8d" %
                (srcSwitch, srcPort, dstSwitch, dstPort))