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.rev180329.FlowspecSubsequentAddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.ipv4.DestinationFlowspecIpv4;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv4.route.FlowspecRoute;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv4.route.FlowspecRouteBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv4.route.FlowspecRouteKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.routes.FlowspecRoutes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.routes.FlowspecRoutesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
29 public final class FlowspecIpv4RIBSupport
30 extends AbstractFlowspecRIBSupport<SimpleFlowspecIpv4NlriParser,
35 private static final FlowspecRoutes EMPTY_CONTAINER
36 = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build();
37 private static final FlowspecRoutesCase EMPTY_CASE
38 = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(EMPTY_CONTAINER).build();
39 private static FlowspecIpv4RIBSupport SINGLETON;
41 private FlowspecIpv4RIBSupport(final SimpleFlowspecExtensionProviderContext context,
42 final BindingNormalizedNodeSerializer mappingService) {
45 FlowspecRoutesCase.class,
48 Ipv4AddressFamily.class,
49 FlowspecSubsequentAddressFamily.class,
50 DestinationFlowspecIpv4.QNAME,
51 new SimpleFlowspecIpv4NlriParser(context
52 .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
53 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
57 static synchronized FlowspecIpv4RIBSupport getInstance(
58 final SimpleFlowspecExtensionProviderContext context,
59 final BindingNormalizedNodeSerializer mappingService) {
60 if (SINGLETON == null){
61 SINGLETON = new FlowspecIpv4RIBSupport(context, mappingService);
67 public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey key,
68 final Attributes attributes) {
69 final FlowspecRouteBuilder builder;
71 builder = new FlowspecRouteBuilder(route);
73 builder = new FlowspecRouteBuilder();
75 return builder.withKey(key).setAttributes(attributes).build();
79 public FlowspecRoutesCase emptyRoutesCase() {
84 public FlowspecRoutes emptyRoutesContainer() {
85 return EMPTY_CONTAINER;
89 public FlowspecRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
90 return new FlowspecRouteKey(pathId, routeKey);
94 public PathId extractPathId(final FlowspecRouteKey routeListKey) {
95 return routeListKey.getPathId();
99 public String extractRouteKey(final FlowspecRouteKey routeListKey) {
100 return routeListKey.getRouteKey();
104 public List<FlowspecRoute> extractAdjRibInRoutes(Routes routes) {
105 verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329
106 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase, "Unrecognized routes %s", routes);
107 return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329
108 .bgp.rib.rib.peer.adj.rib.in.tables.routes.FlowspecRoutesCase) routes).getFlowspecRoutes()
109 .nonnullFlowspecRoute();