BGPCEP-754: Rework EffectiveRibInWriter
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / FlowspecIpv4RIBSupport.java
index a63f30c574527e37dfb068f85c52f6acd8adb2cc..5e6d3cec06e971c6f73fa63568ecd62e71e3e192 100644 (file)
@@ -7,28 +7,75 @@
  */
 package org.opendaylight.protocol.bgp.flowspec;
 
+import java.util.Collection;
+import java.util.Collections;
+import javax.annotation.Nonnull;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.FlowspecSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRouteKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.routes.FlowspecRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 
-public final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv4NlriParser> {
+public final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv4NlriParser,
+        org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.peer
+                .adj.rib.in.tables.routes.FlowspecRoutesCase, FlowspecRoute, FlowspecRouteKey> {
 
     public FlowspecIpv4RIBSupport(SimpleFlowspecExtensionProviderContext context) {
         super(
-            FlowspecRoutesCase.class,
-            FlowspecRoutes.class,
-            FlowspecRoute.class,
-            Ipv4AddressFamily.class,
-            FlowspecSubsequentAddressFamily.class,
-            DestinationFlowspec.QNAME,
-            new SimpleFlowspecIpv4NlriParser(context.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
+                FlowspecRoutesCase.class,
+                FlowspecRoutes.class,
+                FlowspecRoute.class,
+                Ipv4AddressFamily.class,
+                FlowspecSubsequentAddressFamily.class,
+                DestinationFlowspec.QNAME,
+                new SimpleFlowspecIpv4NlriParser(context
+                        .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
+                                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
         );
     }
 
     static FlowspecIpv4RIBSupport getInstance(SimpleFlowspecExtensionProviderContext context) {
         return new FlowspecIpv4RIBSupport(context);
     }
+
+    @Override
+    public FlowspecRouteKey extractRouteKey(final FlowspecRoute route) {
+        return route.getKey();
+    }
+
+    @Nonnull
+    @Override
+    public FlowspecRoute createRoute(
+            final FlowspecRoute route,
+            final FlowspecRouteKey routeKey,
+            final PathId pathId,
+            final Attributes attributes) {
+        final FlowspecRouteBuilder builder;
+        if (route != null) {
+            builder = new FlowspecRouteBuilder(route);
+        } else {
+            builder = new FlowspecRouteBuilder();
+        }
+        return builder.setRouteKey(routeKey.getRouteKey()).setPathId(pathId).setAttributes(attributes).build();
+    }
+
+    @Override
+    public Collection<FlowspecRoute> changedRoutes(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
+            .yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase routes) {
+        final FlowspecRoutes routesCont = routes.getFlowspecRoutes();
+        if (routesCont == null) {
+            return Collections.emptyList();
+        }
+        return routesCont.getFlowspecRoute();
+    }
+
+    @Override
+    public FlowspecRouteKey createNewRouteKey(final PathId pathId, final FlowspecRouteKey routeKey) {
+        return new FlowspecRouteKey(pathId, routeKey.getRouteKey());
+    }
 }