summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java95
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java73
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VppInterfaceStateCustomizer.java30
3 files changed, 112 insertions, 86 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java
index 718cef1b5..f7d473f73 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java
@@ -19,6 +19,14 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
import io.fd.honeycomb.v3po.translate.Context;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -29,21 +37,23 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
+import org.openvpp.jvpp.dto.SwInterfaceDump;
+import org.openvpp.jvpp.future.FutureJVpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.List;
-
-public class InterfaceCustomizer extends io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer
+public class InterfaceCustomizer extends FutureJVppCustomizer
implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder> {
private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class);
+ private final NamingContext interfaceContext;
- public InterfaceCustomizer(org.openvpp.vppjapi.vppApi vppApi) {
- super(vppApi);
+ public InterfaceCustomizer(@Nonnull final FutureJVpp jvpp, final NamingContext interfaceContext) {
+ super(jvpp);
+ this.interfaceContext = interfaceContext;
}
@Override
@@ -54,56 +64,67 @@ public class InterfaceCustomizer extends io.fd.honeycomb.v3po.translate.v3po.uti
@Override
public void readCurrentAttributes(InstanceIdentifier<Interface> id, InterfaceBuilder builder, Context ctx)
throws ReadFailedException {
- vppInterfaceDetails[] ifaces;
-
final InterfaceKey key = id.firstKeyOf(id.getTargetType());
- // Extract one interface detail from VPP
- ifaces = getVppApi().swInterfaceDump((byte) 1, key.getName().getBytes());
- if (null == ifaces) {
- LOG.warn("VPP returned null instead of interface by key {}", key.getName().getBytes());
- return;
- }
- if (1 != ifaces.length) {
- LOG.error("Failed to extract interface {} details from VPP", key.getName());
- return;
+ final SwInterfaceDetails iface;
+ try {
+ iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), key);
+ } catch (Exception e) {
+ throw new ReadFailedException(id, e);
}
- final vppInterfaceDetails iface = ifaces[0];
- builder.setName(iface.interfaceName);
+ builder.setName(key.getName());
// FIXME: report interface type based on name
//Tunnel.class l2vlan(802.1q) bridge (transparent bridge?)
builder.setType(EthernetCsmacd.class);
- builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.ifIndex));
- builder.setAdminStatus(iface.adminUp == 1 ? AdminStatus.Up : AdminStatus.Down);
- builder.setOperStatus(1 == iface.linkUp ? OperStatus.Up : OperStatus.Down);
+ builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.swIfIndex));
+ builder.setAdminStatus(iface.adminUpDown == 1
+ ? AdminStatus.Up
+ : AdminStatus.Down);
+ builder.setOperStatus(1 == iface.linkUpDown
+ ? OperStatus.Up
+ : OperStatus.Down);
if (0 != iface.linkSpeed) {
builder.setSpeed(InterfaceUtils.vppInterfaceSpeedToYang(iface.linkSpeed));
}
- if (iface.physAddr.length == 6) {
- builder.setPhysAddress(new PhysAddress(InterfaceUtils.vppPhysAddrToYang(iface.physAddr)));
+ if (iface.l2AddressLength == 6) {
+ builder.setPhysAddress(new PhysAddress(InterfaceUtils.vppPhysAddrToYang(iface.l2Address)));
}
}
+ @Nonnull
@Override
- public List<InterfaceKey> getAllIds(InstanceIdentifier<Interface> id, Context context) {
- vppInterfaceDetails[] ifaces;
- final ArrayList<InterfaceKey> interfaceKeys = new ArrayList<>();
-
- ifaces = getVppApi().swInterfaceDump((byte) 0, "".getBytes());
- if (null != ifaces) {
- for (vppInterfaceDetails ifc : ifaces) {
- interfaceKeys.add(new InterfaceKey(ifc.interfaceName));
- }
+ public List<InterfaceKey> getAllIds(@Nonnull final InstanceIdentifier<Interface> id,
+ @Nonnull final Context context) throws ReadFailedException {
+ final SwInterfaceDump request = new SwInterfaceDump();
+ request.nameFilter = "".getBytes();
+ request.nameFilterValid = 0;
+
+ final CompletableFuture<SwInterfaceDetailsReplyDump> swInterfaceDetailsReplyDumpCompletableFuture =
+ getFutureJVpp().swInterfaceDump(request).toCompletableFuture();
+ final SwInterfaceDetailsReplyDump ifaces = V3poUtils.getReply(swInterfaceDetailsReplyDumpCompletableFuture);
+
+ // TODO can we get null here?
+ if (null == ifaces || null == ifaces.swInterfaceDetails) {
+ return Collections.emptyList();
}
- return interfaceKeys;
+ return ifaces.swInterfaceDetails.stream()
+ .filter(elt -> elt != null)
+ .map((elt) -> {
+ // Store interface name from VPP in context if not yet present
+ if(!interfaceContext.containsName(elt.swIfIndex)){
+ interfaceContext.addName(elt.swIfIndex, V3poUtils.toString(elt.interfaceName));
+ }
+ return new InterfaceKey(interfaceContext.getName(elt.swIfIndex));
+ })
+ .collect(Collectors.toList());
}
@Override
- public void merge(org.opendaylight.yangtools.concepts.Builder<? extends DataObject> builder,
- List<Interface> readData) {
+ public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder<? extends DataObject> builder,
+ @Nonnull final List<Interface> readData) {
((InterfacesStateBuilder) builder).setInterface(readData);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
index d589c257f..979c9d6bd 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
@@ -16,15 +16,18 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import java.math.BigInteger;
-
+import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
-
+import javax.annotation.Nullable;
+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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
-
-import com.google.common.base.Preconditions;
-import org.openvpp.vppjapi.vppApi;
-import org.openvpp.vppjapi.vppInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
+import org.openvpp.jvpp.dto.SwInterfaceDump;
+import org.openvpp.jvpp.future.FutureJVpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,8 +45,7 @@ public class InterfaceUtils {
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
/**
- * Convert VPP's link speed bitmask to Yang type. 1 = 10M, 2 = 100M, 4 = 1G,
- * 8 = 10G, 16 = 40G, 32 = 100G
+ * Convert VPP's link speed bitmask to Yang type. 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G
*
* @param vppLinkSpeed Link speed in bitmask format from VPP.
* @return Converted value from VPP link speed
@@ -74,16 +76,11 @@ public class InterfaceUtils {
}
/**
- * Convert VPP's physical address stored byte array format to string as Yang
- * dictates
- * <p>
- * Replace later with
- * https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type-
- * util/src/main/
+ * Convert VPP's physical address stored byte array format to string as Yang dictates <p> Replace later with
+ * https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type- util/src/main/
* java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfYangUtil.java
*
- * @param vppPhysAddress byte array of bytes constructing the network IF physical
- * address.
+ * @param vppPhysAddress byte array of bytes constructing the network IF physical address.
* @return String like "aa:bb:cc:dd:ee:ff"
*/
public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
@@ -102,8 +99,8 @@ public class InterfaceUtils {
}
/**
- * VPP's interface index is counted from 0, whereas ietf-interface's
- * if-index is from 1. This function converts from VPP's interface index to YANG's interface index.
+ * VPP's interface index is counted from 0, whereas ietf-interface's if-index is from 1. This function converts from
+ * VPP's interface index to YANG's interface index.
*
* @param vppIfIndex the sw interface index VPP reported.
* @return VPP's interface index incremented by one
@@ -115,7 +112,7 @@ public class InterfaceUtils {
/**
* This function does the opposite of what {@link #vppIfIndexToYang(int)} does.
*
- * @param yangIf if-index from ietf-interfaces.
+ * @param yangIfIndex if-index from ietf-interfaces.
* @return VPP's representation of the if-index
*/
public static int YangIfIndexToVpp(int yangIfIndex) {
@@ -124,25 +121,31 @@ public class InterfaceUtils {
}
- public static vppInterfaceDetails[] getVppInterfaceDetails(final vppApi api,
- final boolean specificInterface,
- String interfaceName) {
- if (interfaceName == null) {
- interfaceName = new String();
- }
- vppInterfaceDetails[] ifaces = api.swInterfaceDump(
- (byte) (specificInterface ? 1 : 0),
- interfaceName.getBytes());
- if (null == ifaces) {
- LOG.warn("VPP returned null instead of interface by key {}", interfaceName);
+ /**
+ * Queries VPP for interface description given interface key.
+ *
+ * @param futureJvpp VPP Java Future API
+ * @param key interface key
+ * @return SwInterfaceDetails DTO or null if interface was not found
+ * @throws ExecutionException if exception has been thrown while executing VPP query
+ * @throws InterruptedException if the current thread was interrupted
+ */
+ @Nullable
+ public static SwInterfaceDetails getVppInterfaceDetails(@Nonnull final FutureJVpp futureJvpp,
+ @Nonnull InterfaceKey key)
+ throws ExecutionException, InterruptedException {
+ final SwInterfaceDump request = new SwInterfaceDump();
+ request.nameFilter = key.getName().getBytes();
+ request.nameFilterValid = 1;
+
+ // TODO should we use timeout?
+ SwInterfaceDetailsReplyDump ifaces = futureJvpp.swInterfaceDump(request).toCompletableFuture().get();
+ if (null == ifaces) { // TODO can we get null here?
+ LOG.warn("VPP returned null instead of interface by key {}", key.getName().getBytes());
return null;
}
- if (1 != ifaces.length) {
- LOG.error("Failed to extract interface {} details from VPP", interfaceName);
- }
-
- return ifaces;
+ return Iterables.getOnlyElement(ifaces.swInterfaceDetails);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VppInterfaceStateCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VppInterfaceStateCustomizer.java
index 8e5cc8932..2bc8beaaa 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VppInterfaceStateCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VppInterfaceStateCustomizer.java
@@ -16,11 +16,10 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
-import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.getVppInterfaceDetails;
-
import io.fd.honeycomb.v3po.translate.Context;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer;
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.InterfaceBuilder;
@@ -32,28 +31,31 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.future.FutureJVpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VppInterfaceStateCustomizer extends io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer
+public class VppInterfaceStateCustomizer extends FutureJVppCustomizer
implements ChildReaderCustomizer<VppInterfaceStateAugmentation, VppInterfaceStateAugmentationBuilder> {
private static final Logger LOG = LoggerFactory.getLogger(VppInterfaceStateCustomizer.class);
- public VppInterfaceStateCustomizer(org.openvpp.vppjapi.vppApi vppApi) {
- super(vppApi);
+ public VppInterfaceStateCustomizer(@Nonnull final FutureJVpp jvpp) {
+ super(jvpp);
}
@Override
- public void merge(@Nonnull Builder<? extends DataObject> parentBuilder, @Nonnull VppInterfaceStateAugmentation readValue) {
+ public void merge(@Nonnull Builder<? extends DataObject> parentBuilder,
+ @Nonnull VppInterfaceStateAugmentation readValue) {
((InterfaceBuilder) parentBuilder).addAugmentation(VppInterfaceStateAugmentation.class, readValue);
}
@Nonnull
@Override
- public VppInterfaceStateAugmentationBuilder getBuilder(@Nonnull InstanceIdentifier<VppInterfaceStateAugmentation> id) {
+ public VppInterfaceStateAugmentationBuilder getBuilder(
+ @Nonnull InstanceIdentifier<VppInterfaceStateAugmentation> id) {
return new VppInterfaceStateAugmentationBuilder();
}
@@ -63,15 +65,15 @@ public class VppInterfaceStateCustomizer extends io.fd.honeycomb.v3po.translate.
@Nonnull final Context ctx) throws ReadFailedException {
final InterfaceKey key = id.firstKeyOf(Interface.class);
- vppInterfaceDetails[] ifaces = getVppInterfaceDetails(getVppApi(), true, key.getName());
- if (null == ifaces || ifaces.length != 1) {
- return;
+ final SwInterfaceDetails iface;
+ try {
+ iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), key);
+ } catch (Exception e) {
+ throw new ReadFailedException(id, e);
}
- final vppInterfaceDetails iface = ifaces[0];
final EthernetBuilder ethernet = new EthernetBuilder();
-
- ethernet.setMtu(iface.linkMtu);
+ ethernet.setMtu((int) iface.linkMtu);
switch (iface.linkDuplex) {
case 1:
ethernet.setDuplex(Ethernet.Duplex.Half);