ONOS-2397 : Added SDN-IP matching on TCP/ICMP

Change-Id: Ibd943c5903472058d6047a15cb18d9ee97e8a569
diff --git a/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py b/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
index 304ed29..13877b2 100644
--- a/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
+++ b/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
@@ -48,6 +48,9 @@
             host1 - Name of first host
             host2 - Name of second host
         Optional:
+            onosNode - ONOS node to install the intents in main.CLIs[ ]
+                       0 by default so that it will always use the first
+                       ONOS node
             host1Id - ONOS id of the first host eg. 00:00:00:00:00:01/-1
             host2Id - ONOS id of the second host
             mac1 - Mac address of first host
@@ -258,6 +261,9 @@
             host1 - Name of first host
             host2 - Name of second host
         Optional:
+            onosNode - ONOS node to install the intents in main.CLIs[ ]
+                       0 by default so that it will always use the first
+                       ONOS node
             deviceId1 - ONOS device id of the first switch, the same as the
                         location of the first host eg. of:0000000000000001/1,
                         located at device 1 port 1
@@ -473,6 +479,9 @@
             name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
             hostNames - List of host names
         Optional:
+            onosNode - ONOS node to install the intents in main.CLIs[ ]
+                       0 by default so that it will always use the first
+                       ONOS node
             devices - List of device ids in the same order as the hosts
                       in hostNames
             ports - List of port numbers in the same order as the device in
@@ -722,6 +731,9 @@
             name - Type of point intent to add eg. IPV4 | VLAN | Dualstack
             hostNames - List of host names
         Optional:
+            onosNode - ONOS node to install the intents in main.CLIs[ ]
+                       0 by default so that it will always use the first
+                       ONOS node
             devices - List of device ids in the same order as the hosts
                       in hostNames
             ports - List of port numbers in the same order as the device in
diff --git a/TestON/tests/FUNCintent/FUNCintent.params b/TestON/tests/FUNCintent/FUNCintent.params
index e1021d3..1daba68 100644
--- a/TestON/tests/FUNCintent/FUNCintent.params
+++ b/TestON/tests/FUNCintent/FUNCintent.params
@@ -1,6 +1,6 @@
 <PARAMS>
 
-    <testcases>1,2,11,12,13,1001,1002,1003,1004</testcases>
+    <testcases>1,2,11,12,13,1000,2000,3000,4000</testcases>
 
     <SCALE>
         <size>1,3</size>
@@ -32,4 +32,12 @@
         <links>20</links>
     </MININET>
 
+    # Intent tests params
+    <SDNIP>
+        <tcpProto>6</tcpProto>
+        <icmpProto>1</icmpProto>
+        <srcPort>5001</srcPort>
+        <dstPort>5001</dstPort>
+    </SDNIP>
+
 </PARAMS>
diff --git a/TestON/tests/FUNCintent/FUNCintent.py b/TestON/tests/FUNCintent/FUNCintent.py
index 0a8092f..1e10db3 100644
--- a/TestON/tests/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNCintent/FUNCintent.py
@@ -316,7 +316,7 @@
             main.cleanup()
             main.exit()
 
