Committed by
Gerrit Code Review
First round of cleanups in optical path provisioner. No more user input for pack…
…et/optical mininet script. Change-Id: Ibbfa6a17a97432da8dee63e9cd15fa6b1c2c1e46
Showing
2 changed files
with
33 additions
and
8 deletions
This diff is collapsed. Click to expand it.
... | @@ -56,6 +56,7 @@ import re | ... | @@ -56,6 +56,7 @@ import re |
56 | import json | 56 | import json |
57 | import os | 57 | import os |
58 | from time import sleep | 58 | from time import sleep |
59 | +import urllib2 | ||
59 | 60 | ||
60 | from mininet.node import Switch, RemoteController | 61 | from mininet.node import Switch, RemoteController |
61 | from mininet.topo import Topo | 62 | from mininet.topo import Topo |
... | @@ -65,6 +66,10 @@ from mininet.log import setLogLevel, info, error, warn | ... | @@ -65,6 +66,10 @@ from mininet.log import setLogLevel, info, error, warn |
65 | from mininet.link import Link, Intf | 66 | from mininet.link import Link, Intf |
66 | from mininet.cli import CLI | 67 | from mininet.cli import CLI |
67 | 68 | ||
69 | +# Sleep time and timeout values in seconds | ||
70 | +SLEEP_TIME = .5 | ||
71 | +TIMEOUT = 60 | ||
72 | + | ||
68 | class OpticalSwitch(Switch): | 73 | class OpticalSwitch(Switch): |
69 | """ | 74 | """ |
70 | For now, same as Switch class. | 75 | For now, same as Switch class. |
... | @@ -414,17 +419,37 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -414,17 +419,37 @@ class LINCSwitch(OpticalSwitch): |
414 | intf2 = intfList[ 0 ] | 419 | intf2 = intfList[ 0 ] |
415 | intf.node.attach(LINCSwitch.findTap(intf2.node, intf2.node.ports[ intf2 ])) | 420 | intf.node.attach(LINCSwitch.findTap(intf2.node, intf2.node.ports[ intf2 ])) |
416 | 421 | ||
417 | - info('*** Press ENTER to push Topology.json to onos...\n') | 422 | + info('*** Waiting for all devices to be available in ONOS...\n') |
418 | - raw_input() # FIXME... we should eventually remove this | 423 | + url = 'http://%s:8181/onos/v1/devices' % LINCSwitch.controllers[0].ip |
424 | + time = 0 | ||
425 | + while True: | ||
426 | + response = json.load(urllib2.urlopen(url)) | ||
427 | + devs = response.get('devices') | ||
428 | + | ||
429 | + # Wait for all devices to be registered & available | ||
430 | + if (len(devices) == len(devs)): | ||
431 | + for d in devs: | ||
432 | + if not d['available']: | ||
433 | + continue | ||
434 | + break | ||
435 | + | ||
436 | + if (time >= TIMEOUT): | ||
437 | + error('***ERROR: ONOS did not register devices within %s seconds\n' % TIMEOUT) | ||
438 | + break | ||
439 | + | ||
440 | + time += SLEEP_TIME | ||
441 | + sleep(SLEEP_TIME) | ||
442 | + | ||
419 | info('*** Pushing Topology.json to ONOS\n') | 443 | info('*** Pushing Topology.json to ONOS\n') |
420 | output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json' % (LINCSwitch.onosDir, LINCSwitch.controllers[ 0 ].ip), shell=True) | 444 | output = quietRun('%s/tools/test/bin/onos-topo-cfg %s Topology.json' % (LINCSwitch.onosDir, LINCSwitch.controllers[ 0 ].ip), shell=True) |
445 | + | ||
421 | # successful output contains the two characters '{}' | 446 | # successful output contains the two characters '{}' |
422 | # if there is more output than this, there is an issue | 447 | # if there is more output than this, there is an issue |
423 | if output.strip('{}'): | 448 | if output.strip('{}'): |
424 | - warn('***WARNING: Could not push topology file to ONOS: %s' % output) | 449 | + warn('***WARNING: Could not push topology file to ONOS: %s\n' % output) |
425 | 450 | ||
426 | @staticmethod | 451 | @staticmethod |
427 | - def waitStarted(net, timeout=None): | 452 | + def waitStarted(net, timeout=TIMEOUT): |
428 | "wait until all tap interfaces are available" | 453 | "wait until all tap interfaces are available" |
429 | tapCount = 0 | 454 | tapCount = 0 |
430 | time = 0 | 455 | time = 0 |
... | @@ -437,11 +462,11 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -437,11 +462,11 @@ class LINCSwitch(OpticalSwitch): |
437 | if str(tapCount) == quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'): | 462 | if str(tapCount) == quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'): |
438 | return True | 463 | return True |
439 | if timeout: | 464 | if timeout: |
440 | - if time >= timeout: | 465 | + if time >= TIMEOUT: |
441 | - error('***ERROR: Linc OE did not start within %s seconds' % timeout) | 466 | + error('***ERROR: LINC OE did not start within %s seconds\n' % TIMEOUT) |
442 | return False | 467 | return False |
443 | - time += .5 | 468 | + time += SLEEP_TIME |
444 | - sleep(.5) | 469 | + sleep(SLEEP_TIME) |
445 | 470 | ||
446 | @staticmethod | 471 | @staticmethod |
447 | def shutdownOE(): | 472 | def shutdownOE(): | ... | ... |
-
Please register or login to post a comment