Add VLAN Treatment Intent Tests to FUNCintent for Host, Point,
MPSP, and SPMP intents.

Change-Id: I49ca2814e6597740e4d2c37ee5451d2a5e147a35
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 0822879..4d8cec7 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -1138,13 +1138,14 @@
             main.cleanup()
             main.exit()
 
-    def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="" ):
+    def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="" ):
         """
         Required:
             * hostIdOne: ONOS host id for host1
             * hostIdTwo: ONOS host id for host2
         Optional:
             * vlanId: specify a VLAN id for the intent
+            * setVlan: specify a VLAN id treatment
         Description:
             Adds a host-to-host intent ( bidirectional ) by
             specifying the two hosts.
@@ -1155,6 +1156,8 @@
             cmdStr = "add-host-intent "
             if vlanId:
                 cmdStr += "-v " + str( vlanId ) + " "
+            if setVlan:
+                cmdStr += "--setVlan " + str( vlanId ) + " "
             cmdStr += str( hostIdOne ) + " " + str( hostIdTwo )
             handle = self.sendline( cmdStr )
             assert "Command not found:" not in handle, handle
@@ -1252,7 +1255,8 @@
             ipDst="",
             tcpSrc="",
             tcpDst="",
-            vlanId="" ):
+            vlanId="",
+            setVlan="" ):
         """
         Required:
             * ingressDevice: device id of ingress device
@@ -1270,6 +1274,7 @@
             * tcpSrc: specify tcp source port
             * tcpDst: specify tcp destination port
             * vlanId: specify vlan ID
+            * setVlan: specify a VLAN id treatment
         Description:
             Adds a point-to-point intent ( uni-directional ) by
             specifying device id's and optional fields
@@ -1281,38 +1286,32 @@
               intent via cli
         """
         try:
-            # If there are no optional arguments
-            if not ethType and not ethSrc and not ethDst\
-                    and not bandwidth and not lambdaAlloc \
-                    and not ipProto and not ipSrc and not ipDst \
-                    and not tcpSrc and not tcpDst:
-                cmd = "add-point-intent"
+            cmd = "add-point-intent"
 
-            else:
-                cmd = "add-point-intent"
-
-                if ethType:
-                    cmd += " --ethType " + str( ethType )
-                if ethSrc:
-                    cmd += " --ethSrc " + str( ethSrc )
-                if ethDst:
-                    cmd += " --ethDst " + str( ethDst )
-                if bandwidth:
-                    cmd += " --bandwidth " + str( bandwidth )
-                if lambdaAlloc:
-                    cmd += " --lambda "
-                if ipProto:
-                    cmd += " --ipProto " + str( ipProto )
-                if ipSrc:
-                    cmd += " --ipSrc " + str( ipSrc )
-                if ipDst:
-                    cmd += " --ipDst " + str( ipDst )
-                if tcpSrc:
-                    cmd += " --tcpSrc " + str( tcpSrc )
-                if tcpDst:
-                    cmd += " --tcpDst " + str( tcpDst )
-                if vlanId:
-                    cmd += " -v " + str( vlanId )
+            if ethType:
+                cmd += " --ethType " + str( ethType )
+            if ethSrc:
+                cmd += " --ethSrc " + str( ethSrc )
+            if ethDst:
+                cmd += " --ethDst " + str( ethDst )
+            if bandwidth:
+                cmd += " --bandwidth " + str( bandwidth )
+            if lambdaAlloc:
+                cmd += " --lambda "
+            if ipProto:
+                cmd += " --ipProto " + str( ipProto )
+            if ipSrc:
+                cmd += " --ipSrc " + str( ipSrc )
+            if ipDst:
+                cmd += " --ipDst " + str( ipDst )
+            if tcpSrc:
+                cmd += " --tcpSrc " + str( tcpSrc )
+            if tcpDst:
+                cmd += " --tcpDst " + str( tcpDst )
+            if vlanId:
+                cmd += " -v " + str( vlanId )
+            if setVlan:
+                cmd += " --setVlan " + str( setVlan )
 
             # Check whether the user appended the port
             # or provided it as an input
@@ -1392,7 +1391,8 @@
             tcpDst="",
             setEthSrc="",
             setEthDst="",
-            vlanId="" ):
+            vlanId="",
+            setVlan="" ):
         """
         Note:
             This function assumes the format of all ingress devices
@@ -1418,6 +1418,7 @@
             * setEthSrc: action to Rewrite Source MAC Address
             * setEthDst: action to Rewrite Destination MAC Address
             * vlanId: specify vlan Id
