Marc De Leenheer

Configure LINC-OE to use multiple controllers

Change-Id: I69b1c8935acdc8869cd19eb916e310965d8a2f48
...@@ -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() )
...@@ -248,11 +242,20 @@ def startOE( net, controllerIP=None, controllerPort=None ): ...@@ -248,11 +242,20 @@ def startOE( net, controllerIP=None, controllerPort=None ):
248 error( "***ERROR: Could not find LINC-config-generator in user's home directory\n" ) 242 error( "***ERROR: Could not find LINC-config-generator in user's home directory\n" )
249 return False 243 return False
250 output = quietRun( '%s/config_generator TopoConfig.json %s/sys.config.template %s %s' 244 output = quietRun( '%s/config_generator TopoConfig.json %s/sys.config.template %s %s'
251 - % ( configGen, configGen, controllerIP, controllerPort ), shell=True ) 245 + % ( configGen, configGen, net.controllers[ 0 ].ip, net.controllers[ 0 ].port ), shell=True )
252 if output: 246 if output:
253 error( '***ERROR: Error creating sys.config file: %s\n' % output ) 247 error( '***ERROR: Error creating sys.config file: %s\n' % output )
254 return False 248 return False
255 249
250 + info ('*** Setting multiple controllers in sys.config...\n' )
251 + searchStr = '{controllers,.*$'
252 + ctrlStr = ''
253 + for index in range(len(net.controllers)):
254 + ctrlStr += '{"Switch%d-Controller","%s",%d,tcp},' % (index, net.controllers[index].ip, net.controllers[index].port)
255 + replaceStr = '{controllers,[%s]},' % ctrlStr[:-1] # Cut off last comma
256 + sedCmd = 'sed -i \'s/%s/%s/\' sys.config' % (searchStr, replaceStr)
257 + output = quietRun( sedCmd, shell=True )
258 +
256 info( '*** Copying sys.config to linc-oe directory: ', output + '\n' ) 259 info( '*** Copying sys.config to linc-oe directory: ', output + '\n' )
257 lincDir = findDir( 'linc-oe' ) 260 lincDir = findDir( 'linc-oe' )
258 if not lincDir: 261 if not lincDir:
...@@ -285,7 +288,7 @@ def startOE( net, controllerIP=None, controllerPort=None ): ...@@ -285,7 +288,7 @@ def startOE( net, controllerIP=None, controllerPort=None ):
285 info( '*** Press ENTER to push Topology.json to onos...\n' ) 288 info( '*** Press ENTER to push Topology.json to onos...\n' )
286 raw_input() # FIXME... we should eventually remove this 289 raw_input() # FIXME... we should eventually remove this
287 info( '*** Pushing Topology.json to ONOS\n' ) 290 info( '*** Pushing Topology.json to ONOS\n' )
288 - output = quietRun( '%s/tools/test/bin/onos-topo-cfg %s Topology.json' % ( onosDir, controllerIP ), shell=True ) 291 + output = quietRun( '%s/tools/test/bin/onos-topo-cfg %s Topology.json' % ( onosDir, net.controllers[ 0 ].ip ), shell=True )
289 # successful output contains the two characters '{}' 292 # successful output contains the two characters '{}'
290 # if there is more output than this, there is an issue 293 # if there is more output than this, there is an issue
291 if output.strip( '{}' ): 294 if output.strip( '{}' ):
......