Bug-3714: Generalize RIBSupport 58/22858/5
authorMilos Fabian <milfabia@cisco.com>
Thu, 18 Jun 2015 07:38:57 +0000 (09:38 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 26 Jun 2015 11:49:13 +0000 (11:49 +0000)
Changed instance idetifier for writing/deleting routes operations in RIBSupport.
Now identifier has to point to table's routes choice data node.
The change allows to properly use write/delete routes DOM operations out of "rib-api" module namespace.

Change-Id: I4b877683fdb5232179da05eab78120187a2fcf4f
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecRIBSupport.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupport.java
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractIPRIBSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupport.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java

index 5539db68b41583545c9468b2275e7e76aef226a4..444a033d4566025e1953a25422f3338ed3e19220 100644 (file)
@@ -134,14 +134,14 @@ final class FlowspecRIBSupport extends AbstractRIBSupport {
         return this.destination;
     }
 
-    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath,
         final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
         if (destination != null) {
             final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(this.nlriRoutesList);
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = tablePath.node(ROUTES).node(routesContainerIdentifier()).node(this.route);
+                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route);
                     for (final UnkeyedListEntryNode e : ((UnkeyedListNode)routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, ROUTE_KEY, FSNlriParser.stringNlri(e));
                         function.apply(tx, base, routeKey,  e, attributes);
@@ -155,14 +155,14 @@ final class FlowspecRIBSupport extends AbstractRIBSupport {
 
     @Override
     protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-        final ContainerNode destination) {
-        processDestination(tx, tablePath, destination, null, DELETE_ROUTE);
+        final ContainerNode destination, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
     }
 
     @Override
     protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-        final ContainerNode destination, final ContainerNode attributes) {
-        processDestination(tx, tablePath, destination, attributes, this.putRoute);
+        final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
     }
 
     @Override
index b40dee5d5b08ccdc21dcabb7bb290f8f0753cc52..a92473de1d73860063bc506013db2ab1f948dae1 100644 (file)
@@ -129,18 +129,18 @@ final class LinkstateRIBSupport extends AbstractRIBSupport {
 
     @Override
     protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-        final ContainerNode destination) {
-        processDestination(tx, tablePath, destination, null, DELETE_ROUTE);
+        final ContainerNode destination, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
     }
 
-    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath,
         final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
         if (destination != null) {
             final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(this.nlriRoutesList);
             if (maybeRoutes.isPresent()) {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof UnkeyedListNode) {
-                    final YangInstanceIdentifier base = tablePath.node(ROUTES).node(routesContainerIdentifier()).node(this.route);
+                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route);
                     for (final UnkeyedListEntryNode e : ((UnkeyedListNode)routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                         function.apply(tx, base, routeKey,  e, attributes);
@@ -154,8 +154,8 @@ final class LinkstateRIBSupport extends AbstractRIBSupport {
 
     @Override
     protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-        final ContainerNode destination, final ContainerNode attributes) {
-        processDestination(tx, tablePath, destination, attributes, this.putRoute);
+        final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
     }
 
     private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode linkstate) {
index 04f8abec8d2739fbfe2cebbdc665f2fa3723c314..bf0b4102d7ee588014edda3d6ea61205fe990c56 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.linkstate;
 
 import static org.junit.Assert.assertEquals;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
@@ -58,6 +59,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUn
 public class LinkstateRIBSupportTest {
 
     private static final Ipv4Address ipv4 = new Ipv4Address("42.42.42.42");
+    private static final NodeIdentifier ROUTES_NODE_ID = new NodeIdentifier(Routes.QNAME);
     final LinkstateRIBSupport link = LinkstateRIBSupport.getInstance();
     final List<MapEntryNode> linkList = new ArrayList<>();
     private List<YangInstanceIdentifier> routes;
@@ -82,7 +84,7 @@ public class LinkstateRIBSupportTest {
             @Override
             public Object answer(final InvocationOnMock invocation) throws Throwable {
                 final Object[] args = invocation.getArguments();
-                LinkstateRIBSupportTest.this.routes.remove((YangInstanceIdentifier) args[1]);
+                LinkstateRIBSupportTest.this.routes.remove(args[1]);
                 return args[1];
             }
         }).when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class));
@@ -91,7 +93,7 @@ public class LinkstateRIBSupportTest {
     @Test
     public void testbuildReach() throws BGPParsingException {
         final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(ipv4).build()).build();
-        MpReachNlri result = link.buildReach(linkList, hop);
+        final MpReachNlri result = link.buildReach(linkList, hop);
         assertEquals(LinkstateAddressFamily.class, result.getAfi());
         assertEquals(LinkstateSubsequentAddressFamily.class, result.getSafi());
         assertEquals(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build(), result.getCNextHop());
@@ -173,11 +175,11 @@ public class LinkstateRIBSupportTest {
             .withNodeIdentifier(new NodeIdentifier(Attributes.QNAME))
             .build();
 
-        link.putDestinationRoutes(tx, yangIdentifier, destination, attributes);
+        link.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID);
 
         Assert.assertEquals(1, this.routes.size());
 
-        link.deleteDestinationRoutes(tx, yangIdentifier, destination);
+        link.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID);
 
         Assert.assertEquals(0, this.routes.size());
     }
index 7027714ef4baefd99361a38b03bea7faf294797e..e8c6f8a8224aa054c2288d5026646841023f4f83 100644 (file)
@@ -73,7 +73,6 @@ abstract class AbstractIPRIBSupport extends AbstractRIBSupport {
     }
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractIPRIBSupport.class);
-    private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
     private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
     private final ApplyRoute putRoute = new PutRoute();
 
