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.ContainerNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
37 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
38 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
41 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
42 * to register an implementation of this class and the RIB core then calls into it
43 * to inquire about details specific to that particular model.
45 public interface RIBSupport<
46 C extends Routes & DataObject & ChoiceIn<Tables>,
47 S extends ChildOf<? super C>,
48 R extends Route & ChildOf<? super S> & Identifiable<I>,
49 I extends Identifier<R>> {
51 * Return the table-type-specific empty table with routes empty container, as augmented into the
52 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
53 * the skeleton nodes under which the individual routes will be stored.
55 * @return Protocol-specific case in the routes choice, may not be null.
58 MapEntryNode emptyTable();
61 * Return the localized identifier of the attributes route member, as expanded
62 * from the route grouping in the specific augmentation of the base routes choice.
64 * @return The attributes identifier, may not be null.
67 NodeIdentifier routeAttributesIdentifier();
70 * Return class object of the Routes Case statement.
75 Class<C> routesCaseClass();
78 * Return class object of the Routes Container statement.
83 Class<S> routesContainerClass();
86 * Return class object of the Routes List statement.
91 Class<R> routesListClass();
94 default ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
95 return ImmutableSet.of();
99 default ImmutableCollection<Class<? extends DataObject>> 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 DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
112 @Nonnull ContainerNode nlri);
116 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
117 * from the DOM model and delete them from RIBs.
119 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
120 * Provide {@link NodeIdentifier} with customized "routes" QName.
121 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
124 * @param tx DOMDataWriteTransaction
125 * @param tablePath YangInstanceIdentifier
126 * @param nlri ContainerNode DOM representation of NLRI in Update message
127 * @param routesNodeId NodeIdentifier of "routes" data node
129 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
130 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
133 * Given the NLRI as ContainerNode, this method should extract advertised routes
134 * from the DOM model and put them into RIBs.
136 * @param tx DOMDataWriteTransaction
137 * @param tablePath YangInstanceIdentifier
138 * @param nlri ContainerNode DOM representation of NLRI in Update message
139 * @param attributes ContainerNode
141 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
142 @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
159 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
160 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
163 * Returns routes that were modified within this RIB support instance.
165 * @param routes DataTreeCandidateNode
166 * @return collection of modified nodes or empty collection if no node was modified
169 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
179 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
180 @Nonnull PathArgument routeId);
183 * To send routes out, we'd need to transform the DOM representation of route to
184 * binding-aware format. This needs to be done per each AFI/SAFI.
186 * @param advertised Collection of advertised routes in DOM format
187 * @param withdrawn Collection of withdrawn routes in DOM format
188 * @param attr Attributes MpReach is part of Attributes so we need to pass
189 * it as argument, create new AttributesBuilder with existing
190 * attributes and add MpReach
191 * @return Update message ready to be sent out
195 @Nonnull Collection<MapEntryNode> advertised,
196 @Nonnull Collection<MapEntryNode> withdrawn,
197 @Nonnull Attributes attr);
200 Class<? extends AddressFamily> getAfi();
203 Class<? extends SubsequentAddressFamily> getSafi();
206 * Creates Route table Peer InstanceIdentifier.
208 * @param tableKey table InstanceIdentifier
209 * @param newRouteKey route key
210 * @return InstanceIdentifier
213 InstanceIdentifier<R> createRouteIdentifier(
214 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
215 @Nonnull I newRouteKey);
218 * Creates a route with new path Id and attributes.
221 * @param routeKey route key
222 * @param pathId new path Id
223 * @param attributes route attributes
224 * @return Route List key
227 R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
230 * Returns TablesKey which we are providing support.
234 TablesKey getTablesKey();
236 interface ApplyRoute {
237 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
238 @Nonnull NodeIdentifierWithPredicates routeKey,
239 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
243 * Return the table-type-specific empty routes container, as augmented into the
244 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
245 * the skeleton nodes under which the individual routes will be stored.
247 * @return Protocol-specific case in the routes choice, may not be null.
253 * Return the table-type-specific empty routes container, as augmented into the
254 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all
255 * the skeleton nodes under which the individual routes will be stored.
257 * @return Protocol-specific container in the routes, may not be null.
260 S emptyRoutesContainer();
265 * Construct a Route List Key using new path Id for Families.
267 * @param pathId The path identifier
268 * @param routeKey RouteKey
269 * @return route list Key (RouteKey + pathId)
272 I createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);