コード例 #1
0
    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = '10.108.90.200'
        self.wsgiPort = 8080
        ##################################################
        self.topo = TopoInfo()
        self.trafficBalance = True
        ######################################
        self.virualTopo = TopoInfo()

        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table
        #self.domaintype = {'L3':[1],'L2':[2]}
        wsgi = kwargs['wsgi']

        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()

        #self.keepalivethread = hub.spawn(self._keep_alive())

        wsgi.register(SuperWsgiController, data)
コード例 #2
0
ファイル: super_controller.py プロジェクト: hyqdvd/ryuCode
    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = '10.108.90.200'
        self.wsgiPort = 8080
        ##################################################
        self.topo = TopoInfo()
        self.trafficBalance = True
        ######################################
        self.virualTopo = TopoInfo()

        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table
        #self.domaintype = {'L3':[1],'L2':[2]}
        wsgi = kwargs['wsgi']

        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()

        #self.keepalivethread = hub.spawn(self._keep_alive())

        wsgi.register(SuperWsgiController, data)
コード例 #3
0
ファイル: super_controller.py プロジェクト: hyqdvd/ryuCode
    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = None
        self.wsgiPort = None
        ##################################################
        self.topo = TopoInfo()
        # gqz
        self.virualTopo = TopoInfo()
        # gqz
        self.trafficBalance = True
        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table

        wsgi = kwargs["wsgi"]
        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()
        wsgi.register(SuperWsgiController, data)
コード例 #4
0
    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = None
        self.wsgiPort = None
        ##################################################
        self.topo = TopoInfo()
        self.trafficBalance = True
        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table

        wsgi = kwargs['wsgi']
        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()
        wsgi.register(SuperWsgiController, data)
