summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'nat/nat2vpp/src/main')
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java20
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java8
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java4
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java8
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java25
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java2
6 files changed, 33 insertions, 34 deletions
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java
index 7592db69b..7a97a68d1 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java
@@ -65,11 +65,13 @@ final class ExternalIpPoolCustomizer implements
ExternalIpPoolCustomizer(@Nonnull final FutureJVppNatFacade jvppNat) {
checkNotNull(jvppNat, "jvppNat should not be null");
this.nat44DumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<Nat44AddressDetailsReplyDump, Void>()
- .withExecutor((id, params) -> getReplyForRead(jvppNat.nat44AddressDump(new Nat44AddressDump()).toCompletableFuture(), id))
+ .withExecutor((id, params) -> getReplyForRead(
+ jvppNat.nat44AddressDump(new Nat44AddressDump()).toCompletableFuture(), id))
.acceptOnly(Nat44AddressDetailsReplyDump.class)
.build();
this.nat64DumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<Nat64PoolAddrDetailsReplyDump, Void>()
- .withExecutor((id, params) -> getReplyForRead(jvppNat.nat64PoolAddrDump(new Nat64PoolAddrDump()).toCompletableFuture(), id))
+ .withExecutor((id, params) -> getReplyForRead(
+ jvppNat.nat64PoolAddrDump(new Nat64PoolAddrDump()).toCompletableFuture(), id))
.acceptOnly(Nat64PoolAddrDetailsReplyDump.class)
.build();
}
@@ -94,7 +96,7 @@ final class ExternalIpPoolCustomizer implements
final Long poolId = id.firstKeyOf(ExternalIpAddressPool.class).getPoolId();
final List<Nat44AddressDetails> nat44Details =
nat44DumpMgr.getDump(id, ctx.getModificationCache())
- .or(new Nat44AddressDetailsReplyDump()).nat44AddressDetails;
+ .orElse(new Nat44AddressDetailsReplyDump()).nat44AddressDetails;
final int nat44PoolCount = nat44Details.size();
// Uses ID<->address mapping as defined by getAllIds (nat44 mappings go before nat64):
@@ -104,7 +106,7 @@ final class ExternalIpPoolCustomizer implements
setPoolType(builder, NatPoolType.Nat44);
} else {
final List<Nat64PoolAddrDetails> nat64Details = nat64DumpMgr.getDump(id, ctx.getModificationCache())
- .or(new Nat64PoolAddrDetailsReplyDump()).nat64PoolAddrDetails;
+ .orElse(new Nat64PoolAddrDetailsReplyDump()).nat64PoolAddrDetails;
final int nat64PoolCount = nat64Details.size();
final int nat64PoolPosition = Math.toIntExact(poolId) - nat44PoolCount;
if (nat64PoolPosition < nat64PoolCount) {
@@ -146,16 +148,14 @@ final class ExternalIpPoolCustomizer implements
// That's why the write and read is not symmetrical in terms of data structure, instead,
// this customizer also returns every single address as a 32 prefix and assigns an artificial key to them
- long addressCount = nat44DumpMgr.getDump(id, ctx.getModificationCache())
- .or(new Nat44AddressDetailsReplyDump()).nat44AddressDetails.stream()
- .count();
+ long addressCount = (long) nat44DumpMgr.getDump(id, ctx.getModificationCache())
+ .orElse(new Nat44AddressDetailsReplyDump()).nat44AddressDetails.size();
// The ietf-nat model groups address pools for Nat44 and Nat64 under the same list,
// but VPP uses different APIs, so we need an other dump:
- addressCount += nat64DumpMgr.getDump(id, ctx.getModificationCache())
- .or(new Nat64PoolAddrDetailsReplyDump()).nat64PoolAddrDetails.stream()
- .count();
+ addressCount += (long) nat64DumpMgr.getDump(id, ctx.getModificationCache())
+ .orElse(new Nat64PoolAddrDetailsReplyDump()).nat64PoolAddrDetails.size();
final List<ExternalIpAddressPoolKey> ids = LongStream.range(0, addressCount)
.mapToObj(ExternalIpAddressPoolKey::new)
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 2be7392d7..1ae452183 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
@@ -86,7 +86,7 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
final int natInstanceId = id.firstKeyOf(Instance.class).getId().intValue();
final List<Nat44StaticMappingDetails> nat44Details =
nat44DumpManager.getDump(id, ctx.getModificationCache())
- .or(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails;
+ .orElse(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails;
final Optional<Nat44StaticMappingDetails> nat44StaticMappingDetails =
mappingEntryContext.findDetailsNat44(nat44Details, natInstanceId, idx, ctx.getMappingContext());
@@ -95,7 +95,7 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
} else {
final List<Nat64BibDetails> nat64Details =
nat64DumpManager.getDump(id, ctx.getModificationCache())
- .or(new Nat64BibDetailsReplyDump()).nat64BibDetails;
+ .orElse(new Nat64BibDetailsReplyDump()).nat64BibDetails;
final Optional<Nat64BibDetails> nat64StaticMappingDetails =
mappingEntryContext.findDetailsNat64(nat64Details, natInstanceId, idx, ctx.getMappingContext());
@@ -153,7 +153,7 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
final List<MappingEntryKey> entryKeys =
nat44DumpManager.getDump(id, context.getModificationCache())
- .or(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails.stream()
+ .orElse(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails.stream()
.filter(detail -> natInstanceId == detail.vrfId)
.map(detail -> mappingEntryContext
.getStoredOrArtificialIndex(natInstanceId, detail, context.getMappingContext()))
@@ -163,7 +163,7 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator,
final List<MappingEntryKey> nat64Keys =
nat64DumpManager.getDump(id, context.getModificationCache())
- .or(new Nat64BibDetailsReplyDump()).nat64BibDetails.stream()
+ .orElse(new Nat64BibDetailsReplyDump()).nat64BibDetails.stream()
.filter(detail -> natInstanceId == detail.vrfId)
.map(detail -> mappingEntryContext
.getStoredOrArtificialIndex(natInstanceId, detail, context.getMappingContext()))
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java
index 81a978559..6d1cf812c 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java
@@ -79,10 +79,10 @@ final class NatInstanceCustomizer
// Find the nat instance IDs (vrf-ids) by listing all static mappings and their VRF assignment
final List<InstanceKey> vrfIds = Stream.concat(
nat44DumpManager.getDump(id, context.getModificationCache())
- .or(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails.stream()
+ .orElse(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails.stream()
.map(detail -> detail.vrfId),
nat64DumpManager.getDump(id, context.getModificationCache())
- .or(new Nat64BibDetailsReplyDump()).nat64BibDetails.stream()
+ .orElse(new Nat64BibDetailsReplyDump()).nat64BibDetails.stream()
.map(detail -> detail.vrfId))
// V4 (nat44) and V6 (nat64) VRFs in VPP can have the same id. We store them under single nat instance,
// because the ietf-nat model does not require separate instances for nat44 and nat64 features.
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java
index 91e2a8bb7..2d8e4cce5 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java
@@ -18,7 +18,6 @@ package io.fd.hc2vpp.nat.read.ifc;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Optional;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.read.ReadContext;
@@ -32,6 +31,7 @@ import io.fd.jvpp.nat.dto.Nat44InterfaceOutputFeatureDump;
import io.fd.jvpp.nat.dto.Nat64InterfaceDetailsReplyDump;
import io.fd.jvpp.nat.dto.Nat64InterfaceDump;
import io.fd.jvpp.nat.future.FutureJVppNatFacade;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yangtools.concepts.Builder;
@@ -95,7 +95,7 @@ abstract class AbstractInterfaceNatCustomizer<C extends DataObject, B extends Bu
final Optional<Nat44InterfaceDetailsReplyDump> dump =
preRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache());
- dump.or(new Nat44InterfaceDetailsReplyDump()).nat44InterfaceDetails.stream()
+ dump.orElse(new Nat44InterfaceDetailsReplyDump()).nat44InterfaceDetails.stream()
.filter(natIfcDetail -> natIfcDetail.swIfIndex == index)
.filter(natIfcDetail -> isExpectedNatType(natIfcDetail.isInside))
.findAny()
@@ -108,7 +108,7 @@ abstract class AbstractInterfaceNatCustomizer<C extends DataObject, B extends Bu
final Optional<Nat64InterfaceDetailsReplyDump> dump =
preRoutingNat64DumpMgr.getDump(id, ctx.getModificationCache());
- dump.or(new Nat64InterfaceDetailsReplyDump()).nat64InterfaceDetails.stream()
+ dump.orElse(new Nat64InterfaceDetailsReplyDump()).nat64InterfaceDetails.stream()
.filter(natIfcDetail -> natIfcDetail.swIfIndex == index)
.filter(natIfcDetail -> isExpectedNatType(natIfcDetail.isInside))
.findAny()
@@ -121,7 +121,7 @@ abstract class AbstractInterfaceNatCustomizer<C extends DataObject, B extends Bu
final Optional<Nat44InterfaceOutputFeatureDetailsReplyDump> dump =
postRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache());
- dump.or(new Nat44InterfaceOutputFeatureDetailsReplyDump()).nat44InterfaceOutputFeatureDetails
+ dump.orElse(new Nat44InterfaceOutputFeatureDetailsReplyDump()).nat44InterfaceOutputFeatureDetails
.stream()
.filter(natIfcDetail -> natIfcDetail.swIfIndex == index)
.filter(natIfcDetail -> isExpectedNatType(natIfcDetail.isInside))
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 14bf3f0a3..aed383b10 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
@@ -19,7 +19,7 @@ package io.fd.hc2vpp.nat.util;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
+import java.util.Optional;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
import io.fd.honeycomb.translate.MappingContext;
@@ -179,8 +179,8 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
@Nonnull final MappingContext mappingContext) {
// Find mapping entry for Index
final MappingEntry ctxMappingEntry = mappingContext.read(getTableId(natInstanceId))
- .transform(MappingTable::getMappingEntry)
- .or(Collections.emptyList())
+ .map(MappingTable::getMappingEntry)
+ .orElse(Collections.emptyList())
.stream()
.filter(entry -> entry.getIndex() == idx)
.findFirst()
@@ -201,8 +201,8 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
@Nonnull final MappingContext mappingContext) {
// Find mapping entry for Index
final MappingEntry ctxMappingEntry = mappingContext.read(getTableId(natInstanceId))
- .transform(MappingTable::getMappingEntry)
- .or(Collections.emptyList())
+ .map(MappingTable::getMappingEntry)
+ .orElse(Collections.emptyList())
.stream()
.filter(entry -> entry.getIndex() == idx)
.findFirst()
@@ -222,8 +222,8 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
@Nonnull final Nat44StaticMappingDetails details,
@Nonnull final MappingContext mappingContext) {
return mappingContext.read(getId(natInstanceId, entryToKey(details)))
- .transform(MappingEntry::getIndex)
- .or(() -> getArtificialId(details, natInstanceId, mappingContext));
+ .map(MappingEntry::getIndex)
+ .orElseGet(() -> getArtificialId(details, natInstanceId, mappingContext));
}
/**
@@ -233,8 +233,8 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
@Nonnull final Nat64BibDetails details,
@Nonnull final MappingContext mappingContext) {
return mappingContext.read(getId(natInstanceId, entryToKey(details)))
- .transform(MappingEntry::getIndex)
- .or(() -> getArtificialId(details, natInstanceId, mappingContext));
+ .map(MappingEntry::getIndex)
+ .orElseGet(() -> getArtificialId(details, natInstanceId, mappingContext));
}
/**
@@ -243,8 +243,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
public synchronized Optional<Long> getStoredIndex(final long natInstanceId,
@Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180628.nat.instances.instance.mapping.table.MappingEntry entry,
@Nonnull final MappingContext mappingContext) {
- return mappingContext.read(getId(natInstanceId, entryToKey(entry)))
- .transform(MappingEntry::getIndex);
+ return mappingContext.read(getId(natInstanceId, entryToKey(entry))).map(MappingEntry::getIndex);
}
private long getArtificialId(final Nat44StaticMappingDetails details, final Long natInstanceId,
@@ -267,8 +266,8 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator {
private long findFreeIndex(final long natInstanceId, final MappingContext mappingContext) {
return mappingContext.read(getTableId(natInstanceId))
- .transform(MappingTable::getMappingEntry)
- .or(Collections.emptyList())
+ .map(MappingTable::getMappingEntry)
+ .orElse(Collections.emptyList())
.stream()
.map(MappingEntry::getIndex)
.max(Comparator.naturalOrder())
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 924f6a6a1..9c8da8c84 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
@@ -16,7 +16,7 @@
package io.fd.hc2vpp.nat.write;
-import com.google.common.base.Optional;
+import java.util.Optional;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.Ipv6Translator;