- private <R extends Route> void deleteRoutes(final InstanceIdentifier<R> routeIID,
- final R route, final WriteTransaction tx) {
- deleteRT(route);
- tx.delete(LogicalDatastoreType.OPERATIONAL, routeIID);
- }
-
- private <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
- R extends Route & ChildOf<? super S> & Identifiable<I>, I extends Identifier<R>> void writeTable(
- final WriteTransaction tx, final DataObjectModification<Tables> table) {
-
- final Tables newTable = table.getDataAfter();
- if (newTable == null) {
- final Tables oldTable = table.getDataBefore();
- if (oldTable != null) {
- final TablesKey tableKey = oldTable.key();
- final KeyedInstanceIdentifier<Tables, TablesKey> tablePath = tablePath(tableKey);
- LOG.trace("Delete table at {}", tablePath);
- tx.delete(LogicalDatastoreType.OPERATIONAL, tablePath);
-
- final RIBSupport<C, S, R, I> ribSupport = this.registry.getRIBSupport(tableKey);
- if (ribSupport != null) {
- final Routes oldRoutes = oldTable.getRoutes();
- if (oldRoutes != null) {
- for (R route : ribSupport.extractAdjRibInRoutes(oldRoutes)) {
- deleteRT(route);
- }
- }
- }
- }
- return;
- }
-
- final TablesKey tableKey = newTable.key();
- final KeyedInstanceIdentifier<Tables, TablesKey> tablePath = tablePath(tableKey);
-
- // Create an empty table
- LOG.trace("Create Empty table at {}", tablePath);
- tx.put(LogicalDatastoreType.OPERATIONAL, tablePath, new TablesBuilder()
- .withKey(tableKey).setAfi(tableKey.getAfi()).setSafi(tableKey.getSafi())
- .setAttributes(newTable.getAttributes()).build());
-
- final RIBSupport<C, S, R, I> ribSupport = this.registry.getRIBSupport(tableKey);
- if (ribSupport == null) {
- LOG.trace("No RIB support for {}", tableKey);
- return;
- }
-
- writeTableRoutes(tx, tableKey, ribSupport, tablePath, newTable);
- }
-
- private <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>,
- R extends Route & ChildOf<? super S> & Identifiable<I>, I extends Identifier<R>> void writeTableRoutes(
- final WriteTransaction tx, final TablesKey tableKey, final RIBSupport<C, S, R, I> ribSupport,
- final KeyedInstanceIdentifier<Tables, TablesKey> tablePath, final Tables newTable) {
- final Routes routes = newTable.getRoutes();
- if (routes != null) {
- final Class<? extends AfiSafiType> afiSafiType = tableTypeRegistry.getAfiSafiType(ribSupport.getTablesKey())
- .get();
- for (R route : ribSupport.extractAdjRibInRoutes(routes)) {
- writeRoutes(tx, tableKey, afiSafiType, ribSupport, tablePath, route.key(), route, false);
- }
- }
- }
-
- private KeyedInstanceIdentifier<Tables, TablesKey> tablePath(TablesKey tableKey) {
- return this.effRibTables.child(Tables.class, tableKey);