Ejemplo n.º 1
0
    def register_taskInstance(self, taskInstance, virSectorialPath, SC):
        registerTask(taskInstance)

        print 'taskInstance.srcSwitch: ', type(taskInstance.srcSwitch)
        print 'SC.topo.nodeToDomainId: ', type(SC.topo.nodeToDomainId.keys()[0])

        i = SC.topo.nodeToDomainId[int(taskInstance.srcSwitch)]
        SC.taskId_domainId[taskInstance.taskId] = i
        if i in virSectorialPath:
            send_message = taskInstance.makeDomainTaskAssign(i, virSectorialPath)
            print 'send_message: ', send_message
            command = SC._to_commad(send_message)
            print "main: ", command
            SC.send_no_return_command(command)
            taskInstance.addMainUnconfirmDomain(i)
Ejemplo n.º 2
0
    def taskAssign(self, req):

        SC = self.SuperController
        body = req.body
        rest = eval(body)
        taskId = rest[TASK_ID]

        if not taskId:
            return Response(status=200, body="Input a task Id\n")
        if assertTaskInDict(taskId):
            taskInstance = getTask(taskId)
        else:
            taskInstance = Task(taskId)

        if taskInstance.isEstablished():

            return Response(status=200, body="taskId duplicated!\n")

        srcSwitch = rest[SRC_SWITCH]
        dstSwitch = rest[DST_SWITCH]
        bandwith = rest[BANDWIDTH]
        # duration = rest[]
        dstIp = rest[DST_IP]
        srcIp = rest[SRC_IP]
        local_mac = rest[LOCAL_MAC]
        next_mac = rest[NEXT_MAC]
        last_outport_num = rest[LAST_OUTPORT_NUM]
        taskInstance.taskSetFields(srcSwitch=srcSwitch,
                                   dstSwitch=dstSwitch,
                                   srcIp=srcIp,
                                   dstIp=dstIp,
                                   local_mac=local_mac,
                                   next_mac=next_mac,
                                   last_outport_num=last_outport_num,
                                   bandwidth=bandwith)

        if SC.trafficBalance:
            completePathMain = SC.topo.getWeightPath(srcSwitch, dstSwitch)
            if not completePathMain:
                self.logger.warning("no main path between switch %d and %d" %
                                    (srcSwitch, dstSwitch))
                return Response(
                    status=200,
                    body="no main path between switch %d and %d\n" %
                    (srcSwitch, dstSwitch))

            taskInstance.setMainCompletePath(completePathMain)
            mainEdges = taskInstance.getMainEdges()
            newTopo = SC.topo.getNewTopoExceptSE(mainEdges)
            completePathBackup = newTopo.getWeightPath(srcSwitch, dstSwitch)
            if not completePathBackup:
                self.logger.warning("no backup path between switch %d and %d" %
                                    (srcSwitch, dstSwitch))

            taskInstance.setBackupCompletePath(completePathBackup)
        else:
            completePathMath = SC.topo.getShortestPath(srcSwitch, dstSwitch)
            if not completePathMath:
                self.logger.warning("no main path between switch %d and %d" %
                                    (srcSwitch, dstSwitch))
                return Response(
                    status=200,
                    body="no main path between switch %d and %d\n" %
                    (srcSwitch, dstSwitch))

            taskInstance.setMainCompletePath(completePathMath)
            mainEdges = taskInstance.getMainEdges()
            newTopo = SC.topo.getNewTopoExceptSE(mainEdges)
            completePathBackup = newTopo.getShorestPath(srcSwitch, dstSwitch)
            if not completePathBackup:
                self.logger.warning("no backup path between switch %d and %d" %
                                    (srcSwitch, dstSwitch))

            taskInstance.setBackupCompletePath(completePathBackup)

        nodeToDomian = SC.topo.nodeToDomainId
        mainSectorialPath = taskInstance.getMainSectorialPath(nodeToDomian)
        backupSectorialPath = taskInstance.getBackupSectorialPath(nodeToDomian)
        # print mainSectorialPath
        # print backupSectorialPath

        allMainPathMpls = SC.LabelsPool.getLabels(len(completePathMain))
        noUseLabels = taskInstance.assignMainPathMpls(allMainPathMpls)
        SC.LabelsPool.recycleLabels(noUseLabels)

        allBackupPathMpls = SC.LabelsPool.getLabels(len(completePathBackup))
        noUseLabels = taskInstance.assignBackuPathMpls(allBackupPathMpls)
        SC.LabelsPool.recycleLabels(noUseLabels)

        registerTask(taskInstance)
        # print "main: ", completePathMain
        # print "backup: ", completePathBackup
        # print "nodeToDomain: ", nodeToDomian

        for i in mainSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(i)

            command = SC._to_commad(send_message)
            print "main: ", command
            SC.send_no_return_command(command)
            taskInstance.addMainUnconfirmDomain(i)

        for j in backupSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(j, type='backup')

            command = SC._to_commad(send_message)
            print "backup: ", command
            SC.send_no_return_command(command)
            taskInstance.addBackupUnconfirmDomain(j)
