From a7147d16c31d9028c6b5dc557264433de0f11c91 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 23 Sep 2016 16:39:09 +0200 Subject: 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 --- .../v3po/interfacesstate/VxlanCustomizer.java | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java index b0a0496ce..2d01c3e39 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java @@ -17,14 +17,13 @@ package io.fd.honeycomb.translate.v3po.interfacesstate; import static com.google.common.base.Preconditions.checkState; -import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.NamingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; @@ -52,7 +51,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class VxlanCustomizer extends FutureJVppCustomizer - implements ReaderCustomizer { + implements ReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); private final NamingContext interfaceContext; @@ -81,7 +80,7 @@ public class VxlanCustomizer extends FutureJVppCustomizer try { final InterfaceKey key = id.firstKeyOf(Interface.class); final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanTunnel.class)) { + if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanTunnel.class, LOG)) { return; } @@ -91,31 +90,32 @@ public class VxlanCustomizer extends FutureJVppCustomizer request.swIfIndex = index; final CompletionStage swInterfaceVxlanDetailsReplyDumpCompletionStage = - getFutureJVpp().vxlanTunnelDump(request); + getFutureJVpp().vxlanTunnelDump(request); final VxlanTunnelDetailsReplyDump reply = - TranslateUtils.getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id); + getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id); // VPP keeps vxlan tunnel interfaces even after they were deleted (optimization) // However there ar no longer any vxlan tunnel specific fields assigned to it and this call // returns nothing if (reply == null || reply.vxlanTunnelDetails == null || reply.vxlanTunnelDetails.isEmpty()) { LOG.debug( - "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + - "after delete", key.getName(), index); + "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + + "after delete", key.getName(), index); return; } checkState(reply.vxlanTunnelDetails.size() == 1, - "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails, key.getName()); + "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails, + key.getName()); LOG.trace("Vxlan tunnel: {} attributes returned from VPP: {}", key.getName(), reply); final VxlanTunnelDetails swInterfaceVxlanDetails = reply.vxlanTunnelDetails.get(0); if (swInterfaceVxlanDetails.isIpv6 == 1) { final Ipv6Address dstIpv6 = - new Ipv6Address(parseAddress(swInterfaceVxlanDetails.dstAddress).getHostAddress()); + new Ipv6Address(parseAddress(swInterfaceVxlanDetails.dstAddress).getHostAddress()); builder.setDst(new IpAddress(dstIpv6)); final Ipv6Address srcIpv6 = - new Ipv6Address(parseAddress(swInterfaceVxlanDetails.srcAddress).getHostAddress()); + new Ipv6Address(parseAddress(swInterfaceVxlanDetails.srcAddress).getHostAddress()); builder.setSrc(new IpAddress(srcIpv6)); } else { final byte[] dstBytes = Arrays.copyOfRange(swInterfaceVxlanDetails.dstAddress, 0, 4); @@ -126,11 +126,11 @@ public class VxlanCustomizer extends FutureJVppCustomizer builder.setSrc(new IpAddress(srcIpv4)); } builder.setEncapVrfId((long) swInterfaceVxlanDetails.encapVrfId); - builder.setVni( new VxlanVni((long) swInterfaceVxlanDetails.vni)); + builder.setVni(new VxlanVni((long) swInterfaceVxlanDetails.vni)); LOG.debug("Vxlan tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); } catch (VppBaseCallException e) { LOG.warn("Failed to readCurrentAttributes for: {}", id); - throw new ReadFailedException( id, e ); + throw new ReadFailedException(id, e); } } -- cgit 1.2.3-korg