BGPCEP-754: Rework EffectiveRibInWriter
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / FlowspecIpv4RIBSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.flowspec;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.FlowspecSubsequentAddressFamily;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspec;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRoute;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRouteBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv4.route.FlowspecRouteKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.routes.FlowspecRoutes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
23
24 public final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv4NlriParser,
25         org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.peer
26                 .adj.rib.in.tables.routes.FlowspecRoutesCase, FlowspecRoute, FlowspecRouteKey> {
27
28     public FlowspecIpv4RIBSupport(SimpleFlowspecExtensionProviderContext context) {
29         super(
30                 FlowspecRoutesCase.class,
31                 FlowspecRoutes.class,
32                 FlowspecRoute.class,
33                 Ipv4AddressFamily.class,
34                 FlowspecSubsequentAddressFamily.class,
35                 DestinationFlowspec.QNAME,
36                 new SimpleFlowspecIpv4NlriParser(context
37                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
38                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
39         );
40     }
41
42     static FlowspecIpv4RIBSupport getInstance(SimpleFlowspecExtensionProviderContext context) {
43         return new FlowspecIpv4RIBSupport(context);
44     }
45
46     @Override
47     public FlowspecRouteKey extractRouteKey(final FlowspecRoute route) {
48         return route.getKey();
49     }
50
51     @Nonnull
52     @Override
53     public FlowspecRoute createRoute(
54             final FlowspecRoute route,
55             final FlowspecRouteKey routeKey,
56             final PathId pathId,
57             final Attributes attributes) {
58         final FlowspecRouteBuilder builder;
59         if (route != null) {
60             builder = new FlowspecRouteBuilder(route);
61         } else {
62             builder = new FlowspecRouteBuilder();
63         }
64         return builder.setRouteKey(routeKey.getRouteKey()).setPathId(pathId).setAttributes(attributes).build();
65     }
66
67     @Override
68     public Collection<FlowspecRoute> changedRoutes(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
69             .yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase routes) {
70         final FlowspecRoutes routesCont = routes.getFlowspecRoutes();
71         if (routesCont == null) {
72             return Collections.emptyList();
73         }
74         return routesCont.getFlowspecRoute();
75     }
76
77     @Override
78     public FlowspecRouteKey createNewRouteKey(final PathId pathId, final FlowspecRouteKey routeKey) {
79         return new FlowspecRouteKey(pathId, routeKey.getRouteKey());
80     }
81 }