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;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
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;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
29 import org.opendaylight.yangtools.yang.binding.BindingObject;
30 import org.opendaylight.yangtools.yang.binding.ChildOf;
31 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.Identifiable;
34 import org.opendaylight.yangtools.yang.binding.Identifier;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
40 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
41 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
42 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
43 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
44 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
45 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
48 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
49 * to register an implementation of this class and the RIB core then calls into it
50 * to inquire about details specific to that particular model.
52 public interface RIBSupport<
53 C extends Routes & DataObject & ChoiceIn<Tables>,
54 S extends ChildOf<? super C>,
55 R extends Route & ChildOf<? super S> & Identifiable<I>,
56 I extends Identifier<R>> {
58 * Return the table-type-specific empty table with routes empty container, as augmented into the
59 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
60 * the skeleton nodes under which the individual routes will be stored.
62 * @return Protocol-specific case in the routes choice, may not be null.
64 @NonNull 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.
72 @NonNull NodeIdentifier routeAttributesIdentifier();
75 * Return class object of the Routes Case statement.
79 @NonNull Class<C> routesCaseClass();
82 * Return class object of the Routes Container statement.
86 @NonNull Class<S> routesContainerClass();
89 * Return class object of the Routes List statement.
93 @NonNull Class<R> routesListClass();
95 default @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheableAttributeObjects() {
96 return ImmutableSet.of();
99 default @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheableNlriObjects() {
100 return ImmutableSet.of();
104 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
105 * from the DOM model and delete them from RIBs.
107 * @param tx DOMDataWriteTransaction
108 * @param tablePath YangInstanceIdentifier
109 * @param nlri ContainerNode DOM representation of NLRI in Update message
111 void deleteRoutes(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier tablePath,
112 @NonNull ContainerNode nlri);
115 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
116 * from the DOM model and delete them from RIBs.
118 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
119 * Provide {@link NodeIdentifier} with customized "routes" QName.
120 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
123 * @param tx DOMDataWriteTransaction
124 * @param tablePath YangInstanceIdentifier
125 * @param nlri ContainerNode DOM representation of NLRI in Update message
126 * @param routesNodeId NodeIdentifier of "routes" data node
128 void deleteRoutes(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier tablePath,
129 @NonNull ContainerNode nlri, @NonNull NodeIdentifier routesNodeId);
132 * Given the NLRI as ContainerNode, this method should extract advertised routes
133 * from the DOM model and put them into RIBs.
135 * @param tx DOMDataWriteTransaction
136 * @param tablePath YangInstanceIdentifier
137 * @param nlri ContainerNode DOM representation of NLRI in Update message
138 * @param attributes ContainerNode
139 * @return List of processed route Identifiers
141 Collection<NodeIdentifierWithPredicates> putRoutes(@NonNull DOMDataTreeWriteTransaction tx,
142 @NonNull YangInstanceIdentifier tablePath, @NonNull ContainerNode nlri, @NonNull ContainerNode attributes);
145 * Given the NLRI as ContainerNode, this method should extract advertised routes
146 * from the DOM model and put them into RIBs.
148 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
149 * Provide {@link NodeIdentifier} with customized "routes" QName.
150 * For default "bgp-rib" RIBs use {@link #putRoutes}
153 * @param tx DOMDataWriteTransaction
154 * @param tablePath YangInstanceIdentifier
155 * @param nlri ContainerNode DOM representation of NLRI in Update message
156 * @param attributes ContainerNode
157 * @param routesNodeId NodeIdentifier of "routes" data node
158 * @return List of processed routes identifiers
160 Collection<NodeIdentifierWithPredicates> putRoutes(@NonNull DOMDataTreeWriteTransaction tx,
161 @NonNull YangInstanceIdentifier tablePath, @NonNull ContainerNode nlri, @NonNull ContainerNode attributes,
162 @NonNull NodeIdentifier routesNodeId);
165 * Returns routes that were modified within this RIB support instance.
167 * @param routes DataTreeCandidateNode
168 * @return collection of modified nodes or empty collection if no node was modified
170 @NonNull Collection<DataTreeCandidateNode> changedRoutes(@NonNull DataTreeCandidateNode routes);
173 * Constructs an instance identifier path to routeId.
175 * @param routesPath YangInstanceIdentifier base path
176 * @param routeId PathArgument leaf path
177 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
179 default @NonNull YangInstanceIdentifier routePath(final @NonNull YangInstanceIdentifier routesPath,
180 final @NonNull PathArgument routeId) {
181 return routesPath(routesPath).node(routeId);
185 * Constructs an instance identifier path to routes list.
187 * @param routesPath YangInstanceIdentifier base path
188 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path
190 @NonNull YangInstanceIdentifier routesPath(@NonNull YangInstanceIdentifier routesPath);
193 * Return the relative path from the generic routes container to the AFI/SAFI specific route list.
195 * @return Relative path.
197 @NonNull List<PathArgument> relativeRoutesPath();
200 * To send routes out, we'd need to transform the DOM representation of route to
201 * binding-aware format. This needs to be done per each AFI/SAFI.
203 * @param advertised Collection of advertised routes in DOM format
204 * @param withdrawn Collection of withdrawn routes in DOM format
205 * @param attr Attributes MpReach is part of Attributes so we need to pass
206 * it as argument, create new AttributesBuilder with existing
207 * attributes and add MpReach
208 * @return Update message ready to be sent out
210 @NonNull Update buildUpdate(@NonNull Collection<MapEntryNode> advertised,
211 @NonNull Collection<MapEntryNode> withdrawn, @NonNull Attributes attr);
213 @NonNull Class<? extends AddressFamily> getAfi();
215 @NonNull Class<? extends SubsequentAddressFamily> getSafi();
218 * Creates Route table Peer InstanceIdentifier.
220 * @param tableKey table InstanceIdentifier
221 * @param newRouteKey route key
222 * @return InstanceIdentifier
224 @NonNull InstanceIdentifier<R> createRouteIdentifier(@NonNull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
225 @NonNull I newRouteKey);
228 * Creates a route with new path Id and attributes.
231 * @param key route key
232 * @param attributes route attributes
233 * @return Route List key
235 @NonNull R createRoute(@Nullable R route, @NonNull I key, @NonNull Attributes attributes);
238 * Returns TablesKey which we are providing support.
242 TablesKey getTablesKey();
245 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding Route.
247 * @param routerId Binding Instance Identifier
248 * @param normalizedNode NormalizedNode representing Route
251 R fromNormalizedNode(YangInstanceIdentifier routerId, NormalizedNode<?, ?> normalizedNode);
254 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data Attribute.
255 * @param advertisedAttrs NormalizedNode representing attributes
258 Attributes attributeFromContainerNode(ContainerNode advertisedAttrs);
261 * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
262 * @param routePath Binding Instance Identifier pointing to data
263 * @param attributes Data object representing Attributes
264 * @return NormalizedNode representation
266 ContainerNode attributeToContainerNode(YangInstanceIdentifier routePath, Attributes attributes);
268 interface ApplyRoute {
269 void apply(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier base,
270 @NonNull NodeIdentifierWithPredicates routeKey, @NonNull DataContainerNode<?> route,
271 ContainerNode attributes);
275 * Return the table-type-specific empty routes container, as augmented into the
276 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
277 * the skeleton nodes under which the individual routes will be stored.
279 * @return Protocol-specific container in the routes, may not be null.
281 @NonNull S emptyRoutesContainer();
284 * Construct a Route List Key using new path Id for Families.
286 * @param pathId The path identifier
287 * @param routeKey RouteKey
288 * @return route list Key (RouteKey + pathId)
290 @NonNull I createRouteListKey(@NonNull PathId pathId, @NonNull String routeKey);
293 * Construct a Route List Key.
295 * @param routeKey RouteKey
296 * @return route list Key (RouteKey + empty pathId)
298 default @NonNull I createRouteListKey(final @NonNull String routeKey) {
299 return createRouteListKey(NON_PATH_ID, routeKey);
303 * Given a route list key, return the associated path ID.
305 * @param routeListKey Route list key
308 @NonNull PathId extractPathId(@NonNull I routeListKey);
311 * Given a route list key, return the associated path ID.
313 * @param routeListKey Route list key
316 @NonNull String extractRouteKey(@NonNull I routeListKey);
319 * Extract a route list from the adj-rib-in instantiation of table routes.
321 * @param routes Table route choice
322 * @return A potentially empty list of routes
324 @NonNull Map<I, R> extractAdjRibInRoutes(Routes routes);