diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2016-12-22 15:25:44 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-12-22 15:25:44 +0100 |
commit | cfcc0585d9801a15ec4b36ac627662dc7f0fe789 (patch) | |
tree | 1df00e8a3e6504da05dc762c614c6e3722724f23 | |
parent | 8649ade681da840c633141fda46c0bd51ef0800f (diff) |
Fix non existing tag handling for mac-ip customizer
Change-Id: I717ea660a773cfd3b56010dbfe1e5691bde32de8
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
3 files changed, 134 insertions, 21 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java index 982d89b9a..7786afee5 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java @@ -49,7 +49,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer - implements ReaderCustomizer<VppMacipAcl, VppMacipAclBuilder>, JvppReplyConsumer, ByteDataTranslator { + implements ReaderCustomizer<VppMacipAcl, VppMacipAclBuilder>, JvppReplyConsumer, ByteDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(VppMacIpAclCustomizer.class); @@ -65,15 +65,15 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer // for dumping of Mac-ip details macIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclDetailsReplyDump, Integer>() - .withExecutor(createMacIpDumpExecutor()) - .acceptOnly(MacipAclDetailsReplyDump.class) - .build(); + .withExecutor(createMacIpDumpExecutor()) + .acceptOnly(MacipAclDetailsReplyDump.class) + .build(); // for dumping of reference on interface interfaceMacIpAclDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<MacipAclInterfaceGetReply, Void>() - .withExecutor(createInterfaceMacIpDumpExecutor()) - .acceptOnly(MacipAclInterfaceGetReply.class) - .build(); + .withExecutor(createInterfaceMacIpDumpExecutor()) + .acceptOnly(MacipAclInterfaceGetReply.class) + .build(); this.interfaceContext = interfaceContext; this.macIpAclContext = macIpAclContext; } @@ -89,8 +89,8 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer private EntityDumpExecutor<MacipAclInterfaceGetReply, Void> createInterfaceMacIpDumpExecutor() { return (identifier, params) -> getReplyForRead( - getjVppAclFacade().macipAclInterfaceGet(new MacipAclInterfaceGet()).toCompletableFuture(), - identifier); + getjVppAclFacade().macipAclInterfaceGet(new MacipAclInterfaceGet()).toCompletableFuture(), + identifier); } @Nonnull @@ -108,26 +108,28 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer final int interfaceIndex = interfaceContext.getIndex(interfaceName, mappingContext); final ModificationCache modificationCache = ctx.getModificationCache(); final Optional<MacipAclInterfaceGetReply> interfacesMacIpDumpReply = - interfaceMacIpAclDumpManager.getDump(id, modificationCache, NO_PARAMS); + interfaceMacIpAclDumpManager.getDump(id, modificationCache, NO_PARAMS); if (interfacesMacIpDumpReply.isPresent() && interfaceIndex < interfacesMacIpDumpReply.get().count) { final int aclIndex = interfacesMacIpDumpReply.get().acls[interfaceIndex]; final Optional<MacipAclDetailsReplyDump> macIpDumpReply = - macIpAclDumpManager.getDump(id, modificationCache, aclIndex); + macIpAclDumpManager.getDump(id, modificationCache, aclIndex); if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { final MacipAclDetails details = macIpDumpReply.get().macipAclDetails.get(0); - builder.setName(macIpAclContext.getName(aclIndex, mappingContext)) - .setType( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class) - .setTag(new HexString(printHexBinary(details.tag))); + builder.setName(macIpAclContext.getName(aclIndex, mappingContext)); + builder.setType( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class); + if (details.tag != null && details.tag.length > 0) { + builder.setTag(new HexString(printHexBinary(details.tag))); + } } else { // this is invalid state(Interface in VPP will act as "deny-all" for security reasons), but generally // it should not happen throw new ReadFailedException(id, - new IllegalStateException(String.format("ACC with index %s not found in VPP", aclIndex))); + new IllegalStateException(String.format("ACE with index %s not found in VPP", aclIndex))); } } else { // this is valid state, so just logging 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 index 85ea0f87f..47e99ebac 100644 --- 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 @@ -72,6 +72,11 @@ public abstract class AbstractVppAclCustomizerTest super(VppAcls.class, parentBuilderClass); } + protected static InstanceIdentifier<Acl> 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); @@ -137,11 +142,6 @@ public abstract class AbstractVppAclCustomizerTest return reply; } - protected InstanceIdentifier<Acl> getAclId(final String ifName) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifName)) - .augmentation(VppAclInterfaceStateAugmentation.class).child(Acl.class); - } - protected abstract InstanceIdentifier<VppAcls> getWildcardedIid(@Nonnull final String ifName); protected abstract InstanceIdentifier<VppAcls> getIid(@Nonnull final String ifName, @Nonnull final VppAclsKey key); 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 new file mode 100644 index 000000000..97169cf06 --- /dev/null +++ b/acl/acl-impl/src/test/java/io/fd/hc2vpp/acl/read/VppMacIpAclCustomizerTest.java @@ -0,0 +1,111 @@ +/* + * 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.AbstractVppAclCustomizerTest.getAclId; +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.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +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.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.InstanceIdentifier; + +public class VppMacIpAclCustomizerTest extends ReaderCustomizerTest<VppMacipAcl, VppMacipAclBuilder> { + + 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"; + 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<? extends AclBase> ACL_TYPE = + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class; + @Mock + protected FutureJVppAclFacade aclApi; + protected NamingContext interfaceContext = new NamingContext("iface", IFC_CTX_NAME); + protected NamingContext macIpAclContext = new NamingContext("macIpAcl", ACL_CTX_NAME); + + 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); + defineMapping(mappingContext, ACL_NAME, ACL_ID, ACL_CTX_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[] {-1, 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 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); + } + + protected InstanceIdentifier<VppMacipAcl> getIid(@Nonnull final String ifName) { + return getAclId(ifName).child(Ingress.class).child(VppMacipAcl.class); + } + +}
\ No newline at end of file |