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.PathId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.Identifier;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
32 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
39 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
40 * to register an implementation of this class and the RIB core then calls into it
41 * to inquire about details specific to that particular model.
43 public interface RIBSupport<R extends Route, N extends Identifier> extends AddPathRibSupport {
45 * Return the table-type-specific empty routes container, as augmented into the
46 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
47 * the skeleton nodes under which the individual routes will be stored.
49 * @return Protocol-specific case in the routes choice, may not be null.
52 ChoiceNode emptyRoutes();
55 * Return the localized identifier of the attributes route member, as expanded
56 * from the route grouping in the specific augmentation of the base routes choice.
58 * @return The attributes identifier, may not be null.
61 NodeIdentifier routeAttributesIdentifier();
64 * Return class object of the Routes Case statement.
69 Class<? extends Routes> routesCaseClass();
72 * Return class object of the Routes Container statement.
77 Class<? extends DataObject> routesContainerClass();
80 * Return class object of the Routes List statement.
85 Class<? extends Route> routesListClass();
88 ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
91 ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
94 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
95 * from the DOM model and delete them from RIBs.
97 * @param tx DOMDataWriteTransaction
98 * @param tablePath YangInstanceIdentifier
99 * @param nlri ContainerNode DOM representation of NLRI in Update message
101 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
102 @Nonnull ContainerNode nlri);
106 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
107 * from the DOM model and delete them from RIBs.
109 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
110 * Provide {@link NodeIdentifier} with customized "routes" QName.
111 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
114 * @param tx DOMDataWriteTransaction
115 * @param tablePath YangInstanceIdentifier
116 * @param nlri ContainerNode DOM representation of NLRI in Update message
117 * @param routesNodeId NodeIdentifier of "routes" data node
119 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
120 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
123 * Given the NLRI as ContainerNode, this method should extract advertised routes
124 * from the DOM model and put them into RIBs.
126 * @param tx DOMDataWriteTransaction
127 * @param tablePath YangInstanceIdentifier
128 * @param nlri ContainerNode DOM representation of NLRI in Update message
129 * @param attributes ContainerNode
131 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
132 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
135 * Given the NLRI as ContainerNode, this method should extract advertised routes
136 * from the DOM model and put them into RIBs.
138 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
139 * Provide {@link NodeIdentifier} with customized "routes" QName.
140 * For default "bgp-rib" RIBs use {@link #putRoutes}
143 * @param tx DOMDataWriteTransaction
144 * @param tablePath YangInstanceIdentifier
145 * @param nlri ContainerNode DOM representation of NLRI in Update message
146 * @param attributes ContainerNode
147 * @param routesNodeId NodeIdentifier of "routes" data node
149 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
150 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
153 * Returns routes that were modified within this RIB support instance.
155 * @param routes DataTreeCandidateNode
156 * @return collection of modified nodes or empty collection if no node was modified
159 Collection<DataTreeCandidateNode> changedDOMRoutes(@Nonnull DataTreeCandidateNode routes);
162 * Constructs an instance identifier path to routeId.
164 * @param routesPath YangInstanceIdentifier base path
165 * @param routeId PathArgument leaf path
166 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
169 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
170 @Nonnull PathArgument routeId);
173 * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
174 * only have their key and attributes, complex routes are those which include more structured data.
176 * @return True if this is a complex route, false otherwise.
178 boolean isComplexRoute();
181 * To send routes out, we'd need to transform the DOM representation of route to
182 * binding-aware format. This needs to be done per each AFI/SAFI.
184 * @param advertised Collection of advertised routes in DOM format
185 * @param withdrawn Collection of withdrawn routes in DOM format
186 * @param attr Attributes MpReach is part of Attributes so we need to pass
187 * it as argument, create new AttributesBuilder with existing
188 * attributes and add MpReach
189 * @return Update message ready to be sent out
192 Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised,
193 @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
196 Class<? extends AddressFamily> getAfi();
199 Class<? extends SubsequentAddressFamily> getSafi();
202 * Creates Route Rib out Peer InstanceIdentifier.
204 * @param ribOutIId table InstanceIdentifier
205 * @param newRouteKey route key
206 * @return InstanceIdentifier
209 InstanceIdentifier<R> createRouteIId(
210 @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> ribOutIId,
211 @Nonnull N newRouteKey);
214 R createRoute(@Nullable R route, N routeKey, @Nullable PathId pathId, @Nonnull Attributes attributes);
217 * Construct a PathArgument to an AddPathRoute.
219 * @param pathId The path identifier
220 * @param routeKey RouteKey
221 * @return routeId PathArgument + pathId or Null in case Add-path is not supported
224 default Identifier createNewRouteKey(@Nonnull PathId pathId, @Nonnull N routeKey) {
229 * Creates Yii for route entry.
231 * @param ribYii Rib Yii
232 * @param routeKey route key
235 YangInstanceIdentifier buildRouteAttributeYii(final YangInstanceIdentifier ribYii, PathArgument routeKey);
237 interface ApplyRoute {
238 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
239 @Nonnull NodeIdentifierWithPredicates routeKey,
240 @Nonnull DataContainerNode<?> route, ContainerNode attributes);