Ejemplo n.º 3
0
    def taskAssign(self, req):

        SC = self.SuperController
        body = req
        #print repr(req)
        rest = eval(body)
        taskId = rest[TASK_ID]

        if not taskId:
            return Response(status=200, body="there is no task Id\n")

        #if taskid and task object have been registered,return a task object ,or instantiate a task object
        if assertTaskInDict(taskId):
            taskInstance = getTask(taskId)
        else:
            taskInstance = Task(taskId)

        if taskInstance.isEstablished():

            return Response(status=200, body="taskId duplicated!\n")

        srcSwitch = rest[SRC_SWITCH]
        dstSwitch = rest[DST_SWITCH]
        bandwith = rest[BANDWIDTH]
        # duration = rest[]
        local_mac = rest[LOCAL_MAC]
        next_mac = rest[NEXT_MAC]
        last_outport_num = rest[LAST_OUTPORT_NUM]

        domain_type = rest[DOMAINTYPE]

        if domain_type is 'L3':
            dstIp = rest[DST_IP]
            srcIp = rest[SRC_IP]
            taskInstance.taskSetIpFields(srcSwitch=srcSwitch,
                                         dstSwitch=dstSwitch,
                                         srcIp=srcIp,
                                         dstIp=dstIp,
                                         local_mac=local_mac,
                                         next_mac=next_mac,
                                         last_outport_num=last_outport_num,
                                         bandwidth=bandwith)
        #generate a task object
        else:
            srcMac = rest['srcMac']
            dstMac = rest['dstMac']
            #print 'srcMac,dstMac: ',srcMac,dstMac
            taskInstance.taskSetMacFields(srcSwitch=srcSwitch,
                                          dstSwitch=dstSwitch,
                                          srcMac=srcMac,
                                          dstMac=dstMac,
                                          last_outport_num=last_outport_num,
                                          bandwidth=bandwith)
##########################################################################################################
#print 'SC.virualTopo.topo.edges(): ',SC.virualTopo.topo.edges()
#print 'srcSwitch,dstSwitch: ',srcSwitch,dstSwitch
        completePathVir = SC.virualTopo.getWeightPath(int(srcSwitch),
                                                      int(dstSwitch))
        # print 'New Task src_dpid,dst_dpid: ',srcSwitch,dstSwitch
        # print 'New Task completePathVir: ', completePathVir
        # print 'New Task topo: ',SC.virualTopo.edges()
        #print 'topo: ',SC.virualTopo.edge()

        if not completePathVir:
            self.logger.warning(
                "no virual path between switch %0x16 and %0x16" %
                (srcSwitch, dstSwitch))
            return Response(
                status=200,
                body="no main path between switch %0x16 and %0x16\n" %
                (srcSwitch, dstSwitch))
        print "Link calculate success between %0x16 and %0x16:" % (
            int(srcSwitch), int(dstSwitch)), completePathVir

        # allMainPathMpls = SC.LabelsPool.getLabels(len(completePathVir))#n different numbers
        # noUseLabels = taskInstance.assignMainPathMpls(allMainPathMpls)
        # SC.LabelsPool.recycleLabels(noUseLabels)

        taskInstance.setVirCompletePath(completePathVir)
        virEdges = taskInstance.getVirEdges()
        # print 'virEdges: ',virEdges
        nodeToDomain = SC.topo.nodeToDomainId
        virSectorialPath = taskInstance.getVirSectorialPath(
            nodeToDomain, virEdges)

        # print 'virSectorialPath: ', virSectorialPath

        registerTask(taskInstance)
        print "Begin send task to Domain."
        for i in virSectorialPath:
            send_message = taskInstance.makeDomainTaskAssign(i)
            # print 'send_message: ', send_message
            command = SC._to_commad(send_message)
            # print "main: ", command
            SC.send_no_return_command(command)
            taskInstance.addMainUnconfirmDomain(i)