+            * setVlan: specify VLAN Id treatment
         Description:
             Adds a multipoint-to-singlepoint intent ( uni-directional ) by
             specifying device id's and optional fields
@@ -1429,43 +1430,36 @@
               intent via cli
         """
         try:
-            # If there are no optional arguments
-            if not ethType and not ethSrc and not ethDst\
-                    and not bandwidth and not lambdaAlloc\
-                    and not ipProto and not ipSrc and not ipDst\
-                    and not tcpSrc and not tcpDst and not setEthSrc\
-                    and not setEthDst:
-                cmd = "add-multi-to-single-intent"
+            cmd = "add-multi-to-single-intent"
 
-            else:
-                cmd = "add-multi-to-single-intent"
-
-                if ethType:
-                    cmd += " --ethType " + str( ethType )
-                if ethSrc:
-                    cmd += " --ethSrc " + str( ethSrc )
-                if ethDst:
-                    cmd += " --ethDst " + str( ethDst )
-                if bandwidth:
-                    cmd += " --bandwidth " + str( bandwidth )
-                if lambdaAlloc:
-                    cmd += " --lambda "
-                if ipProto:
-                    cmd += " --ipProto " + str( ipProto )
-                if ipSrc:
-                    cmd += " --ipSrc " + str( ipSrc )
-                if ipDst:
-                    cmd += " --ipDst " + str( ipDst )
-                if tcpSrc:
-                    cmd += " --tcpSrc " + str( tcpSrc )
-                if tcpDst:
-                    cmd += " --tcpDst " + str( tcpDst )
-                if setEthSrc:
-                    cmd += " --setEthSrc " + str( setEthSrc )
-                if setEthDst:
-                    cmd += " --setEthDst " + str( setEthDst )
-                if vlanId:
-                    cmd += " -v " + str( vlanId )
+            if ethType:
+                cmd += " --ethType " + str( ethType )
+            if ethSrc:
+                cmd += " --ethSrc " + str( ethSrc )
+            if ethDst:
+                cmd += " --ethDst " + str( ethDst )
+            if bandwidth:
+                cmd += " --bandwidth " + str( bandwidth )
+            if lambdaAlloc:
+                cmd += " --lambda "
+            if ipProto:
+                cmd += " --ipProto " + str( ipProto )
+            if ipSrc:
+                cmd += " --ipSrc " + str( ipSrc )
+            if ipDst:
+                cmd += " --ipDst " + str( ipDst )
+            if tcpSrc:
+                cmd += " --tcpSrc " + str( tcpSrc )
+            if tcpDst:
+                cmd += " --tcpDst " + str( tcpDst )
+            if setEthSrc:
+                cmd += " --setEthSrc " + str( setEthSrc )
+            if setEthDst:
+                cmd += " --setEthDst " + str( setEthDst )
+            if vlanId:
+                cmd += " -v " + str( vlanId )
+            if setVlan:
+                cmd += " --setVlan " + str( setVlan )
 
             # Check whether the user appended the port
             # or provided it as an input
@@ -1549,7 +1543,8 @@
             tcpDst="",
             setEthSrc="",
             setEthDst="",
-            vlanId="" ):
+            vlanId="",
+            setVlan="" ):
         """
         Note:
             This function assumes the format of all egress devices
@@ -1575,6 +1570,7 @@
             * setEthSrc: action to Rewrite Source MAC Address
             * setEthDst: action to Rewrite Destination MAC Address
             * vlanId: specify vlan Id
+            * setVlan: specify VLAN ID treatment
         Description:
             Adds a singlepoint-to-multipoint intent ( uni-directional ) by
             specifying device id's and optional fields
