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.base.Preconditions;
14 import com.google.common.collect.ImmutableCollection;
15 import com.google.common.collect.ImmutableSet;
16 import com.google.common.collect.Iterables;
17 import java.util.Collection;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
20 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
21 import org.opendaylight.protocol.bgp.rib.spi.MultiPathAbstractRIBSupport;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
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;
37 public abstract class AbstractFlowspecRIBSupport<T extends AbstractFlowspecNlriParser> extends MultiPathAbstractRIBSupport {
38 protected final T nlriParser;
40 protected AbstractFlowspecRIBSupport(
41 final Class<? extends Routes> cazeClass,
42 final Class<? extends DataObject> containerClass,
43 final Class<? extends Route> listClass,
44 final Class<? extends AddressFamily> afiClass,
45 final Class<? extends SubsequentAddressFamily> safiClass,
46 final QName dstContainerClassQName,
49 super(cazeClass, containerClass, listClass, afiClass, safiClass, "route-key", dstContainerClassQName);
51 this.nlriParser = requireNonNull(nlriParser);
56 public final ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
57 return ImmutableSet.of();
62 public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
63 return ImmutableSet.of();
67 public final boolean isComplexRoute() {
73 protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) {
74 final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
75 final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
76 return this.nlriParser.createAdvertizedRoutesDestinationType(
77 new Object[] {this.nlriParser.extractFlowspec(routesCont)},
84 protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
85 final MapEntryNode routesCont = Iterables.getOnlyElement(routes);
86 final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid());
87 return this.nlriParser.createWithdrawnDestinationType(
88 new Object[] {this.nlriParser.extractFlowspec(Iterables.getOnlyElement(routes))},
94 protected final void processDestination(
95 final DOMDataWriteTransaction tx,
96 final YangInstanceIdentifier routesPath,
97 final ContainerNode destination,
98 final ContainerNode attributes,
99 final ApplyRoute function
101 if (destination != null) {
102 final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
103 final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = destination.getChild(routePathIdNid());
104 final String routeKeyValue = this.nlriParser.stringNlri(destination);
105 final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
106 function.apply(tx, base, routeKey, destination, attributes);