Ejemplo n.º 4
0
    def taskAssign(self, req):

        SC = self.SuperController
        body = req
        rest = eval(body)
        taskId = rest[TASK_ID]

        if not taskId:
            return Response(status=200, body="Input a task Id\n")
        if assertTaskInDict(taskId):
            taskInstance = getTask(taskId)
        else:
            taskInstance = Task(taskId)

        if taskInstance.isEstablished():

            return Response(status=200, body="taskId duplicated!\n")

        srcSwitch = rest[SRC_SWITCH]
        dstSwitch = rest[DST_SWITCH]
        bandwith = rest[BANDWIDTH]
        # duration = rest[]
        dstIp = rest[DST_IP]
        srcIp = rest[SRC_IP]
        local_mac = rest[LOCAL_MAC]
        next_mac = rest[NEXT_MAC]
        last_outport_num = rest[LAST_OUTPORT_NUM]
        taskInstance.taskSetFields(srcSwitch=srcSwitch, dstSwitch=dstSwitch, srcIp=srcIp, dstIp=dstIp, local_mac=local_mac, next_mac=next_mac, last_outport_num=last_outport_num, bandwidth=bandwith)


        if SC.trafficBalance:
            completePathMain = SC.topo.getWeightPath(srcSwitch, dstSwitch)
            if not completePathMain:
                self.logger.warning("no main path between switch %d and %d" % (srcSwitch, dstSwitch))
                return Response(status=200, body="no main path between switch %d and %d\n" % (srcSwitch, dstSwitch))

            taskInstance.setMainCompletePath(completePathMain)
            mainEdges = taskInstance.getMainEdges()
            newTopo = SC.topo.getNewTopoExceptSE(mainEdges)
            completePathBackup = newTopo.getWeightPath(srcSwitch, dstSwitch)
            if not completePathBackup:
                self.logger.warning("no backup path between switch %d and %d" % (srcSwitch, dstSwitch))

            taskInstance.setBackupCompletePath(completePathBackup)
        else:
            completePathMath = SC.topo.getShortestPath(srcSwitch, dstSwitch)
            if not completePathMath:
                self.logger.warning("no main path between switch %d and %d" % (srcSwitch, dstSwitch))
                return Response(status=200, body="no main path between switch %d and %d\n" % (srcSwitch, dstSwitch))

            taskInstance.setMainCompletePath(completePathMath)
            mainEdges = taskInstance.getMainEdges()
            newTopo = SC.topo.getNewTopoExceptSE(mainEdges)
            completePathBackup = newTopo.getShorestPath(srcSwitch, dstSwitch)
            if not completePathBackup:
                self.logger.warning("no backup path between switch %d and %d" % (srcSwitch, dstSwitch))

            taskInstance.setBackupCompletePath(completePathBackup)
            # backupEdges = taskInstance.getBackupEdges()
            # newTopo = SC.topo.getNewTopoExceptSE(backupEdges)

        nodeToDomian = SC.topo.nodeToDomainId
        mainSectorialPath = taskInstance.getMainSectorialPath(nodeToDomian)
        backupSectorialPath = taskInstance.getBackupSectorialPath(nodeToDomian)
        # print mainSectorialPath
        # print backupSectorialPath


        allMainPathMpls = SC.LabelsPool.getLabels(len(completePathMain))
        noUseLabels = taskInstance.assignMainPathMpls(allMainPathMpls)
        SC.LabelsPool.recycleLabels(noUseLabels)

        allBackupPathMpls = SC.LabelsPool.getLabels(len(completePathBackup))
        noUseLabels = taskInstance.assignBackuPathMpls(allBackupPathMpls)
        SC.LabelsPool.recycleLabels(noUseLabels)

        registerTask(taskInstance)
        # print "main: ", completePathMain
        # print "backup: ", completePathBackup
        # print "nodeToDomain: ", nodeToDomian

        for i in mainSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(i)

            command = SC._to_commad(send_message)
            print "main: ", command
            SC.send_no_return_command(command)
            taskInstance.addMainUnconfirmDomain(i)

        

        for j in backupSectorialPath:
            send_message = taskInstance.makeDoaminTaskAssign(j, type='backup')

            command = SC._to_commad(send_message)
            print "backup: ",command
            SC.send_no_return_command(command)
            taskInstance.addBackupUnconfirmDomain(j)
