From 81391595dca425ae58e2294898f09f11d9a32dbc Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 22 Sep 2015 12:49:09 -0700 Subject: bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4 Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f --- framework/src/onos/tools/test/topos/onos.py | 2 +- .../src/onos/tools/test/topos/opticalUtils.py | 74 ++++++++++++++++++---- 2 files changed, 64 insertions(+), 12 deletions(-) (limited to 'framework/src/onos/tools/test/topos') diff --git a/framework/src/onos/tools/test/topos/onos.py b/framework/src/onos/tools/test/topos/onos.py index 3e5bff7c..ae6045e3 100755 --- a/framework/src/onos/tools/test/topos/onos.py +++ b/framework/src/onos/tools/test/topos/onos.py @@ -62,7 +62,7 @@ class ONOS( Controller ): def start( self ): if self.inNamespace: - instanceOpts = ( '-furl mvn:org.onosproject/onos-features/1.3.0-SNAPSHOT/xml/features ' + instanceOpts = ( '-furl mvn:org.onosproject/onos-features/1.4.0-SNAPSHOT/xml/features ' '-s 8101' ) if self.ip is not None: instanceOpts += (' -a %s' % self.IP() ) diff --git a/framework/src/onos/tools/test/topos/opticalUtils.py b/framework/src/onos/tools/test/topos/opticalUtils.py index bef9deca..a1ae834b 100644 --- a/framework/src/onos/tools/test/topos/opticalUtils.py +++ b/framework/src/onos/tools/test/topos/opticalUtils.py @@ -70,9 +70,6 @@ from mininet.cli import CLI SLEEP_TIME = 2 TIMEOUT = 60 -REST_USER = 'onos' -REST_PW = 'rocks' - class OpticalSwitch(Switch): """ For now, same as Switch class. @@ -152,6 +149,17 @@ class LINCSwitch(OpticalSwitch): error('Please set ONOS_ROOT environment variable!\n') else: os.environ[ 'ONOS_ROOT' ] = onosDir + ### REST USER/PASS ### + try: + restUser = os.environ[ 'ONOS_WEB_USER' ] + restPass = os.environ[ 'ONOS_WEB_PASS' ] + except: + error('***WARNING: $ONOS_WEB_USER and $ONOS_WEB_PASS aren\'t set!\n') + error('***WARNING: Setting (probably) sane WEB user/pass values\n') + restUser = 'onos' + restPass = 'rocks' + os.environ[ 'ONOS_WEB_USER' ] = restUser + os.environ[ 'ONOS_WEB_PASS' ] = restPass ### LINC-directory lincDir = findDir.__func__('linc-oe', user) if not lincDir: @@ -283,7 +291,7 @@ class LINCSwitch(OpticalSwitch): json.dump(crossConnectJSON, fd, indent=4, separators=(',', ': ')) info('*** Pushing crossConnect.json to ONOS\n') output = quietRun('%s/tools/test/bin/onos-topo-cfg %s\ - Topology.json' % (self.onosDir, self.controllers[ 0 ].ip), shell=True) + Topology.json network/configuration/' % (self.onosDir, self.controllers[ 0 ].ip), shell=True) def stop_oe(self): ''' @@ -366,16 +374,17 @@ class LINCSwitch(OpticalSwitch): LINCSwitch.opticalJSON[ 'links' ] = linkConfig info('*** Writing Topology.json file\n') + topoJSON = LINCSwitch.makeTopoJSON() with open('Topology.json', 'w') as outfile: - json.dump(LINCSwitch.opticalJSON, outfile, indent=4, separators=(',', ': ')) + json.dump(topoJSON, outfile, indent=4, separators=(',', ': ')) info('*** Converting Topology.json to linc-oe format (TopoConfig.json) file (no oecfg) \n') - topoConfigJson = {}; - dpIdToName = {}; + topoConfigJson = {} + dpIdToName = {} - topoConfigJson["switchConfig"] = LINCSwitch.getSwitchConfig(dpIdToName); - topoConfigJson["linkConfig"] = LINCSwitch.getLinkConfig(dpIdToName); + topoConfigJson["switchConfig"] = LINCSwitch.getSwitchConfig(dpIdToName) + topoConfigJson["linkConfig"] = LINCSwitch.getLinkConfig(dpIdToName) #Writing to TopoConfig.json with open( 'TopoConfig.json', 'w' ) as outfile: @@ -433,7 +442,7 @@ class LINCSwitch(OpticalSwitch): time = 0 # Set up password authentication pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() - pw_mgr.add_password(None, url, REST_USER, REST_PW) + pw_mgr.add_password(None, url, LINCSwitch.restUser, LINCSwitch.restPass) handler = urllib2.HTTPBasicAuthHandler(pw_mgr) opener = urllib2.build_opener(handler) opener.open(url) @@ -462,7 +471,8 @@ class LINCSwitch(OpticalSwitch): info('*** Pushing Topology.json to ONOS\n') for index in range(len(LINCSwitch.controllers)): - output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json &' % (LINCSwitch.onosDir, LINCSwitch.controllers[ index ].ip), shell=True) + output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json network/configuration/ &'\ + % (LINCSwitch.onosDir, LINCSwitch.controllers[ index ].ip), shell=True) # successful output contains the two characters '{}' # if there is more output than this, there is an issue if output.strip('{}'): @@ -477,6 +487,48 @@ class LINCSwitch(OpticalSwitch): nodeDpid += (id[i:(i + 2):]) + ":" return nodeDpid[0:-1]; + @staticmethod + def makeTopoJSON(): + """ + Builds ONOS network conifg system compatible dicts to be written as Topology.json file. + """ + topology = {} + links = {} + devices = {} + ports = {} + + for switch in LINCSwitch.opticalJSON[ 'devices' ]: + # build device entries - keyed on uri (DPID) and config key 'basic' + devDict = {} + devDict[ 'driver' ] = switch[ 'hw' ] + devDict[ 'mfr' ] = switch[ 'mfr' ] + devDict[ 'mac' ] = switch[ 'mac' ] + devDict[ 'type' ] = switch[ 'type' ] + devDict.update(switch[ 'annotations' ]) + + devSubj = switch[ 'uri' ] + devices[ devSubj ] = { 'basic': devDict } + + # build port entries - keyed on "uri/port" and config key 'optical' + for port in switch[ 'ports' ]: + portSubj = devSubj + '/' + str(port[ 'port' ]) + ports[ portSubj ] = { 'optical': port } + + # build link entries - keyed on "uri/port-uri/port" and config key 'basic' + for link in LINCSwitch.opticalJSON[ 'links' ]: + linkDict = {} + linkDict[ 'type' ] = link[ 'type' ] + linkDict.update(link[ 'annotations' ]) + + linkSubj = link[ 'src' ] + '-' + link[ 'dst' ] + links[ linkSubj ] = { 'basic': linkDict } + + topology[ 'links' ] = links + topology[ 'devices' ] = devices + topology[ 'ports' ] = ports + + return topology + @staticmethod def getSwitchConfig (dpIdToName): switchConfig = []; -- cgit 1.2.3-korg