コード例 #5
0
class SuperController(app_manager.RyuApp):

    _CONTEXTS = {'wsgi': WSGIApplication}

    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = None
        self.wsgiPort = None
        ##################################################
        self.topo = TopoInfo()
        self.trafficBalance = True
        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table

        wsgi = kwargs['wsgi']
        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()
        wsgi.register(SuperWsgiController, data)
        # self.newtaskThreadFlag = self.CONF.newtask_thread_flag
        # if self.newtaskThreadFlag:
        # self.newtaskThread = hub.spawn(self.newTask)

    def startBackupHandler(self, taskId):
        taskInstance = getTask(taskId)
        backupPathDomains = taskInstance.getBackupCrossDomains()
        if not backupPathDomains:
            self.logger.info('NO Backup Path for this Task')
            return

        mainPathDomains = taskInstance.getMainCrossDomains()

        handlerDomains = self._add_diff_from_list(backupPathDomains,
                                                  mainPathDomains)

        for domainId in handlerDomains:
            self.sendStartBackupPathMsg(domainId, taskId)

        taskInstance.changeBackupToMain()

    def _add_diff_from_list(self, list1, list2):
        list_ = []
        for i in list1:
            list_.append(i)

        for j in list2:
            if j not in list_:
                list_.append(j)

        return list_

    def sendStartBackupPathMsg(self, domainId, taskId):
        send_message = self._make_start_backup_msg(domainId, taskId)
        command = self._to_commad(send_message)
        print "start backup: ", command
        self.send_no_return_command(command)

    def _make_start_backup_msg(self, domainId, taskId):

        to_send = {}
        to_send[TYPE] = 'startBackup'
        to_send[DOMAINID] = domainId
        to_send[TASK_ID] = taskId

        send_message = json.dumps(to_send)
        return send_message

    def setNewBackupPath(self, taskId):
        taskInstance = getTask(taskId)
        completePathMain = taskInstance.getMainCompletePath()
        assert len(
            completePathMain
        ) > 1  # to make sure we set a backupPath for a task having a mainPath
        mainEdges = taskInstance.getMainEdges()
        newTopo = self.topo.getNewTopoExceptSE(mainEdges)

        srcSwitch = taskInstance.getSrcSwtich()
        dstSwtich = taskInstance.getDstSwitch()

        if self.trafficBalance:
            newCompletePathBackup = newTopo.getWeightPath(srcSwitch, dstSwtich)
        else:
            newCompletePathBackup = newTopo.getShortestPath(
                srcSwitch, dstSwtich)

        if not newCompletePathBackup:
            self.logger.warning(
                "can not assign a new backupPath for this task ")
            return

        taskInstance.setBackupCompletePath(newCompletePathBackup)
        nodeToDomain = self.topo.nodeToDomainId
        newBackupSectorialPath = taskInstance.getBackupSectorialPath(
            nodeToDomain)

        newAllBackupPathMpls = self.LabelsPool.getLabels(
            len(newCompletePathBackup))
        noUseLabels = taskInstance.assignBackuPathMpls(newAllBackupPathMpls)
        self.LabelsPool.recycleLabels(noUseLabels)

        for i in newBackupSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(i, type='backup')
            command = self._to_commad(send_message)
            print 'newbackup: ', command
            self.send_no_return_command(command)
            taskInstance.addBackupUnconfirmDomain(i)

    def _keep_alive(self):
        while True:
            for i in self.domains:
                self.sendKeepAlive(i)
                self.logger.info("send keepalive to domain %d" % i)
            hub.sleep(10)

    def sendKeepAlive(self, i):
        send_message = self._make_keep_alive(i)
        command = self._to_commad(send_message)
        self.send_no_return_command(command)

    def _make_keep_alive(self, i):
        to_send = {}
        to_send[TYPE] = 'keepAlive'
        to_send[DOMAINID] = i

        send_message = json.dumps(to_send)
        return send_message

    def send_no_return_command(self, command):
        try:
            os.popen2(command)
        except:
            self.logger.debug('command exceute fail.Fail Command: %s' %
                              command)
            return

    def _to_commad(self, send_message, returnType=False):

        message = eval(send_message)
        domainId = message.get(DOMAINID)
        domainInstance = self.domains.get(domainId)
        domainWsgiIp = domainInstance.getWsgiIp()
        domainWsgiPort = domainInstance.getWsgiPort()

        command = 'curl -X '
        if returnType:
            command += 'GET -d \''
        else:
            command += 'PUT -d \''
        command += send_message
        command += '\' http://'
        command += domainWsgiIp
        command += ':'
        command += str(domainWsgiPort)
        if not returnType:
            command += DOMAINURLNORETURN
        else:
            command += DOMAINURLRETURN

        command += ' 2> /dev/null'

        return command

    ###################################################################

    @set_ev_cls(bgpevent, MAIN_DISPATCHER)
    def handler_bgp_msg(self, ev):
        bgp_msg = ev.ev
        remote_as = bgp_msg.remote_as
        route_dist = bgp_msg.route_dist
        prefix = bgp_msg.prefix
        nexthop = bgp_msg.nexthop
        label = bgp_msg.label
        is_withdraw = bgp_msg.is_withdraw
        Table.prefix_to_nexthop = {prefix: nexthop}