@@ -114,7 +113,7 @@ abstract class AbstractIPRIBSupport extends AbstractRIBSupport {
         return false;
     }
 
-    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+    private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath,
             final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
         if (destination != null) {
             final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(nlriRoutesListIdentifier());
@@ -123,7 +122,7 @@ abstract class AbstractIPRIBSupport extends AbstractRIBSupport {
                 if (routes instanceof UnkeyedListNode) {
                     // Instance identifier to table/(choice routes)/(map of route)
                     // FIXME: cache on per-table basis (in TableContext, for example)
-                    final YangInstanceIdentifier base = tablePath.node(ROUTES).node(routesContainerIdentifier()).node(routeIdentifier());
+                    final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeIdentifier());
                     for (final UnkeyedListEntryNode e : ((UnkeyedListNode)routes).getValue()) {
                         final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                         function.apply(tx, base, routeKey,  e, attributes);
@@ -147,12 +146,14 @@ abstract class AbstractIPRIBSupport extends AbstractRIBSupport {
 
 
     @Override
-    protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode destination, final ContainerNode attributes) {
-        processDestination(tx, tablePath, destination, attributes, this.putRoute);
+    protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode destination,
+            final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
     }
 
     @Override
-    protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode destination) {
-        processDestination(tx, tablePath, destination, null, DELETE_ROUTE);
+    protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+            final ContainerNode destination, final NodeIdentifier routesNodeId) {
+        processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
     }
 }
index 63a10cc0dd23190adba2495297639fa27a12136b..cc12cf28215086fdd13ede97247af16b92e27191 100644 (file)
@@ -50,7 +50,7 @@ public abstract class AbstractRIBSupport implements RIBSupport {
     private static final NodeIdentifier ADVERTIZED_ROUTES = new NodeIdentifier(AdvertizedRoutes.QNAME);
     private static final NodeIdentifier WITHDRAWN_ROUTES = new NodeIdentifier(WithdrawnRoutes.QNAME);
     private static final NodeIdentifier DESTINATION_TYPE = new NodeIdentifier(DestinationType.QNAME);
-    protected static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
+    private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
 
     private final NodeIdentifier routesContainerIdentifier;
     private final NodeIdentifier routesListIdentifier;
@@ -124,8 +124,9 @@ public abstract class AbstractRIBSupport implements RIBSupport {
      * @param tx DOMDataWriteTransaction to be passed into implementation
      * @param tablePath YangInstanceIdentifier to be passed into implementation
      * @param destination ContainerNode DOM representation of NLRI in Update message
+     * @param routesNodeId NodeIdentifier
      */
-    protected abstract void deleteDestinationRoutes(DOMDataWriteTransaction tx, YangInstanceIdentifier tablePath, ContainerNode destination);
+    protected abstract void deleteDestinationRoutes(DOMDataWriteTransaction tx, YangInstanceIdentifier tablePath, ContainerNode destination, NodeIdentifier routesNodeId);
 
     /**
      * Given the destination as ContainerNode, implementation needs to parse the DOM model
@@ -139,8 +140,10 @@ public abstract class AbstractRIBSupport implements RIBSupport {
      * @param tablePath YangInstanceIdentifier to be passed into implementation
      * @param destination ContainerNode DOM representation of NLRI in Update message
      * @param attributes ContainerNode to be passed into implementation
+     * @param routesNodeId NodeIdentifier
      */
-    protected abstract void putDestinationRoutes(DOMDataWriteTransaction tx, YangInstanceIdentifier tablePath, ContainerNode destination, ContainerNode attributes);
+    protected abstract void putDestinationRoutes(DOMDataWriteTransaction tx, YangInstanceIdentifier tablePath, ContainerNode destination, ContainerNode attributes,
+            NodeIdentifier routesNodeId);
 
     private static ContainerNode getDestination(final DataContainerChild<? extends PathArgument, ?> routes, final NodeIdentifier destinationId) {
         if (routes instanceof ContainerNode) {
@@ -199,28 +202,12 @@ public abstract class AbstractRIBSupport implements RIBSupport {
 
     @Override
     public final void deleteRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode nlri) {
-        final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(WITHDRAWN_ROUTES);
-        if (maybeRoutes.isPresent()) {
-            final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
-            if (destination != null) {
-                deleteDestinationRoutes(tx, tablePath, destination);
-            }
-        } else {
-            LOG.debug("Withdrawn routes are not present in NLRI {}", nlri);
-        }
+        deleteRoutes(tx, tablePath, nlri, ROUTES);
     }
 
     @Override
     public final void putRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode nlri, final ContainerNode attributes) {
-        final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(ADVERTIZED_ROUTES);
-        if (maybeRoutes.isPresent()) {
-            final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
-            if (destination != null) {
-                putDestinationRoutes(tx, tablePath, destination, attributes);
-            }
-        } else {
-            LOG.debug("Advertized routes are not present in NLRI {}", nlri);
-        }
+        putRoutes(tx, tablePath, nlri, attributes, ROUTES);
     }
 
     /**
@@ -261,4 +248,33 @@ public abstract class AbstractRIBSupport implements RIBSupport {
         ub.setAttributes(ab.build());
         return ub.build();
     }
+
+    @Override
+    public final void deleteRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode nlri,
+            final NodeIdentifier routesNodeId) {
+        final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(WITHDRAWN_ROUTES);
+        if (maybeRoutes.isPresent()) {
+            final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
+            if (destination != null) {
+                deleteDestinationRoutes(tx, tablePath, destination, routesNodeId);
+            }
+        } else {
+            LOG.debug("Withdrawn routes are not present in NLRI {}", nlri);
+        }
+    }
+
+    @Override
+    public final void putRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath, final ContainerNode nlri,
+            final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+        final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = nlri.getChild(ADVERTIZED_ROUTES);
+        if (maybeRoutes.isPresent()) {
+            final ContainerNode destination = getDestination(maybeRoutes.get(), destinationContainerIdentifier());
+            if (destination != null) {
+                putDestinationRoutes(tx, tablePath, destination, attributes, routesNodeId);
+            }
+        } else {
+            LOG.debug("Advertized routes are not present in NLRI {}", nlri);
+        }
+    }
+
 }
index d94a9b8a61882eb05e8e3e5b50a6295b9a82055b..6be31c19f9572e5e4f3b9507ab39649e11796fc6 100644 (file)
@@ -81,6 +81,23 @@ public interface RIBSupport {
      */
     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri);
 
+
+    /**
+     * Given the NLRI as ContainerNode, this method should extract withdrawn routes
+     * from the DOM model and delete them from RIBs.
+     * <p>
+     * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
+     * Provide {@link NodeIdentifier} with customized "routes" QName.
+     * For default "bgp-rib" RIBs use {@link #deleteRoutes}
+     * </p>
+     *
+     * @param tx DOMDataWriteTransaction
+     * @param tablePath YangInstanceIdentifier
+     * @param nlri ContainerNode DOM representation of NLRI in Update message
+     * @param routesNodeId NodeIdentifier of "routes" data node
+     */
+    void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
+
     /**
      * Given the NLRI as ContainerNode, this method should extract advertised routes
      * from the DOM model and put them into RIBs.
@@ -92,6 +109,24 @@ public interface RIBSupport {
      */
     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
 
+    /**
+     * Given the NLRI as ContainerNode, this method should extract advertised routes
+     * from the DOM model and put them into RIBs.
+     * <p>
+     * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
+     * Provide {@link NodeIdentifier} with customized "routes" QName.
+     * For default "bgp-rib" RIBs use {@link #putRoutes}
+     * </p>
+     *
+     * @param tx DOMDataWriteTransaction
+     * @param tablePath YangInstanceIdentifier
+     * @param nlri ContainerNode DOM representation of NLRI in Update message
+     * @param attributes ContainerNode
+     * @param routesNodeId NodeIdentifier of "routes" data node
+     */
+    void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri,
+            @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
+
     /**
      * Returns routes that were modified within this RIB support instance.
      *
index e828a6ce5e46b789f2dc10d9b9e6517b24755873..0ced640a9c0f9a3a7ef3a5b4efdcc4c0cf0533a0 100644 (file)
@@ -70,13 +70,13 @@ public class AbstractRIBSupportTest {
 
         @Override
         protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-            final ContainerNode destination) {
+            final ContainerNode destination, final NodeIdentifier routesNodeId) {
             AbstractRIBSupportTest.dest = destination;
         }
 
         @Override
         protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-            final ContainerNode destination, final ContainerNode attributes) {
+            final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
             AbstractRIBSupportTest.dest = destination;
         }