Committed by
Gerrit Code Review
opticalUtils.py modifications
o Topology.json matches what the network configuration system expects. New method for converting opticalJSON added to add layer of indirection to (hopefully) make changes easier in the future if syntax changes for any files. o onos-topo-cfg takes a third argument for REST uri path. This is for backwards compatibility, and can hopefully be removed when everything is ported away from using the ConfigProvider. Change-Id: I56a117f33194dd420ea4970cd612c980b5c020b9
Showing
2 changed files
with
53 additions
and
8 deletions
... | @@ -8,7 +8,8 @@ | ... | @@ -8,7 +8,8 @@ |
8 | 8 | ||
9 | node="${1:-$OCI}" | 9 | node="${1:-$OCI}" |
10 | file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}" | 10 | file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}" |
11 | +url="${3:-config/topology}" | ||
11 | 12 | ||
12 | curl -sS --fail -L --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ | 13 | curl -sS --fail -L --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ |
13 | -X POST -H 'Content-Type:application/json' \ | 14 | -X POST -H 'Content-Type:application/json' \ |
14 | - http://$node:8181/onos/v1/config/topology -d@$file | 15 | + http://$node:8181/onos/v1/${url} -d@$file | ... | ... |
... | @@ -291,7 +291,7 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -291,7 +291,7 @@ class LINCSwitch(OpticalSwitch): |
291 | json.dump(crossConnectJSON, fd, indent=4, separators=(',', ': ')) | 291 | json.dump(crossConnectJSON, fd, indent=4, separators=(',', ': ')) |
292 | info('*** Pushing crossConnect.json to ONOS\n') | 292 | info('*** Pushing crossConnect.json to ONOS\n') |
293 | output = quietRun('%s/tools/test/bin/onos-topo-cfg %s\ | 293 | output = quietRun('%s/tools/test/bin/onos-topo-cfg %s\ |
294 | - Topology.json' % (self.onosDir, self.controllers[ 0 ].ip), shell=True) | 294 | + Topology.json network/configuration/' % (self.onosDir, self.controllers[ 0 ].ip), shell=True) |
295 | 295 | ||
296 | def stop_oe(self): | 296 | def stop_oe(self): |
297 | ''' | 297 | ''' |
... | @@ -374,16 +374,17 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -374,16 +374,17 @@ class LINCSwitch(OpticalSwitch): |
374 | LINCSwitch.opticalJSON[ 'links' ] = linkConfig | 374 | LINCSwitch.opticalJSON[ 'links' ] = linkConfig |
375 | 375 | ||
376 | info('*** Writing Topology.json file\n') | 376 | info('*** Writing Topology.json file\n') |
377 | + topoJSON = LINCSwitch.makeTopoJSON() | ||
377 | with open('Topology.json', 'w') as outfile: | 378 | with open('Topology.json', 'w') as outfile: |
378 | - json.dump(LINCSwitch.opticalJSON, outfile, indent=4, separators=(',', ': ')) | 379 | + json.dump(topoJSON, outfile, indent=4, separators=(',', ': ')) |
379 | 380 | ||
380 | info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n') | 381 | info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n') |
381 | 382 | ||
382 | - topoConfigJson = {}; | 383 | + topoConfigJson = {} |
383 | - dpIdToName = {}; | 384 | + dpIdToName = {} |
384 | 385 | ||
385 | - topoConfigJson["switchConfig"] = LINCSwitch.getSwitchConfig(dpIdToName); | 386 | + topoConfigJson["switchConfig"] = LINCSwitch.getSwitchConfig(dpIdToName) |
386 | - topoConfigJson["linkConfig"] = LINCSwitch.getLinkConfig(dpIdToName); | 387 | + topoConfigJson["linkConfig"] = LINCSwitch.getLinkConfig(dpIdToName) |
387 | 388 | ||
388 | #Writing to TopoConfig.json | 389 | #Writing to TopoConfig.json |
389 | with open( 'TopoConfig.json', 'w' ) as outfile: | 390 | with open( 'TopoConfig.json', 'w' ) as outfile: |
... | @@ -470,7 +471,8 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -470,7 +471,8 @@ class LINCSwitch(OpticalSwitch): |
470 | 471 | ||
471 | info('*** Pushing Topology.json to ONOS\n') | 472 | info('*** Pushing Topology.json to ONOS\n') |
472 | for index in range(len(LINCSwitch.controllers)): | 473 | for index in range(len(LINCSwitch.controllers)): |
473 | - output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json &' % (LINCSwitch.onosDir, LINCSwitch.controllers[ index ].ip), shell=True) | 474 | + output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json network/configuration/ &'\ |
475 | + % (LINCSwitch.onosDir, LINCSwitch.controllers[ index ].ip), shell=True) | ||
474 | # successful output contains the two characters '{}' | 476 | # successful output contains the two characters '{}' |
475 | # if there is more output than this, there is an issue | 477 | # if there is more output than this, there is an issue |
476 | if output.strip('{}'): | 478 | if output.strip('{}'): |
... | @@ -486,6 +488,48 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -486,6 +488,48 @@ class LINCSwitch(OpticalSwitch): |
486 | return nodeDpid[0:-1]; | 488 | return nodeDpid[0:-1]; |
487 | 489 | ||
488 | @staticmethod | 490 | @staticmethod |
491 | + def makeTopoJSON(): | ||
492 | + """ | ||
493 | + Builds ONOS network conifg system compatible dicts to be written as Topology.json file. | ||
494 | + """ | ||
495 | + topology = {} | ||
496 | + links = {} | ||
497 | + devices = {} | ||
498 | + ports = {} | ||
499 | + | ||
500 | + for switch in LINCSwitch.opticalJSON[ 'devices' ]: | ||
501 | + # build device entries - keyed on uri (DPID) and config key 'basic' | ||
502 | + devDict = {} | ||
503 | + devDict[ 'driver' ] = switch[ 'hw' ] | ||
504 | + devDict[ 'mfr' ] = switch[ 'mfr' ] | ||
505 | + devDict[ 'mac' ] = switch[ 'mac' ] | ||
506 | + devDict[ 'type' ] = switch[ 'type' ] | ||
507 | + devDict.update(switch[ 'annotations' ]) | ||
508 | + | ||
509 | + devSubj = switch[ 'uri' ] | ||
510 | + devices[ devSubj ] = { 'basic': devDict } | ||
511 | + | ||
512 | + # build port entries - keyed on "uri/port" and config key 'optical' | ||
513 | + for port in switch[ 'ports' ]: | ||
514 | + portSubj = devSubj + '/' + str(port[ 'port' ]) | ||
515 | + ports[ portSubj ] = { 'optical': port } | ||
516 | + | ||
517 | + # build link entries - keyed on "uri/port-uri/port" and config key 'basic' | ||
518 | + for link in LINCSwitch.opticalJSON[ 'links' ]: | ||
519 | + linkDict = {} | ||
520 | + linkDict[ 'type' ] = link[ 'type' ] | ||
521 | + linkDict.update(link[ 'annotations' ]) | ||
522 | + | ||
523 | + linkSubj = link[ 'src' ] + '-' + link[ 'dst' ] | ||
524 | + links[ linkSubj ] = { 'basic': linkDict } | ||
525 | + | ||
526 | + topology[ 'links' ] = links | ||
527 | + topology[ 'devices' ] = devices | ||
528 | + topology[ 'ports' ] = ports | ||
529 | + | ||
530 | + return topology | ||
531 | + | ||
532 | + @staticmethod | ||
489 | def getSwitchConfig (dpIdToName): | 533 | def getSwitchConfig (dpIdToName): |
490 | switchConfig = []; | 534 | switchConfig = []; |
491 | #Iterate through all switches and convert the ROADM switches to linc-oe format | 535 | #Iterate through all switches and convert the ROADM switches to linc-oe format | ... | ... |
-
Please register or login to post a comment