[ONOS-5760] Add protected intents to FUNCintent

Change-Id: I1f0d5e02fe00de6b3cccb4d333ead09e766df6d8
diff --git a/TestON/tests/FUNC/FUNCintent/FUNCintent.py b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
index 4785200..6297464 100644
--- a/TestON/tests/FUNC/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNC/FUNCintent/FUNCintent.py
@@ -1119,6 +1119,42 @@
                                  actual=testResult,
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString )
+
+        main.step("Protected: Add point intents between h1 and h9")
+        main.assertReturnString = "Assertion Result for protected point intent\n"
+        senders = [
+            {"name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01"}
+        ]
+        recipients = [
+            {"name": "h9", "device": "of:0000000000000006/1", "mac": "00:00:00:00:00:09"}
+        ]
+        testResult = main.FALSE
+        installResult = main.intentFunction.installPointIntent(
+            main,
+            name="Protected",
+            senders=senders,
+            recipients=recipients,
+            protected=True )
+
+        if installResult:
+            testResult = main.intentFunction.testPointIntent(
+                main,
+                name="Protected",
+                intentId=installResult,
+                senders=senders,
+                recipients=recipients,
+                sw1="s5",
+                sw2="s2",
+                protected=True,
+                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( "IPV4_2: Add point intents between h1 and h9" )
         main.assertReturnString = "Assertion Result for IPV4 no mac address point intents\n"
         senders = [
diff --git a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
index 1760324..d8a0e36 100755
--- a/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintent/dependencies/FuncIntentFunction.py
@@ -309,6 +309,7 @@
                         ethType="",
                         bandwidth="",
                         lambdaAlloc=False,
+                        protected=False,
                         ipProto="",
                         ipSrc="",
                         ipDst="",
@@ -397,6 +398,7 @@
                                             ethDst=dstMac,
                                             bandwidth=bandwidth,
                                             lambdaAlloc=lambdaAlloc,
+                                            protected=protected,
                                             ipProto=ipProto,
                                             ipSrc=ipSrc,
                                             ipDst=ipDst,
@@ -423,6 +425,7 @@
                 main.assertReturnString += 'Encapsulation intents check Passed\n'
             else:
                 main.assertReturnString += 'Encapsulation intents check failed\n'
+
         if flowDuration( main ):
             main.assertReturnString += 'Flow duration check Passed\n'
             return intentId
@@ -972,6 +975,7 @@
                      ethType="",
                      bandwidth="",
                      lambdaAlloc=False,
+                     protected=False,
                      ipProto="",
                      ipAddresses="",
                      tcp="",
@@ -1109,6 +1113,21 @@
             main.assertReturnString += 'Link Down Failed\n'
             testResult = main.FALSE
 
+        if protected:
+            # Check Connection
+            if utilities.retry(f=scapyCheckConnection, retValue=main.FALSE,
+                               args=(main, senderNames, recipientNames, vlanId, useTCP) ):
+                main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
+            else:
+                main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
+                testResult = main.FALSE
+
+            if ProtectedIntentCheck( main ):
+                main.assertReturnString += 'Protected Intent Check Passed\n'
+            else:
+                main.assertReturnString += 'Protected Intent Check Failed\n'
+                testResult = main.FALSE
+
         # Check intent state
         if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, [ intentId ] ), sleep=main.checkIntentSleep ):
             main.assertReturnString += 'Link Down Intent State Passed\n'
@@ -1996,4 +2015,11 @@
     if pop == totalflows and push == totalflows:
         return main.TRUE
     else:
-        return main.FALSE
\ No newline at end of file
+        return main.FALSE
+
+def ProtectedIntentCheck( main ):
+    import json
+    intent = main.CLIs[ 0 ].intents( jsonFormat=False )
+    if "Protection" in intent:
+        return main.TRUE
+    return main.FALSE
\ No newline at end of file
diff --git a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
index dcf7425..71bf286 100644
--- a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
+++ b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.py
@@ -1173,6 +1173,39 @@
                                  onpass=main.assertReturnString,
                                  onfail=main.assertReturnString )
 
+        # main.step( "Protected: Add point intents between h1 and h9" )
+        # main.assertReturnString = "Assertion Result for protected point intent\n"
+        # senders = [
+        #     { "name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01" }
+        # ]
+        # recipients = [
+        #     { "name": "h9", "device": "of:0000000000000006/1", "mac": "00:00:00:00:00:09" }
+        # ]
+        # testResult = main.FALSE
+        # installResult = main.intentFunction.installPointIntent(
+        #     main,
+        #     name="Protected",
+        #     senders=senders,
+        #     recipients=recipients,
+        #     protected=True )
+        # 
+        # if installResult:
+        #     testResult = main.intentFunction.testPointIntent(
+        #         main,
+        #         name="Protected",
+        #         intentId=installResult,
+        #         senders=senders,
+        #         recipients=recipients,
+        #         sw1="s5",
+        #         sw2="s2",
+        #         protected=True,
+        #         expectedLink=18 )
+        #
+        # utilities.assert_equals( expect=main.TRUE,
+        #                          actual=testResult,
+        #                          onpass=main.assertReturnString,
+        #                          onfail=main.assertReturnString )
+
         main.step( "IPV4_2: Add point intents between h1 and h9" )
         main.assertReturnString = "Assertion Result for IPV4 no mac address point intents\n"
         senders = [
diff --git a/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py b/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
index 088d38d..8fa65f2 100755
--- a/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
+++ b/TestON/tests/FUNC/FUNCintentRest/dependencies/FuncIntentFunction.py
@@ -305,6 +305,7 @@
                         ethType="",
                         bandwidth="",
                         lambdaAlloc=False,
+                        protected=False,
                         ipProto="",
                         ipSrc="",
                         ipDst="",
@@ -394,6 +395,7 @@
                                             ethDst=dstMac,
                                             bandwidth=bandwidth,
                                             lambdaAlloc=lambdaAlloc,
+                                            protected=protected,
                                             ipProto=ipProto,
                                             ipSrc=ipSrc,
                                             ipDst=ipDst,
@@ -436,6 +438,7 @@
                      ethType="",
                      bandwidth="",
                      lambdaAlloc=False,
+                     protected=False,
                      ipProto="",
                      ipAddresses="",
                      tcp="",
@@ -575,6 +578,21 @@
             main.assertReturnString += 'Link Down Failed\n'
             testResult = main.FALSE
 
+        if protected:
+            # Check Connection
+            if utilities.retry(f=scapyCheckConnection, retValue=main.FALSE,
+                               args=(main, senderNames, recipientNames, vlanId, useTCP)):
+                main.assertReturnString += 'Link down Scapy Packet Received Passed\n'
+            else:
+                main.assertReturnString += 'Link down Scapy Packet Recieved Failed\n'
+                testResult = main.FALSE
+
+            if ProtectedIntentCheck(main):
+                main.assertReturnString += 'Protected Intent Check Passed\n'
+            else:
+                main.assertReturnString += 'Protected Intent Check Failed\n'
+                testResult = main.FALSE
+
         # Check intent state
         if utilities.retry( f=checkIntentState, retValue=main.FALSE, args=( main, intentId ), sleep=main.checkIntentSleep ):
             main.assertReturnString += 'Link Down Intent State Passed\n'
@@ -1731,3 +1749,11 @@
     else:
         return main.FALSE
     return main.TRUE
+
+def ProtectedIntentCheck( main ):
+    intent = main.RESTs[ 0 ].intents()
+    main.log.debug(intent)
+    main.stop()
+    if "Protection" in intent:
+        return main.TRUE
+    return main.FALSE