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 --- .../translate/v3po/interfaces/AclWriter.java | 15 +-- .../translate/v3po/interfaces/GreCustomizer.java | 58 ++++++----- .../v3po/interfaces/InterconnectionWriteUtils.java | 38 +++---- .../v3po/interfaces/InterfaceCustomizer.java | 33 +++--- .../v3po/interfaces/ProxyArpCustomizer.java | 11 +- .../v3po/interfaces/RewriteCustomizer.java | 12 +-- .../v3po/interfaces/RoutingCustomizer.java | 19 ++-- .../v3po/interfaces/SubInterfaceCustomizer.java | 40 ++++---- .../v3po/interfaces/SubInterfaceL2Customizer.java | 2 +- .../translate/v3po/interfaces/TapCustomizer.java | 48 +++++---- .../v3po/interfaces/VhostUserCustomizer.java | 32 +++--- .../translate/v3po/interfaces/VxlanCustomizer.java | 32 +++--- .../v3po/interfaces/VxlanGpeCustomizer.java | 62 +++++++----- .../v3po/interfaces/acl/AbstractAceWriter.java | 22 ++-- .../v3po/interfaces/acl/AceEthWriter.java | 25 ++--- .../v3po/interfaces/acl/AceIp4Writer.java | 28 +++--- .../v3po/interfaces/acl/IetfAClWriter.java | 39 ++++---- .../v3po/interfaces/ip/Ipv4AddressCustomizer.java | 9 +- .../interfaces/ip/Ipv4NeighbourCustomizer.java | 17 ++-- .../v3po/interfaces/ip/Ipv4WriteUtils.java | 111 --------------------- .../translate/v3po/interfaces/ip/Ipv4Writer.java | 109 ++++++++++++++++++++ .../v3po/interfaces/ip/Ipv6Customizer.java | 2 +- .../ip/SubInterfaceIpv4AddressCustomizer.java | 34 +++---- .../ip/subnet/validation/SubnetValidator.java | 8 +- 24 files changed, 426 insertions(+), 380 deletions(-) delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/AclWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/AclWriter.java index a1bdf6aa9..ce4494757 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/AclWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/AclWriter.java @@ -17,10 +17,10 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static com.google.common.base.Preconditions.checkNotNull; -import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte; import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; import java.util.concurrent.CompletionStage; @@ -36,13 +36,14 @@ import org.openvpp.jvpp.core.dto.InputAclSetInterface; import org.openvpp.jvpp.core.dto.InputAclSetInterfaceReply; import org.openvpp.jvpp.core.future.FutureJVppCore; -interface AclWriter { +interface AclWriter extends ByteDataTranslator, JvppReplyConsumer { default void inputAclSetInterface(@Nonnull final FutureJVppCore futureJVppCore, final boolean isAdd, @Nonnull final InstanceIdentifier id, @Nonnull final AclBaseAttributes acl, - @Nonnegative final int ifIndex, @Nonnull final VppClassifierContextManager classifyTableContext, + @Nonnegative final int ifIndex, + @Nonnull final VppClassifierContextManager classifyTableContext, @Nonnull final MappingContext mappingContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final InputAclSetInterface request = new InputAclSetInterface(); request.isAdd = booleanToByte(isAdd); request.swIfIndex = ifIndex; @@ -67,8 +68,8 @@ interface AclWriter { } final CompletionStage inputAclSetInterfaceReplyCompletionStage = - futureJVppCore.inputAclSetInterface(request); + futureJVppCore.inputAclSetInterface(request); - TranslateUtils.getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizer.java index 1e3057d8c..04398f4b3 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizer.java @@ -20,8 +20,8 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.v3po.util.AbstractInterfaceTypeCustomizer; +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 io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -35,13 +35,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Gre; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.core.future.FutureJVppCore; import org.openvpp.jvpp.core.dto.GreAddDelTunnel; import org.openvpp.jvpp.core.dto.GreAddDelTunnelReply; +import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class GreCustomizer extends AbstractInterfaceTypeCustomizer { +public class GreCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class); private final NamingContext interfaceContext; @@ -51,6 +51,17 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { this.interfaceContext = interfaceContext; } + private static GreAddDelTunnel getGreTunnelRequest(final byte isAdd, final byte[] srcAddr, final byte[] dstAddr, + final int outerFibId, final byte isIpv6) { + final GreAddDelTunnel greAddDelTunnel = new GreAddDelTunnel(); + greAddDelTunnel.isAdd = isAdd; + greAddDelTunnel.srcAddress = srcAddr; + greAddDelTunnel.dstAddress = dstAddr; + greAddDelTunnel.outerFibId = outerFibId; + greAddDelTunnel.isIpv6 = isIpv6; + return greAddDelTunnel; + } + @Override protected Class getExpectedInterfaceType() { return GreTunnel.class; @@ -58,7 +69,7 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { @Override protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataAfter, - @Nonnull final WriteContext writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); try { @@ -91,8 +102,10 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { } private void createGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, - final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(gre) ? 1 : 0); + final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { + final byte isIpv6 = (byte) (isIpv6(gre) + ? 1 + : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(gre.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(gre.getDst())); @@ -104,9 +117,9 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { dstAddress.getAddress(), outerFibId, isIpv6)); final GreAddDelTunnelReply reply = - TranslateUtils.getReplyForWrite(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Gre tunnel set successfully for: {}, gre: {}", swIfName, gre); - if(interfaceContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { + if (interfaceContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { // VPP keeps gre tunnels present even after they are delete(reserving ID for next tunnel) // This may cause inconsistencies in mapping context when configuring tunnels like this: // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. gre_tunnel0 -> 6 @@ -116,7 +129,7 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { // new name for that ID final String formerName = interfaceContext.getName(reply.swIfIndex, writeContext.getMappingContext()); LOG.debug("Removing updated mapping of a gre tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); + reply.swIfIndex, formerName, swIfName); interfaceContext.removeName(formerName, writeContext.getMappingContext()); } // Add new interface to our interface context @@ -126,22 +139,26 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { private boolean isIpv6(final Gre gre) { if (gre.getSrc().getIpv4Address() == null) { checkArgument(gre.getDst().getIpv4Address() == null, "Inconsistent ip addresses: %s, %s", gre.getSrc(), - gre.getDst()); + gre.getDst()); return true; } else { checkArgument(gre.getDst().getIpv6Address() == null, "Inconsistent ip addresses: %s, %s", gre.getSrc(), - gre.getDst()); + gre.getDst()); return false; } } private String getAddressString(final IpAddress addr) { - return addr.getIpv4Address() == null ? addr.getIpv6Address().getValue() : addr.getIpv4Address().getValue(); + return addr.getIpv4Address() == null + ? addr.getIpv6Address().getValue() + : addr.getIpv4Address().getValue(); } private void deleteGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, - final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(gre) ? 1 : 0); + final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { + final byte isIpv6 = (byte) (isIpv6(gre) + ? 1 + : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(gre.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(gre.getDst())); @@ -152,20 +169,9 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer { getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 0 /* is add */, srcAddress.getAddress(), dstAddress.getAddress(), outerFibId, isIpv6)); - TranslateUtils.getReplyForWrite(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Gre tunnel deleted successfully for: {}, gre: {}", swIfName, gre); // Remove interface from our interface context interfaceContext.removeName(swIfName, writeContext.getMappingContext()); } - - private static GreAddDelTunnel getGreTunnelRequest(final byte isAdd, final byte[] srcAddr, final byte[] dstAddr, - final int outerFibId, final byte isIpv6) { - final GreAddDelTunnel greAddDelTunnel = new GreAddDelTunnel(); - greAddDelTunnel.isAdd = isAdd; - greAddDelTunnel.srcAddress = srcAddr; - greAddDelTunnel.dstAddress = dstAddr; - greAddDelTunnel.outerFibId = outerFibId; - greAddDelTunnel.isIpv6 = isIpv6; - return greAddDelTunnel; - } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterconnectionWriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterconnectionWriteUtils.java index 64d262f23..e6b93dfee 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterconnectionWriteUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterconnectionWriteUtils.java @@ -19,11 +19,11 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.Interconnection; @@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory; /** * Utility class providing Interconnection CUD support. */ -final class InterconnectionWriteUtils { +final class InterconnectionWriteUtils implements JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(InterconnectionWriteUtils.class); @@ -61,7 +61,7 @@ final class InterconnectionWriteUtils { void setInterconnection(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final Interconnection ic, final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { try { if (ic == null) { // TODO in case of update we should delete interconnection LOG.trace("Interconnection is not set. Skipping"); @@ -77,14 +77,14 @@ final class InterconnectionWriteUtils { } } catch (VppBaseCallException e) { LOG.warn("Failed to update bridge/xconnect based interconnection flags for: {}, interconnection: {}", - ifcName, ic); + ifcName, ic); throw new WriteFailedException(id, "Unable to handle Interconnection of type " + ic.getClass(), e); } } void deleteInterconnection(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final Interconnection ic, final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { try { if (ic == null) { // TODO in case of update we should delete interconnection LOG.trace("Interconnection is not set. Skipping"); @@ -98,7 +98,7 @@ final class InterconnectionWriteUtils { } } catch (VppBaseCallException e) { LOG.warn("Failed to delete bridge/xconnect based interconnection flags for: {}, interconnection: {}", - ifcName, ic); + ifcName, ic); throw new WriteFailedException(id, "Unable to delete Interconnection of type " + ic.getClass(), e); } } @@ -106,27 +106,27 @@ final class InterconnectionWriteUtils { private void setBridgeBasedL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final BridgeBased bb, final WriteContext writeContext, final byte enabled) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Setting bridge based interconnection(bridge-domain={}) for interface: {}", bb.getBridgeDomain(), - ifcName); + ifcName); String bdName = bb.getBridgeDomain(); int bdId = bridgeDomainContext.getIndex(bdName, writeContext.getMappingContext()); checkArgument(bdId > 0, "Unable to set Interconnection for Interface: %s, bridge domain: %s does not exist", - ifcName, bdName); + ifcName, bdName); byte bvi = bb.isBridgedVirtualInterface() - ? (byte) 1 - : (byte) 0; + ? (byte) 1 + : (byte) 0; byte shg = 0; if (bb.getSplitHorizonGroup() != null) { shg = bb.getSplitHorizonGroup().byteValue(); } final CompletionStage swInterfaceSetL2BridgeReplyCompletionStage = futureJVppCore - .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bvi, enabled)); - TranslateUtils.getReplyForWrite(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture(), id); + .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bvi, enabled)); + getReplyForWrite(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifcName, bb); } @@ -145,19 +145,19 @@ final class InterconnectionWriteUtils { private void setXconnectBasedL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final XconnectBased ic, final WriteContext writeContext, final byte enabled) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { String outSwIfName = ic.getXconnectOutgoingInterface(); LOG.debug("Setting xconnect based interconnection(outgoing ifc={}) for interface: {}", outSwIfName, ifcName); int outSwIfIndex = interfaceContext.getIndex(outSwIfName, writeContext.getMappingContext()); checkArgument(outSwIfIndex > 0, - "Unable to set Interconnection for Interface: %s, outgoing interface: %s does not exist", - ifcName, outSwIfIndex); + "Unable to set Interconnection for Interface: %s, outgoing interface: %s does not exist", + ifcName, outSwIfIndex); final CompletionStage swInterfaceSetL2XconnectReplyCompletionStage = - futureJVppCore - .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, enabled)); - TranslateUtils.getReplyForWrite(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture(), id); + futureJVppCore + .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, enabled)); + getReplyForWrite(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifcName, ic); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceCustomizer.java index be0c4af09..91861015c 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceCustomizer.java @@ -18,11 +18,11 @@ package io.fd.honeycomb.translate.v3po.interfaces; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; 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.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.v3po.util.NamingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; @@ -38,7 +38,8 @@ import org.slf4j.LoggerFactory; /** * Ietf interface write customizer that only caches interface objects for child writers */ -public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer { +public class InterfaceCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); private final NamingContext interfaceContext; @@ -52,7 +53,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { try { setInterface(id, dataAfter, writeContext); @@ -67,7 +68,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri @Nonnull final Interface dataBefore, @Nonnull final Interface dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { try { updateInterface(id, dataBefore, dataAfter, writeContext); @@ -86,41 +87,45 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri private void setInterface(final InstanceIdentifier id, final Interface swIf, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Setting interface: {} to: {}", id, swIf); setInterfaceAttributes(id, swIf, swIf.getName(), writeContext); } private void setInterfaceAttributes(final InstanceIdentifier id, final Interface swIf, final String swIfName, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { setInterfaceFlags(id, swIfName, interfaceContext.getIndex(swIfName, writeContext.getMappingContext()), - swIf.isEnabled() ? (byte) 1 : (byte) 0); + swIf.isEnabled() + ? (byte) 1 + : (byte) 0); } private void updateInterface(final InstanceIdentifier id, final Interface dataBefore, final Interface dataAfter, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Updating interface:{} to: {}", id, dataAfter); setInterfaceAttributes(id, dataAfter, dataAfter.getName(), writeContext); } private void setInterfaceFlags(final InstanceIdentifier id, final String swIfName, final int swIfIndex, final byte enabled) - throws VppBaseCallException, WriteTimeoutException { - final CompletionStage swInterfaceSetFlagsReplyFuture = getFutureJVpp().swInterfaceSetFlags( - getSwInterfaceSetFlagsInput(swIfIndex, enabled, (byte) 0 /* deleted */)); + throws VppBaseCallException, WriteTimeoutException { + final CompletionStage swInterfaceSetFlagsReplyFuture = + getFutureJVpp().swInterfaceSetFlags( + getSwInterfaceSetFlagsInput(swIfIndex, enabled, (byte) 0 /* deleted */)); LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}", swIfName, swIfIndex, enabled); - TranslateUtils.getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); + getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); LOG.debug("Interface flags updated successfully for: {}, index: {}, enabled: {}", swIfName, swIfIndex, enabled); } - private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled, final byte deleted) { + private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled, + final byte deleted) { final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); swInterfaceSetFlags.swIfIndex = swIfIndex; swInterfaceSetFlags.adminUpDown = enabled; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ProxyArpCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ProxyArpCustomizer.java index 18100e218..002cc4c77 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ProxyArpCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ProxyArpCustomizer.java @@ -19,8 +19,8 @@ package io.fd.honeycomb.translate.v3po.interfaces; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; 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 io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import java.net.InetAddress; @@ -31,14 +31,14 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.ProxyArp; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.core.future.FutureJVppCore; import org.openvpp.jvpp.core.dto.ProxyArpAddDel; import org.openvpp.jvpp.core.dto.ProxyArpAddDelReply; +import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCustomizer { +public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCustomizer, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(ProxyArpCustomizer.class); private final NamingContext interfaceContext; @@ -49,7 +49,8 @@ public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCu } @Override - public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull ProxyArp dataAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { + public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull ProxyArp dataAfter, + @Nonnull WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); try { @@ -93,7 +94,7 @@ public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCu dstAddress.getAddress(), vrfId)); final ProxyArpAddDelReply reply = - TranslateUtils.getReplyForWrite(proxyArpAddDelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(proxyArpAddDelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Proxy ARP setting applied, with reply context:", reply.context); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizer.java index ebaad456b..b17cfc820 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizer.java @@ -16,15 +16,14 @@ package io.fd.honeycomb.translate.v3po.interfaces; -import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte; - import com.google.common.base.Preconditions; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; 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.SubInterfaceUtils; import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -49,7 +48,8 @@ import org.slf4j.LoggerFactory; * Writer Customizer responsible for vlan tag rewrite.
Sends {@code l2_interface_vlan_tag_rewrite} message to * VPP.
Equivalent of invoking {@code vppctl set interface l2 tag-rewrite} command. */ -public class RewriteCustomizer extends FutureJVppCustomizer implements WriterCustomizer { +public class RewriteCustomizer extends FutureJVppCustomizer + implements WriterCustomizer, ByteDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class); private final NamingContext interfaceContext; @@ -80,14 +80,14 @@ public class RewriteCustomizer extends FutureJVppCustomizer implements WriterCus private void setTagRewrite(final InstanceIdentifier id, final String ifname, final Rewrite rewrite, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final int swIfIndex = interfaceContext.getIndex(ifname, writeContext.getMappingContext()); LOG.debug("Setting tag rewrite for interface {}(id=): {}", ifname, swIfIndex, rewrite); final CompletionStage replyCompletionStage = getFutureJVpp().l2InterfaceVlanTagRewrite(getTagRewriteRequest(swIfIndex, rewrite)); - TranslateUtils.getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); LOG.debug("Tag rewrite for interface {}(id=) set successfully: {}", ifname, swIfIndex, rewrite); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java index 51bf31d07..44fd8807c 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/RoutingCustomizer.java @@ -16,13 +16,13 @@ package io.fd.honeycomb.translate.v3po.interfaces; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; 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.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; @@ -35,7 +35,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer { +public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class); private final NamingContext interfaceContext; @@ -48,7 +48,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String ifName = id.firstKeyOf(Interface.class).getName(); try { @@ -63,7 +63,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String ifName = id.firstKeyOf(Interface.class).getName(); try { @@ -86,13 +86,14 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus LOG.debug("Setting routing for interface: {}, {}. Routing: {}", name, swIfc, rt); int vrfId = (rt != null) - ? rt.getVrfId().intValue() - : 0; + ? rt.getVrfId().intValue() + : 0; if (vrfId != 0) { final CompletionStage swInterfaceSetTableReplyCompletionStage = - getFutureJVpp().swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, /* isIpv6 */ vrfId)); - TranslateUtils.getReplyForWrite(swInterfaceSetTableReplyCompletionStage.toCompletableFuture(), id); + getFutureJVpp() + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, /* isIpv6 */ vrfId)); + getReplyForWrite(swInterfaceSetTableReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizer.java index 10dd60841..f2c1cc418 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizer.java @@ -19,17 +19,16 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static com.google.common.base.Preconditions.checkState; import static io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils.getNumberOfTags; import static io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils.getSubInterfaceName; -import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte; import com.google.common.base.Preconditions; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; 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 io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.List; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -60,12 +59,13 @@ import org.slf4j.LoggerFactory; * Equivalent of invoking {@code vppclt create subif} command. */ public class SubInterfaceCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer { + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class); private final NamingContext interfaceContext; - public SubInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext) { + public SubInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { super(futureJVppCore); this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null"); } @@ -73,7 +73,7 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String superIfName = id.firstKeyOf(Interface.class).getName(); try { createSubInterface(id, superIfName, dataAfter, writeContext); @@ -89,15 +89,15 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer WriteTimeoutException { final int superIfIndex = interfaceContext.getIndex(superIfName, writeContext.getMappingContext()); final CompletionStage createSubifReplyCompletionStage = - getFutureJVpp().createSubif(getCreateSubifRequest(subInterface, superIfIndex)); + getFutureJVpp().createSubif(getCreateSubifRequest(subInterface, superIfIndex)); final CreateSubifReply reply = - TranslateUtils.getReplyForWrite(createSubifReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(createSubifReplyCompletionStage.toCompletableFuture(), id); setInterfaceState(id, reply.swIfIndex, booleanToByte(subInterface.isEnabled())); interfaceContext.addName(reply.swIfIndex, - getSubInterfaceName(superIfName, Math.toIntExact(subInterface.getIdentifier())), - writeContext.getMappingContext()); + getSubInterfaceName(superIfName, Math.toIntExact(subInterface.getIdentifier())), + writeContext.getMappingContext()); LOG.debug("Sub interface created successfully for: {}, subInterface: {}", superIfName, subInterface); } @@ -124,7 +124,7 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer // TODO HONEYCOMB-183 match should be mandatory final MatchType matchType = subInterface.getMatch().getMatchType(); request.exactMatch = - booleanToByte(matchType instanceof VlanTagged && ((VlanTagged) matchType).isMatchExactTags()); + booleanToByte(matchType instanceof VlanTagged && ((VlanTagged) matchType).isMatchExactTags()); request.defaultSub = booleanToByte(matchType instanceof Default); if (numberOfTags > 0) { @@ -167,41 +167,41 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final SubInterface dataBefore, @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String subIfaceName = getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(dataAfter.getIdentifier())); + Math.toIntExact(dataAfter.getIdentifier())); try { setInterfaceState(id, interfaceContext.getIndex(subIfaceName, writeContext.getMappingContext()), - booleanToByte(dataAfter.isEnabled())); + booleanToByte(dataAfter.isEnabled())); } catch (VppBaseCallException e) { LOG.warn("Failed to update interface state for: interface if={}, enabled: {}", - subIfaceName, booleanToByte(dataAfter.isEnabled())); + subIfaceName, booleanToByte(dataAfter.isEnabled())); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); } } private void setInterfaceState(final InstanceIdentifier id, final int swIfIndex, final byte enabled) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); swInterfaceSetFlags.swIfIndex = swIfIndex; swInterfaceSetFlags.adminUpDown = enabled; final CompletionStage swInterfaceSetFlagsReplyFuture = - getFutureJVpp().swInterfaceSetFlags(swInterfaceSetFlags); + getFutureJVpp().swInterfaceSetFlags(swInterfaceSetFlags); LOG.debug("Updating interface state for interface if={}, enabled: {}", swIfIndex, enabled); SwInterfaceSetFlagsReply reply = - TranslateUtils.getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); + getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); LOG.debug("Interface state updated successfully for interface index: {}, enabled: {}, ctxId: {}", - swIfIndex, enabled, reply.context); + swIfIndex, enabled, reply.context); } @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final SubInterface dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException.DeleteFailedException { + throws WriteFailedException.DeleteFailedException { throw new UnsupportedOperationException("Sub interface delete is not supported"); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceL2Customizer.java index cfb78499a..8bccb7a99 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceL2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceL2Customizer.java @@ -16,11 +16,11 @@ package io.fd.honeycomb.translate.v3po.interfaces; -import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizer.java index ba3c99ca8..3dec19803 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizer.java @@ -17,10 +17,11 @@ package io.fd.honeycomb.translate.v3po.interfaces; import io.fd.honeycomb.translate.v3po.util.AbstractInterfaceTypeCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.v3po.util.MacTranslator; import io.fd.honeycomb.translate.v3po.util.NamingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; +import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -40,7 +41,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TapCustomizer extends AbstractInterfaceTypeCustomizer { +public class TapCustomizer extends AbstractInterfaceTypeCustomizer implements MacTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(TapCustomizer.class); private final NamingContext interfaceContext; @@ -57,8 +58,8 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { @Override protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Tap dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { + @Nonnull final WriteContext writeContext) + throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); try { createTap(id, ifcName, dataAfter, writeContext); @@ -71,7 +72,7 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Tap dataBefore, @Nonnull final Tap dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); final int index; @@ -92,7 +93,7 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Tap dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); final int index; @@ -114,31 +115,33 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Setting tap interface: {}. Tap: {}", swIfName, tap); final CompletionStage tapConnectFuture = - getFutureJVpp().tapConnect(getTapConnectRequest(tap.getTapName(), tap.getMac(), tap.getDeviceInstance())); + getFutureJVpp() + .tapConnect(getTapConnectRequest(tap.getTapName(), tap.getMac(), tap.getDeviceInstance())); final TapConnectReply reply = - TranslateUtils.getReplyForWrite(tapConnectFuture.toCompletableFuture(), id); + getReplyForWrite(tapConnectFuture.toCompletableFuture(), id); LOG.debug("Tap set successfully for: {}, tap: {}", swIfName, tap); // Add new interface to our interface context interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); } private void modifyTap(final InstanceIdentifier id, final String swIfName, final int index, final Tap tap) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Modifying tap interface: {}. Tap: {}", swIfName, tap); final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().tapModify(getTapModifyRequest(tap.getTapName(), index, tap.getMac(), tap.getDeviceInstance())); - TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getFutureJVpp() + .tapModify(getTapModifyRequest(tap.getTapName(), index, tap.getMac(), tap.getDeviceInstance())); + getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Tap modified successfully for: {}, tap: {}", swIfName, tap); } private void deleteTap(final InstanceIdentifier id, final String swIfName, final int index, final Tap dataBefore, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Deleting tap interface: {}. Tap: {}", swIfName, dataBefore); final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().tapDelete(getTapDeleteRequest(index)); - TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getFutureJVpp().tapDelete(getTapDeleteRequest(index)); + getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Tap deleted successfully for: {}, tap: {}", swIfName, dataBefore); // Remove deleted interface from interface context interfaceContext.removeName(swIfName, writeContext.getMappingContext()); @@ -148,15 +151,15 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { final TapConnect tapConnect = new TapConnect(); tapConnect.tapName = tapName.getBytes(); - if(mac == null) { + if (mac == null) { tapConnect.useRandomMac = 1; tapConnect.macAddress = new byte[6]; } else { tapConnect.useRandomMac = 0; - tapConnect.macAddress = TranslateUtils.parseMac(mac.getValue()); + tapConnect.macAddress = parseMac(mac.getValue()); } - if(deviceInstance == null) { + if (deviceInstance == null) { tapConnect.renumber = 0; } else { tapConnect.renumber = 1; @@ -166,20 +169,21 @@ public class TapCustomizer extends AbstractInterfaceTypeCustomizer { return tapConnect; } - private TapModify getTapModifyRequest(final String tapName, final int swIndex, final PhysAddress mac, final Long deviceInstance) { + private TapModify getTapModifyRequest(final String tapName, final int swIndex, final PhysAddress mac, + final Long deviceInstance) { final TapModify tapConnect = new TapModify(); tapConnect.tapName = tapName.getBytes(); tapConnect.swIfIndex = swIndex; - if(mac == null) { + if (mac == null) { tapConnect.useRandomMac = 1; tapConnect.macAddress = new byte[6]; } else { tapConnect.useRandomMac = 0; - tapConnect.macAddress = TranslateUtils.parseMac(mac.getValue()); + tapConnect.macAddress = parseMac(mac.getValue()); } - if(deviceInstance == null) { + if (deviceInstance == null) { tapConnect.renumber = 0; } else { tapConnect.renumber = 1; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizer.java index d4e734da1..b66afb2b5 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizer.java @@ -18,10 +18,11 @@ package io.fd.honeycomb.translate.v3po.interfaces; import com.google.common.base.Preconditions; import io.fd.honeycomb.translate.v3po.util.AbstractInterfaceTypeCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +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 io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; +import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -44,7 +45,8 @@ import org.slf4j.LoggerFactory; /** * Writer Customizer responsible for passing vhost user interface CRD operations to VPP */ -public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer { +public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer + implements ByteDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); private final NamingContext interfaceContext; @@ -61,7 +63,7 @@ public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer id, - @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) + @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); try { @@ -74,13 +76,13 @@ public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Creating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage createVhostUserIfReplyCompletionStage = getFutureJVpp().createVhostUserIf(getCreateVhostUserIfRequest(vhostUser)); final CreateVhostUserIfReply reply = - TranslateUtils.getReplyForWrite(createVhostUserIfReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(createVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface created successfully for: {}, vhostUser: {}", swIfName, vhostUser); // Add new interface to our interface context interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); @@ -88,7 +90,7 @@ public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Updating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage modifyVhostUserIfReplyCompletionStage = getFutureJVpp() - .modifyVhostUserIf(getModifyVhostUserIfRequest(vhostUser, interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); + .modifyVhostUserIf(getModifyVhostUserIfRequest(vhostUser, + interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); - TranslateUtils.getReplyForWrite(modifyVhostUserIfReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(modifyVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface updated successfully for: {}, vhostUser: {}", swIfName, vhostUser); } private ModifyVhostUserIf getModifyVhostUserIfRequest(final VhostUser vhostUser, final int swIfIndex) { ModifyVhostUserIf request = new ModifyVhostUserIf(); - request.isServer = TranslateUtils.booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); + request.isServer = booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); request.sockFilename = vhostUser.getSocket().getBytes(); // TODO HONEYCOMB-177 request.renumber = 0; @@ -150,12 +153,13 @@ public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { LOG.debug("Deleting vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage deleteVhostUserIfReplyCompletionStage = - getFutureJVpp().deleteVhostUserIf(getDeleteVhostUserIfRequest(interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); + getFutureJVpp().deleteVhostUserIf(getDeleteVhostUserIfRequest( + interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); - TranslateUtils.getReplyForWrite(deleteVhostUserIfReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(deleteVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface deleted successfully for: {}, vhostUser: {}", swIfName, vhostUser); // Remove interface from our interface context interfaceContext.removeName(swIfName, writeContext.getMappingContext()); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizer.java index 1513f7b15..d96ef3e34 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizer.java @@ -21,8 +21,8 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; import io.fd.honeycomb.translate.v3po.util.AbstractInterfaceTypeCustomizer; +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 io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -42,7 +42,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { +public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); @@ -64,7 +64,7 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { @Override protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataAfter, - @Nonnull final WriteContext writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); try { @@ -98,7 +98,9 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { private void createVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(vxlan) ? 1 : 0); + final byte isIpv6 = (byte) (isIpv6(vxlan) + ? 1 + : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(vxlan.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(vxlan.getDst())); @@ -111,7 +113,7 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { dstAddress.getAddress(), encapVrfId, -1, vni, isIpv6)); final VxlanAddDelTunnelReply reply = - TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vxlan tunnel set successfully for: {}, vxlan: {}", swIfName, vxlan); if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { // VPP keeps vxlan tunnels present even after they are delete(reserving ID for next tunnel) @@ -123,7 +125,7 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { // new name for that ID final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); LOG.debug("Removing updated mapping of a vxlan tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); + reply.swIfIndex, formerName, swIfName); interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); } @@ -142,22 +144,26 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { private boolean isIpv6(final Vxlan vxlan) { if (vxlan.getSrc().getIpv4Address() == null) { checkArgument(vxlan.getDst().getIpv4Address() == null, "Inconsistent ip addresses: %s, %s", vxlan.getSrc(), - vxlan.getDst()); + vxlan.getDst()); return true; } else { checkArgument(vxlan.getDst().getIpv6Address() == null, "Inconsistent ip addresses: %s, %s", vxlan.getSrc(), - vxlan.getDst()); + vxlan.getDst()); return false; } } private String getAddressString(final IpAddress addr) { - return addr.getIpv4Address() == null ? addr.getIpv6Address().getValue() : addr.getIpv4Address().getValue(); + return addr.getIpv4Address() == null + ? addr.getIpv6Address().getValue() + : addr.getIpv4Address().getValue(); } private void deleteVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(vxlan) ? 1 : 0); + final byte isIpv6 = (byte) (isIpv6(vxlan) + ? 1 + : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(vxlan.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(vxlan.getDst())); @@ -169,7 +175,7 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 0 /* is add */, srcAddress.getAddress(), dstAddress.getAddress(), encapVrfId, -1, vni, isIpv6)); - TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vxlan tunnel deleted successfully for: {}, vxlan: {}", swIfName, vxlan); final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); @@ -182,8 +188,8 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer { } private static VxlanAddDelTunnel getVxlanTunnelRequest(final byte isAdd, final byte[] srcAddr, final byte[] dstAddr, - final int encapVrfId, - final int decapNextIndex, final int vni, final byte isIpv6) { + final int encapVrfId, + final int decapNextIndex, final int vni, final byte isIpv6) { final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel(); vxlanAddDelTunnel.isAdd = isAdd; vxlanAddDelTunnel.srcAddress = srcAddr; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizer.java index 699c33d21..aeba262db 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizer.java @@ -21,11 +21,11 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; import io.fd.honeycomb.translate.v3po.util.AbstractInterfaceTypeCustomizer; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import java.net.InetAddress; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -42,7 +42,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer { +public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class); private final NamingContext interfaceNamingContext; @@ -62,8 +62,9 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, @Nonnull final VxlanGpe dataAfter, - @Nonnull final WriteContext writeContext) + protected final void writeInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpe dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); try { @@ -75,7 +76,8 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, @Nonnull final VxlanGpe dataBefore, + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpe dataBefore, @Nonnull final VxlanGpe dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, @@ -83,7 +85,8 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, @Nonnull final VxlanGpe dataBefore, + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpe dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { final String swIfName = id.firstKeyOf(Interface.class).getName(); @@ -97,8 +100,10 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VxlanGpe vxlanGpe, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(vxlanGpe) ? 1 : 0); + throws VppBaseCallException, WriteTimeoutException { + final byte isIpv6 = (byte) (isIpv6(vxlanGpe) + ? 1 + : 0); final InetAddress Local = InetAddresses.forString(getAddressString(vxlanGpe.getLocal())); final InetAddress Remote = InetAddresses.forString(getAddressString(vxlanGpe.getRemote())); @@ -110,15 +115,15 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer VxlanGpeAddDelTunnelReplyCompletionStage = getFutureJVpp().vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 1 /* is add */, Local.getAddress(), - Remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + Remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); final VxlanGpeAddDelTunnelReply reply = - TranslateUtils.getReplyForWrite(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("VxlanGpe tunnel set successfully for: {}, VxlanGpe: {}", swIfName, vxlanGpe); if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); LOG.debug("Removing updated mapping of a vxlan-gpe tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); + reply.swIfIndex, formerName, swIfName); interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); } @@ -135,24 +140,30 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VxlanGpe vxlanGpe, final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { - final byte isIpv6 = (byte) (isIpv6(vxlanGpe) ? 1 : 0); + throws VppBaseCallException, WriteTimeoutException { + final byte isIpv6 = (byte) (isIpv6(vxlanGpe) + ? 1 + : 0); final InetAddress local = InetAddresses.forString(getAddressString(vxlanGpe.getLocal())); final InetAddress remote = InetAddresses.forString(getAddressString(vxlanGpe.getRemote())); @@ -163,10 +174,11 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer VxlanGpeAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, local.getAddress(), - remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + getFutureJVpp() + .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, local.getAddress(), + remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); - TranslateUtils.getReplyForWrite(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); // Mark this interface as disabled to not include it in operational reads @@ -177,9 +189,11 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer type of access control list entry */ -abstract class AbstractAceWriter implements AceWriter { +abstract class AbstractAceWriter implements AceWriter, JvppReplyConsumer { // TODO: HONEYCOMB-181 minimise memory used by classify tables (we create a lot of them to make ietf-acl model // mapping more convenient): @@ -60,7 +60,7 @@ abstract class AbstractAceWriter implements AceWriter { static final int VLAN_TAG_LEN = 4; private static final Collector SINGLE_ITEM_COLLECTOR = - RWUtils.singleItemCollector(); + RWUtils.singleItemCollector(); private final FutureJVppCore futureJVppCore; @@ -107,9 +107,9 @@ abstract class AbstractAceWriter implements AceWriter { @Override public final void write(@Nonnull final InstanceIdentifier id, @Nonnull final List aces, @Nonnull final InputAclSetInterface request, @Nonnegative final int vlanTags) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final PacketHandling action = aces.stream().map(ace -> ace.getActions().getPacketHandling()).distinct() - .collect(SINGLE_ITEM_COLLECTOR); + .collect(SINGLE_ITEM_COLLECTOR); checkArgument(vlanTags >= 0 && vlanTags <= 2, "Number of vlan tags %s is not in [0,2] range"); @@ -118,29 +118,29 @@ abstract class AbstractAceWriter implements AceWriter { // Create table + session per entry final ClassifyAddDelTable ctRequest = - createClassifyTable(action, (T) ace.getMatches().getAceType(), nextTableIndex, vlanTags); + createClassifyTable(action, (T) ace.getMatches().getAceType(), nextTableIndex, vlanTags); nextTableIndex = createClassifyTable(id, ctRequest); createClassifySession(id, - createClassifySession(action, (T) ace.getMatches().getAceType(), nextTableIndex, vlanTags)); + createClassifySession(action, (T) ace.getMatches().getAceType(), nextTableIndex, vlanTags)); } setClassifyTable(request, nextTableIndex); } private int createClassifyTable(@Nonnull final InstanceIdentifier id, @Nonnull final ClassifyAddDelTable request) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final CompletionStage cs = futureJVppCore.classifyAddDelTable(request); - final ClassifyAddDelTableReply reply = TranslateUtils.getReplyForWrite(cs.toCompletableFuture(), id); + final ClassifyAddDelTableReply reply = getReplyForWrite(cs.toCompletableFuture(), id); return reply.newTableIndex; } private void createClassifySession(@Nonnull final InstanceIdentifier id, @Nonnull final ClassifyAddDelSession request) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final CompletionStage cs = futureJVppCore.classifyAddDelSession(request); - TranslateUtils.getReplyForWrite(cs.toCompletableFuture(), id); + getReplyForWrite(cs.toCompletableFuture(), id); } protected ClassifyAddDelTable createClassifyTable(@Nonnull final PacketHandling action, final int nextTableIndex) { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriter.java index f6bb9c879..395058399 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/AceEthWriter.java @@ -17,7 +17,7 @@ package io.fd.honeycomb.translate.v3po.interfaces.acl; import com.google.common.annotations.VisibleForTesting; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.MacTranslator; import java.util.List; 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; @@ -29,7 +29,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class AceEthWriter extends AbstractAceWriter { +final class AceEthWriter extends AbstractAceWriter implements MacTranslator { @VisibleForTesting static final int MATCH_N_VECTORS = 1; @@ -54,10 +54,10 @@ final class AceEthWriter extends AbstractAceWriter { if (aceEth.getDestinationMacAddressMask() != null) { aceIsEmpty = false; final String macAddress = aceEth.getDestinationMacAddressMask().getValue(); - final List parts = TranslateUtils.COLON_SPLITTER.splitToList(macAddress); + final List parts = COLON_SPLITTER.splitToList(macAddress); int i = 0; for (String part : parts) { - request.mask[i++] = TranslateUtils.parseHexByte(part); + request.mask[i++] = parseHexByte(part); } } else if (aceEth.getDestinationMacAddress() != null) { aceIsEmpty = false; @@ -71,10 +71,10 @@ final class AceEthWriter extends AbstractAceWriter { if (aceEth.getSourceMacAddressMask() != null) { aceIsEmpty = false; final String macAddress = aceEth.getSourceMacAddressMask().getValue(); - final List parts = TranslateUtils.COLON_SPLITTER.splitToList(macAddress); + final List parts = COLON_SPLITTER.splitToList(macAddress); int i = 6; for (String part : parts) { - request.mask[i++] = TranslateUtils.parseHexByte(part); + request.mask[i++] = parseHexByte(part); } } else if (aceEth.getSourceMacAddress() != null) { aceIsEmpty = false; @@ -85,7 +85,7 @@ final class AceEthWriter extends AbstractAceWriter { if (aceIsEmpty) { throw new IllegalArgumentException( - String.format("Ace %s does not define packet field match values", aceEth.toString())); + String.format("Ace %s does not define packet field match values", aceEth.toString())); } request.skipNVectors = 0; @@ -108,26 +108,27 @@ final class AceEthWriter extends AbstractAceWriter { if (aceEth.getDestinationMacAddress() != null) { noMatch = false; final String macAddress = aceEth.getDestinationMacAddress().getValue(); - final List parts = TranslateUtils.COLON_SPLITTER.splitToList(macAddress); + final List parts = COLON_SPLITTER.splitToList(macAddress); int i = 0; for (String part : parts) { - request.match[i++] = TranslateUtils.parseHexByte(part); + request.match[i++] = parseHexByte(part); } } if (aceEth.getSourceMacAddress() != null) { noMatch = false; final String macAddress = aceEth.getSourceMacAddress().getValue(); - final List parts = TranslateUtils.COLON_SPLITTER.splitToList(macAddress); + final List parts = COLON_SPLITTER.splitToList(macAddress); int i = 6; for (String part : parts) { - request.match[i++] = TranslateUtils.parseHexByte(part); + request.match[i++] = parseHexByte(part); } } if (noMatch) { throw new IllegalArgumentException( - String.format("Ace %s does not define neither source nor destination MAC address", aceEth.toString())); + String.format("Ace %s does not define neither source nor destination MAC address", + aceEth.toString())); } LOG.debug("ACE action={}, rule={} translated to session={}.", action, aceEth, request); 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 { +final class AceIp4Writer extends AbstractAceWriter implements Ipv4Translator { @VisibleForTesting static final int MATCH_N_VECTORS = 3; // number of 16B vectors @@ -63,7 +63,8 @@ final class AceIp4Writer extends AbstractAceWriter { 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 { 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 { 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 { 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); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAClWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAClWriter.java index 3f75d6729..f337cebd0 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAClWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/acl/IetfAClWriter.java @@ -20,7 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -54,7 +54,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class IetfAClWriter { +public final class IetfAClWriter implements JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(IetfAClWriter.class); private final FutureJVppCore jvpp; @@ -75,12 +75,12 @@ public final class IetfAClWriter { // ietf-acl updates are handled first, so we use writeContext.readAfter final Optional - aclOptional = writeContext.readAfter(AclWriter.ACL_ID.child( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class, - new AclKey(aclName, aclType))); + aclOptional = writeContext.readAfter(AclWriter.ACL_ID.child( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl.class, + new AclKey(aclName, aclType))); checkArgument(aclOptional.isPresent(), "Acl lists not configured"); final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl - acl = aclOptional.get(); + acl = aclOptional.get(); final AccessListEntries accessListEntries = acl.getAccessListEntries(); checkArgument(accessListEntries != null, "access list entries not configured"); @@ -89,13 +89,13 @@ public final class IetfAClWriter { } void deleteAcl(@Nonnull final InstanceIdentifier id, final int swIfIndex) - throws WriteTimeoutException, WriteFailedException.DeleteFailedException { + throws WriteTimeoutException, WriteFailedException.DeleteFailedException { final ClassifyTableByInterface request = new ClassifyTableByInterface(); request.swIfIndex = swIfIndex; try { final CompletionStage cs = jvpp.classifyTableByInterface(request); - final ClassifyTableByInterfaceReply reply = TranslateUtils.getReplyForWrite(cs.toCompletableFuture(), id); + final ClassifyTableByInterfaceReply reply = getReplyForWrite(cs.toCompletableFuture(), id); // We unassign and remove all ACL-related classify tables for given interface (we assume we are the only // classify table manager) @@ -112,7 +112,7 @@ public final class IetfAClWriter { private void unassignClassifyTables(@Nonnull final InstanceIdentifier id, final ClassifyTableByInterfaceReply currentState) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { final InputAclSetInterface request = new InputAclSetInterface(); request.isAdd = 0; request.swIfIndex = currentState.swIfIndex; @@ -120,12 +120,12 @@ public final class IetfAClWriter { request.ip4TableIndex = currentState.ip4TableId; request.ip6TableIndex = currentState.ip6TableId; final CompletionStage inputAclSetInterfaceReplyCompletionStage = - jvpp.inputAclSetInterface(request); - TranslateUtils.getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); + jvpp.inputAclSetInterface(request); + getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); } private void removeClassifyTable(@Nonnull final InstanceIdentifier id, final int tableIndex) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { if (tableIndex == -1) { return; // classify table id is absent @@ -133,23 +133,23 @@ public final class IetfAClWriter { final ClassifyAddDelTable request = new ClassifyAddDelTable(); request.tableIndex = tableIndex; final CompletionStage cs = jvpp.classifyAddDelTable(request); - TranslateUtils.getReplyForWrite(cs.toCompletableFuture(), id); + getReplyForWrite(cs.toCompletableFuture(), id); } void write(@Nonnull final InstanceIdentifier id, final int swIfIndex, @Nonnull final List acls, @Nonnull final WriteContext writeContext) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { write(id, swIfIndex, acls, writeContext, 0); } void write(@Nonnull final InstanceIdentifier id, final int swIfIndex, @Nonnull final List acls, @Nonnull final WriteContext writeContext, @Nonnegative final int numberOfTags) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { // filter ACE entries and group by AceType final Map> acesByType = acls.stream() - .flatMap(acl -> aclToAceStream(acl, writeContext)) - .collect(Collectors.groupingBy(AclType::fromAce)); + .flatMap(acl -> aclToAceStream(acl, writeContext)) + .collect(Collectors.groupingBy(AclType::fromAce)); final InputAclSetInterface request = new InputAclSetInterface(); request.isAdd = 1; @@ -173,9 +173,8 @@ public final class IetfAClWriter { } final CompletionStage inputAclSetInterfaceReplyCompletionStage = - jvpp.inputAclSetInterface(request); - TranslateUtils.getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); - + jvpp.inputAclSetInterface(request); + getReplyForWrite(inputAclSetInterfaceReplyCompletionStage.toCompletableFuture(), id); } private enum AclType { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java index 574a42eb5..8ab5b6b62 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java @@ -45,7 +45,8 @@ import org.slf4j.LoggerFactory; /** * Customizer for writing {@link Address} */ -public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer { +public class Ipv4AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, Ipv4Writer { private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); private final NamingContext interfaceContext; @@ -131,8 +132,8 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListW final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); - final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); @@ -148,7 +149,7 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListW LOG.debug("Setting Subnet(prefix-length) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnet.getPrefixLength().byteValue()); LOG.debug("Subnet(prefix-length) set successfully for interface: {}(id={}). Subnet: {}, address: {}", diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java index 72d8277fc..ab25970e7 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java @@ -20,14 +20,16 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.v3po.util.AddressTranslator; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; 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.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; @@ -45,7 +47,8 @@ import org.slf4j.LoggerFactory; * Customizer for writing {@link Neighbor} for {@link Ipv4}. */ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer { + implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, + JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(Ipv4NeighbourCustomizer.class); @@ -119,15 +122,15 @@ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer IpNeighborAddDel request = new IpNeighborAddDel(); - request.isAdd = TranslateUtils.booleanToByte(add); + request.isAdd = booleanToByte(add); request.isIpv6 = 0; request.isStatic = 1; - request.dstAddress = TranslateUtils.ipv4AddressNoZoneToArray(data.getIp()); - request.macAddress = TranslateUtils.parseMac(data.getLinkLayerAddress().getValue()); + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); request.swIfIndex = parentInterfaceIndex; //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid //request.vrfId - TranslateUtils.getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); + getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); } } \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java deleted file mode 100644 index 412030200..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.honeycomb.translate.v3po.interfaces.ip; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; -import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddress; -import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; -import org.openvpp.jvpp.core.future.FutureJVppCore; - -/** - * Utility class providing Ipv4 CUD support. - */ -// TODO HONEYCOMB-175 replace with interface with default methods or abstract class -public final class Ipv4WriteUtils { - - private static final int DOTTED_QUAD_MASK_LENGTH = 4; - private static final int IPV4_ADDRESS_PART_BITS_COUNT = 8; - private static final int NETMASK_PART_LIMIT = 256; // 2 power to 8 - - private Ipv4WriteUtils() { - throw new UnsupportedOperationException("This utility class cannot be instantiated"); - } - - static void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, final InstanceIdentifier id, - @Nonnegative final int ifaceId, - @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) - throws VppBaseCallException, WriteTimeoutException { - checkArgument(prefixLength > 0, "Invalid prefix length"); - checkNotNull(address, "address should not be null"); - - final byte[] addressBytes = TranslateUtils.ipv4AddressNoZoneToArray(address); - - final CompletionStage swInterfaceAddDelAddressReplyCompletionStage = - futureJVppCore.swInterfaceAddDelAddress( - getSwInterfaceAddDelAddressRequest(ifaceId, TranslateUtils.booleanToByte(add) /* isAdd */, - (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); - - TranslateUtils.getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); - } - - static SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, - final byte ipv6, final byte deleteAll, - final byte length, final byte[] addr) { - final SwInterfaceAddDelAddress swInterfaceAddDelAddress = new SwInterfaceAddDelAddress(); - swInterfaceAddDelAddress.swIfIndex = swIfc; - swInterfaceAddDelAddress.isAdd = isAdd; - swInterfaceAddDelAddress.isIpv6 = ipv6; - swInterfaceAddDelAddress.delAll = deleteAll; - swInterfaceAddDelAddress.address = addr; - swInterfaceAddDelAddress.addressLength = length; - return swInterfaceAddDelAddress; - } - - /** - * Returns the prefix size in bits of the specified subnet mask. Example: For the subnet mask 255.255.255.128 it - * returns 25 while for 255.0.0.0 it returns 8. If the passed subnetMask array is not complete or contains not only - * leading ones, IllegalArgumentExpression is thrown - * - * @param mask the subnet mask in dot notation 255.255.255.255 - * @return the prefix length as number of bits - */ - public static byte getSubnetMaskLength(final String mask) { - String[] maskParts = mask.split("\\."); - - checkArgument(maskParts.length == DOTTED_QUAD_MASK_LENGTH, - "Network mask %s is not in Quad Dotted Decimal notation!", mask); - - long maskAsNumber = 0; - for (int i = 0; i < DOTTED_QUAD_MASK_LENGTH; i++) { - maskAsNumber <<= IPV4_ADDRESS_PART_BITS_COUNT; - int value = Integer.parseInt(maskParts[i]); - checkArgument(value < NETMASK_PART_LIMIT, "Network mask %s contains invalid number(s) over 255!", mask); - checkArgument(value >= 0, "Network mask %s contains invalid negative number(s)!", mask); - maskAsNumber += value; - } - - String bits = Long.toBinaryString(maskAsNumber); - checkArgument(bits.length() == IPV4_ADDRESS_PART_BITS_COUNT * DOTTED_QUAD_MASK_LENGTH, - "Incorrect network mask %s", mask); - final int leadingOnes = bits.indexOf('0'); - checkArgument(leadingOnes != -1, "Broadcast address %s is not allowed!", mask); - checkArgument(bits.substring(leadingOnes).indexOf('1') == -1, - "Non-contiguous network mask %s is not allowed!", mask); - return (byte) leadingOnes; - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java new file mode 100644 index 000000000..a950d45de --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java @@ -0,0 +1,109 @@ +/* + * 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.honeycomb.translate.v3po.interfaces.ip; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +import io.fd.honeycomb.translate.v3po.util.Ipv4Translator; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.VppBaseCallException; +import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddress; +import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; +import org.openvpp.jvpp.core.future.FutureJVppCore; + +/** + * Utility class providing Ipv4 CUD support. + */ +public interface Ipv4Writer extends ByteDataTranslator, Ipv4Translator, JvppReplyConsumer { + + int DOTTED_QUAD_MASK_LENGTH = 4; + int IPV4_ADDRESS_PART_BITS_COUNT = 8; + int NETMASK_PART_LIMIT = 256; // 2 power to 8 + + default void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, + final InstanceIdentifier id, + @Nonnegative final int ifaceId, + @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) + throws VppBaseCallException, WriteTimeoutException { + checkArgument(prefixLength > 0, "Invalid prefix length"); + checkNotNull(address, "address should not be null"); + + final byte[] addressBytes = ipv4AddressNoZoneToArray(address); + + final CompletionStage swInterfaceAddDelAddressReplyCompletionStage = + futureJVppCore.swInterfaceAddDelAddress( + getSwInterfaceAddDelAddressRequest(ifaceId, booleanToByte(add) /* isAdd */, + (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); + + getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); + } + + default SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, + final byte ipv6, final byte deleteAll, + final byte length, final byte[] addr) { + final SwInterfaceAddDelAddress swInterfaceAddDelAddress = new SwInterfaceAddDelAddress(); + swInterfaceAddDelAddress.swIfIndex = swIfc; + swInterfaceAddDelAddress.isAdd = isAdd; + swInterfaceAddDelAddress.isIpv6 = ipv6; + swInterfaceAddDelAddress.delAll = deleteAll; + swInterfaceAddDelAddress.address = addr; + swInterfaceAddDelAddress.addressLength = length; + return swInterfaceAddDelAddress; + } + + /** + * Returns the prefix size in bits of the specified subnet mask. Example: For the subnet mask 255.255.255.128 it + * returns 25 while for 255.0.0.0 it returns 8. If the passed subnetMask array is not complete or contains not only + * leading ones, IllegalArgumentExpression is thrown + * + * @param mask the subnet mask in dot notation 255.255.255.255 + * @return the prefix length as number of bits + */ + default byte getSubnetMaskLength(final String mask) { + String[] maskParts = mask.split("\\."); + + checkArgument(maskParts.length == DOTTED_QUAD_MASK_LENGTH, + "Network mask %s is not in Quad Dotted Decimal notation!", mask); + + long maskAsNumber = 0; + for (int i = 0; i < DOTTED_QUAD_MASK_LENGTH; i++) { + maskAsNumber <<= IPV4_ADDRESS_PART_BITS_COUNT; + int value = Integer.parseInt(maskParts[i]); + checkArgument(value < NETMASK_PART_LIMIT, "Network mask %s contains invalid number(s) over 255!", mask); + checkArgument(value >= 0, "Network mask %s contains invalid negative number(s)!", mask); + maskAsNumber += value; + } + + String bits = Long.toBinaryString(maskAsNumber); + checkArgument(bits.length() == IPV4_ADDRESS_PART_BITS_COUNT * DOTTED_QUAD_MASK_LENGTH, + "Incorrect network mask %s", mask); + final int leadingOnes = bits.indexOf('0'); + checkArgument(leadingOnes != -1, "Broadcast address %s is not allowed!", mask); + checkArgument(bits.substring(leadingOnes).indexOf('1') == -1, + "Non-contiguous network mask %s is not allowed!", mask); + return (byte) leadingOnes; + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java index 192906854..c04d14604 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java @@ -16,9 +16,9 @@ package io.fd.honeycomb.translate.v3po.interfaces.ip; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java index e0fa46335..3fbb493af 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java @@ -21,9 +21,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; @@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory; * Write customizer for sub-interface {@link Address} */ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer { + implements ListWriterCustomizer, Ipv4Writer { private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); private final NamingContext interfaceContext; @@ -58,7 +58,7 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer @Override public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { setAddress(true, id, dataAfter, writeContext); } @@ -66,12 +66,12 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, WriteContext writeContext) throws WriteFailedException { throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Operation not supported")); + new UnsupportedOperationException("Operation not supported")); } @Override public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { setAddress(false, id, dataBefore, writeContext); } @@ -98,26 +98,26 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); return SubInterfaceUtils - .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); + .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); } private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, @Nonnull final String subInterfaceName, final int subInterfaceIndex, @Nonnull final Address address, @Nonnull final Netmask subnet) - throws WriteFailedException { + throws WriteFailedException { try { LOG.debug("Setting Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); - final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } } @@ -125,19 +125,19 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, @Nonnull final String subInterfaceName, final int subInterfaceIndex, @Nonnull final Address address, @Nonnull final PrefixLength subnet) - throws WriteFailedException { + throws WriteFailedException { try { LOG.debug("Setting Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), - subnet.getPrefixLength().byteValue()); + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), + subnet.getPrefixLength().byteValue()); LOG.debug("Subnet(prefix-length) set successfully for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java index 361113858..a314eaf14 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java @@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Function; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4WriteUtils; +import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4Writer; import java.util.List; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; @@ -32,7 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061 /** * Validator for detecting if there is an attempt to assign multiple addresses from same subnet */ -public class SubnetValidator { +public class SubnetValidator implements Ipv4Writer { /** * Checks whether data provided for writing are not in collision with already existing data @@ -60,7 +60,7 @@ public class SubnetValidator { .forConflictingData(conflictingPrefix, prefixLengthRegister.get(conflictingPrefix)); } - private static Function toPrefixLength() { + private Function toPrefixLength() { return (final Address address) -> { final Subnet subnet = address.getSubnet(); @@ -69,7 +69,7 @@ public class SubnetValidator { } if (address.getSubnet() instanceof Netmask) { - return (short) Ipv4WriteUtils.getSubnetMaskLength( + return (short) getSubnetMaskLength( checkNotNull(((Netmask) subnet).getNetmask(), "No netmask defined for %s", subnet) .getValue()); } -- cgit 1.2.3-korg