Update MRI projects for Aluminium
[bgpcep.git] / bgp / extensions / 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 static com.google.common.base.Verify.verify;
11
12 import java.util.Collections;
13 import java.util.Map;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRoute;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRouteKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6RoutesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
27
28 public final class FlowspecIpv6RIBSupport
29         extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv6NlriParser,
30         FlowspecIpv6RoutesCase,
31         FlowspecIpv6Routes,
32         FlowspecRoute,
33         FlowspecRouteKey> {
34     private static final FlowspecIpv6Routes EMPTY_CONTAINER = new FlowspecIpv6RoutesBuilder()
35             .setFlowspecRoute(Collections.emptyList()).build();
36     private static FlowspecIpv6RIBSupport SINGLETON;
37
38     private FlowspecIpv6RIBSupport(final SimpleFlowspecExtensionProviderContext context,
39             final BindingNormalizedNodeSerializer mappingService) {
40         super(
41                 mappingService,
42                 FlowspecIpv6RoutesCase.class,
43                 FlowspecIpv6Routes.class,
44                 FlowspecRoute.class,
45                 Ipv6AddressFamily.class,
46                 FlowspecSubsequentAddressFamily.class,
47                 DestinationFlowspecIpv6.QNAME,
48                 new SimpleFlowspecIpv6NlriParser(context
49                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
50                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
51         );
52     }
53
54     static synchronized FlowspecIpv6RIBSupport getInstance(
55             final SimpleFlowspecExtensionProviderContext context,
56             final BindingNormalizedNodeSerializer mappingService) {
57         if (SINGLETON == null) {
58             SINGLETON = new FlowspecIpv6RIBSupport(context, mappingService);
59         }
60         return SINGLETON;
61     }
62
63     @Override
64     public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey key,
65             final Attributes attributes) {
66         final FlowspecRouteBuilder builder;
67         if (route != null) {
68             builder = new FlowspecRouteBuilder(route);
69         } else {
70             builder = new FlowspecRouteBuilder();
71         }
72         return builder.withKey(key).setAttributes(attributes).build();
73     }
74
75     @Override
76     public FlowspecIpv6Routes emptyRoutesContainer() {
77         return EMPTY_CONTAINER;
78     }
79
80     @Override
81     public FlowspecRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
82         return new FlowspecRouteKey(pathId, routeKey);
83     }
84
85     @Override
86     public PathId extractPathId(final FlowspecRouteKey routeListKey) {
87         return routeListKey.getPathId();
88     }
89
90     @Override
91     public String extractRouteKey(final FlowspecRouteKey routeListKey) {
92         return routeListKey.getRouteKey();
93     }
94
95     @Override
96     public Map<FlowspecRouteKey, FlowspecRoute> extractAdjRibInRoutes(final Routes routes) {
97         verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
98             .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecIpv6RoutesCase, "Unrecognized routes %s", routes);
99         return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
100                 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecIpv6RoutesCase) routes).getFlowspecIpv6Routes()
101                 .nonnullFlowspecRoute();
102     }
103 }