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 org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
25 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
32 * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
33 * to register an implementation of this class and the RIB core then calls into it
34 * to inquire about details specific to that particular model.
36 public interface RIBSupport extends AddPathRibSupport {
38 * Return the table-type-specific empty routes container, as augmented into the
39 * bgp-rib model under /rib/tables/routes choice node. This needs to include all
40 * the skeleton nodes under which the individual routes will be stored.
42 * @return Protocol-specific case in the routes choice, may not be null.
45 ChoiceNode emptyRoutes();
48 * Return the localized identifier of the attributes route member, as expanded
49 * from the route grouping in the specific augmentation of the base routes choice.
51 * @return The attributes identifier, may not be null.
54 NodeIdentifier routeAttributesIdentifier();
57 * Return class object of the Routes Case statement.
62 Class<? extends Routes> routesCaseClass();
65 * Return class object of the Routes Container statement.
70 Class<? extends DataObject> routesContainerClass();
73 * Return class object of the Routes List statement.
78 Class<? extends Route> routesListClass();
81 ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
84 ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
87 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
88 * from the DOM model and delete them from RIBs.
90 * @param tx DOMDataWriteTransaction
91 * @param tablePath YangInstanceIdentifier
92 * @param nlri ContainerNode DOM representation of NLRI in Update message
94 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
95 @Nonnull ContainerNode nlri);
99 * Given the NLRI as ContainerNode, this method should extract withdrawn routes
100 * from the DOM model and delete them from RIBs.
102 * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
103 * Provide {@link NodeIdentifier} with customized "routes" QName.
104 * For default "bgp-rib" RIBs use {@link #deleteRoutes}
107 * @param tx DOMDataWriteTransaction
108 * @param tablePath YangInstanceIdentifier
109 * @param nlri ContainerNode DOM representation of NLRI in Update message
110 * @param routesNodeId NodeIdentifier of "routes" data node
112 void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
113 @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
116 * Given the NLRI as ContainerNode, this method should extract advertised routes
117 * from the DOM model and put them into RIBs.
119 * @param tx DOMDataWriteTransaction
120 * @param tablePath YangInstanceIdentifier
121 * @param nlri ContainerNode DOM representation of NLRI in Update message
122 * @param attributes ContainerNode
124 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
125 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
128 * Given the NLRI as ContainerNode, this method should extract advertised routes
129 * from the DOM model and put them into RIBs.
131 * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
132 * Provide {@link NodeIdentifier} with customized "routes" QName.
133 * For default "bgp-rib" RIBs use {@link #putRoutes}
136 * @param tx DOMDataWriteTransaction
137 * @param tablePath YangInstanceIdentifier
138 * @param nlri ContainerNode DOM representation of NLRI in Update message
139 * @param attributes ContainerNode
140 * @param routesNodeId NodeIdentifier of "routes" data node
142 void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
143 @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
146 * Returns routes that were modified within this RIB support instance.
148 * @param routes DataTreeCandidateNode
149 * @return collection of modified nodes or empty collection if no node was modified
152 Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
155 * Constructs an instance identifier path to routeId.
157 * @param routesPath YangInstanceIdentifier base path
158 * @param routeId PathArgument leaf path
159 * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
162 YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
163 @Nonnull PathArgument routeId);
166 * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
167 * only have their key and attributes, complex routes are those which include more structured data.
169 * @return True if this is a complex route, false otherwise.
171 boolean isComplexRoute();
174 * To send routes out, we'd need to transform the DOM representation of route to
175 * binding-aware format. This needs to be done per each AFI/SAFI.
177 * @param advertised Collection of advertised routes in DOM format
178 * @param withdrawn Collection of withdrawn routes in DOM format
179 * @param attr Attributes MpReach is part of Attributes so we need to pass
180 * it as argument, create new AttributesBuilder with existing
181 * attributes and add MpReach
182 * @return Update message ready to be sent out
185 Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised,
186 @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
189 Class<? extends AddressFamily> getAfi();
192 Class<? extends SubsequentAddressFamily> getSafi();
195 * Creates Yii for route entry.
197 * @param ribYii Rib Yii
198 * @param routeKey route key
201 YangInstanceIdentifier buildRouteAttributeYii(final YangInstanceIdentifier ribYii, PathArgument routeKey);
203 interface ApplyRoute {
204 void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
205 @Nonnull NodeIdentifierWithPredicates routeKey,
206 @Nonnull DataContainerNode<?> route, ContainerNode attributes);