コード例 #6
0
ファイル: super_controller.py プロジェクト: hyqdvd/ryuCode
class SuperController(app_manager.RyuApp):

    _CONTEXTS = {'wsgi': WSGIApplication}

    def __init__(self, *args, **kwargs):
        super(SuperController, self).__init__(*args, **kwargs)

        self.wsgiIp = None
        self.wsgiPort = None
        ##################################################
        self.topo = TopoInfo()
        self.trafficBalance = True
        ##################################################
        self.LabelsPool = MplsLabelsPool()
        self.LabelsPool.initPool()
        ##################################################
        self.domains = {}

        ###################################################
        self.table = Table

        wsgi = kwargs['wsgi']
        data = {}
        data[SUPERCONTROLLER] = self
        data[SUPERREPLYCONTROLLER] = SuperReplyController()
        wsgi.register(SuperWsgiController, data)
        # self.newtaskThreadFlag = self.CONF.newtask_thread_flag
        # if self.newtaskThreadFlag:
        # self.newtaskThread = hub.spawn(self.newTask)


    def startBackupHandler(self, taskId):
        taskInstance = getTask(taskId)
        backupPathDomains = taskInstance.getBackupCrossDomains()
        if not backupPathDomains:
            self.logger.info('NO Backup Path for this Task')
            return

        mainPathDomains = taskInstance.getMainCrossDomains()

        handlerDomains = self._add_diff_from_list(backupPathDomains, mainPathDomains)

        for domainId in handlerDomains:
            self.sendStartBackupPathMsg(domainId, taskId)

        taskInstance.changeBackupToMain()

    def _add_diff_from_list(self, list1, list2):
        list_ = []
        for i in list1:
            list_.append(i)

        for j in list2:
            if j not in list_:
                list_.append(j)

        return list_

    def sendStartBackupPathMsg(self, domainId, taskId):
        send_message = self._make_start_backup_msg(domainId, taskId)
        command = self._to_commad(send_message)
        print "start backup: ", command
        self.send_no_return_command(command)

    def _make_start_backup_msg(self, domainId, taskId):

        to_send = {}
        to_send[TYPE] = 'startBackup'
        to_send[DOMAINID] = domainId
        to_send[TASK_ID] = taskId

        send_message = json.dumps(to_send)
        return send_message

    def setNewBackupPath(self, taskId):
        taskInstance = getTask(taskId)
        completePathMain = taskInstance.getMainCompletePath()
        assert len(completePathMain) > 1  # to make sure we set a backupPath for a task having a mainPath
        mainEdges = taskInstance.getMainEdges()
        newTopo = self.topo.getNewTopoExceptSE(mainEdges)

        srcSwitch = taskInstance.getSrcSwtich()
        dstSwtich = taskInstance.getDstSwitch()

        if self.trafficBalance:
            newCompletePathBackup = newTopo.getWeightPath(srcSwitch, dstSwtich)
        else:
            newCompletePathBackup = newTopo.getShortestPath(srcSwitch, dstSwtich)

        if not newCompletePathBackup:
            self.logger.warning("can not assign a new backupPath for this task ")
            return

        taskInstance.setBackupCompletePath(newCompletePathBackup)
        nodeToDomain = self.topo.nodeToDomainId
        newBackupSectorialPath = taskInstance.getBackupSectorialPath(nodeToDomain)

        newAllBackupPathMpls = self.LabelsPool.getLabels(len(newCompletePathBackup))
        noUseLabels = taskInstance.assignBackuPathMpls(newAllBackupPathMpls)
        self.LabelsPool.recycleLabels(noUseLabels)

        for i in newBackupSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(i,  type='backup')
            command = self._to_commad(send_message)
            print 'newbackup: ', command
            self.send_no_return_command(command)
            taskInstance.addBackupUnconfirmDomain(i)


    def _keep_alive(self):
        while True:
            for i in self.domains:
                self.sendKeepAlive(i)
                self.logger.info("send keepalive to domain %d" % i)
            hub.sleep(10)

    def sendKeepAlive(self, i):
        send_message = self._make_keep_alive(i)
        command = self._to_commad(send_message)
        self.send_no_return_command(command)


    def _make_keep_alive(self, i):
        to_send = {}
        to_send[TYPE] = 'keepAlive'
        to_send[DOMAINID] = i

        send_message = json.dumps(to_send)
        return send_message


    def send_no_return_command(self, command):
        try:
            os.popen2(command)
        except:
            self.logger.debug('command exceute fail.Fail Command: %s' % command)
            return

    def _to_commad(self, send_message, returnType=False):

        message = eval(send_message)
        domainId = message.get(DOMAINID)
        domainInstance = self.domains.get(domainId)
        domainWsgiIp = domainInstance.getWsgiIp()
        domainWsgiPort = domainInstance.getWsgiPort()

        command = 'curl -X '
        if returnType:
            command += 'GET -d \''
        else:
            command += 'PUT -d \''
        command += send_message
        command += '\' http://'
        command += domainWsgiIp
        command += ':'
        command += str(domainWsgiPort)
        if not returnType:
            command += DOMAINURLNORETURN
        else:
            command += DOMAINURLRETURN

        command += ' 2> /dev/null'

        return command

    ###################################################################



    @set_ev_cls(bgpevent, MAIN_DISPATCHER)
    def handler_bgp_msg(self, ev):
        bgp_msg = ev.ev
        remote_as = bgp_msg.remote_as
        route_dist = bgp_msg.route_dist
        prefix = bgp_msg.prefix
        nexthop = bgp_msg.nexthop
        label = bgp_msg.label
        is_withdraw = bgp_msg.is_withdraw
        #Table.prefix_to_nexthop.update({prefix: nexthop})
        if prefix not in Table.prefix_to_nexthop.keys():
            Table.prefix_to_nexthop[prefix] = nexthop