Merge "Decouple Mininet for SRBridging test"
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/SRBridgingTest.py b/TestON/tests/USECASE/SegmentRouting/dependencies/SRBridgingTest.py
index 814667c..1523811 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/SRBridgingTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/SRBridgingTest.py
@@ -53,17 +53,28 @@
         main.resultFileName = 'CASE%02d' % test_idx
         main.Cluster.setRunningNode( onosNodes )
         run.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
-        mininet_args = ' --spine=%d --leaf=%d' % ( topo[ topology ][ 0 ], topo[ topology ][ 1 ] )
-        if topo[ topology ][ 2 ]:
-            mininet_args += ' --dual-homed'
-        if len( vlan ) > 0 :
-            mininet_args += ' --vlan=%s' % ( ','.join( ['%d' % vlanId for vlanId in vlan ] ) )
+        if hasattr( main, 'Mininet1' ):
+            # Run the test with Mininet
+            mininet_args = ' --spine=%d --leaf=%d' % ( topo[ topology ][ 0 ], topo[ topology ][ 1 ] )
+            if topo[ topology ][ 2 ]:
+                mininet_args += ' --dual-homed'
+            if len( vlan ) > 0 :
+                mininet_args += ' --vlan=%s' % ( ','.join( ['%d' % vlanId for vlanId in vlan ] ) )
 
-        run.startMininet( main, 'trellis_fabric.py', args=mininet_args )
+            run.startMininet( main, 'trellis_fabric.py', args=mininet_args )
+        else:
+            # Run the test with physical devices
+            # TODO: connect TestON to the physical network
+            pass
+
         run.checkFlows( main, minFlowCount=topo[ topology ][ 4 ] * topo[ topology ][ 1 ], sleep=5 )
-
         leaf_dpid = [ "of:%016d" % ( ls + 1 ) for ls in range( topo[ topology ][ 1 ] ) ]
         for dpid in leaf_dpid:
             run.checkFlowsByDpid( main, dpid, topo[ topology ][ 4 ], sleep=5 )
         run.pingAll( main, 'CASE%02d' % test_idx )
-        run.cleanup( main )
+
+        if hasattr( main, 'Mininet1' ):
+            run.cleanup( main )
+        else:
+            # TODO: disconnect TestON from the physical network
+            pass
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index f7b1eed..ba4e0d7 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -47,6 +47,8 @@
         except ImportError:
             main.log.error( "ONOSSetup not found. exiting the test" )
             main.cleanAndExit()
+        from tests.dependencies.Network import Network
+        main.Network = Network()
         main.testSetUp.envSetupDescription()
         stepResult = main.FALSE
         try:
@@ -63,13 +65,7 @@
             main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
             # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
             main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
-            # -- INIT SECTION, ONLY RUNS ONCE -- #
 
-            copyResult1 = main.ONOSbench.scp( main.Mininet1,
-                                              main.dependencyPath +
-                                              main.topology,
-                                              main.Mininet1.home,
-                                              direction="to" )
             stepResult = main.testSetUp.envSetup()
         except Exception as e:
             main.testSetUp.envSetupException( e )
@@ -78,16 +74,6 @@
         try:
             main.topologyLib1 = main.params[ 'DEPENDENCY' ][ 'lib1' ]
             main.topologyLib2 = main.params[ 'DEPENDENCY' ][ 'lib2' ]
-            copyResult2 = main.ONOSbench.scp(main.Mininet1,
-                                             main.dependencyPath +
-                                             main.topologyLib1,
-                                             main.Mininet1.home,
-                                             direction="to")
-            copyResult3 = main.ONOSbench.scp(main.Mininet1,
-                                             main.dependencyPath +
-                                             main.topologyLib2,
-                                             main.Mininet1.home,
-                                             direction="to")
         except:
             pass
 
@@ -144,6 +130,24 @@
 
     @staticmethod
     def startMininet( main, topology, args="" ):
+        try:
+            copyResult1 = main.ONOSbench.scp( main.Mininet1,
+                                              main.dependencyPath +
+                                              main.topology,
+                                              main.Mininet1.home,
+                                              direction="to" )
+            copyResult2 = main.ONOSbench.scp( main.Mininet1,
+                                              main.dependencyPath +
+                                              main.topologyLib1,
+                                              main.Mininet1.home,
+                                              direction="to" )
+            copyResult3 = main.ONOSbench.scp( main.Mininet1,
+                                              main.dependencyPath +
+                                              main.topologyLib2,
+                                              main.Mininet1.home,
+                                              direction="to" )
+        except:
+            pass
         main.step( "Starting Mininet Topology" )
         arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
         main.topology = topology
@@ -264,7 +268,7 @@
             except:
                 expect = main.FALSE
             main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
-            pa = main.Mininet1.pingallHosts( hosts )
+            pa = main.Network.pingallHosts( hosts )
 
             utilities.assert_equals( expect=expect, actual=pa,
                                      onpass="IP connectivity successfully tested",
@@ -288,8 +292,8 @@
         """
         main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
         main.step( "Kill link between %s and %s" % ( end1, end2 ) )
-        LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
-        LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
+        LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
+        LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
         main.log.info(
                 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
         time.sleep( main.linkSleep )
@@ -320,8 +324,8 @@
         count = 0
         while True:
             count += 1
-            main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
-            main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
+            main.Network.link( END1=end1, END2=end2, OPTION="up" )
+            main.Network.link( END2=end1, END1=end2, OPTION="up" )
             main.log.info(
                     "Waiting %s seconds for link up to be discovered" % main.linkSleep )
             time.sleep( main.linkSleep )
@@ -351,7 +355,7 @@
         main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
         main.step( "Kill " + switch )
         main.log.info( "Stopping" + switch )
-        main.Mininet1.switch( SW=switch, OPTION="stop" )
+        main.Network.switch( SW=switch, OPTION="stop" )
         # todo make this repeatable
         main.log.info( "Waiting %s seconds for switch down to be discovered" % (
             main.switchSleep ) )
@@ -375,7 +379,7 @@
         # todo make this repeatable
         main.step( "Recovering " + switch )
         main.log.info( "Starting" + switch )
-        main.Mininet1.switch( SW=switch, OPTION="start" )
+        main.Network.switch( SW=switch, OPTION="start" )
         main.log.info( "Waiting %s seconds for switch up to be discovered" % (
             main.switchSleep ) )
         time.sleep( main.switchSleep )