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 org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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.rev200120.AddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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.
63 @NonNull MapEntryNode emptyTable();
66 * Return the localized identifier of the attributes route member, as expanded
67 * from the route grouping in the specific augmentation of the base routes choice.
69 * @return The attributes identifier, may not be null.
71 @NonNull NodeIdentifier routeAttributesIdentifier();
74 * Return class object of the Routes Case statement.
78 @NonNull Class<C> routesCaseClass();
81 * Return class object of the Routes Container statement.
85 @NonNull Class<S> routesContainerClass();
88 * Return class object of the Routes List statement.
92 @NonNull Class<R> routesListClass();
94 default @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheableAttributeObjects() {
95 return ImmutableSet.of();
98 default @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheableNlriObjects() {
99 return ImmutableSet.of();
103 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
104 * from the DOM model and delete them from RIBs.
106 * @param tx DOMDataWriteTransaction
107 * @param tablePath YangInstanceIdentifier
108 * @param nlri ContainerNode DOM representation of NLRI in Update message
110 void deleteRoutes(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier tablePath,
111 @NonNull ContainerNode nlri);
114 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
115 * from the DOM model and delete them from RIBs.
117 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
118 * Provide {@link NodeIdentifier} with customized "routes" QName.
119 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
122 * @param tx DOMDataWriteTransaction
123 * @param tablePath YangInstanceIdentifier
124 * @param nlri ContainerNode DOM representation of NLRI in Update message
125 * @param routesNodeId NodeIdentifier of "routes" data node
127 void deleteRoutes(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier tablePath,
128 @NonNull ContainerNode nlri, @NonNull NodeIdentifier routesNodeId);
131 * Given the NLRI as ContainerNode, this method should extract advertised routes
132 * from the DOM model and put them into RIBs.
134 * @param tx DOMDataWriteTransaction
135 * @param tablePath YangInstanceIdentifier
136 * @param nlri ContainerNode DOM representation of NLRI in Update message
137 * @param attributes ContainerNode
138 * @return List of processed route Identifiers
140 Collection<NodeIdentifierWithPredicates> putRoutes(@NonNull DOMDataTreeWriteTransaction tx,
141 @NonNull YangInstanceIdentifier tablePath, @NonNull ContainerNode nlri, @NonNull ContainerNode attributes);
144 * Given the NLRI as ContainerNode, this method should extract advertised routes
145 * from the DOM model and put them into RIBs.
147 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
148 * Provide {@link NodeIdentifier} with customized "routes" QName.
149 * For default "bgp-rib" RIBs use {@link #putRoutes}
152 * @param tx DOMDataWriteTransaction
153 * @param tablePath YangInstanceIdentifier
154 * @param nlri ContainerNode DOM representation of NLRI in Update message
155 * @param attributes ContainerNode
156 * @param routesNodeId NodeIdentifier of "routes" data node
157 * @return List of processed routes identifiers
159 Collection<NodeIdentifierWithPredicates> putRoutes(@NonNull DOMDataTreeWriteTransaction tx,
160 @NonNull YangInstanceIdentifier tablePath, @NonNull ContainerNode nlri, @NonNull ContainerNode attributes,
161 @NonNull NodeIdentifier routesNodeId);
164 * Returns routes that were modified within this RIB support instance.
166 * @param routes DataTreeCandidateNode
167 * @return collection of modified nodes or empty collection if no node was modified
169 @NonNull Collection<DataTreeCandidateNode> changedRoutes(@NonNull DataTreeCandidateNode routes);
172 * Constructs an instance identifier path to routeId.
174 * @param routesPath YangInstanceIdentifier base path
175 * @param routeId PathArgument leaf path
176 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
178 default @NonNull YangInstanceIdentifier routePath(final @NonNull YangInstanceIdentifier routesPath,
179 final @NonNull PathArgument routeId) {
180 return routesPath(routesPath).node(routeId);
184 * Constructs an instance identifier path to routes list.
186 * @param routesPath YangInstanceIdentifier base path
187 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path
189 @NonNull YangInstanceIdentifier routesPath(@NonNull YangInstanceIdentifier routesPath);
192 * Return the relative path from the generic routes container to the AFI/SAFI specific route list.
194 * @return Relative path.
196 @NonNull List<PathArgument> relativeRoutesPath();
199 * To send routes out, we'd need to transform the DOM representation of route to
200 * binding-aware format. This needs to be done per each AFI/SAFI.
202 * @param advertised Collection of advertised routes in DOM format
203 * @param withdrawn Collection of withdrawn routes in DOM format
204 * @param attr Attributes MpReach is part of Attributes so we need to pass
205 * it as argument, create new AttributesBuilder with existing
206 * attributes and add MpReach
207 * @return Update message ready to be sent out
209 @NonNull Update buildUpdate(@NonNull Collection<MapEntryNode> advertised,
210 @NonNull Collection<MapEntryNode> withdrawn, @NonNull Attributes attr);
212 @NonNull Class<? extends AddressFamily> getAfi();
214 @NonNull Class<? extends SubsequentAddressFamily> getSafi();
217 * Creates Route table Peer InstanceIdentifier.
219 * @param tableKey table InstanceIdentifier
220 * @param newRouteKey route key
221 * @return InstanceIdentifier
223 @NonNull InstanceIdentifier<R> createRouteIdentifier(@NonNull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
224 @NonNull I newRouteKey);
227 * Creates a route with new path Id and attributes.
230 * @param key route key
231 * @param attributes route attributes
232 * @return Route List key
234 @NonNull R createRoute(@Nullable R route, @NonNull I key, @NonNull Attributes attributes);
237 * Returns TablesKey which we are providing support.
241 TablesKey getTablesKey();
244 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding Route.
246 * @param routerId Binding Instance Identifier
247 * @param normalizedNode NormalizedNode representing Route
250 R fromNormalizedNode(YangInstanceIdentifier routerId, NormalizedNode<?, ?> normalizedNode);
253 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data Attribute.
254 * @param advertisedAttrs NormalizedNode representing attributes
257 Attributes attributeFromContainerNode(ContainerNode advertisedAttrs);
260 * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
261 * @param routePath Binding Instance Identifier pointing to data
262 * @param attributes Data object representing Attributes
263 * @return NormalizedNode representation
265 ContainerNode attributeToContainerNode(YangInstanceIdentifier routePath, Attributes attributes);
267 interface ApplyRoute {
268 void apply(@NonNull DOMDataTreeWriteTransaction tx, @NonNull YangInstanceIdentifier base,
269 @NonNull NodeIdentifierWithPredicates routeKey, @NonNull DataContainerNode<?> route,
270 ContainerNode attributes);
274 * Return the table-type-specific empty routes container, as augmented into the
275 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
276 * the skeleton nodes under which the individual routes will be stored.
278 * @return Protocol-specific container in the routes, may not be null.
280 @NonNull S emptyRoutesContainer();
283 * Construct a Route List Key using new path Id for Families.
285 * @param pathId The path identifier
286 * @param routeKey RouteKey
287 * @return route list Key (RouteKey + pathId)
289 @NonNull I createRouteListKey(@NonNull PathId pathId, @NonNull String routeKey);
292 * Construct a Route List Key.
294 * @param routeKey RouteKey
295 * @return route list Key (RouteKey + empty pathId)
297 default @NonNull I createRouteListKey(final @NonNull 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
307 @NonNull PathId extractPathId(@NonNull I routeListKey);
310 * Given a route list key, return the associated path ID.
312 * @param routeListKey Route list key
315 @NonNull String extractRouteKey(@NonNull I routeListKey);
318 * Extract a route list from the adj-rib-in instantiation of table routes.
320 * @param routes Table route choice
321 * @return A potentially empty list of routes
323 @NonNull List<R> extractAdjRibInRoutes(Routes routes);