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.base.Optional;
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 javax.annotation.Nonnull;
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.MultiPathAbstractRIBSupport;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
32 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
34 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
36 public abstract class AbstractFlowspecRIBSupport<T extends AbstractFlowspecNlriParser> extends MultiPathAbstractRIBSupport {
37 protected final T nlriParser;
39 protected AbstractFlowspecRIBSupport(
40 final Class<? extends Routes> cazeClass,
41 final Class<? extends DataObject> containerClass,
42 final Class<? extends Route> listClass,
43 final Class<? extends AddressFamily> afiClass,
44 final Class<? extends SubsequentAddressFamily> safiClass,
45 final QName dstContainerClassQName,
48 super(cazeClass, containerClass, listClass, afiClass, safiClass, "route-key", dstContainerClassQName);
50 this.nlriParser = requireNonNull(nlriParser);
55 public final ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
56 return ImmutableSet.of();
61 public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
62 return ImmutableSet.of();
66 public final boolean isComplexRoute() {
72 protected DestinationType buildDestination(@Nonnull 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)},
83 protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
84 final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
85 final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
86 return this.nlriParser.createWithdrawnDestinationType(
87 new Object[] {this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))},
93 protected final void processDestination(
94 final DOMDataWriteTransaction tx,
95 final YangInstanceIdentifier routesPath,
96 final ContainerNode destination,
97 final ContainerNode attributes,
98 final ApplyRoute function
100 if (destination != null) {
101 final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
102 final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = destination.getChild(routePathIdNid());
103 final String routeKeyValue = this.nlriParser.stringNlri(destination);
104 final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
105 function.apply(tx, base, routeKey, destination, attributes);