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;
/**
* 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<SwInterfaceDetailsReplyDump, String> specificDumpManager;
+ private final DumpCacheManager<SwInterfaceDetailsReplyDump, Integer> specificDumpManager;
private final DumpCacheManager<SwInterfaceDetailsReplyDump, Void> fullDumpManager;
InterfaceCacheDumpManagerImpl(@Nonnull final FutureJVppCore jvpp,
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
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()) {
.build();
}
- private static DumpCacheManager<SwInterfaceDetailsReplyDump, String> specificInterfaceDumpManager(
+ private static DumpCacheManager<SwInterfaceDetailsReplyDump, Integer> specificInterfaceDumpManager(
final FutureJVppCore jvpp) {
- return new DumpCacheManager.DumpCacheManagerBuilder<SwInterfaceDetailsReplyDump, String>()
+ return new DumpCacheManager.DumpCacheManagerBuilder<SwInterfaceDetailsReplyDump, Integer>()
.withExecutor(specificInterfaceDumpExecutor(jvpp))
.acceptOnly(SwInterfaceDetailsReplyDump.class)
.build();
};
}
- private static EntityDumpExecutor<SwInterfaceDetailsReplyDump, String> specificInterfaceDumpExecutor(
+ private static EntityDumpExecutor<SwInterfaceDetailsReplyDump, Integer> 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<SwInterfaceDetailsReplyDump>
swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture();
// this one is not in full dump
when(jvpp.swInterfaceDump(specificRequest(IFACE_3))).thenReturn(future(specificReplyThree()));
+ when(jvpp.swInterfaceDump(specificRequest(3))).thenReturn(future(specificReplyThree()));
defineMapping(mappingContext, IFACE_0, 0, "interface-context");
defineMapping(mappingContext, IFACE_1, 1, "interface-context");
defineMapping(mappingContext, IFACE_2, 2, "interface-context");
final SwInterfaceDetails specificDetail = manager.getInterfaceDetail(identifierThree, ctx, IFACE_3);
assertEquals(detailThree(), specificDetail);
- verify(jvpp, times(1)).swInterfaceDump(specificRequest(IFACE_3));
+ verify(jvpp, times(1)).swInterfaceDump(specificRequest(3));
}
private SwInterfaceDetailsReplyDump fullReply() {
specificRequest.nameFilter = ifaceName.getBytes();
return specificRequest;
}
+ private static SwInterfaceDump specificRequest(final int swIfIndex) {
+ final SwInterfaceDump specificRequest = new SwInterfaceDump();
+ specificRequest.swIfIndex = new InterfaceIndex();
+ specificRequest.swIfIndex.interfaceindex = swIfIndex;
+ specificRequest.nameFilterValid = 0;
+ specificRequest.nameFilter = "".getBytes();
+ return specificRequest;
+ }
private static SwInterfaceDump fullRequest() {
final SwInterfaceDump fullRequest = new SwInterfaceDump();