-    def CASE1001( self, main ):
+    def CASE1000( self, main ):
         """
             Add host intents between 2 host:
                 - Discover hosts
@@ -349,8 +349,8 @@
 
         main.case( "Add host intents between 2 host" )
 
-        stepResult = main.TRUE
         main.step( "IPV4: Add host intents between h1 and h9" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               onosNode='0',
                                               name='IPV4',
@@ -367,8 +367,8 @@
                                  onpass="IPV4: Add host intent successful",
                                  onfail="IPV4: Add host intent failed" )
 
-        stepResult = main.TRUE
         main.step( "DUALSTACK1: Add host intents between h3 and h11" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='DUALSTACK',
                                               host1='h3',
@@ -385,8 +385,8 @@
                                         " successful",
                                  onfail="DUALSTACK1: Add host intent failed" )
 
-        stepResult = main.TRUE
         main.step( "DUALSTACK2: Add host intents between h1 and h11" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='DUALSTACK2',
                                               host1='h1',
@@ -401,8 +401,8 @@
                                         " successful",
                                  onfail="DUALSTACK2: Add host intent failed" )
 
-        stepResult = main.TRUE
         main.step( "1HOP: Add host intents between h1 and h3" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='1HOP',
                                               host1='h1',
@@ -414,8 +414,8 @@
                                         " successful",
                                  onfail="1HOP: Add host intent failed" )
 
-        stepResult = main.TRUE
         main.step( "VLAN1: Add vlan host intents between h4 and h12" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='VLAN1',
                                               host1='h4',
@@ -432,8 +432,8 @@
                                         " intent successful",
                                  onfail="VLAN1: Add vlan host intent failed" )
 
-        stepResult = main.TRUE
         main.step( "VLAN2: Add inter vlan host intents between h13 and h20" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='VLAN2',
                                               host1='h13',
@@ -446,7 +446,7 @@
                                  onfail="VLAN2: Add inter vlan host" +
                                         " intent failed" )
 
-    def CASE1002( self, main ):
+    def CASE2000( self, main ):
         """
             Add point intents between 2 hosts:
                 - Get device ids | ports
@@ -479,9 +479,9 @@
 
         main.case( "Add point intents between 2 devices" )
 
-        stepResult = main.TRUE
         # No option point intents
         main.step( "NOOPTION: Add point intents between h1 and h9" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.pointIntent(
                                        main,
                                        name="NOOPTION",
@@ -493,13 +493,13 @@
                                        sw2="s2",
                                        expectedLink=18 )
 
-        stepResult = main.TRUE
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
                                  onpass="NOOPTION: Add point intent successful",
                                  onfail="NOOPTION: Add point intent failed" )
 
         stepResult = main.TRUE
+        main.step( "IPV4: Add point intents between h1 and h9" )
         stepResult = main.intentFunction.pointIntent(
                                        main,
                                        name="IPV4",
@@ -528,6 +528,7 @@
                                  onpass="IPV4: Add point intent successful",
                                  onfail="IPV4: Add point intent failed" )
 
+        main.step( "IPV4_2: Add point intents between h1 and h9" )
         stepResult = main.TRUE
         stepResult = main.intentFunction.pointIntent(
                                        main,
@@ -536,7 +537,7 @@
                                        host2="h9",
                                        deviceId1="of:0000000000000005/1",
                                        deviceId2="of:0000000000000006/1",
-                                       ipProto=1,
+                                       ipProto="",
                                        ip1="",
                                        ip2="",
                                        tcp1="",
@@ -550,8 +551,66 @@
                                  onpass="IPV4_2: Add point intent successful",
                                  onfail="IPV4_2: Add point intent failed" )
 
+        main.step( "SDNIP-TCP: Add point intents between h1 and h9" )
         stepResult = main.TRUE
