From 7d961bf199719410b2e4111c830fbf35b41c83c2 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Wed, 30 May 2018 13:45:41 +0200 Subject: HC2VPP-325: use ip-prefix instead of ip-address in ietf-nat@2018-02-23.yang Only /32 prefix for IPv4 and /128 for IPv6 are supported. Change-Id: I875b1eb6c2cb43da54de0a731aeeb9757b39c39c Signed-off-by: Marek Gradzki --- .../fd/hc2vpp/nat/read/MappingEntryCustomizer.java | 12 +++--- .../io/fd/hc2vpp/nat/util/MappingEntryContext.java | 25 ++++++------ .../hc2vpp/nat/write/MappingEntryCustomizer.java | 47 +++++++++++++--------- 3 files changed, 46 insertions(+), 38 deletions(-) (limited to 'nat/nat2vpp/src/main/java') diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java index 43dba092a..15f73e66f 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; 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.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.ExternalSrcPortBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.InternalSrcPortBuilder; @@ -114,9 +114,8 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, builder.setIndex((long) index); builder.setType( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.Static); - builder.setExternalSrcAddress(arrayToIpv4AddressNoZone(detail.externalIpAddress)); - builder.setInternalSrcAddress( - new IpAddress(arrayToIpv4AddressNoZone(detail.localIpAddress))); + builder.setExternalSrcAddress(new IpPrefix(toIpv4Prefix(detail.externalIpAddress, 32))); + builder.setInternalSrcAddress(new IpPrefix(toIpv4Prefix(detail.localIpAddress, 32))); if (detail.addrOnly == 0) { builder.setExternalSrcPort(new ExternalSrcPortBuilder() @@ -136,9 +135,8 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, builder.setType( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.DynamicImplicit); } - builder.setExternalSrcAddress(arrayToIpv4AddressNoZone(detail.oAddr)); - builder.setInternalSrcAddress( - new IpAddress(arrayToIpv6AddressNoZone(detail.iAddr))); + builder.setExternalSrcAddress(new IpPrefix(toIpv4Prefix(detail.oAddr,32 ))); + builder.setInternalSrcAddress(new IpPrefix(toIpv6Prefix(detail.iAddr, 128))); builder.setExternalSrcPort(new ExternalSrcPortBuilder() .setStartPortNumber(new PortNumber(Short.toUnsignedInt(detail.oPort))).build()); diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java index 0f7220988..d136764d0 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java @@ -40,8 +40,11 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntryBuilder; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntryKey; 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.IpPrefix; 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.Ipv4Prefix; 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.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,32 +97,30 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { static MappingEntryKey entryToKey( final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry) { // Only IPv4 - return new MappingEntryKey(new IpAddress(entry.getExternalSrcAddress()), entry.getInternalSrcAddress()); + return new MappingEntryKey(entry.getExternalSrcAddress(), entry.getInternalSrcAddress()); } private MappingEntryKey entryToKey(final Nat44StaticMappingDetails entry) { // Only IPv4 return new MappingEntryKey( - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(entry.externalIpAddress))), - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(entry.localIpAddress)))); + new IpPrefix(new Ipv4Prefix(toIpv4Prefix(entry.externalIpAddress,32))), + new IpPrefix(new Ipv4Prefix(toIpv4Prefix(entry.localIpAddress, 32)))); } private MappingEntryKey entryToKey(final Nat64BibDetails entry) { return new MappingEntryKey( - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(entry.oAddr))), - new IpAddress(new Ipv6Address(arrayToIpv6AddressNoZone(entry.iAddr)))); + new IpPrefix(new Ipv4Prefix(toIpv4Prefix(entry.oAddr, 32))), + new IpPrefix(new Ipv6Prefix(toIpv6Prefix(entry.iAddr, 128)))); } private boolean equalEntries(final Nat44StaticMappingDetails detail, final MappingEntry ctxMappingEntry) { - final IpAddress internalAddrFromDetails = - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(detail.localIpAddress))); // Only IPv4 + final IpPrefix internalAddrFromDetails = new IpPrefix(toIpv4Prefix(detail.localIpAddress, 32)); if (!ctxMappingEntry.getInternal().equals(internalAddrFromDetails)) { return false; } // Only IPv4 - final IpAddress externalAddrFromDetails = - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(detail.externalIpAddress))); + final IpPrefix externalAddrFromDetails = new IpPrefix(toIpv4Prefix(detail.externalIpAddress, 32)); if (!ctxMappingEntry.getExternal().equals(externalAddrFromDetails)) { return false; } @@ -127,15 +128,13 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { } private boolean equalEntries(final Nat64BibDetails detail, final MappingEntry ctxMappingEntry) { - final IpAddress internalAddrFromDetails = - new IpAddress(new Ipv6Address(arrayToIpv6AddressNoZone(detail.iAddr))); // Only IPv6 + final IpPrefix internalAddrFromDetails = new IpPrefix(toIpv6Prefix(detail.iAddr, 128)); if (!ctxMappingEntry.getInternal().equals(internalAddrFromDetails)) { return false; } // Only IPv4 - final IpAddress externalAddrFromDetails = - new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZone(detail.oAddr))); + final IpPrefix externalAddrFromDetails = new IpPrefix(toIpv4Prefix(detail.oAddr, 32)); if (!ctxMappingEntry.getExternal().equals(externalAddrFromDetails)) { return false; } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java index 6aca1af9e..74160683b 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java @@ -32,9 +32,9 @@ import io.fd.vpp.jvpp.nat.dto.Nat44AddDelStaticMapping; import io.fd.vpp.jvpp.nat.dto.Nat64AddDelStaticBib; import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; 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.inet.types.rev130715.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry; @@ -85,15 +85,15 @@ final class MappingEntryCustomizer implements ListWriterCustomizer id, final PortNumber portNumber) { if (portNumber != null) { if (portNumber.getStartPortNumber() != null && portNumber.getEndPortNumber() == null) { -- cgit 1.2.3-korg