Refactor single instance packet optical testcases to support new topology
diff --git a/TestON/tests/ProdFunc/ProdFunc.params b/TestON/tests/ProdFunc/ProdFunc.params
index a9b212f..4367bf4 100755
--- a/TestON/tests/ProdFunc/ProdFunc.params
+++ b/TestON/tests/ProdFunc/ProdFunc.params
@@ -38,11 +38,4 @@
         <LinkDiscovery>5</LinkDiscovery>
         <SwitchDiscovery>15</SwitchDiscovery>
     </timers>
-
-    <OPTICAL>
-        <jsonfile> /home/admin/ONOS/tools/test/topos/oe-nonlinear-4.json </jsonfile>
-    </OPTICAL>    
-
-
-
 </PARAMS>
diff --git a/TestON/tests/ProdFunc/ProdFunc.py b/TestON/tests/ProdFunc/ProdFunc.py
index fdba3ad..2cd04c1 100644
--- a/TestON/tests/ProdFunc/ProdFunc.py
+++ b/TestON/tests/ProdFunc/ProdFunc.py
@@ -231,8 +231,8 @@
     def CASE21( self, main ):
         """
             On ONOS bench, run this command:
-             ./~/ONOS/tools/test/bin/onos-topo-cfg
-            which starts the rest and copies the links
+            sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1
+            which spawns packet optical topology and copies the links
             json file to the onos instance.
             Note that in case of Packet Optical, the links are not learnt
             from the topology, instead the links are learnt
@@ -243,18 +243,10 @@
         main.log.report( "_____________________________________________" )
         main.case( "Starting LINC-OE and other components" )
         main.step( "Starting LINC-OE and other components" )
-        startConsoleResult = main.LincOE1.startConsole()
+        appInstallResult = main.ONOS2.featureInstall( "onos-app-optical" )
         opticalMnScript = main.LincOE2.runOpticalMnScript()
-        onosTopoCfgResult = main.ONOSbench.runOnosTopoCfg(
-            instanceName=main.params[ 'CTRL' ][ 'ip1' ],
-            jsonFile=main.params[ 'OPTICAL' ][ 'jsonfile' ] )
 
-        print "start_console_result =", startConsoleResult
-        print "optical_mn_script = ", opticalMnScript
-        print "onos_topo_cfg_result =", onosTopoCfgResult
-
-        case21Result = startConsoleResult and opticalMnScript and \
-            onosTopoCfgResult
+        case21Result = opticalMnScript and appInstallResult
         utilities.assert_equals(
             expect=main.TRUE,
             actual=case21Result,
@@ -263,11 +255,12 @@
 
     def CASE22( self, main ):
         """
