From ba6e99e27e2a54bd448c491e22a4e3fc26f45df6 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 3 Jul 2018 14:09:36 +0200 Subject: HC2VPP-79: use AddressTranslator for ip-address-no-zone translation Change-Id: I46955630709e3d837f95f488cb2fe089952865c4 Signed-off-by: Marek Gradzki --- .../hc2vpp/l3/write/ipv4/ProxyRangeCustomizer.java | 16 ++++----- .../fd/hc2vpp/v3po/interfaces/GreCustomizer.java | 31 ++++++----------- .../fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java | 40 ++++++++-------------- .../hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java | 29 +++++----------- .../hc2vpp/v3po/interfaces/GreCustomizerTest.java | 10 +++--- .../v3po/interfaces/VxlanCustomizerTest.java | 11 +++--- .../v3po/interfaces/VxlanGpeCustomizerTest.java | 10 +++--- .../v3po/interfacesstate/GreCustomizerTest.java | 8 ++--- .../v3po/interfacesstate/VxlanCustomizerTest.java | 6 ++-- .../interfacesstate/VxlanGpeCustomizerTest.java | 9 ++--- 10 files changed, 66 insertions(+), 104 deletions(-) diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/ProxyRangeCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/ProxyRangeCustomizer.java index 8c55df046..111e32296 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/ProxyRangeCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/ProxyRangeCustomizer.java @@ -16,8 +16,8 @@ package io.fd.hc2vpp.l3.write.ipv4; -import com.google.common.net.InetAddresses; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; @@ -26,9 +26,9 @@ import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel; import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import io.fd.vpp.jvpp.core.types.ProxyArp; -import java.net.InetAddress; import java.util.concurrent.Future; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev180703.proxy.ranges.ProxyRange; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev180703.proxy.ranges.ProxyRangeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -62,11 +62,9 @@ public class ProxyRangeCustomizer extends FutureJVppCustomizer private Future getProxyArpRequestFuture(ProxyRange proxyArp, byte operation) throws WriteFailedException { - final InetAddress srcAddress = InetAddresses.forString(proxyArp.getLowAddr().getValue()); - final InetAddress dstAddress = InetAddresses.forString(proxyArp.getHighAddr().getValue()); final int vrfId = proxyArp.getVrfId().getValue().intValue(); return getFutureJVpp().proxyArpAddDel( - getProxyArpConfRequest(operation, srcAddress.getAddress(), dstAddress.getAddress(), vrfId)) + getProxyArpConfRequest(operation, proxyArp.getLowAddr(), proxyArp.getHighAddr(), vrfId)) .toCompletableFuture(); } @@ -85,13 +83,13 @@ public class ProxyRangeCustomizer extends FutureJVppCustomizer LOG.debug("Proxy ARP setting delete successful, with reply context:", reply.context); } - private static ProxyArpAddDel getProxyArpConfRequest(final byte isAdd, final byte[] lAddr, final byte[] hAddr, - final int vrfId) { + private static ProxyArpAddDel getProxyArpConfRequest(final byte isAdd, final Ipv4AddressNoZone lAddr, + final Ipv4AddressNoZone hAddr, final int vrfId) { final ProxyArpAddDel proxyArpAddDel = new ProxyArpAddDel(); proxyArpAddDel.isAdd = isAdd; proxyArpAddDel.proxy = new ProxyArp(); - proxyArpAddDel.proxy.lowAddress = lAddr; - proxyArpAddDel.proxy.hiAddress = hAddr; + proxyArpAddDel.proxy.lowAddress = Ipv4Translator.INSTANCE.ipv4AddressNoZoneToArray(lAddr); + proxyArpAddDel.proxy.hiAddress = Ipv4Translator.INSTANCE.ipv4AddressNoZoneToArray(hAddr); proxyArpAddDel.proxy.vrfId = vrfId; return proxyArpAddDel; } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java index 2f6d4a51c..4e99c9397 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java @@ -18,8 +18,8 @@ package io.fd.hc2vpp.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.net.InetAddresses; import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.write.WriteContext; @@ -27,7 +27,6 @@ import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.GreAddDelTunnel; import io.fd.vpp.jvpp.core.dto.GreAddDelTunnelReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.net.InetAddress; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; @@ -49,12 +48,13 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer implemen this.interfaceContext = interfaceContext; } - private static GreAddDelTunnel getGreTunnelRequest(final byte isAdd, final byte[] srcAddr, final byte[] dstAddr, - final int outerFibId, final byte isIpv6) { + private static GreAddDelTunnel getGreTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, + final IpAddressNoZone dstAddr, final int outerFibId, + final byte isIpv6) { final GreAddDelTunnel greAddDelTunnel = new GreAddDelTunnel(); greAddDelTunnel.isAdd = isAdd; - greAddDelTunnel.srcAddress = srcAddr; - greAddDelTunnel.dstAddress = dstAddr; + greAddDelTunnel.srcAddress = AddressTranslator.INSTANCE.ipAddressToArray(srcAddr); + greAddDelTunnel.dstAddress = AddressTranslator.INSTANCE.ipAddressToArray(dstAddr); greAddDelTunnel.outerFibId = outerFibId; greAddDelTunnel.isIpv6 = isIpv6; return greAddDelTunnel; @@ -87,15 +87,12 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer implemen final byte isIpv6 = (byte) (isIpv6(gre) ? 1 : 0); - final InetAddress srcAddress = InetAddresses.forString(getAddressString(gre.getSrc())); - final InetAddress dstAddress = InetAddresses.forString(getAddressString(gre.getDst())); - int outerFibId = gre.getOuterFibId().intValue(); LOG.debug("Setting gre tunnel for interface: {}. Gre: {}", swIfName, gre); final CompletionStage greAddDelTunnelReplyCompletionStage = - getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 1 /* is add */, srcAddress.getAddress(), - dstAddress.getAddress(), outerFibId, isIpv6)); + getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 1 /* is add */, gre.getSrc(), + gre.getDst(), outerFibId, isIpv6)); final GreAddDelTunnelReply reply = getReplyForCreate(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, gre); @@ -129,26 +126,18 @@ public class GreCustomizer extends AbstractInterfaceTypeCustomizer implemen } } - private String getAddressString(final IpAddressNoZone addr) { - return addr.getIpv4AddressNoZone() == null - ? addr.getIpv6AddressNoZone().getValue() - : addr.getIpv4AddressNoZone().getValue(); - } - private void deleteGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, final WriteContext writeContext) throws WriteFailedException { final byte isIpv6 = (byte) (isIpv6(gre) ? 1 : 0); - final InetAddress srcAddress = InetAddresses.forString(getAddressString(gre.getSrc())); - final InetAddress dstAddress = InetAddresses.forString(getAddressString(gre.getDst())); int outerFibId = gre.getOuterFibId().intValue(); LOG.debug("Deleting gre tunnel for interface: {}. Gre: {}", swIfName, gre); final CompletionStage greAddDelTunnelReplyCompletionStage = - getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 0 /* is add */, srcAddress.getAddress(), - dstAddress.getAddress(), outerFibId, isIpv6)); + getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 0 /* is add */, gre.getSrc(), + gre.getDst(), outerFibId, isIpv6)); getReplyForDelete(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Gre tunnel deleted successfully for: {}, gre: {}", swIfName, gre); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java index b0387d1b6..5d5b086ec 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java @@ -18,8 +18,8 @@ package io.fd.hc2vpp.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.net.InetAddresses; import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.DisabledInterfacesManager; @@ -28,7 +28,6 @@ import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.VxlanAddDelTunnel; import io.fd.vpp.jvpp.core.dto.VxlanAddDelTunnelReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.net.InetAddress; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; @@ -82,10 +81,8 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer impl final WriteContext writeContext) throws WriteFailedException { final byte isIpv6 = (byte) (isIpv6(vxlan) - ? 1 - : 0); - final InetAddress srcAddress = InetAddresses.forString(getAddressString(vxlan.getSrc())); - final InetAddress dstAddress = InetAddresses.forString(getAddressString(vxlan.getDst())); + ? 1 + : 0); checkArgument(vxlan.getEncapVrfId() != null && vxlan.getEncapVrfId().getValue() != null, "encap-vrf-id is mandatory but was not given"); @@ -101,8 +98,8 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer impl LOG.debug("Setting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 1 /* is add */, srcAddress.getAddress(), - dstAddress.getAddress(), encapVrfId, decapNext, vni, isIpv6)); + getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 1 /* is add */, vxlan.getSrc(), + vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); final VxlanAddDelTunnelReply reply = getReplyForCreate(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlan); @@ -145,19 +142,11 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer impl } } - private String getAddressString(final IpAddressNoZone addr) { - return addr.getIpv4AddressNoZone() == null - ? addr.getIpv6AddressNoZone().getValue() - : addr.getIpv4AddressNoZone().getValue(); - } - private void deleteVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, final WriteContext writeContext) throws WriteFailedException { final byte isIpv6 = (byte) (isIpv6(vxlan) - ? 1 - : 0); - final InetAddress srcAddress = InetAddresses.forString(getAddressString(vxlan.getSrc())); - final InetAddress dstAddress = InetAddresses.forString(getAddressString(vxlan.getDst())); + ? 1 + : 0); checkArgument(vxlan.getEncapVrfId() != null && vxlan.getEncapVrfId().getValue() != null, "encap-vrf-id is mandatory but was not given"); @@ -173,8 +162,8 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer impl LOG.debug("Deleting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 0 /* is add */, srcAddress.getAddress(), - dstAddress.getAddress(), encapVrfId, decapNext, vni, isIpv6)); + getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 0 /* is add */, vxlan.getSrc(), + vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); getReplyForDelete(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vxlan tunnel deleted successfully for: {}, vxlan: {}", swIfName, vxlan); @@ -188,13 +177,14 @@ public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer impl interfaceNamingContext.removeName(swIfName, writeContext.getMappingContext()); } - 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) { + private static VxlanAddDelTunnel getVxlanTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, + final IpAddressNoZone dstAddr, + final int encapVrfId, + final int decapNextIndex, final int vni, final byte isIpv6) { final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel(); vxlanAddDelTunnel.isAdd = isAdd; - vxlanAddDelTunnel.srcAddress = srcAddr; - vxlanAddDelTunnel.dstAddress = dstAddr; + vxlanAddDelTunnel.srcAddress = AddressTranslator.INSTANCE.ipAddressToArray(srcAddr); + vxlanAddDelTunnel.dstAddress = AddressTranslator.INSTANCE.ipAddressToArray(dstAddr); vxlanAddDelTunnel.encapVrfId = encapVrfId; vxlanAddDelTunnel.vni = vni; vxlanAddDelTunnel.decapNextIndex = decapNextIndex; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java index ac21c4dbd..c875b87dc 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java @@ -18,8 +18,8 @@ package io.fd.hc2vpp.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.net.InetAddresses; import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.DisabledInterfacesManager; @@ -28,7 +28,6 @@ import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.VxlanGpeAddDelTunnel; import io.fd.vpp.jvpp.core.dto.VxlanGpeAddDelTunnelReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.net.InetAddress; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; @@ -83,8 +82,6 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer VxlanGpeAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 1 /* is add */, Local.getAddress(), - Remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + getFutureJVpp().vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 1 /* is add */, vxlanGpe.getLocal(), + vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); final VxlanGpeAddDelTunnelReply reply = getReplyForCreate(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlanGpe); @@ -131,20 +128,12 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer id, final String swIfName, final VxlanGpe vxlanGpe, final WriteContext writeContext) throws WriteFailedException { final byte isIpv6 = (byte) (isIpv6(vxlanGpe) ? 1 : 0); - final InetAddress local = InetAddresses.forString(getAddressString(vxlanGpe.getLocal())); - final InetAddress remote = InetAddresses.forString(getAddressString(vxlanGpe.getRemote())); int vni = vxlanGpe.getVni().getValue().intValue(); byte protocol = (byte) vxlanGpe.getNextProtocol().getIntValue(); @@ -154,8 +143,8 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer VxlanGpeAddDelTunnelReplyCompletionStage = getFutureJVpp() - .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, local.getAddress(), - remote.getAddress(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, vxlanGpe.getLocal(), + vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); getReplyForDelete(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); // Mark this interface as disabled to not include it in operational reads @@ -166,15 +155,15 @@ public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer { +public class GreCustomizerTest extends ReaderCustomizerTest implements AddressTranslator { private static final String IFACE_NAME = "ifc1"; private static final int IFACE_ID = 0; @@ -79,8 +79,8 @@ public class GreCustomizerTest extends ReaderCustomizerTest { final GreTunnelDetailsReplyDump value = new GreTunnelDetailsReplyDump(); final GreTunnelDetails greTunnelDetails = new GreTunnelDetails(); greTunnelDetails.isIpv6 = 0; - greTunnelDetails.dstAddress = InetAddresses.forString("1.2.3.4").getAddress(); - greTunnelDetails.srcAddress = InetAddresses.forString("1.2.3.5").getAddress(); + greTunnelDetails.dstAddress = ipv4AddressNoZoneToArray("1.2.3.4"); + greTunnelDetails.srcAddress = ipv4AddressNoZoneToArray("1.2.3.5"); greTunnelDetails.outerFibId = 55; greTunnelDetails.swIfIndex = 0; value.greTunnelDetails = Lists.newArrayList(greTunnelDetails); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java index 6ce09132b..a98a2cf67 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java @@ -26,8 +26,8 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import com.google.common.collect.Lists; -import com.google.common.net.InetAddresses; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -143,8 +143,8 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest { +public class VxlanGpeCustomizerTest extends ReaderCustomizerTest + implements AddressTranslator { private static final String IFC_CTX_NAME = "ifc-test-instance"; private static final String IF_NAME = "ifc2"; @@ -80,8 +81,8 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest