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 java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableCollection;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.collect.Iterables;
16 import java.util.Collection;
17 import java.util.Optional;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
19 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
20 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
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.multiprotocol.rev180329.destination.DestinationType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.Identifier;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
35 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
38 public abstract class AbstractFlowspecRIBSupport<T extends AbstractFlowspecNlriParser,
39 R extends Route, S extends Identifier> extends AbstractRIBSupport<R, S> {
40 protected final T nlriParser;
42 protected AbstractFlowspecRIBSupport(
43 final Class<? extends Routes> cazeClass,
44 final Class<? extends DataObject> containerClass,
45 final Class<? extends Route> listClass,
46 final Class<? extends AddressFamily> afiClass,
47 final Class<? extends SubsequentAddressFamily> safiClass,
48 final QName dstContainerClassQName,
51 super(cazeClass, containerClass, listClass, afiClass, safiClass, dstContainerClassQName);
53 this.nlriParser = requireNonNull(nlriParser);
57 public final ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
58 return ImmutableSet.of();
62 public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
63 return ImmutableSet.of();
67 public final boolean isComplexRoute() {
72 protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
73 final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
74 final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
75 return this.nlriParser.createAdvertizedRoutesDestinationType(
76 new Object[] {this.nlriParser.extractFlowspec(routesCont)},
82 protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
83 final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
84 final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
85 return this.nlriParser.createWithdrawnDestinationType(
86 new Object[] {this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))},
92 protected final void processDestination(
93 final DOMDataWriteTransaction tx,
94 final YangInstanceIdentifier routesPath,
95 final ContainerNode destination,
96 final ContainerNode attributes,
97 final ApplyRoute function
99 if (destination != null) {
100 final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
101 final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf
102 = destination.getChild(routePathIdNid());
103 final String routeKeyValue = this.nlriParser.stringNlri(destination);
104 final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
105 pathIdQName(), routeKeyValue, maybePathIdLeaf);
106 function.apply(tx, base, routeKey, destination, attributes);