diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-01-12 15:11:16 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-01-16 11:15:09 +0000 |
commit | 99a666433adaf8009e60060e6078bdf64d99090c (patch) | |
tree | 88d7cfa22574b1a31e9c9d5002461f2f095b190f /acl/acl-impl/src/main/java/io/fd | |
parent | 376fb276f70629cfe0256dcebf3a0c9b09edf0b5 (diff) |
HC2VPP-38 / HONEYCOMB-336 - removed mandatory from ace-ip-version
Removed mandatory statements
Fixed multiple NPE
Change-Id: Iebb64dcb47ddbd4346b7b317d368094205137e28
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'acl/acl-impl/src/main/java/io/fd')
4 files changed, 136 insertions, 47 deletions
diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java index b98daa5ce..503ff47dc 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/MacIpAceDataExtractor.java @@ -16,76 +16,116 @@ package io.fd.hc2vpp.acl.util.ace.extractor; + import io.fd.hc2vpp.common.translate.util.MacTranslator; import io.fd.vpp.jvpp.acl.types.MacipAclRule; +import java.util.Optional; import javax.annotation.Nonnull; 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.Matches; 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.PacketHandling; 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.Permit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAceEthHeaderFields; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAceIpv4HeaderFields; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.VppMacipAceIpv6HeaderFields; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppMacipAce; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.VppMacipAceNodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.AceIpVersion; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.macip.ace.vpp.macip.ace.nodes.ace.ip.version.AceIpv6Builder; public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator { + String DEFAULT_MAC = "00:00:00:00:00:00"; + String DEFAULT_MAC_MASK = "00:00:00:00:00:00"; + byte[] DEFAULT_MAC_BYTES = {0, 0, 0, 0, 0, 0}; + byte[] DEFAULT_MAC_MASK_BYTES = {0, 0, 0, 0, 0, 0}; + default VppMacipAce fromMacIpAce(@Nonnull final Ace ace) { - return VppMacipAce.class.cast(ace.getMatches().getAceType()); + return Optional.ofNullable(ace.getMatches()) + .map(Matches::getAceType) + .map(VppMacipAce.class::cast) + .orElseThrow( + () -> new IllegalArgumentException(String.format("Unable to create VppMacipAce from %s", ace))); } default boolean macIpIsIpv6(@Nonnull final VppMacipAce ace) { - return ace.getVppMacipAceNodes().getAceIpVersion() instanceof AceIpv6; + return Optional.ofNullable(ace.getVppMacipAceNodes()) + .map(VppMacipAceNodes::getAceIpVersion) + .map(aceIpVersion -> aceIpVersion instanceof AceIpv6) + .orElse(false); } default byte[] sourceMacAsBytes(@Nonnull final VppMacipAce ace) { - return macToByteArray(ace.getVppMacipAceNodes().getSourceMacAddress().getValue()); + return macToByteArray(Optional.ofNullable(ace.getVppMacipAceNodes()) + .map(VppMacipAceEthHeaderFields::getSourceMacAddress) + .map(MacAddress::getValue) + .orElse(DEFAULT_MAC)); } default byte[] sourceMacMaskAsBytes(@Nonnull final VppMacipAce ace) { - return macToByteArray(ace.getVppMacipAceNodes().getSourceMacAddressMask().getValue()); + return macToByteArray(Optional.ofNullable(ace.getVppMacipAceNodes()) + .map(VppMacipAceEthHeaderFields::getSourceMacAddressMask) + .map(MacAddress::getValue) + .orElse(DEFAULT_MAC_MASK)); } default byte[] ipv4Address(@Nonnull final VppMacipAce ace) { - return extractIp4Address( - VppMacipAceIpv4HeaderFields.class.cast(ace.getVppMacipAceNodes().getAceIpVersion()).getSourceIpv4Network()); + return extractIp4Address(extractV4NetworkAddressOrNull(ace)); } default byte ipv4AddressPrefix(@Nonnull final VppMacipAce ace) { - return extractIp4AddressPrefix( - VppMacipAceIpv4HeaderFields.class.cast(ace.getVppMacipAceNodes().getAceIpVersion()).getSourceIpv4Network()); + return extractIp4AddressPrefix(extractV4NetworkAddressOrNull(ace)); + } + + static Ipv4Prefix extractV4NetworkAddressOrNull(final @Nonnull VppMacipAce ace) { + return Optional.ofNullable(ace.getVppMacipAceNodes()) + .map(VppMacipAceNodes::getAceIpVersion) + .map(VppMacipAceIpv4HeaderFields.class::cast) + .map(VppMacipAceIpv4HeaderFields::getSourceIpv4Network) + .orElse(null); } default byte[] ipv6Address(@Nonnull final VppMacipAce ace) { - return extractIp6Address( - VppMacipAceIpv6HeaderFields.class.cast(ace.getVppMacipAceNodes().getAceIpVersion()).getSourceIpv6Network()); + return extractIp6Address(extractV6NetworkAddressOrNull(ace)); } default byte ipv6AddressPrefix(@Nonnull final VppMacipAce ace) { - return extractIp6AddressPrefix( - VppMacipAceIpv6HeaderFields.class.cast(ace.getVppMacipAceNodes().getAceIpVersion()).getSourceIpv6Network()); + return extractIp6AddressPrefix(extractV6NetworkAddressOrNull(ace)); + } + + default Ipv6Prefix extractV6NetworkAddressOrNull(@Nonnull final VppMacipAce ace) { + return Optional.ofNullable(ace.getVppMacipAceNodes()) + .map(VppMacipAceNodes::getAceIpVersion) + .map(VppMacipAceIpv6HeaderFields.class::cast) + .map(VppMacipAceIpv6HeaderFields::getSourceIpv6Network) + .orElse(null); } /** * Only 0 and 1 are allowed for mac-ip */ default byte macIpAction(@Nonnull final Ace ace) { - final PacketHandling action = ace.getActions().getPacketHandling(); + // action choice itself has default, but nothing stops us from not defining actions container itself + final PacketHandling action = Optional.ofNullable(ace.getActions()).orElseThrow( + () -> new IllegalArgumentException(String.format("Unable to extract Action from %s", ace))) + .getPacketHandling(); if (action instanceof Permit) { return 1; } else if (action instanceof Deny) { return 0; } else { throw new IllegalArgumentException( - String.format("Unsupported packet-handling action %s for ACE %s", action, ace)); + String.format("Unsupported packet-handling action %s for ACE %s", action, ace)); } } - default AceIpVersion ipVersion(final MacipAclRule rule) { + default AceIpVersion ipVersion(@Nonnull final MacipAclRule rule) { if (rule.isIpv6 == 0) { return ip4Ace(rule); } else { @@ -93,7 +133,7 @@ public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator { } } - default AceIpVersion ip4Ace(MacipAclRule rule) { + default AceIpVersion ip4Ace(@Nonnull final MacipAclRule rule) { final AceIpv4Builder ipVersion = new AceIpv4Builder(); if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) { ipVersion.setSourceIpv4Network(toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen)); @@ -101,7 +141,7 @@ public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator { return ipVersion.build(); } - default AceIpVersion ip6Ace(MacipAclRule rule) { + default AceIpVersion ip6Ace(@Nonnull final MacipAclRule rule) { final AceIpv6Builder ipVersion = new AceIpv6Builder(); if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) { ipVersion.setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen)); @@ -109,13 +149,15 @@ public interface MacIpAceDataExtractor extends AddressExtractor, MacTranslator { return ipVersion.build(); } - default MacAddress sourceMac(final MacipAclRule rule) { - return new MacAddress(byteArrayToMacSeparated(rule.srcMac)); + default MacAddress sourceMac(@Nonnull final MacipAclRule rule) { + return new MacAddress(byteArrayToMacSeparated(rule.srcMac != null + ? rule.srcMac + : DEFAULT_MAC_BYTES)); } - default MacAddress sourceMacMask(final MacipAclRule rule) { - return new MacAddress(byteArrayToMacSeparated(rule.srcMacMask)); + default MacAddress sourceMacMask(@Nonnull final MacipAclRule rule) { + return new MacAddress(byteArrayToMacSeparated(rule.srcMacMask != null + ? rule.srcMacMask + : DEFAULT_MAC_MASK_BYTES)); } - - } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java index 664023947..49587ec7f 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/ace/extractor/StandardAceDataExtractor.java @@ -21,22 +21,26 @@ import io.fd.hc2vpp.acl.util.protocol.IpProtocolReader; import io.fd.hc2vpp.acl.util.protocol.ProtoPreBindRuleProducer; import io.fd.vpp.jvpp.acl.types.AclRule; import java.util.Map; +import java.util.Optional; import javax.annotation.Nonnull; 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; 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.Matches; 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.PacketHandling; 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.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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.AclIpv4HeaderFields; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.AclIpv6HeaderFields; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.actions.packet.handling.Stateful; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.actions.packet.handling.StatefulBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.VppAce; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.VppAceNodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.AceIpVersion; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.access.lists.acl.access.list.entries.ace.matches.ace.type.vpp.ace.vpp.ace.nodes.ace.ip.version.AceIpv6Builder; @@ -50,55 +54,94 @@ public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBind Stateful.class, 2); default VppAce fromStandardAce(@Nonnull final Ace ace) { - return VppAce.class.cast(ace.getMatches().getAceType()); + return Optional.ofNullable(ace.getMatches()) + .map(Matches::getAceType) + .map(VppAce.class::cast) + .orElseThrow(() -> new IllegalArgumentException(String.format("Unable to create VppAce from %s", ace))); } default boolean standardIsIpv6(@Nonnull final Ace ace) { - return VppAce.class.cast(ace.getMatches().getAceType()).getVppAceNodes().getAceIpVersion() instanceof AceIpv6; + return Optional.ofNullable(ace.getMatches()) + .map(Matches::getAceType) + .map(VppAce.class::cast) + .map(VppAce::getVppAceNodes) + .map(VppAceNodes::getAceIpVersion) + .map(aceIpVersion -> aceIpVersion instanceof AceIpv6) + .orElse(false); } default byte[] ipv4SourceAddress(@Nonnull final VppAce ace) { return extractIp4Address( - AclIpv4HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getSourceIpv4Network()); + extractV4SourceAddressOrNull(ace)); } default byte ipv4SourceAddressPrefix(@Nonnull final VppAce ace) { return extractIp4AddressPrefix( - AclIpv4HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getSourceIpv4Network()); + extractV4SourceAddressOrNull(ace)); } + static Ipv4Prefix extractV4SourceAddressOrNull(@Nonnull final VppAce ace) { + return Optional.ofNullable(ace.getVppAceNodes()) + .map(VppAceNodes::getAceIpVersion) + .map(AclIpv4HeaderFields.class::cast) + .map(AclIpv4HeaderFields::getSourceIpv4Network) + .orElse(null); + } + + default byte[] ipv4DestinationAddress(@Nonnull final VppAce ace) { - return extractIp4Address( - AclIpv4HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getDestinationIpv4Network()); + return extractIp4Address(extractV4DestinationAddressOrNull(ace)); } default byte ipv4DestinationAddressPrefix(@Nonnull final VppAce ace) { - return extractIp4AddressPrefix(AceIpv4.class.cast(ace.getVppAceNodes().getAceIpVersion()).getDestinationIpv4Network()); + return extractIp4AddressPrefix(extractV4DestinationAddressOrNull(ace)); } + static Ipv4Prefix extractV4DestinationAddressOrNull(@Nonnull final VppAce ace) { + return Optional.ofNullable(ace.getVppAceNodes()) + .map(VppAceNodes::getAceIpVersion) + .map(AclIpv4HeaderFields.class::cast) + .map(AclIpv4HeaderFields::getDestinationIpv4Network) + .orElse(null); + } default byte[] ipv6SourceAddress(@Nonnull final VppAce ace) { - return extractIp6Address( - AclIpv6HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getSourceIpv6Network()); + return extractIp6Address(extractV6SourceAddressOrNull(ace)); } default byte ipv6SourceAddressPrefix(@Nonnull final VppAce ace) { - return extractIp6AddressPrefix( - AclIpv6HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getSourceIpv6Network()); + return extractIp6AddressPrefix(extractV6SourceAddressOrNull(ace)); + } + + static Ipv6Prefix extractV6SourceAddressOrNull(@Nonnull final VppAce ace) { + return Optional.ofNullable(ace.getVppAceNodes()) + .map(VppAceNodes::getAceIpVersion) + .map(AclIpv6HeaderFields.class::cast) + .map(AclIpv6HeaderFields::getSourceIpv6Network) + .orElse(null); } default byte[] ipv6DestinationAddress(@Nonnull final VppAce ace) { - return extractIp6Address( - AclIpv6HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getDestinationIpv6Network()); + return extractIp6Address(extractV6DestinationAddressOrNull(ace)); } default byte ipv6DestinationAddressPrefix(@Nonnull final VppAce ace) { - return extractIp6AddressPrefix( - AclIpv6HeaderFields.class.cast(ace.getVppAceNodes().getAceIpVersion()).getDestinationIpv6Network()); + return extractIp6AddressPrefix(extractV6DestinationAddressOrNull(ace)); + } + + static Ipv6Prefix extractV6DestinationAddressOrNull(@Nonnull final VppAce ace) { + return Optional.ofNullable(ace.getVppAceNodes()) + .map(VppAceNodes::getAceIpVersion) + .map(AclIpv6HeaderFields.class::cast) + .map(AclIpv6HeaderFields::getDestinationIpv6Network) + .orElse(null); } default byte standardAction(@Nonnull final Ace ace) { - final PacketHandling action = ace.getActions().getPacketHandling(); + // default == deny + final PacketHandling action = Optional.ofNullable(ace.getActions()) + .orElseThrow(() -> new IllegalArgumentException(String.format("Unable to extract Action from %s", ace))) + .getPacketHandling(); return ACTION_VALUE_PAIRS.get(ACTION_VALUE_PAIRS.keySet().stream() .filter(aClass -> aClass.isInstance(action)) .findAny() @@ -107,7 +150,7 @@ public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBind ace.getRuleName())))).byteValue(); } - default AceIpVersion ipVersion(final AclRule rule) { + default AceIpVersion ipVersion(@Nonnull final AclRule rule) { if (rule.isIpv6 == 0) { return ip4Ace(rule); } else { @@ -115,7 +158,7 @@ public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBind } } - default AceIpVersion ip4Ace(final AclRule rule) { + default AceIpVersion ip4Ace(@Nonnull final AclRule rule) { final AceIpv4Builder ipVersion = new AceIpv4Builder(); if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) { ipVersion.setSourceIpv4Network(toIpv4Prefix(truncateIp4Array(rule.srcIpAddr), rule.srcIpPrefixLen)); @@ -126,7 +169,7 @@ public interface StandardAceDataExtractor extends AddressExtractor, ProtoPreBind return ipVersion.build(); } - default AceIpVersion ip6Ace(final AclRule rule) { + default AceIpVersion ip6Ace(@Nonnull final AclRule rule) { final AceIpv6Builder ipVersion = new AceIpv6Builder(); if (rule.srcIpAddr != null && rule.srcIpAddr.length != 0) { ipVersion.setSourceIpv6Network(toIpv6Prefix(rule.srcIpAddr, rule.srcIpPrefixLen)); diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java index 77e58fe0c..8c6cdcfef 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/util/acl/AclDataExtractor.java @@ -18,6 +18,7 @@ package io.fd.hc2vpp.acl.util.acl; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; 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.acl.access.list.entries.Ace; @@ -56,13 +57,16 @@ public interface AclDataExtractor { } default List<Ace> getAces(@Nonnull final Acl acl) { - return acl.getAccessListEntries().getAce(); + return Optional.ofNullable(acl.getAccessListEntries()).orElseThrow(() -> + new IllegalArgumentException(String.format("Unable to extract aces from %s", acl))).getAce(); } /** * Convert {@link Acl} name to byte array as UTF_8 */ default byte[] getAclNameAsBytes(@Nonnull final Acl acl) { - return acl.getAclName().getBytes(StandardCharsets.UTF_8); + return Optional.ofNullable(acl.getAclName()) + .orElseThrow(() -> new IllegalArgumentException("Unable to extract bytes for null")) + .getBytes(StandardCharsets.UTF_8); } } diff --git a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java index f83808205..43360c629 100644 --- a/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java +++ b/acl/acl-impl/src/main/java/io/fd/hc2vpp/acl/write/InterfaceAclCustomizer.java @@ -87,7 +87,7 @@ public class InterfaceAclCustomizer extends FutureJVppAclCustomizer implements W .executeAsDelete(getjVppAclFacade()); } - private static List<String> getAclNames(@Nonnull final VppAclsBaseAttributes acls) { + private static List<String> getAclNames(final VppAclsBaseAttributes acls) { if (acls == null || acls.getVppAcls() == null) { return Collections.emptyList(); } else { |