Create common parent for extensions families
[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 java.util.Collections;
11 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
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.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRoute;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4RoutesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
25
26 public final class FlowspecL3vpnIpv4RIBSupport
27         extends AbstractFlowspecL3vpnRIBSupport<FlowspecL3vpnIpv4NlriParser,
28         FlowspecL3vpnIpv4RoutesCase,
29         FlowspecL3vpnIpv4Routes,
30         FlowspecL3vpnRoute,
31         FlowspecL3vpnRouteKey> {
32     private static final FlowspecL3vpnIpv4Routes EMPTY_CONTAINER
33             = new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build();
34     private static final FlowspecL3vpnIpv4RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv4RoutesCaseBuilder()
35             .setFlowspecL3vpnIpv4Routes(EMPTY_CONTAINER).build();
36     private static FlowspecL3vpnIpv4RIBSupport SINGLETON;
37
38     private FlowspecL3vpnIpv4RIBSupport(
39             final SimpleFlowspecExtensionProviderContext context,
40             final BindingNormalizedNodeSerializer mappingService) {
41         super(
42                 mappingService,
43                 FlowspecL3vpnIpv4RoutesCase.class,
44                 FlowspecL3vpnIpv4Routes.class,
45                 FlowspecL3vpnRoute.class,
46                 DestinationFlowspecL3vpnIpv4.QNAME,
47                 Ipv4AddressFamily.class,
48                 new FlowspecL3vpnIpv4NlriParser(context
49                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
50                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
51         );
52     }
53
54     public static synchronized FlowspecL3vpnIpv4RIBSupport getInstance(
55             final SimpleFlowspecExtensionProviderContext context,
56             final BindingNormalizedNodeSerializer mappingService) {
57         if(SINGLETON == null){
58             SINGLETON = new FlowspecL3vpnIpv4RIBSupport(context, mappingService);
59         }
60         return SINGLETON;
61     }
62
63     @Override
64     public final FlowspecL3vpnRouteKey createRouteListKey(final long pathId, final String routeKey) {
65         return new FlowspecL3vpnRouteKey(new PathId(pathId), routeKey);
66     }
67
68     @Override
69     public FlowspecL3vpnRoute createRoute(final FlowspecL3vpnRoute route, final String routeKey,
70             final long pathId, final Attributes attributes) {
71         final FlowspecL3vpnRouteBuilder builder;
72         if (route != null) {
73             builder = new FlowspecL3vpnRouteBuilder(route);
74         } else {
75             builder = new FlowspecL3vpnRouteBuilder();
76         }
77         return builder.withKey(new FlowspecL3vpnRouteKey(new PathId(pathId), routeKey))
78                 .setAttributes(attributes).build();
79     }
80
81     @Override
82     public FlowspecL3vpnIpv4RoutesCase emptyRoutesCase() {
83         return EMPTY_CASE;
84     }
85
86     @Override
87     public FlowspecL3vpnIpv4Routes emptyRoutesContainer() {
88         return EMPTY_CONTAINER;
89     }
90 }