- final TablesKey tableKey = table.getKey();
- final KeyedInstanceIdentifier<Tables, TablesKey> tablePath
- = this.effRibTables.child(Tables.class, tableKey);
-
- // Create an empty table
- LOG.trace("Create Empty table", tablePath);
- tx.put(LogicalDatastoreType.OPERATIONAL, tablePath, new TablesBuilder()
- .setAfi(tableKey.getAfi()).setSafi(tableKey.getSafi())
- .setAttributes(table.getAttributes()).build());
-
- final RIBSupport ribSupport = this.registry.getRIBSupport(tableKey);
- final Routes routes = table.getRoutes();
- if (routes == null) {
+ this.rtMembershipsUpdated = true;
+ }
+
+ final TablesKey tablesKey = ribSupport.getTablesKey();
+ CountersUtil.add(prefixesInstalled.get(tablesKey), tablesKey, -deletedRoutes.size());
+ }
+
+ private void processRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?, ?, ?> ribSupport,
+ final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route, final boolean longLivedStale) {
+ LOG.debug("Process route {}", route.getIdentifier());
+ final YangInstanceIdentifier routePath = ribSupport.routePath(routesPath, route.getIdentifier());
+ switch (route.getModificationType()) {
+ case DELETE:
+ case DISAPPEARED:
+ deleteRoute(tx, ribSupport, routePath, route.getDataBefore().orElse(null));
+ break;
+ case UNMODIFIED:
+ // No-op
+ break;
+ case APPEARED:
+ case SUBTREE_MODIFIED:
+ case WRITE:
+ writeRoute(tx, ribSupport, routePath, route.getDataBefore(), route.getDataAfter().get(),
+ longLivedStale);
+ break;
+ default:
+ LOG.warn("Ignoring unhandled route {}", route);
+ break;
+ }
+ }
+
+ private void deleteRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?, ?, ?> ribSupport,
+ final YangInstanceIdentifier routeIdPath, final NormalizedNode<?, ?> route) {
+ handleRouteTarget(ModificationType.DELETE, ribSupport, routeIdPath, route);
+ tx.delete(LogicalDatastoreType.OPERATIONAL, routeIdPath);
+ LOG.debug("Route deleted. routeId={}", routeIdPath);
+ final TablesKey tablesKey = ribSupport.getTablesKey();
+ CountersUtil.decrement(this.prefixesInstalled.get(tablesKey), tablesKey);
+ }
+
+ private void writeRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?, ?, ?> ribSupport,
+ final YangInstanceIdentifier routePath, final Optional<NormalizedNode<?, ?>> routeBefore,
+ final NormalizedNode<?, ?> routeAfter, final boolean longLivedStale) {
+ final TablesKey tablesKey = ribSupport.getTablesKey();
+ CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
+ // Lookup per-table attributes from RIBSupport
+ final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(routeAfter,
+ ribSupport.routeAttributesIdentifier()).orElse(null);
+ final Attributes routeAttrs = ribSupport.attributeFromContainerNode(advertisedAttrs);
+ final Optional<Attributes> optEffAtt;
+ // In case we want to add LLGR_STALE we do not process route through policies since it may be
+ // considered as received with LLGR_STALE from peer which is not true.
+ if (longLivedStale) {
+ // LLGR procedures are in effect. If the route is tagged with NO_LLGR, it needs to be removed.
+ final List<Communities> effCommunities = routeAttrs.getCommunities();
+ if (effCommunities != null && effCommunities.contains(CommunityUtil.NO_LLGR)) {
+ deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));