Marc De Leenheer
Committed by Pavlin Radoslavov

Configure LINC-OE to use multiple controllers

[Merged from onos-1.0]

Change-Id: I69b1c8935acdc8869cd19eb916e310965d8a2f48
(cherry picked from commit 16268818)
...@@ -197,18 +197,12 @@ def switchJSON( switch ): ...@@ -197,18 +197,12 @@ def switchJSON( switch ):
197 return configDict 197 return configDict
198 198
199 199
200 -def startOE( net, controllerIP=None, controllerPort=None ): 200 +def startOE( net ):
201 "Start the LINC optical emulator within a mininet instance" 201 "Start the LINC optical emulator within a mininet instance"
202 opticalJSON = {} 202 opticalJSON = {}
203 linkConfig = [] 203 linkConfig = []
204 devices = [] 204 devices = []
205 205
206 - # if we are not given a controller IP or Port, we use the first found in Mininet
207 - if controllerIP is None:
208 - controllerIP = net.controllers[ 0 ].ip
209 - if controllerPort is None:
210 - controllerPort = net.controllers[ 0 ].port
211 -
212 for switch in net.switches: 206 for switch in net.switches:
213 if isinstance( switch, OpticalSwitch ): 207 if isinstance( switch, OpticalSwitch ):
214 devices.append( switch.json() ) 208 devices.append( switch.json() )
...@@ -247,11 +241,20 @@ def startOE( net, controllerIP=None, controllerPort=None ): ...@@ -247,11 +241,20 @@ def startOE( net, controllerIP=None, controllerPort=None ):
247 error( "***ERROR: Could not find LINC-config-generator in user's home directory\n" ) 241 error( "***ERROR: Could not find LINC-config-generator in user's home directory\n" )
248 return False 242 return False
249 output = quietRun( '%s/config_generator TopoConfig.json %s/sys.config.template %s %s' 243 output = quietRun( '%s/config_generator TopoConfig.json %s/sys.config.template %s %s'
250 - % ( configGen, configGen, controllerIP, controllerPort ), shell=True ) 244 + % ( configGen, configGen, net.controllers[ 0 ].ip, net.controllers[ 0 ].port ), shell=True )
251 if output: 245 if output:
252 error( '***ERROR: Error creating sys.config file: %s\n' % output ) 246 error( '***ERROR: Error creating sys.config file: %s\n' % output )
253 return False 247 return False
254 248
249 + info ('*** Setting multiple controllers in sys.config...\n' )
250 + searchStr = '{controllers,.*$'
251 + ctrlStr = ''
252 + for index in range(len(net.controllers)):
253 + ctrlStr += '{"Switch%d-Controller","%s",%d,tcp},' % (index, net.controllers[index].ip, net.controllers[index].port)
254 + replaceStr = '{controllers,[%s]},' % ctrlStr[:-1] # Cut off last comma
255 + sedCmd = 'sed -i \'s/%s/%s/\' sys.config' % (searchStr, replaceStr)
256 + output = quietRun( sedCmd, shell=True )
257 +
255 info( '*** Copying sys.config to linc-oe directory: ', output + '\n' ) 258 info( '*** Copying sys.config to linc-oe directory: ', output + '\n' )
256 lincDir = findDir( 'linc-oe' ) 259 lincDir = findDir( 'linc-oe' )
257 if not lincDir: 260 if not lincDir:
...@@ -284,7 +287,7 @@ def startOE( net, controllerIP=None, controllerPort=None ): ...@@ -284,7 +287,7 @@ def startOE( net, controllerIP=None, controllerPort=None ):
284 info( '*** Press any key to push Topology.json to onos...\n' ) 287 info( '*** Press any key to push Topology.json to onos...\n' )
285 raw_input() # FIXME... we should eventually remove this 288 raw_input() # FIXME... we should eventually remove this
286 info( '*** Pushing Topology.json to ONOS\n' ) 289 info( '*** Pushing Topology.json to ONOS\n' )
287 - output = quietRun( '%s/tools/test/bin/onos-topo-cfg %s Topology.json' % ( onosDir, controllerIP ), shell=True ) 290 + output = quietRun( '%s/tools/test/bin/onos-topo-cfg %s Topology.json' % ( onosDir, net.controllers[ 0 ].ip ), shell=True )
288 # successful output contains the two characters '{}' 291 # successful output contains the two characters '{}'
289 # if there is more output than this, there is an issue 292 # if there is more output than this, there is an issue
290 if output.strip( '{}' ): 293 if output.strip( '{}' ):
......