From b5d9c75265a5779ed7404b426f3f91a6b1e07e49 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 19 May 2017 14:01:09 +0200 Subject: Adapt to vpp API changes Changes were introduced by https://gerrit.fd.io/r/#/c/6662/ Change-Id: If5d4866339623c6789ac1674c5c190a4a28f51c6 Signed-off-by: Marek Gradzki --- .../interfacesstate/InterconnectionReadUtils.java | 60 +++++++++++----------- .../hc2vpp/v3po/l2state/L2FibEntryCustomizer.java | 24 ++++----- .../v3po/interfacesstate/L2CustomizerTest.java | 45 ++++++++-------- .../v3po/l2state/L2FibEntryCustomizerTest.java | 23 ++++----- .../io/fd/hc2vpp/v3po/l2state/L2StateTest.java | 10 ++-- 5 files changed, 80 insertions(+), 82 deletions(-) (limited to 'v3po/v3po2vpp/src') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java index 2111deee0..731619641 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java @@ -19,15 +19,16 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainSwIfDetails; import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import io.fd.vpp.jvpp.core.types.BridgeDomainSwIf; +import java.util.Arrays; import java.util.Optional; import java.util.concurrent.CompletableFuture; import javax.annotation.Nonnull; @@ -68,40 +69,41 @@ final class InterconnectionReadUtils implements InterfaceDataTranslator { LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); final BridgeDomainDetailsReplyDump dumpReply = getDumpReply(id); - final Optional bdForInterface = getBridgeDomainForInterface(ifaceId, dumpReply); - if (bdForInterface.isPresent()) { - final BridgeDomainSwIfDetails bdSwIfDetails = bdForInterface.get(); - final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); - bbBuilder.setBridgeDomain(bridgeDomainContext.getName(bdSwIfDetails.bdId, ctx.getMappingContext())); - - // Set BVI if the bridgeDomainDetails.bviSwIfIndex == current sw if index - final Optional bridgeDomainForInterface = - 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) { - bbBuilder.setBridgedVirtualInterface(true); - } else { - bbBuilder.setBridgedVirtualInterface(false); - } - - if (bdSwIfDetails.shg != 0) { - bbBuilder.setSplitHorizonGroup((short) bdSwIfDetails.shg); + for (final BridgeDomainDetails bd : dumpReply.bridgeDomainDetails) { + final Optional bdIfAssignment = getBridgeDomainSwIf(ifaceId, bd); + if (bdIfAssignment.isPresent()) { + final BridgeDomainSwIf bridgeDomainSwIf = bdIfAssignment.get(); + final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); + bbBuilder.setBridgeDomain(bridgeDomainContext.getName(bd.bdId, ctx.getMappingContext())); + + // Set BVI if the bridgeDomainDetails.bviSwIfIndex == current sw if index + final Optional bridgeDomainForInterface = + getBridgeDomainForInterface(dumpReply, bd.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) { + bbBuilder.setBridgedVirtualInterface(true); + } else { + bbBuilder.setBridgedVirtualInterface(false); + } + + if (bridgeDomainSwIf.shg != 0) { + bbBuilder.setSplitHorizonGroup((short) bridgeDomainSwIf.shg); + } + return bbBuilder.build(); } - return bbBuilder.build(); } // TODO HONEYCOMB-190 is there a way to check if interconnection is XconnectBased? return null; } - private Optional getBridgeDomainForInterface(final int ifaceId, - final BridgeDomainDetailsReplyDump reply) { - if (null == reply || null == reply.bridgeDomainSwIfDetails || reply.bridgeDomainSwIfDetails.isEmpty()) { + private Optional getBridgeDomainSwIf(final int ifaceId, @Nonnull final BridgeDomainDetails bd) { + if (null == bd.swIfDetails) { return Optional.empty(); } // interface can be added to only one BD only - return reply.bridgeDomainSwIfDetails.stream().filter(a -> a.swIfIndex == ifaceId).findFirst(); + return Arrays.stream(bd.swIfDetails).filter(el -> el.swIfIndex == ifaceId).findFirst(); } private Optional getBridgeDomainForInterface(final BridgeDomainDetailsReplyDump reply, @@ -112,13 +114,13 @@ final class InterconnectionReadUtils implements InterfaceDataTranslator { private BridgeDomainDetailsReplyDump getDumpReply(@Nonnull final InstanceIdentifier id) throws ReadFailedException { // 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?) - // TODO HONEYCOMB-190 cache dump result + // to ask VPP for BD details given interface id/name (TODO HC2VPP-22 add it to vpp.api?) + // TODO HC2VPP-22 cache dump result final BridgeDomainDump request = new BridgeDomainDump(); request.bdId = -1; final CompletableFuture bdCompletableFuture = - futureJVppCore.bridgeDomainSwIfDump(request).toCompletableFuture(); + futureJVppCore.bridgeDomainDump(request).toCompletableFuture(); return getReplyForRead(bdCompletableFuture, id); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java index 587c1132d..21f250e86 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java @@ -18,18 +18,18 @@ package io.fd.hc2vpp.v3po.l2state; import com.google.common.base.Preconditions; import com.google.common.primitives.Longs; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.core.dto.L2FibTableDetails; +import io.fd.vpp.jvpp.core.dto.L2FibTableDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.Collections; import java.util.List; @@ -59,7 +59,7 @@ public final class L2FibEntryCustomizer extends FutureJVppCustomizer private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class); - private static final Collector SINGLE_ITEM_COLLECTOR = + private static final Collector SINGLE_ITEM_COLLECTOR = RWUtils.singleItemCollector(); private final NamingContext bdContext; @@ -84,7 +84,7 @@ public final class L2FibEntryCustomizer extends FutureJVppCustomizer try { // TODO HONEYCOMB-186 use cached l2FibTable - final L2FibTableEntry entry = dumpL2Fibs(id, bdId).stream().filter(e -> key.getPhysAddress() + final L2FibTableDetails entry = dumpL2Fibs(id, bdId).stream().filter(e -> key.getPhysAddress() .equals(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(e.mac), 2)))) .collect(SINGLE_ITEM_COLLECTOR); @@ -105,20 +105,20 @@ public final class L2FibEntryCustomizer extends FutureJVppCustomizer } @Nonnull - private List dumpL2Fibs(final InstanceIdentifier id, final int bdId) + private List dumpL2Fibs(final InstanceIdentifier id, final int bdId) throws ReadFailedException { final L2FibTableDump l2FibRequest = new L2FibTableDump(); l2FibRequest.bdId = bdId; - final CompletableFuture l2FibTableDumpCompletableFuture = + final CompletableFuture l2FibTableDumpCompletableFuture = getFutureJVpp().l2FibTableDump(l2FibRequest).toCompletableFuture(); - final L2FibTableEntryReplyDump dump = getReplyForRead(l2FibTableDumpCompletableFuture, id); + final L2FibTableDetailsReplyDump dump = getReplyForRead(l2FibTableDumpCompletableFuture, id); - if (null == dump || null == dump.l2FibTableEntry) { + if (null == dump || null == dump.l2FibTableDetails) { return Collections.emptyList(); } else { - return dump.l2FibTableEntry; + return dump.l2FibTableDetails; } } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java index 96645551b..1d58efc5e 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java @@ -21,9 +21,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; +import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; +import io.fd.vpp.jvpp.core.types.BridgeDomainSwIf; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -39,11 +44,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.base.attributes.Interconnection; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.base.attributes.interconnection.BridgeBasedBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainSwIfDetails; -import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails; public class L2CustomizerTest extends ReaderCustomizerTest { @@ -73,24 +73,21 @@ public class L2CustomizerTest extends ReaderCustomizerTest { VppInterfaceStateAugmentation.class).child(L2.class); } - private void whenBridgeDomainSwIfDumpThenReturn(final List bdSwIfList, - final List bridgeDomainDetailses) { + private void whenBridgeDomainDumpThenReturn(final List bridgeDomainDetails) { final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); - reply.bridgeDomainSwIfDetails = bdSwIfList; - reply.bridgeDomainDetails = bridgeDomainDetailses; - when(api.bridgeDomainSwIfDump(any(BridgeDomainDump.class))).thenReturn(future(reply)); + reply.bridgeDomainDetails = bridgeDomainDetails; + when(api.bridgeDomainDump(any(BridgeDomainDump.class))).thenReturn(future(reply)); } - private BridgeDomainSwIfDetails generateBdSwIfDetails(final int ifId, final int bdId) { - final BridgeDomainSwIfDetails bdSwIfDetails = new BridgeDomainSwIfDetails(); + private BridgeDomainSwIf generateBdSwIfDetails(final int ifId) { + final BridgeDomainSwIf bdSwIfDetails = new BridgeDomainSwIf(); bdSwIfDetails.swIfIndex = ifId; bdSwIfDetails.shg = 1; - bdSwIfDetails.bdId = bdId; return bdSwIfDetails; } - private Interconnection generateInterconnection(final int ifId, final String bdName, final Boolean bvi) { + private Interconnection generateInterconnection(final String bdName, final Boolean bvi) { final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); bbBuilder.setBridgeDomain(bdName); bbBuilder.setSplitHorizonGroup((short) 1); @@ -118,28 +115,28 @@ public class L2CustomizerTest extends ReaderCustomizerTest { cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); // BVIinterfaceContext - whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)), - Collections.singletonList(generateBdDetails(ifId, bdId))); + whenBridgeDomainDumpThenReturn(Collections.singletonList(generateBdDetails(ifId, ifId, bdId))); L2Builder builder = mock(L2Builder.class); getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); - verify(builder).setInterconnection(generateInterconnection(ifId, bdName, true)); + verify(builder).setInterconnection(generateInterconnection(bdName, true)); // Not BVI - whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)), - Collections.singletonList(generateBdDetails(99 /* Different ifc is marked as BVI in bd details */, bdId))); + whenBridgeDomainDumpThenReturn(Collections + .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); builder = mock(L2Builder.class); getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); - verify(builder).setInterconnection(generateInterconnection(ifId, bdName, null)); + verify(builder).setInterconnection(generateInterconnection(bdName, null)); } - private BridgeDomainDetails generateBdDetails(final int ifId, final int bdId) { + private BridgeDomainDetails generateBdDetails(final int ifId, final int bviSwIfIndex, int bdId) { final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); - bridgeDomainDetails.bviSwIfIndex = ifId; + bridgeDomainDetails.bviSwIfIndex = bviSwIfIndex; bridgeDomainDetails.bdId = bdId; + bridgeDomainDetails.swIfDetails = new BridgeDomainSwIf[] {generateBdSwIfDetails(ifId)}; return bridgeDomainDetails; } } \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java index 1633cab5b..e9031c93f 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java @@ -22,15 +22,18 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.L2FibTableDetails; +import io.fd.vpp.jvpp.core.dto.L2FibTableDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; import java.util.Collections; import java.util.List; 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.rev170315.BridgeDomains; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.BridgeDomainsState; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.L2FibForward; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.bridge.domains.state.BridgeDomain; @@ -41,10 +44,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.fib.attributes.l2.fib.table.L2FibEntryKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest { @@ -78,10 +77,10 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest l2FibTableEntryList) + private void whenL2FibTableDumpThenReturn(final List l2FibTableEntryList) throws ExecutionException, InterruptedException, VppInvocationException { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = l2FibTableEntryList; + final L2FibTableDetailsReplyDump reply = new L2FibTableDetailsReplyDump(); + reply.l2FibTableDetails = l2FibTableEntryList; when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); } @@ -104,8 +103,8 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest entryList) { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = entryList; + private void whenL2FibTableDumpThenReturn(final List entryList) { + final L2FibTableDetailsReplyDump reply = new L2FibTableDetailsReplyDump(); + reply.l2FibTableDetails = entryList; when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); } -- cgit 1.2.3-korg