summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizer.java10
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizer.java10
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizer.java25
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterconnectionReadUtils.java17
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizer.java64
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslator.java (renamed from v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtils.java)116
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2Customizer.java5
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizer.java6
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizer.java12
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizer.java71
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2Customizer.java2
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizer.java22
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java42
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java26
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizer.java29
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java67
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java2
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4ReadUtils.java130
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4Reader.java68
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java50
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/AddressDumpExecutor.java47
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java16
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java28
23 files changed, 468 insertions, 397 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizer.java
index 639b36651..04141ab12 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizer.java
@@ -20,11 +20,11 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
-import io.fd.honeycomb.translate.read.ReadFailedException;
+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.vppclassifier.VppClassifierContextManager;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
* Customizer for reading ACLs enabled on given interface.
*/
public class AclCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Acl, AclBuilder>, AclReader {
+ implements ReaderCustomizer<Acl, AclBuilder>, AclReader, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(AclCustomizer.class);
private final NamingContext interfaceContext;
@@ -80,8 +80,8 @@ public class AclCustomizer extends FutureJVppCustomizer
final ClassifyTableByInterface request = new ClassifyTableByInterface();
request.swIfIndex = interfaceContext.getIndex(interfaceKey.getName(), ctx.getMappingContext());
try {
- final ClassifyTableByInterfaceReply reply = TranslateUtils
- .getReplyForRead(getFutureJVpp().classifyTableByInterface(request).toCompletableFuture(), id);
+ final ClassifyTableByInterfaceReply reply =
+ getReplyForRead(getFutureJVpp().classifyTableByInterface(request).toCompletableFuture(), id);
builder.setL2Acl(readL2Acl(reply.l2TableId, classifyTableContext, ctx.getMappingContext()));
builder.setIp4Acl(readIp4Acl(reply.ip4TableId, classifyTableContext, ctx.getMappingContext()));
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizer.java
index abded50a3..fda8befe5 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/EthernetCustomizer.java
@@ -17,9 +17,9 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
-import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
public class EthernetCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Ethernet, EthernetBuilder> {
+ implements ReaderCustomizer<Ethernet, EthernetBuilder>, InterfaceDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(EthernetCustomizer.class);
private NamingContext interfaceContext;
@@ -66,10 +66,10 @@ public class EthernetCustomizer extends FutureJVppCustomizer
@Nonnull final ReadContext ctx) throws ReadFailedException {
final InterfaceKey key = id.firstKeyOf(Interface.class);
- final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, key.getName(),
- interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache());
+ final SwInterfaceDetails iface = getVppInterfaceDetails(getFutureJVpp(), id, key.getName(),
+ interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache(), LOG);
- if(iface.linkMtu != 0) {
+ if (iface.linkMtu != 0) {
builder.setMtu((int) iface.linkMtu);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizer.java
index 8b0a42068..fe672640a 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizer.java
@@ -17,14 +17,12 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -35,8 +33,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
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.rev150105.VppInterfaceStateAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.GreTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Gre;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.GreBuilder;
import org.opendaylight.yangtools.concepts.Builder;
@@ -51,7 +49,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GreCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Gre, GreBuilder> {
+ implements ReaderCustomizer<Gre, GreBuilder>, InterfaceDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class);
private NamingContext interfaceContext;
@@ -80,7 +78,7 @@ public class GreCustomizer extends FutureJVppCustomizer
try {
final InterfaceKey key = id.firstKeyOf(Interface.class);
final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext());
- if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, GreTunnel.class)) {
+ if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, GreTunnel.class, LOG)) {
return;
}
@@ -90,31 +88,32 @@ public class GreCustomizer extends FutureJVppCustomizer
request.swIfIndex = index;
final CompletionStage<GreTunnelDetailsReplyDump> swInterfaceGreDetailsReplyDumpCompletionStage =
- getFutureJVpp().greTunnelDump(request);
+ getFutureJVpp().greTunnelDump(request);
final GreTunnelDetailsReplyDump reply =
- TranslateUtils.getReplyForRead(swInterfaceGreDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
+ getReplyForRead(swInterfaceGreDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
// VPP keeps gre tunnel interfaces even after they were deleted (optimization)
// However there ar no longer any gre tunnel specific fields assigned to it and this call
// returns nothing
if (reply == null || reply.greTunnelDetails == null || reply.greTunnelDetails.isEmpty()) {
LOG.debug(
- "Gre tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
- "after delete", key.getName(), index);
+ "Gre tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
+ "after delete", key.getName(), index);
return;
}
checkState(reply.greTunnelDetails.size() == 1,
- "Unexpected number of returned gre tunnels: {} for tunnel: {}", reply.greTunnelDetails, key.getName());
+ "Unexpected number of returned gre tunnels: {} for tunnel: {}", reply.greTunnelDetails,
+ key.getName());
LOG.trace("Gre tunnel: {} attributes returned from VPP: {}", key.getName(), reply);
final GreTunnelDetails swInterfaceGreDetails = reply.greTunnelDetails.get(0);
if (swInterfaceGreDetails.isIpv6 == 1) {
final Ipv6Address dstIpv6 =
- new Ipv6Address(parseAddress(swInterfaceGreDetails.dstAddress).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceGreDetails.dstAddress).getHostAddress());
builder.setDst(new IpAddress(dstIpv6));
final Ipv6Address srcIpv6 =
- new Ipv6Address(parseAddress(swInterfaceGreDetails.srcAddress).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceGreDetails.srcAddress).getHostAddress());
builder.setSrc(new IpAddress(srcIpv6));
} else {
final byte[] dstBytes = Arrays.copyOfRange(swInterfaceGreDetails.dstAddress, 0, 4);
@@ -128,7 +127,7 @@ public class GreCustomizer extends FutureJVppCustomizer
LOG.debug("Gre tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
LOG.warn("Failed to readCurrentAttributes for: {}", id, e);
- throw new ReadFailedException( id, e );
+ throw new ReadFailedException(id, e);
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterconnectionReadUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterconnectionReadUtils.java
index 5dec9b426..acb7d855d 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterconnectionReadUtils.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterconnectionReadUtils.java
@@ -22,7 +22,6 @@ import static java.util.Objects.requireNonNull;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
@@ -43,7 +42,7 @@ import org.slf4j.LoggerFactory;
/**
* Utility class providing Interconnection read support.
*/
-final class InterconnectionReadUtils {
+final class InterconnectionReadUtils implements InterfaceDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(InterconnectionReadUtils.class);
@@ -62,11 +61,11 @@ final class InterconnectionReadUtils {
@Nullable
Interconnection readInterconnection(@Nonnull final InstanceIdentifier<?> id, @Nonnull final String ifaceName,
@Nonnull final ReadContext ctx)
- throws ReadFailedException {
+ throws ReadFailedException {
final int ifaceId = interfaceContext.getIndex(ifaceName, ctx.getMappingContext());
- final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(futureJVppCore, id, ifaceName,
- ifaceId, ctx.getModificationCache());
+ final SwInterfaceDetails iface = getVppInterfaceDetails(futureJVppCore, id, ifaceName,
+ ifaceId, ctx.getModificationCache(), LOG);
LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface);
final BridgeDomainDetailsReplyDump dumpReply = getDumpReply(id);
@@ -78,7 +77,7 @@ final class InterconnectionReadUtils {
// Set BVI if the bridgeDomainDetails.bviSwIfIndex == current sw if index
final Optional<BridgeDomainDetails> bridgeDomainForInterface =
- getBridgeDomainForInterface(dumpReply, bdForInterface.get().bdId);
+ getBridgeDomainForInterface(dumpReply, bdForInterface.get().bdId);
// Since we already found an interface assigned to a bridge domain, the details for BD must be present
checkState(bridgeDomainForInterface.isPresent());
if (bridgeDomainForInterface.get().bviSwIfIndex == ifaceId) {
@@ -112,7 +111,7 @@ final class InterconnectionReadUtils {
}
private BridgeDomainDetailsReplyDump getDumpReply(@Nonnull final InstanceIdentifier<?> id)
- throws ReadFailedException {
+ throws ReadFailedException {
try {
// We need to perform full bd dump, because there is no way
// to ask VPP for BD details given interface id/name (TODO HONEYCOMB-190 add it to vpp.api?)
@@ -121,8 +120,8 @@ final class InterconnectionReadUtils {
request.bdId = -1;
final CompletableFuture<BridgeDomainDetailsReplyDump> bdCompletableFuture =
- futureJVppCore.bridgeDomainSwIfDump(request).toCompletableFuture();
- return TranslateUtils.getReplyForRead(bdCompletableFuture, id);
+ futureJVppCore.bridgeDomainSwIfDump(request).toCompletableFuture();
+ return getReplyForRead(bdCompletableFuture, id);
} catch (VppBaseCallException e) {
throw new ReadFailedException(id, e);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizer.java
index d0baf003a..a85bfc09a 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizer.java
@@ -22,9 +22,9 @@ import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
+import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -54,12 +54,12 @@ import org.slf4j.LoggerFactory;
* Customizer for reading ietf-interfaces:interfaces-state/interface.
*/
public class InterfaceCustomizer extends FutureJVppCustomizer
- implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder> {
+ implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder>, ByteDataTranslator,
+ InterfaceDataTranslator {
- private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class);
public static final String DUMPED_IFCS_CONTEXT_KEY =
- InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds";
-
+ InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds";
+ private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class);
private final NamingContext interfaceNamingContext;
private final DisabledInterfacesManager interfaceDisableContext;
@@ -72,6 +72,19 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
}
@Nonnull
+ @SuppressWarnings("unchecked")
+ public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(@Nonnull final ModificationCache ctx) {
+ return ctx.get(DUMPED_IFCS_CONTEXT_KEY) == null
+ ? new HashMap<>()
+ // allow customizers to update the cache
+ : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY);
+ }
+
+ private static boolean isRegularInterface(final SwInterfaceDetails iface) {
+ return iface.subId == 0;
+ }
+
+ @Nonnull
@Override
public InterfaceBuilder getBuilder(@Nonnull InstanceIdentifier<Interface> id) {
return new InterfaceBuilder();
@@ -92,8 +105,8 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
}
// Pass cached details from getAllIds to getDetails to avoid additional dumps
- final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, ifaceName,
- index, ctx.getModificationCache());
+ final SwInterfaceDetails iface = getVppInterfaceDetails(getFutureJVpp(), id, ifaceName,
+ index, ctx.getModificationCache(), LOG);
LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface);
if (!isRegularInterface(iface)) {
@@ -102,33 +115,24 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
}
builder.setName(ifaceName);
- builder.setType(InterfaceUtils.getInterfaceType(new String(iface.interfaceName).intern()));
- builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.swIfIndex));
+ builder.setType(getInterfaceType(new String(iface.interfaceName).intern()));
+ builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex));
builder.setAdminStatus(1 == iface.adminUpDown
- ? AdminStatus.Up
- : AdminStatus.Down);
+ ? AdminStatus.Up
+ : AdminStatus.Down);
builder.setOperStatus(1 == iface.linkUpDown
- ? OperStatus.Up
- : OperStatus.Down);
+ ? OperStatus.Up
+ : OperStatus.Down);
if (0 != iface.linkSpeed) {
- builder.setSpeed(InterfaceUtils.vppInterfaceSpeedToYang(iface.linkSpeed));
+ builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed));
}
if (iface.l2AddressLength == 6) {
- builder.setPhysAddress(new PhysAddress(InterfaceUtils.vppPhysAddrToYang(iface.l2Address)));
+ builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address)));
}
LOG.trace("Base attributes read for interface: {} as: {}", ifaceName, builder);
}
@Nonnull
- @SuppressWarnings("unchecked")
- public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(@Nonnull final ModificationCache ctx) {
- return ctx.get(DUMPED_IFCS_CONTEXT_KEY) == null
- ? new HashMap<>()
- // allow customizers to update the cache
- : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY);
- }
-
- @Nonnull
@Override
public List<InterfaceKey> getAllIds(@Nonnull final InstanceIdentifier<Interface> id,
@Nonnull final ReadContext context) throws ReadFailedException {
@@ -141,9 +145,9 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
request.nameFilterValid = 0;
final CompletableFuture<SwInterfaceDetailsReplyDump> swInterfaceDetailsReplyDumpCompletableFuture =
- getFutureJVpp().swInterfaceDump(request).toCompletableFuture();
+ getFutureJVpp().swInterfaceDump(request).toCompletableFuture();
final SwInterfaceDetailsReplyDump ifaces =
- TranslateUtils.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, id);
+ getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, id);
if (null == ifaces || null == ifaces.swInterfaceDetails) {
LOG.debug("No interfaces for :{} found in VPP", id);
@@ -152,7 +156,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
// Cache interfaces dump in per-tx context to later be used in readCurrentAttributes
context.getModificationCache().put(DUMPED_IFCS_CONTEXT_KEY, ifaces.swInterfaceDetails.stream()
- .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
+ .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
final MappingContext mappingCtx = context.getMappingContext();
final Set<Integer> interfacesIdxs = ifaces.swInterfaceDetails.stream()
@@ -164,7 +168,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
.map((elt) -> {
// Store interface name from VPP in context if not yet present
if (!interfaceNamingContext.containsName(elt.swIfIndex, mappingCtx)) {
- interfaceNamingContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName),
+ interfaceNamingContext.addName(elt.swIfIndex, toString(elt.interfaceName),
mappingCtx);
}
LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP",
@@ -199,10 +203,6 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
}
}
- private static boolean isRegularInterface(final SwInterfaceDetails iface) {
- return iface.subId == 0;
- }
-
@Override
public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder<? extends DataObject> builder,
@Nonnull final List<Interface> readData) {
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslator.java
index 499f21dea..986b92c24 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtils.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslator.java
@@ -22,7 +22,8 @@ import static java.util.Objects.requireNonNull;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.util.RWUtils;
-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 java.math.BigInteger;
import java.util.Map;
import java.util.Objects;
@@ -34,11 +35,11 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.re
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
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.yang.types.rev130715.Gauge64;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.GreTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanGpeTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.GreTunnel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
@@ -46,29 +47,23 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
import org.openvpp.jvpp.core.dto.SwInterfaceDump;
import org.openvpp.jvpp.core.future.FutureJVppCore;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public final class InterfaceUtils {
- private static final Logger LOG = LoggerFactory.getLogger(InterfaceUtils.class);
+public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyConsumer {
- private static final Gauge64 vppLinkSpeed0 = new Gauge64(BigInteger.ZERO);
- private static final Gauge64 vppLinkSpeed1 = new Gauge64(BigInteger.valueOf(10L * 1000000));
- private static final Gauge64 vppLinkSpeed2 = new Gauge64(BigInteger.valueOf(100L * 1000000));
- private static final Gauge64 vppLinkSpeed4 = new Gauge64(BigInteger.valueOf(1000L * 1000000));
- private static final Gauge64 vppLinkSpeed8 = new Gauge64(BigInteger.valueOf(10000L * 1000000));
- private static final Gauge64 vppLinkSpeed16 = new Gauge64(BigInteger.valueOf(40000L * 1000000));
- private static final Gauge64 vppLinkSpeed32 = new Gauge64(BigInteger.valueOf(100000L * 1000000));
+ Gauge64 vppLinkSpeed0 = new Gauge64(BigInteger.ZERO);
+ Gauge64 vppLinkSpeed1 = new Gauge64(BigInteger.valueOf(10L * 1000000));
+ Gauge64 vppLinkSpeed2 = new Gauge64(BigInteger.valueOf(100L * 1000000));
+ Gauge64 vppLinkSpeed4 = new Gauge64(BigInteger.valueOf(1000L * 1000000));
+ Gauge64 vppLinkSpeed8 = new Gauge64(BigInteger.valueOf(10000L * 1000000));
+ Gauge64 vppLinkSpeed16 = new Gauge64(BigInteger.valueOf(40000L * 1000000));
+ Gauge64 vppLinkSpeed32 = new Gauge64(BigInteger.valueOf(100000L * 1000000));
- private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
+ char[] HEX_CHARS = "0123456789abcdef".toCharArray();
- private static final int PHYSICAL_ADDRESS_LENGTH = 6;
+ int PHYSICAL_ADDRESS_LENGTH = 6;
- private static final Collector<SwInterfaceDetails, ?, SwInterfaceDetails> SINGLE_ITEM_COLLECTOR =
- RWUtils.singleItemCollector();
-
- private InterfaceUtils() {
- throw new UnsupportedOperationException("This utility class cannot be instantiated");
- }
+ Collector<SwInterfaceDetails, ?, SwInterfaceDetails> SINGLE_ITEM_COLLECTOR =
+ RWUtils.singleItemCollector();
/**
* Convert VPP's link speed bitmask to Yang type. 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G
@@ -76,7 +71,7 @@ public final class InterfaceUtils {
* @param vppLinkSpeed Link speed in bitmask format from VPP.
* @return Converted value from VPP link speed
*/
- public static Gauge64 vppInterfaceSpeedToYang(byte vppLinkSpeed) {
+ default Gauge64 vppInterfaceSpeedToYang(byte vppLinkSpeed) {
switch (vppLinkSpeed) {
case 1:
return vppLinkSpeed1;
@@ -95,7 +90,7 @@ public final class InterfaceUtils {
}
}
- private static final void appendHexByte(final StringBuilder sb, final byte b) {
+ default void appendHexByte(final StringBuilder sb, final byte b) {
final int v = b & 0xFF;
sb.append(HEX_CHARS[v >>> 4]);
sb.append(HEX_CHARS[v & 15]);
@@ -111,25 +106,25 @@ public final class InterfaceUtils {
* @throws NullPointerException if vppPhysAddress is null
* @throws IllegalArgumentException if vppPhysAddress.length < 6
*/
- public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
+ default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
return vppPhysAddrToYang(vppPhysAddress, 0);
}
- public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress, final int startIndex) {
+ default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress, final int startIndex) {
Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes");
final int endIndex = startIndex + PHYSICAL_ADDRESS_LENGTH;
checkArgument(endIndex <= vppPhysAddress.length,
- "Invalid physical address size (%s) for given startIndex (%s), expected >= %s", vppPhysAddress.length,
- startIndex, endIndex);
+ "Invalid physical address size (%s) for given startIndex (%s), expected >= %s", vppPhysAddress.length,
+ startIndex, endIndex);
return printHexBinary(vppPhysAddress, startIndex, endIndex);
}
- public static String printHexBinary(@Nonnull final byte[] bytes) {
+ default String printHexBinary(@Nonnull final byte[] bytes) {
Objects.requireNonNull(bytes, "bytes array should not be null");
return printHexBinary(bytes, 0, bytes.length);
}
- private static String printHexBinary(@Nonnull final byte[] bytes, final int startIndex, final int endIndex) {
+ default String printHexBinary(@Nonnull final byte[] bytes, final int startIndex, final int endIndex) {
StringBuilder str = new StringBuilder();
appendHexByte(str, bytes[startIndex]);
@@ -148,7 +143,7 @@ public final class InterfaceUtils {
* @param vppIfIndex the sw interface index VPP reported.
* @return VPP's interface index incremented by one
*/
- public static int vppIfIndexToYang(int vppIfIndex) {
+ default int vppIfIndexToYang(int vppIfIndex) {
return vppIfIndex + 1;
}
@@ -158,7 +153,7 @@ public final class InterfaceUtils {
* @param yangIfIndex if-index from ietf-interfaces.
* @return VPP's representation of the if-index
*/
- public static int yangIfIndexToVpp(int yangIfIndex) {
+ default int yangIfIndexToVpp(int yangIfIndex) {
checkArgument(yangIfIndex >= 1, "YANG if-index has invalid value %s", yangIfIndex);
return yangIfIndex - 1;
}
@@ -168,21 +163,22 @@ public final class InterfaceUtils {
* Queries VPP for interface description given interface key.
*
* @param futureJVppCore VPP Java Future API
- * @param id InstanceIdentifier, which is passed in ReadFailedException
- * @param name interface name
- * @param index VPP index of the interface
- * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not
- * available or outdated, another dump will be performed.
+ * @param id InstanceIdentifier, which is passed in ReadFailedException
+ * @param name interface name
+ * @param index VPP index of the interface
+ * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not
+ * available or outdated, another dump will be performed.
* @return SwInterfaceDetails DTO or null if interface was not found
* @throws IllegalArgumentException If interface cannot be found
* @throws ReadFailedException If read operation had failed
*/
@Nonnull
- public static SwInterfaceDetails getVppInterfaceDetails(@Nonnull final FutureJVppCore futureJVppCore,
- @Nonnull final InstanceIdentifier<?> id,
- @Nonnull final String name, final int index,
- @Nonnull final ModificationCache ctx)
- throws ReadFailedException {
+ default SwInterfaceDetails getVppInterfaceDetails(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final InstanceIdentifier<?> id,
+ @Nonnull final String name, final int index,
+ @Nonnull final ModificationCache ctx,
+ @Nonnull final Logger callerLogger)
+ throws ReadFailedException {
requireNonNull(futureJVppCore, "futureJVppCore should not be null");
requireNonNull(name, "name should not be null");
requireNonNull(ctx, "ctx should not be null");
@@ -201,21 +197,21 @@ public final class InterfaceUtils {
SwInterfaceDetailsReplyDump ifaces;
try {
CompletionStage<SwInterfaceDetailsReplyDump> requestFuture = futureJVppCore.swInterfaceDump(request);
- ifaces = TranslateUtils.getReplyForRead(requestFuture.toCompletableFuture(), id);
+ ifaces = getReplyForRead(requestFuture.toCompletableFuture(), id);
if (null == ifaces || null == ifaces.swInterfaceDetails || ifaces.swInterfaceDetails.isEmpty()) {
request.nameFilterValid = 0;
- LOG.warn("VPP returned null instead of interface by key {} and its not cached", name);
- LOG.warn("Iterating through all the interfaces to find interface: {}", name);
+ callerLogger.warn("VPP returned null instead of interface by key {} and its not cached", name);
+ callerLogger.warn("Iterating through all the interfaces to find interface: {}", name);
// Or else just perform full dump and do inefficient filtering
requestFuture = futureJVppCore.swInterfaceDump(request);
- ifaces = TranslateUtils.getReplyForRead(requestFuture.toCompletableFuture(), id);
+ ifaces = getReplyForRead(requestFuture.toCompletableFuture(), id);
// Update the cache
allInterfaces.clear();
allInterfaces
- .putAll(ifaces.swInterfaceDetails.stream().collect(Collectors.toMap(d -> d.swIfIndex, d -> d)));
+ .putAll(ifaces.swInterfaceDetails.stream().collect(Collectors.toMap(d -> d.swIfIndex, d -> d)));
if (allInterfaces.containsKey(index)) {
return allInterfaces.get(index);
@@ -223,13 +219,13 @@ public final class InterfaceUtils {
throw new IllegalArgumentException("Unable to find interface " + name);
}
} catch (VppBaseCallException e) {
- LOG.warn("getVppInterfaceDetails for id :{} and name :{} failed with exception :", id, name, e);
+ callerLogger.warn("getVppInterfaceDetails for id :{} and name :{} failed with exception :", id, name, e);
throw new ReadFailedException(id, e);
}
// SwInterfaceDump's name filter does prefix match, so we need additional filtering:
final SwInterfaceDetails iface =
- ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect(SINGLE_ITEM_COLLECTOR);
+ ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect(SINGLE_ITEM_COLLECTOR);
allInterfaces.put(index, iface); // update the cache
return iface;
}
@@ -241,7 +237,7 @@ public final class InterfaceUtils {
* @return Interface type
*/
@Nonnull
- public static Class<? extends InterfaceType> getInterfaceType(@Nonnull final String interfaceName) {
+ default Class<? extends InterfaceType> getInterfaceType(@Nonnull final String interfaceName) {
if (interfaceName.startsWith("tap")) {
return Tap.class;
}
@@ -267,23 +263,25 @@ public final class InterfaceUtils {
/**
* Check interface type. Uses interface details from VPP to determine. Uses {@link
- * #getVppInterfaceDetails(FutureJVppCore, InstanceIdentifier, String, int, ModificationCache)} internally so tries to
- * utilize cache before asking VPP.
+ * #getVppInterfaceDetails(FutureJVppCore, InstanceIdentifier, String, int, ModificationCache, Logger)} internally so
+ * tries to utilize cache before asking VPP.
*/
- static boolean isInterfaceOfType(@Nonnull final FutureJVppCore jvpp,
- @Nonnull final ModificationCache cache,
- @Nonnull final InstanceIdentifier<?> id,
- final int index,
- @Nonnull final Class<? extends InterfaceType> ifcType) throws ReadFailedException {
+ default boolean isInterfaceOfType(@Nonnull final FutureJVppCore jvpp,
+ @Nonnull final ModificationCache cache,
+ @Nonnull final InstanceIdentifier<?> id,
+ final int index,
+ @Nonnull final Class<? extends InterfaceType> ifcType,
+ @Nonnull final Logger callerLogger)
+ throws ReadFailedException {
final String name = id.firstKeyOf(Interface.class).getName();
final SwInterfaceDetails vppInterfaceDetails =
- getVppInterfaceDetails(jvpp, id, name, index, cache);
+ getVppInterfaceDetails(jvpp, id, name, index, cache, callerLogger);
return isInterfaceOfType(ifcType, vppInterfaceDetails);
}
- static boolean isInterfaceOfType(final Class<? extends InterfaceType> ifcType,
- final SwInterfaceDetails cachedDetails) {
- return ifcType.equals(getInterfaceType(TranslateUtils.toString(cachedDetails.interfaceName)));
+ default boolean isInterfaceOfType(final Class<? extends InterfaceType> ifcType,
+ final SwInterfaceDetails cachedDetails) {
+ return ifcType.equals(getInterfaceType(toString(cachedDetails.interfaceName)));
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2Customizer.java
index e8e50f6d6..1590746c7 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2Customizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2Customizer.java
@@ -21,6 +21,7 @@ import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
+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.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.rev150105.VppInterfaceStateAugmentationBuilder;
@@ -33,10 +34,6 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-
-import static com.google.common.base.Preconditions.checkState;
-
/**
* Customizer for reading ietf-interfaces:interfaces-state/interface/iface_name/v3po:l2
*/
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizer.java
index 6ecaee63f..f84a3f792 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizer.java
@@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory;
* Customizer for reading vlan tag-rewrite configuration state form the VPP.
*/
public class RewriteCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Rewrite, RewriteBuilder> {
+ implements ReaderCustomizer<Rewrite, RewriteBuilder>, InterfaceDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class);
private final NamingContext interfaceContext;
@@ -86,8 +86,8 @@ public class RewriteCustomizer extends FutureJVppCustomizer
final String subInterfaceName = getSubInterfaceName(id);
LOG.debug("Reading attributes for sub interface: {}", subInterfaceName);
- final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, subInterfaceName,
- interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache());
+ final SwInterfaceDetails iface = getVppInterfaceDetails(getFutureJVpp(), id, subInterfaceName,
+ interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache(), LOG);
LOG.debug("VPP sub-interface details: {}", iface);
checkState(iface.subId != 0, "Interface returned by the VPP is not a sub-interface");
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizer.java
index cbc8c7ed1..8e7568d85 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceAclCustomizer.java
@@ -21,11 +21,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils.getSubInterfaceName;
import io.fd.honeycomb.translate.read.ReadContext;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
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.vppclassifier.VppClassifierContextManager;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory;
* Customizer for reading ACLs enabled on given sub-interface.
*/
public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Acl, AclBuilder>, AclReader {
+ implements ReaderCustomizer<Acl, AclBuilder>, AclReader, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceAclCustomizer.class);
private final NamingContext interfaceContext;
@@ -82,13 +82,13 @@ public class SubInterfaceAclCustomizer extends FutureJVppCustomizer
final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class);
checkArgument(subInterfacekey != null, "No sub-interface key found");
final String subInterfaceName =
- getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
+ getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue());
final ClassifyTableByInterface request = new ClassifyTableByInterface();
request.swIfIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
try {
- final ClassifyTableByInterfaceReply reply = TranslateUtils
- .getReplyForRead(getFutureJVpp().classifyTableByInterface(request).toCompletableFuture(), id);
+ final ClassifyTableByInterfaceReply reply =
+ getReplyForRead(getFutureJVpp().classifyTableByInterface(request).toCompletableFuture(), id);
builder.setL2Acl(readL2Acl(reply.l2TableId, classifyTableContext, ctx.getMappingContext()));
builder.setIp4Acl(readIp4Acl(reply.ip4TableId, classifyTableContext, ctx.getMappingContext()));
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizer.java
index 167ae6a8c..3ba102fde 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizer.java
@@ -17,16 +17,15 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
-import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.byteToBoolean;
import com.google.common.base.Preconditions;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
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.v3po.util.TranslateUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -72,11 +71,12 @@ import org.slf4j.LoggerFactory;
* Customizer for reading sub interfaces form the VPP.
*/
public class SubInterfaceCustomizer extends FutureJVppCustomizer
- implements ListReaderCustomizer<SubInterface, SubInterfaceKey, SubInterfaceBuilder> {
+ implements ListReaderCustomizer<SubInterface, SubInterfaceKey, SubInterfaceBuilder>, ByteDataTranslator,
+ InterfaceDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class);
- private NamingContext interfaceContext;
private static final Dot1qTag.VlanId ANY_VLAN_ID = new Dot1qTag.VlanId(Dot1qTag.VlanId.Enumeration.Any);
+ private NamingContext interfaceContext;
public SubInterfaceCustomizer(@Nonnull final FutureJVppCore jvpp,
@Nonnull final NamingContext interfaceContext) {
@@ -84,6 +84,28 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null");
}
+ private static String getSubInterfaceName(final InstanceIdentifier<SubInterface> id) {
+ return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(),
+ Math.toIntExact(id.firstKeyOf(id.getTargetType()).getIdentifier()));
+ }
+
+ private static Tag buildTag(final short index, final Class<? extends Dot1qTagVlanType> tagType,
+ final Dot1qTag.VlanId vlanId) {
+ TagBuilder tag = new TagBuilder();
+ tag.setIndex(index);
+ tag.setKey(new TagKey(index));
+ final Dot1qTagBuilder dtag = new Dot1qTagBuilder();
+ dtag.setTagType(tagType);
+ dtag.setVlanId(vlanId);
+ tag.setDot1qTag(dtag.build());
+ return tag.build();
+ }
+
+ private static Dot1qTag.VlanId buildVlanId(final short vlanId) {
+ // treat vlanId as unsigned value:
+ return new Dot1qTag.VlanId(new Dot1qVlanId(0xffff & vlanId));
+ }
+
@Nonnull
@Override
public List<SubInterfaceKey> getAllIds(@Nonnull final InstanceIdentifier<SubInterface> id,
@@ -105,7 +127,7 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
final CompletableFuture<SwInterfaceDetailsReplyDump> swInterfaceDetailsReplyDumpCompletableFuture =
getFutureJVpp().swInterfaceDump(request).toCompletableFuture();
final SwInterfaceDetailsReplyDump ifaces =
- TranslateUtils.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, id);
+ getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, id);
if (null == ifaces || null == ifaces.swInterfaceDetails) {
LOG.warn("Looking for sub-interfaces, but no interfaces found in VPP");
@@ -113,8 +135,9 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
}
// Cache interfaces dump in per-tx context to later be used in readCurrentAttributes
- context.getModificationCache().put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, ifaces.swInterfaceDetails.stream()
- .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
+ context.getModificationCache()
+ .put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, ifaces.swInterfaceDetails.stream()
+ .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
final List<SubInterfaceKey> interfacesKeys = ifaces.swInterfaceDetails.stream()
.filter(elt -> elt != null)
@@ -126,7 +149,7 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
LOG.debug("Sub-interfaces of {} found in VPP: {}", ifaceName, interfacesKeys);
return interfacesKeys;
} catch (VppBaseCallException e) {
- throw new ReadFailedException(id,e);
+ throw new ReadFailedException(id, e);
}
}
@@ -149,8 +172,8 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
final String subInterfaceName = getSubInterfaceName(id);
LOG.debug("Reading attributes for sub interface: {}", subInterfaceName);
- final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, subInterfaceName,
- interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache());
+ final SwInterfaceDetails iface = getVppInterfaceDetails(getFutureJVpp(), id, subInterfaceName,
+ interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()), ctx.getModificationCache(), LOG);
LOG.debug("VPP sub-interface details: {}", iface);
checkState(iface.subId != 0, "Interface returned by the VPP is not a sub-interface");
@@ -169,20 +192,15 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
builder.setOperStatus(1 == iface.linkUpDown
? SubInterfaceStatus.Up
: SubInterfaceStatus.Down);
- builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.swIfIndex));
+ builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex));
if (iface.l2AddressLength == 6) {
- builder.setPhysAddress(new PhysAddress(InterfaceUtils.vppPhysAddrToYang(iface.l2Address)));
+ builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address)));
}
if (0 != iface.linkSpeed) {
- builder.setSpeed(InterfaceUtils.vppInterfaceSpeedToYang(iface.linkSpeed));
+ builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed));
}
}
- private static String getSubInterfaceName(final InstanceIdentifier<SubInterface> id) {
- return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(),
- Math.toIntExact(id.firstKeyOf(id.getTargetType()).getIdentifier()));
- }
-
private Tags readTags(final SwInterfaceDetails iface) {
final TagsBuilder tags = new TagsBuilder();
final List<Tag> list = new ArrayList<>();
@@ -205,23 +223,6 @@ public class SubInterfaceCustomizer extends FutureJVppCustomizer
return tags.build();
}
- private static Tag buildTag(final short index, final Class<? extends Dot1qTagVlanType> tagType,
- final Dot1qTag.VlanId vlanId) {
- TagBuilder tag = new TagBuilder();
- tag.setIndex(index);
- tag.setKey(new TagKey(index));
- final Dot1qTagBuilder dtag = new Dot1qTagBuilder();
- dtag.setTagType(tagType);
- dtag.setVlanId(vlanId);
- tag.setDot1qTag(dtag.build());
- return tag.build();
- }
-
- private static Dot1qTag.VlanId buildVlanId(final short vlanId) {
- // treat vlanId as unsigned value:
- return new Dot1qTag.VlanId(new Dot1qVlanId(0xffff & vlanId));
- }
-
private Match readMatch(final SwInterfaceDetails iface) {
final MatchBuilder match = new MatchBuilder();
if (iface.subDefault == 1) {
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2Customizer.java
index debf0efee..37d85abca 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2Customizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceL2Customizer.java
@@ -19,8 +19,8 @@ package io.fd.honeycomb.translate.v3po.interfacesstate;
import static io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils.getSubInterfaceName;
import io.fd.honeycomb.translate.read.ReadContext;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import javax.annotation.Nonnull;
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizer.java
index 5bf3435ce..37ba6bbd9 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/TapCustomizer.java
@@ -16,14 +16,12 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
-
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
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 java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -48,7 +46,7 @@ import org.slf4j.LoggerFactory;
public class TapCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Tap, TapBuilder> {
+ implements ReaderCustomizer<Tap, TapBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(TapCustomizer.class);
public static final String DUMPED_TAPS_CONTEXT_KEY = TapCustomizer.class.getName() + "dumpedTapsDuringGetAllIds";
@@ -78,7 +76,7 @@ public class TapCustomizer extends FutureJVppCustomizer
final InterfaceKey key = id.firstKeyOf(Interface.class);
final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext());
if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index,
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class)) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class, LOG)) {
return;
}
@@ -86,23 +84,23 @@ public class TapCustomizer extends FutureJVppCustomizer
@SuppressWarnings("unchecked")
Map<Integer, SwInterfaceTapDetails> mappedTaps =
- (Map<Integer, SwInterfaceTapDetails>) ctx.getModificationCache().get(DUMPED_TAPS_CONTEXT_KEY);
+ (Map<Integer, SwInterfaceTapDetails>) ctx.getModificationCache().get(DUMPED_TAPS_CONTEXT_KEY);
- if(mappedTaps == null) {
+ if (mappedTaps == null) {
// Full Tap dump has to be performed here, no filter or anything is here to help so at least we cache it
final SwInterfaceTapDump request = new SwInterfaceTapDump();
final CompletionStage<SwInterfaceTapDetailsReplyDump> swInterfaceTapDetailsReplyDumpCompletionStage =
- getFutureJVpp().swInterfaceTapDump(request);
+ getFutureJVpp().swInterfaceTapDump(request);
final SwInterfaceTapDetailsReplyDump reply =
- TranslateUtils.getReplyForRead(swInterfaceTapDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
+ getReplyForRead(swInterfaceTapDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
- if(null == reply || null == reply.swInterfaceTapDetails) {
+ if (null == reply || null == reply.swInterfaceTapDetails) {
mappedTaps = Collections.emptyMap();
} else {
final List<SwInterfaceTapDetails> swInterfaceTapDetails = reply.swInterfaceTapDetails;
// Cache interfaces dump in per-tx context to later be used in readCurrentAttributes
mappedTaps = swInterfaceTapDetails.stream()
- .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails));
+ .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails));
}
ctx.getModificationCache().put(DUMPED_TAPS_CONTEXT_KEY, mappedTaps);
@@ -111,7 +109,7 @@ public class TapCustomizer extends FutureJVppCustomizer
final SwInterfaceTapDetails swInterfaceTapDetails = mappedTaps.get(index);
LOG.trace("Tap interface: {} attributes returned from VPP: {}", key.getName(), swInterfaceTapDetails);
- builder.setTapName(TranslateUtils.toString(swInterfaceTapDetails.devName));
+ builder.setTapName(toString(swInterfaceTapDetails.devName));
LOG.debug("Tap interface: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
LOG.warn("Failed to readCurrentAttributes for: {}", id, e);
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java
index 96ae4fdf0..032b3c214 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VhostUserCustomizer.java
@@ -16,14 +16,12 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
-
import io.fd.honeycomb.translate.read.ReadContext;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
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 java.math.BigInteger;
import java.util.Collections;
import java.util.List;
@@ -50,10 +48,11 @@ import org.slf4j.LoggerFactory;
public class VhostUserCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<VhostUser, VhostUserBuilder> {
+ implements ReaderCustomizer<VhostUser, VhostUserBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
+ public static final String DUMPED_VHOST_USERS_CONTEXT_KEY =
+ VhostUserCustomizer.class.getName() + "dumpedVhostUsersDuringGetAllIds";
private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class);
- public static final String DUMPED_VHOST_USERS_CONTEXT_KEY = VhostUserCustomizer.class.getName() + "dumpedVhostUsersDuringGetAllIds";
private NamingContext interfaceContext;
public VhostUserCustomizer(@Nonnull final FutureJVppCore jvpp, @Nonnull final NamingContext interfaceContext) {
@@ -80,7 +79,8 @@ public class VhostUserCustomizer extends FutureJVppCustomizer
final InterfaceKey key = id.firstKeyOf(Interface.class);
final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext());
if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index,
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class,
+ LOG)) {
return;
}
@@ -88,23 +88,26 @@ public class VhostUserCustomizer extends FutureJVppCustomizer
@SuppressWarnings("unchecked")
Map<Integer, SwInterfaceVhostUserDetails> mappedVhostUsers =
- (Map<Integer, SwInterfaceVhostUserDetails>) ctx.getModificationCache().get(DUMPED_VHOST_USERS_CONTEXT_KEY);
+ (Map<Integer, SwInterfaceVhostUserDetails>) ctx.getModificationCache()
+ .get(DUMPED_VHOST_USERS_CONTEXT_KEY);
- if(mappedVhostUsers == null) {
+ if (mappedVhostUsers == null) {
// Full VhostUser dump has to be performed here, no filter or anything is here to help so at least we cache it
final SwInterfaceVhostUserDump request = new SwInterfaceVhostUserDump();
- final CompletionStage<SwInterfaceVhostUserDetailsReplyDump> swInterfaceVhostUserDetailsReplyDumpCompletionStage =
- getFutureJVpp().swInterfaceVhostUserDump(request);
+ final CompletionStage<SwInterfaceVhostUserDetailsReplyDump>
+ swInterfaceVhostUserDetailsReplyDumpCompletionStage =
+ getFutureJVpp().swInterfaceVhostUserDump(request);
final SwInterfaceVhostUserDetailsReplyDump reply =
- TranslateUtils.getReplyForRead(swInterfaceVhostUserDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
+ getReplyForRead(swInterfaceVhostUserDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
- if(null == reply || null == reply.swInterfaceVhostUserDetails) {
+ if (null == reply || null == reply.swInterfaceVhostUserDetails) {
mappedVhostUsers = Collections.emptyMap();
} else {
- final List<SwInterfaceVhostUserDetails> swInterfaceVhostUserDetails = reply.swInterfaceVhostUserDetails;
+ final List<SwInterfaceVhostUserDetails> swInterfaceVhostUserDetails =
+ reply.swInterfaceVhostUserDetails;
// Cache interfaces dump in per-tx context to later be used in readCurrentAttributes
mappedVhostUsers = swInterfaceVhostUserDetails.stream()
- .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails));
+ .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails));
}
ctx.getModificationCache().put(DUMPED_VHOST_USERS_CONTEXT_KEY, mappedVhostUsers);
@@ -112,12 +115,15 @@ public class VhostUserCustomizer extends FutureJVppCustomizer
// Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping
final SwInterfaceVhostUserDetails swInterfaceVhostUserDetails = mappedVhostUsers.get(index);
- LOG.trace("Vhost user interface: {} attributes returned from VPP: {}", key.getName(), swInterfaceVhostUserDetails);
+ LOG.trace("Vhost user interface: {} attributes returned from VPP: {}", key.getName(),
+ swInterfaceVhostUserDetails);
- builder.setRole(swInterfaceVhostUserDetails.isServer == 1 ? VhostUserRole.Server : VhostUserRole.Client);
+ builder.setRole(swInterfaceVhostUserDetails.isServer == 1
+ ? VhostUserRole.Server
+ : VhostUserRole.Client);
builder.setFeatures(BigInteger.valueOf(swInterfaceVhostUserDetails.features));
builder.setNumMemoryRegions((long) swInterfaceVhostUserDetails.numRegions);
- builder.setSocket(TranslateUtils.toString(swInterfaceVhostUserDetails.sockFilename));
+ builder.setSocket(toString(swInterfaceVhostUserDetails.sockFilename));
builder.setVirtioNetHdrSize((long) swInterfaceVhostUserDetails.virtioNetHdrSz);
builder.setConnectError(Integer.toString(swInterfaceVhostUserDetails.sockErrno));
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java
index b0a0496ce..2d01c3e39 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizer.java
@@ -17,14 +17,13 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
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 java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -52,7 +51,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VxlanCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<Vxlan, VxlanBuilder> {
+ implements ReaderCustomizer<Vxlan, VxlanBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class);
private final NamingContext interfaceContext;
@@ -81,7 +80,7 @@ public class VxlanCustomizer extends FutureJVppCustomizer
try {
final InterfaceKey key = id.firstKeyOf(Interface.class);
final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext());
- if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanTunnel.class)) {
+ if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanTunnel.class, LOG)) {
return;
}
@@ -91,31 +90,32 @@ public class VxlanCustomizer extends FutureJVppCustomizer
request.swIfIndex = index;
final CompletionStage<VxlanTunnelDetailsReplyDump> swInterfaceVxlanDetailsReplyDumpCompletionStage =
- getFutureJVpp().vxlanTunnelDump(request);
+ getFutureJVpp().vxlanTunnelDump(request);
final VxlanTunnelDetailsReplyDump reply =
- TranslateUtils.getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
+ getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
// VPP keeps vxlan tunnel interfaces even after they were deleted (optimization)
// However there ar no longer any vxlan tunnel specific fields assigned to it and this call
// returns nothing
if (reply == null || reply.vxlanTunnelDetails == null || reply.vxlanTunnelDetails.isEmpty()) {
LOG.debug(
- "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
- "after delete", key.getName(), index);
+ "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
+ "after delete", key.getName(), index);
return;
}
checkState(reply.vxlanTunnelDetails.size() == 1,
- "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails, key.getName());
+ "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails,
+ key.getName());
LOG.trace("Vxlan tunnel: {} attributes returned from VPP: {}", key.getName(), reply);
final VxlanTunnelDetails swInterfaceVxlanDetails = reply.vxlanTunnelDetails.get(0);
if (swInterfaceVxlanDetails.isIpv6 == 1) {
final Ipv6Address dstIpv6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanDetails.dstAddress).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceVxlanDetails.dstAddress).getHostAddress());
builder.setDst(new IpAddress(dstIpv6));
final Ipv6Address srcIpv6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanDetails.srcAddress).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceVxlanDetails.srcAddress).getHostAddress());
builder.setSrc(new IpAddress(srcIpv6));
} else {
final byte[] dstBytes = Arrays.copyOfRange(swInterfaceVxlanDetails.dstAddress, 0, 4);
@@ -126,11 +126,11 @@ public class VxlanCustomizer extends FutureJVppCustomizer
builder.setSrc(new IpAddress(srcIpv4));
}
builder.setEncapVrfId((long) swInterfaceVxlanDetails.encapVrfId);
- builder.setVni( new VxlanVni((long) swInterfaceVxlanDetails.vni));
+ builder.setVni(new VxlanVni((long) swInterfaceVxlanDetails.vni));
LOG.debug("Vxlan tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
LOG.warn("Failed to readCurrentAttributes for: {}", id);
- throw new ReadFailedException( id, e );
+ throw new ReadFailedException(id, e);
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizer.java
index e6a9f85a2..deeba8ae0 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizer.java
@@ -17,14 +17,13 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static com.google.common.base.Preconditions.checkState;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.isInterfaceOfType;
import io.fd.honeycomb.translate.read.ReadContext;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
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 java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -53,7 +52,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class VxlanGpeCustomizer extends FutureJVppCustomizer
- implements ReaderCustomizer<VxlanGpe, VxlanGpeBuilder> {
+ implements ReaderCustomizer<VxlanGpe, VxlanGpeBuilder>, InterfaceDataTranslator, JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class);
private NamingContext interfaceContext;
@@ -82,7 +81,7 @@ public class VxlanGpeCustomizer extends FutureJVppCustomizer
try {
final InterfaceKey key = id.firstKeyOf(Interface.class);
final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext());
- if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanGpeTunnel.class)) {
+ if (!isInterfaceOfType(getFutureJVpp(), ctx.getModificationCache(), id, index, VxlanGpeTunnel.class, LOG)) {
return;
}
@@ -92,31 +91,33 @@ public class VxlanGpeCustomizer extends FutureJVppCustomizer
request.swIfIndex = index;
final CompletionStage<VxlanGpeTunnelDetailsReplyDump> swInterfaceVxlanGpeDetailsReplyDumpCompletionStage =
- getFutureJVpp().vxlanGpeTunnelDump(request);
+ getFutureJVpp().vxlanGpeTunnelDump(request);
final VxlanGpeTunnelDetailsReplyDump reply =
- TranslateUtils.getReplyForRead(swInterfaceVxlanGpeDetailsReplyDumpCompletionStage.toCompletableFuture(), id);
+ getReplyForRead(swInterfaceVxlanGpeDetailsReplyDumpCompletionStage.toCompletableFuture(),
+ id);
// VPP keeps VxlanGpe tunnel interfaces even after they were deleted (optimization)
// However there are no longer any VxlanGpe tunnel specific fields assigned to it and this call
// returns nothing
if (reply == null || reply.vxlanGpeTunnelDetails == null || reply.vxlanGpeTunnelDetails.isEmpty()) {
LOG.debug(
- "VxlanGpe tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
- "after delete", key.getName(), index);
+ "VxlanGpe tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" +
+ "after delete", key.getName(), index);
return;
}
checkState(reply.vxlanGpeTunnelDetails.size() == 1,
- "Unexpected number of returned VxlanGpe tunnels: {} for tunnel: {}", reply.vxlanGpeTunnelDetails, key.getName());
+ "Unexpected number of returned VxlanGpe tunnels: {} for tunnel: {}", reply.vxlanGpeTunnelDetails,
+ key.getName());
LOG.trace("VxlanGpe tunnel: {} attributes returned from VPP: {}", key.getName(), reply);
final VxlanGpeTunnelDetails swInterfaceVxlanGpeDetails = reply.vxlanGpeTunnelDetails.get(0);
if (swInterfaceVxlanGpeDetails.isIpv6 == 1) {
final Ipv6Address remote6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.remote).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.remote).getHostAddress());
builder.setRemote(new IpAddress(remote6));
final Ipv6Address local6 =
- new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.local).getHostAddress());
+ new Ipv6Address(parseAddress(swInterfaceVxlanGpeDetails.local).getHostAddress());
builder.setLocal(new IpAddress(local6));
} else {
final byte[] dstBytes = Arrays.copyOfRange(swInterfaceVxlanGpeDetails.remote, 0, 4);
@@ -127,13 +128,13 @@ public class VxlanGpeCustomizer extends FutureJVppCustomizer
builder.setLocal(new IpAddress(local4));
}
builder.setVni(new VxlanGpeVni((long) swInterfaceVxlanGpeDetails.vni));
- builder.setNextProtocol(VxlanGpeNextProtocol.forValue(swInterfaceVxlanGpeDetails.protocol));
+ builder.setNextProtocol(VxlanGpeNextProtocol.forValue(swInterfaceVxlanGpeDetails.protocol));
builder.setEncapVrfId((long) swInterfaceVxlanGpeDetails.encapVrfId);
builder.setDecapVrfId((long) swInterfaceVxlanGpeDetails.decapVrfId);
LOG.debug("VxlanGpe tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
LOG.warn("Failed to readCurrentAttributes for: {}", id);
- throw new ReadFailedException( id, e );
+ throw new ReadFailedException(id, e);
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
index f3605ca0f..e2df8e2cb 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java
@@ -17,17 +17,18 @@
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
import static com.google.common.base.Preconditions.checkNotNull;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.dumpAddresses;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.findIpAddressDetailsByIp;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.getAllIpv4AddressIds;
import com.google.common.base.Optional;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.AddressDumpExecutor;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check.AddressDumpCheck;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -49,15 +50,22 @@ import org.slf4j.LoggerFactory;
* Read customizer for interface Ipv4 addresses.
*/
public class Ipv4AddressCustomizer extends FutureJVppCustomizer
- implements ListReaderCustomizer<Address, AddressKey, AddressBuilder> {
+ implements ListReaderCustomizer<Address, AddressKey, AddressBuilder>, Ipv4Reader {
private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class);
+ private static final String CACHE_KEY = Ipv4AddressCustomizer.class.getName();
private final NamingContext interfaceContext;
+ private final DumpCacheManager<IpAddressDetailsReplyDump, AddressDumpParams> dumpManager;
- public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext) {
+ public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final NamingContext interfaceContext) {
super(futureJVppCore);
this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
+ this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
+ .withExecutor(new AddressDumpExecutor(futureJVppCore))
+ .withNonEmptyPredicate(new AddressDumpCheck())
+ .build();
}
@Override
@@ -69,38 +77,55 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
@Override
public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder,
@Nonnull ReadContext ctx)
- throws ReadFailedException {
+ throws ReadFailedException {
LOG.debug("Reading attributes for interface address: {}", id);
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- final Optional<IpAddressDetailsReplyDump> dumpOptional =
- dumpAddresses(getFutureJVpp(), id, interfaceName, interfaceIndex, ctx);
+ final Optional<IpAddressDetailsReplyDump> dumpOptional;
+ try {
+ dumpOptional =
+ dumpManager.getDump(CACHE_KEY, ctx.getModificationCache(),
+ new AddressDumpParams(interfaceIndex, false));
+ } catch (DumpExecutionFailedException e) {
+ throw new ReadFailedException(id, e);
+ }
- final Optional<IpAddressDetails> ipAddressDetails =
- findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
+ if (dumpOptional.isPresent()) {
+ final Optional<IpAddressDetails> ipAddressDetails =
+ findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
- if (ipAddressDetails.isPresent()) {
- final IpAddressDetails detail = ipAddressDetails.get();
- builder.setIp(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip))
- .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
+ if (ipAddressDetails.isPresent()) {
+ final IpAddressDetails detail = ipAddressDetails.get();
+ builder.setIp(arrayToIpv4AddressNoZone(detail.ip))
+ .setSubnet(
+ new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
- if (LOG.isDebugEnabled()) {
- LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}",
- interfaceName, interfaceIndex, id, builder.build());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}",
+ interfaceName, interfaceIndex, id, builder.build());
+ }
}
}
+
+
}
@Override
public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx)
- throws ReadFailedException {
+ throws ReadFailedException {
LOG.debug("Reading list of keys for interface addresses: {}", id);
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- final Optional<IpAddressDetailsReplyDump> dumpOptional =
- dumpAddresses(getFutureJVpp(), id, interfaceName, interfaceIndex, ctx);
+ final Optional<IpAddressDetailsReplyDump> dumpOptional;
+ try {
+ dumpOptional =
+ dumpManager.getDump(CACHE_KEY, ctx.getModificationCache(),
+ new AddressDumpParams(interfaceIndex, false));
+ } catch (DumpExecutionFailedException e) {
+ throw new ReadFailedException(id, e);
+ }
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java
index 05b5ef47c..d95557e6d 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java
@@ -17,9 +17,9 @@
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
-import io.fd.honeycomb.translate.read.ReadFailedException;
import java.util.Collections;
import java.util.List;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder;
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4ReadUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4ReadUtils.java
deleted file mode 100644
index c3c5616c9..000000000
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4ReadUtils.java
+++ /dev/null
@@ -1,130 +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.interfacesstate.ip;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Optional;
-import io.fd.honeycomb.translate.read.ReadContext;
-import io.fd.honeycomb.translate.util.RWUtils;
-import io.fd.honeycomb.translate.ModificationCache;
-import io.fd.honeycomb.translate.read.ReadFailedException;
-import io.fd.honeycomb.translate.v3po.util.ReadTimeoutException;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
-import java.util.Collections;
-import java.util.List;
-import java.util.function.Function;
-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.Ipv4AddressNoZone;
-import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.jvpp.VppBaseCallException;
-import org.openvpp.jvpp.core.dto.IpAddressDetails;
-import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
-import org.openvpp.jvpp.core.dto.IpAddressDump;
-import org.openvpp.jvpp.core.future.FutureJVppCore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Utility class providing Ipv4 read support.
- */
-final class Ipv4ReadUtils {
-
- static final String CACHE_KEY = Ipv4ReadUtils.class.getName();
- private static final Logger LOG = LoggerFactory.getLogger(Ipv4ReadUtils.class);
-
- private Ipv4ReadUtils() {
- throw new UnsupportedOperationException("This utility class cannot be instantiated");
- }
-
- // Many VPP APIs do not provide get operation for single item. Dump requests for all items are used instead.
- // To improve HC performance, caching dump requests is a common pattern.
- // TODO: HONEYCOMB-102 use more generic caching implementation, once provided
- static Optional<IpAddressDetailsReplyDump> dumpAddresses(@Nonnull final FutureJVppCore futureJVppCore,
- @Nonnull final InstanceIdentifier<?> id,
- @Nonnull final String interfaceName,
- final int interfaceIndex, @Nonnull final ReadContext ctx)
- throws ReadFailedException {
-
- final String cacheKey = CACHE_KEY + interfaceName;
- Optional<IpAddressDetailsReplyDump> dumpFromCache = dumpAddressFromCache(cacheKey, ctx.getModificationCache());
-
- if (dumpFromCache.isPresent()) {
- return dumpFromCache;
- }
-
- Optional<IpAddressDetailsReplyDump> dumpFromOperational;
- try {
- dumpFromOperational = dumpAddressFromOperationalData(futureJVppCore, id, interfaceIndex);
- } catch (VppBaseCallException e) {
- throw new ReadFailedException(id, e);
- }
-
- if (dumpFromOperational.isPresent()) {
- ctx.getModificationCache().put(cacheKey, dumpFromOperational.get());
- }
-
- return dumpFromOperational;
- }
-
- private static Optional<IpAddressDetailsReplyDump> dumpAddressFromCache(@Nonnull final String cacheKey,
- @Nonnull final ModificationCache cache) {
- LOG.debug("Retrieving Ipv4 addresses from cache for {}", cacheKey);
- return Optional.fromNullable((IpAddressDetailsReplyDump) cache.get(cacheKey));
- }
-
- private static Optional<IpAddressDetailsReplyDump> dumpAddressFromOperationalData(
- @Nonnull final FutureJVppCore futureJVppCore, @Nonnull final InstanceIdentifier<?> id, final int interfaceIndex)
- throws VppBaseCallException, ReadTimeoutException {
- LOG.debug("Dumping Ipv4 addresses for interface id={}", interfaceIndex);
- final IpAddressDump dumpRequest = new IpAddressDump();
- dumpRequest.isIpv6 = 0;
- dumpRequest.swIfIndex = interfaceIndex;
- return Optional.fromNullable(
- TranslateUtils.getReplyForRead(futureJVppCore.ipAddressDump(dumpRequest).toCompletableFuture(), id));
- }
-
- @Nonnull static <T extends Identifier> List<T> getAllIpv4AddressIds(
- final Optional<IpAddressDetailsReplyDump> dumpOptional,
- @Nonnull final Function<Ipv4AddressNoZone, T> keyConstructor) {
- if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) {
- return dumpOptional.get().ipAddressDetails.stream()
- .map(detail -> keyConstructor.apply(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip)))
- .collect(Collectors.toList());
- } else {
- return Collections.emptyList();
- }
- }
-
- static Optional<IpAddressDetails> findIpAddressDetailsByIp(
- final Optional<IpAddressDetailsReplyDump> dump,
- @Nonnull final Ipv4AddressNoZone ip) {
- checkNotNull(ip, "ip address should not be null");
-
- if (dump.isPresent() && dump.get().ipAddressDetails != null) {
- final List<IpAddressDetails> details = dump.get().ipAddressDetails;
-
- return Optional.of(details.stream()
- .filter(singleDetail -> ip.equals(TranslateUtils.arrayToIpv4AddressNoZone(singleDetail.ip)))
- .collect(RWUtils.singleItemCollector()));
- }
- return Optional.absent();
- }
-
-}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4Reader.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4Reader.java
new file mode 100644
index 000000000..60447d974
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4Reader.java
@@ -0,0 +1,68 @@
+/*
+ * 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.interfacesstate.ip;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
+import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Function;
+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.Ipv4AddressNoZone;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.openvpp.jvpp.core.dto.IpAddressDetails;
+import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+
+/**
+ * Utility class providing Ipv4 read support.
+ */
+interface Ipv4Reader extends Ipv4Translator, JvppReplyConsumer {
+
+ @Nonnull
+ default <T extends Identifier> List<T> getAllIpv4AddressIds(
+ final Optional<IpAddressDetailsReplyDump> dumpOptional,
+ @Nonnull final Function<Ipv4AddressNoZone, T> keyConstructor) {
+ if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) {
+ return dumpOptional.get().ipAddressDetails.stream()
+ .map(detail -> keyConstructor.apply(arrayToIpv4AddressNoZone(detail.ip)))
+ .collect(Collectors.toList());
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ default Optional<IpAddressDetails> findIpAddressDetailsByIp(
+ final Optional<IpAddressDetailsReplyDump> dump,
+ @Nonnull final Ipv4AddressNoZone ip) {
+ checkNotNull(ip, "ip address should not be null");
+
+ if (dump.isPresent() && dump.get().ipAddressDetails != null) {
+ final List<IpAddressDetails> details = dump.get().ipAddressDetails;
+
+ return Optional.of(details.stream()
+ .filter(singleDetail -> ip.equals(arrayToIpv4AddressNoZone(singleDetail.ip)))
+ .collect(RWUtils.singleItemCollector()));
+ }
+ return Optional.absent();
+ }
+
+}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
index e1f306140..bd96bfbb9 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java
@@ -17,18 +17,19 @@
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
import static com.google.common.base.Preconditions.checkNotNull;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.dumpAddresses;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.findIpAddressDetailsByIp;
-import static io.fd.honeycomb.translate.v3po.interfacesstate.ip.Ipv4ReadUtils.getAllIpv4AddressIds;
import com.google.common.base.Optional;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.AddressDumpExecutor;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check.AddressDumpCheck;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
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.v3po.util.TranslateUtils;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -51,16 +52,22 @@ import org.slf4j.LoggerFactory;
* Read customizer for sub-interface Ipv4 addresses.
*/
public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
- implements ListReaderCustomizer<Address, AddressKey, AddressBuilder> {
+ implements ListReaderCustomizer<Address, AddressKey, AddressBuilder>, Ipv4Reader {
private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class);
+ private static final String CACHE_KEY = SubInterfaceIpv4AddressCustomizer.class.getName();
private final NamingContext interfaceContext;
+ private final DumpCacheManager<IpAddressDetailsReplyDump, AddressDumpParams> dumpManager;
public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
@Nonnull final NamingContext interfaceContext) {
super(futureJVppCore);
this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
+ this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
+ .withExecutor(new AddressDumpExecutor(futureJVppCore))
+ .withNonEmptyPredicate(new AddressDumpCheck())
+ .build();
}
@Override
@@ -72,38 +79,49 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
@Override
public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder,
@Nonnull ReadContext ctx)
- throws ReadFailedException {
+ throws ReadFailedException {
LOG.debug("Reading attributes for sub-interface address: {}", id);
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
- final Optional<IpAddressDetailsReplyDump> dumpOptional =
- dumpAddresses(getFutureJVpp(), id, subInterfaceName, subInterfaceIndex, ctx);
+ final Optional<IpAddressDetailsReplyDump> dumpOptional;
+ try {
+ dumpOptional = dumpManager
+ .getDump(CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ } catch (DumpExecutionFailedException e) {
+ throw new ReadFailedException(id, e);
+ }
+
final Optional<IpAddressDetails> ipAddressDetails =
- findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
+ findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
if (ipAddressDetails.isPresent()) {
final IpAddressDetails detail = ipAddressDetails.get();
- builder.setIp(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip))
- .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
+ builder.setIp(arrayToIpv4AddressNoZone(detail.ip))
+ .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
if (LOG.isDebugEnabled()) {
LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}",
- subInterfaceName, subInterfaceIndex, id, builder.build());
+ subInterfaceName, subInterfaceIndex, id, builder.build());
}
}
}
@Override
public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx)
- throws ReadFailedException {
+ throws ReadFailedException {
LOG.debug("Reading list of keys for sub-interface addresses: {}", id);
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
- final Optional<IpAddressDetailsReplyDump> dumpOptional =
- dumpAddresses(getFutureJVpp(), id, subInterfaceName, subInterfaceIndex, ctx);
+ final Optional<IpAddressDetailsReplyDump> dumpOptional;
+ try {
+ dumpOptional = dumpManager
+ .getDump(CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ } catch (DumpExecutionFailedException e) {
+ throw new ReadFailedException(id, e);
+ }
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
@@ -115,6 +133,6 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer
private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) {
return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(),
- Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier()));
+ Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier()));
}
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/AddressDumpExecutor.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/AddressDumpExecutor.java
new file mode 100644
index 000000000..a94e47c91
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/AddressDumpExecutor.java
@@ -0,0 +1,47 @@
+package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump;
+
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException;
+import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
+import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
+import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer;
+import java.util.concurrent.TimeoutException;
+import javax.annotation.Nonnull;
+import org.openvpp.jvpp.VppBaseCallException;
+import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import org.openvpp.jvpp.core.dto.IpAddressDump;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+public class AddressDumpExecutor
+ implements EntityDumpExecutor<IpAddressDetailsReplyDump, AddressDumpParams>, ByteDataTranslator,
+ JvppReplyConsumer {
+
+ private FutureJVppCore vppApi;
+
+ public AddressDumpExecutor(@Nonnull final FutureJVppCore vppApi) {
+ this.vppApi = checkNotNull(vppApi, "Vpp api refference cannot be null");
+ }
+
+ @Override
+ public IpAddressDetailsReplyDump executeDump(final AddressDumpParams params) throws DumpExecutionFailedException {
+ checkNotNull(params, "Address dump params cannot be null");
+
+ IpAddressDump dumpRequest = new IpAddressDump();
+ dumpRequest.isIpv6 = booleanToByte(params.isIpv6());
+ dumpRequest.swIfIndex = params.getInterfaceIndex();
+
+ try {
+ return getReply(vppApi.ipAddressDump(dumpRequest).toCompletableFuture());
+ } catch (TimeoutException e) {
+ throw DumpTimeoutException
+ .wrapTimeoutException("Dumping or addresses ended in timeout[params : ]" + params, e);
+ } catch (VppBaseCallException e) {
+ throw DumpCallFailedException.wrapFailedCallException("Dumping of addresses failed[params : ]" + params, e);
+ }
+ }
+}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java
new file mode 100644
index 000000000..d6ab28db0
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/check/AddressDumpCheck.java
@@ -0,0 +1,16 @@
+package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check;
+
+import io.fd.honeycomb.translate.util.read.cache.EntityDumpNonEmptyCheck;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.check.DumpCheckFailedException;
+import io.fd.honeycomb.translate.util.read.cache.exceptions.check.i.DumpEmptyException;
+import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+
+public class AddressDumpCheck implements EntityDumpNonEmptyCheck<IpAddressDetailsReplyDump> {
+
+ @Override
+ public void assertNotEmpty(final IpAddressDetailsReplyDump data) throws DumpCheckFailedException {
+ if (data == null || data.ipAddressDetails == null) {
+ throw new DumpEmptyException("Invalid data dumped");
+ }
+ }
+}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java
new file mode 100644
index 000000000..9b7591b58
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java
@@ -0,0 +1,28 @@
+package io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params;
+
+public class AddressDumpParams {
+
+ private final int interfaceIndex;
+ private final boolean isIpv6;
+
+ public AddressDumpParams(final int interfaceIndex, final boolean isIpv6) {
+ this.interfaceIndex = interfaceIndex;
+ this.isIpv6 = isIpv6;
+ }
+
+ public int getInterfaceIndex() {
+ return interfaceIndex;
+ }
+
+ public boolean isIpv6() {
+ return isIpv6;
+ }
+
+ @Override
+ public String toString() {
+ return "AddressDumpParams{" +
+ "interfaceIndex=" + interfaceIndex +
+ ", isIpv6=" + isIpv6 +
+ '}';
+ }
+}