@@ -1586,43 +1582,36 @@
               intent via cli
         """
         try:
-            # If there are no optional arguments
-            if not ethType and not ethSrc and not ethDst\
-                    and not bandwidth and not lambdaAlloc\
-                    and not ipProto and not ipSrc and not ipDst\
-                    and not tcpSrc and not tcpDst and not setEthSrc\
-                    and not setEthDst:
-                cmd = "add-single-to-multi-intent"
+            cmd = "add-single-to-multi-intent"
 
-            else:
-                cmd = "add-single-to-multi-intent"
-
-                if ethType:
-                    cmd += " --ethType " + str( ethType )
-                if ethSrc:
-                    cmd += " --ethSrc " + str( ethSrc )
-                if ethDst:
-                    cmd += " --ethDst " + str( ethDst )
-                if bandwidth:
-                    cmd += " --bandwidth " + str( bandwidth )
-                if lambdaAlloc:
-                    cmd += " --lambda "
-                if ipProto:
-                    cmd += " --ipProto " + str( ipProto )
-                if ipSrc:
-                    cmd += " --ipSrc " + str( ipSrc )
-                if ipDst:
-                    cmd += " --ipDst " + str( ipDst )
-                if tcpSrc:
-                    cmd += " --tcpSrc " + str( tcpSrc )
-                if tcpDst:
-                    cmd += " --tcpDst " + str( tcpDst )
-                if setEthSrc:
-                    cmd += " --setEthSrc " + str( setEthSrc )
-                if setEthDst:
-                    cmd += " --setEthDst " + str( setEthDst )
-                if vlanId:
-                    cmd += " -v " + str( vlanId )
+            if ethType:
+                cmd += " --ethType " + str( ethType )
+            if ethSrc:
+                cmd += " --ethSrc " + str( ethSrc )
+            if ethDst:
+                cmd += " --ethDst " + str( ethDst )
+            if bandwidth:
+                cmd += " --bandwidth " + str( bandwidth )
+            if lambdaAlloc:
+                cmd += " --lambda "
+            if ipProto:
+                cmd += " --ipProto " + str( ipProto )
+            if ipSrc:
+                cmd += " --ipSrc " + str( ipSrc )
+            if ipDst:
+                cmd += " --ipDst " + str( ipDst )
+            if tcpSrc:
+                cmd += " --tcpSrc " + str( tcpSrc )
+            if tcpDst:
+                cmd += " --tcpDst " + str( tcpDst )
+            if setEthSrc:
+                cmd += " --setEthSrc " + str( setEthSrc )
+            if setEthDst:
+                cmd += " --setEthDst " + str( setEthDst )
+            if vlanId:
+                cmd += " -v " + str( vlanId )
+            if setVlan:
+                cmd += " --setVlan " + str( setVlan )
 
             # Check whether the user appended the port
             # or provided it as an input
@@ -1737,43 +1726,34 @@
               intent via cli
         """
         try:
-            # If there are no optional arguments
-            if not ethType and not ethSrc and not ethDst\
-                    and not bandwidth and not lambdaAlloc \
-                    and not ipProto and not ipSrc and not ipDst \
-                    and not tcpSrc and not tcpDst and not ingressLabel \
-                    and not egressLabel:
-                cmd = "add-mpls-intent"
+            cmd = "add-mpls-intent"
 
-            else:
-                cmd = "add-mpls-intent"
-
-                if ethType:
-                    cmd += " --ethType " + str( ethType )
-                if ethSrc:
-                    cmd += " --ethSrc " + str( ethSrc )
-                if ethDst:
-                    cmd += " --ethDst " + str( ethDst )
-                if bandwidth:
-                    cmd += " --bandwidth " + str( bandwidth )
-                if lambdaAlloc:
-                    cmd += " --lambda "
-                if ipProto:
-                    cmd += " --ipProto " + str( ipProto )
-                if ipSrc:
-                    cmd += " --ipSrc " + str( ipSrc )
-                if ipDst:
-                    cmd += " --ipDst " + str( ipDst )
-                if tcpSrc:
-                    cmd += " --tcpSrc " + str( tcpSrc )
-                if tcpDst:
-                    cmd += " --tcpDst " + str( tcpDst )
-                if ingressLabel:
-                    cmd += " --ingressLabel " + str( ingressLabel )
-                if egressLabel:
-                    cmd += " --egressLabel " + str( egressLabel )
-                if priority:
-                    cmd += " --priority " + str( priority )
+            if ethType:
+                cmd += " --ethType " + str( ethType )
+            if ethSrc:
+                cmd += " --ethSrc " + str( ethSrc )
+            if ethDst:
+                cmd += " --ethDst " + str( ethDst )
+            if bandwidth:
+                cmd += " --bandwidth " + str( bandwidth )
+            if lambdaAlloc:
+                cmd += " --lambda "
+            if ipProto:
+                cmd += " --ipProto " + str( ipProto )
+            if ipSrc:
+                cmd += " --ipSrc " + str( ipSrc )
+            if ipDst:
+                cmd += " --ipDst " + str( ipDst )
+            if tcpSrc:
+                cmd += " --tcpSrc " + str( tcpSrc )
+            if tcpDst:
+                cmd += " --tcpDst " + str( tcpDst )
+            if ingressLabel:
+                cmd += " --ingressLabel " + str( ingressLabel )
+            if egressLabel:
+                cmd += " --egressLabel " + str( egressLabel )
+            if priority:
+                cmd += " --priority " + str( priority )
 
             # Check whether the user appended the port
             # or provided it as an input
