diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2016-09-23 16:39:09 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2016-09-23 16:41:57 +0200 |
commit | a7147d16c31d9028c6b5dc557264433de0f11c91 (patch) | |
tree | 15816600ab3dfa5eea706ef1b1910b2e13ae66d7 /v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java | |
parent | e7a0775b21c2ea6b7bb8efb63b5384df26e27fbb (diff) |
HONEYCOMB-145 - Utility Class Refactoring
problematic mockito-all changed to mockito-core( https://github.com/mockito/mockito/issues/324)
Translate Utils Splitted to multiple Trait Interfaces
Ipv4Translator - Logic for translation of ipv4-based data
Ipv6Translator - Logic for translation of ipv6-based data
MacTranslator - Logic for translation of mac-based data
AddressTranslator - Aggregation trait for Ipv4/Ipv6/Mac
JvppReplyConsumer - Logic for extracting replies from jvpp calls
ByteDataTranslator - any byte-based conversions
Plus some existing utility classes changed to traits
Change-Id: I342b625954223966802e65dca0fabf8456c89345
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java index cb232ed3e..b19c754e5 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceIp4Writer.java @@ -17,10 +17,10 @@ package io.fd.honeycomb.translate.v3po.interfaces.acl; import static com.google.common.base.Preconditions.checkArgument; -import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.ipv4AddressNoZoneToArray; import com.google.common.annotations.VisibleForTesting; import com.google.common.primitives.Ints; +import io.fd.honeycomb.translate.v3po.util.Ipv4Translator; 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.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.matches.ace.type.AceIp; @@ -33,7 +33,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class AceIp4Writer extends AbstractAceWriter<AceIp> { +final class AceIp4Writer extends AbstractAceWriter<AceIp> implements Ipv4Translator { @VisibleForTesting static final int MATCH_N_VECTORS = 3; // number of 16B vectors @@ -63,7 +63,8 @@ final class AceIp4Writer extends AbstractAceWriter<AceIp> { return toByteMask(prefixLength); } - private static byte[] toMatchValue(final Ipv4Prefix ipv4Prefix) { + // static removed, cant use default from static content + private byte[] toMatchValue(final Ipv4Prefix ipv4Prefix) { final String[] split = ipv4Prefix.getValue().split("/"); final byte[] addressBytes = ipv4AddressNoZoneToArray(split[0]); final byte[] mask = toByteMask(Byte.valueOf(split[1])); @@ -111,19 +112,19 @@ final class AceIp4Writer extends AbstractAceWriter<AceIp> { if (ipVersion.getSourceIpv4Network() != null) { aceIsEmpty = false; System.arraycopy(toByteMask(ipVersion.getSourceIpv4Network()), 0, request.mask, baseOffset + SRC_IP_OFFSET, - IP4_LEN); + IP4_LEN); } if (ipVersion.getDestinationIpv4Network() != null) { aceIsEmpty = false; System - .arraycopy(toByteMask(ipVersion.getDestinationIpv4Network()), 0, request.mask, - baseOffset + DST_IP_OFFSET, IP4_LEN); + .arraycopy(toByteMask(ipVersion.getDestinationIpv4Network()), 0, request.mask, + baseOffset + DST_IP_OFFSET, IP4_LEN); } if (aceIsEmpty) { throw new IllegalArgumentException( - String.format("Ace %s does not define packet field match values", aceIp.toString())); + String.format("Ace %s does not define packet field match values", aceIp.toString())); } LOG.debug("ACE action={}, rule={} translated to table={}.", action, aceIp, request); @@ -147,7 +148,7 @@ final class AceIp4Writer extends AbstractAceWriter<AceIp> { if (aceIp.getProtocol() != null) { request.match[baseOffset + IP_VERSION_OFFSET] = - (byte) (IP_VERSION_MASK & (aceIp.getProtocol().intValue() << 4)); + (byte) (IP_VERSION_MASK & (aceIp.getProtocol().intValue() << 4)); } if (aceIp.getDscp() != null) { @@ -166,20 +167,21 @@ final class AceIp4Writer extends AbstractAceWriter<AceIp> { if (ipVersion.getSourceIpv4Network() != null) { noMatch = false; System - .arraycopy(toMatchValue(ipVersion.getSourceIpv4Network()), 0, request.match, baseOffset + SRC_IP_OFFSET, - IP4_LEN); + .arraycopy(toMatchValue(ipVersion.getSourceIpv4Network()), 0, request.match, + baseOffset + SRC_IP_OFFSET, + IP4_LEN); } if (ipVersion.getDestinationIpv4Network() != null) { noMatch = false; System.arraycopy(toMatchValue(ipVersion.getDestinationIpv4Network()), 0, request.match, - baseOffset + DST_IP_OFFSET, - IP4_LEN); + baseOffset + DST_IP_OFFSET, + IP4_LEN); } if (noMatch) { throw new IllegalArgumentException( - String.format("Ace %s does not define packet field match values", aceIp.toString())); + String.format("Ace %s does not define packet field match values", aceIp.toString())); } LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceIp, request); |