-            Curretly we use, 4 linear switch optical topology and
-            2 packet layer mininet switches each with one host.
-            Therefore, the roadmCount variable = 4,
-            packetLayerSWCount variable = 2 and hostCount = 2
-            and this is hardcoded in the testcase. If the topology changes,
+            Curretly we use, 10 optical switches(ROADM's) and
+            6 packet layer mininet switches each with one host.
+            Therefore, the roadmCount variable = 10,
+            packetLayerSWCount variable = 6, hostCount=6 and
+            links=42.
+            All this is hardcoded in the testcase. If the topology changes,
             these hardcoded values need to be changed
         """
         main.log.report(
@@ -291,7 +284,7 @@
                 roadmCount += 1
             elif availability == 'true' and type == 'SWITCH':
                 packetLayerSWCount += 1
-        if roadmCount == 4:
+        if roadmCount == 10:
             print "Number of Optical Switches = %d and is" % roadmCount +\
                   " correctly detected"
             main.log.info(
@@ -307,7 +300,7 @@
                 " and is wrong" )
             opticalSWResult = main.FALSE
 
-        if packetLayerSWCount == 2:
+        if packetLayerSWCount == 6:
             print "Number of Packet layer or mininet Switches = %d "\
                     % packetLayerSWCount + "and is correctly detected"
             main.log.info(
@@ -328,6 +321,16 @@
         linksResult = main.ONOS3.links( jsonFormat=False )
         print "links_result = ", linksResult
         print "_________________________________"
+        linkActiveCount = linksResult.count("state=ACTIVE") 
+        main.log.info( "linkActiveCount = " + str( linkActiveCount ))
+        if linkActiveCount == 42:
+            linkActiveResult = main.TRUE
+            main.log.info(
+                "Number of links in ACTIVE state are correct")
+        else:
+            linkActiveResult = main.FALSE
+            main.log.info(
+                "Number of links in ACTIVE state are wrong")
 
         # NOTE:Since only point intents are added, there is no
         # requirement to discover the hosts
@@ -356,7 +359,8 @@
                             is wrong" )
             hostDiscovery = main.FALSE
         """
-        case22Result = opticalSWResult and packetSWResult
+        case22Result = opticalSWResult and packetSWResult and \
+                        linkActiveResult
         utilities.assert_equals(
             expect=main.TRUE,
             actual=case22Result,
@@ -377,45 +381,45 @@
         main.step( "Adding point intents" )
         ptpIntentResult = main.ONOS3.addPointIntent(
             "of:0000ffffffff0001/1",
-            "of:0000ffffffff0002/1" )
+            "of:0000ffffffff0005/1" )
         if ptpIntentResult == main.TRUE:
             main.ONOS3.intents( jsonFormat=False )
             main.log.info( "Point to point intent install successful" )
 
         ptpIntentResult = main.ONOS3.addPointIntent(
-            "of:0000ffffffff0002/1",
+            "of:0000ffffffff0005/1",
             "of:0000ffffffff0001/1" )
         if ptpIntentResult == main.TRUE:
             main.ONOS3.intents( jsonFormat=False )
             main.log.info( "Point to point intent install successful" )
 
-        time.sleep( 10 )
+        time.sleep( 30 )
         flowHandle = main.ONOS3.flows()
         main.log.info( "flows :" + flowHandle )
 
         # Sleep for 30 seconds to provide time for the intent state to change
-        time.sleep( 30 )
+        time.sleep( 60 )
         intentHandle = main.ONOS3.intents( jsonFormat=False )
         main.log.info( "intents :" + intentHandle )
 
         PingResult = main.TRUE
         count = 1
-        main.log.info( "\n\nh1 is Pinging h2" )
-        ping = main.LincOE2.pingHostOptical( src="h1", target="h2" )
+        main.log.info( "\n\nh1 is Pinging h5" )
+        ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
         # ping = main.LincOE2.pinghost()
         if ping == main.FALSE and count < 5:
             count += 1
             PingResult = main.FALSE
             main.log.info(
-                "Ping between h1 and h2  failed. Making attempt number " +
+                "Ping between h1 and h5  failed. Making attempt number " +
                 str( count ) +
                 " in 2 seconds" )
             time.sleep( 2 )
         elif ping == main.FALSE:
-            main.log.info( "All ping attempts between h1 and h2 have failed" )
+            main.log.info( "All ping attempts between h1 and h5 have failed" )
             PingResult = main.FALSE
         elif ping == main.TRUE:
-            main.log.info( "Ping test between h1 and h2 passed!" )
+            main.log.info( "Ping test between h1 and h5 passed!" )
             PingResult = main.TRUE
         else:
             main.log.info( "Unknown error" )
@@ -443,20 +447,39 @@
         import time
         import json
         """
+            LINC uses its own switch IDs. You can use the following
+            command on the LINC console to find the mapping between 
+            DPIDs and LINC IDs.
+            rp(application:get_all_key(linc)).
+            
             Test Rerouting of Packet Optical by bringing a port down
-            ( port 22 ) of a switch( switchID=1 ), so that link
-            ( between switch1 port22 - switch4-port30 ) is inactive
+            ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ), 
+            so that link
+            ( between switch1 port20 - switch5 port50 ) is inactive
             and do a ping test. If rerouting is successful,
             ping should pass. also check the flows
         """
         main.log.report(
             "This testcase tests rerouting and pings mininet hosts" )
         main.case( "Test rerouting and pings mininet hosts" )
+        main.step( "Attach to the Linc-OE session" )
+        attachConsole = main.LincOE1.attachLincOESession() 
+        print "attachConsole = ", attachConsole
+
         main.step( "Bring a port down and verify the link state" )
-        main.LincOE1.portDown( swId="1", ptId="22" )
+        main.LincOE1.portDown( swId="9", ptId="20" )
         linksNonjson = main.ONOS3.links( jsonFormat=False )
         main.log.info( "links = " + linksNonjson )
 
+        linkInactiveCount = linksNonjson.count("state=INACTIVE")
+        main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
+        if linkInactiveCount == 2:
+            main.log.info(
+                "Number of links in INACTIVE state are correct")
+        else:
+            main.log.info(
+                "Number of links in INACTIVE state are wrong")
+        
         links = main.ONOS3.links()
         main.log.info( "links = " + links )
 
@@ -464,9 +487,9 @@
         linksStateResult = main.FALSE
         for item in linksResult:
             if item[ 'src' ][ 'device' ] == "of:0000ffffffffff01" and item[
-                    'src' ][ 'port' ] == "22":
-                if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff04" and item[
-                        'dst' ][ 'port' ] == "30":
+                    'src' ][ 'port' ] == "20":
+                if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff05" and item[
+                        'dst' ][ 'port' ] == "50":
                     linksState = item[ 'state' ]
                     if linksState == "INACTIVE":
                         main.log.info(
@@ -492,22 +515,22 @@
         main.step( "Verify Rerouting by a ping test" )
         PingResult = main.TRUE
         count = 1
-        main.log.info( "\n\nh1 is Pinging h2" )
-        ping = main.LincOE2.pingHostOptical( src="h1", target="h2" )
+        main.log.info( "\n\nh1 is Pinging h5" )
+        ping = main.LincOE2.pingHostOptical( src="h1", target="h5" )
         # ping = main.LincOE2.pinghost()
         if ping == main.FALSE and count < 5:
             count += 1
             PingResult = main.FALSE
             main.log.info(
-                "Ping between h1 and h2  failed. Making attempt number " +
+                "Ping between h1 and h5  failed. Making attempt number " +
                 str( count ) +
                 " in 2 seconds" )
             time.sleep( 2 )
         elif ping == main.FALSE:
-            main.log.info( "All ping attempts between h1 and h2 have failed" )
+            main.log.info( "All ping attempts between h1 and h5 have failed" )
             PingResult = main.FALSE
         elif ping == main.TRUE:
-            main.log.info( "Ping test between h1 and h2 passed!" )
+            main.log.info( "Ping test between h1 and h5 passed!" )
             PingResult = main.TRUE
         else:
             main.log.info( "Unknown error" )
@@ -768,7 +791,7 @@
 
     def CASE12( self ):
         """
-        Verify the default flows on each switch
+        Verify the default flows on each switch in proactive mode
         """
         main.log.report( "This testcase is verifying num of default" +
                          " flows on each switch" )
@@ -844,11 +867,12 @@
             host2 = "00:00:00:00:00:" + \
                 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
             # NOTE: get host can return None
-            # TODO: handle this
-            host1Id = main.ONOS2.getHost( host1 )[ 'id' ]
-      
-            host2Id = main.ONOS2.getHost( host2 )[ 'id' ]
-            main.ONOS2.addHostIntent( host1Id, host2Id )
+            if host1:
+                host1Id = main.ONOS2.getHost( host1 )[ 'id' ]
+            if host2:
+                host2Id = main.ONOS2.getHost( host2 )[ 'id' ]
+            if host1Id and host2Id:
+                main.ONOS2.addHostIntent( host1Id, host2Id )
 
         time.sleep( 10 )
         hIntents = main.ONOS2.intents( jsonFormat=False )
@@ -1076,8 +1100,8 @@
         main.step( "Determine the current number of switches and links" )
         topologyOutput = main.ONOS2.topology()
         topologyResult = main.ONOS1.getTopology( topologyOutput )
-        activeSwitches = topologyResult[ 'devices' ]
-        links = topologyResult[ 'links' ]
+        activeSwitches = topologyResult[ 'deviceCount' ]
+        links = topologyResult[ 'linkCount' ]
         print "activeSwitches = ", type( activeSwitches )
         print "links = ", type( links )
         main.log.info(
diff --git a/TestON/tests/ProdFunc/ProdFunc.topo b/TestON/tests/ProdFunc/ProdFunc.topo
index 73a0b4f..3f3323e 100755
--- a/TestON/tests/ProdFunc/ProdFunc.topo
+++ b/TestON/tests/ProdFunc/ProdFunc.topo
@@ -69,25 +69,22 @@
         </Mininet2>
 
         <LincOE1>
-            <host>10.128.20.30</host>
+            <host>10.128.10.11</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>LincOEDriver</type>
             <connect_order>7</connect_order>
             <COMPONENTS>
-                <arg1> </arg1>
             </COMPONENTS>
         </LincOE1>
 
         <LincOE2>
-            <host>10.128.20.30</host>
+            <host>10.128.10.11</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>RemoteMininetDriver</type>
             <connect_order>8</connect_order>
             <COMPONENTS>
-                <arg1> sudo python /home/admin/optical.py </arg1>
-                <arg2> </arg2>
             </COMPONENTS>
         </LincOE2>