Update Cluster Driver

Change-Id: I8a3a57e19637ff210548e57d41178e6f194cf694
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
index 83dbcb7..63940cb 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.py
@@ -53,7 +53,8 @@
         swResult = main.TRUE
         for i in range ( 1, int( main.params['config']['switchNum'] ) + 1 ):
             sw = "sw%s" % ( i )
-            swResult = swResult and main.Mininet.assignSwController( sw, main.ONOSip )
+            swResult = swResult and \
+                       main.Mininet.assignSwController( sw, main.Cluster.getIps() )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=swResult,
                                  onpass="Successfully connect all switches to ONOS",
@@ -102,13 +103,13 @@
         time.sleep( int( main.params['timers']['TopoDiscovery'] ) )
 
         main.step( "Get links in the network" )
-        summaryResult = main.ONOScli1.summary()
+        summaryResult = main.Cluster.active( 0 ).CLI.summary()
         linkNum = json.loads( summaryResult )[ "links" ]
         main.log.info( "Expected 100 links, actual number is: {}".format( linkNum ) )
         if linkNum < 100:
             main.log.error( "Link number is wrong! Retrying..." )
             time.sleep( int( main.params['timers']['TopoDiscovery'] ) )
-            summaryResult = main.ONOScli1.summary()
+            summaryResult = main.Cluster.active( 0 ).CLI.summary()
             linkNum = json.loads( summaryResult )[ "links" ]
         main.log.info( "Expected 100 links, actual number is: {}".format( linkNum ) )
         utilities.assert_equals( expect=100,
@@ -120,7 +121,7 @@
             main.exit()
 
         main.step( "Activate sdn-ip application" )
-        activeSDNIPresult = main.ONOScli1.activateApp( "org.onosproject.sdnip" )
+        activeSDNIPresult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.sdnip" )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=activeSDNIPresult,
                                  onpass="Activate SDN-IP succeeded",
@@ -144,8 +145,11 @@
                                           wrapperFile1 +
                                           ".py" )
         # Create tunnels
-        for i in range ( len( main.ONOSip ) ):
-            main.Functions.setupTunnel( main, '1.1.1.' + str( ( i + 1 ) * 2 ), 2000, main.ONOSip[ i ], 2000 )
+        for i in range ( main.Cluster.numCtrls ):
+            main.Functions.setupTunnel( main,
+                                        '1.1.1.' + str( ( i + 1 ) * 2 ),
+                                        2000,
+                                        main.Cluster.active( i ).ipAddress, 2000 )
 
         main.log.info( "Wait SDN-IP to finish installing connectivity intents \
         and the BGP paths in data plane are ready..." )
@@ -305,7 +309,7 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -328,7 +332,7 @@
                                  onpass="Starting switch succeeded!",
                                  onfail="Starting switch failed!" )
 
-        result2 = main.Mininet.assignSwController( "sw32", main.ONOSip[ 0 ] )
+        result2 = main.Mininet.assignSwController( "sw32", main.Cluster.active( 0 ).ipAddress )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=result2,
                                  onpass="Connect switch to ONOS succeeded!",
@@ -345,7 +349,7 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -400,7 +404,7 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -439,7 +443,7 @@
         utilities.assert_equals( expect=main.TRUE, actual=result1,
                                  onpass="Starting switch succeeded!",
                                  onfail="Starting switch failed!" )
-        result2 = main.Mininet.assignSwController( "sw11", main.ONOSip[ 0 ] )
+        result2 = main.Mininet.assignSwController( "sw11", main.Cluster.active( 0 ).ipAddress )
         utilities.assert_equals( expect=main.TRUE, actual=result2,
                                  onpass="Connect switch to ONOS succeeded!",
                                  onfail="Connect switch to ONOS failed!" )
@@ -458,7 +462,7 @@
             main.exit()
 
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -487,7 +491,7 @@
         main.Functions.checkM2SintentNum( main, 7 )
         main.Functions.checkP2PintentNum( main, 30 * 2 )
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -537,7 +541,7 @@
         main.Functions.checkP2PintentNum( main, 30 * 2 )
 
         main.step( "Check whether all flow status are ADDED" )
-        flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+        flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                      main.FALSE,
                                      kwargs={'isPENDING':False},
                                      attempts=10 )
@@ -565,7 +569,7 @@
         main.case( "Bring down leader ONOS node, check: \
         route number, P2P intent number, M2S intent number, ping test" )
         main.step( "Find out ONOS leader node" )
-        result = main.ONOScli1.leaders()
+        result = main.Cluster.active( 0 ).CLI.leaders()
         jsonResult = json.loads( result )
         leaderIP = ""
         for entry in jsonResult:
@@ -575,7 +579,7 @@
                 main.log.info( leaderIP )
 
         main.step( "Uninstall ONOS/SDN-IP leader node" )
-        for ip in main.ONOSip:
+        for ip in main.Cluster.getIps():
             if leaderIP == ip:
                 uninstallResult = main.ONOSbench.onosStop( ip )
 
@@ -588,13 +592,13 @@
             main.exit()
         time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
 
-        if leaderIP == main.ONOSip[ 0 ]:
-            main.Functions.checkRouteNum( main, 7, ONOScli="ONOScli2" )
-            main.Functions.checkM2SintentNum( main, 7, ONOScli="ONOScli2" )
-            main.Functions.checkP2PintentNum( main, 30 * 2, ONOScli="ONOScli2" )
+        if leaderIP == main.Cluster.active( 0 ).ipAddress:
+            main.Functions.checkRouteNum( main, 7, node=2 )
+            main.Functions.checkM2SintentNum( main, 7, node=2 )
+            main.Functions.checkP2PintentNum( main, 30 * 2, node=2 )
 
             main.step( "Check whether all flow status are ADDED" )
