HC2VPP-31: fix vpp-ace translation with no protocol set 22/4622/1
authorMarek Gradzki <[email protected]>
Tue, 10 Jan 2017 08:14:19 +0000 (09:14 +0100)
committerMarek Gradzki <[email protected]>
Tue, 10 Jan 2017 10:49:28 +0000 (10:49 +0000)
Change-Id: I9d319ae3d04d90c7652828b0cb382ad142f9d2b6
Signed-off-by: Marek Gradzki <[email protected]>
(cherry picked from commit 1b7a019ae9ceeddee496b20f83c095ffcb87b6c2)

acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/AceConverter.java
acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducer.java
acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtoPreBindRuleProducerTest.java
acl/acl-impl/src/test/resources/rules/no-protocol-rule.json [new file with mode: 0644]

index 3053fe9..5293b5b 100644 (file)
@@ -75,7 +75,7 @@ public interface AceConverter extends MacIpAceDataExtractor, StandardAceDataExtr
                 .map(ace -> {
                     final VppAce standardAce = fromStandardAce(ace);
 
-                    // pre-bind rule with protocol based attributes
+                    // pre-bind rule with protocol based attributes (if present)
                     AclRule rule = createPreBindRule(standardAce);
 
                     rule.isPermit = standardAction(ace);
index c1f9a40..f5de7e3 100644 (file)
@@ -172,10 +172,23 @@ public interface ProtoPreBindRuleProducer {
         return portNumber.getValue().shortValue();
     }
 
+    /**
+     * Pre-bind rule with protocol based attributes (if present).
+     *
+     * @param vppAce rule to be processed
+     * @return AclRule with protocol filled protocol fields
+     */
     default AclRule createPreBindRule(@Nonnull final VppAce vppAce) {
         AclRule rule = new AclRule();
 
-        rule.proto = protocol(vppAce.getVppAceNodes().getIpProtocol());
+
+        final IpProtocol ipProtocol = vppAce.getVppAceNodes().getIpProtocol();
+        if (ipProtocol == null) {
+            // returns AclRule with rule.proto set to 0 (protocol fields will be ignored by vpp)
+            return rule;
+        }
+
+        rule.proto = protocol(ipProtocol);
 
         switch (rule.proto) {
             case ICMP_INDEX: {
index 8f41003..24de2c9 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.
 
 @RunWith(HoneycombTestRunner.class)
 public class ProtoPreBindRuleProducerTest implements ProtoPreBindRuleProducer, AclTestSchemaContext {
+    private static final byte IGNORE_PROTOCOL = 0;
 
     //TODO - remove after resolving how to address identity from different model in textual yang instance identifier
     private VppAce extractAce(AccessLists accessLists) {
@@ -99,4 +100,11 @@ public class ProtoPreBindRuleProducerTest implements ProtoPreBindRuleProducer, A
         assertEquals(0, icmpRule.tcpFlagsValue);
     }
 
+    @Test
+    public void tesProtocolNotSpecified(@InjectTestData(resourcePath = "/rules/no-protocol-rule.json") AccessLists acls) {
+        final AclRule noProtocolRule = createPreBindRule(extractAce(acls));
+
+        assertEquals(IGNORE_PROTOCOL, noProtocolRule.proto);
+    }
+
 }
\ No newline at end of file
diff --git a/acl/acl-impl/src/test/resources/rules/no-protocol-rule.json b/acl/acl-impl/src/test/resources/rules/no-protocol-rule.json
new file mode 100644 (file)
index 0000000..a022bf0
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "access-lists": {
+    "acl": [
+      {
+        "acl-name": "standard-acl",
+        "acl-type": "vpp-acl:vpp-acl",
+        "access-list-entries": {
+          "ace": [
+            {
+              "rule-name": "no-protocol-rule",
+              "matches": {
+                "vpp-ace-nodes": {
+                  "destination-ipv4-network": "192.168.2.1/32",
+                  "source-ipv4-network": "192.168.2.2/32"
+                }
+              }
+            }
+          ]
+        }
+      }
+    ]
+  }
+}
\ No newline at end of file