summaryrefslogtreecommitdiffstats
path: root/acl/acl-impl/src/test/java
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-01-11 18:27:43 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-01-16 11:15:21 +0000
commit3d4bfd545b1ea1f64b5aa32af80061002176f5d0 (patch)
tree94326a0fc73e80cefec12e334d0e558a3b3f9ce3 /acl/acl-impl/src/test/java
parentc4fb60c6d78c2b686650733488690d164e3b0e15 (diff)
HC2VPP-38 / HONEYCOMB-336 - removed mandatory from ace-ip-version
Removed mandatory statements Fixed multiple NPE Change-Id: I30af417b0594d9634a9352f7721285257fbcee1e Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'acl/acl-impl/src/test/java')
-rw-r--r--acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/AceDataExtractorTestCase.java50
-rw-r--r--acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractorTest.java218
-rw-r--r--acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractorTest.java252
3 files changed, 520 insertions, 0 deletions
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/AceDataExtractorTestCase.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/AceDataExtractorTestCase.java
new file mode 100644
index 000000000..fc925c992
--- /dev/null
+++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/AceDataExtractorTestCase.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.acl.util.ace.extractor;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+
+abstract class AceDataExtractorTestCase {
+
+ protected static final byte[] DEFAULT_MAC_ADDRESS_BYTES = new byte[]{0, 0, 0, 0, 0, 0};
+ protected static final MacAddress DEFAULT_MAC_ADDRESS = new MacAddress("00:00:00:00:00:00");
+ protected static final MacAddress DEFAULT_MAC_MASK_ADDRESS = new MacAddress("00:00:00:00:00:00");
+ protected static final MacAddress MAC_ADDRESS = new MacAddress("00:11:11:00:11:11");
+ protected static final MacAddress MAC_ADDRESS_MASK = new MacAddress("00:11:00:11:11:11");
+ protected static final byte[] MAC_ADDRESS_BYTES = {0, 17, 17, 0, 17, 17};
+ protected static final byte[] MAC_ADDRESS_MASK_BYTES = {0, 17, 0, 17, 17, 17};
+
+ protected static final byte[] DEFAULT_IPV4_ADDRESS_BYTES = new byte[4];
+ protected static final Ipv4Prefix IPV4_PREFIX = new Ipv4Prefix("192.168.2.1/32");
+ protected static final Ipv4Prefix IPV4_2_PREFIX = new Ipv4Prefix("192.168.2.2/24");
+ protected static final byte[] IPV4_PREFIX_BYTES = {-64, -88, 2, 1};
+ protected static final byte[] IPV4_2_PREFIX_BYTES = {-64, -88, 2, 2};
+ protected static final byte IPV4_PREFIX_VALUE = (byte) 32;
+ protected static final byte IPV4_2_PREFIX_VALUE = (byte) 24;
+ protected static final int DEFAULT_IPV4_PREFIX_VALUE = 0;
+
+ protected static final byte[] DEFAULT_IPV6_ADDRESS_BYTES = new byte[16];
+ protected static final Ipv6Prefix IPV6_PREFIX = new Ipv6Prefix("2001:db8:a0b:12f0:0:0:0:1/64");
+ protected static final Ipv6Prefix IPV6_2_PREFIX = new Ipv6Prefix("2001:db8:a0b:12f0:0:0:0:2/48");
+ protected static final byte[] IPV6_PREFIX_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
+ protected static final byte[] IPV6_2_PREFIX_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2};
+ protected static final byte IPV6_PREFIX_VALUE = (byte) 64;
+ protected static final byte IPV6_2_PREFIX_VALUE = (byte) 48;
+ protected static final int DEFAULT_IPV6_PREFIX_VALUE = 0;
+}
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractorTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractorTest.java
new file mode 100644
index 000000000..5eb733c1e
--- /dev/null
+++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractorTest.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.acl.util.ace.extractor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import io.fd.hc2vpp.common.test.util.CommonTests;
+import io.fd.vpp.jvpp.acl.types.MacipAclRule;
+import java.util.Arrays;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.ActionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.MatchesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.PermitBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.VppMacipAceNodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.AceIpVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6Builder;
+
+public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implements MacIpAceDataExtractor, CommonTests {
+
+ @Test
+ public void testFromMacIpAce() {
+ verifyExceptionalCase(() -> fromMacIpAce(new AceBuilder().build()), IllegalArgumentException.class);
+ verifyExceptionalCase(() -> fromMacIpAce(new AceBuilder().setMatches(new MatchesBuilder().build()).build()),
+ IllegalArgumentException.class);
+
+ final VppMacipAce macipAce = new VppMacipAceBuilder().build();
+ assertEquals(macipAce, fromMacIpAce(new AceBuilder().setMatches(new MatchesBuilder()
+ .setAceType(macipAce).build()).build()));
+ }
+
+ @Test
+ public void testMacIpIsIpv6() {
+ assertFalse(macIpIsIpv6(new VppMacipAceBuilder().build()));
+ assertFalse(macIpIsIpv6(
+ new VppMacipAceBuilder().setVppMacipAceNodes(new VppMacipAceNodesBuilder().build()).build()));
+ assertFalse(macIpIsIpv6(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build()));
+ assertTrue(macIpIsIpv6(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build()));
+ }
+
+ @Test
+ public void testSourceMacAsBytes() {
+ assertTrue(Arrays.equals(DEFAULT_MAC_ADDRESS_BYTES, sourceMacAsBytes(new VppMacipAceBuilder().build())));
+ assertTrue(
+ Arrays.equals(DEFAULT_MAC_ADDRESS_BYTES, sourceMacAsBytes(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(MAC_ADDRESS_BYTES,
+ sourceMacAsBytes(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setSourceMacAddress(MAC_ADDRESS).build())
+ .build())));
+ }
+
+ @Test
+ public void sourceMacMaskAsBytes() {
+ assertTrue(Arrays.equals(DEFAULT_MAC_ADDRESS_BYTES, sourceMacMaskAsBytes(new VppMacipAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_MAC_ADDRESS_BYTES,
+ sourceMacMaskAsBytes(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(MAC_ADDRESS_BYTES,
+ sourceMacMaskAsBytes(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setSourceMacAddressMask(MAC_ADDRESS).build())
+ .build())));
+ }
+
+ @Test
+ public void testIpv4Address() {
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4Address(new VppMacipAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4Address(
+ new VppMacipAceBuilder().setVppMacipAceNodes(new VppMacipAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4Address(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, ipv4Address(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setSourceIpv4Network(IPV4_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void testIpv4AddressPrefix() {
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4AddressPrefix(new VppMacipAceBuilder().build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4AddressPrefix(
+ new VppMacipAceBuilder().setVppMacipAceNodes(new VppMacipAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4AddressPrefix(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build()));
+ assertEquals(IPV4_PREFIX_VALUE, ipv4AddressPrefix(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setSourceIpv4Network(IPV4_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void testIpv6Address() {
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6Address(new VppMacipAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6Address(
+ new VppMacipAceBuilder().setVppMacipAceNodes(new VppMacipAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6Address(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, ipv6Address(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setSourceIpv6Network(IPV6_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void testIpv6AddressPrefix() {
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6AddressPrefix(new VppMacipAceBuilder().build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6AddressPrefix(
+ new VppMacipAceBuilder().setVppMacipAceNodes(new VppMacipAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6AddressPrefix(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build()));
+ assertEquals(IPV6_PREFIX_VALUE, ipv6AddressPrefix(new VppMacipAceBuilder().setVppMacipAceNodes(
+ new VppMacipAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setSourceIpv6Network(IPV6_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void testMacIpAction() {
+ verifyExceptionalCase(() -> macIpAction(new AceBuilder().build()), IllegalArgumentException.class);
+ verifyExceptionalCase(() -> macIpAction(new AceBuilder().setActions(new ActionsBuilder().build()).build()),
+ IllegalArgumentException.class);
+ // this one must pass even if deny is not fully set, because of default value definition
+ assertEquals((byte) 0, macIpAction(new AceBuilder().setActions(new ActionsBuilder().setPacketHandling(
+ new DenyBuilder().build()).build()).build()));
+
+ assertEquals((byte) 1, macIpAction(new AceBuilder().setActions(new ActionsBuilder().setPacketHandling(
+ new PermitBuilder().setPermit(true).build()).build()).build()));
+ }
+
+ @Test
+ public void testIpVersionV4Defined() {
+ MacipAclRule rule = new MacipAclRule();
+
+ rule.isIpv6 = 0;
+ rule.srcIpAddr = IPV4_PREFIX_BYTES;
+ rule.srcIpPrefixLen = IPV4_PREFIX_VALUE;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv4);
+ assertEquals(IPV4_PREFIX, AceIpv4.class.cast(result).getSourceIpv4Network());
+ }
+
+ @Test
+ public void testIpVersionV4Undefined() {
+ MacipAclRule rule = new MacipAclRule();
+
+ rule.isIpv6 = 0;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv4);
+ assertNull(AceIpv4.class.cast(result).getSourceIpv4Network());
+ }
+
+ @Test
+ public void testIpVersionV6Defined() {
+ MacipAclRule rule = new MacipAclRule();
+
+ rule.isIpv6 = 1;
+ rule.srcIpAddr = IPV6_PREFIX_BYTES;
+ rule.srcIpPrefixLen = IPV6_PREFIX_VALUE;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv6);
+ assertEquals(IPV6_PREFIX, AceIpv6.class.cast(result).getSourceIpv6Network());
+ }
+
+ @Test
+ public void testIpVersionV6Undefined() {
+ MacipAclRule rule = new MacipAclRule();
+
+ rule.isIpv6 = 1;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv6);
+ assertNull(AceIpv6.class.cast(result).getSourceIpv6Network());
+ }
+
+ @Test
+ public void testSourceMac() {
+ assertEquals(DEFAULT_MAC_ADDRESS, sourceMac(new MacipAclRule()));
+
+
+ MacipAclRule rule = new MacipAclRule();
+ rule.srcMac = MAC_ADDRESS_BYTES;
+ assertEquals(MAC_ADDRESS, sourceMac(rule));
+ }
+
+ @Test
+ public void testSourceMacMask() {
+ assertEquals(DEFAULT_MAC_MASK_ADDRESS, sourceMacMask(new MacipAclRule()));
+
+
+ MacipAclRule rule = new MacipAclRule();
+ rule.srcMac = MAC_ADDRESS_MASK_BYTES;
+ assertEquals(MAC_ADDRESS_MASK, sourceMac(rule));
+ }
+} \ No newline at end of file
diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractorTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractorTest.java
new file mode 100644
index 000000000..35add44a2
--- /dev/null
+++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractorTest.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.acl.util.ace.extractor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import io.fd.hc2vpp.common.test.util.CommonTests;
+import io.fd.vpp.jvpp.acl.types.AclRule;
+import java.util.Arrays;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.AceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.ActionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.MatchesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Deny;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.DenyBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.actions.packet.handling.Permit;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.actions.packet.handling.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.actions.packet.handling.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.AceIpVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6Builder;
+
+
+public class StandardAceDataExtractorTest extends AceDataExtractorTestCase implements StandardAceDataExtractor,
+ CommonTests {
+
+ @Test
+ public void testFromStandardAce() {
+ verifyExceptionalCase(() -> fromStandardAce(new AceBuilder().build()), IllegalArgumentException.class);
+ verifyExceptionalCase(() -> fromStandardAce(new AceBuilder().setMatches(new MatchesBuilder().build()).build()),
+ IllegalArgumentException.class);
+
+ final VppAce ace = new VppAceBuilder().build();
+ assertEquals(ace, fromStandardAce(new AceBuilder().setMatches(new MatchesBuilder()
+ .setAceType(ace).build()).build()));
+ }
+
+ @Test
+ public void testStandardIsIpv6() {
+ assertFalse(standardIsIpv6(new AceBuilder().build()));
+ assertFalse(standardIsIpv6(new AceBuilder().setMatches(new MatchesBuilder().build()).build()));
+ assertFalse(standardIsIpv6(
+ new AceBuilder().setMatches(new MatchesBuilder().setAceType(new VppAceBuilder().build()).build())
+ .build()));
+ assertFalse(standardIsIpv6(new AceBuilder().setMatches(new MatchesBuilder()
+ .setAceType(new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build()).build())
+ .build()));
+ assertTrue(standardIsIpv6(new AceBuilder().setMatches(new MatchesBuilder().setAceType(new VppAceBuilder()
+ .setVppAceNodes(new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build())
+ .build()).build()));
+ }
+
+ @Test
+ public void testIpv4SourceAddress() {
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(new VppAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, ipv4SourceAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setSourceIpv4Network(IPV4_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void testIpv4SourceAddressPrefix() {
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new VppAceBuilder().build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build()));
+ assertEquals(IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setSourceIpv4Network(IPV4_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void testIpv4DestinationAddress() {
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4DestinationAddress(new VppAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4DestinationAddress(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4DestinationAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, ipv4DestinationAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setDestinationIpv4Network(IPV4_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void testIpv4DestinationAddressPrefix() {
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(new VppAceBuilder().build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()).build()));
+ assertEquals(IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder()
+ .setDestinationIpv4Network(IPV4_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void testIpv6SourceAddress() {
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(new VppAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, ipv6SourceAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setSourceIpv6Network(IPV6_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void ipv6SourceAddressPrefix() {
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new VppAceBuilder().build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build()));
+ assertEquals(IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setSourceIpv6Network(IPV6_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void ipv6DestinationAddress() {
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(new VppAceBuilder().build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build())));
+ assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build())));
+ assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, ipv6DestinationAddress(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setDestinationIpv6Network(IPV6_PREFIX).build()).build()).build())));
+ }
+
+ @Test
+ public void ipv6DestinationAddressPrefix() {
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new VppAceBuilder().build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(
+ new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build()));
+ assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder().build()).build()).build()));
+ assertEquals(IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new VppAceBuilder().setVppAceNodes(
+ new VppAceNodesBuilder().setAceIpVersion(new AceIpv6Builder()
+ .setDestinationIpv6Network(IPV6_PREFIX).build()).build()).build()));
+ }
+
+ @Test
+ public void testStandardAction() {
+ verifyExceptionalCase(() -> standardAction(new AceBuilder().build()), IllegalArgumentException.class);
+ verifyExceptionalCase(() -> standardAction(new AceBuilder().setActions(new ActionsBuilder().build()).build()),
+ IllegalArgumentException.class);
+
+ // this one should pass because of default value
+ assertEquals(0, standardAction(
+ new AceBuilder().setActions(new ActionsBuilder().setPacketHandling(new DenyBuilder().build()).build())
+ .build()));
+
+ assertEquals(2, standardAction(new AceBuilder().setActions(
+ new ActionsBuilder().setPacketHandling(new StatefulBuilder().setPermit(true).build()).build())
+ .build()));
+ }
+
+ @Test
+ public void testIpVersionV4Defined() {
+ AclRule rule = new AclRule();
+
+ rule.isIpv6 = 0;
+ rule.srcIpAddr = IPV4_PREFIX_BYTES;
+ rule.srcIpPrefixLen = IPV4_PREFIX_VALUE;
+ rule.dstIpAddr = IPV4_2_PREFIX_BYTES;
+ rule.dstIpPrefixLen = IPV4_2_PREFIX_VALUE;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv4);
+ assertEquals(IPV4_PREFIX, AceIpv4.class.cast(result).getSourceIpv4Network());
+ assertEquals(IPV4_2_PREFIX, AceIpv4.class.cast(result).getDestinationIpv4Network());
+ }
+
+ @Test
+ public void testIpVersionV4Undefined() {
+ AclRule rule = new AclRule();
+
+ rule.isIpv6 = 0;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv4);
+ assertNull(AceIpv4.class.cast(result).getSourceIpv4Network());
+ assertNull(AceIpv4.class.cast(result).getDestinationIpv4Network());
+ }
+
+ @Test
+ public void testIpVersionV6Defined() {
+ AclRule rule = new AclRule();
+
+ rule.isIpv6 = 1;
+ rule.srcIpAddr = IPV6_PREFIX_BYTES;
+ rule.srcIpPrefixLen = IPV6_PREFIX_VALUE;
+ rule.dstIpAddr = IPV6_2_PREFIX_BYTES;
+ rule.dstIpPrefixLen = IPV6_2_PREFIX_VALUE;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv6);
+ assertEquals(IPV6_PREFIX, AceIpv6.class.cast(result).getSourceIpv6Network());
+ assertEquals(IPV6_2_PREFIX, AceIpv6.class.cast(result).getDestinationIpv6Network());
+ }
+
+ @Test
+ public void testIpVersionV6Undefined() {
+ AclRule rule = new AclRule();
+
+ rule.isIpv6 = 1;
+
+ final AceIpVersion result = ipVersion(rule);
+ assertTrue(result instanceof AceIpv6);
+ assertNull(AceIpv6.class.cast(result).getSourceIpv6Network());
+ assertNull(AceIpv6.class.cast(result).getDestinationIpv6Network());
+ }
+
+
+ @Test
+ public void testActions() {
+ verifyExceptionalCase(() -> actions((byte) -1), IllegalArgumentException.class);
+ assertTrue(actions((byte) 0).getPacketHandling() instanceof Deny);
+ assertTrue(actions((byte) 1).getPacketHandling() instanceof Permit);
+ assertTrue(actions((byte) 2).getPacketHandling() instanceof Stateful);
+ }
+
+} \ No newline at end of file