diff --git a/TestON/tests/FUNC/FUNCintent/FUNCintent.py b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
index 1bff0f1..1b4afd0 100644
--- a/TestON/tests/FUNC/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
@@ -864,6 +864,36 @@
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString)
 
+        main.step( "VLAN2: Add vlan host intents between h4 and h13" )
+        main.assertReturnString = "Assertion Result vlan IPV4\n"
+        host1 = { "name":"h5", "vlan":"200" }
+        host2 = { "name":"h12", "vlan":"100" }
+        testResult = main.FALSE
+        installResult = main.FALSE
+        installResult = main.intentFunction.installHostIntent( main,
+                                              name='VLAN2',
+                                              onosNode='0',
+                                              host1=host1,
+                                              host2=host2)
+
+        if installResult:
+            testResult = main.intentFunction.testHostIntent( main,
+                                              name='VLAN2',
+                                              intentId = installResult,
+                                              onosNode='0',
+                                              host1=host1,
+                                              host2=host2,
+                                              sw1='s5',
+                                              sw2='s2',
+                                              expectedLink = 18)
+        else:
+            main.CLIs[ 0 ].removeAllIntents( purge=True )
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass=main.assertReturnString,
+                                 onfail=main.assertReturnString)
+
         main.step( "Confirm that ONOS leadership is unchanged")
         intentLeadersNew = main.CLIs[ 0 ].leaderCandidates()
         main.intentFunction.checkLeaderChange( intentLeadersOld,
@@ -1183,6 +1213,39 @@
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString )
 
+        main.step( "VLAN: Add point intents between h5 and h21" )
+        main.assertReturnString = "Assertion Result for VLAN IPV4 point intents with VLAN treatment\n"
+        senders = [
+            { "name":"h4", "vlan":"100" }
+        ]
+        recipients = [
+            { "name":"h21", "vlan":"200" }
+        ]
+        testResult = main.FALSE
+        installResult = main.FALSE
+        installResult = main.intentFunction.installPointIntent(
+                                       main,
+                                       name="VLAN2",
+                                       senders=senders,
+                                       recipients=recipients,
+                                       setVlan=200)
+
+        if installResult:
+            testResult = main.intentFunction.testPointIntent(
+                                         main,
+                                         intentId=installResult,
+                                         name="VLAN2",
+                                         senders=senders,
+                                         recipients=recipients,
+                                         sw1="s5",
+                                         sw2="s2",
+                                         expectedLink=18)
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass=main.assertReturnString,
+                                 onfail=main.assertReturnString )
+
         main.step( "1HOP: Add point intents between h1 and h3" )
         main.assertReturnString = "Assertion Result for 1HOP IPV4 with no mac address point intents\n"
         senders = [
@@ -1441,6 +1504,48 @@
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString )
 
+        main.step( "VLAN: Add single point to multi point intents" )
+        main.assertReturnString = "Assertion results for single to multi point intent with VLAN treatment\n"
+        senders = [
+            { "name":"h5", "vlan":"200" }
+        ]
+        recipients = [
+            { "name":"h12", "device":"of:0000000000000006/4", "mac":"00:00:00:00:00:0C", "vlan":"100" },
+            { "name":"h20", "device":"of:0000000000000007/4", "mac":"00:00:00:00:00:14", "vlan":"100" }
+        ]
+        badSenders=[ { "name":"h13" } ]  # Senders that are not in the intent
+        badRecipients=[ { "name":"h21" } ]  # Recipients that are not in the intent
+        testResult = main.FALSE
+        installResult = main.FALSE
+        installResult = main.intentFunction.installSingleToMultiIntent(
+                                         main,
+                                         name="VLAN2",
+                                         senders=senders,
+                                         recipients=recipients,
+                                         sw1="s5",
+                                         sw2="s2",
+                                         setVlan=100)
+
+        if installResult:
+            testResult = main.intentFunction.testPointIntent(
+                                         main,
+                                         intentId=installResult,
+                                         name="VLAN2",
+                                         senders=senders,
+                                         recipients=recipients,
+                                         badSenders=badSenders,
+                                         badRecipients=badRecipients,
+                                         sw1="s5",
+                                         sw2="s2",
+                                         expectedLink=18)
+        else:
+            main.CLIs[ 0 ].removeAllIntents( purge=True )
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass=main.assertReturnString,
+                                 onfail=main.assertReturnString )
+
         main.intentFunction.report( main )
 
     def CASE4000( self, main ):
@@ -1664,6 +1769,49 @@
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString )
 
