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 java.util.Collection;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.Identifier;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
31 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
38 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
39 * to register an implementation of this class and the RIB core then calls into it
40 * to inquire about details specific to that particular model.
42 public interface RIBSupport<R extends Route, N extends Identifier> extends AddPathRibSupport {
44 * Return the table-type-specific empty routes container, as augmented into the
45 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
46 * the skeleton nodes under which the individual routes will be stored.
48 * @return Protocol-specific case in the routes choice, may not be null.
51 ChoiceNode emptyRoutes();
54 * Return the localized identifier of the attributes route member, as expanded
55 * from the route grouping in the specific augmentation of the base routes choice.
57 * @return The attributes identifier, may not be null.
60 NodeIdentifier routeAttributesIdentifier();
63 * Return class object of the Routes Case statement.
68 Class<? extends Routes> routesCaseClass();
71 * Return class object of the Routes Container statement.
76 Class<? extends DataObject> routesContainerClass();
79 * Return class object of the Routes List statement.
84 Class<? extends Route> routesListClass();
87 ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
90 ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
93 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
94 * from the DOM model and delete them from RIBs.
96 * @param tx DOMDataWriteTransaction
97 * @param tablePath YangInstanceIdentifier
98 * @param nlri ContainerNode DOM representation of NLRI in Update message
100 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
101 @Nonnull ContainerNode nlri);
105 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
106 * from the DOM model and delete them from RIBs.
108 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
109 * Provide {@link NodeIdentifier} with customized "routes" QName.
110 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
113 * @param tx DOMDataWriteTransaction
114 * @param tablePath YangInstanceIdentifier
115 * @param nlri ContainerNode DOM representation of NLRI in Update message
116 * @param routesNodeId NodeIdentifier of "routes" data node
118 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
119 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
122 * Given the NLRI as ContainerNode, this method should extract advertised routes
123 * from the DOM model and put them into RIBs.
125 * @param tx DOMDataWriteTransaction
126 * @param tablePath YangInstanceIdentifier
127 * @param nlri ContainerNode DOM representation of NLRI in Update message
128 * @param attributes ContainerNode
130 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
131 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
134 * Given the NLRI as ContainerNode, this method should extract advertised routes
135 * from the DOM model and put them into RIBs.
137 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
138 * Provide {@link NodeIdentifier} with customized "routes" QName.
139 * For default "bgp-rib" RIBs use {@link #putRoutes}
142 * @param tx DOMDataWriteTransaction
143 * @param tablePath YangInstanceIdentifier
144 * @param nlri ContainerNode DOM representation of NLRI in Update message
145 * @param attributes ContainerNode
146 * @param routesNodeId NodeIdentifier of "routes" data node
148 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
149 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
152 * Returns routes that were modified within this RIB support instance.
154 * @param routes DataTreeCandidateNode
155 * @return collection of modified nodes or empty collection if no node was modified
158 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
161 * Constructs an instance identifier path to routeId.
163 * @param routesPath YangInstanceIdentifier base path
164 * @param routeId PathArgument leaf path
165 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
168 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
169 @Nonnull PathArgument routeId);
172 * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
173 * only have their key and attributes, complex routes are those which include more structured data.
175 * @return True if this is a complex route, false otherwise.
176 * @deprecated All routes are complex.
179 boolean isComplexRoute();
182 * To send routes out, we'd need to transform the DOM representation of route to
183 * binding-aware format. This needs to be done per each AFI/SAFI.
185 * @param advertised Collection of advertised routes in DOM format
186 * @param withdrawn Collection of withdrawn routes in DOM format
187 * @param attr Attributes MpReach is part of Attributes so we need to pass
188 * it as argument, create new AttributesBuilder with existing
189 * attributes and add MpReach
190 * @return Update message ready to be sent out
194 @Nonnull Collection<MapEntryNode> advertised,
195 @Nonnull Collection<MapEntryNode> withdrawn,
196 @Nonnull Attributes attr);
199 Class<? extends AddressFamily> getAfi();
202 Class<? extends SubsequentAddressFamily> getSafi();
205 * Creates Route table Peer InstanceIdentifier.
207 * @param tableKey table InstanceIdentifier
208 * @param newRouteKey route key
209 * @return InstanceIdentifier
212 InstanceIdentifier<R> createRouteIdentifier(
213 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
214 @Nonnull N newRouteKey);
217 * Creates a route with new path Id and attributes.
220 * @param routeKey route key
221 * @param pathId new path Id
222 * @param attributes route attributes
223 * @return Route List key
226 R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
228 interface ApplyRoute {
229 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
230 @Nonnull NodeIdentifierWithPredicates routeKey,
231 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
235 * Return the table-type-specific empty routes container, as augmented into the
236 * bgp-peer model under /peer/effect-rib-in/tables/routes choice node. This needs to include all
237 * the skeleton nodes under which the individual routes will be stored.
239 * @return Protocol-specific case in the routes choice, may not be null.
242 Routes emptyRoutesContainer();
246 * Construct a Route List Key using new path Id for Families.
248 * @param pathId The path identifier
249 * @param routeKey RouteKey
250 * @return route list Key (RouteKey + pathId)
253 N createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);