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_VALUE;
12 import com.google.common.collect.ImmutableCollection;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Collection;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
26 import org.opendaylight.yangtools.yang.binding.ChildOf;
27 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.Identifiable;
30 import org.opendaylight.yangtools.yang.binding.Identifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
37 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
38 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
39 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
40 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
43 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
44 * to register an implementation of this class and the RIB core then calls into it
45 * to inquire about details specific to that particular model.
47 public interface RIBSupport<
48 C extends Routes & DataObject & ChoiceIn<Tables>,
49 S extends ChildOf<? super C>,
50 R extends Route & ChildOf<? super S> & Identifiable<I>,
51 I extends Identifier<R>> {
53 * Return the table-type-specific empty table with routes empty container, as augmented into the
54 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
55 * the skeleton nodes under which the individual routes will be stored.
57 * @return Protocol-specific case in the routes choice, may not be null.
60 MapEntryNode emptyTable();
63 * Return the localized identifier of the attributes route member, as expanded
64 * from the route grouping in the specific augmentation of the base routes choice.
66 * @return The attributes identifier, may not be null.
69 NodeIdentifier routeAttributesIdentifier();
72 * Return class object of the Routes Case statement.
77 Class<C> routesCaseClass();
80 * Return class object of the Routes Container statement.
85 Class<S> routesContainerClass();
88 * Return class object of the Routes List statement.
93 Class<R> routesListClass();
96 default ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
97 return ImmutableSet.of();
101 default ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
102 return ImmutableSet.of();
106 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
107 * from the DOM model and delete them from RIBs.
109 * @param tx DOMDataWriteTransaction
110 * @param tablePath YangInstanceIdentifier
111 * @param nlri ContainerNode DOM representation of NLRI in Update message
113 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
114 @Nonnull ContainerNode nlri);
118 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
119 * from the DOM model and delete them from RIBs.
121 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
122 * Provide {@link NodeIdentifier} with customized "routes" QName.
123 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
126 * @param tx DOMDataWriteTransaction
127 * @param tablePath YangInstanceIdentifier
128 * @param nlri ContainerNode DOM representation of NLRI in Update message
129 * @param routesNodeId NodeIdentifier of "routes" data node
131 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
132 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
135 * Given the NLRI as ContainerNode, this method should extract advertised routes
136 * from the DOM model and put them into RIBs.
138 * @param tx DOMDataWriteTransaction
139 * @param tablePath YangInstanceIdentifier
140 * @param nlri ContainerNode DOM representation of NLRI in Update message
141 * @param attributes ContainerNode
142 * @return List of processed route Identifiers
144 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
145 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
148 * Given the NLRI as ContainerNode, this method should extract advertised routes
149 * from the DOM model and put them into RIBs.
151 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
152 * Provide {@link NodeIdentifier} with customized "routes" QName.
153 * For default "bgp-rib" RIBs use {@link #putRoutes}
156 * @param tx DOMDataWriteTransaction
157 * @param tablePath YangInstanceIdentifier
158 * @param nlri ContainerNode DOM representation of NLRI in Update message
159 * @param attributes ContainerNode
160 * @param routesNodeId NodeIdentifier of "routes" data node
161 * @return List of processed routes identifiers
163 Collection<NodeIdentifierWithPredicates> putRoutes(@Nonnull DOMDataWriteTransaction tx,
164 @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes,
165 @Nonnull NodeIdentifier routesNodeId);
168 * Returns routes that were modified within this RIB support instance.
170 * @param routes DataTreeCandidateNode
171 * @return collection of modified nodes or empty collection if no node was modified
174 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
177 * Constructs an instance identifier path to routeId.
179 * @param routesPath YangInstanceIdentifier base path
180 * @param routeId PathArgument leaf path
181 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
184 default YangInstanceIdentifier routePath(@Nonnull final YangInstanceIdentifier routesPath,
185 @Nonnull final PathArgument routeId) {
186 return routesPath(routesPath).node(routeId);
190 * Constructs an instance identifier path to routes list.
192 * @param routesPath YangInstanceIdentifier base path
193 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path
196 YangInstanceIdentifier routesPath(@Nonnull YangInstanceIdentifier routesPath);
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
211 @Nonnull Collection<MapEntryNode> advertised,
212 @Nonnull Collection<MapEntryNode> withdrawn,
213 @Nonnull Attributes attr);
216 Class<? extends AddressFamily> getAfi();
219 Class<? extends SubsequentAddressFamily> getSafi();
222 * Creates Route table Peer InstanceIdentifier.
224 * @param tableKey table InstanceIdentifier
225 * @param newRouteKey route key
226 * @return InstanceIdentifier
229 InstanceIdentifier<R> createRouteIdentifier(
230 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
231 @Nonnull I newRouteKey);
234 * Creates a route with new path Id and attributes.
237 * @param routeKey route key
238 * @param pathId new path Id
239 * @param attributes route attributes
240 * @return Route List key
243 R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
246 * Returns TablesKey which we are providing support.
250 TablesKey getTablesKey();
252 interface ApplyRoute {
253 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
254 @Nonnull NodeIdentifierWithPredicates routeKey,
255 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
259 * Return the table-type-specific empty routes container, as augmented into the
260 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
261 * the skeleton nodes under which the individual routes will be stored.
263 * @return Protocol-specific case in the routes choice, may not be null.
270 * Return the table-type-specific empty routes container, as augmented into the
271 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
272 * the skeleton nodes under which the individual routes will be stored.
274 * @return Protocol-specific container in the routes, may not be null.
277 S emptyRoutesContainer();
280 * Construct a Route List Key using new path Id for Families.
282 * @param pathId The path identifier
283 * @param routeKey RouteKey
284 * @return route list Key (RouteKey + pathId)
287 I createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);
290 * Construct a Route List Key using new path Id for Families.
292 * @param routeKey RouteKey
293 * @return route list Key (RouteKey + empty pathId)
296 default I createRouteListKey(@Nonnull final String routeKey) {
297 return createRouteListKey(NON_PATH_ID_VALUE, routeKey);