diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-08-16 08:09:19 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-08-16 08:09:19 +0200 |
commit | 3a7a67fe142749eb6b41f660d101f3fdffb8b3de (patch) | |
tree | 2e565e89ae1b0c39b7e328a5e5dab12a323585ce /v3po/v3po2vpp | |
parent | c14b1fd0cee29fc2cd9d1ff395bdf2209f79bd48 (diff) |
HC2VPP-22 - Interconnetion improvements
Change-Id: I0abb937df505663ecbae47f4c4a75681b3ff75be
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java | 34 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java | 20 |
2 files changed, 35 insertions, 19 deletions
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 a25531303..4209f2a11 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 @@ -17,12 +17,14 @@ package io.fd.hc2vpp.v3po.interfacesstate; import static com.google.common.base.Preconditions.checkState; +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; import static java.util.Objects.requireNonNull; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; @@ -47,19 +49,30 @@ final class InterconnectionReadUtils implements InterfaceDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(InterconnectionReadUtils.class); - private final FutureJVppCore futureJVppCore; private final NamingContext interfaceContext; private final NamingContext bridgeDomainContext; private final InterfaceCacheDumpManager dumpManager; + private final DumpCacheManager<BridgeDomainDetailsReplyDump,Void> bdDumpManager; InterconnectionReadUtils(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext, @Nonnull final NamingContext bridgeDomainContext, @Nonnull final InterfaceCacheDumpManager dumpManager) { - this.futureJVppCore = requireNonNull(futureJVppCore, "futureJVppCore should not be null"); + requireNonNull(futureJVppCore, "futureJVppCore should not be null"); this.interfaceContext = requireNonNull(interfaceContext, "interfaceContext should not be null"); this.bridgeDomainContext = requireNonNull(bridgeDomainContext, "bridgeDomainContext should not be null"); this.dumpManager = requireNonNull(dumpManager, "dumpManager should not be null"); + this.bdDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<BridgeDomainDetailsReplyDump, Void>() + .acceptOnly(BridgeDomainDetailsReplyDump.class) + .withExecutor((id, params) -> { + final BridgeDomainDump request = new BridgeDomainDump(); + request.bdId = -1; + + final CompletableFuture<BridgeDomainDetailsReplyDump> bdCompletableFuture = + futureJVppCore.bridgeDomainDump(request).toCompletableFuture(); + return getReplyForRead(bdCompletableFuture, id); + }) + .build(); } @Nullable @@ -71,7 +84,8 @@ final class InterconnectionReadUtils implements InterfaceDataTranslator { final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, ifaceName); LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); - final BridgeDomainDetailsReplyDump dumpReply = getDumpReply(id); + final BridgeDomainDetailsReplyDump dumpReply = bdDumpManager.getDump(id, ctx.getModificationCache(), NO_PARAMS) + .or(new BridgeDomainDetailsReplyDump()); for (final BridgeDomainDetails bd : dumpReply.bridgeDomainDetails) { final Optional<BridgeDomainSwIf> bdIfAssignment = getBridgeDomainSwIf(ifaceId, bd); if (bdIfAssignment.isPresent()) { @@ -113,18 +127,4 @@ final class InterconnectionReadUtils implements InterfaceDataTranslator { int bdId) { return reply.bridgeDomainDetails.stream().filter(a -> a.bdId == bdId).findFirst(); } - - 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 HC2VPP-22 add it to vpp.api?) - // TODO HC2VPP-22 cache dump result - final BridgeDomainDump request = new BridgeDomainDump(); - request.bdId = -1; - - final CompletableFuture<BridgeDomainDetailsReplyDump> bdCompletableFuture = - futureJVppCore.bridgeDomainDump(request).toCompletableFuture(); - return getReplyForRead(bdCompletableFuture, id); - - } } 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 53934ff80..f3640769b 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 @@ -105,7 +105,7 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { } @Test - public void testRead() throws Exception { + public void testReadBvi() throws Exception { final int ifId = 1; final int bdId = 1; final String bdName = "bd001"; @@ -123,12 +123,28 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> { getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); verify(builder).setInterconnection(generateInterconnection(bdName, true)); + } + + // split to separate test to avoid using cached value from previous run(cannot mock cache) + @Test + public void testReadNoBvi() throws Exception { + final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>(); + final int ifId = 1; + final int bdId = 1; + final String bdName = "bd001"; + final String ifName = "eth0.sub0"; + defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = ifId; + cachedInterfaceDump.put(ifId, ifaceDetails); // Not BVI whenBridgeDomainDumpThenReturn(Collections .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); - builder = mock(L2Builder.class); + L2Builder builder = mock(L2Builder.class); getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); verify(builder).setInterconnection(generateInterconnection(bdName, null)); |