summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-06-10 15:28:09 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-06-15 10:32:09 +0000
commit5502b2eb50c9a3f9fb23ab758036bdbd67fbd32d (patch)
tree66095b607083e9d356400c02bde893fa1893565a /v3po/v3po2vpp
parent53ec754bd9ca566bd718dd915ae8d83a67b0f7f8 (diff)
HONEYCOMB-91: Create read customizer for L2FibEntry
Change-Id: I0ad5d98ba6c9442c79b21bf04be07b81d04a4595 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java14
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java62
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizer.java151
-rw-r--r--v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java21
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java27
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java2
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizerTest.java139
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java37
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java10
9 files changed, 358 insertions, 105 deletions
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 b9a25974b..1db7b8a42 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
@@ -102,7 +102,6 @@ public final class InterfaceUtils {
}
// TODO rename and move to V3poUtils
-
/**
* Reads first 6 bytes of supplied byte array and converts to string as Yang dictates <p> Replace later with
* https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type- util/src/main/
@@ -114,13 +113,18 @@ public final class InterfaceUtils {
* @throws IllegalArgumentException if vppPhysAddress.length < 6
*/
public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
+ return vppPhysAddrToYang(vppPhysAddress, 0);
+ }
+
+ public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress, int startIndex) {
Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes");
- Preconditions.checkArgument(PHYSICAL_ADDRESS_LENGTH <= vppPhysAddress.length,
- "Invalid physical address size %s, expected >= 6", vppPhysAddress.length);
+ final int endIndex = startIndex+PHYSICAL_ADDRESS_LENGTH;
+ Preconditions.checkArgument(endIndex <= vppPhysAddress.length,
+ "Invalid physical address size (%s) for given startIndex (%d), expected >= %d", vppPhysAddress.length, startIndex, endIndex);
StringBuilder physAddr = new StringBuilder();
- appendHexByte(physAddr, vppPhysAddress[0]);
- for (int i = 1; i < PHYSICAL_ADDRESS_LENGTH; i++) {
+ appendHexByte(physAddr, vppPhysAddress[startIndex]);
+ for (int i = startIndex+1; i < endIndex; i++) {
physAddr.append(":");
appendHexByte(physAddr, vppPhysAddress[i]);
}
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java
index a6a31e2ae..4f0b0f741 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java
@@ -20,8 +20,6 @@ import static io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils.byteToBool
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.primitives.Longs;
import io.fd.honeycomb.v3po.translate.read.ReadContext;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer;
@@ -31,13 +29,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibFilter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibForward;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
@@ -48,9 +39,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.dto.BridgeDomainDetails;
import org.openvpp.jvpp.dto.BridgeDomainDetailsReplyDump;
import org.openvpp.jvpp.dto.BridgeDomainDump;
-import org.openvpp.jvpp.dto.L2FibTableDump;
-import org.openvpp.jvpp.dto.L2FibTableEntry;
-import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
import org.openvpp.jvpp.future.FutureJVpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,13 +48,10 @@ public final class BridgeDomainCustomizer extends FutureJVppCustomizer
private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class);
private final NamingContext bdContext;
- private final NamingContext interfaceContext;
- public BridgeDomainCustomizer(@Nonnull final FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext,
- @Nonnull final NamingContext interfaceContext) {
+ public BridgeDomainCustomizer(@Nonnull final FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext) {
super(futureJVpp);
this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null");
- this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null");;
}
@Override
@@ -102,39 +87,6 @@ public final class BridgeDomainCustomizer extends FutureJVppCustomizer
builder.setForward(byteToBoolean(bridgeDomainDetails.forward));
builder.setLearn(byteToBoolean(bridgeDomainDetails.learn));
builder.setUnknownUnicastFlood(byteToBoolean(bridgeDomainDetails.uuFlood));
-
- final L2FibTableDump l2FibRequest = new L2FibTableDump();
- l2FibRequest.bdId = bdId;
- try {
- final L2FibTableEntryReplyDump dump =
- getFutureJVpp().l2FibTableDump(l2FibRequest).toCompletableFuture().get();
- final List<L2FibEntry> l2Fibs;
-
- if(null == dump || null == dump.l2FibTableEntry) {
- l2Fibs = Collections.emptyList();
- } else {
- l2Fibs = Lists.newArrayListWithCapacity(dump.l2FibTableEntry.size());
- for (L2FibTableEntry entry : dump.l2FibTableEntry) {
- // entry.mac is a long value in the format 66:55:44:33:22:11:XX:XX
- // where mac address is 11:22:33:44:55:66
- final PhysAddress address = new PhysAddress(getMacAddress(Longs.toByteArray(entry.mac)));
- l2Fibs.add(new L2FibEntryBuilder()
- .setAction(byteToBoolean(entry.filterMac)
- ? L2FibFilter.class
- : L2FibForward.class)
- .setBridgedVirtualInterface(byteToBoolean(entry.bviMac))
- .setOutgoingInterface(interfaceContext.getName(entry.swIfIndex, context.getMappingContext()))
- .setStaticConfig(byteToBoolean(entry.staticMac))
- .setPhysAddress(address)
- .setKey(new L2FibEntryKey(address))
- .build());
- }
- }
- builder.setL2FibTable(new L2FibTableBuilder().setL2FibEntry(l2Fibs).build());
-
- } catch (Exception e) {
- LOG.warn("Failed to acquire l2FibTableDump for domain id={}", bdId, e);
- }
}
private void logBridgeDomainDetails(final BridgeDomainDetails bridgeDomainDetails) {
@@ -151,18 +103,6 @@ public final class BridgeDomainCustomizer extends FutureJVppCustomizer
}
}
- // TODO move to some utility class
- private static String getMacAddress(byte[] mac) {
- StringBuilder sb = new StringBuilder(18);
- for (int i=5; i>=0; --i) {
- if (sb.length() > 0) {
- sb.append(':');
- }
- sb.append(String.format("%02x", mac[i]));
- }
- return sb.toString();
- }
-
@Nonnull
@Override
public BridgeDomainBuilder getBuilder(@Nonnull final InstanceIdentifier<BridgeDomain> id) {
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizer.java
new file mode 100644
index 000000000..f3393c26d
--- /dev/null
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizer.java
@@ -0,0 +1,151 @@
+/*
+ * 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.v3po.translate.v3po.vppstate;
+
+import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.vppPhysAddrToYang;
+import static io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils.byteToBoolean;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Longs;
+import io.fd.honeycomb.v3po.translate.read.ReadContext;
+import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
+import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.util.RWUtils;
+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.util.TranslateUtils;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibFilter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibForward;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppBaseCallException;
+import org.openvpp.jvpp.dto.L2FibTableDump;
+import org.openvpp.jvpp.dto.L2FibTableEntry;
+import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
+import org.openvpp.jvpp.future.FutureJVpp;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class L2FibEntryCustomizer extends FutureJVppCustomizer
+ implements ListReaderCustomizer<L2FibEntry, L2FibEntryKey, L2FibEntryBuilder> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class);
+
+ Collector<L2FibTableEntry, ?, L2FibTableEntry> SINGLE_ITEM_COLLECTOR =
+ RWUtils.singleItemCollector();
+
+ private final NamingContext bdContext;
+ private final NamingContext interfaceContext;
+
+ public L2FibEntryCustomizer(@Nonnull final FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext,
+ @Nonnull final NamingContext interfaceContext) {
+ super(futureJVpp);
+ this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null");
+ this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null");
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull final InstanceIdentifier<L2FibEntry> id,
+ @Nonnull final L2FibEntryBuilder builder, @Nonnull final ReadContext ctx)
+ throws ReadFailedException {
+
+ final L2FibEntryKey key = id.firstKeyOf(id.getTargetType());
+ final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class);
+ final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext());
+ LOG.debug("Reading L2 FIB entry: key={}. bridgeDomainKey={}, bdId={}", key, bridgeDomainKey, bdId);
+
+ try {
+ // TODO use cached l2FibTable
+ final L2FibTableEntry entry = dumpL2Fibs(bdId).stream().filter(e -> key.getPhysAddress()
+ .equals(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(e.mac), 2))))
+ .collect(SINGLE_ITEM_COLLECTOR);
+
+ builder.setAction(byteToBoolean(entry.filterMac)
+ ? L2FibFilter.class
+ : L2FibForward.class);
+ builder.setBridgedVirtualInterface(byteToBoolean(entry.bviMac));
+
+ if (entry.swIfIndex != -1) {
+ builder.setOutgoingInterface(interfaceContext.getName(entry.swIfIndex, ctx.getMappingContext()));
+ }
+ builder.setStaticConfig(byteToBoolean(entry.staticMac));
+ builder.setPhysAddress(key.getPhysAddress());
+ builder.setKey(key);
+ } catch (Exception e) {
+ throw new ReadFailedException(id, e);
+ }
+ }
+
+ @Nonnull
+ private List<L2FibTableEntry> dumpL2Fibs(final int bdId) throws VppBaseCallException {
+ final L2FibTableDump l2FibRequest = new L2FibTableDump();
+ l2FibRequest.bdId = bdId;
+
+ final CompletableFuture<L2FibTableEntryReplyDump> l2FibTableDumpCompletableFuture =
+ getFutureJVpp().l2FibTableDump(l2FibRequest).toCompletableFuture();
+
+ final L2FibTableEntryReplyDump dump = TranslateUtils.getReply(l2FibTableDumpCompletableFuture);
+
+ if (null == dump || null == dump.l2FibTableEntry) {
+ return Collections.emptyList();
+ } else {
+ return dump.l2FibTableEntry;
+ }
+ }
+
+ @Nonnull
+ @Override
+ public List<L2FibEntryKey> getAllIds(@Nonnull final InstanceIdentifier<L2FibEntry> id,
+ @Nonnull final ReadContext ctx) throws ReadFailedException {
+ final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class);
+ final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext());
+
+ LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId);
+ try {
+ return dumpL2Fibs(bdId).stream()
+ .map(entry -> new L2FibEntryKey(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(entry.mac), 2)))
+ ).collect(Collectors.toList());
+ } catch (VppBaseCallException e) {
+ throw new ReadFailedException(id, e);
+ }
+ }
+
+ @Override
+ public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<L2FibEntry> readData) {
+ ((L2FibTableBuilder) builder).setL2FibEntry(readData);
+ }
+
+ @Nonnull
+ @Override
+ public L2FibEntryBuilder getBuilder(@Nonnull final InstanceIdentifier<L2FibEntry> id) {
+ return new L2FibEntryBuilder();
+ }
+}
diff --git a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java
index 32e5dabc0..f56c824a6 100644
--- a/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java
+++ b/v3po/v3po2vpp/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/v3po2vpp/rev160406/VppStateHoneycombReaderModule.java
@@ -11,6 +11,7 @@ import io.fd.honeycomb.v3po.translate.util.read.ReflexiveChildReaderCustomizer;
import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.util.ReadTimeoutException;
import io.fd.honeycomb.v3po.translate.v3po.vppstate.BridgeDomainCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.vppstate.L2FibEntryCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.vppstate.VersionCustomizer;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
@@ -26,6 +27,11 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.vpp.jvpp.cf
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.vpp.jvpp.cfg.rev160406.VppJvppImplModuleFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
@@ -66,9 +72,20 @@ public class VppStateHoneycombReaderModule extends org.opendaylight.yang.gen.v1.
versionReader = new KeepaliveReaderWrapper<>(versionReader, getKeepaliveExecutorDependency().getExecutor(),
ReadTimeoutException.class, 30, () -> reinitializeJVpp(reinitializationCounter));
+ final CompositeListReader<L2FibEntry, L2FibEntryKey, L2FibEntryBuilder> l2FibEntryReader = new CompositeListReader<>(L2FibEntry.class,
+ new L2FibEntryCustomizer(vppApi,
+ getBridgeDomainContextVppStateDependency(), getInterfaceContextVppStateDependency()));
+
+ final ChildReader<L2FibTable> l2FibTableReader = new CompositeChildReader<>(
+ L2FibTable.class,
+ RWUtils.singletonChildReaderList(l2FibEntryReader),
+ new ReflexiveChildReaderCustomizer<>(L2FibTableBuilder.class));
+
final CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- new CompositeListReader<>(BridgeDomain.class, new BridgeDomainCustomizer(vppApi,
- getBridgeDomainContextVppStateDependency(), getInterfaceContextVppStateDependency()));
+ new CompositeListReader<>(BridgeDomain.class,
+ RWUtils.singletonChildReaderList((ChildReader)l2FibTableReader),
+ new BridgeDomainCustomizer(vppApi,
+ getBridgeDomainContextVppStateDependency()));
final ChildReader<BridgeDomains> bridgeDomainsReader = new CompositeChildReader<>(
BridgeDomains.class,
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java
index ce20f0734..5828da850 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java
@@ -16,10 +16,16 @@
package io.fd.honeycomb.v3po.translate.v3po.test;
+import static org.mockito.Mockito.doReturn;
+
import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import java.util.List;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
@@ -37,4 +43,25 @@ public class ContextTestUtils {
org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class,
new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
}
+
+ public static void mockMapping(final MappingContext mappingContext, final String name, final int id, final String namingContextName) {
+ final InstanceIdentifier<Mappings> mappingsIid = getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
+
+ final Optional<Mapping> singleMapping = getMapping(name, id);
+ final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
+
+ final MappingsBuilder mappingsBuilder;
+ if(previousMappings != null && previousMappings.isPresent()) {
+ mappingsBuilder = new MappingsBuilder(previousMappings.get());
+ } else {
+ mappingsBuilder = new MappingsBuilder();
+ mappingsBuilder.setMapping(Lists.newArrayList());
+ }
+
+ final List<Mapping> mappingList = mappingsBuilder.getMapping();
+ mappingList.add(singleMapping.get());
+ doReturn(Optional.of(mappingsBuilder.setMapping(mappingList).build()))
+ .when(mappingContext).read(mappingsIid);
+ doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName));
+ }
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
index 369038687..80403eb58 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
@@ -54,6 +54,6 @@ public class BridgeDomainCustomizerTest extends ListReaderCustomizerTest<BridgeD
@Override
protected RootReaderCustomizer<BridgeDomain, BridgeDomainBuilder> initCustomizer() {
- return new BridgeDomainCustomizer(api, bdContext, interfacesContext);
+ return new BridgeDomainCustomizer(api, bdContext);
}
} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
new file mode 100644
index 000000000..4808b6d88
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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.v3po.translate.v3po.vppstate;
+
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.mockMapping;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibForward;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.L2FibTableDump;
+import org.openvpp.jvpp.dto.L2FibTableEntry;
+import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
+
+public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntry, L2FibEntryKey, L2FibEntryBuilder> {
+
+ private static final String BD_NAME = "testBD0";
+ private static final int BD_ID = 111;
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 123;
+ private static final String BD_CTX_NAME = "bd-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private NamingContext bdContext;
+ private NamingContext interfacesContext;
+
+ public L2FibEntryCustomizerTest() {
+ super(L2FibEntry.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ }
+
+ @Override
+ protected RootReaderCustomizer<L2FibEntry, L2FibEntryBuilder> initCustomizer() {
+ return new L2FibEntryCustomizer(api, bdContext, interfacesContext);
+ }
+
+ @Test
+ public void testMerge() throws Exception {
+ final L2FibTableBuilder builder = mock(L2FibTableBuilder.class);
+ final List<L2FibEntry> value = Collections.emptyList();
+ getCustomizer().merge(builder, value);
+ verify(builder).setL2FibEntry(value);
+ }
+
+ private static InstanceIdentifier<L2FibEntry> getL2FibEntryId(final String bdName, final PhysAddress address) {
+ return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName))
+ .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
+ }
+
+ private void whenL2FibTableDumpThenReturn(final List<L2FibTableEntry> l2FibTableEntryList)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump();
+ reply.l2FibTableEntry = l2FibTableEntryList;
+
+ final CompletableFuture<L2FibTableEntryReplyDump> replyFuture = new CompletableFuture<>();
+ replyFuture.complete(reply);
+ when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(replyFuture);
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ final long address_vpp = 0x0000010203040506L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+
+ mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+
+ whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
+
+ final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class);
+ getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx);
+
+ verify(builder).setAction(L2FibForward.class);
+ verify(builder).setBridgedVirtualInterface(false);
+ verify(builder).setOutgoingInterface(IFACE_NAME);
+ verify(builder).setStaticConfig(false);
+ verify(builder).setPhysAddress(address);
+ verify(builder).setKey(new L2FibEntryKey(address));
+ }
+
+ private L2FibTableEntry generateL2FibEntry(final long mac) {
+ final L2FibTableEntry entry = new L2FibTableEntry();
+ entry.mac = mac;
+ entry.swIfIndex = IFACE_ID;
+ return entry;
+ }
+
+ @Test
+ public void testGetAllIds() throws Exception {
+ final long address_vpp = 0x0000112233445566L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+
+ whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
+
+ final List<L2FibEntryKey> ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx);
+ assertEquals(1, ids.size());
+ assertEquals(address, ids.get(0).getPhysAddress());
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
index 4ca89da8f..8b11769d6 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
@@ -16,8 +16,8 @@
package io.fd.honeycomb.v3po.translate.v3po.vppstate;
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.mockMapping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -30,7 +30,6 @@ import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.ModificationCache;
@@ -47,11 +46,9 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
@@ -101,7 +98,7 @@ public class VppStateTest {
bdContext = new NamingContext("generatedBdName", "bd-test-instance");
interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
- vppStateReader = VppStateTestUtils.getVppStateReader(api, bdContext, interfaceContext);
+ vppStateReader = VppStateTestUtils.getVppStateReader(api, bdContext);
readerRegistry = new DelegatingReaderRegistry(Collections.<Reader<? extends DataObject>>singletonList(vppStateReader));
}
@@ -208,13 +205,14 @@ public class VppStateTest {
* L2fib does not have a dedicated reader, relying on auto filtering
*/
@Test
+ @Ignore("L2 FIB was moved to dedicated customizer. TODO: add infra test that covers such case")
@SuppressWarnings("unchecked")
public void testReadL2Fib() throws Exception {
final BridgeDomainDetails bd = new BridgeDomainDetails();
bd.bdId = 0;
final String bdName = "bdn1";
mockBdMapping(bd, bdName);
- mockMapping("eth1", 0, "ifc-test-instance");
+ mockMapping(mappingContext, "eth1", 0, "ifc-test-instance");
whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
final L2FibTableEntry l2FibEntry = new L2FibTableEntry();
@@ -237,28 +235,7 @@ public class VppStateTest {
}
private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
- mockMapping(bdName, bd.bdId, "bd-test-instance");
- }
-
- private void mockMapping(final String name, final int id, final String namingContextName) {
- final InstanceIdentifier<Mappings> mappingsIid = getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
-
- final Optional<Mapping> singleMapping = getMapping(name, id);
- final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
-
- final MappingsBuilder mappingsBuilder;
- if(previousMappings != null && previousMappings.isPresent()) {
- mappingsBuilder = new MappingsBuilder(previousMappings.get());
- } else {
- mappingsBuilder = new MappingsBuilder();
- mappingsBuilder.setMapping(Lists.newArrayList());
- }
-
- final List<Mapping> mappingList = mappingsBuilder.getMapping();
- mappingList.add(singleMapping.get());
- doReturn(Optional.of(mappingsBuilder.setMapping(mappingList).build()))
- .when(mappingContext).read(mappingsIid);
- doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName));
+ mockMapping(mappingContext, bdName, bd.bdId, "bd-test-instance");
}
@Test
@@ -272,7 +249,7 @@ public class VppStateTest {
VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
final CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- VppStateTestUtils.getBridgeDomainReader(api, bdContext, interfaceContext);
+ VppStateTestUtils.getBridgeDomainReader(api, bdContext);
final List<BridgeDomain> read =
bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java
index 688f75911..8fd57d679 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java
@@ -47,14 +47,13 @@ final class VppStateTestUtils {
* Create root VppState reader with all its children wired
*/
static CompositeRootReader<VppState, VppStateBuilder> getVppStateReader(@Nonnull final FutureJVpp futureJVpp,
- @Nonnull final NamingContext bdContext,
- @Nonnull final NamingContext interfaceContext) {
+ @Nonnull final NamingContext bdContext) {
final ChildReader<Version> versionReader = new CompositeChildReader<>(
Version.class, new VersionCustomizer(futureJVpp));
final CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- getBridgeDomainReader(futureJVpp, bdContext, interfaceContext);
+ getBridgeDomainReader(futureJVpp, bdContext);
final ChildReader<BridgeDomains> bridgeDomainsReader = new CompositeChildReader<>(
BridgeDomains.class,
@@ -73,10 +72,9 @@ final class VppStateTestUtils {
}
static CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader(
- final @Nonnull FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext,
- @Nonnull final NamingContext interfaceContext) {
+ final @Nonnull FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext) {
return new CompositeListReader<>(
BridgeDomain.class,
- new BridgeDomainCustomizer(futureJVpp, bdContext, interfaceContext));
+ new BridgeDomainCustomizer(futureJVpp, bdContext));
}
}