Ejemplo n.º 5
0
    def taskAssign(self, req):

        SC = self.SuperController
        body = req
        #print repr(req)
        rest = eval(body)
        taskId = rest[TASK_ID]

        if not taskId:
            return Response(status=200, body="there is no task Id\n")

        #if taskid and task object have been registered,return a task object ,or instantiate a task object
        if assertTaskInDict(taskId):
            taskInstance = getTask(taskId)
        else:
            taskInstance = Task(taskId)


        if taskInstance.isEstablished():
            
            return Response(status=200, body="taskId duplicated!\n")

        srcSwitch = rest[SRC_SWITCH]
        dstSwitch = rest[DST_SWITCH]
        bandwith = rest[BANDWIDTH]
        # duration = rest[]
        local_mac = rest[LOCAL_MAC]
        next_mac = rest[NEXT_MAC]
        last_outport_num = rest[LAST_OUTPORT_NUM]

        domain_type = rest[DOMAINTYPE]

        if domain_type is 'L3':
            dstIp = rest[DST_IP]
            srcIp = rest[SRC_IP]
            taskInstance.taskSetIpFields(srcSwitch=srcSwitch, dstSwitch=dstSwitch, srcIp=srcIp, dstIp=dstIp,
                                   local_mac=local_mac, next_mac=next_mac, last_outport_num=last_outport_num,
                                   bandwidth=bandwith)
        #generate a task object
        else:
            srcMac = rest['srcMac']
            dstMac = rest['dstMac']
            #print 'srcMac,dstMac: ',srcMac,dstMac
            taskInstance.taskSetMacFields(srcSwitch=srcSwitch, dstSwitch=dstSwitch, srcMac=srcMac,dstMac=dstMac,
                                      last_outport_num=last_outport_num,bandwidth=bandwith)
##########################################################################################################
        #print 'SC.virualTopo.topo.edges(): ',SC.virualTopo.topo.edges()
        #print 'srcSwitch,dstSwitch: ',srcSwitch,dstSwitch
        completePathVir = SC.virualTopo.getWeightPath(int(srcSwitch), int(dstSwitch))
        # print 'New Task src_dpid,dst_dpid: ',srcSwitch,dstSwitch
        # print 'New Task completePathVir: ', completePathVir
        # print 'New Task topo: ',SC.virualTopo.edges()
        #print 'topo: ',SC.virualTopo.edge()



        if not completePathVir:
            self.logger.warning("no virual path between switch %0x16 and %0x16" % (srcSwitch, dstSwitch))
            return Response(status=200, body="no main path between switch %0x16 and %0x16\n" % (srcSwitch, dstSwitch))
        print "Link calculate success between %0x16 and %0x16:"%(int(srcSwitch), int(dstSwitch)),completePathVir

        # allMainPathMpls = SC.LabelsPool.getLabels(len(completePathVir))#n different numbers
        # noUseLabels = taskInstance.assignMainPathMpls(allMainPathMpls)
        # SC.LabelsPool.recycleLabels(noUseLabels)

        taskInstance.setVirCompletePath(completePathVir)
        virEdges = taskInstance.getVirEdges()
        # print 'virEdges: ',virEdges
        nodeToDomain = SC.topo.nodeToDomainId
        virSectorialPath = taskInstance.getVirSectorialPath(nodeToDomain, virEdges)

        # print 'virSectorialPath: ', virSectorialPath

        registerTask(taskInstance)
        print "Begin send task to Domain."
        for i in virSectorialPath:
            send_message = taskInstance.makeDomainTaskAssign(i)
            # print 'send_message: ', send_message
            command = SC._to_commad(send_message)
            # print "main: ", command
            SC.send_no_return_command(command)
            taskInstance.addMainUnconfirmDomain(i)