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.ChildOf;
29 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.binding.Identifiable;
32 import org.opendaylight.yangtools.yang.binding.Identifier;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
39 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
40 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
41 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
42 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
45 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
46 * to register an implementation of this class and the RIB core then calls into it
47 * to inquire about details specific to that particular model.
49 public interface RIBSupport<
50 C extends Routes & DataObject & ChoiceIn<Tables>,
51 S extends ChildOf<? super C>,
52 R extends Route & ChildOf<? super S> & Identifiable<I>,
53 I extends Identifier<R>> {
55 * Return the table-type-specific empty table with routes empty container, as augmented into the
56 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
57 * the skeleton nodes under which the individual routes will be stored.
59 * @return Protocol-specific case in the routes choice, may not be null.
62 MapEntryNode emptyTable();
65 * Return the localized identifier of the attributes route member, as expanded
66 * from the route grouping in the specific augmentation of the base routes choice.
68 * @return The attributes identifier, may not be null.
71 NodeIdentifier routeAttributesIdentifier();
74 * Return class object of the Routes Case statement.
79 Class<C> routesCaseClass();
82 * Return class object of the Routes Container statement.
87 Class<S> routesContainerClass();
90 * Return class object of the Routes List statement.
95 Class<R> routesListClass();
98 default ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
99 return ImmutableSet.of();
103 default ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
104 return ImmutableSet.of();
108 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
109 * from the DOM model and delete them from RIBs.
111 * @param tx DOMDataWriteTransaction
112 * @param tablePath YangInstanceIdentifier
113 * @param nlri ContainerNode DOM representation of NLRI in Update message
115 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
116 @Nonnull ContainerNode nlri);
120 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
121 * from the DOM model and delete them from RIBs.
123 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
124 * Provide {@link NodeIdentifier} with customized "routes" QName.
125 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
128 * @param tx DOMDataWriteTransaction
129 * @param tablePath YangInstanceIdentifier
130 * @param nlri ContainerNode DOM representation of NLRI in Update message
131 * @param routesNodeId NodeIdentifier of "routes" data node
133 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
134 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
137 * Given the NLRI as ContainerNode, this method should extract advertised routes
138 * from the DOM model and put them into RIBs.
140 * @param tx DOMDataWriteTransaction
141 * @param tablePath YangInstanceIdentifier
142 * @param nlri ContainerNode DOM representation of NLRI in Update message
143 * @param attributes ContainerNode
144 * @return List of processed route Identifiers
146 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
147 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
150 * Given the NLRI as ContainerNode, this method should extract advertised routes
151 * from the DOM model and put them into RIBs.
153 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
154 * Provide {@link NodeIdentifier} with customized "routes" QName.
155 * For default "bgp-rib" RIBs use {@link #putRoutes}
158 * @param tx DOMDataWriteTransaction
159 * @param tablePath YangInstanceIdentifier
160 * @param nlri ContainerNode DOM representation of NLRI in Update message
161 * @param attributes ContainerNode
162 * @param routesNodeId NodeIdentifier of "routes" data node
163 * @return List of processed routes identifiers
165 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
166 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes,
167 @Nonnull NodeIdentifier routesNodeId);
170 * Returns routes that were modified within this RIB support instance.
172 * @param routes DataTreeCandidateNode
173 * @return collection of modified nodes or empty collection if no node was modified
176 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
179 * Constructs an instance identifier path to routeId.
181 * @param routesPath YangInstanceIdentifier base path
182 * @param routeId PathArgument leaf path
183 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
186 default YangInstanceIdentifier routePath(@Nonnull final YangInstanceIdentifier routesPath,
187 @Nonnull final PathArgument routeId) {
188 return routesPath(routesPath).node(routeId);
192 * Constructs an instance identifier path to routes list.
194 * @param routesPath YangInstanceIdentifier base path
195 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path
198 YangInstanceIdentifier routesPath(@Nonnull YangInstanceIdentifier routesPath);
201 * To send routes out, we'd need to transform the DOM representation of route to
202 * binding-aware format. This needs to be done per each AFI/SAFI.
204 * @param advertised Collection of advertised routes in DOM format
205 * @param withdrawn Collection of withdrawn routes in DOM format
206 * @param attr Attributes MpReach is part of Attributes so we need to pass
207 * it as argument, create new AttributesBuilder with existing
208 * attributes and add MpReach
209 * @return Update message ready to be sent out
213 @Nonnull Collection<MapEntryNode> advertised,
214 @Nonnull Collection<MapEntryNode> withdrawn,
215 @Nonnull Attributes attr);
218 Class<? extends AddressFamily> getAfi();
221 Class<? extends SubsequentAddressFamily> getSafi();
224 * Creates Route table Peer InstanceIdentifier.
226 * @param tableKey table InstanceIdentifier
227 * @param newRouteKey route key
228 * @return InstanceIdentifier
231 InstanceIdentifier<R> createRouteIdentifier(
232 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
233 @Nonnull I newRouteKey);
236 * Creates a route with new path Id and attributes.
239 * @param key route key
240 * @param attributes route attributes
241 * @return Route List key
244 R createRoute(@Nullable R route, @Nonnull I key, @Nonnull Attributes attributes);
247 * Returns TablesKey which we are providing support.
251 TablesKey getTablesKey();
253 interface ApplyRoute {
254 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
255 @Nonnull NodeIdentifierWithPredicates routeKey,
256 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
260 * Return the table-type-specific empty routes container, as augmented into the
261 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
262 * the skeleton nodes under which the individual routes will be stored.
264 * @return Protocol-specific case in the routes choice, may not be null.
271 * Return the table-type-specific empty routes container, as augmented into the
272 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
273 * the skeleton nodes under which the individual routes will be stored.
275 * @return Protocol-specific container in the routes, may not be null.
278 S emptyRoutesContainer();
281 * Construct a Route List Key using new path Id for Families.
283 * @param pathId The path identifier
284 * @param routeKey RouteKey
285 * @return route list Key (RouteKey + pathId)
288 I createRouteListKey(@Nonnull PathId pathId, @Nonnull String routeKey);
291 * Construct a Route List Key.
293 * @param routeKey RouteKey
294 * @return route list Key (RouteKey + empty pathId)
297 default I createRouteListKey(@Nonnull final String routeKey) {
298 return createRouteListKey(NON_PATH_ID, routeKey);
302 * Given a route list key, return the associated path ID.
304 * @param routeListKey Route list key
308 PathId extractPathId(@Nonnull I routeListKey);
311 * Given a route list key, return the associated path ID.
313 * @param routeListKey Route list key
317 String extractRouteKey(@Nonnull I routeListKey);
320 * Extract a route list from the adj-rib-in instantiation of table routes.
322 * @param routes Table route choice
323 * @return A potentially empty list of routes
326 List<R> extractAdjRibInRoutes(Routes routes);