Committed by
Gerrit Code Review
Minor opticalUtils.py patch
Change-Id: I03e1daf02da024c9a27baf3e1de719f36868e6f9
Showing
1 changed file
with
16 additions
and
14 deletions
... | @@ -251,7 +251,7 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -251,7 +251,7 @@ class LINCSwitch(OpticalSwitch): |
251 | #-------------------------------------------------------------------------- | 251 | #-------------------------------------------------------------------------- |
252 | def start_oe(self): | 252 | def start_oe(self): |
253 | ''' | 253 | ''' |
254 | - start the existing LINC switch | 254 | + existing LINC switch |
255 | ''' | 255 | ''' |
256 | #starting Switch | 256 | #starting Switch |
257 | cmd = "linc:start_switch({}).\r\n".format(self.lincId) | 257 | cmd = "linc:start_switch({}).\r\n".format(self.lincId) |
... | @@ -344,7 +344,7 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -344,7 +344,7 @@ class LINCSwitch(OpticalSwitch): |
344 | @staticmethod | 344 | @staticmethod |
345 | def bootOE(net): | 345 | def bootOE(net): |
346 | "Start the LINC optical emulator within a mininet instance" | 346 | "Start the LINC optical emulator within a mininet instance" |
347 | - opticalJSON = {} | 347 | + LINCSwitch.opticalJSON = {} |
348 | linkConfig = [] | 348 | linkConfig = [] |
349 | devices = [] | 349 | devices = [] |
350 | #setting up the controllers for LINCSwitch class | 350 | #setting up the controllers for LINCSwitch class |
... | @@ -355,24 +355,24 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -355,24 +355,24 @@ class LINCSwitch(OpticalSwitch): |
355 | devices.append(switch.json()) | 355 | devices.append(switch.json()) |
356 | else: | 356 | else: |
357 | devices.append(LINCSwitch.switchJSON(switch)) | 357 | devices.append(LINCSwitch.switchJSON(switch)) |
358 | - opticalJSON[ 'devices' ] = devices | 358 | + LINCSwitch.opticalJSON[ 'devices' ] = devices |
359 | 359 | ||
360 | for link in net.links: | 360 | for link in net.links: |
361 | if isinstance(link, LINCLink) : | 361 | if isinstance(link, LINCLink) : |
362 | linkConfig.append(link.json()) | 362 | linkConfig.append(link.json()) |
363 | - opticalJSON[ 'links' ] = linkConfig | 363 | + LINCSwitch.opticalJSON[ 'links' ] = linkConfig |
364 | 364 | ||
365 | info('*** Writing Topology.json file\n') | 365 | info('*** Writing Topology.json file\n') |
366 | with open('Topology.json', 'w') as outfile: | 366 | with open('Topology.json', 'w') as outfile: |
367 | - json.dump(opticalJSON, outfile, indent=4, separators=(',', ': ')) | 367 | + json.dump(LINCSwitch.opticalJSON, outfile, indent=4, separators=(',', ': ')) |
368 | 368 | ||
369 | info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n') | 369 | info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n') |
370 | 370 | ||
371 | topoConfigJson = {}; | 371 | topoConfigJson = {}; |
372 | dpIdToName = {}; | 372 | dpIdToName = {}; |
373 | 373 | ||
374 | - topoConfigJson["switchConfig"] = getSwitchConfig(dpIdToName); | 374 | + topoConfigJson["switchConfig"] = LINCSwitch.getSwitchConfig(dpIdToName); |
375 | - topoConfigJson["linkConfig"] = getLinkConfig(dpIdToName); | 375 | + topoConfigJson["linkConfig"] = LINCSwitch.getLinkConfig(dpIdToName); |
376 | 376 | ||
377 | #Writing to TopoConfig.json | 377 | #Writing to TopoConfig.json |
378 | with open( 'TopoConfig.json', 'w' ) as outfile: | 378 | with open( 'TopoConfig.json', 'w' ) as outfile: |
... | @@ -459,17 +459,19 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -459,17 +459,19 @@ class LINCSwitch(OpticalSwitch): |
459 | warn('***WARNING: Could not push topology file to ONOS: %s\n' % output) | 459 | warn('***WARNING: Could not push topology file to ONOS: %s\n' % output) |
460 | 460 | ||
461 | #converts node ids to linc-oe format, with colons every two chars | 461 | #converts node ids to linc-oe format, with colons every two chars |
462 | + @staticmethod | ||
462 | def dpId(id): | 463 | def dpId(id): |
463 | nodeDpid = "" | 464 | nodeDpid = "" |
464 | id = id.split("/", 1)[0] | 465 | id = id.split("/", 1)[0] |
465 | for i in range(3, len(id) - 1, 2): | 466 | for i in range(3, len(id) - 1, 2): |
466 | nodeDpid += (id[i:(i + 2):]) + ":" | 467 | nodeDpid += (id[i:(i + 2):]) + ":" |
467 | - return nodeDpid[0:(len(nodeDpid) - 1)]; | 468 | + return nodeDpid[0:-1]; |
468 | 469 | ||
470 | + @staticmethod | ||
469 | def getSwitchConfig (dpIdToName): | 471 | def getSwitchConfig (dpIdToName): |
470 | switchConfig = []; | 472 | switchConfig = []; |
471 | #Iterate through all switches and convert the ROADM switches to linc-oe format | 473 | #Iterate through all switches and convert the ROADM switches to linc-oe format |
472 | - for switch in opticalJSON["devices"]: | 474 | + for switch in LINCSwitch.opticalJSON["devices"]: |
473 | if switch.get("type", "none") == "ROADM": | 475 | if switch.get("type", "none") == "ROADM": |
474 | builtSwitch = {} | 476 | builtSwitch = {} |
475 | 477 | ||
... | @@ -482,7 +484,7 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -482,7 +484,7 @@ class LINCSwitch(OpticalSwitch): |
482 | nodeId = switch["uri"] | 484 | nodeId = switch["uri"] |
483 | 485 | ||
484 | #convert the nodeId to linc-oe format | 486 | #convert the nodeId to linc-oe format |
485 | - nodeDpid = dpId(nodeId); | 487 | + nodeDpid = LINCSwitch.dpId(nodeId); |
486 | 488 | ||
487 | builtSwitch["name"] = switch.get("name", "none"); | 489 | builtSwitch["name"] = switch.get("name", "none"); |
488 | 490 | ||
... | @@ -500,18 +502,18 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -500,18 +502,18 @@ class LINCSwitch(OpticalSwitch): |
500 | switchConfig.append(builtSwitch); | 502 | switchConfig.append(builtSwitch); |
501 | return switchConfig | 503 | return switchConfig |
502 | 504 | ||
503 | - | 505 | + @staticmethod |
504 | def getLinkConfig (dpIdToName): | 506 | def getLinkConfig (dpIdToName): |
505 | newLinkConfig = []; | 507 | newLinkConfig = []; |
506 | #Iterate through all optical links and convert them to linc-oe format | 508 | #Iterate through all optical links and convert them to linc-oe format |
507 | - for link in opticalJSON["links"]: | 509 | + for link in LINCSwitch.opticalJSON["links"]: |
508 | if link.get("type", "none") == "OPTICAL": | 510 | if link.get("type", "none") == "OPTICAL": |
509 | builtLink = {} | 511 | builtLink = {} |
510 | 512 | ||
511 | #set basic link params for src and dst | 513 | #set basic link params for src and dst |
512 | builtLink["allowed"] = True; | 514 | builtLink["allowed"] = True; |
513 | - builtLink["nodeDpid1"] = dpId(link["src"]) | 515 | + builtLink["nodeDpid1"] = LINCSwitch.dpId(link["src"]) |
514 | - builtLink["nodeDpid2"] = dpId(link["dst"]) | 516 | + builtLink["nodeDpid2"] = LINCSwitch.dpId(link["dst"]) |
515 | 517 | ||
516 | #set more params such as name/bandwidth/port/waves if they exist | 518 | #set more params such as name/bandwidth/port/waves if they exist |
517 | params = {} | 519 | params = {} | ... | ... |
-
Please register or login to post a comment