BGPCEP-754: Rework EffectiveRibInWriter
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / l3vpn / ipv6 / FlowspecL3vpnIpv6RIBSupport.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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.l3vpn.ipv6;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
13 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
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.Ipv6AddressFamily;
23
24 public final class FlowspecL3vpnIpv6RIBSupport
25         extends AbstractFlowspecL3vpnRIBSupport<FlowspecL3vpnIpv6NlriParser,
26         org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj
27                 .rib.in.tables.routes.FlowspecL3vpnIpv6RoutesCase, FlowspecL3vpnRoute, FlowspecL3vpnRouteKey> {
28     private FlowspecL3vpnIpv6RIBSupport(SimpleFlowspecExtensionProviderContext context) {
29         super(
30                 FlowspecL3vpnIpv6RoutesCase.class,
31                 FlowspecL3vpnIpv6Routes.class,
32                 FlowspecL3vpnRoute.class,
33                 DestinationFlowspecL3vpnIpv6.QNAME,
34                 Ipv6AddressFamily.class,
35                 new FlowspecL3vpnIpv6NlriParser(context
36                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
37                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
38         );
39     }
40
41     public static FlowspecL3vpnIpv6RIBSupport getInstance(final SimpleFlowspecExtensionProviderContext context) {
42         return new FlowspecL3vpnIpv6RIBSupport(context);
43     }
44
45     @Override
46     public final FlowspecL3vpnRouteKey createNewRouteKey(final PathId pathId, final FlowspecL3vpnRouteKey routeKey) {
47         return new FlowspecL3vpnRouteKey(pathId, routeKey.getRouteKey());
48     }
49
50     @Override
51     public FlowspecL3vpnRouteKey extractRouteKey(final FlowspecL3vpnRoute route) {
52         return route.getKey();
53     }
54
55     @Override
56     public FlowspecL3vpnRoute createRoute(
57             final FlowspecL3vpnRoute route,
58             final FlowspecL3vpnRouteKey routeKey,
59             final PathId pathId,
60             final Attributes attributes) {
61         final FlowspecL3vpnRouteBuilder builder;
62         if (route != null) {
63             builder = new FlowspecL3vpnRouteBuilder(route);
64         } else {
65             builder = new FlowspecL3vpnRouteBuilder();
66         }
67         return builder.setRouteKey(routeKey.getRouteKey()).setPathId(pathId).setAttributes(attributes).build();
68     }
69
70     @Override
71     public Collection<FlowspecL3vpnRoute> changedRoutes(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
72             .ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecL3vpnIpv6RoutesCase routes) {
73         final FlowspecL3vpnIpv6Routes routeCont = routes.getFlowspecL3vpnIpv6Routes();
74         if (routeCont == null) {
75             return Collections.emptyList();
76         }
77         return routeCont.getFlowspecL3vpnRoute();
78     }
79 }