From 718e9a3c7cac01860f3e3fe6174fcc1bd33fb4eb Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Mon, 19 Nov 2018 14:59:14 +0100 Subject: HC2VPP-291: ACL model bump - bump ACL yang models - fix ACL module implementation and validation - fix ACL Unit tests - update postman collection Change-Id: Iaab64e6d92d17babc3ccef7921b41070c3716516 Signed-off-by: Michal Cmarada --- .../io/fd/hc2vpp/acl/AclTestSchemaContext.java | 8 +- .../hc2vpp/acl/read/AbstractAclCustomizerTest.java | 215 ++++++++++++ .../acl/read/AbstractVppAclCustomizerTest.java | 168 --------- .../io/fd/hc2vpp/acl/read/AclCustomizerTest.java | 52 ++- .../hc2vpp/acl/read/EgressAclCustomizerTest.java | 70 ++++ .../acl/read/EgressVppAclCustomizerTest.java | 68 ---- .../hc2vpp/acl/read/IngressAclCustomizerTest.java | 70 ++++ .../acl/read/IngressVppAclCustomizerTest.java | 68 ---- .../fd/hc2vpp/acl/read/MacIpAclCustomizerTest.java | 183 ++++++++++ .../hc2vpp/acl/read/VppMacIpAclCustomizerTest.java | 150 --------- .../ace/extractor/MacIpAceDataExtractorTest.java | 144 +++----- .../extractor/StandardAceDataExtractorTest.java | 327 ++++++++++-------- .../acl/AclInterfaceAssignmentRequestTest.java | 20 +- .../macip/MacIpInterfaceAssignmentRequestTest.java | 24 +- .../acl/util/protocol/ProtocolParsingTest.java | 143 ++++---- .../io/fd/hc2vpp/acl/write/AclCustomizerTest.java | 373 ++++++++++++++++++++ .../io/fd/hc2vpp/acl/write/AclValidatorTest.java | 141 ++++++++ .../acl/write/InterfaceAclCustomizerTest.java | 72 ++-- .../acl/write/InterfaceAclMacipCustomizerTest.java | 45 +-- .../fd/hc2vpp/acl/write/VppAclCustomizerTest.java | 374 --------------------- .../fd/hc2vpp/acl/write/VppAclValidatorTest.java | 143 -------- .../src/test/resources/acl/ipv4/ipv4-acl.json | 10 +- .../src/test/resources/acl/macip/macip-acl.json | 18 +- .../acl/standard/interface-ref-acl-udp.json | 28 +- .../acl/standard/standard-acl-icmp-v6.json | 24 +- .../resources/acl/standard/standard-acl-icmp.json | 24 +- .../acl/standard/standard-acl-tcp-src-only.json | 40 +-- .../resources/acl/standard/standard-acl-tcp.json | 40 +-- .../resources/acl/standard/standard-acl-udp.json | 34 +- .../resources/interface-acl/acl-references.json | 45 +-- .../src/test/resources/rules/icmp-rule.json | 22 +- .../src/test/resources/rules/icmp-v6-rule.json | 24 +- .../src/test/resources/rules/no-protocol-rule.json | 16 +- .../src/test/resources/rules/other-rule.json | 26 -- .../test/resources/rules/tcp-rule-no-flags.json | 28 +- .../src/test/resources/rules/tcp-rule.json | 38 ++- .../src/test/resources/rules/udp-rule.json | 32 +- 37 files changed, 1692 insertions(+), 1615 deletions(-) create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizerTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressAclCustomizerTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressAclCustomizerTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/MacIpAclCustomizerTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclCustomizerTest.java create mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclValidatorTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java delete mode 100644 acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java delete mode 100644 acl/acl-impl/src/test/resources/rules/other-rule.json (limited to 'acl/acl-impl/src/test') diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java index 6eb6862bf..6e10be47a 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/AclTestSchemaContext.java @@ -33,13 +33,11 @@ public interface AclTestSchemaContext { .getInstance(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.$YangModuleInfoImpl - .getInstance(), - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.$YangModuleInfoImpl .getInstance())); return context; } diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizerTest.java new file mode 100644 index 000000000..beda3ccff --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractAclCustomizerTest.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2016 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.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.acl.AclIIds; +import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.vpp.jvpp.acl.dto.AclDetails; +import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGetReply; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetails; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.ArrayList; +import java.util.Collections; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public abstract class AbstractAclCustomizerTest + extends InitializingListReaderCustomizerTest { + + protected static final String IF_NAME = "eth1"; + protected static final int IF_ID = 1; + protected static final int ACL_ID = 1; + protected static final int ACL_MAC_ID = 2; + private static final String ACL_NAME = "acl-name"; + private static final String ACL_MAC_NAME = "acl-mac-name"; + + protected static final String IF_NAME_NO_ACL = "eth2"; + protected static final int IF_ID_NO_ACL = 2; + + protected static final String IFC_CTX_NAME = "interface-context"; + protected static final String ACL_CTX_NAME = "standard-acl-context"; + + @Mock + protected FutureJVppAclFacade aclApi; + + protected NamingContext interfaceContext = new NamingContext("iface", IFC_CTX_NAME); + + @Mock + protected AclContextManager standardAclContext; + + @Mock + protected AclContextManager macIpAclContext; + + protected AbstractAclCustomizerTest(final Class> parentBuilderClass) { + super(AclSet.class, parentBuilderClass); + } + + protected static KeyedInstanceIdentifier getAclId(final String ifName) { + return AclIIds.ACLS_AP.child(Interface.class, new InterfaceKey(ifName)); + } + + @Override + protected void setUp() throws Exception { + defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME_NO_ACL, IF_ID_NO_ACL, IFC_CTX_NAME); + when(macIpAclContext.getAclName(ACL_MAC_ID, mappingContext)).thenReturn(ACL_MAC_NAME); + when(standardAclContext.getAclName(ACL_ID, mappingContext)).thenReturn(ACL_NAME); + when(macIpAclContext.containsAcl(ACL_MAC_NAME, mappingContext)).thenReturn(true); + when(standardAclContext.containsAcl(ACL_NAME, mappingContext)).thenReturn(true); + final MacipAclInterfaceListDetailsReplyDump macReply = macAaclInterfaceDump(0); + when(aclApi.macipAclInterfaceListDump(any())).thenReturn(future(macReply)); + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 0); + when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); + } + + @Test + public void testGetAllIdsNoAclConfigured() throws ReadFailedException { + assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); + } + + @Test + public void testRead() throws ReadFailedException { + final String aclName = "acl-name"; + defineMapping(mappingContext, aclName, 1, ACL_CTX_NAME); + + final AclDetailsReplyDump reply = new AclDetailsReplyDump(); + reply.aclDetails = new ArrayList<>(); + final AclDetails detail = new AclDetails(); + detail.tag = new byte[0]; + reply.aclDetails.add(detail); + when(aclApi.aclDump(any())).thenReturn(future(reply)); + + final AclSetBuilder builder = mock(AclSetBuilder.class); + getCustomizer().readCurrentAttributes(getIid(IF_NAME, new AclSetKey(aclName)), builder, ctx); + verify(builder).setName(aclName); + } + + @Test + public void testReadAllTwoIfacesInOneTx() throws ReadFailedException { + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 2, "acl1", "acl2", "acl3"); + final MacipAclInterfaceListDetailsReplyDump macReply = macAaclInterfaceDump(0); + final MacipAclInterfaceListDetailsReplyDump macReply2 = macAaclInterfaceDump(1); + final MacipAclInterfaceGetReply interfaceGet = macipAclInterfaceGetReply(); + + + when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); + when(aclApi.macipAclInterfaceListDump(any())).thenReturn(future(macReply)); + when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(interfaceGet)); + + when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID_NO_ACL))) + .thenReturn(future(aclInterfaceDump((byte) 0))); + + // read all for interface with defined ACLs: + assertFalse(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); + // read all for interface without ACLs defined: + assertEquals(0, getCustomizer().getAllIds(getWildcardedIid(IF_NAME_NO_ACL), ctx).size()); + } + + protected MacipAclInterfaceGetReply macipAclInterfaceGetReply(final String... aclNames) { + final MacipAclInterfaceGetReply reply = new MacipAclInterfaceGetReply(); + reply.acls = new int[aclNames.length]; + for (int i = 0; i < aclNames.length; ++i) { + defineMapping(mappingContext, aclNames[i], i, ACL_CTX_NAME); + reply.acls[i] = i; + } + reply.count = (byte) aclNames.length; + return reply; + } + + @Test + public void testInit() { + final String aclName = "acl-name"; + defineMapping(mappingContext, aclName, 1, ACL_CTX_NAME); + + final AclSet readValue = new AclSetBuilder().build(); + final Initialized cfgValue = + getCustomizer().init(getIid(IF_NAME, new AclSetKey(aclName)), readValue, ctx); + assertEquals(readValue, cfgValue.getData()); + assertNotNull(cfgValue.getId().firstKeyOf(Interface.class)); + assertEquals(cfgValue.getId().getTargetType(), AclSet.class); + } + + protected AclInterfaceListDump aclInterfaceRequest(final int swIfIndex) { + final AclInterfaceListDump request = new AclInterfaceListDump(); + request.swIfIndex = swIfIndex; + return request; + } + + protected AclInterfaceListDetailsReplyDump aclInterfaceDump(final byte nInput, final String... aclNames) { + final AclInterfaceListDetailsReplyDump reply = new AclInterfaceListDetailsReplyDump(); + final AclInterfaceListDetails details = new AclInterfaceListDetails(); + details.acls = new int[aclNames.length]; + for (int i = 0; i < aclNames.length; ++i) { + defineMapping(mappingContext, aclNames[i], i, ACL_CTX_NAME); + details.acls[i] = i; + } + details.count = (byte) aclNames.length; + details.nInput = nInput; + reply.aclInterfaceListDetails.add(details); + return reply; + } + + protected MacipAclInterfaceListDetailsReplyDump macAaclInterfaceDump(int swIfIndex, final String... aclNames) { + final MacipAclInterfaceListDetailsReplyDump assignedAcls = new MacipAclInterfaceListDetailsReplyDump(); + + MacipAclInterfaceListDetails details = new MacipAclInterfaceListDetails(); + details.swIfIndex = swIfIndex; + details.count = (byte) aclNames.length; + details.acls = new int[aclNames.length]; + for (int i = 0; i < aclNames.length; ++i) { + defineMapping(mappingContext, aclNames[i], i, ACL_CTX_NAME); + details.acls[i] = i; + } + + assignedAcls.macipAclInterfaceListDetails.add(details); + assignedAcls.macipAclInterfaceListDetails = Collections.singletonList(details); + + return assignedAcls; + } + + protected abstract InstanceIdentifier getWildcardedIid(@Nonnull final String ifName); + + protected abstract InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final AclSetKey key); +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizerTest.java deleted file mode 100644 index 074b25b29..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AbstractVppAclCustomizerTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2016 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.read; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.vpp.jvpp.acl.dto.AclDetails; -import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetails; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDump; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; -import java.util.ArrayList; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public abstract class AbstractVppAclCustomizerTest - extends InitializingListReaderCustomizerTest { - - protected static final String IF_NAME = "eth1"; - protected static final int IF_ID = 1; - - protected static final String IF_NAME_NO_ACL = "eth2"; - protected static final int IF_ID_NO_ACL = 2; - - protected static final String IFC_CTX_NAME = "interface-context"; - protected static final String ACL_CTX_NAME = "standard-acl-context"; - - @Mock - protected FutureJVppAclFacade aclApi; - - protected NamingContext interfaceContext = new NamingContext("iface", IFC_CTX_NAME); - - @Mock - protected AclContextManager standardAclContext; - - protected AbstractVppAclCustomizerTest(final Class> parentBuilderClass) { - super(VppAcls.class, parentBuilderClass); - } - - protected static InstanceIdentifier getAclId(final String ifName) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifName)) - .augmentation(VppAclInterfaceStateAugmentation.class).child(Acl.class); - } - - @Override - protected void setUp() throws Exception { - defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME_NO_ACL, IF_ID_NO_ACL, IFC_CTX_NAME); - } - - @Test - public void testGetAllIdsNoAclConfigured() throws ReadFailedException { - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 0); - when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); - assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); - } - - @Test - public void testRead() throws ReadFailedException { - final String aclName = "acl-name"; - final Class aclType = VppAcl.class; - defineMapping(mappingContext, aclName, 1, ACL_CTX_NAME); - - final AclDetailsReplyDump reply = new AclDetailsReplyDump(); - reply.aclDetails = new ArrayList<>(); - final AclDetails detail = new AclDetails(); - detail.tag = new byte[0]; - reply.aclDetails.add(detail); - when(aclApi.aclDump(any())).thenReturn(future(reply)); - - final VppAclsBuilder builder = mock(VppAclsBuilder.class); - getCustomizer().readCurrentAttributes(getIid(IF_NAME, new VppAclsKey(aclName, aclType)), builder, ctx); - verify(builder).setName(aclName); - verify(builder).setType(aclType); - } - - @Test - public void testReadAllTwoIfacesInOneTx() throws ReadFailedException { - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 2, "acl1", "acl2", "acl3"); - when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); - - when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID_NO_ACL))) - .thenReturn(future(aclInterfaceDump((byte) 0))); - - // read all for interface with defined ACLs: - assertFalse(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); - // read all for interface without ACLs defined: - assertEquals(0, getCustomizer().getAllIds(getWildcardedIid(IF_NAME_NO_ACL), ctx).size()); - } - - @Test - public void testInit() { - final String aclName = "acl-name"; - final Class aclType = VppAcl.class; - defineMapping(mappingContext, aclName, 1, ACL_CTX_NAME); - - final VppAcls readValue = new VppAclsBuilder().build(); - final Initialized cfgValue = - getCustomizer().init(getIid(IF_NAME, new VppAclsKey(aclName, aclType)), readValue, ctx); - assertEquals(readValue, cfgValue.getData()); - assertNotNull(cfgValue.getId().firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface.class)); - assertEquals(cfgValue.getId().getTargetType(), VppAcls.class); - } - - protected AclInterfaceListDump aclInterfaceRequest(final int swIfIndex) { - final AclInterfaceListDump request = new AclInterfaceListDump(); - request.swIfIndex = swIfIndex; - return request; - } - - protected AclInterfaceListDetailsReplyDump aclInterfaceDump(final byte nInput, final String... aclNames) { - final AclInterfaceListDetailsReplyDump reply = new AclInterfaceListDetailsReplyDump(); - final AclInterfaceListDetails details = new AclInterfaceListDetails(); - details.acls = new int[aclNames.length]; - for (int i = 0; i < aclNames.length; ++i) { - defineMapping(mappingContext, aclNames[i], i, ACL_CTX_NAME); - details.acls[i] = i; - } - details.nInput = nInput; - reply.aclInterfaceListDetails.add(details); - return reply; - } - - protected abstract InstanceIdentifier getWildcardedIid(@Nonnull final String ifName); - - protected abstract InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final VppAclsKey key); -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AclCustomizerTest.java index 1b4403b2d..7501815a6 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AclCustomizerTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AclCustomizerTest.java @@ -35,18 +35,15 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessListsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace; -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.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.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.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Other; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Acls; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.AclsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Drop; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -58,7 +55,7 @@ public class AclCustomizerTest extends InitializingListReaderCustomizerTest ACL_IID = - InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey( - ACL_NAME, VppAcl.class)); + InstanceIdentifier.create(Acls.class).child(Acl.class, new AclKey(ACL_NAME)); private KeyedInstanceIdentifier MACIP_ACL_IID = - InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(MACIP_ACL_NAME, VppMacipAcl.class)); + InstanceIdentifier.create(Acls.class).child(Acl.class, new AclKey(MACIP_ACL_NAME)); public AclCustomizerTest() { - super(Acl.class, AccessListsBuilder.class); + super(Acl.class, AclsBuilder.class); } @Override @@ -103,15 +99,18 @@ public class AclCustomizerTest extends InitializingListReaderCustomizerTest allIds = getCustomizer().getAllIds(InstanceIdentifier.create(AccessLists.class).child(Acl.class), ctx); + final List allIds = + getCustomizer().getAllIds(InstanceIdentifier.create(Acls.class).child(Acl.class), ctx); assertEquals(2, allIds.size()); assertEquals(ACL_IID.getKey(), allIds.get(0)); assertEquals(MACIP_ACL_IID.getKey(), allIds.get(1)); @@ -122,14 +121,13 @@ public class AclCustomizerTest extends InitializingListReaderCustomizerTest aces = builder.getAccessListEntries().getAce(); + final List aces = builder.getAces().getAce(); assertEquals(1, aces.size()); final Ace ace = aces.get(0); - assertEquals(ACE_NAME, ace.key().getRuleName()); - assertTrue(ace.getActions().getPacketHandling() instanceof Deny); - final VppAceNodes nodes = ((VppAce) (ace.getMatches().getAceType())).getVppAceNodes(); - assertEquals(PROTOCOL, ((Other) nodes.getIpProtocol()).getOtherNodes().getProtocol().shortValue()); - + assertEquals(ACE_NAME, ace.key().getName()); + assertTrue(ace.getActions().getForwarding().equals(Drop.class)); + final L4 l4 = ((ace.getMatches())).getL4(); + assertEquals(Icmp.class, l4.getImplementedInterface()); } @Test @@ -137,10 +135,10 @@ public class AclCustomizerTest extends InitializingListReaderCustomizerTest aces = builder.getAccessListEntries().getAce(); + final List aces = builder.getAces().getAce(); assertEquals(1, aces.size()); final Ace ace = aces.get(0); - assertEquals(MACIP_ACE_NAME, ace.key().getRuleName()); - assertTrue(ace.getActions().getPacketHandling() instanceof Deny); + assertEquals(MACIP_ACE_NAME, ace.key().getName()); + assertTrue(ace.getActions().getForwarding().equals(Drop.class)); } } \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressAclCustomizerTest.java new file mode 100644 index 000000000..18f1978ef --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressAclCustomizerTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 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.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.Egress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSets; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public class EgressAclCustomizerTest extends AbstractAclCustomizerTest { + + public EgressAclCustomizerTest() { + super(AclSetsBuilder.class); + } + + @Override + protected EgressAclCustomizer initCustomizer() { + return new EgressAclCustomizer(aclApi, interfaceContext, standardAclContext); + } + + @Test + public void testGetAllIdsNoOutputAclConfigured() throws ReadFailedException { + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 1, "acl1"); + when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); + assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); + } + + @Test + public void testGetAllIds() throws ReadFailedException { + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 2, "acl1", "acl2", "acl3"); + when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); + assertEquals(1, getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).size()); + } + + @Override + protected InstanceIdentifier getWildcardedIid(@Nonnull final String ifName) { + return getAclId(ifName).child(Egress.class).child(AclSets.class).child(AclSet.class); + } + + protected KeyedInstanceIdentifier getIid(@Nonnull final String ifName, + @Nonnull final AclSetKey key) { + return getAclId(ifName).child(Egress.class).child(AclSets.class).child(AclSet.class, key); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizerTest.java deleted file mode 100644 index 967b8200a..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/EgressVppAclCustomizerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2016 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.read; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Egress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.EgressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class EgressVppAclCustomizerTest extends AbstractVppAclCustomizerTest { - - public EgressVppAclCustomizerTest() { - super(EgressBuilder.class); - } - - @Override - protected EgressVppAclCustomizer initCustomizer() { - return new EgressVppAclCustomizer(aclApi, interfaceContext, standardAclContext); - } - - @Test - public void testGetAllIdsNoOutputAclConfigured() throws ReadFailedException { - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 1, "acl1"); - when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); - assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); - } - - @Test - public void testGetAllIds() throws ReadFailedException { - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 2, "acl1", "acl2", "acl3"); - when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); - assertEquals(1, getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).size()); - } - - @Override - protected InstanceIdentifier getWildcardedIid(@Nonnull final String ifName) { - return getAclId(ifName).child(Egress.class).child(VppAcls.class); - } - - @Override - protected InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final VppAclsKey key) { - return getAclId(ifName).child(Egress.class).child(VppAcls.class, key); - } -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressAclCustomizerTest.java new file mode 100644 index 000000000..666f6d8c9 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressAclCustomizerTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 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.read; + +import static io.fd.vpp.jvpp.Assertions.assertEquals; +import static junit.framework.TestCase.assertTrue; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.Ingress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSets; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class IngressAclCustomizerTest extends AbstractAclCustomizerTest { + + public IngressAclCustomizerTest() { + super(AclSetsBuilder.class); + } + + @Override + protected IngressAclCustomizer initCustomizer() { + return new IngressAclCustomizer(aclApi, interfaceContext, standardAclContext, macIpAclContext); + } + + + @Test + public void testGetAllIdsNoInputAclConfigured() throws ReadFailedException { + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 0, "acl1"); + when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); + assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); + } + + @Test + public void testGetAllIds() throws ReadFailedException { + final byte nInput = 2; + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump(nInput, "acl1", "acl2", "acl3"); + when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); + assertEquals(nInput, getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).size()); + } + + @Override + protected InstanceIdentifier getWildcardedIid(@Nonnull final String ifName) { + return getAclId(ifName).child(Ingress.class).child(AclSets.class).child(AclSet.class); + } + + @Override + protected InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final AclSetKey key) { + return getAclId(ifName).child(Ingress.class).child(AclSets.class).child(AclSet.class, key); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizerTest.java deleted file mode 100644 index 42a798e88..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/IngressVppAclCustomizerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2016 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.read; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class IngressVppAclCustomizerTest extends AbstractVppAclCustomizerTest { - - public IngressVppAclCustomizerTest() { - super(IngressBuilder.class); - } - - @Override - protected IngressVppAclCustomizer initCustomizer() { - return new IngressVppAclCustomizer(aclApi, interfaceContext, standardAclContext); - } - - @Test - public void testGetAllIdsNoInputAclConfigured() throws ReadFailedException { - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 0, "acl1"); - when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); - assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); - } - - @Test - public void testGetAllIds() throws ReadFailedException { - final byte nInput = 2; - final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump(nInput, "acl1", "acl2", "acl3"); - when(aclApi.aclInterfaceListDump(aclInterfaceRequest(IF_ID))).thenReturn(future(reply)); - assertEquals(nInput, getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).size()); - } - - @Override - protected InstanceIdentifier getWildcardedIid(@Nonnull final String ifName) { - return getAclId(ifName).child(Ingress.class).child(VppAcls.class); - } - - @Override - protected InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final VppAclsKey key) { - return getAclId(ifName).child(Ingress.class).child(VppAcls.class, key); - } -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/MacIpAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/MacIpAclCustomizerTest.java new file mode 100644 index 000000000..6678ab53a --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/MacIpAclCustomizerTest.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2016 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.read; + +import static io.fd.hc2vpp.acl.read.IngressAclCustomizer.ACL_NOT_ASSIGNED; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; +import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGetReply; +import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceListDetailsReplyDump; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import javax.annotation.Nonnull; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.Ingress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSets; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MacIpAclCustomizerTest extends AbstractAclCustomizerTest { + + protected static final String IF_NAME_NO_ACL = "eth2"; + protected static final int IF_ID_NO_ACL = 1; + protected static final String IFC_CTX_NAME = "interface-context"; + private static final String IF_NAME = "eth1"; + private static final int IF_ID = 1; + private static final String ACL_NAME = "acl-name"; + private static final int ACL_ID = 1; + @Mock + protected FutureJVppAclFacade aclApi; + protected NamingContext interfaceContext = new NamingContext("iface", IFC_CTX_NAME); + + public MacIpAclCustomizerTest() { + super(AclSetsBuilder.class); + } + + @Override + protected IngressAclCustomizer initCustomizer() { + return new IngressAclCustomizer(aclApi, interfaceContext, standardAclContext, macIpAclContext); + } + + @Override + protected void setUp() { + defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME_NO_ACL, IF_ID_NO_ACL, IFC_CTX_NAME); + when(macIpAclContext.getAclName(ACL_ID, mappingContext)).thenReturn(ACL_NAME); + when(macIpAclContext.containsAcl(ACL_NAME, mappingContext)).thenReturn(true); + when(standardAclContext.containsAcl(ACL_NAME, mappingContext)).thenReturn(false); + final AclInterfaceListDetailsReplyDump reply = aclInterfaceDump((byte) 0); + when(aclApi.aclInterfaceListDump(any())).thenReturn(future(reply)); + final MacipAclInterfaceListDetailsReplyDump macReply = macAaclInterfaceDump(1, "acl-name"); + when(aclApi.macipAclInterfaceListDump(any())).thenReturn(future(macReply)); + } + + + @Test + public void testRead() throws ReadFailedException { + final AclSetBuilder builder = mock(AclSetBuilder.class); + + final MacipAclInterfaceGetReply assignedAcls = new MacipAclInterfaceGetReply(); + assignedAcls.count = 2; + assignedAcls.acls = new int[]{ACL_NOT_ASSIGNED, ACL_ID}; + when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(assignedAcls)); + + final MacipAclDump request = new MacipAclDump(); + request.aclIndex = ACL_ID; + final MacipAclDetailsReplyDump reply = new MacipAclDetailsReplyDump(); + final MacipAclDetails details = new MacipAclDetails(); + details.aclIndex = ACL_ID; + reply.macipAclDetails.add(details); + when(aclApi.macipAclDump(request)).thenReturn(future(reply)); + + getCustomizer().readCurrentAttributes(getIid(IF_NAME_NO_ACL, new AclSetKey(ACL_NAME)), builder, ctx); + verify(builder).setName(ACL_NAME); + } + + @Test + public void testReadNotAssigned() throws ReadFailedException { + final AclSetBuilder builder = mock(AclSetBuilder.class); + + final MacipAclInterfaceGetReply assignedAcls = new MacipAclInterfaceGetReply(); + // pretending we have 3 interfaces, IF_NAME does not have MacipAcl assigned + assignedAcls.count = 3; + assignedAcls.acls = new int[]{ACL_NOT_ASSIGNED, ACL_NOT_ASSIGNED, ACL_NOT_ASSIGNED}; + when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(assignedAcls)); + + final MacipAclDump request = new MacipAclDump(); + request.aclIndex = ACL_ID; + final MacipAclDetailsReplyDump reply = new MacipAclDetailsReplyDump(); + final MacipAclDetails details = new MacipAclDetails(); + details.aclIndex = ACL_ID; + reply.macipAclDetails.add(details); + when(aclApi.macipAclDump(request)).thenReturn(future(reply)); + + getCustomizer().readCurrentAttributes(getIid(IF_NAME_NO_ACL, new AclSetKey(ACL_NAME)), builder, ctx); + verifyZeroInteractions(builder); + } + + @Test + public void testReadNoAcls() throws ReadFailedException { + final AclSetBuilder builder = mock(AclSetBuilder.class); + final MacipAclInterfaceGetReply assignedAcls = new MacipAclInterfaceGetReply(); + assignedAcls.count = 0; + assignedAcls.acls = new int[0]; + when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(assignedAcls)); + getCustomizer().readCurrentAttributes(getIid(IF_NAME_NO_ACL, new AclSetKey(ACL_NAME)), builder, ctx); + verifyZeroInteractions(builder); + } + + @Test + public void testGetAllIdsNoAclConfigured() throws ReadFailedException { + final MacipAclInterfaceListDetailsReplyDump macReply = macAaclInterfaceDump(1); + when(aclApi.macipAclInterfaceListDump(any())).thenReturn(future(macReply)); + assertTrue(getCustomizer().getAllIds(getWildcardedIid(IF_NAME_NO_ACL), ctx).isEmpty()); + } + + @Test + public void testReadAllTwoIfacesInOneTx() throws ReadFailedException { + final MacipAclInterfaceListDetailsReplyDump macReply = macAaclInterfaceDump(1); + final MacipAclInterfaceGetReply interfaceGet = macipAclInterfaceGetReply(); + // read all for interface with defined ACLs: + assertFalse(getCustomizer().getAllIds(getWildcardedIid(IF_NAME), ctx).isEmpty()); + // read all for interface without ACLs defined: + when(aclApi.macipAclInterfaceListDump(any())).thenReturn(future(macReply)); + when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(interfaceGet)); + Assert.assertEquals(0, getCustomizer().getAllIds(getWildcardedIid(IF_NAME_NO_ACL), ctx).size()); + } + + @Test + public void testInit() { + final AclSet readValue = new AclSetBuilder().build(); + final Initialized + cfgValue = getCustomizer().init(getWildcardedIid(IF_NAME), readValue, ctx); + assertEquals(cfgValue.getData(), readValue); + assertNotNull(cfgValue.getId().firstKeyOf(Interface.class)); + assertEquals(cfgValue.getId().getTargetType(), AclSet.class); + + } + + @Override + protected InstanceIdentifier getWildcardedIid(@Nonnull final String ifName) { + return getAclId(ifName).child(Ingress.class).child(AclSets.class).child(AclSet.class); + } + + @Override + protected InstanceIdentifier getIid(@Nonnull final String ifName, @Nonnull final AclSetKey key) { + return getAclId(ifName).child(Ingress.class).child(AclSets.class).child(AclSet.class, key); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizerTest.java deleted file mode 100644 index 23ce85640..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizerTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2016 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.read; - -import static io.fd.hc2vpp.acl.read.VppMacIpAclCustomizer.ACL_NOT_ASSIGNED; -import static io.fd.hc2vpp.acl.read.AbstractVppAclCustomizerTest.getAclId; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; -import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; -import io.fd.vpp.jvpp.acl.dto.MacipAclDump; -import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceGetReply; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AclBase; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAclBuilder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VppMacIpAclCustomizerTest extends InitializingReaderCustomizerTest { - - protected static final String IF_NAME_NO_ACL = "eth2"; - protected static final int IF_ID_NO_ACL = 2; - protected static final String IFC_CTX_NAME = "interface-context"; - private static final String IF_NAME = "eth1"; - private static final int IF_ID = 1; - private static final String ACL_NAME = "acl-name"; - private static final int ACL_ID = 1; - private static final Class ACL_TYPE = - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl.class; - @Mock - protected FutureJVppAclFacade aclApi; - protected NamingContext interfaceContext = new NamingContext("iface", IFC_CTX_NAME); - @Mock - protected AclContextManager macIpAclContext; - - public VppMacIpAclCustomizerTest() { - super(VppMacipAcl.class, IngressBuilder.class); - } - - @Override - protected VppMacIpAclCustomizer initCustomizer() { - return new VppMacIpAclCustomizer(aclApi, interfaceContext, macIpAclContext); - } - - @Override - protected void setUp() { - defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME_NO_ACL, IF_ID_NO_ACL, IFC_CTX_NAME); - when(macIpAclContext.getAclName(ACL_ID, mappingContext)).thenReturn(ACL_NAME); - } - - @Test - public void testRead() throws ReadFailedException { - final VppMacipAclBuilder builder = mock(VppMacipAclBuilder.class); - - final MacipAclInterfaceGetReply assignedAcls = new MacipAclInterfaceGetReply(); - assignedAcls.count = 2; - assignedAcls.acls = new int[] {ACL_NOT_ASSIGNED, ACL_ID}; - when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(assignedAcls)); - - final MacipAclDump request = new MacipAclDump(); - request.aclIndex = ACL_ID; - final MacipAclDetailsReplyDump reply = new MacipAclDetailsReplyDump(); - final MacipAclDetails details = new MacipAclDetails(); - details.aclIndex = ACL_ID; - reply.macipAclDetails.add(details); - when(aclApi.macipAclDump(request)).thenReturn(future(reply)); - - getCustomizer().readCurrentAttributes(getIid(IF_NAME), builder, ctx); - verify(builder).setName(ACL_NAME); - verify(builder).setType(ACL_TYPE); - } - - @Test - public void testReadNotAssigned() throws ReadFailedException { - final VppMacipAclBuilder builder = mock(VppMacipAclBuilder.class); - - final MacipAclInterfaceGetReply assignedAcls = new MacipAclInterfaceGetReply(); - // pretending we have 3 interfaces, IF_NAME does not have MacipAcl assigned - assignedAcls.count = 3; - assignedAcls.acls = new int[] {ACL_NOT_ASSIGNED, ACL_NOT_ASSIGNED, ACL_ID}; - when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(assignedAcls)); - - final MacipAclDump request = new MacipAclDump(); - request.aclIndex = ACL_ID; - final MacipAclDetailsReplyDump reply = new MacipAclDetailsReplyDump(); - final MacipAclDetails details = new MacipAclDetails(); - details.aclIndex = ACL_ID; - reply.macipAclDetails.add(details); - when(aclApi.macipAclDump(request)).thenReturn(future(reply)); - - getCustomizer().readCurrentAttributes(getIid(IF_NAME), builder, ctx); - verifyZeroInteractions(builder); - } - - @Test - public void testReadNoAcls() throws ReadFailedException { - final VppMacipAclBuilder builder = mock(VppMacipAclBuilder.class); - when(aclApi.macipAclInterfaceGet(any())).thenReturn(future(new MacipAclInterfaceGetReply())); - getCustomizer().readCurrentAttributes(getIid(IF_NAME_NO_ACL), builder, ctx); - verifyZeroInteractions(builder); - } - - @Test - public void testInit() { - final VppMacipAcl readValue = new VppMacipAclBuilder().build(); - final Initialized cfgValue = getCustomizer().init(getIid(IF_NAME), readValue, ctx); - assertEquals(cfgValue.getData(), readValue); - assertNotNull(cfgValue.getId().firstKeyOf(Interface.class)); - assertEquals(cfgValue.getId().getTargetType(), VppMacipAcl.class); - - } - - protected InstanceIdentifier getIid(@Nonnull final String ifName) { - return getAclId(ifName).child(Ingress.class).child(VppMacipAcl.class); - } - -} \ No newline at end of file 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 index ea01cedb6..5375ee429 100644 --- 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 @@ -17,7 +17,6 @@ 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; @@ -25,114 +24,56 @@ 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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Accept; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Drop; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.AceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.ActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4NetworkBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6NetworkBuilder; 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()))); + assertTrue(Arrays.equals(MAC_ADDRESS_BYTES, sourceMacAsBytes(MAC_ADDRESS))); } @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()))); + assertTrue(Arrays.equals(MAC_ADDRESS_BYTES, sourceMacMaskAsBytes(MAC_ADDRESS))); } @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()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4Address(new SourceIpv4NetworkBuilder().build()))); + assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, + ipv4Address(new SourceIpv4NetworkBuilder().setSourceIpv4Network(IPV4_PREFIX).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())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4AddressPrefix(new SourceIpv4NetworkBuilder().build())); + assertEquals(IPV4_PREFIX_VALUE, + ipv4AddressPrefix(new SourceIpv4NetworkBuilder().setSourceIpv4Network(IPV4_PREFIX).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()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6Address(new SourceIpv6NetworkBuilder().build()))); + assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, + ipv6Address(new SourceIpv6NetworkBuilder().setSourceIpv6Network(IPV6_PREFIX).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())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6AddressPrefix(new SourceIpv6NetworkBuilder().build())); + assertEquals(IPV6_PREFIX_VALUE, + ipv6AddressPrefix(new SourceIpv6NetworkBuilder().setSourceIpv6Network(IPV6_PREFIX).build())); } @Test @@ -141,11 +82,10 @@ public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implemen 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())); + assertEquals((byte) 0, macIpAction( + new AceBuilder().setActions(new ActionsBuilder().setForwarding(Drop.class).build()).build())); + assertEquals((byte) 1, macIpAction( + new AceBuilder().setActions(new ActionsBuilder().setForwarding(Accept.class).build()).build())); } @Test @@ -156,9 +96,10 @@ public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implemen 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()); + final L3 result = parseMacIpAceL3(rule); + assertEquals(Ipv4.class, result.getImplementedInterface()); + assertEquals(IPV4_PREFIX, + ((SourceIpv4Network) ((Ipv4) result).getIpv4().getSourceNetwork()).getSourceIpv4Network()); } @Test @@ -167,9 +108,9 @@ public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implemen rule.isIpv6 = 0; - final AceIpVersion result = ipVersion(rule); - assertTrue(result instanceof AceIpv4); - assertNull(AceIpv4.class.cast(result).getSourceIpv4Network()); + final L3 result = parseMacIpAceL3(rule); + assertEquals(Ipv4.class, result.getImplementedInterface()); + assertNull(((Ipv4) result).getIpv4()); } @Test @@ -180,9 +121,10 @@ public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implemen 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()); + final L3 result = parseMacIpAceL3(rule); + assertEquals(Ipv6.class, result.getImplementedInterface()); + assertEquals(IPV6_PREFIX, ((SourceIpv6Network) ((Ipv6) result).getIpv6().getSourceNetwork()) + .getSourceIpv6Network()); } @Test @@ -191,9 +133,9 @@ public class MacIpAceDataExtractorTest extends AceDataExtractorTestCase implemen rule.isIpv6 = 1; - final AceIpVersion result = ipVersion(rule); - assertTrue(result instanceof AceIpv6); - assertNull(AceIpv6.class.cast(result).getSourceIpv6Network()); + final L3 result = parseMacIpAceL3(rule); + assertEquals(Ipv6.class, result.getImplementedInterface()); + assertNull(((Ipv6) result).getIpv6()); } @Test 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 index f22d6600a..627dba6b0 100644 --- 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 @@ -25,159 +25,212 @@ 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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.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.rev170615.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.AcceptAndReflect; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Accept; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Drop; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.AceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.ActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.MatchesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.L3; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.destination.network.DestinationIpv4Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.destination.network.DestinationIpv4NetworkBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv4.header.fields.source.network.SourceIpv4NetworkBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.destination.network.DestinationIpv6Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.destination.network.DestinationIpv6NetworkBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6Network; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.acl.ipv6.header.fields.source.network.SourceIpv6NetworkBuilder; 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 testStandardIsIpv6WithoutMatch() { - assertFalse(standardIsIpv6(new VppAceBuilder().build(), null)); - assertFalse(standardIsIpv6(new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder().build()).build(), null)); - assertFalse(standardIsIpv6(new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder() - .setIpProtocol(new IcmpBuilder().build()).build()).build(), null)); - assertTrue(standardIsIpv6(new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder() - .setIpProtocol(new IcmpV6Builder().build()).build()).build(), null)); - } - - @Test - public void testStandardIsIpv6WithMatch() { - final VppAce ipv6Ace = new VppAceBuilder().setVppAceNodes(new VppAceNodesBuilder() - .setIpProtocol(new IcmpV6Builder().build()).build()).build(); - - assertTrue(standardIsIpv6(ipv6Ace, new MatchesBuilder().build())); - assertTrue(standardIsIpv6(ipv6Ace, new MatchesBuilder().setAceType(new VppAceBuilder().build()).build())); - assertTrue(standardIsIpv6(ipv6Ace, new MatchesBuilder().setAceType(new VppAceBuilder() - .setVppAceNodes(new VppAceNodesBuilder().build()) - .build()).build())); - assertFalse(standardIsIpv6(ipv6Ace, new MatchesBuilder().setAceType(new VppAceBuilder() - .setVppAceNodes(new VppAceNodesBuilder().setAceIpVersion(new AceIpv4Builder().build()).build()) - .build()).build())); + assertFalse(standardIsIpv6(null)); + assertFalse(standardIsIpv6(new MatchesBuilder().build())); + assertFalse(standardIsIpv6(new MatchesBuilder().setL3(new Ipv6Builder().build()).build())); + assertTrue(standardIsIpv6(new MatchesBuilder().setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .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()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(new MatchesBuilder().build()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, + ipv4SourceAddress(new MatchesBuilder().setL3(new Ipv4Builder().build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .build()).build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4SourceAddress(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setSourceNetwork(new SourceIpv4NetworkBuilder().build()).build()).build()).build()))); + assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, ipv4SourceAddress(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setSourceNetwork( + new SourceIpv4NetworkBuilder().setSourceIpv4Network(IPV4_PREFIX).build()) + .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())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new MatchesBuilder().build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, + ipv4SourceAddressPrefix(new MatchesBuilder().setL3(new Ipv4Builder().build()).build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .build()).build()).build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setSourceNetwork(new SourceIpv4NetworkBuilder().build()).build()).build()).build())); + assertEquals(IPV4_PREFIX_VALUE, ipv4SourceAddressPrefix(new MatchesBuilder() + .setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setSourceNetwork( + new SourceIpv4NetworkBuilder().setSourceIpv4Network(IPV4_PREFIX).build()) + .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 MatchesBuilder().build()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4DestinationAddress( + new MatchesBuilder().setL3(new Ipv4Builder().build()).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()))); + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .build()).build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV4_ADDRESS_BYTES, ipv4DestinationAddress( + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setDestinationNetwork(new DestinationIpv4NetworkBuilder() + .build()).build()).build()).build()))); + assertTrue(Arrays.equals(IPV4_PREFIX_BYTES, ipv4DestinationAddress( + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setDestinationNetwork( + new DestinationIpv4NetworkBuilder().setDestinationIpv4Network(IPV4_PREFIX) + .build()).build()).build()).build()))); } @Test public void testIpv4DestinationAddressPrefix() { - assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(new VppAceBuilder().build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix(new MatchesBuilder().build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix( + new MatchesBuilder().setL3(new Ipv4Builder().build()).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())); + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .build()).build()).build())); + assertEquals(DEFAULT_IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix( + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setDestinationNetwork(new DestinationIpv4NetworkBuilder() + .build()).build()).build()).build())); + assertEquals(IPV4_PREFIX_VALUE, ipv4DestinationAddressPrefix( + new MatchesBuilder().setL3(new Ipv4Builder().setIpv4( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv4.Ipv4Builder() + .setDestinationNetwork( + new DestinationIpv4NetworkBuilder().setDestinationIpv4Network(IPV4_PREFIX) + .build()).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()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(new MatchesBuilder().build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, + ipv6SourceAddress(new MatchesBuilder().setL3(new Ipv6Builder().build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .build()).build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6SourceAddress(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setSourceNetwork(new SourceIpv6NetworkBuilder().build()).build()).build()).build()))); + assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, ipv6SourceAddress(new MatchesBuilder().setL3(new Ipv6Builder() + .setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setSourceNetwork( + new SourceIpv6NetworkBuilder().setSourceIpv6Network(IPV6_PREFIX).build()) + .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())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new MatchesBuilder().build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, + ipv6SourceAddressPrefix(new MatchesBuilder().setL3(new Ipv6Builder().build()).build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .build()).build()).build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setSourceNetwork(new SourceIpv6NetworkBuilder().build()).build()).build()).build())); + assertEquals(IPV6_PREFIX_VALUE, ipv6SourceAddressPrefix(new MatchesBuilder().setL3(new Ipv6Builder() + .setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setSourceNetwork( + new SourceIpv6NetworkBuilder().setSourceIpv6Network(IPV6_PREFIX).build()) + .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()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(new MatchesBuilder().build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, + ipv6DestinationAddress(new MatchesBuilder().setL3(new Ipv6Builder().build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .build()).build()).build()))); + assertTrue(Arrays.equals(DEFAULT_IPV6_ADDRESS_BYTES, ipv6DestinationAddress(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setDestinationNetwork(new DestinationIpv6NetworkBuilder().build()).build()).build()) + .build()))); + assertTrue(Arrays.equals(IPV6_PREFIX_BYTES, ipv6DestinationAddress(new MatchesBuilder().setL3(new Ipv6Builder() + .setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setDestinationNetwork( + new DestinationIpv6NetworkBuilder().setDestinationIpv6Network(IPV6_PREFIX) + .build()) + .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())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new MatchesBuilder().build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, + ipv6DestinationAddressPrefix(new MatchesBuilder().setL3(new Ipv6Builder().build()).build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .build()).build()).build())); + assertEquals(DEFAULT_IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new MatchesBuilder() + .setL3(new Ipv6Builder().setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setDestinationNetwork(new DestinationIpv6NetworkBuilder().build()).build()).build()) + .build())); + assertEquals(IPV6_PREFIX_VALUE, ipv6DestinationAddressPrefix(new MatchesBuilder().setL3(new Ipv6Builder() + .setIpv6( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l3.ipv6.Ipv6Builder() + .setDestinationNetwork( + new DestinationIpv6NetworkBuilder().setDestinationIpv6Network(IPV6_PREFIX) + .build()) + .build()).build()).build())); } @Test @@ -188,12 +241,10 @@ public class StandardAceDataExtractorTest extends AceDataExtractorTestCase imple // this one should pass because of default value assertEquals(0, standardAction( - new AceBuilder().setActions(new ActionsBuilder().setPacketHandling(new DenyBuilder().build()).build()) - .build())); + new AceBuilder().setActions(new ActionsBuilder().setForwarding(Drop.class).build()).build())); assertEquals(2, standardAction(new AceBuilder().setActions( - new ActionsBuilder().setPacketHandling(new StatefulBuilder().setPermitAndReflect(true).build()).build()) - .build())); + new ActionsBuilder().setForwarding(AcceptAndReflect.class).build()).build())); } @Test @@ -206,10 +257,13 @@ public class StandardAceDataExtractorTest extends AceDataExtractorTestCase imple 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()); + final L3 result = parseStandardAceL3(rule); + assertEquals(result.getImplementedInterface(), Ipv4.class); + assertEquals(IPV4_PREFIX, + ((SourceIpv4Network) ((Ipv4) result).getIpv4().getSourceNetwork()).getSourceIpv4Network()); + assertEquals(IPV4_2_PREFIX, + ((DestinationIpv4Network) ((Ipv4) result).getIpv4().getDestinationNetwork()) + .getDestinationIpv4Network()); } @Test @@ -218,10 +272,10 @@ public class StandardAceDataExtractorTest extends AceDataExtractorTestCase imple rule.isIpv6 = 0; - final AceIpVersion result = ipVersion(rule); - assertTrue(result instanceof AceIpv4); - assertNull(AceIpv4.class.cast(result).getSourceIpv4Network()); - assertNull(AceIpv4.class.cast(result).getDestinationIpv4Network()); + final L3 result = parseStandardAceL3(rule); + assertEquals(result.getImplementedInterface(), Ipv4.class); + assertNull(((Ipv4) result).getIpv4().getSourceNetwork()); + assertNull(((Ipv4) result).getIpv4().getDestinationNetwork()); } @Test @@ -234,10 +288,13 @@ public class StandardAceDataExtractorTest extends AceDataExtractorTestCase imple 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()); + final L3 result = parseStandardAceL3(rule); + assertEquals(result.getImplementedInterface(), Ipv6.class); + assertEquals(IPV6_PREFIX, + ((SourceIpv6Network) ((Ipv6) result).getIpv6().getSourceNetwork()).getSourceIpv6Network()); + assertEquals(IPV6_2_PREFIX, + ((DestinationIpv6Network) ((Ipv6) result).getIpv6().getDestinationNetwork()) + .getDestinationIpv6Network()); } @Test @@ -246,19 +303,17 @@ public class StandardAceDataExtractorTest extends AceDataExtractorTestCase imple rule.isIpv6 = 1; - final AceIpVersion result = ipVersion(rule); - assertTrue(result instanceof AceIpv6); - assertNull(AceIpv6.class.cast(result).getSourceIpv6Network()); - assertNull(AceIpv6.class.cast(result).getDestinationIpv6Network()); + final L3 result = parseStandardAceL3(rule); + assertEquals(result.getImplementedInterface(), Ipv6.class); + assertNull((((Ipv6) result).getIpv6().getSourceNetwork())); + assertNull((((Ipv6) result).getIpv6().getDestinationNetwork())); } @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); + assertTrue(actions((byte) 0).getForwarding().equals(Drop.class)); + assertTrue(actions((byte) 1).getForwarding().equals(Accept.class)); } - } \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java index fb5d61458..1b7cf8c32 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/acl/AclInterfaceAssignmentRequestTest.java @@ -16,19 +16,20 @@ package io.fd.hc2vpp.acl.util.iface.acl; -import static io.fd.hc2vpp.acl.util.iface.acl.AclInterfaceAssignmentRequest.create; +import static io.fd.hc2vpp.acl.write.request.AclInterfaceAssignmentRequest.create; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.collect.ImmutableList; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.acl.write.request.AclInterfaceAssignmentRequest; import io.fd.hc2vpp.common.test.util.FutureProducer; import io.fd.hc2vpp.common.test.util.NamingContextHelper; import io.fd.hc2vpp.common.translate.util.NamingContext; @@ -43,11 +44,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, FutureProducer { @@ -76,7 +74,7 @@ public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, F @Mock private MappingContext mappingContext; - private InstanceIdentifier validIdentifier; + private InstanceIdentifier validIdentifier; private NamingContext interfaceContext; @Mock @@ -86,10 +84,8 @@ public class AclInterfaceAssignmentRequestTest implements NamingContextHelper, F public void setUp() { initMocks(this); - validIdentifier = InstanceIdentifier.create(Interfaces.class). - child(Interface.class, new InterfaceKey(INTERFACE_NAME)) - .augmentation(VppAclInterfaceAugmentation.class) - .child(Acl.class); + validIdentifier = AclIIds.ACLS_AP + .child(Interface.class, new InterfaceKey(INTERFACE_NAME)); interfaceContext = new NamingContext("iface", "interface-context"); diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java index a7049b77f..145eec38e 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/iface/macip/MacIpInterfaceAssignmentRequestTest.java @@ -16,8 +16,8 @@ package io.fd.hc2vpp.acl.util.iface.macip; -import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.addNew; -import static io.fd.hc2vpp.acl.util.iface.macip.MacIpInterfaceAssignmentRequest.deleteExisting; +import static io.fd.hc2vpp.acl.write.request.MacIpInterfaceAssignmentRequest.addNew; +import static io.fd.hc2vpp.acl.write.request.MacIpInterfaceAssignmentRequest.deleteExisting; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -27,7 +27,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.acl.write.request.MacIpInterfaceAssignmentRequest; import io.fd.hc2vpp.common.test.util.FutureProducer; import io.fd.hc2vpp.common.test.util.NamingContextHelper; import io.fd.hc2vpp.common.translate.util.NamingContext; @@ -41,13 +43,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class MacIpInterfaceAssignmentRequestTest implements NamingContextHelper,FutureProducer { @@ -66,7 +63,7 @@ public class MacIpInterfaceAssignmentRequestTest implements NamingContextHelper, @Mock private MappingContext mappingContext; - private InstanceIdentifier validIdentifier; + private InstanceIdentifier validIdentifier; private NamingContext interfaceContext; @Mock private AclContextManager macIpAclContext; @@ -75,12 +72,7 @@ public class MacIpInterfaceAssignmentRequestTest implements NamingContextHelper, public void setUp() throws Exception { initMocks(this); - validIdentifier = InstanceIdentifier.create(Interfaces.class). - child(Interface.class, new InterfaceKey(INTERFACE_NAME)) - .augmentation(VppAclInterfaceAugmentation.class) - .child(Acl.class) - .child(Ingress.class) - .child(VppMacipAcl.class); + validIdentifier = AclIIds.ACLS_AP.child(Interface.class, new InterfaceKey(INTERFACE_NAME)); interfaceContext = new NamingContext("iface", "interface-context"); diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtocolParsingTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtocolParsingTest.java index 08fe6f38b..170080b66 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtocolParsingTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/util/protocol/ProtocolParsingTest.java @@ -24,41 +24,44 @@ import io.fd.honeycomb.test.tools.annotations.InjectTestData; import io.fd.vpp.jvpp.acl.types.AclRule; import org.junit.Test; import org.junit.runner.RunWith; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.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.rev170615.acl.ip.protocol.header.fields.ip.protocol.Icmp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.IcmpV6; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Other; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Tcp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.acl.ip.protocol.header.fields.ip.protocol.Udp; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppIcmpAceAugmentation; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Acls; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.Ace; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Icmp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Tcp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.Udp; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.source.port.source.port.RangeOrOperator; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev181001.port.range.or.operator.port.range.or.operator.Range; @RunWith(HoneycombTestRunner.class) public class ProtocolParsingTest implements ProtoPreBindRuleProducer, IpProtocolReader, 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) { - return VppAce.class - .cast(accessLists.getAcl().get(0).getAccessListEntries().getAce().get(0).getMatches().getAceType()); + private Ace extractAce(Acls acls) { + return acls.getAcl().get(0).getAces().getAce().get(0); } @Test - public void testIcmpRule(@InjectTestData(resourcePath = "/rules/icmp-rule.json") AccessLists acls) { + public void testIcmpRule(@InjectTestData(resourcePath = "/rules/icmp-rule.json") Acls acls) { final AclRule icmpRule = createPreBindRule(extractAce(acls)); assertEquals(1, icmpRule.proto); assertEquals(0, icmpRule.tcpFlagsMask); assertEquals(0, icmpRule.tcpFlagsValue); - final Icmp protocol = (Icmp)parseProtocol(icmpRule); - assertEquals(5, protocol.getIcmpNodes().getIcmpTypeRange().getFirst().shortValue()); - assertEquals(8, protocol.getIcmpNodes().getIcmpTypeRange().getLast().shortValue()); - assertEquals(1, protocol.getIcmpNodes().getIcmpCodeRange().getFirst().shortValue()); - assertEquals(3, protocol.getIcmpNodes().getIcmpCodeRange().getLast().shortValue()); + final Icmp protocol = (Icmp) parseProtocol(icmpRule); + assertEquals(5, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpTypeRange() + .getFirst().shortValue()); + assertEquals(8, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpTypeRange() + .getLast().shortValue()); + assertEquals(1, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpCodeRange() + .getFirst().shortValue()); + assertEquals(3, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpCodeRange() + .getLast().shortValue()); } @Test - public void testIcmpv6Rule(@InjectTestData(resourcePath = "/rules/icmp-v6-rule.json") AccessLists acls) { + public void testIcmpv6Rule(@InjectTestData(resourcePath = "/rules/icmp-v6-rule.json") Acls acls) { final AclRule icmpv6Rule = createPreBindRule(extractAce(acls)); assertEquals(58, icmpv6Rule.proto); @@ -69,43 +72,67 @@ public class ProtocolParsingTest implements ProtoPreBindRuleProducer, IpProtocol assertEquals(0, icmpv6Rule.tcpFlagsMask); assertEquals(0, icmpv6Rule.tcpFlagsValue); - final IcmpV6 protocol = (IcmpV6)parseProtocol(icmpv6Rule); - assertEquals(5, protocol.getIcmpV6Nodes().getIcmpTypeRange().getFirst().shortValue()); - assertEquals(8, protocol.getIcmpV6Nodes().getIcmpTypeRange().getLast().shortValue()); - assertEquals(1, protocol.getIcmpV6Nodes().getIcmpCodeRange().getFirst().shortValue()); - assertEquals(3, protocol.getIcmpV6Nodes().getIcmpCodeRange().getLast().shortValue()); + final Icmp protocol = (Icmp) parseProtocol(icmpv6Rule); + assertEquals(5, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpTypeRange() + .getFirst().shortValue()); + assertEquals(8, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpTypeRange() + .getLast().shortValue()); + assertEquals(1, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpCodeRange() + .getFirst().shortValue()); + assertEquals(3, protocol.getIcmp().augmentation(VppIcmpAceAugmentation.class).getVppIcmpAce().getIcmpCodeRange() + .getLast().shortValue()); } @Test - public void testTcpRule(@InjectTestData(resourcePath = "/rules/tcp-rule.json") AccessLists acls) { + public void testTcpRule(@InjectTestData(resourcePath = "/rules/tcp-rule.json") Acls acls) { final AclRule tcpRule = createPreBindRule(extractAce(acls)); assertEquals(6, tcpRule.proto); assertEquals(1, tcpRule.tcpFlagsMask); assertEquals(7, tcpRule.tcpFlagsValue); - final Tcp protocol = (Tcp)parseProtocol(tcpRule); - assertEquals(1, protocol.getTcpNodes().getSourcePortRange().getLowerPort().getValue().intValue()); - assertEquals(5487, protocol.getTcpNodes().getSourcePortRange().getUpperPort().getValue().intValue()); - assertEquals(87, protocol.getTcpNodes().getDestinationPortRange().getLowerPort().getValue().intValue()); - assertEquals(6745, protocol.getTcpNodes().getDestinationPortRange().getUpperPort().getValue().intValue()); + final Tcp protocol = (Tcp) parseProtocol(tcpRule); + assertEquals(1, + ((Range) ((RangeOrOperator) protocol.getTcp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getLowerPort().getValue().intValue()); + assertEquals(5487, + ((Range) ((RangeOrOperator) protocol.getTcp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getUpperPort().getValue().intValue()); + assertEquals(87, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) protocol + .getTcp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getLowerPort().getValue().intValue()); + assertEquals(6745, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) protocol + .getTcp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getUpperPort().getValue().intValue()); } @Test - public void testTcpRuleNoFlags(@InjectTestData(resourcePath = "/rules/tcp-rule-no-flags.json") AccessLists acls) { + public void testTcpRuleNoFlags(@InjectTestData(resourcePath = "/rules/tcp-rule-no-flags.json") Acls acls) { final AclRule tcpRule = createPreBindRule(extractAce(acls)); assertEquals(6, tcpRule.proto); assertEquals(123, tcpRule.srcportOrIcmptypeFirst); assertEquals(123, tcpRule.srcportOrIcmptypeLast); - assertEquals((short)65000, tcpRule.dstportOrIcmpcodeFirst); - assertEquals((short)65000, tcpRule.dstportOrIcmpcodeLast); + assertEquals((short) 65000, tcpRule.dstportOrIcmpcodeFirst); + assertEquals((short) 65000, tcpRule.dstportOrIcmpcodeLast); assertEquals(0, tcpRule.tcpFlagsMask); assertEquals(0, tcpRule.tcpFlagsValue); - final Tcp protocol = (Tcp)parseProtocol(tcpRule); - assertEquals(123, protocol.getTcpNodes().getSourcePortRange().getLowerPort().getValue().intValue()); - assertEquals(123, protocol.getTcpNodes().getSourcePortRange().getUpperPort().getValue().intValue()); - assertEquals(65000, protocol.getTcpNodes().getDestinationPortRange().getLowerPort().getValue().intValue()); - assertEquals(65000, protocol.getTcpNodes().getDestinationPortRange().getUpperPort().getValue().intValue()); + final Tcp protocol = (Tcp) parseProtocol(tcpRule); + assertEquals(123, + ((Range) ((RangeOrOperator) protocol.getTcp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getLowerPort().getValue().intValue()); + assertEquals(123, + ((Range) ((RangeOrOperator) protocol.getTcp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getUpperPort().getValue().intValue()); + assertEquals(65000, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) protocol + .getTcp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getLowerPort().getValue().intValue()); + assertEquals(65000, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.tcp.tcp.destination.port.destination.port.RangeOrOperator) protocol + .getTcp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getUpperPort().getValue().intValue()); } @Test @@ -125,40 +152,36 @@ public class ProtocolParsingTest implements ProtoPreBindRuleProducer, IpProtocol } @Test - public void testUdpRule(@InjectTestData(resourcePath = "/rules/udp-rule.json") AccessLists acls) { + public void testUdpRule(@InjectTestData(resourcePath = "/rules/udp-rule.json") Acls acls) { final AclRule udpRule = createPreBindRule(extractAce(acls)); assertEquals(17, udpRule.proto); assertEquals(0, udpRule.tcpFlagsMask); assertEquals(0, udpRule.tcpFlagsValue); - final Udp protocol = (Udp)parseProtocol(udpRule); - assertEquals(1, protocol.getUdpNodes().getSourcePortRange().getLowerPort().getValue().intValue()); - assertEquals(5487, protocol.getUdpNodes().getSourcePortRange().getUpperPort().getValue().intValue()); - assertEquals(87, protocol.getUdpNodes().getDestinationPortRange().getLowerPort().getValue().intValue()); - assertEquals(6745, protocol.getUdpNodes().getDestinationPortRange().getUpperPort().getValue().intValue()); + final Udp protocol = (Udp) parseProtocol(udpRule); + assertEquals(1, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.source.port.RangeOrOperator) protocol + .getUdp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getLowerPort().getValue().intValue()); + assertEquals(5487, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.source.port.source.port.RangeOrOperator) protocol + .getUdp().getSourcePort().getSourcePort()).getPortRangeOrOperator()) + .getUpperPort().getValue().intValue()); + assertEquals(87, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.destination.port.RangeOrOperator) protocol + .getUdp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getLowerPort().getValue().intValue()); + assertEquals(6745, + ((Range) ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.acl.aces.ace.matches.l4.udp.udp.destination.port.destination.port.RangeOrOperator) protocol + .getUdp().getDestinationPort().getDestinationPort()) + .getPortRangeOrOperator()).getUpperPort().getValue().intValue()); } - @Test - public void testOtherRule(@InjectTestData(resourcePath = "/rules/other-rule.json") AccessLists acls) { - final AclRule rule = createPreBindRule(extractAce(acls)); - final int protocolNumber = 64; - assertEquals(protocolNumber, rule.proto); - assertEquals(0, rule.srcportOrIcmptypeFirst); - assertEquals((short) 65535, rule.srcportOrIcmptypeLast); - assertEquals(0, rule.dstportOrIcmpcodeFirst); - assertEquals((short) 65535, rule.dstportOrIcmpcodeLast); - assertEquals(0, rule.tcpFlagsMask); - assertEquals(0, rule.tcpFlagsValue); - - final Other protocol = (Other)parseProtocol(rule); - assertEquals(protocolNumber, protocol.getOtherNodes().getProtocol().shortValue()); - } @Test - public void tesProtocolNotSpecified(@InjectTestData(resourcePath = "/rules/no-protocol-rule.json") AccessLists acls) { + public void tesProtocolNotSpecified(@InjectTestData(resourcePath = "/rules/no-protocol-rule.json") Acls 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/java/io/fd/hc2vpp/acl/write/AclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclCustomizerTest.java new file mode 100644 index 000000000..ae7023059 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclCustomizerTest.java @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2016 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.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.acl.AclIIds; +import io.fd.hc2vpp.acl.AclTestSchemaContext; +import io.fd.hc2vpp.acl.util.AclContextManager; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.acl.dto.AclAddReplace; +import io.fd.vpp.jvpp.acl.dto.AclAddReplaceReply; +import io.fd.vpp.jvpp.acl.dto.AclDel; +import io.fd.vpp.jvpp.acl.dto.AclDelReply; +import io.fd.vpp.jvpp.acl.dto.MacipAclAdd; +import io.fd.vpp.jvpp.acl.dto.MacipAclAddReply; +import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import io.fd.vpp.jvpp.acl.types.AclRule; +import io.fd.vpp.jvpp.acl.types.MacipAclRule; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Acls; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@RunWith(HoneycombTestRunner.class) +public class AclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { + + @Mock + private FutureJVppAclFacade aclApi; + + @Captor + private ArgumentCaptor aclAddReplaceRequestCaptor; + + @Captor + private ArgumentCaptor macipAclAddReplaceRequestCaptor; + + @Captor + private ArgumentCaptor aclDelRequestCaptor; + + private InstanceIdentifier validId; + private InstanceIdentifier validMacipId; + private AclCustomizer aclCustomizer; + + @Mock + private AclContextManager standardAclContext; + @Mock + private AclContextManager macIpAclContext; + + + @Override + protected void setUpTest() throws Exception { + validId = AclIIds.ACLS.child(Acl.class, new AclKey("standard-acl")); + validMacipId = AclIIds.ACLS.child(Acl.class, new AclKey("macip-acl")); + aclCustomizer = new AclCustomizer(aclApi, standardAclContext, macIpAclContext); + + when(aclApi.aclAddReplace(any())).thenReturn(future(new AclAddReplaceReply())); + when(aclApi.aclDel(any())).thenReturn(future(new AclDelReply())); + when(aclApi.macipAclAdd(any())).thenReturn(future(new MacipAclAddReply())); + } + + @Test + public void writeCurrentAttributesMacip(@InjectTestData(resourcePath = "/acl/macip/macip-acl.json") + Acls macipAcl) throws WriteFailedException { + + aclCustomizer.writeCurrentAttributes(validMacipId, macipAcl.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).macipAclAdd(macipAclAddReplaceRequestCaptor.capture()); + + final MacipAclAdd request = macipAclAddReplaceRequestCaptor.getValue(); + + assertEquals(1, request.count); + assertEquals("macip-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); + + final MacipAclRule rule = request.r[0]; + + assertEquals(0, rule.isIpv6); + assertEquals(1, rule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, rule.srcIpAddr)); + assertEquals(32, rule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa}, rule.srcMac)); + assertTrue(Arrays.equals(new byte[]{(byte)0xff, 0, 0, 0, 0, 0}, rule.srcMacMask)); + } + + @Test + public void writeCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + Acls standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpIpv4Request(-1); + } + + @Test + public void updateCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + Acls standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpIpv4Request(aclIndex); + } + + + @Test + public void writeCurrentAttributesIcmpIpv6(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + Acls standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpv6Request(-1); + } + + @Test + public void updateCurrentAttributesIcmpIpv6( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + Acls standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyIcmpv6Request(aclIndex); + } + + + @Test + public void writeCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + Acls standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyTcpRequest(-1); + } + + @Test + public void updateCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + Acls standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyTcpRequest(aclIndex); + } + + @Test + public void updateCurrentAttributesTcpSrcOnly( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp-src-only.json") + Acls standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + final AclRule tcpRule = request.r[0]; + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); + assertEquals(32, tcpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{0, 0, 0, 0}, tcpRule.dstIpAddr)); + assertEquals(0, tcpRule.dstIpPrefixLen); + } + + + @Test + public void writeCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + Acls standardAcls) throws Exception { + aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + + verifyUdpRequest(-1); + } + + @Test + public void updateCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + Acls standardAcls) throws Exception { + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + final Acl data = standardAcls.getAcl().get(0); + aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); + + verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); + verifyUdpRequest(aclIndex); + } + + + @Test + public void deleteCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") + Acls standardAcls) throws Exception { + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesIcmpIpv6( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") + Acls standardAcls) throws Exception { + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") + Acls standardAcls) throws Exception { + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); + } + + @Test + public void deleteCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + Acls standardAcls) throws Exception { + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + final int aclIndex = 4; + when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); + aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); + + verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); + assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); + } + + private void verifyUdpRequest(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertEquals("udp-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); + + final AclRule udpRule = request.r[0]; + + assertEquals(0, udpRule.isIpv6); + assertEquals(1, udpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, udpRule.srcIpAddr)); + assertEquals(32, udpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, udpRule.dstIpAddr)); + assertEquals(24, udpRule.dstIpPrefixLen); + + assertEquals(17, udpRule.proto); + assertEquals(1, udpRule.srcportOrIcmptypeFirst); + assertEquals(5487, udpRule.srcportOrIcmptypeLast); + assertEquals(87, udpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, udpRule.dstportOrIcmpcodeLast); + assertEquals(0, udpRule.tcpFlagsMask); + assertEquals(0, udpRule.tcpFlagsValue); + } + + private void verifyTcpRequest(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertEquals("tcp-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); + + final AclRule tcpRule = request.r[0]; + + assertEquals(0, tcpRule.isIpv6); + assertEquals(1, tcpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); + assertEquals(32, tcpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, tcpRule.dstIpAddr)); + assertEquals(24, tcpRule.dstIpPrefixLen); + + assertEquals(6, tcpRule.proto); + assertEquals(1, tcpRule.srcportOrIcmptypeFirst); + assertEquals(5487, tcpRule.srcportOrIcmptypeLast); + assertEquals(87, tcpRule.dstportOrIcmpcodeFirst); + assertEquals(6745, tcpRule.dstportOrIcmpcodeLast); + assertEquals(1, tcpRule.tcpFlagsMask); + assertEquals(7, tcpRule.tcpFlagsValue); + } + + private void verifyIcmpv6Request(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertEquals("icmp-v6-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); + + + final AclRule icmpv6Rule = request.r[0]; + + assertEquals(1, icmpv6Rule.isIpv6); + assertEquals(1, icmpv6Rule.isPermit); + assertTrue( + Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2}, + icmpv6Rule.srcIpAddr)); + assertEquals(48, icmpv6Rule.srcIpPrefixLen); + assertTrue( + Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}, + icmpv6Rule.dstIpAddr)); + assertEquals(64, icmpv6Rule.dstIpPrefixLen); + + assertEquals(58, icmpv6Rule.proto); + assertEquals(5, icmpv6Rule.srcportOrIcmptypeFirst); + assertEquals(8, icmpv6Rule.srcportOrIcmptypeLast); + assertEquals(1, icmpv6Rule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpv6Rule.dstportOrIcmpcodeLast); + assertEquals(0, icmpv6Rule.tcpFlagsMask); + assertEquals(0, icmpv6Rule.tcpFlagsValue); + } + + private void verifyIcmpIpv4Request(final int aclIndex) { + final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); + assertEquals(aclIndex, request.aclIndex); + assertEquals(1, request.count); + assertEquals("icmp-v4-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); + + final AclRule icmpRule = request.r[0]; + + assertEquals(0, icmpRule.isIpv6); + assertEquals(1, icmpRule.isPermit); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, icmpRule.srcIpAddr)); + assertEquals(32, icmpRule.srcIpPrefixLen); + assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, icmpRule.dstIpAddr)); + assertEquals(24, icmpRule.dstIpPrefixLen); + + assertEquals(1, icmpRule.proto); + assertEquals(5, icmpRule.srcportOrIcmptypeFirst); + assertEquals(8, icmpRule.srcportOrIcmptypeLast); + assertEquals(1, icmpRule.dstportOrIcmpcodeFirst); + assertEquals(3, icmpRule.dstportOrIcmpcodeLast); + assertEquals(0, icmpRule.tcpFlagsMask); + assertEquals(0, icmpRule.tcpFlagsValue); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclValidatorTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclValidatorTest.java new file mode 100644 index 000000000..6f4d8556f --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/AclValidatorTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2018 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.write; + +import static io.fd.hc2vpp.acl.write.AclValidator.checkAclReferenced; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.acl.AclIIds; +import io.fd.hc2vpp.acl.AclTestSchemaContext; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.HashSet; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppAcl; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.acl.rev181022.VppMacipAcl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.Acls; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.Acl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AclKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AttachmentPoints; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.AttachmentPointsBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@RunWith(HoneycombTestRunner.class) +public class AclValidatorTest implements AclTestSchemaContext { + + private static final InstanceIdentifier ID = AclIIds.ACLS + .child(Acl.class, new AclKey("standard-acl")); + + @InjectTestData(id = "/ietf-access-control-list:acls/ietf-access-control-list:attachment-points", resourcePath = "/interface-acl/acl-references.json") + private AttachmentPoints attachmentPoints; + + @Mock + private WriteContext writeContext; + + private AclValidator validator; + + @Before + public void init(){ + initMocks(this); + when(writeContext.readAfter(AclIIds.ACLS_AP)).thenReturn(Optional.of(attachmentPoints)); + validator = new AclValidator(); + } + + @Test + public void testValidateWrite( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") Acls acls) + throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, acls.getAcl().get(0), writeContext); + } + + @Test(expected = DataValidationFailedException.CreateValidationFailedException.class) + public void testValidateWriteEmptyAcl() + throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, new AclBuilder().build(), writeContext); + } + + @Test + public void testValidateUpdate( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") Acls acls) + throws DataValidationFailedException.UpdateValidationFailedException { + final Acl data = acls.getAcl().get(0); + validator.validateUpdate(ID, data, data, writeContext); + } + + @Test(expected = DataValidationFailedException.UpdateValidationFailedException.class) + public void testValidateUpdateUnsupportedType( + @InjectTestData(resourcePath = "/acl/ipv4/ipv4-acl.json") Acls acls) + throws DataValidationFailedException.UpdateValidationFailedException { + final Acl data = acls.getAcl().get(0); + validator.validateUpdate(ID, data, data, writeContext); + } + + @Test + public void testValidateDelete( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") Acls acls) + throws DataValidationFailedException.DeleteValidationFailedException { + validator.validateDelete(ID, acls.getAcl().get(0), writeContext); + } + + @Test(expected = DataValidationFailedException.DeleteValidationFailedException.class) + public void testValidateDeleteReferenced( + @InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") + Acls standardAcls, + @InjectTestData(id = "/ietf-access-control-list:acls/ietf-access-control-list:attachment-points", + resourcePath = "/acl/standard/interface-ref-acl-udp.json") + AttachmentPoints references) throws Exception { + when(writeContext.readAfter(AclIIds.ACLS_AP)).thenReturn( + Optional.of(new AttachmentPointsBuilder().setInterface(references.getInterface()).build())); + validator.validateDelete(ID, standardAcls.getAcl().get(0), writeContext); + } + + @Test + public void testReferencedVppAclFirst() { + final List referenced = checkAclReferenced(writeContext, new AclBuilder() + .setName("acl1").setType(VppAcl.class).build()); + assertThat(referenced, hasSize(3)); + assertThat(new HashSet<>(referenced), containsInAnyOrder("eth0", "eth1", "eth2")); + } + + @Test + public void testReferencedVppAclSecond() { + final List referenced = checkAclReferenced(writeContext, new AclBuilder() + .setName("acl2").setType(VppAcl.class).build()); + assertThat(referenced, hasSize(1)); + assertThat(new HashSet<>(referenced), containsInAnyOrder("eth1")); + } + + @Test + public void testReferencedMacipAcl() { + final List referenced = checkAclReferenced(writeContext, new AclBuilder() + .setName("acl4").setType(VppMacipAcl.class).build()); + assertThat(referenced, hasSize(1)); + assertThat(new HashSet<>(referenced), containsInAnyOrder("eth2")); + } +} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java index 5dc139acc..b6c26ceeb 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizerTest.java @@ -17,10 +17,10 @@ package io.fd.hc2vpp.acl.write; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.AclTestSchemaContext; import io.fd.hc2vpp.acl.util.AclContextManager; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; @@ -31,15 +31,12 @@ import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; import java.util.Collections; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.IngressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfaceAclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { @@ -47,61 +44,70 @@ public class InterfaceAclCustomizerTest extends WriterCustomizerTest implements private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IFACE_NAME = "eth0"; private static final int IFACE_ID = 123; + private static final int ACL_ID = 111; @Mock private FutureJVppAclFacade aclApi; @Mock private AclContextManager standardAclContext; + @Mock + private AclContextManager macipAclContext; private InterfaceAclCustomizer customizer; - private NamingContext interfaceContext; - private InstanceIdentifier ACL_ID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)).augmentation(VppAclInterfaceAugmentation.class).child(Acl.class); + private InstanceIdentifier IFC_IID = + AclIIds.ACLS_AP.child(Interface.class, new InterfaceKey(IFACE_NAME)); + private Interface ifcAcl; + private static final String ACL_NAME = "standard_acl"; + @Override - protected void setUpTest() throws Exception { + protected void setUpTest() { defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - customizer = new InterfaceAclCustomizer(aclApi, interfaceContext, standardAclContext); + final NamingContext interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + customizer = new InterfaceAclCustomizer(aclApi, interfaceContext, standardAclContext, macipAclContext); + ifcAcl = new InterfaceBuilder() + .setIngress(new IngressBuilder() + .setAclSets(new AclSetsBuilder() + .setAclSet(Collections.singletonList(new AclSetBuilder() + .setName(ACL_NAME) + .build())) + .build()) + .build()) + .build(); + when(standardAclContext.getAclIndex(ACL_NAME, mappingContext)).thenReturn(ACL_ID); + when(standardAclContext.containsAcl(ACL_NAME, mappingContext)).thenReturn(true); when(aclApi.aclInterfaceSetAclList(any())).thenReturn(future(new AclInterfaceSetAclListReply())); } @Test public void testWrite() throws Exception { - final Acl acl = new AclBuilder().build(); - customizer.writeCurrentAttributes(ACL_ID, acl, writeContext); + customizer.writeCurrentAttributes(IFC_IID, ifcAcl, writeContext); final AclInterfaceSetAclList list = new AclInterfaceSetAclList(); list.swIfIndex = IFACE_ID; - list.acls = new int[]{}; + list.acls = new int[]{ACL_ID}; + list.count = 1; + list.nInput = 1; verify(aclApi).aclInterfaceSetAclList(list); } @Test public void testUpdate() throws Exception { - final Acl acl = new AclBuilder().build(); - customizer.updateCurrentAttributes(ACL_ID, acl, acl, writeContext); + final Interface updIfcAcl = new InterfaceBuilder().build(); + customizer.updateCurrentAttributes(IFC_IID, updIfcAcl, ifcAcl, writeContext); final AclInterfaceSetAclList list = new AclInterfaceSetAclList(); list.swIfIndex = IFACE_ID; - list.acls = new int[]{}; + list.acls = new int[]{ACL_ID}; + list.count = 1; + list.nInput = 1; verify(aclApi).aclInterfaceSetAclList(list); } @Test public void testDelete() throws Exception { - final VppAcls - element = mock(VppAcls.class); - final Acl acl = new AclBuilder() - .setIngress(new IngressBuilder() - .setVppAcls(Collections.singletonList(new VppAclsBuilder() - .setName("asd") - .build())) - .build()) - .build(); - customizer.deleteCurrentAttributes(ACL_ID, acl, writeContext); + customizer.deleteCurrentAttributes(IFC_IID, ifcAcl, writeContext); final AclInterfaceSetAclList list = new AclInterfaceSetAclList(); list.swIfIndex = IFACE_ID; list.acls = new int[]{}; verify(aclApi).aclInterfaceSetAclList(list); } - } \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclMacipCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclMacipCustomizerTest.java index b5fa649ca..af3deaca2 100644 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclMacipCustomizerTest.java +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/InterfaceAclMacipCustomizerTest.java @@ -20,23 +20,24 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.fd.hc2vpp.acl.AclIIds; import io.fd.hc2vpp.acl.AclTestSchemaContext; import io.fd.hc2vpp.acl.util.AclContextManager; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclListReply; import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceAddDel; import io.fd.vpp.jvpp.acl.dto.MacipAclInterfaceAddDelReply; import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import java.util.Collections; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.Acl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214._interface.acl.attributes.acl.Ingress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.macip.acls.base.attributes.VppMacipAclBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.IngressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.AclSetsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev181001.acls.attachment.points._interface.acl.acl.sets.AclSetBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfaceAclMacipCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { @@ -51,27 +52,31 @@ public class InterfaceAclMacipCustomizerTest extends WriterCustomizerTest implem private FutureJVppAclFacade aclApi; @Mock private AclContextManager macipAclContext; + @Mock + private AclContextManager standardAclContext; - private InterfaceAclMacIpCustomizer customizer; + private InterfaceAclCustomizer customizer; private NamingContext interfaceContext; - private InstanceIdentifier ACL_IID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)).augmentation(VppAclInterfaceAugmentation.class) - .child(Acl.class).child(Ingress.class).child(VppMacipAcl.class); - private VppMacipAcl acl; + private InstanceIdentifier IFC_IID = + AclIIds.ACLS_AP.child(Interface.class, new InterfaceKey(IFACE_NAME)); + private Interface ifcAcl; @Override protected void setUpTest() throws Exception { defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - customizer = new InterfaceAclMacIpCustomizer(aclApi, macipAclContext, interfaceContext); - acl = new VppMacipAclBuilder().setName(ACL_NAME).build(); + customizer = new InterfaceAclCustomizer(aclApi, interfaceContext, standardAclContext, macipAclContext); + ifcAcl = new InterfaceBuilder().setIngress(new IngressBuilder().setAclSets(new AclSetsBuilder().setAclSet( + Collections.singletonList(new AclSetBuilder().setName(ACL_NAME).build())).build()).build()).build(); when(macipAclContext.getAclIndex(ACL_NAME, mappingContext)).thenReturn(ACL_ID); + when(macipAclContext.containsAcl(ACL_NAME, mappingContext)).thenReturn(true); when(aclApi.macipAclInterfaceAddDel(any())).thenReturn(future(new MacipAclInterfaceAddDelReply())); + when(aclApi.aclInterfaceSetAclList(any())).thenReturn(future(new AclInterfaceSetAclListReply())); } @Test public void testWrite() throws Exception { - customizer.writeCurrentAttributes(ACL_IID, acl, writeContext); + customizer.writeCurrentAttributes(IFC_IID, ifcAcl, writeContext); final MacipAclInterfaceAddDel request = new MacipAclInterfaceAddDel(); request.swIfIndex = IFACE_ID; request.isAdd = 1; @@ -79,19 +84,19 @@ public class InterfaceAclMacipCustomizerTest extends WriterCustomizerTest implem verify(aclApi).macipAclInterfaceAddDel(request); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testUpdate() throws Exception { - customizer.updateCurrentAttributes(ACL_IID, acl, acl, writeContext); + customizer.updateCurrentAttributes(IFC_IID, ifcAcl, ifcAcl, writeContext); + verify(aclApi).aclInterfaceSetAclList(any()); } @Test public void testDelete() throws Exception { - customizer.deleteCurrentAttributes(ACL_IID, acl, writeContext); + customizer.deleteCurrentAttributes(IFC_IID, ifcAcl, writeContext); final MacipAclInterfaceAddDel request = new MacipAclInterfaceAddDel(); request.swIfIndex = IFACE_ID; request.isAdd = 0; request.aclIndex = ACL_ID; verify(aclApi).macipAclInterfaceAddDel(request); } - } \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java deleted file mode 100644 index a3fa6db0e..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclCustomizerTest.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright (c) 2016 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.write; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.acl.AclTestSchemaContext; -import io.fd.hc2vpp.acl.util.AclContextManager; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.honeycomb.test.tools.HoneycombTestRunner; -import io.fd.honeycomb.test.tools.annotations.InjectTestData; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.acl.dto.AclAddReplace; -import io.fd.vpp.jvpp.acl.dto.AclAddReplaceReply; -import io.fd.vpp.jvpp.acl.dto.AclDel; -import io.fd.vpp.jvpp.acl.dto.AclDelReply; -import io.fd.vpp.jvpp.acl.dto.MacipAclAdd; -import io.fd.vpp.jvpp.acl.dto.MacipAclAddReply; -import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; -import io.fd.vpp.jvpp.acl.types.AclRule; -import io.fd.vpp.jvpp.acl.types.MacipAclRule; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -@RunWith(HoneycombTestRunner.class) -public class VppAclCustomizerTest extends WriterCustomizerTest implements AclTestSchemaContext { - - @Mock - private FutureJVppAclFacade aclApi; - - @Captor - private ArgumentCaptor aclAddReplaceRequestCaptor; - - @Captor - private ArgumentCaptor macipAclAddReplaceRequestCaptor; - - @Captor - private ArgumentCaptor aclDelRequestCaptor; - - private InstanceIdentifier validId; - private InstanceIdentifier validMacipId; - private VppAclCustomizer aclCustomizer; - - @Mock - private AclContextManager standardAclContext; - @Mock - private AclContextManager macIpAclContext; - - - @Override - protected void setUpTest() throws Exception { - validId = - InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey("standard-acl", VppAcl.class)); - validMacipId = - InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey("macip-acl", VppAcl.class)); - aclCustomizer = new VppAclCustomizer(aclApi, standardAclContext, macIpAclContext); - - when(aclApi.aclAddReplace(any())).thenReturn(future(new AclAddReplaceReply())); - when(aclApi.aclDel(any())).thenReturn(future(new AclDelReply())); - when(aclApi.macipAclAdd(any())).thenReturn(future(new MacipAclAddReply())); - } - - @Test - public void writeCurrentAttributesMacip(@InjectTestData(resourcePath = "/acl/macip/macip-acl.json") - AccessLists macipAcl) throws WriteFailedException { - - aclCustomizer.writeCurrentAttributes(validMacipId, macipAcl.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).macipAclAdd(macipAclAddReplaceRequestCaptor.capture()); - - final MacipAclAdd request = macipAclAddReplaceRequestCaptor.getValue(); - - assertEquals(1, request.count); - assertEquals("macip-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); - - final MacipAclRule rule = request.r[0]; - - assertEquals(0, rule.isIpv6); - assertEquals(1, rule.isPermit); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, rule.srcIpAddr)); - assertEquals(32, rule.srcIpPrefixLen); - assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa, (byte)0xaa}, rule.srcMac)); - assertTrue(Arrays.equals(new byte[]{(byte)0xff, 0, 0, 0, 0, 0}, rule.srcMacMask)); - } - - @Test - public void writeCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") - AccessLists standardAcls) throws Exception { - aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyIcmpIpv4Request(-1); - } - - @Test - public void updateCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") - AccessLists standardAcls) throws Exception { - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - final Acl data = standardAcls.getAcl().get(0); - - aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyIcmpIpv4Request(aclIndex); - } - - - @Test - public void writeCurrentAttributesIcmpIpv6(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") - AccessLists standardAcls) throws Exception { - aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyIcmpv6Request(-1); - } - - @Test - public void updateCurrentAttributesIcmpIpv6( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") - AccessLists standardAcls) throws Exception { - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - final Acl data = standardAcls.getAcl().get(0); - aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyIcmpv6Request(aclIndex); - } - - - @Test - public void writeCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") - AccessLists standardAcls) throws Exception { - aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyTcpRequest(-1); - } - - @Test - public void updateCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") - AccessLists standardAcls) throws Exception { - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - final Acl data = standardAcls.getAcl().get(0); - aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyTcpRequest(aclIndex); - } - - @Test - public void updateCurrentAttributesTcpSrcOnly(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp-src-only.json") - AccessLists standardAcls) throws Exception { - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - final Acl data = standardAcls.getAcl().get(0); - aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); - final AclRule tcpRule = request.r[0]; - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); - assertEquals(32, tcpRule.srcIpPrefixLen); - assertTrue(Arrays.equals(new byte[]{0, 0, 0, 0}, tcpRule.dstIpAddr)); - assertEquals(0, tcpRule.dstIpPrefixLen); - } - - - @Test - public void writeCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") - AccessLists standardAcls) throws Exception { - aclCustomizer.writeCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - - verifyUdpRequest(-1); - } - - @Test - public void updateCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") - AccessLists standardAcls) throws Exception { - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - final Acl data = standardAcls.getAcl().get(0); - aclCustomizer.updateCurrentAttributes(validId, data, data, writeContext); - - verify(aclApi, times(1)).aclAddReplace(aclAddReplaceRequestCaptor.capture()); - verifyUdpRequest(aclIndex); - } - - - @Test - public void deleteCurrentAttributesIcmpIpv4(@InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") - AccessLists standardAcls) throws Exception { - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); - assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); - } - - @Test - public void deleteCurrentAttributesIcmpIpv6( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp-v6.json") - AccessLists standardAcls) throws Exception { - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); - assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); - } - - @Test - public void deleteCurrentAttributesTcp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-tcp.json") - AccessLists standardAcls) throws Exception { - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); - assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); - } - - @Test - public void deleteCurrentAttributesUdp(@InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") - AccessLists standardAcls) throws Exception { - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - final int aclIndex = 4; - when(standardAclContext.getAclIndex("standard-acl", mappingContext)).thenReturn(aclIndex); - aclCustomizer.deleteCurrentAttributes(validId, standardAcls.getAcl().get(0), writeContext); - - verify(aclApi, times(1)).aclDel(aclDelRequestCaptor.capture()); - assertEquals(aclIndex, aclDelRequestCaptor.getValue().aclIndex); - } - - private void verifyUdpRequest(final int aclIndex) { - final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); - assertEquals(aclIndex, request.aclIndex); - assertEquals(1, request.count); - assertEquals("udp-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); - - final AclRule udpRule = request.r[0]; - - assertEquals(0, udpRule.isIpv6); - assertEquals(1, udpRule.isPermit); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, udpRule.srcIpAddr)); - assertEquals(32, udpRule.srcIpPrefixLen); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, udpRule.dstIpAddr)); - assertEquals(24, udpRule.dstIpPrefixLen); - - assertEquals(17, udpRule.proto); - assertEquals(1, udpRule.srcportOrIcmptypeFirst); - assertEquals(5487, udpRule.srcportOrIcmptypeLast); - assertEquals(87, udpRule.dstportOrIcmpcodeFirst); - assertEquals(6745, udpRule.dstportOrIcmpcodeLast); - assertEquals(0, udpRule.tcpFlagsMask); - assertEquals(0, udpRule.tcpFlagsValue); - } - - private void verifyTcpRequest(final int aclIndex) { - final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); - assertEquals(aclIndex, request.aclIndex); - assertEquals(1, request.count); - assertEquals("tcp-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); - - final AclRule tcpRule = request.r[0]; - - assertEquals(0, tcpRule.isIpv6); - assertEquals(1, tcpRule.isPermit); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, tcpRule.srcIpAddr)); - assertEquals(32, tcpRule.srcIpPrefixLen); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, tcpRule.dstIpAddr)); - assertEquals(24, tcpRule.dstIpPrefixLen); - - assertEquals(6, tcpRule.proto); - assertEquals(1, tcpRule.srcportOrIcmptypeFirst); - assertEquals(5487, tcpRule.srcportOrIcmptypeLast); - assertEquals(87, tcpRule.dstportOrIcmpcodeFirst); - assertEquals(6745, tcpRule.dstportOrIcmpcodeLast); - assertEquals(1, tcpRule.tcpFlagsMask); - assertEquals(7, tcpRule.tcpFlagsValue); - } - - private void verifyIcmpv6Request(final int aclIndex) { - final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); - assertEquals(aclIndex, request.aclIndex); - assertEquals(1, request.count); - assertEquals("icmp-v6-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); - - - final AclRule icmpv6Rule = request.r[0]; - - assertEquals(1, icmpv6Rule.isIpv6); - assertEquals(1, icmpv6Rule.isPermit); - assertTrue( - Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2}, - icmpv6Rule.srcIpAddr)); - assertEquals(48, icmpv6Rule.srcIpPrefixLen); - assertTrue( - Arrays.equals(new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}, - icmpv6Rule.dstIpAddr)); - assertEquals(64, icmpv6Rule.dstIpPrefixLen); - - assertEquals(58, icmpv6Rule.proto); - assertEquals(5, icmpv6Rule.srcportOrIcmptypeFirst); - assertEquals(8, icmpv6Rule.srcportOrIcmptypeLast); - assertEquals(1, icmpv6Rule.dstportOrIcmpcodeFirst); - assertEquals(3, icmpv6Rule.dstportOrIcmpcodeLast); - assertEquals(0, icmpv6Rule.tcpFlagsMask); - assertEquals(0, icmpv6Rule.tcpFlagsValue); - } - - private void verifyIcmpIpv4Request(final int aclIndex) { - final AclAddReplace request = aclAddReplaceRequestCaptor.getValue(); - assertEquals(aclIndex, request.aclIndex); - assertEquals(1, request.count); - assertEquals("icmp-v4-tag-value", new String(request.tag, StandardCharsets.US_ASCII)); - - final AclRule icmpRule = request.r[0]; - - assertEquals(0, icmpRule.isIpv6); - assertEquals(1, icmpRule.isPermit); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 2}, icmpRule.srcIpAddr)); - assertEquals(32, icmpRule.srcIpPrefixLen); - assertTrue(Arrays.equals(new byte[]{-64, -88, 2, 1}, icmpRule.dstIpAddr)); - assertEquals(24, icmpRule.dstIpPrefixLen); - - assertEquals(1, icmpRule.proto); - assertEquals(5, icmpRule.srcportOrIcmptypeFirst); - assertEquals(8, icmpRule.srcportOrIcmptypeLast); - assertEquals(1, icmpRule.dstportOrIcmpcodeFirst); - assertEquals(3, icmpRule.dstportOrIcmpcodeLast); - assertEquals(0, icmpRule.tcpFlagsMask); - assertEquals(0, icmpRule.tcpFlagsValue); - } -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java deleted file mode 100644 index 287e53f80..000000000 --- a/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/write/VppAclValidatorTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2018 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.write; - -import static io.fd.hc2vpp.acl.write.VppAclValidator.checkAclReferenced; -import static java.util.stream.Collectors.toSet; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.acl.AclTestSchemaContext; -import io.fd.honeycomb.test.tools.HoneycombTestRunner; -import io.fd.honeycomb.test.tools.annotations.InjectTestData; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppMacipAcl; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -@RunWith(HoneycombTestRunner.class) -public class VppAclValidatorTest implements AclTestSchemaContext { - - private static final InstanceIdentifier ID = InstanceIdentifier.create(AccessLists.class) - .child(Acl.class, new AclKey("standard-acl", VppAcl.class)); - - @InjectTestData(id = "/ietf-interfaces:interfaces", resourcePath = "/interface-acl/acl-references.json") - private Interfaces interfaces; - - @Mock - private WriteContext writeContext; - - private VppAclValidator validator; - - @Before - public void init(){ - initMocks(this); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of(interfaces)); - validator = new VppAclValidator(); - } - - @Test - public void testValidateWrite( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) - throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, acls.getAcl().get(0), writeContext); - } - - @Test(expected = DataValidationFailedException.CreateValidationFailedException.class) - public void testValidateWriteEmptyAcl() - throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, new AclBuilder().build(), writeContext); - } - - @Test - public void testValidateUpdate( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) - throws DataValidationFailedException.UpdateValidationFailedException { - final Acl data = acls.getAcl().get(0); - validator.validateUpdate(ID, data, data, writeContext); - } - - @Test(expected = DataValidationFailedException.UpdateValidationFailedException.class) - public void testValidateUpdateUnsupportedType( - @InjectTestData(resourcePath = "/acl/ipv4/ipv4-acl.json") AccessLists acls) - throws DataValidationFailedException.UpdateValidationFailedException { - final Acl data = acls.getAcl().get(0); - validator.validateUpdate(ID, data, data, writeContext); - } - - @Test - public void testValidateDelete( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-icmp.json") AccessLists acls) - throws DataValidationFailedException.DeleteValidationFailedException { - validator.validateDelete(ID, acls.getAcl().get(0), writeContext); - } - - @Test(expected = DataValidationFailedException.DeleteValidationFailedException.class) - public void testValidateDeleteReferenced( - @InjectTestData(resourcePath = "/acl/standard/standard-acl-udp.json") - AccessLists standardAcls, - @InjectTestData(resourcePath = "/acl/standard/interface-ref-acl-udp.json") - Interfaces references) throws Exception { - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn( - Optional.of(new InterfacesBuilder().setInterface(references.getInterface()).build())); - validator.validateDelete(ID, standardAcls.getAcl().get(0), writeContext); - } - - @Test - public void testReferencedVppAclFirst() { - final List referenced = checkAclReferenced(writeContext, new AclBuilder() - .setAclName("acl1").setAclType(VppAcl.class).build()); - assertThat(referenced, hasSize(3)); - assertThat(referenced.stream().map(Interface::getName).collect(toSet()), - containsInAnyOrder("eth0", "eth1", "eth2")); - } - - @Test - public void testReferencedVppAclSecond() { - final List referenced = checkAclReferenced(writeContext, new AclBuilder() - .setAclName("acl2").setAclType(VppAcl.class).build()); - assertThat(referenced, hasSize(1)); - assertThat(referenced.stream().map(Interface::getName).collect(toSet()), - containsInAnyOrder("eth1")); - } - - @Test - public void testReferencedMacipAcl() { - final List referenced = checkAclReferenced(writeContext, new AclBuilder() - .setAclName("acl4").setAclType(VppMacipAcl.class).build()); - assertThat(referenced, hasSize(1)); - assertThat(referenced.stream().map(Interface::getName).collect(toSet()), - containsInAnyOrder("eth2")); - } -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/resources/acl/ipv4/ipv4-acl.json b/acl/acl-impl/src/test/resources/acl/ipv4/ipv4-acl.json index 04a08ff44..9946bc4f7 100644 --- a/acl/acl-impl/src/test/resources/acl/ipv4/ipv4-acl.json +++ b/acl/acl-impl/src/test/resources/acl/ipv4/ipv4-acl.json @@ -1,13 +1,13 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "ipv4-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "ipv4-acl-type", + "aces": { "ace": [ { - "rule-name": "rule1" + "name": "rule1" } ] } diff --git a/acl/acl-impl/src/test/resources/acl/macip/macip-acl.json b/acl/acl-impl/src/test/resources/acl/macip/macip-acl.json index 21ac2597c..bcde22d6b 100644 --- a/acl/acl-impl/src/test/resources/acl/macip/macip-acl.json +++ b/acl/acl-impl/src/test/resources/acl/macip/macip-acl.json @@ -1,23 +1,25 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "macip-acl", - "acl-type": "vpp-acl:vpp-macip-acl", + "name": "macip-acl", + "type": "vpp-acl:vpp-macip-acl", "tag": "macip-tag-value", - "access-list-entries": { + "aces": { "ace": [ { - "rule-name": "macip-rule", + "name": "macip-rule", "matches": { - "vpp-macip-ace-nodes": { - "source-ipv4-network": "192.168.2.2/32", + "eth": { "source-mac-address": "aa:aa:aa:aa:aa:aa", "source-mac-address-mask": "ff:00:00:00:00:00" + }, + "ipv4": { + "source-ipv4-network": "192.168.2.2/32" } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/acl/standard/interface-ref-acl-udp.json b/acl/acl-impl/src/test/resources/acl/standard/interface-ref-acl-udp.json index ae987a798..060551b9b 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/interface-ref-acl-udp.json +++ b/acl/acl-impl/src/test/resources/acl/standard/interface-ref-acl-udp.json @@ -1,21 +1,21 @@ { - "interfaces":{ - "interface": [{ - "name": "eth2", - "acl": { + "attachment-points": { + "interface": [ + { + "interface-id": "eth2", "ingress": { - "vpp-acls": [ - { - "type": "vpp-acl:vpp-acl", - "name": "standard-acl" - } - ], - "vpp-macip-acl": { - "name": "acl4", - "type": "vpp-acl:vpp-macip-acl" + "acl-sets": { + "acl-set": [ + { + "name": "standard-acl" + }, + { + "name": "acl4" + } + ] } } } - }] + ] } } \ No newline at end of file diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp-v6.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp-v6.json index 9c6530fa9..5973741ed 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp-v6.json +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp-v6.json @@ -1,24 +1,26 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", "tag": "icmp-v6-tag-value", - "access-list-entries": { + "aces": { "ace": [ { - "rule-name": "imcp-v6-rule", + "name": "imcp-v6-rule", "matches": { - "vpp-ace-nodes": { - "destination-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64", + "ipv6": { "source-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0002/48", - "icmp-v6-nodes": { - "icmp-type-range": { + "destination-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64" + }, + "icmp": { + "vpp-acl:vpp-icmp-ace": { + "vpp-acl:icmp-type-range": { "first": "5", "last": "8" }, - "icmp-code-range": { + "vpp-acl:icmp-code-range": { "first": "1", "last": "3" } @@ -26,7 +28,7 @@ } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp.json index 73a9a6543..cc534f4b4 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp.json +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-icmp.json @@ -1,24 +1,26 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", "tag": "icmp-v4-tag-value", - "access-list-entries": { + "aces": { "ace": [ { - "rule-name": "imcp-rule", + "name": "imcp-rule", "matches": { - "vpp-ace-nodes": { - "destination-ipv4-network": "192.168.2.1/24", + "ipv4": { "source-ipv4-network": "192.168.2.2/32", - "icmp-nodes": { - "icmp-type-range": { + "destination-ipv4-network": "192.168.2.1/24" + }, + "icmp": { + "vpp-acl:vpp-icmp-ace": { + "vpp-acl:icmp-type-range": { "first": "5", "last": "8" }, - "icmp-code-range": { + "vpp-acl:icmp-code-range": { "first": "1", "last": "3" } @@ -26,7 +28,7 @@ } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json index 13e757907..9d9b396ba 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp-src-only.json @@ -1,32 +1,34 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "tcp-rule", + "name": "tcp-rule", "matches": { - "vpp-ace-nodes": { - "source-ipv4-network": "192.168.2.2/32", - "tcp-nodes": { - "source-port-range": { - "lower-port": "1", - "upper-port": "5487" - }, - "destination-port-range": { - "lower-port": "87", - "upper-port": "6745" - }, - "tcp-flags-mask": "1", - "tcp-flags-value": "7" + "ipv4": { + "source-ipv4-network": "192.168.2.2/32" + }, + "tcp": { + "source-port": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port": { + "lower-port": "87", + "upper-port": "6745" + }, + "flags": "cwr ece urg", + "vpp-acl:vpp-tcp-ace": { + "vpp-acl:flags-mask": "cwr" } } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp.json index 6b5dbafc7..35ad4b1da 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp.json +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-tcp.json @@ -1,34 +1,36 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", "tag": "tcp-tag-value", - "access-list-entries": { + "aces": { "ace": [ { - "rule-name": "tcp-rule", + "name": "tcp-rule", "matches": { - "vpp-ace-nodes": { + "ipv4": { "destination-ipv4-network": "192.168.2.1/24", - "source-ipv4-network": "192.168.2.2/32", - "tcp-nodes": { - "source-port-range": { - "lower-port": "1", - "upper-port": "5487" - }, - "destination-port-range": { - "lower-port": "87", - "upper-port": "6745" - }, - "tcp-flags-mask": "1", - "tcp-flags-value": "7" + "source-ipv4-network": "192.168.2.2/32" + }, + "tcp": { + "source-port": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port": { + "lower-port": "87", + "upper-port": "6745" + }, + "flags": "cwr ece urg", + "vpp-acl:vpp-tcp-ace": { + "vpp-acl:flags-mask": "cwr" } } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-udp.json b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-udp.json index e49a93cfa..10edb349e 100644 --- a/acl/acl-impl/src/test/resources/acl/standard/standard-acl-udp.json +++ b/acl/acl-impl/src/test/resources/acl/standard/standard-acl-udp.json @@ -1,32 +1,32 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", "tag": "udp-tag-value", - "access-list-entries": { + "aces": { "ace": [ { - "rule-name": "udp-rule", + "name": "udp-rule", "matches": { - "vpp-ace-nodes": { + "ipv4": { "destination-ipv4-network": "192.168.2.1/24", - "source-ipv4-network": "192.168.2.2/32", - "udp-nodes": { - "source-port-range": { - "lower-port": "1", - "upper-port": "5487" - }, - "destination-port-range": { - "lower-port": "87", - "upper-port": "6745" - } + "source-ipv4-network": "192.168.2.2/32" + }, + "udp": { + "source-port": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port": { + "lower-port": "87", + "upper-port": "6745" } } }, "actions": { - "permit": [null] + "forwarding": "ietf-access-control-list:accept" } } ] diff --git a/acl/acl-impl/src/test/resources/interface-acl/acl-references.json b/acl/acl-impl/src/test/resources/interface-acl/acl-references.json index 63c9e20c9..00a86965d 100644 --- a/acl/acl-impl/src/test/resources/interface-acl/acl-references.json +++ b/acl/acl-impl/src/test/resources/interface-acl/acl-references.json @@ -1,13 +1,12 @@ { - "interfaces": { + "attachment-points": { "interface": [ { - "name": "eth0", - "acl": { - "ingress": { - "vpp-acls": [ + "interface-id": "eth0", + "ingress": { + "acl-sets": { + "acl-set": [ { - "type": "vpp-acl:vpp-acl", "name": "acl1" } ] @@ -15,20 +14,14 @@ } }, { - "name": "eth1", - "acl": { - "egress": { - "vpp-acls": [ + "interface-id": "eth1", + "ingress": { + "acl-sets": { + "acl-set": [ { - "type": "vpp-acl:vpp-acl", "name": "acl1" - } - ] - }, - "ingress": { - "vpp-acls": [ + }, { - "type": "vpp-acl:vpp-acl", "name": "acl2" } ] @@ -36,19 +29,17 @@ } }, { - "name": "eth2", - "acl": { - "ingress": { - "vpp-acls": [ + "interface-id": "eth2", + "ingress": { + "acl-sets": { + "acl-set": [ { - "type": "vpp-acl:vpp-acl", "name": "acl1" + }, + { + "name": "acl4" } - ], - "vpp-macip-acl": { - "name": "acl4", - "type": "vpp-acl:vpp-macip-acl" - } + ] } } } diff --git a/acl/acl-impl/src/test/resources/rules/icmp-rule.json b/acl/acl-impl/src/test/resources/rules/icmp-rule.json index 330a448fc..dbee65ea3 100644 --- a/acl/acl-impl/src/test/resources/rules/icmp-rule.json +++ b/acl/acl-impl/src/test/resources/rules/icmp-rule.json @@ -1,23 +1,25 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "imcp-rule", + "name": "imcp-rule", "matches": { - "vpp-ace-nodes": { - "destination-ipv4-network": "192.168.2.1/32", + "ipv4": { "source-ipv4-network": "192.168.2.2/32", - "icmp-nodes": { - "icmp-type-range": { + "destination-ipv4-network": "192.168.2.1/32" + }, + "icmp": { + "vpp-acl:vpp-icmp-ace": { + "vpp-acl:icmp-type-range": { "first": "5", "last": "8" }, - "icmp-code-range": { + "vpp-acl:icmp-code-range": { "first": "1", "last": "3" } diff --git a/acl/acl-impl/src/test/resources/rules/icmp-v6-rule.json b/acl/acl-impl/src/test/resources/rules/icmp-v6-rule.json index 9ea82a19a..3cb989858 100644 --- a/acl/acl-impl/src/test/resources/rules/icmp-v6-rule.json +++ b/acl/acl-impl/src/test/resources/rules/icmp-v6-rule.json @@ -1,23 +1,25 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "imcp-rule", + "name": "imcp-v6-rule", "matches": { - "vpp-ace-nodes": { - "destination-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64", - "source-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0002/64", - "icmp-v6-nodes": { - "icmp-type-range": { + "ipv6": { + "source-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0002/48", + "destination-ipv6-network": "2001:0db8:0a0b:12f0:0000:0000:0000:0001/64" + }, + "icmp": { + "vpp-acl:vpp-icmp-ace": { + "vpp-acl:icmp-type-range": { "first": "5", "last": "8" }, - "icmp-code-range": { + "vpp-acl:icmp-code-range": { "first": "1", "last": "3" } 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 index a022bf08d..dad0f05bb 100644 --- a/acl/acl-impl/src/test/resources/rules/no-protocol-rule.json +++ b/acl/acl-impl/src/test/resources/rules/no-protocol-rule.json @@ -1,17 +1,17 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "no-protocol-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" + "ipv4": { + "source-ipv4-network": "192.168.2.2/32", + "destination-ipv4-network": "192.168.2.1/32" } } } diff --git a/acl/acl-impl/src/test/resources/rules/other-rule.json b/acl/acl-impl/src/test/resources/rules/other-rule.json deleted file mode 100644 index 0e60dccf7..000000000 --- a/acl/acl-impl/src/test/resources/rules/other-rule.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "access-lists": { - "acl": [ - { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { - "ace": [ - { - "rule-name": "imcp-rule", - "matches": { - "vpp-ace-nodes": { - "destination-ipv4-network": "192.168.2.1/32", - "source-ipv4-network": "192.168.2.2/32", - "other-nodes": { - "protocol": "64" - } - } - } - } - ] - } - } - ] - } -} \ No newline at end of file diff --git a/acl/acl-impl/src/test/resources/rules/tcp-rule-no-flags.json b/acl/acl-impl/src/test/resources/rules/tcp-rule-no-flags.json index 31cc854df..2130f4a32 100644 --- a/acl/acl-impl/src/test/resources/rules/tcp-rule-no-flags.json +++ b/acl/acl-impl/src/test/resources/rules/tcp-rule-no-flags.json @@ -1,24 +1,24 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "tcp-no-flags-rule", + "name": "tcp-no-flags-rule", "matches": { - "vpp-ace-nodes": { + "ipv4": { "destination-ipv4-network": "192.168.2.1/32", - "source-ipv4-network": "192.168.2.2/32", - "tcp-nodes": { - "source-port-range": { - "lower-port": "123" - }, - "destination-port-range": { - "lower-port": "65000" - } + "source-ipv4-network": "192.168.2.2/32" + }, + "tcp": { + "source-port": { + "lower-port": "123" + }, + "destination-port": { + "lower-port": "65000" } } } diff --git a/acl/acl-impl/src/test/resources/rules/tcp-rule.json b/acl/acl-impl/src/test/resources/rules/tcp-rule.json index de3697eef..95fa836d4 100644 --- a/acl/acl-impl/src/test/resources/rules/tcp-rule.json +++ b/acl/acl-impl/src/test/resources/rules/tcp-rule.json @@ -1,28 +1,30 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "imcp-rule", + "name": "tcp-rule", "matches": { - "vpp-ace-nodes": { + "ipv4": { "destination-ipv4-network": "192.168.2.1/32", - "source-ipv4-network": "192.168.2.2/32", - "tcp-nodes": { - "source-port-range": { - "lower-port": "1", - "upper-port": "5487" - }, - "destination-port-range": { - "lower-port": "87", - "upper-port": "6745" - }, - "tcp-flags-mask": "1", - "tcp-flags-value": "7" + "source-ipv4-network": "192.168.2.2/32" + }, + "tcp": { + "source-port": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port": { + "lower-port": "87", + "upper-port": "6745" + }, + "flags": "cwr ece urg", + "vpp-acl:vpp-tcp-ace": { + "vpp-acl:flags-mask": "cwr" } } } diff --git a/acl/acl-impl/src/test/resources/rules/udp-rule.json b/acl/acl-impl/src/test/resources/rules/udp-rule.json index 4bc05d4b2..8ee8b82d6 100644 --- a/acl/acl-impl/src/test/resources/rules/udp-rule.json +++ b/acl/acl-impl/src/test/resources/rules/udp-rule.json @@ -1,26 +1,26 @@ { - "access-lists": { + "acls": { "acl": [ { - "acl-name": "standard-acl", - "acl-type": "vpp-acl:vpp-acl", - "access-list-entries": { + "name": "standard-acl", + "type": "vpp-acl:vpp-acl", + "aces": { "ace": [ { - "rule-name": "imcp-rule", + "name": "imcp-rule", "matches": { - "vpp-ace-nodes": { + "ipv4": { "destination-ipv4-network": "192.168.2.1/32", - "source-ipv4-network": "192.168.2.2/32", - "udp-nodes": { - "source-port-range": { - "lower-port": "1", - "upper-port": "5487" - }, - "destination-port-range": { - "lower-port": "87", - "upper-port": "6745" - } + "source-ipv4-network": "192.168.2.2/32" + }, + "udp": { + "source-port": { + "lower-port": "1", + "upper-port": "5487" + }, + "destination-port": { + "lower-port": "87", + "upper-port": "6745" } } } -- cgit 1.2.3-korg