8232685f08855c367714ba1573d60ad00e2a73d5
[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.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.FlowspecL3vpnIpv6RoutesCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6RoutesBuilder;
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.Ipv6AddressFamily;
25
26 public final class FlowspecL3vpnIpv6RIBSupport
27         extends AbstractFlowspecL3vpnRIBSupport<FlowspecL3vpnIpv6NlriParser,
28         FlowspecL3vpnIpv6RoutesCase,
29         FlowspecL3vpnIpv6Routes,
30         FlowspecL3vpnRoute,
31         FlowspecL3vpnRouteKey> {
32     private static final FlowspecL3vpnIpv6Routes EMPTY_CONTAINER
33             = new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build();
34     private static final FlowspecL3vpnIpv6RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv6RoutesCaseBuilder()
35             .setFlowspecL3vpnIpv6Routes(EMPTY_CONTAINER).build();
36     private static FlowspecL3vpnIpv6RIBSupport SINGLETON;
37
38     private FlowspecL3vpnIpv6RIBSupport(
39             final SimpleFlowspecExtensionProviderContext context,
40             final BindingNormalizedNodeSerializer mappingService) {
41         super(
42                 mappingService,
43                 FlowspecL3vpnIpv6RoutesCase.class,
44                 FlowspecL3vpnIpv6Routes.class,
45                 FlowspecL3vpnRoute.class,
46                 DestinationFlowspecL3vpnIpv6.QNAME,
47                 Ipv6AddressFamily.class,
48                 new FlowspecL3vpnIpv6NlriParser(context
49                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
50                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
51         );
52     }
53
54     public static synchronized FlowspecL3vpnIpv6RIBSupport getInstance(
55             final SimpleFlowspecExtensionProviderContext context,
56             final BindingNormalizedNodeSerializer mappingService) {
57         if (SINGLETON == null) {
58             SINGLETON = new FlowspecL3vpnIpv6RIBSupport(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 FlowspecL3vpnIpv6RoutesCase emptyRoutesCase() {
83         return EMPTY_CASE;
84     }
85
86     @Override
87     public FlowspecL3vpnIpv6Routes emptyRoutesContainer() {
88         return EMPTY_CONTAINER;
89     }
90 }