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)
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)