provide way to extract routes from routesContainer
[bgpcep.git] / bgp / extensions / 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 java.util.List;
12 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
13 import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
14 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6RoutesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
26
27 public final class FlowspecL3vpnIpv6RIBSupport
28         extends AbstractFlowspecL3vpnRIBSupport<FlowspecL3vpnIpv6NlriParser,
29         FlowspecL3vpnIpv6RoutesCase,
30         FlowspecL3vpnIpv6Routes,
31         FlowspecL3vpnRoute,
32         FlowspecL3vpnRouteKey> {
33     private static final FlowspecL3vpnIpv6Routes EMPTY_CONTAINER
34             = new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build();
35     private static final FlowspecL3vpnIpv6RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv6RoutesCaseBuilder()
36             .setFlowspecL3vpnIpv6Routes(EMPTY_CONTAINER).build();
37     private static FlowspecL3vpnIpv6RIBSupport SINGLETON;
38
39     private FlowspecL3vpnIpv6RIBSupport(
40             final SimpleFlowspecExtensionProviderContext context,
41             final BindingNormalizedNodeSerializer mappingService) {
42         super(
43                 mappingService,
44                 FlowspecL3vpnIpv6RoutesCase.class,
45                 FlowspecL3vpnIpv6Routes.class,
46                 FlowspecL3vpnRoute.class,
47                 DestinationFlowspecL3vpnIpv6.QNAME,
48                 Ipv6AddressFamily.class,
49                 new FlowspecL3vpnIpv6NlriParser(context
50                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
51                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
52         );
53     }
54
55     public static synchronized FlowspecL3vpnIpv6RIBSupport getInstance(
56             final SimpleFlowspecExtensionProviderContext context,
57             final BindingNormalizedNodeSerializer mappingService) {
58         if (SINGLETON == null) {
59             SINGLETON = new FlowspecL3vpnIpv6RIBSupport(context, mappingService);
60         }
61         return SINGLETON;
62     }
63
64     @Override
65     public FlowspecL3vpnRouteKey createRouteListKey(final long pathId, final String routeKey) {
66         return new FlowspecL3vpnRouteKey(new PathId(pathId), routeKey);
67     }
68
69     @Override
70     public FlowspecL3vpnRoute createRoute(final FlowspecL3vpnRoute route, final String routeKey,
71             final long pathId, 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(new FlowspecL3vpnRouteKey(new PathId(pathId), routeKey))
79                 .setAttributes(attributes).build();
80     }
81
82     @Override
83     public FlowspecL3vpnIpv6RoutesCase emptyRoutesCase() {
84         return EMPTY_CASE;
85     }
86
87     @Override
88     public FlowspecL3vpnIpv6Routes emptyRoutesContainer() {
89         return EMPTY_CONTAINER;
90     }
91
92     @Override
93     public List<FlowspecL3vpnRoute> routesFromContainer(final FlowspecL3vpnIpv6Routes container) {
94         return container.getFlowspecL3vpnRoute();
95     }
96 }