Update MRI projects for Aluminium
[bgpcep.git] / bgp / extensions / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / l3vpn / ipv4 / FlowspecL3vpnIpv4RIBSupport.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.ipv4;
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.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
16 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRoute;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4RoutesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
28
29 public final class FlowspecL3vpnIpv4RIBSupport
30         extends AbstractFlowspecL3vpnRIBSupport<FlowspecL3vpnIpv4NlriParser,
31         FlowspecL3vpnIpv4RoutesCase,
32         FlowspecL3vpnIpv4Routes,
33         FlowspecL3vpnRoute,
34         FlowspecL3vpnRouteKey> {
35     private static final FlowspecL3vpnIpv4Routes EMPTY_CONTAINER
36             = new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build();
37     private static FlowspecL3vpnIpv4RIBSupport SINGLETON;
38
39     private FlowspecL3vpnIpv4RIBSupport(
40             final SimpleFlowspecExtensionProviderContext context,
41             final BindingNormalizedNodeSerializer mappingService) {
42         super(
43                 mappingService,
44                 FlowspecL3vpnIpv4RoutesCase.class,
45                 FlowspecL3vpnIpv4Routes.class,
46                 FlowspecL3vpnRoute.class,
47                 DestinationFlowspecL3vpnIpv4.QNAME,
48                 Ipv4AddressFamily.class,
49                 new FlowspecL3vpnIpv4NlriParser(context
50                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
51                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
52         );
53     }
54
55     public static synchronized FlowspecL3vpnIpv4RIBSupport getInstance(
56             final SimpleFlowspecExtensionProviderContext context,
57             final BindingNormalizedNodeSerializer mappingService) {
58         if (SINGLETON == null) {
59             SINGLETON = new FlowspecL3vpnIpv4RIBSupport(context, mappingService);
60         }
61         return SINGLETON;
62     }
63
64     @Override
65     public FlowspecL3vpnRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
66         return new FlowspecL3vpnRouteKey(pathId, routeKey);
67     }
68
69     @Override
70     public FlowspecL3vpnRoute createRoute(final FlowspecL3vpnRoute route, final FlowspecL3vpnRouteKey key,
71             final Attributes attributes) {
72         final FlowspecL3vpnRouteBuilder builder;
73         if (route != null) {
74             builder = new FlowspecL3vpnRouteBuilder(route);
75         } else {
76             builder = new FlowspecL3vpnRouteBuilder();
77         }
78         return builder.withKey(key).setAttributes(attributes).build();
79     }
80
81     @Override
82     public FlowspecL3vpnIpv4Routes emptyRoutesContainer() {
83         return EMPTY_CONTAINER;
84     }
85
86     @Override
87     public PathId extractPathId(final FlowspecL3vpnRouteKey routeListKey) {
88         return routeListKey.getPathId();
89     }
90
91     @Override
92     public String extractRouteKey(final FlowspecL3vpnRouteKey routeListKey) {
93         return routeListKey.getRouteKey();
94     }
95
96     @Override
97     public Map<FlowspecL3vpnRouteKey, FlowspecL3vpnRoute> extractAdjRibInRoutes(final Routes routes) {
98         verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
99             .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecL3vpnIpv4RoutesCase, "Unrecognized routes %s", routes);
100         return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
101                 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecL3vpnIpv4RoutesCase) routes)
102                 .getFlowspecL3vpnIpv4Routes().nonnullFlowspecL3vpnRoute();
103     }
104 }