- public long getPrefixedInstalledCount(@Nonnull final TablesKey tablesKey) {
- return this.adjInTracker.getPrefixedInstalledCount(tablesKey);
- }
-
- @Override
- public long getTotalPrefixesInstalled() {
- return this.adjInTracker.getTotalPrefixesInstalled();
- }
-
- private static final class AdjInTracker implements PrefixesReceivedCounters, PrefixesInstalledCounters,
- AutoCloseable, ClusteredDataTreeChangeListener<Tables> {
- private final RIBSupportContextRegistry registry;
- private final KeyedInstanceIdentifier<Peer, PeerKey> peerIId;
- private final InstanceIdentifier<EffectiveRibIn> effRibTables;
- private final ListenerRegistration<?> reg;
- private final BindingTransactionChain chain;
- private final Map<TablesKey, LongAdder> prefixesReceived;
- private final Map<TablesKey, LongAdder> prefixesInstalled;
- private final BGPRibRoutingPolicy ribPolicies;
- private final BGPRouteEntryImportParameters peerImportParameters;
-
- @SuppressWarnings("unchecked")
- AdjInTracker(final BGPRouteEntryImportParameters peer, final RIB rib,
- final BindingTransactionChain chain,
- final KeyedInstanceIdentifier<Peer, PeerKey> peerIId,
- @Nonnull final Set<TablesKey> tables) {
- this.registry = requireNonNull(rib.getRibSupportContext());
- this.chain = requireNonNull(chain);
- this.peerIId = requireNonNull(peerIId);
- this.effRibTables = this.peerIId.child(EffectiveRibIn.class);
- this.prefixesInstalled = buildPrefixesTables(tables);
- this.prefixesReceived = buildPrefixesTables(tables);
- this.ribPolicies = requireNonNull(rib.getRibPolicies());
- this.peerImportParameters = peer;
- final DataTreeIdentifier treeId = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
- this.peerIId.child(AdjRibIn.class).child(Tables.class));
- LOG.debug("Registered Effective RIB on {}", this.peerIId);
- this.reg = requireNonNull(rib.getDataBroker()).registerDataTreeChangeListener(treeId, this);
- }
-
- private Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
- final ImmutableMap.Builder<TablesKey, LongAdder> b = ImmutableMap.builder();
- tables.forEach(table -> b.put(table, new LongAdder()));
- return b.build();
- }
+ @SuppressWarnings("unchecked")
+ public synchronized void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<Tables>> changes) {
+ LOG.trace("Data changed called to effective RIB. Change : {}", changes);
+ WriteTransaction tx = null;
+ for (final DataTreeModification<Tables> tc : changes) {
+ final DataObjectModification<Tables> table = tc.getRootNode();
+ if (tx == null) {
+ tx = this.chain.newWriteOnlyTransaction();
+ }
+ final DataObjectModification.ModificationType modificationType = table.getModificationType();
+ switch (modificationType) {
+ case DELETE:
+ final Tables removeTable = table.getDataBefore();
+ final TablesKey tableKey = removeTable.getKey();
+ final KeyedInstanceIdentifier<Tables, TablesKey> effectiveTablePath
+ = this.effRibTables.child(Tables.class, tableKey);
+ LOG.debug("Delete Effective Table {} modification type {}, "
+ , effectiveTablePath, modificationType);
+ tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath);
+ CountersUtil.decrement(this.prefixesInstalled.get(tableKey), tableKey);
+ break;
+ case SUBTREE_MODIFIED:
+ final Tables before = table.getDataBefore();
+ final Tables after = table.getDataAfter();
+ final TablesKey tk = after.getKey();
+ LOG.debug("Process table {} type {}, dataAfter {}, dataBefore {}",
+ tk, modificationType, after, before);