7729d8942ee6fbd9d69ae9578705c5d755d8a70d
[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 java.util.Collections;
11 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecSubsequentAddressFamily;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCaseBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.ipv6.DestinationFlowspecIpv6;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.route.FlowspecRoute;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.route.FlowspecRouteBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.route.FlowspecRouteKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.routes.FlowspecIpv6Routes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.routes.FlowspecIpv6RoutesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
24
25 public final class FlowspecIpv6RIBSupport
26         extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv6NlriParser,
27         FlowspecIpv6RoutesCase,
28         FlowspecIpv6Routes,
29         FlowspecRoute,
30         FlowspecRouteKey> {
31     private static final FlowspecIpv6Routes EMPTY_CONTAINER = new FlowspecIpv6RoutesBuilder()
32             .setFlowspecRoute(Collections.emptyList()).build();
33     private static final FlowspecIpv6RoutesCase EMPTY_CASE = new FlowspecIpv6RoutesCaseBuilder()
34             .setFlowspecIpv6Routes(EMPTY_CONTAINER).build();
35     private static FlowspecIpv6RIBSupport SINGLETON;
36
37     private FlowspecIpv6RIBSupport(final SimpleFlowspecExtensionProviderContext context,
38             final BindingNormalizedNodeSerializer mappingService) {
39         super(
40                 mappingService,
41                 FlowspecIpv6RoutesCase.class,
42                 FlowspecIpv6Routes.class,
43                 FlowspecRoute.class,
44                 Ipv6AddressFamily.class,
45                 FlowspecSubsequentAddressFamily.class,
46                 DestinationFlowspecIpv6.QNAME,
47                 new SimpleFlowspecIpv6NlriParser(context
48                         .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
49                                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
50         );
51     }
52
53     static synchronized FlowspecIpv6RIBSupport getInstance(
54             final SimpleFlowspecExtensionProviderContext context,
55             final BindingNormalizedNodeSerializer mappingService) {
56         if (SINGLETON == null) {
57             SINGLETON = new FlowspecIpv6RIBSupport(context, mappingService);
58         }
59         return SINGLETON;
60     }
61
62     @Override
63     public FlowspecRoute createRoute(final FlowspecRoute route, final String routeKey,
64             final long pathId, final Attributes attributes) {
65         final FlowspecRouteBuilder builder;
66         if (route != null) {
67             builder = new FlowspecRouteBuilder(route);
68         } else {
69             builder = new FlowspecRouteBuilder();
70         }
71         return builder.withKey(new FlowspecRouteKey(new PathId(pathId), routeKey)).setAttributes(attributes).build();
72     }
73
74     @Override
75     public FlowspecIpv6RoutesCase emptyRoutesCase() {
76         return EMPTY_CASE;
77     }
78
79     @Override
80     public FlowspecIpv6Routes emptyRoutesContainer() {
81         return EMPTY_CONTAINER;
82     }
83
84     @Override
85     public FlowspecRouteKey createRouteListKey(final long pathId, final String routeKey) {
86         return new FlowspecRouteKey(new PathId(pathId), routeKey);
87     }
88 }