2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.flowspec;
10 import static com.google.common.base.Verify.verify;
12 import java.util.Collections;
13 import java.util.List;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv4.DestinationFlowspecIpv4;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv4.route.FlowspecRoute;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv4.route.FlowspecRouteBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv4.route.FlowspecRouteKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.routes.FlowspecRoutes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.routes.FlowspecRoutesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
28 public final class FlowspecIpv4RIBSupport
29 extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv4NlriParser,
34 private static final FlowspecRoutes EMPTY_CONTAINER
35 = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build();
36 private static FlowspecIpv4RIBSupport SINGLETON;
38 private FlowspecIpv4RIBSupport(final SimpleFlowspecExtensionProviderContext context,
39 final BindingNormalizedNodeSerializer mappingService) {
42 FlowspecRoutesCase.class,
45 Ipv4AddressFamily.class,
46 FlowspecSubsequentAddressFamily.class,
47 DestinationFlowspecIpv4.QNAME,
48 new SimpleFlowspecIpv4NlriParser(context
49 .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
50 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
54 static synchronized FlowspecIpv4RIBSupport getInstance(
55 final SimpleFlowspecExtensionProviderContext context,
56 final BindingNormalizedNodeSerializer mappingService) {
57 if (SINGLETON == null) {
58 SINGLETON = new FlowspecIpv4RIBSupport(context, mappingService);
64 public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey key,
65 final Attributes attributes) {
66 final FlowspecRouteBuilder builder;
68 builder = new FlowspecRouteBuilder(route);
70 builder = new FlowspecRouteBuilder();
72 return builder.withKey(key).setAttributes(attributes).build();
76 public FlowspecRoutes emptyRoutesContainer() {
77 return EMPTY_CONTAINER;
81 public FlowspecRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
82 return new FlowspecRouteKey(pathId, routeKey);
86 public PathId extractPathId(final FlowspecRouteKey routeListKey) {
87 return routeListKey.getPathId();
91 public String extractRouteKey(final FlowspecRouteKey routeListKey) {
92 return routeListKey.getRouteKey();
96 public List<FlowspecRoute> extractAdjRibInRoutes(final Routes routes) {
97 verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
98 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase, "Unrecognized routes %s", routes);
99 return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120
100 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase) routes).getFlowspecRoutes()
101 .nonnullFlowspecRoute();