in opticalUtils.py:

General logic fixes for emulating multi-domain networks

Change-Id: I58e487e0b663a6b64e99d93d6fa5cea6afe86aac
diff --git a/tools/test/topos/opticalUtils.py b/tools/test/topos/opticalUtils.py
index 5d955e5..dddf755 100644
--- a/tools/test/topos/opticalUtils.py
+++ b/tools/test/topos/opticalUtils.py
@@ -58,7 +58,7 @@
 from time import sleep
 import urllib2
 
-from mininet.node import Switch, RemoteController
+from mininet.node import Switch, OVSSwitch, RemoteController
 from mininet.topo import Topo
 from mininet.util import quietRun
 from mininet.net import Mininet
@@ -357,7 +357,13 @@
 
     @staticmethod
     def bootOE(net):
-        "Start the LINC optical emulator within a mininet instance"
+        """
+        Start the LINC optical emulator within a mininet instance
+
+        This involves 1. converting the information stored in Linc* to configs
+        for both LINC and the network config system, 2. starting Linc, 3. connecting
+        cross-connects, and finally pushing the network configs to ONOS.
+        """
         LINCSwitch.opticalJSON = {}
         linkConfig = []
         devices = []
@@ -367,7 +373,7 @@
         for switch in net.switches:
             if isinstance(switch, OpticalSwitch):
                 devices.append(switch.json())
-            else:
+            elif isinstance(switch, OVSSwitch):
                 devices.append(LINCSwitch.switchJSON(switch))
         LINCSwitch.opticalJSON[ 'devices' ] = devices
 
@@ -450,18 +456,21 @@
         opener = urllib2.build_opener(handler)
         opener.open(url)
         urllib2.install_opener(opener)
+        # focus on just checking the state of devices we're interested in
+        devlist =  map( lambda x: x['uri'], devices )
         while True:
             response = json.load(urllib2.urlopen(url))
             devs = response.get('devices')
 
-            # Wait for all devices to be registered
-            if (len(devices) != len(devs)):
+            # Wait for all devices to be registered. There is a chance that this is only a subgraph.
+            if (len(devices) > len(devs)):
                 continue
 
             # Wait for all devices to available
             available = True
             for d in devs:
-                available &= d['available']
+                if d['id'] in devlist:
+                    available &= d['available']
             if available:
                 break
 
@@ -615,9 +624,11 @@
             if isinstance(link, LINCLink):
                 if link.annotations[ 'optical.type' ] == 'cross-connect':
                     tapCount += 1
-
         while True:
-            if str(tapCount) == quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'):
+            # tapCount can be less than the actual number of taps if the optical network
+            # is a subgraph of a larger multidomain network.
+            tapNum = int(quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'))
+            if tapCount <= tapNum:
                 return True
             if timeout:
                 if time >= TIMEOUT: