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 static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
12 import com.google.common.collect.ImmutableCollection;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Collection;
15 import java.util.List;
16 import javax.annotation.Nonnull;
17 import javax.annotation.Nullable;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
28 import org.opendaylight.yangtools.yang.binding.BindingObject;
29 import org.opendaylight.yangtools.yang.binding.ChildOf;
30 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.Identifiable;
33 import org.opendaylight.yangtools.yang.binding.Identifier;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
40 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
41 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
42 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
43 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
44 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
47 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
48 * to register an implementation of this class and the RIB core then calls into it
49 * to inquire about details specific to that particular model.
51 public interface RIBSupport<
52 C extends Routes & DataObject & ChoiceIn<Tables>,
53 S extends ChildOf<? super C>,
54 R extends Route & ChildOf<? super S> & Identifiable<I>,
55 I extends Identifier<R>> {
57 * Return the table-type-specific empty table with routes empty container, as augmented into the
58 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
59 * the skeleton nodes under which the individual routes will be stored.
61 * @return Protocol-specific case in the routes choice, may not be null.
64 MapEntryNode emptyTable();
67 * Return the localized identifier of the attributes route member, as expanded
68 * from the route grouping in the specific augmentation of the base routes choice.
70 * @return The attributes identifier, may not be null.
73 NodeIdentifier routeAttributesIdentifier();
76 * Return class object of the Routes Case statement.
81 Class<C> routesCaseClass();
84 * Return class object of the Routes Container statement.
89 Class<S> routesContainerClass();
92 * Return class object of the Routes List statement.
97 Class<R> routesListClass();
100 default ImmutableCollection<Class<? extends BindingObject>> cacheableAttributeObjects() {
101 return ImmutableSet.of();
105 default ImmutableCollection<Class<? extends BindingObject>> cacheableNlriObjects() {
106 return ImmutableSet.of();
110 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
111 * from the DOM model and delete them from RIBs.
113 * @param tx DOMDataWriteTransaction
114 * @param tablePath YangInstanceIdentifier
115 * @param nlri ContainerNode DOM representation of NLRI in Update message
117 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
118 @Nonnull ContainerNode nlri);
122 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
123 * from the DOM model and delete them from RIBs.
125 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
126 * Provide {@link NodeIdentifier} with customized "routes" QName.
127 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
130 * @param tx DOMDataWriteTransaction
131 * @param tablePath YangInstanceIdentifier
132 * @param nlri ContainerNode DOM representation of NLRI in Update message
133 * @param routesNodeId NodeIdentifier of "routes" data node
135 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
136 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
139 * Given the NLRI as ContainerNode, this method should extract advertised routes
140 * from the DOM model and put them into RIBs.
142 * @param tx DOMDataWriteTransaction
143 * @param tablePath YangInstanceIdentifier
144 * @param nlri ContainerNode DOM representation of NLRI in Update message
145 * @param attributes ContainerNode
146 * @return List of processed route Identifiers
148 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
149 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
152 * Given the NLRI as ContainerNode, this method should extract advertised routes
153 * from the DOM model and put them into RIBs.
155 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
156 * Provide {@link NodeIdentifier} with customized "routes" QName.
157 * For default "bgp-rib" RIBs use {@link #putRoutes}
160 * @param tx DOMDataWriteTransaction
161 * @param tablePath YangInstanceIdentifier
162 * @param nlri ContainerNode DOM representation of NLRI in Update message
163 * @param attributes ContainerNode
164 * @param routesNodeId NodeIdentifier of "routes" data node
165 * @return List of processed routes identifiers
167 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
168 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes,
169 @Nonnull NodeIdentifier routesNodeId);
172 * Returns routes that were modified within this RIB support instance.
174 * @param routes DataTreeCandidateNode
175 * @return collection of modified nodes or empty collection if no node was modified
178 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
181 * Constructs an instance identifier path to routeId.
183 * @param routesPath YangInstanceIdentifier base path
184 * @param routeId PathArgument leaf path
185 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
188 default YangInstanceIdentifier routePath(@Nonnull final YangInstanceIdentifier routesPath,
189 @Nonnull final PathArgument routeId) {
190 return routesPath(routesPath).node(routeId);
194 * Constructs an instance identifier path to routes list.
196 * @param routesPath YangInstanceIdentifier base path
197 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path
200 YangInstanceIdentifier routesPath(@Nonnull YangInstanceIdentifier routesPath);
203 * Return the relative path from the generic routes container to the AFI/SAFI specific route list.
205 * @return Relative path.
208 List<PathArgument> relativeRoutesPath();
211 * To send routes out, we'd need to transform the DOM representation of route to
212 * binding-aware format. This needs to be done per each AFI/SAFI.
214 * @param advertised Collection of advertised routes in DOM format
215 * @param withdrawn Collection of withdrawn routes in DOM format
216 * @param attr Attributes MpReach is part of Attributes so we need to pass
217 * it as argument, create new AttributesBuilder with existing
218 * attributes and add MpReach
219 * @return Update message ready to be sent out
223 @Nonnull Collection<MapEntryNode> advertised,
224 @Nonnull Collection<MapEntryNode> withdrawn,
225 @Nonnull Attributes attr);
228 Class<? extends AddressFamily> getAfi();
231 Class<? extends SubsequentAddressFamily> getSafi();
234 * Creates Route table Peer InstanceIdentifier.
236 * @param tableKey table InstanceIdentifier
237 * @param newRouteKey route key
238 * @return InstanceIdentifier
241 InstanceIdentifier<R> createRouteIdentifier(
242 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
243 @Nonnull I newRouteKey);
246 * Creates a route with new path Id and attributes.
249 * @param key route key
250 * @param attributes route attributes
251 * @return Route List key
254 R createRoute(@Nullable R route, @Nonnull I key, @Nonnull Attributes attributes);
257 * Returns TablesKey which we are providing support.
261 TablesKey getTablesKey();
264 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding Route.
266 * @param routerId Binding Instance Identifier
267 * @param normalizedNode NormalizedNode representing Route
270 R fromNormalizedNode(YangInstanceIdentifier routerId, NormalizedNode<?, ?> normalizedNode);
273 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data Attribute.
274 * @param advertisedAttrs NormalizedNode representing attributes
277 Attributes attributeFromContainerNode(ContainerNode advertisedAttrs);
280 * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
281 * @param routePath Binding Instance Identifier pointing to data
282 * @param attributes Data object representing Attributes
283 * @return NormalizedNode representation
285 ContainerNode attributeToContainerNode(YangInstanceIdentifier routePath, Attributes attributes);
287 interface ApplyRoute {
288 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
289 @Nonnull NodeIdentifierWithPredicates routeKey,
290 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
294 * Return the table-type-specific empty routes container, as augmented into the
295 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
296 * the skeleton nodes under which the individual routes will be stored.
298 * @return Protocol-specific case in the routes choice, may not be null.
305 * Return the table-type-specific empty routes container, as augmented into the
306 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
307 * the skeleton nodes under which the individual routes will be stored.
309 * @return Protocol-specific container in the routes, may not be null.
312 S emptyRoutesContainer();
315 * Construct a Route List Key using new path Id for Families.
317 * @param pathId The path identifier
318 * @param routeKey RouteKey
319 * @return route list Key (RouteKey + pathId)
322 I createRouteListKey(@Nonnull PathId pathId, @Nonnull String routeKey);
325 * Construct a Route List Key.
327 * @param routeKey RouteKey
328 * @return route list Key (RouteKey + empty pathId)
331 default I createRouteListKey(@Nonnull final String routeKey) {
332 return createRouteListKey(NON_PATH_ID, routeKey);
336 * Given a route list key, return the associated path ID.
338 * @param routeListKey Route list key
342 PathId extractPathId(@Nonnull I routeListKey);
345 * Given a route list key, return the associated path ID.
347 * @param routeListKey Route list key
351 String extractRouteKey(@Nonnull I routeListKey);
354 * Extract a route list from the adj-rib-in instantiation of table routes.
356 * @param routes Table route choice
357 * @return A potentially empty list of routes
360 List<R> extractAdjRibInRoutes(Routes routes);