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.rib.spi;
10 import com.google.common.collect.ImmutableCollection;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.Identifier;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
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.ChoiceNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
39 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
40 * to register an implementation of this class and the RIB core then calls into it
41 * to inquire about details specific to that particular model.
43 public interface RIBSupport<R extends Route, N extends Identifier> extends AddPathRibSupport {
45 * Return the table-type-specific empty routes container, as augmented into the
46 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
47 * the skeleton nodes under which the individual routes will be stored.
49 * @return Protocol-specific case in the routes choice, may not be null.
52 ChoiceNode emptyRoutes();
55 * Return the localized identifier of the attributes route member, as expanded
56 * from the route grouping in the specific augmentation of the base routes choice.
58 * @return The attributes identifier, may not be null.
61 NodeIdentifier routeAttributesIdentifier();
64 * Return class object of the Routes Case statement.
69 Class<? extends Routes> routesCaseClass();
72 * Return class object of the Routes Container statement.
77 Class<? extends DataObject> routesContainerClass();
80 * Return class object of the Routes List statement.
85 Class<? extends Route> routesListClass();
88 default ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
89 return ImmutableSet.of();
93 default ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
94 return ImmutableSet.of();
98 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
99 * from the DOM model and delete them from RIBs.
101 * @param tx DOMDataWriteTransaction
102 * @param tablePath YangInstanceIdentifier
103 * @param nlri ContainerNode DOM representation of NLRI in Update message
105 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
106 @Nonnull ContainerNode nlri);
110 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
111 * from the DOM model and delete them from RIBs.
113 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
114 * Provide {@link NodeIdentifier} with customized "routes" QName.
115 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
118 * @param tx DOMDataWriteTransaction
119 * @param tablePath YangInstanceIdentifier
120 * @param nlri ContainerNode DOM representation of NLRI in Update message
121 * @param routesNodeId NodeIdentifier of "routes" data node
123 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
124 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
127 * Given the NLRI as ContainerNode, this method should extract advertised routes
128 * from the DOM model and put them into RIBs.
130 * @param tx DOMDataWriteTransaction
131 * @param tablePath YangInstanceIdentifier
132 * @param nlri ContainerNode DOM representation of NLRI in Update message
133 * @param attributes ContainerNode
135 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
136 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
139 * Given the NLRI as ContainerNode, this method should extract advertised routes
140 * from the DOM model and put them into RIBs.
142 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
143 * Provide {@link NodeIdentifier} with customized "routes" QName.
144 * For default "bgp-rib" RIBs use {@link #putRoutes}
147 * @param tx DOMDataWriteTransaction
148 * @param tablePath YangInstanceIdentifier
149 * @param nlri ContainerNode DOM representation of NLRI in Update message
150 * @param attributes ContainerNode
151 * @param routesNodeId NodeIdentifier of "routes" data node
153 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
154 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
157 * Returns routes that were modified within this RIB support instance.
159 * @param routes DataTreeCandidateNode
160 * @return collection of modified nodes or empty collection if no node was modified
163 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
166 * Constructs an instance identifier path to routeId.
168 * @param routesPath YangInstanceIdentifier base path
169 * @param routeId PathArgument leaf path
170 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
173 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
174 @Nonnull PathArgument routeId);
177 * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
178 * only have their key and attributes, complex routes are those which include more structured data.
180 * @return True if this is a complex route, false otherwise.
181 * @deprecated All routes are complex.
184 default boolean isComplexRoute() {
189 * To send routes out, we'd need to transform the DOM representation of route to
190 * binding-aware format. This needs to be done per each AFI/SAFI.
192 * @param advertised Collection of advertised routes in DOM format
193 * @param withdrawn Collection of withdrawn routes in DOM format
194 * @param attr Attributes MpReach is part of Attributes so we need to pass
195 * it as argument, create new AttributesBuilder with existing
196 * attributes and add MpReach
197 * @return Update message ready to be sent out
201 @Nonnull Collection<MapEntryNode> advertised,
202 @Nonnull Collection<MapEntryNode> withdrawn,
203 @Nonnull Attributes attr);
206 Class<? extends AddressFamily> getAfi();
209 Class<? extends SubsequentAddressFamily> getSafi();
212 * Creates Route table Peer InstanceIdentifier.
214 * @param tableKey table InstanceIdentifier
215 * @param newRouteKey route key
216 * @return InstanceIdentifier
219 InstanceIdentifier<R> createRouteIdentifier(
220 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
221 @Nonnull N newRouteKey);
224 * Creates a route with new path Id and attributes.
227 * @param routeKey route key
228 * @param pathId new path Id
229 * @param attributes route attributes
230 * @return Route List key
233 R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
235 interface ApplyRoute {
236 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
237 @Nonnull NodeIdentifierWithPredicates routeKey,
238 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
242 * Return the table-type-specific empty routes container, as augmented into the
243 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
244 * the skeleton nodes under which the individual routes will be stored.
246 * @return Protocol-specific case in the routes choice, may not be null.
249 Routes emptyRoutesContainer();
253 * Construct a Route List Key using new path Id for Families.
255 * @param pathId The path identifier
256 * @param routeKey RouteKey
257 * @return route list Key (RouteKey + pathId)
260 N createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);