BGPCEP-754: Rework EffectiveRibInWriter
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / FlowspecIpv6RIBSupport.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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.FlowspecSubsequentAddressFamily;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv6.DestinationFlowspec;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv6.route.FlowspecRoute;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv6.route.FlowspecRouteBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv6.route.FlowspecRouteKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.ipv6.routes.FlowspecIpv6Routes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
22
23 public final class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv6NlriParser,
24         org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj
25                 .rib.in.tables.routes.FlowspecIpv6RoutesCase, FlowspecRoute, FlowspecRouteKey> {
26
27     public FlowspecIpv6RIBSupport(SimpleFlowspecExtensionProviderContext context) {
28         super(
29                 FlowspecIpv6RoutesCase.class,
30                 FlowspecIpv6Routes.class,
31                 FlowspecRoute.class,
32                 Ipv6AddressFamily.class,
33                 FlowspecSubsequentAddressFamily.class,
34                 DestinationFlowspec.QNAME,
35                 new SimpleFlowspecIpv6NlriParser(context
36                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
37                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
38         );
39     }
40
41     static FlowspecIpv6RIBSupport getInstance(SimpleFlowspecExtensionProviderContext context) {
42         return new FlowspecIpv6RIBSupport(context);
43     }
44
45     @Override
46     public FlowspecRouteKey extractRouteKey(final FlowspecRoute route) {
47         return route.getKey();
48     }
49
50     @Override
51     public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey routeKey,
52             final PathId pathId, final Attributes attributes) {
53         final FlowspecRouteBuilder builder;
54         if (route != null) {
55             builder = new FlowspecRouteBuilder(route);
56         } else {
57             builder = new FlowspecRouteBuilder();
58         }
59         return builder.setRouteKey(routeKey.getRouteKey()).setPathId(pathId).setAttributes(attributes).build();
60     }
61
62     @Override
63     public Collection<FlowspecRoute> changedRoutes(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
64             .yang.bgp.flowspec.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecIpv6RoutesCase routes) {
65         final FlowspecIpv6Routes routesCont = routes.getFlowspecIpv6Routes();
66         if (routesCont == null) {
67             return Collections.emptyList();
68         }
69         return routesCont.getFlowspecRoute();
70     }
71
72     @Override
73     public FlowspecRouteKey createNewRouteKey(final PathId pathId, final FlowspecRouteKey routeKey) {
74         return new FlowspecRouteKey(pathId, routeKey.getRouteKey());
75     }
76 }