Exemplo n.º 1
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)
Exemplo n.º 2
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)