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 com.google.common.collect.ImmutableCollection;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
24 import org.opendaylight.yangtools.yang.binding.ChildOf;
25 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.Identifiable;
28 import org.opendaylight.yangtools.yang.binding.Identifier;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
35 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
37 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
38 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
39 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
42 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
43 * to register an implementation of this class and the RIB core then calls into it
44 * to inquire about details specific to that particular model.
46 public interface RIBSupport<
47 C extends Routes & DataObject & ChoiceIn<Tables>,
48 S extends ChildOf<? super C>,
49 R extends Route & ChildOf<? super S> & Identifiable<I>,
50 I extends Identifier<R>> {
52 * Return the table-type-specific empty routes container, as augmented into the
53 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
54 * the skeleton nodes under which the individual routes will be stored.
56 * @return Protocol-specific case in the routes choice, may not be null.
59 ChoiceNode emptyRoutes();
62 * Return the localized identifier of the attributes route member, as expanded
63 * from the route grouping in the specific augmentation of the base routes choice.
65 * @return The attributes identifier, may not be null.
68 NodeIdentifier routeAttributesIdentifier();
71 * Return class object of the Routes Case statement.
76 Class<C> routesCaseClass();
79 * Return class object of the Routes Container statement.
84 Class<S> routesContainerClass();
87 * Return class object of the Routes List statement.
92 Class<R> routesListClass();
95 default ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
96 return ImmutableSet.of();
100 default ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
101 return ImmutableSet.of();
105 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
106 * from the DOM model and delete them from RIBs.
108 * @param tx DOMDataWriteTransaction
109 * @param tablePath YangInstanceIdentifier
110 * @param nlri ContainerNode DOM representation of NLRI in Update message
112 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
113 @Nonnull ContainerNode nlri);
117 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
118 * from the DOM model and delete them from RIBs.
120 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
121 * Provide {@link NodeIdentifier} with customized "routes" QName.
122 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
125 * @param tx DOMDataWriteTransaction
126 * @param tablePath YangInstanceIdentifier
127 * @param nlri ContainerNode DOM representation of NLRI in Update message
128 * @param routesNodeId NodeIdentifier of "routes" data node
130 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
131 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
134 * Given the NLRI as ContainerNode, this method should extract advertised routes
135 * from the DOM model and put them into RIBs.
137 * @param tx DOMDataWriteTransaction
138 * @param tablePath YangInstanceIdentifier
139 * @param nlri ContainerNode DOM representation of NLRI in Update message
140 * @param attributes ContainerNode
142 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
143 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
146 * Given the NLRI as ContainerNode, this method should extract advertised routes
147 * from the DOM model and put them into RIBs.
149 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
150 * Provide {@link NodeIdentifier} with customized "routes" QName.
151 * For default "bgp-rib" RIBs use {@link #putRoutes}
154 * @param tx DOMDataWriteTransaction
155 * @param tablePath YangInstanceIdentifier
156 * @param nlri ContainerNode DOM representation of NLRI in Update message
157 * @param attributes ContainerNode
158 * @param routesNodeId NodeIdentifier of "routes" data node
160 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
161 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @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
170 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
180 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
181 @Nonnull PathArgument routeId);
184 * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
185 * only have their key and attributes, complex routes are those which include more structured data.
187 * @return True if this is a complex route, false otherwise.
188 * @deprecated All routes are complex.
191 default boolean isComplexRoute() {
196 * To send routes out, we'd need to transform the DOM representation of route to
197 * binding-aware format. This needs to be done per each AFI/SAFI.
199 * @param advertised Collection of advertised routes in DOM format
200 * @param withdrawn Collection of withdrawn routes in DOM format
201 * @param attr Attributes MpReach is part of Attributes so we need to pass
202 * it as argument, create new AttributesBuilder with existing
203 * attributes and add MpReach
204 * @return Update message ready to be sent out
208 @Nonnull Collection<MapEntryNode> advertised,
209 @Nonnull Collection<MapEntryNode> withdrawn,
210 @Nonnull Attributes attr);
213 Class<? extends AddressFamily> getAfi();
216 Class<? extends SubsequentAddressFamily> getSafi();
219 * Creates Route table Peer InstanceIdentifier.
221 * @param tableKey table InstanceIdentifier
222 * @param newRouteKey route key
223 * @return InstanceIdentifier
226 InstanceIdentifier<R> createRouteIdentifier(
227 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
228 @Nonnull I newRouteKey);
231 * Creates a route with new path Id and attributes.
234 * @param routeKey route key
235 * @param pathId new path Id
236 * @param attributes route attributes
237 * @return Route List key
240 R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
243 * Returns TablesKey which we are providing support.
247 TablesKey getTablesKey();
249 interface ApplyRoute {
250 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
251 @Nonnull NodeIdentifierWithPredicates routeKey,
252 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
256 * Return the table-type-specific empty routes container, as augmented into the
257 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
258 * the skeleton nodes under which the individual routes will be stored.
260 * @return Protocol-specific case in the routes choice, may not be null.
266 * Return the table-type-specific empty routes container, as augmented into the
267 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
268 * the skeleton nodes under which the individual routes will be stored.
270 * @return Protocol-specific container in the routes, may not be null.
273 S emptyRoutesContainer();
278 * Construct a Route List Key using new path Id for Families.
280 * @param pathId The path identifier
281 * @param routeKey RouteKey
282 * @return route list Key (RouteKey + pathId)
285 I createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);