summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-11-20 17:40:57 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-11-20 17:41:02 +0100
commit26a0ea950f75927f84ff86aae58a6d572d4ec30b (patch)
tree7707061c6c540a43a3bac6b24f49438fb8aa3f4a /v3po/v3po2vpp/src/main
parent868f11f4f4da49198b8102509fb0234578be25e8 (diff)
Use IP Translators for creating ietf-inet-types DTOs
Cleans classes that uses custom IP translation code. Change-Id: Ia22a651d0bf0fcce143e8bf9aabcc326cfd50c2e Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java35
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java35
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java35
3 files changed, 24 insertions, 81 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java
index ee54a110f..abf319909 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java
@@ -19,6 +19,8 @@ package io.fd.hc2vpp.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager;
import io.fd.honeycomb.translate.read.ReadContext;
@@ -30,14 +32,9 @@ import io.fd.vpp.jvpp.core.dto.GreTunnelDetails;
import io.fd.vpp.jvpp.core.dto.GreTunnelDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.GreTunnelDump;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Arrays;
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.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.GreTunnel;
@@ -52,7 +49,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GreCustomizer extends FutureJVppCustomizer
- implements InitializingReaderCustomizer<Gre, GreBuilder>, InterfaceDataTranslator {
+ implements InitializingReaderCustomizer<Gre, GreBuilder>, InterfaceDataTranslator, Ipv4Translator,
+ Ipv6Translator {
private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class);
private final NamingContext interfaceContext;
@@ -115,33 +113,16 @@ public class GreCustomizer extends FutureJVppCustomizer
final GreTunnelDetails swInterfaceGreDetails = reply.greTunnelDetails.get(0);
if (swInterfaceGreDetails.isIpv6 == 1) {
- final Ipv6Address dstIpv6 =
- new Ipv6Address(parseAddress(swInterfaceGreDetails.dstAddress).getHostAddress());
- builder.setDst(new IpAddress(dstIpv6));
- final Ipv6Address srcIpv6 =
- new Ipv6Address(parseAddress(swInterfaceGreDetails.srcAddress).getHostAddress());
- builder.setSrc(new IpAddress(srcIpv6));
+ builder.setDst(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceGreDetails.dstAddress)));
+ builder.setSrc(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceGreDetails.srcAddress)));
} else {
- final byte[] dstBytes = Arrays.copyOfRange(swInterfaceGreDetails.dstAddress, 0, 4);
- final Ipv4Address dstIpv4 = new Ipv4Address(parseAddress(dstBytes).getHostAddress());
- builder.setDst(new IpAddress(dstIpv4));
- final byte[] srcBytes = Arrays.copyOfRange(swInterfaceGreDetails.srcAddress, 0, 4);
- final Ipv4Address srcIpv4 = new Ipv4Address(parseAddress(srcBytes).getHostAddress());
- builder.setSrc(new IpAddress(srcIpv4));
+ builder.setDst(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceGreDetails.dstAddress)));
+ builder.setSrc(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceGreDetails.srcAddress)));
}
builder.setOuterFibId((long) swInterfaceGreDetails.outerFibId);
LOG.debug("Gre tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
}
- @Nonnull
- private static InetAddress parseAddress(@Nonnull final byte[] addr) {
- try {
- return InetAddress.getByAddress(addr);
- } catch (UnknownHostException e) {
- throw new IllegalArgumentException("Cannot create InetAddress from " + Arrays.toString(addr), e);
- }
- }
-
@Override
public Initialized<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.Gre> init(
@Nonnull final InstanceIdentifier<Gre> id, @Nonnull final Gre readValue, @Nonnull final ReadContext ctx) {
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java
index c11d2398c..dd9f84090 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java
@@ -19,6 +19,8 @@ package io.fd.hc2vpp.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager;
@@ -31,14 +33,9 @@ import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetails;
import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.VxlanTunnelDump;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Arrays;
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.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.L2Input;
@@ -56,7 +53,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VxlanCustomizer extends FutureJVppCustomizer
- implements InitializingReaderCustomizer<Vxlan, VxlanBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
+ implements InitializingReaderCustomizer<Vxlan, VxlanBuilder>, InterfaceDataTranslator, JvppReplyConsumer,
+ Ipv4Translator, Ipv6Translator {
private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class);
private final NamingContext interfaceContext;
@@ -119,19 +117,11 @@ public class VxlanCustomizer extends FutureJVppCustomizer
final VxlanTunnelDetails swInterfaceVxlanDetails = reply.vxlanTunnelDetails.get(0);
if (swInterfaceVxlanDetails.isIpv6 == 1) {
- final Ipv6Address dstIpv6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanDetails.dstAddress).getHostAddress());
- builder.setDst(new IpAddress(dstIpv6));
- final Ipv6Address srcIpv6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanDetails.srcAddress).getHostAddress());
- builder.setSrc(new IpAddress(srcIpv6));
+ builder.setDst(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.dstAddress)));
+ builder.setSrc(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.srcAddress)));
} else {
- final byte[] dstBytes = Arrays.copyOfRange(swInterfaceVxlanDetails.dstAddress, 0, 4);
- final Ipv4Address dstIpv4 = new Ipv4Address(parseAddress(dstBytes).getHostAddress());
- builder.setDst(new IpAddress(dstIpv4));
- final byte[] srcBytes = Arrays.copyOfRange(swInterfaceVxlanDetails.srcAddress, 0, 4);
- final Ipv4Address srcIpv4 = new Ipv4Address(parseAddress(srcBytes).getHostAddress());
- builder.setSrc(new IpAddress(srcIpv4));
+ builder.setDst(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.dstAddress)));
+ builder.setSrc(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.srcAddress)));
}
builder.setEncapVrfId((long) swInterfaceVxlanDetails.encapVrfId);
builder.setVni(new VxlanVni((long) swInterfaceVxlanDetails.vni));
@@ -149,15 +139,6 @@ public class VxlanCustomizer extends FutureJVppCustomizer
LOG.debug("Vxlan tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
}
- @Nonnull
- private static InetAddress parseAddress(@Nonnull final byte[] addr) {
- try {
- return InetAddress.getByAddress(addr);
- } catch (UnknownHostException e) {
- throw new IllegalArgumentException("Cannot create InetAddress from " + Arrays.toString(addr), e);
- }
- }
-
@Override
public Initialized<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.Vxlan> init(
@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan readValue,
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java
index 2e2f60c2e..eda33165d 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java
@@ -19,6 +19,8 @@ package io.fd.hc2vpp.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager;
@@ -31,14 +33,9 @@ import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetails;
import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.VxlanGpeTunnelDump;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Arrays;
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.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
@@ -55,7 +52,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VxlanGpeCustomizer extends FutureJVppCustomizer
- implements InitializingReaderCustomizer<VxlanGpe, VxlanGpeBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
+ implements InitializingReaderCustomizer<VxlanGpe, VxlanGpeBuilder>, InterfaceDataTranslator, JvppReplyConsumer,
+ Ipv4Translator, Ipv6Translator {
private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class);
private final NamingContext interfaceContext;
@@ -120,19 +118,11 @@ public class VxlanGpeCustomizer extends FutureJVppCustomizer
final VxlanGpeTunnelDetails swInterfaceVxlanGpeDetails = reply.vxlanGpeTunnelDetails.get(0);
if (swInterfaceVxlanGpeDetails.isIpv6 == 1) {
- final Ipv6Address remote6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.remote).getHostAddress());
- builder.setRemote(new IpAddress(remote6));
- final Ipv6Address local6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.local).getHostAddress());
- builder.setLocal(new IpAddress(local6));
+ builder.setRemote(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.remote)));
+ builder.setLocal(new IpAddress(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.local)));
} else {
- final byte[] dstBytes = Arrays.copyOfRange(swInterfaceVxlanGpeDetails.remote, 0, 4);
- final Ipv4Address remote4 = new Ipv4Address(parseAddress(dstBytes).getHostAddress());
- builder.setRemote(new IpAddress(remote4));
- final byte[] srcBytes = Arrays.copyOfRange(swInterfaceVxlanGpeDetails.local, 0, 4);
- final Ipv4Address local4 = new Ipv4Address(parseAddress(srcBytes).getHostAddress());
- builder.setLocal(new IpAddress(local4));
+ builder.setRemote(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.remote)));
+ builder.setLocal(new IpAddress(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.local)));
}
builder.setVni(new VxlanGpeVni((long) swInterfaceVxlanGpeDetails.vni));
builder.setNextProtocol(VxlanGpeNextProtocol.forValue(swInterfaceVxlanGpeDetails.protocol));
@@ -141,15 +131,6 @@ public class VxlanGpeCustomizer extends FutureJVppCustomizer
LOG.debug("VxlanGpe tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
}
- @Nonnull
- private static InetAddress parseAddress(@Nonnull final byte[] addr) {
- try {
- return InetAddress.getByAddress(addr);
- } catch (UnknownHostException e) {
- throw new IllegalArgumentException("Cannot create InetAddress from " + Arrays.toString(addr), e);
- }
- }
-
@Override
public Initialized<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.VxlanGpe> init(
@Nonnull final InstanceIdentifier<VxlanGpe> id, @Nonnull final VxlanGpe readValue,