ReaderCustomizer<BridgeDomainSubtable, BridgeDomainSubtableBuilder>, SubtableReader {
private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainSubtableCustomizer.class);
- private static final String CACHE_KEY = BridgeDomainSubtableCustomizer.class.getName();
- private final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager;
+ private final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams>
+ dumpManager;
private final NamingContext bridgeDomainContext;
public BridgeDomainSubtableCustomizer(@Nonnull final FutureJVppCore futureJvppCore,
@Nonnull final NamingContext bridgeDomainContext) {
super(futureJvppCore);
- dumpManager = new DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, SubtableDumpParams>()
- .withExecutor(createExecutor(futureJvppCore))
- .build();
+ dumpManager =
+ new DumpCacheManagerBuilder<LispEidTableMapDetailsReplyDump, SubtableDumpParams>()
+ .withExecutor(createExecutor(futureJvppCore))
+ .build();
this.bridgeDomainContext = checkNotNull(bridgeDomainContext, "Bridge domain context cannot be null");
}
LOG.debug("Read attributes for id {}", id);
//dumps only L2(bridge domains)
final Optional<LispEidTableMapDetailsReplyDump> reply =
- readSubtable(dumpManager, CACHE_KEY, ctx.getModificationCache(), id, L2_PARAMS);
+ dumpManager.getDump(id, ctx.getModificationCache(), L2_PARAMS);
if (!reply.isPresent() || reply.get().lispEidTableMapDetails.isEmpty()) {
return;
extends FutureJVppCustomizer
implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder>, LocatorReader {
- private static final String KEY_BASE = InterfaceCustomizer.class.getName();
-
private final NamingContext interfaceContext;
private final NamingContext locatorSetContext;
private final DumpCacheManager<LispLocatorDetailsReplyDump, LocatorDumpParams> dumpCacheManager;
new LocatorDumpParamsBuilder().setLocatorSetIndex(locatorSetIndexIndex).build();
final Optional<LispLocatorDetailsReplyDump> reply =
- dumpCacheManager.getDump(id, KEY_BASE, ctx.getModificationCache(), params);
+ dumpCacheManager.getDump(id, ctx.getModificationCache(), params);
if (!reply.isPresent() || reply.get().lispLocatorDetails.isEmpty()) {
return;
.setLocatorSetIndex(locatorSetContext.getIndex(name, context.getMappingContext())).build();
final Optional<LispLocatorDetailsReplyDump> reply =
- dumpCacheManager.getDump(id, KEY_BASE, context.getModificationCache(), params);
+ dumpCacheManager.getDump(id, context.getModificationCache(), params);
if (!reply.isPresent() || reply.get().lispLocatorDetails.isEmpty()) {
return Collections.emptyList();
implements ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder>, ByteDataTranslator,
JvppReplyConsumer {
- private static final String CACHE_KEY = ItrRemoteLocatorSetCustomizer.class.getName();
-
private final DumpCacheManager<LispGetMapRequestItrRlocsReply, Void> dumpCacheManager;
public ItrRemoteLocatorSetCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
throws ReadFailedException {
final Optional<LispGetMapRequestItrRlocsReply> reply =
- dumpCacheManager.getDump(id, CACHE_KEY, ctx.getModificationCache(), NO_PARAMS);
+ dumpCacheManager.getDump(id, ctx.getModificationCache(), NO_PARAMS);
if (!reply.isPresent() || reply.get().locatorSetName == null) {
return;
}
MappingReader {
private static final Logger LOG = LoggerFactory.getLogger(LocalMappingCustomizer.class);
- private static final String KEY = LocalMappingCustomizer.class.getName();
private final DumpCacheManager<LispEidTableDetailsReplyDump, MappingsDumpParams> dumpManager;
private final NamingContext locatorSetContext;
LOG.debug("Dumping data for LocalMappings(id={})", id);
final Optional<LispEidTableDetailsReplyDump> replyOptional =
- dumpManager.getDump(id, bindKey("SPECIFIC_" + localMappingId), ctx.getModificationCache(), dumpParams);
+ dumpManager.getDump(id, ctx.getModificationCache(), dumpParams);
if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) {
return;
LOG.debug("Dumping data for LocalMappings(id={})", id);
final Optional<LispEidTableDetailsReplyDump> replyOptional =
- dumpManager.getDump(id, bindKey("ALL_LOCAL"), context.getModificationCache(), dumpParams);
+ dumpManager.getDump(id, context.getModificationCache(), dumpParams);
if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) {
return Collections.emptyList();
public void merge(Builder<? extends DataObject> builder, List<LocalMapping> readData) {
((LocalMappingsBuilder) builder).setLocalMapping(readData);
}
-
- private static String bindKey(String prefix) {
- return prefix + "_" + KEY;
- }
-
}
implements ListReaderCustomizer<LocatorSet, LocatorSetKey, LocatorSetBuilder>, ByteDataTranslator,
LocatorSetReader {
- private static final String LOCATOR_SETS_CACHE_ID = LocatorSetCustomizer.class.getName();
private static final Logger LOG = LoggerFactory.getLogger(LocatorSetCustomizer.class);
private final DumpCacheManager<LispLocatorSetDetailsReplyDump, Void> dumpManager;
LOG.debug("Reading attributes for Locator Set {}", id);
final Optional<LispLocatorSetDetailsReplyDump> dumpOptional =
- dumpManager.getDump(id, LOCATOR_SETS_CACHE_ID, ctx.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, ctx.getModificationCache(), NO_PARAMS);
if (!dumpOptional.isPresent() || dumpOptional.get().lispLocatorSetDetails.isEmpty()) {
return;
LOG.debug("Dumping Locator Set {}", id);
final Optional<LispLocatorSetDetailsReplyDump> dumpOptional =
- dumpManager.getDump(id, LOCATOR_SETS_CACHE_ID, context.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, context.getModificationCache(), NO_PARAMS);
if (!dumpOptional.isPresent() || dumpOptional.get().lispLocatorSetDetails.isEmpty()) {
return Collections.emptyList();
JvppReplyConsumer {
private static final Logger LOG = LoggerFactory.getLogger(MapResolverCustomizer.class);
- private static final String MAP_RESOLVERS_CACHE_ID = MapResolverCustomizer.class.getName();
private final DumpCacheManager<LispMapResolverDetailsReplyDump, Void> dumpManager;
public MapResolverCustomizer(FutureJVppCore futureJvpp) {
super(futureJvpp);
- this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispMapResolverDetailsReplyDump, Void>()
- .withExecutor((identifier, params) -> getReplyForRead(
- futureJvpp.lispMapResolverDump(new LispMapResolverDump()).toCompletableFuture(), identifier))
- .build();
+ this.dumpManager =
+ new DumpCacheManager.DumpCacheManagerBuilder<LispMapResolverDetailsReplyDump, Void>()
+ .withExecutor((identifier, params) -> getReplyForRead(
+ futureJvpp.lispMapResolverDump(new LispMapResolverDump()).toCompletableFuture(),
+ identifier))
+ .build();
}
@Override
LOG.debug("Reading attributes...");
final Optional<LispMapResolverDetailsReplyDump> dumpOptional =
- dumpManager.getDump(id, MAP_RESOLVERS_CACHE_ID, ctx.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, ctx.getModificationCache(), NO_PARAMS);
if (!dumpOptional.isPresent() || dumpOptional.get().lispMapResolverDetails.isEmpty()) {
LOG.warn("No data dumped");
LOG.debug("Dumping MapResolver...");
final Optional<LispMapResolverDetailsReplyDump> dumpOptional =
- dumpManager.getDump(id, MAP_RESOLVERS_CACHE_ID, context.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, context.getModificationCache(), NO_PARAMS);
if (!dumpOptional.isPresent() || dumpOptional.get().lispMapResolverDetails.isEmpty()) {
return Collections.emptyList();
import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MapReplyAction.NoAction;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
import io.fd.honeycomb.lisp.context.util.EidMappingContext;
import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams;
import io.fd.honeycomb.lisp.translate.read.dump.executor.params.LocatorDumpParams.LocatorDumpParamsBuilder;
import io.fd.honeycomb.lisp.translate.read.trait.LocatorReader;
import io.fd.honeycomb.lisp.translate.read.trait.MappingReader;
import io.fd.honeycomb.lisp.translate.util.EidTranslator;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.honeycomb.translate.vpp.util.AddressTranslator;
import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
+import io.fd.honeycomb.translate.vpp.util.NamingContext;
import io.fd.vpp.jvpp.core.dto.LispEidTableDetails;
import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.LispLocatorDetails;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.LocatorBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.LocatorKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.Interface;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
EidTranslator, AddressTranslator, ByteDataTranslator, MappingReader, LocatorReader {
private static final Logger LOG = LoggerFactory.getLogger(RemoteMappingCustomizer.class);
- private static final String KEY = RemoteMappingCustomizer.class.getName();
private final DumpCacheManager<LispEidTableDetailsReplyDump, MappingsDumpParams> dumpManager;
private final DumpCacheManager<LispLocatorDetailsReplyDump, LocatorDumpParams> locatorsDumpManager;
+ private final NamingContext locatorSetContext;
private final EidMappingContext remoteMappingContext;
- public RemoteMappingCustomizer(@Nonnull FutureJVppCore futureJvpp,
- @Nonnull EidMappingContext remoteMappingContext) {
+ public RemoteMappingCustomizer(@Nonnull final FutureJVppCore futureJvpp,
+ @Nonnull final NamingContext locatorSetContext,
+ @Nonnull final EidMappingContext remoteMappingContext) {
super(futureJvpp);
+ this.locatorSetContext = checkNotNull(locatorSetContext, "Locator sets context not present");
this.remoteMappingContext = checkNotNull(remoteMappingContext, "Remote mappings not present");
+ // this one should have default scope == RemoteMapping
this.dumpManager =
new DumpCacheManager.DumpCacheManagerBuilder<LispEidTableDetailsReplyDump, MappingsDumpParams>()
.withExecutor(createMappingDumpExecutor(futureJvpp))
.build();
+
+ // cache key needs to have locator set scope to not mix with cached data
this.locatorsDumpManager =
new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorDetailsReplyDump, LocatorDumpParams>()
.withExecutor(createLocatorDumpExecutor(futureJvpp))
+ .withCacheKeyFactory(new IdentifierCacheKeyFactory(ImmutableSet.of(LocatorSet.class)))
.build();
}
LOG.debug("Dumping data for LocalMappings(id={})", id);
final Optional<LispEidTableDetailsReplyDump> replyOptional =
- dumpManager.getDump(id, bindKey("SPECIFIC_" + remoteMappingId), ctx.getModificationCache(), dumpParams);
+ dumpManager.getDump(id, ctx.getModificationCache(), dumpParams);
if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) {
return;
builder.setTtl(resolveTtl(details.ttl));
builder.setAuthoritative(
new RemoteMapping.Authoritative(byteToBoolean(details.authoritative)));
- resolverMappings(id, builder, details, ctx.getModificationCache());
+ resolveMappings(id, builder, details, ctx.getModificationCache(), ctx.getMappingContext());
}
//compensate ~0 as default value of ttl
LOG.debug("Dumping data for LocalMappings(id={})", id);
final Optional<LispEidTableDetailsReplyDump> replyOptional =
- dumpManager.getDump(id, bindKey("ALL_REMOTE"), context.getModificationCache(), dumpParams);
+ dumpManager.getDump(id, context.getModificationCache(), dumpParams);
if (!replyOptional.isPresent() || replyOptional.get().lispEidTableDetails.isEmpty()) {
return Collections.emptyList();
((RemoteMappingsBuilder) builder).setRemoteMapping(readData);
}
- private String bindKey(String prefix) {
- return prefix + "_" + KEY;
- }
-
- private void resolverMappings(final InstanceIdentifier id, final RemoteMappingBuilder builder,
- final LispEidTableDetails details,
- final ModificationCache cache) throws ReadFailedException {
+ private void resolveMappings(final InstanceIdentifier id, final RemoteMappingBuilder builder,
+ final LispEidTableDetails details,
+ final ModificationCache cache,
+ final MappingContext mappingContext) throws ReadFailedException {
if (details.action != 0) {
// in this case ,negative action was defined
// cache key needs to have locator set scope to not mix with cached data
final Optional<LispLocatorDetailsReplyDump> reply;
+
+ // this will serve to achieve that locators have locator set scope
+ final InstanceIdentifier<Interface> locatorIfaceIdentifier = InstanceIdentifier.create(LocatorSets.class)
+ .child(LocatorSet.class,
+ new LocatorSetKey(locatorSetContext.getName(details.locatorSetIndex, mappingContext)))
+ .child(Interface.class);
try {
- reply = locatorsDumpManager.getDump(id, KEY + "_locator_set_" + details.locatorSetIndex, cache,
+ reply = locatorsDumpManager.getDump(locatorIfaceIdentifier, cache,
new LocatorDumpParamsBuilder().setLocatorSetIndex(details.locatorSetIndex).build());
} catch (ReadFailedException e) {
throw new ReadFailedException(id,
private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class);
- private static final String LISP_TABLE_ID_DUMP = VniTableCustomizer.class.getName();
private final DumpCacheManager<LispEidTableVniDetailsReplyDump, Void> dumpManager;
public VniTableCustomizer(@Nonnull final FutureJVppCore futureJvpp) {
LOG.trace("Reading all IDS...");
final Optional<LispEidTableVniDetailsReplyDump> optionalReply =
- dumpManager.getDump(id, LISP_TABLE_ID_DUMP, context.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, context.getModificationCache(), NO_PARAMS);
if (!optionalReply.isPresent() || optionalReply.get().lispEidTableVniDetails.isEmpty()) {
return Collections.emptyList();
VniTableKey key = new VniTableKey(id.firstKeyOf(VniTable.class).getVirtualNetworkIdentifier());
final Optional<LispEidTableVniDetailsReplyDump> optionalReply =
- dumpManager.getDump(id, LISP_TABLE_ID_DUMP, ctx.getModificationCache(), NO_PARAMS);
+ dumpManager.getDump(id, ctx.getModificationCache(), NO_PARAMS);
if (!optionalReply.isPresent() || optionalReply.get().lispEidTableVniDetails.isEmpty()) {
return;
implements ReaderCustomizer<VrfSubtable, VrfSubtableBuilder>, SubtableReader {
private static final Logger LOG = LoggerFactory.getLogger(VrfSubtableCustomizer.class);
- private static final String CACHE_KEY = VrfSubtableCustomizer.class.getName();
private final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager;
final int vni = checkNotNull(id.firstKeyOf(VniTable.class), "Cannot find parent VNI Table")
.getVirtualNetworkIdentifier().intValue();
- final Optional<LispEidTableMapDetailsReplyDump> reply =
- readSubtable(dumpManager, CACHE_KEY, ctx.getModificationCache(), id, L3_PARAMS);
+ final Optional<LispEidTableMapDetailsReplyDump> reply = dumpManager.getDump(id, ctx.getModificationCache(), L3_PARAMS);
if (!reply.isPresent() || reply.get().lispEidTableMapDetails.isEmpty()) {
return;
remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class),
remoteMappingSubtreeId.child(MapReply.class)),
new GenericListReader<>(vrfTableRemoteMappingsInstanceIdentifier.child(RemoteMapping.class),
- new RemoteMappingCustomizer(vppApi, remoteMappingContext)));
+ new RemoteMappingCustomizer(vppApi, locatorSetContext, remoteMappingContext)));
registry.subtreeAdd(ImmutableSet.of(remoteMappingSubtreeId
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class),
remoteMappingSubtreeId.child(Rlocs.class),
remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class),
remoteMappingSubtreeId.child(MapReply.class)),
new GenericListReader<>(bridgeDomainRemoteMappingsInstanceIdentifier.child(RemoteMapping.class),
- new RemoteMappingCustomizer(vppApi, remoteMappingContext)));
+ new RemoteMappingCustomizer(vppApi, locatorSetContext, remoteMappingContext)));
registry.addStructuralReader(vrfTableAdjacenciesInstanceIdentifier, AdjacenciesBuilder.class);
registry.addStructuralReader(bridgeDomainAdjacenciesInstanceIdentifier, AdjacenciesBuilder.class);
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
SubtableDumpParams L2_PARAMS = new SubtableDumpParamsBuilder().setL2(L2).build();
SubtableDumpParams L3_PARAMS = new SubtableDumpParamsBuilder().setL2(L3).build();
- default Optional<LispEidTableMapDetailsReplyDump> readSubtable(
- @Nonnull final DumpCacheManager<LispEidTableMapDetailsReplyDump, SubtableDumpParams> dumpManager,
- @Nonnull final String cacheKey,
- @Nonnull final ModificationCache cache,
- @Nonnull final InstanceIdentifier<? extends ChildOf<VniTable>> id,
- @Nonnull final SubtableDumpParams params) throws ReadFailedException {
- return dumpManager.getDump(id, cacheKey, cache, params);
- }
-
default EntityDumpExecutor<LispEidTableMapDetailsReplyDump, SubtableDumpParams> createExecutor(
@Nonnull final FutureJVppCore vppApi) {
return (identifier, params) -> {
LocatorSetReader {
private final NamingContext locatorSetContext;
- private final DumpCacheManager<LispLocatorSetDetailsReplyDump, Void> dumpManager;
public LocatorSetCustomizer(@Nonnull final FutureJVppCore futureJvpp,
@Nonnull final NamingContext locatorSetContext) {
super(futureJvpp);
this.locatorSetContext = checkNotNull(locatorSetContext, "Locator set context cannot be null");
- this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<LispLocatorSetDetailsReplyDump, Void>()
- .withExecutor(createExecutor(futureJvpp))
- .build();
}
@Override
import io.fd.honeycomb.lisp.translate.util.EidTranslator;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.vpp.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
import io.fd.vpp.jvpp.core.dto.LispEidTableDetails;
import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump;
.child(RemoteMappings.class)
.child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")));
mockMappings();
+ defineMapping(mappingContext,"loc-set",1,"loc-set-context");
}
when(eidMappingContext.containsEid(new MappingId("remote-mapping"), mappingContext)).thenReturn(true);
when(eidMappingContext.getEid(new MappingId("remote-mapping"), mappingContext))
.thenReturn(new EidBuilder().setAddress(EID_ADDRESS).build());
+
}
@Test
@Override
protected ReaderCustomizer<RemoteMapping, RemoteMappingBuilder> initCustomizer() {
- return new RemoteMappingCustomizer(api, eidMappingContext);
+ return new RemoteMappingCustomizer(api, new NamingContext("loc-set", "loc-set-context"), eidMappingContext);
}
}
\ No newline at end of file
final Long poolId = id.firstKeyOf(ExternalIpAddressPool.class).getPoolId();
final SnatAddressDetails details =
- dumpMgr.getDump(id, getClass().getName(), ctx.getModificationCache(), null)
+ dumpMgr.getDump(id, ctx.getModificationCache(), null)
.or(new SnatAddressDetailsReplyDump()).snatAddressDetails.get(Math.toIntExact(poolId));
- builder.setExternalIpPool(new Ipv4Prefix(arrayToIpv4AddressNoZoneReversed(details.ipAddress).getValue() + "/32"));
+ builder.setExternalIpPool(
+ new Ipv4Prefix(arrayToIpv4AddressNoZoneReversed(details.ipAddress).getValue() + "/32"));
builder.setPoolId(poolId);
LOG.trace("External IP pool: {}. Read as: {}", id, builder);
// That's why the write and read is not symmetrical in terms of data structure, instead,
// this customizer also returns every single address as a 32 prefix and assigns an artificial key to them
- final long addressCount = dumpMgr.getDump(id, getClass().getName(), ctx.getModificationCache(), null)
+ final long addressCount = dumpMgr.getDump(id, ctx.getModificationCache(), null)
.or(new SnatAddressDetailsReplyDump()).snatAddressDetails.stream()
.count();
private final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager;
private final MappingEntryContext mappingEntryContext;
- MappingEntryCustomizer(final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager,
- final MappingEntryContext mappingEntryContext) {
+ MappingEntryCustomizer(
+ final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager,
+ final MappingEntryContext mappingEntryContext) {
this.dumpCacheManager = dumpCacheManager;
this.mappingEntryContext = mappingEntryContext;
}
final int idx = id.firstKeyOf(MappingEntry.class).getIndex().intValue();
final int natInstanceId = id.firstKeyOf(NatInstance.class).getId().intValue();
final List<SnatStaticMappingDetails> details =
- dumpCacheManager.getDump(id, getClass().getName(), ctx.getModificationCache(), null)
+ dumpCacheManager.getDump(id, ctx.getModificationCache(), null)
.or(new SnatStaticMappingDetailsReplyDump()).snatStaticMappingDetails;
final SnatStaticMappingDetails snatStaticMappingDetails =
mappingEntryContext.findDetails(details, natInstanceId, idx, ctx.getMappingContext());
LOG.trace("Listing IDs for all mapping-entries within nat-instance(vrf):{}", natInstanceId);
final List<MappingEntryKey> entryKeys =
- dumpCacheManager.getDump(id, getClass().getName(), context.getModificationCache(), null)
+ dumpCacheManager.getDump(id, context.getModificationCache(), null)
.or(new SnatStaticMappingDetailsReplyDump()).snatStaticMappingDetails.stream()
.filter(detail -> natInstanceId == detail.vrfId)
.map(detail -> mappingEntryContext
private final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager;
- NatInstanceCustomizer(final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager) {
+ NatInstanceCustomizer(
+ final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> dumpCacheManager) {
this.dumpCacheManager = dumpCacheManager;
}
// Find the nat instance IDs (vrf-ids) by listing all static mappings and their VRF assignment
final List<NatInstanceKey> vrfIds =
- dumpCacheManager.getDump(id, getClass().getName(), context.getModificationCache(), null)
+ dumpCacheManager.getDump(id, context.getModificationCache(), null)
.or(new SnatStaticMappingDetailsReplyDump()).snatStaticMappingDetails.stream()
.map(detail -> detail.vrfId)
- .map(vrfId -> new NatInstanceKey((long)vrfId))
+ .map(vrfId -> new NatInstanceKey((long) vrfId))
.collect(Collectors.toList());
// Add default vrf id if not present
private static final InstanceIdentifier<NatState> NAT_OPER_ID = InstanceIdentifier.create(NatState.class);
private static final InstanceIdentifier<NatInstances> NAT_INSTANCES_ID = NAT_OPER_ID.child(NatInstances.class);
private static final InstanceIdentifier<NatInstance> NAT_INSTANCE_ID = NAT_INSTANCES_ID.child(NatInstance.class);
- private static final InstanceIdentifier<NatCurrentConfig> CURRENT_CONFIG = NAT_INSTANCE_ID.child(NatCurrentConfig.class);
+ private static final InstanceIdentifier<NatCurrentConfig> CURRENT_CONFIG =
+ NAT_INSTANCE_ID.child(NatCurrentConfig.class);
private static final InstanceIdentifier<MappingTable> MAP_TABLE_ID = NAT_INSTANCE_ID.child(MappingTable.class);
private static final InstanceIdentifier<MappingEntry> MAP_ENTRY_ID = MAP_TABLE_ID.child(MappingEntry.class);
private final DumpCacheManager<SnatStaticMappingDetailsReplyDump, Void> mapEntryDumpMgr;
private final DumpCacheManager<SnatAddressDetailsReplyDump, Void> addressRangeDumpMgr;
+
@Inject
public NatReaderFactory(final FutureJVppSnatFacade jvppSnat,
final MappingEntryContext mappingEntryContext) {
this.mappingEntryContext = mappingEntryContext;
- this.mapEntryDumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<SnatStaticMappingDetailsReplyDump, Void>()
- .withExecutor(new MappingEntryCustomizer.MappingEntryDumpExecutor(jvppSnat))
- .build();
- this.addressRangeDumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<SnatAddressDetailsReplyDump, Void>()
- .withExecutor(new ExternalIpPoolCustomizer.AddressRangeDumpExecutor(jvppSnat))
- .build();
+ this.mapEntryDumpMgr =
+ new DumpCacheManager.DumpCacheManagerBuilder<SnatStaticMappingDetailsReplyDump, Void>()
+ .withExecutor(new MappingEntryCustomizer.MappingEntryDumpExecutor(jvppSnat))
+ .build();
+
+ this.addressRangeDumpMgr =
+ new DumpCacheManager.DumpCacheManagerBuilder<SnatAddressDetailsReplyDump, Void>()
+ .withExecutor(new ExternalIpPoolCustomizer.AddressRangeDumpExecutor(jvppSnat))
+ .build();
}
@Override
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
import com.google.common.base.Preconditions;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceCustomizer;
import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
@Nonnull final NamingContext interfaceContext) {
super(futureJVppCore);
this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
- this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
- .withExecutor(createExecutor(futureJVppCore))
- .build();
+ this.dumpManager =
+ new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
+ .withExecutor(createExecutor(futureJVppCore))
+ // Key needs to contain interface ID to distinguish dumps between interfaces
+ .withCacheKeyFactory(new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class)))
+ .build();
}
@Override
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- // Key needs to contain interface ID to distinguish dumps between interfaces
- final String cacheKey = CACHE_KEY + interfaceName;
- final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, cacheKey, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
+ final Optional<IpAddressDetailsReplyDump> dumpOptional =
+ dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) {
return;
final String interfaceName = id.firstKeyOf(Interface.class).getName();
final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
- // Key needs to contain interface ID to distinguish dumps between interfaces
- final String cacheKey = CACHE_KEY + interfaceName;
- final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, cacheKey, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
+ final Optional<IpAddressDetailsReplyDump> dumpOptional =
+ dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder>, Ipv4Reader {
private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class);
- private static final String CACHE_KEY = SubInterfaceIpv4AddressCustomizer.class.getName();
private final NamingContext interfaceContext;
private final DumpCacheManager<IpAddressDetailsReplyDump, AddressDumpParams> dumpManager;
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
final Optional<IpAddressDetails> ipAddressDetails =
findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
final String subInterfaceName = getSubInterfaceName(id);
final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext());
final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
- .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
+ .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false));
return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
}
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
import io.fd.honeycomb.translate.vpp.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
private NamingContext interfacesContext;
private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier;
private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier;
+ private CacheKeyFactory cacheKeyFactory;
public Ipv4AddressCustomizerTest() {
super(Address.class, Ipv4Builder.class);
.augmentation(Interface2.class)
.child(Ipv4.class)
.child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1")));
+
+ // to simulate complex key
+ cacheKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(Interface.class));
}
@Override
ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detailIfaceTwoAddressOne.prefixLength = 23;
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne);
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, replyIfaceTwo);
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo);
}
private void fillCacheForFirstIfaceSecondEmpty() {
ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detailIfaceOneAddressOne.prefixLength = 22;
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, replyIfaceOne);
- cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_2_NAME, new IpAddressDetailsReplyDump());
+ cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne);
+ cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump());
}
}
import com.google.common.base.Optional;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory;
import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
import io.fd.honeycomb.translate.util.read.cache.EntityDumpPostProcessingFunction;
+import io.fd.honeycomb.translate.util.read.cache.IdentifierCacheKeyFactory;
import io.fd.vpp.jvpp.core.dto.IpDetails;
import io.fd.vpp.jvpp.core.dto.IpDetailsReplyDump;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class DumpCacheManagerTest {
- private static final String KEY = "cacheKey";
+ private interface DataObj extends DataObject {}
@Mock
private EntityDumpExecutor<IpDetailsReplyDump, Void> executor;
- @Mock
- private InstanceIdentifier identifier;
+ private InstanceIdentifier<DataObj> identifier;
private DumpCacheManager<IpDetailsReplyDump, Void> managerPositive;
private DumpCacheManager<IpDetailsReplyDump, Void> managerPositiveWithPostProcessing;
private DumpCacheManager<IpDetailsReplyDump, Void> managerNegative;
private ModificationCache cache;
+ private CacheKeyFactory cacheKeyFactory;
@Before
public void init() {
.withExecutor(executor)
.build();
- managerPositiveWithPostProcessing = new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
- .withExecutor(executor)
- .withPostProcessingFunction(createPostProcessor())
- .build();
+ managerPositiveWithPostProcessing =
+ new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
+ .withExecutor(executor)
+ .withPostProcessingFunction(createPostProcessor())
+ .build();
managerNegative =
new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
.build();
cache = new ModificationCache();
+ identifier = InstanceIdentifier.create(DataObj.class);
+ //manager uses this implementation by default, so it can be used to test behaviour
+ cacheKeyFactory = new IdentifierCacheKeyFactory();
+
}
/**
@Test
public void testCaching() throws ReadFailedException {
final IpDetailsReplyDump stage1Data = new IpDetailsReplyDump();
+ final String key = cacheKeyFactory.createKey(identifier);
+
// executor cant return null data
when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(new IpDetailsReplyDump());
- final Optional<IpDetailsReplyDump> stage1Optional = managerNegative.getDump(identifier, KEY, cache, NO_PARAMS);
+ final Optional<IpDetailsReplyDump> stage1Optional = managerNegative.getDump(identifier, cache, NO_PARAMS);
// this is first call so instance should be from executor
// and it should be cached after calling executor
assertEquals(true, stage1Optional.isPresent());
assertEquals(stage1Data, stage1Optional.get());
- assertEquals(true, cache.containsKey(KEY));
- assertEquals(stage1Data, cache.get(KEY));
+ assertEquals(true, cache.containsKey(key));
+ assertEquals(stage1Data, cache.get(key));
//rebind executor with other data
IpDetailsReplyDump stage2LoadedDump = new IpDetailsReplyDump();
when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(stage2LoadedDump);
- final Optional<IpDetailsReplyDump> stage2Optional = managerPositive.getDump(identifier, KEY, cache, NO_PARAMS);
+ final Optional<IpDetailsReplyDump> stage2Optional = managerPositive.getDump(identifier, cache, NO_PARAMS);
assertEquals(true, stage2Optional.isPresent());
assertEquals(stage2LoadedDump, stage2Optional.get());
IpDetailsReplyDump stage3LoadedDump = new IpDetailsReplyDump();
when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(stage3LoadedDump);
- final Optional<IpDetailsReplyDump> stage3Optional = managerPositive.getDump(identifier, KEY, cache, NO_PARAMS);
+ final Optional<IpDetailsReplyDump> stage3Optional = managerPositive.getDump(identifier, cache, NO_PARAMS);
assertEquals(true, stage3Optional.isPresent());
//check if it returns instance cached from previous stage
assertEquals(stage2LoadedDump, stage3Optional.get());
when(executor.executeDump(identifier, null)).thenReturn(dump);
Optional<IpDetailsReplyDump> optionalDump =
- managerPositiveWithPostProcessing.getDump(identifier, KEY, cache, NO_PARAMS);
+ managerPositiveWithPostProcessing.getDump(identifier, cache, NO_PARAMS);
assertEquals(true, optionalDump.isPresent());
assertEquals(1, optionalDump.get().ipDetails.size());