-            flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+            flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                          main.FALSE,
                                          kwargs={'isPENDING':False},
                                          attempts=10 )
@@ -608,7 +612,7 @@
             main.Functions.checkP2PintentNum( main, 30 * 2 )
 
             main.step( "Check whether all flow status are ADDED" )
-            flowCheck = utilities.retry( main.ONOScli1.checkFlowsState,
+            flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
                                          main.FALSE,
                                          kwargs={'isPENDING':False},
                                          attempts=10 )
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.topo b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.topo
index a666721..46a573a 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.topo
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/USECASE_SdnipFunctionCluster.topo
@@ -1,56 +1,32 @@
 <TOPOLOGY>
     <COMPONENT>
 
-        <ONOSbench>
-            <host>127.0.0.1</host>
+        <ONOScell>
+            <host>localhost</host>  # ONOS "bench" machine
             <user>sdn</user>
             <password>rocks</password>
-            <type>OnosDriver</type>
+            <type>OnosClusterDriver</type>
             <connect_order>1</connect_order>
             <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOSbench>
-
-        <ONOScli1>
-            <host>127.0.0.1</host>
-            <user>sdn</user>
-            <password>rocks</password>
-            <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
-            <COMPONENTS>
+                <cluster_name></cluster_name>  # Used as a prefix for cluster components. Defaults to 'ONOS'
+                <diff_clihost></diff_clihost> # if it has different host other than localhost for CLI. True or empty. OC# will be used if True.
                 <karaf_username></karaf_username>
                 <karaf_password></karaf_password>
-                <prompt></prompt>
+                <web_user></web_user>
+                <web_pass></web_pass>
+                <rest_port></rest_port>
+                <prompt></prompt>  # TODO: we technically need a few of these, one per component
+                <onos_home></onos_home>  # defines where onos home is
+                <nodes> 3 </nodes>  # number of nodes in the cluster
             </COMPONENTS>
-        </ONOScli1>
-        <ONOScli2>
-            <host>127.0.0.1</host>
-            <user>sdn</user>
-            <password>rocks</password>
-            <type>OnosCliDriver</type>
-            <connect_order>3</connect_order>
-            <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOScli2>
-        <ONOScli3>
-            <host>127.0.0.1</host>
-            <user>sdn</user>
-            <password>rocks</password>
-            <type>OnosCliDriver</type>
-            <connect_order>3</connect_order>
-            <COMPONENTS>
-                <prompt></prompt>
-            </COMPONENTS>
-        </ONOScli3>
+        </ONOScell>
 
         <QuaggaCliSpeaker1>
             <host>127.0.0.1</host>
             <user>sdn</user>
             <password>rocks</password>
             <type>QuaggaCliDriver</type>
-            <connect_order>4</connect_order>
+            <connect_order>2</connect_order>
             <COMPONENTS>
                 <prompt></prompt>
             </COMPONENTS>
@@ -61,7 +37,7 @@
             <user>sdn</user>
             <password>rocks</password>
             <type>MininetCliDriver</type>
-            <connect_order>5</connect_order>
+            <connect_order>3</connect_order>
             <COMPONENTS>
                 <home>~/Mininet/mininet/custom/</home>
                 <prompt></prompt>
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
index f291195..3a042a5 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
@@ -19,7 +19,7 @@
     along with TestON.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ):
+def checkRouteNum( main, routeNumExpected, node=1 ):
     import time
     main.step( "Check routes installed" )
     wait = int( main.params['timers']['PathAvailable'] )
@@ -27,10 +27,7 @@
     main.log.info( routeNumExpected )
     main.log.info( "Route number from ONOS CLI:" )
 
-    if ONOScli == "ONOScli1":
-        cli = main.ONOScli1
-    else:
-        cli = main.ONOScli2
+    cli = main.Cluster.active( node - 1 ).CLI
     routeNumActual = cli.ipv4RouteNumber()
     if routeNumActual != routeNumExpected:
         time.sleep( wait )
@@ -42,17 +39,14 @@
         onpass = "Route number is correct!",
         onfail = "Route number is wrong!" )
 
-def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
+def checkM2SintentNum( main, intentNumExpected, node=1 ):
     import time
     main.step( "Check M2S intents installed" )
     wait = int( main.params['timers']['PathAvailable'] )
     main.log.info( "Intent number expected:" )
     main.log.info( intentNumExpected )
     main.log.info( "Intent number from ONOS CLI:" )
-    if ONOScli == "ONOScli1":
-        cli = main.ONOScli1
-    else:
-        cli = main.ONOScli2
+    cli = main.Cluster.active( node - 1 ).CLI
     jsonResult = cli.intents( jsonFormat = True, summary = True,
                               TYPE = "multiPointToSinglePoint" )
     intentNumActual = jsonResult['installed']
@@ -67,17 +61,14 @@
         onpass = "M2S intent number is correct!",
         onfail = "M2S intent number is wrong!" )
 
-def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
+def checkP2PintentNum( main, intentNumExpected, node=1 ):
     import time
     main.step( "Check P2P intents installed" )
     wait = int( main.params['timers']['PathAvailable'] )
     main.log.info( "Intent number expected:" )
     main.log.info( intentNumExpected )
     main.log.info( "Intent number from ONOS CLI:" )
-    if ONOScli == "ONOScli1":
-        cli = main.ONOScli1
-    else:
-        cli = main.ONOScli2
+    cli = main.Cluster.active( node - 1 ).CLI
     jsonResult = cli.intents( jsonFormat = True, summary = True,
                               TYPE = "pointToPoint" )
     intentNumActual = jsonResult['installed']