From 670859f797cd442f184ace2e65c0c04778482420 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 24 Jan 2017 09:21:06 +0100 Subject: Fix mac-ip acl assignment read Now unassigned acls are filtered out. As a bonus acl plugin coverage was raised above 80%. Change-Id: Ia71be2086d0baadfbffc1f1263bab67f555c0687 Signed-off-by: Marek Gradzki --- .../io/fd/hc2vpp/acl/read/AclCustomizerTest.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/AclCustomizerTest.java') 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 7c86025fb..375c8e22e 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 @@ -16,23 +16,60 @@ 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.hc2vpp.acl.util.AclContextManager; import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.acl.dto.AclDetails; +import io.fd.vpp.jvpp.acl.dto.AclDetailsReplyDump; +import io.fd.vpp.jvpp.acl.dto.MacipAclDetails; +import io.fd.vpp.jvpp.acl.dto.MacipAclDetailsReplyDump; 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.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.rev161214.VppAcl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.Other; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; public class AclCustomizerTest extends InitializingListReaderCustomizerTest { + private static final String ACL_NAME = "vpp-acl"; + private static final String ACE_NAME = "vpp-ace"; + private static final int ACL_INDEX = 123; + private static final String MACIP_ACL_NAME = "vpp-macip-acl"; + private static final String MACIP_ACE_NAME = "vpp-macip-ace"; + private static final int MACIP_ACL_INDEX = 456; + private static final short PROTOCOL = 2; @Mock private FutureJVppAclFacade aclApi; @Mock private AclContextManager standardAclContext; @Mock private AclContextManager macipAclContext; + private KeyedInstanceIdentifier ACL_IID = + InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey( + ACL_NAME, VppAcl.class)); + private KeyedInstanceIdentifier MACIP_ACL_IID = + InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(MACIP_ACL_NAME, VppMacipAcl.class)); public AclCustomizerTest() { super(Acl.class, AccessListsBuilder.class); @@ -42,4 +79,68 @@ public class AclCustomizerTest extends InitializingListReaderCustomizerTest(); + final AclDetails acl1 = new AclDetails(); + acl1.r = new AclRule[1]; + acl1.r[0] = new AclRule(); + acl1.r[0].proto = PROTOCOL; + acl1.aclIndex = ACL_INDEX; + aclDump.aclDetails.add(acl1); + when(aclApi.aclDump(any())).thenReturn(future(aclDump)); + + final MacipAclDetailsReplyDump macipAclDump = new MacipAclDetailsReplyDump(); + macipAclDump.macipAclDetails = new ArrayList<>(); + final MacipAclDetails macipAcl1 = new MacipAclDetails(); + macipAcl1.r = new MacipAclRule[]{new MacipAclRule()}; + macipAcl1.aclIndex = MACIP_ACL_INDEX; + macipAclDump.macipAclDetails.add(macipAcl1); + when(aclApi.macipAclDump(any())).thenReturn(future(macipAclDump)); + + when(standardAclContext.getAclName(ACL_INDEX, mappingContext)).thenReturn(ACL_NAME); + when(standardAclContext.getAclIndex(ACL_NAME, mappingContext)).thenReturn(ACL_INDEX); + when(standardAclContext.getAceName(ACL_NAME, 0, mappingContext)).thenReturn(ACE_NAME); + + when(macipAclContext.getAclName(MACIP_ACL_INDEX, mappingContext)).thenReturn(MACIP_ACL_NAME); + when(macipAclContext.getAclIndex(MACIP_ACL_NAME, mappingContext)).thenReturn(MACIP_ACL_INDEX); + when(macipAclContext.getAceName(MACIP_ACL_NAME, 0, mappingContext)).thenReturn(MACIP_ACE_NAME); + } + + @Test + public void testGetAllIds() throws ReadFailedException { + final List allIds = getCustomizer().getAllIds(InstanceIdentifier.create(AccessLists.class).child(Acl.class), ctx); + assertEquals(2, allIds.size()); + assertEquals(ACL_IID.getKey(), allIds.get(0)); + assertEquals(MACIP_ACL_IID.getKey(), allIds.get(1)); + } + + @Test + public void testReadStandardAcl() throws ReadFailedException { + final AclBuilder builder = new AclBuilder(); + getCustomizer().readCurrentAttributes(ACL_IID, builder, ctx); + assertEquals(ACL_IID.getKey(), builder.getKey()); + final List aces = builder.getAccessListEntries().getAce(); + assertEquals(1, aces.size()); + final Ace ace = aces.get(0); + assertEquals(ACE_NAME, ace.getKey().getRuleName()); + assertTrue(ace.getActions().getPacketHandling() instanceof Deny); + final VppAceNodes nodes = ((VppAce) (ace.getMatches().getAceType())).getVppAceNodes(); + assertEquals(PROTOCOL, ((Other) nodes.getIpProtocol()).getOtherNodes().getProtocol().shortValue()); + + } + + @Test + public void testReadMacipAcl() throws ReadFailedException { + final AclBuilder builder = new AclBuilder(); + getCustomizer().readCurrentAttributes(MACIP_ACL_IID, builder, ctx); + assertEquals(MACIP_ACL_IID.getKey(), builder.getKey()); + final List aces = builder.getAccessListEntries().getAce(); + assertEquals(1, aces.size()); + final Ace ace = aces.get(0); + assertEquals(MACIP_ACE_NAME, ace.getKey().getRuleName()); + assertTrue(ace.getActions().getPacketHandling() instanceof Deny); + } } \ No newline at end of file -- cgit 1.2.3-korg