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 --- .../fd/hc2vpp/acl/read/VppMacIpAclCustomizer.java | 36 ++++++++++++---------- .../hc2vpp/acl/util/protocol/IpProtocolReader.java | 3 +- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'acl/acl-impl/src/main/java/io/fd') 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 b95acf82d..7ebe99b10 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 @@ -19,6 +19,7 @@ package io.fd.hc2vpp.acl.read; import static io.fd.hc2vpp.acl.read.AbstractVppAclCustomizer.getAclCfgId; import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import io.fd.hc2vpp.acl.util.AclContextManager; import io.fd.hc2vpp.acl.util.FutureJVppAclCustomizer; @@ -56,6 +57,8 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer implements InitializingReaderCustomizer, JvppReplyConsumer, ByteDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(VppMacIpAclCustomizer.class); + @VisibleForTesting + protected static final int ACL_NOT_ASSIGNED = -1; private final DumpCacheManager macIpAclDumpManager; private final DumpCacheManager interfaceMacIpAclDumpManager; @@ -121,24 +124,25 @@ public class VppMacIpAclCustomizer extends FutureJVppAclCustomizer if (interfacesMacIpDumpReply.isPresent() && interfaceIndex < interfacesMacIpDumpReply.get().count) { final int aclIndex = interfacesMacIpDumpReply.get().acls[interfaceIndex]; - - final Optional macIpDumpReply = - macIpAclDumpManager.getDump(id, modificationCache, aclIndex); - - if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { - builder.setName(macIpAclContext.getAclName(aclIndex, mappingContext)); - builder.setType( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class); - } 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("ACE with index %s not found in VPP", aclIndex))); + if (aclIndex != ACL_NOT_ASSIGNED) { + final Optional macIpDumpReply = + macIpAclDumpManager.getDump(id, modificationCache, aclIndex); + + if (macIpDumpReply.isPresent() && !macIpDumpReply.get().macipAclDetails.isEmpty()) { + builder.setName(macIpAclContext.getAclName(aclIndex, mappingContext)); + builder.setType( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAcl.class); + return; + } 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("ACE with index %s not found in VPP", aclIndex))); + } } - } else { - // this is valid state, so just logging - LOG.debug("No Mac-ip ACL specified for Interface name={},index={}", interfaceName, interfaceIndex); } + // this is valid state, so just logging + LOG.debug("No Mac-ip ACL specified for Interface name={},index={}", interfaceName, interfaceIndex); } @Override diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java index 767baef3d..b1a43793f 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/protocol/IpProtocolReader.java @@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.IcmpBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.IcmpV6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.IcmpV6Builder; +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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.OtherBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.Tcp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.ip.protocol.header.fields.ip.protocol.TcpBuilder; @@ -131,7 +132,7 @@ public interface IpProtocolReader { return new IcmpV6Builder().setIcmpV6Nodes(nodes.build()).build(); } - private static IpProtocol parse(final AclRule rule) { + private static Other parse(final AclRule rule) { final OtherNodesBuilder nodes = new OtherNodesBuilder(); nodes.setProtocol((short) Short.toUnsignedInt(rule.proto)); return new OtherBuilder().setOtherNodes(nodes.build()).build(); -- cgit 1.2.3-korg