+        # Right now this fails because of this bug: https://jira.onosproject.org/browse/ONOS-4383
+        main.step( "VLAN: Add multi point to single point intents" )
+        main.assertReturnString = "Assertion results for multi to single point intent with VLAN ID treatment\n"
+        senders = [
+            { "name":"h13", "device":"of:0000000000000006/5", "vlan":"200" },
+            { "name":"h21", "device":"of:0000000000000007/5", "vlan":"200" }
+        ]
+        recipients = [
+            { "name":"h4", "vlan":"100" }
+        ]
+        badSenders=[ { "name":"h12" } ]  # Senders that are not in the intent
+        badRecipients=[ { "name":"h20" } ]  # Recipients that are not in the intent
+        testResult = main.FALSE
+        installResult = main.FALSE
+        installResult = main.intentFunction.installMultiToSingleIntent(
+                                         main,
+                                         name="VLAN2",
+                                         senders=senders,
+                                         recipients=recipients,
+                                         sw1="s5",
+                                         sw2="s2",
+                                         setVlan=100)
+
+        if installResult:
+            testResult = main.intentFunction.testPointIntent(
+                                         main,
+                                         intentId=installResult,
+                                         name="VLAN2",
+                                         senders=senders,
+                                         recipients=recipients,
+                                         badSenders=badSenders,
+                                         badRecipients=badRecipients,
+                                         sw1="s5",
+                                         sw2="s2",
+                                         expectedLink=18)
+        else:
+            main.CLIs[ 0 ].removeAllIntents( purge=True )
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=testResult,
+                                 onpass=main.assertReturnString,
+                                 onfail=main.assertReturnString )
+
         main.intentFunction.report( main )
 
     def CASE5000( self, main ):
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
index dede2c8..ee0492d 100644
--- a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
@@ -22,7 +22,8 @@
                        ipAddresses="",
                        tcp="",
                        sw1="",
-                       sw2="" ):
+                       sw2="",
+                       setVlan="" ):
     """
     Installs a Host Intent
 
@@ -78,7 +79,8 @@
         vlanId = host1.get( "vlan" )
         intentId = main.CLIs[ onosNode ].addHostIntent( hostIdOne=host1.get( "id" ),
                                                         hostIdTwo=host2.get( "id" ),
-                                                        vlanId=vlanId )
+                                                        vlanId=vlanId,
+                                                        setVlan=setVlan )
     except (KeyError, TypeError):
         errorMsg = "There was a problem loading the hosts data."
         if intentId:
@@ -296,7 +298,8 @@
                         ipSrc="",
                         ipDst="",
                         tcpSrc="",
-                        tcpDst=""):
+                        tcpDst="",
+                        setVlan=""):
     """
     Installs a Single to Single Point Intent
 
@@ -384,7 +387,8 @@
                                             ipDst=ipDst,
                                             tcpSrc=tcpSrc,
                                             tcpDst=tcpDst,
-                                            vlanId=vlanId )
+                                            vlanId=vlanId,
+                                            setVlan=setVlan )
     except (KeyError, TypeError):
         errorMsg = "There was a problem loading the hosts data."
         if intentId:
@@ -694,7 +698,8 @@
                                 ipAddresses="",
                                 tcp="",
                                 sw1="",
-                                sw2=""):
+                                sw2="",
+                                setVlan=""):
     """
     Installs a Single to Multi Point Intent
 
@@ -781,7 +786,8 @@
                                             ipDst="",
                                             tcpSrc="",
                                             tcpDst="",
-                                            vlanId=vlanId )
+                                            vlanId=vlanId,
+                                            setVlan=setVlan )
     except (KeyError, TypeError):
         errorMsg = "There was a problem loading the hosts data."
         if intentId:
@@ -808,7 +814,8 @@
                                 ipAddresses="",
                                 tcp="",
                                 sw1="",
-                                sw2=""):
+                                sw2="",
+                                setVlan=""):
     """
     Installs a Multi to Single Point Intent
 
@@ -894,7 +901,8 @@
                                             ipDst="",
                                             tcpSrc="",
                                             tcpDst="",
-                                            vlanId=vlanId )
+                                            vlanId=vlanId,
+                                            setVlan=setVlan )
     except (KeyError, TypeError):
         errorMsg = "There was a problem loading the hosts data."
         if intentId:
@@ -1592,7 +1600,7 @@
 def checkFlowsState( main ):
 
     main.log.info( itemName + ": Check flows state" )
-    checkFlowsResult = main.CLIs[ 0 ].checkFlowsState()
+    checkFlowsResult = main.CLIs[ 0 ].checkFlowsState( isPENDING=False )
     return checkFlowsResult
 
 def link( main, sw1, sw2, option):