From 27c59c4083cb300f528d63b3e3924c348dd090e0 Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Fri, 31 May 2019 11:18:36 +0200 Subject: HC2VPP-391: Fix read of oper interface state Several interface types that have different name in vpp than in the model didn't load their operational state. Since vpp supports listing interface by its index too, this fix changes the dump interface by name to dump by index. Change-Id: I6c2500d2caddad58b52aaee00ed2bff0fbd9f401 Signed-off-by: Michal Cmarada --- .../read/cache/InterfaceCacheDumpManagerImpl.java | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java index 0aee8e459..99a7a94ee 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java @@ -16,11 +16,11 @@ package io.fd.hc2vpp.v3po.read.cache; -import static io.fd.hc2vpp.common.translate.util.JvppReplyConsumer.INSTANCE; import static java.util.stream.Collectors.toMap; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.InterfaceDataTranslator; import io.fd.honeycomb.translate.ModificationCache; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -44,14 +44,14 @@ import org.slf4j.LoggerFactory; /** * Manager for dump data of interfaces/sub-interfaces */ -final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { +final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager, InterfaceDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(InterfaceCacheDumpManagerImpl.class); // byNameIndex must be cached, not held as reference here, to have it destroyed with cache after transaction static final String BY_NAME_INDEX_KEY = InterfaceCacheDumpManagerImpl.class.getName() + "_byNameIndex"; private NamingContext namingContext; - private final DumpCacheManager specificDumpManager; + private final DumpCacheManager specificDumpManager; private final DumpCacheManager fullDumpManager; InterfaceCacheDumpManagerImpl(@Nonnull final FutureJVppCore jvpp, @@ -59,7 +59,8 @@ final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { this.namingContext = namingContext; specificDumpManager = specificInterfaceDumpManager(jvpp); fullDumpManager = fullInterfaceDumpManager(jvpp, - new StaticCacheKeyFactory(InterfaceCacheDumpManagerImpl.class.getName() + "_dump", SwInterfaceDetailsReplyDump.class)); + new StaticCacheKeyFactory(InterfaceCacheDumpManagerImpl.class.getName() + "_dump", + SwInterfaceDetailsReplyDump.class)); } @Override @@ -95,8 +96,9 @@ final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { throws ReadFailedException { LOG.debug("Interface {} not present in cached data, performing specific dump[{}]", interfaceName, identifier); + int index = namingContext.getIndex(interfaceName, ctx.getMappingContext()); final SwInterfaceDetailsReplyDump reply = - specificDumpManager.getDump(identifier, ctx.getModificationCache(), interfaceName) + specificDumpManager.getDump(identifier, ctx.getModificationCache(), index) .orElse(new SwInterfaceDetailsReplyDump()); if (reply.swInterfaceDetails.isEmpty()) { @@ -162,9 +164,9 @@ final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { .build(); } - private static DumpCacheManager specificInterfaceDumpManager( + private static DumpCacheManager specificInterfaceDumpManager( final FutureJVppCore jvpp) { - return new DumpCacheManager.DumpCacheManagerBuilder() + return new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor(specificInterfaceDumpExecutor(jvpp)) .acceptOnly(SwInterfaceDetailsReplyDump.class) .build(); @@ -185,14 +187,14 @@ final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { }; } - private static EntityDumpExecutor specificInterfaceDumpExecutor( + private static EntityDumpExecutor specificInterfaceDumpExecutor( final FutureJVppCore api) { - return (identifier, ifaceName) -> { + return (identifier, swIfIndex) -> { final SwInterfaceDump request = new SwInterfaceDump(); request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex =~0; - request.nameFilter = ifaceName.getBytes(); - request.nameFilterValid = 1; + request.swIfIndex.interfaceindex = swIfIndex; + request.nameFilter = "".getBytes(); + request.nameFilterValid = 0; final CompletableFuture swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture(); -- cgit 1.2.3-korg