+        mac1 = main.hostsData[ 'h1' ][ 'mac' ]
+        mac2 = main.hostsData[ 'h9' ][ 'mac' ]
+        ip1 = str( main.hostsData[ 'h1' ][ 'ipAddresses' ][ 0 ] ) + "/24"
+        ip2 = str( main.hostsData[ 'h9' ][ 'ipAddresses' ][ 0 ] ) + "/24"
+        ipProto = main.params[ 'SDNIP' ][ 'icmpProto' ]
+        tcp1 = main.params[ 'SDNIP' ][ 'srcPort' ]
+        tcp2 = main.params[ 'SDNIP' ][ 'dstPort' ]
+
+        stepResult = main.intentFunction.pointIntent(
+                                           main,
+                                           name="SDNIP-TCP",
+                                           host1="h1",
+                                           host2="h9",
+                                           deviceId1="of:0000000000000005/1",
+                                           deviceId2="of:0000000000000006/1",
+                                           mac1=mac1,
+                                           mac2=mac2,
+                                           ethType="IPV4",
+                                           ipProto=ipProto,
+                                           ip1=ip1,
+                                           ip2=ip2,
+                                           tcp1=tcp1,
+                                           tcp2=tcp2 )
+
+        utilities.assert_equals( expect=main.TRUE,
+                             actual=stepResult,
+                             onpass="SDNIP-TCP: Add point intent successful",
+                             onfail="SDNIP-TCP: Add point intent failed" )
+
+        main.step( "SDNIP-ICMP: Add point intents between h1 and h9" )
+        stepResult = main.TRUE
+        mac1 = main.hostsData[ 'h1' ][ 'mac' ]
+        mac2 = main.hostsData[ 'h9' ][ 'mac' ]
+        ip1 = str( main.hostsData[ 'h1' ][ 'ipAddresses' ][ 0 ] ) + "/24"
+        ip2 = str( main.hostsData[ 'h9' ][ 'ipAddresses' ][ 0 ] ) + "/24"
+        ipProto = main.params[ 'SDNIP' ][ 'tcpProto' ]
+        tcp1 = main.params[ 'SDNIP' ][ 'srcPort' ]
+        tcp2 = main.params[ 'SDNIP' ][ 'dstPort' ]
+
+        stepResult = main.intentFunction.pointIntent(
+                                           main,
+                                           name="SDNIP-ICMP",
+                                           host1="h1",
+                                           host2="h9",
+                                           deviceId1="of:0000000000000005/1",
+                                           deviceId2="of:0000000000000006/1",
+                                           mac1=mac1,
+                                           mac2=mac2,
+                                           ethType="IPV4",
+                                           ipProto=ipProto )
+
+        utilities.assert_equals( expect=main.TRUE,
+                             actual=stepResult,
+                             onpass="SDNIP-ICMP: Add point intent successful",
+                             onfail="SDNIP-ICMP: Add point intent failed" )
+
         main.step( "DUALSTACK1: Add point intents between h1 and h9" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.pointIntent(
                                        main,
                                        name="DUALSTACK1",
@@ -580,8 +639,9 @@
                                  onpass="DUALSTACK1: Add point intent" +
                                         " successful",
                                  onfail="DUALSTACK1: Add point intent failed" ) 
-        stepResult = main.TRUE
+
         main.step( "VLAN: Add point intents between h5 and h21" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.pointIntent(
                                        main,
                                        name="VLAN",
@@ -610,8 +670,8 @@
                                  onpass="VLAN: Add point intent successful",
                                  onfail="VLAN: Add point intent failed" )
 
-        stepResult = main.TRUE
         main.step( "1HOP: Add point intents between h1 and h3" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.hostIntent( main,
                                               name='1HOP',
                                               host1='h1',
@@ -623,7 +683,7 @@
                                         " successful",
                                  onfail="1HOP: Add point intent failed" )
 
-    def CASE1003( self, main ):
+    def CASE3000( self, main ):
         """
             Add single point to multi point intents
                 - Get device ids
@@ -650,13 +710,12 @@
 
         main.case( "Add single point to multi point intents between devices" )
 
+        main.step( "NOOPTION: Add single point to multi point intents" )
         stepResult = main.TRUE
         hostNames = [ 'h8', 'h16', 'h24' ]
         devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
                     'of:0000000000000007/8' ]
         macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
-
-        main.step( "NOOPTION: Add single point to multi point intents" )
         stepResult = main.intentFunction.singleToMultiIntent(
                                          main,
                                          name="NOOPTION",
@@ -673,8 +732,8 @@
                                  onfail="NOOPTION: Failed to add single point" +
                                         " to multi point intents" )
 
-        stepResult = main.TRUE
         main.step( "IPV4: Add single point to multi point intents" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.singleToMultiIntent(
                                          main,
                                          name="IPV4",
@@ -699,8 +758,8 @@
                                  onfail="IPV4: Failed to add single point" +
                                         " to multi point intents" )
 
-        stepResult = main.TRUE
         main.step( "IPV4_2: Add single point to multi point intents" )
+        stepResult = main.TRUE
         hostNames = [ 'h8', 'h16', 'h24' ]
         stepResult = main.intentFunction.singleToMultiIntent(
                                          main,
@@ -715,8 +774,9 @@
                                         + " point to multi point intents",
                                  onfail="IPV4_2: Failed to add single point" +
                                         " to multi point intents" )
-        stepResult = main.TRUE
+
         main.step( "VLAN: Add single point to multi point intents" )
+        stepResult = main.TRUE
         hostNames = [ 'h4', 'h12', 'h20' ]
         devices = [ 'of:0000000000000005/4', 'of:0000000000000006/4', \
                     'of:0000000000000007/4' ]
@@ -745,7 +805,7 @@
                                  onfail="VLAN: Failed to add single point" +
                                         " to multi point intents" ) 
 
-    def CASE1004( self, main ):
+    def CASE4000( self, main ):
         """
             Add multi point to single point intents
                 - Get device ids
@@ -772,13 +832,12 @@
 
         main.case( "Add multi point to single point intents between devices" )
 
+        main.step( "NOOPTION: Add multi point to single point intents" )
         stepResult = main.TRUE
         hostNames = [ 'h8', 'h16', 'h24' ]
         devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
                     'of:0000000000000007/8' ]
         macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
-
-        main.step( "NOOPTION: Add multi point to single point intents" )
         stepResult = main.intentFunction.multiToSingleIntent(
                                          main,
                                          name="NOOPTION",
@@ -795,8 +854,8 @@
                                  onfail="NOOPTION: Failed to add multi point" +
                                         " to single point intents" )
 
-        stepResult = main.TRUE
         main.step( "IPV4: Add multi point to single point intents" )
+        stepResult = main.TRUE
         stepResult = main.intentFunction.multiToSingleIntent(
                                          main,
                                          name="IPV4",
@@ -821,8 +880,8 @@
                                  onfail="IPV4: Failed to add multi point" +
                                         " to single point intents" )
 
-        stepResult = main.TRUE
         main.step( "IPV4_2: Add multi point to single point intents" )
+        stepResult = main.TRUE
         hostNames = [ 'h8', 'h16', 'h24' ]
         stepResult = main.intentFunction.multiToSingleIntent(
                                          main,
@@ -838,8 +897,8 @@
                                  onfail="IPV4_2: Failed to add multi point" +
                                         " to single point intents" )
 
-        stepResult = main.TRUE
         main.step( "VLAN: Add multi point to single point intents" )
+        stepResult = main.TRUE
         hostNames = [ 'h5', 'h13', 'h21' ]
         devices = [ 'of:0000000000000005/5', 'of:0000000000000006/5', \
                     'of:0000000000000007/5' ]
diff --git a/TestON/tests/FUNCintent/README b/TestON/tests/FUNCintent/README
new file mode 100644
index 0000000..ce4e99f
--- /dev/null
+++ b/TestON/tests/FUNCintent/README
@@ -0,0 +1,39 @@
+Summary:
+        This test suite consist of basic intent functionality testing.
+        The following is an overview of how host intents is being tested.
+        Steps:
+            - Discover hosts
+            - Add host intents
+            - Check intents
+            - Verify flows
+            - Ping hosts
+            - Reroute
+                - Link down
+                - Verify flows
+                - Check topology
+                - Ping hosts
+                - Link up
+                - Verify flows
+                - Check topology
+                - Ping hosts
+            - Remove intents
+        This test suite includes testing of different types of intents such as
+        host, point, single-to-multi and multi-to-single ( More intent types to
+        add later ). The same steps above is being performed to other type of
+        intents.
+
+Required:
+        This test requires Mininet topology file newFuncIntent.py that is in the
+        Dependency folder. You should run the topology file to check for any
+        missing packages. The mininet topology file has different type of hosts
+        including VLAN hosts. Therefore you need to install VLAN module to build
+        the topology correctly.
+
+VLAN configuration:
+        Execute command:
+            $ sudo apt-get install vlan
+        Configuration:
+            $ sudo modprobe 8021q
+        NOTE:To make this configuration permanent
+            $ sudo su -c 'echo "8021q" >> /etc/modules'
+