BGPCEP-574: Remove unnesary methods
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / RIBSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.spi;
9
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;
37
38 /**
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.
42  */
43 public interface RIBSupport<R extends Route, N extends Identifier> extends AddPathRibSupport {
44     /**
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.
48      *
49      * @return Protocol-specific case in the routes choice, may not be null.
50      */
51     @Nonnull
52     ChoiceNode emptyRoutes();
53
54     /**
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.
57      *
58      * @return The attributes identifier, may not be null.
59      */
60     @Nonnull
61     NodeIdentifier routeAttributesIdentifier();
62
63     /**
64      * Return class object of the Routes Case statement.
65      *
66      * @return Class
67      */
68     @Nonnull
69     Class<? extends Routes> routesCaseClass();
70
71     /**
72      * Return class object of the Routes Container statement.
73      *
74      * @return Class
75      */
76     @Nonnull
77     Class<? extends DataObject> routesContainerClass();
78
79     /**
80      * Return class object of the Routes List statement.
81      *
82      * @return Class
83      */
84     @Nonnull
85     Class<? extends Route> routesListClass();
86
87     @Nonnull
88     ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
89
90     @Nonnull
91     ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
92
93     /**
94      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
95      * from the DOM model and delete them from RIBs.
96      *
97      * @param tx        DOMDataWriteTransaction
98      * @param tablePath YangInstanceIdentifier
99      * @param nlri      ContainerNode DOM representation of NLRI in Update message
100      */
101     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
102             @Nonnull ContainerNode nlri);
103
104
105     /**
106      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
107      * from the DOM model and delete them from RIBs.
108      * <p>
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}
112      * </p>
113      *
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
118      */
119     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
120             @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
121
122     /**
123      * Given the NLRI as ContainerNode, this method should extract advertised routes
124      * from the DOM model and put them into RIBs.
125      *
126      * @param tx         DOMDataWriteTransaction
127      * @param tablePath  YangInstanceIdentifier
128      * @param nlri       ContainerNode DOM representation of NLRI in Update message
129      * @param attributes ContainerNode
130      */
131     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
132             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
133
134     /**
135      * Given the NLRI as ContainerNode, this method should extract advertised routes
136      * from the DOM model and put them into RIBs.
137      * <p>
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}
141      * </p>
142      *
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
148      */
149     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
150             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
151
152     /**
153      * Returns routes that were modified within this RIB support instance.
154      *
155      * @param routes DataTreeCandidateNode
156      * @return collection of modified nodes or empty collection if no node was modified
157      */
158     @Nonnull
159     Collection<DataTreeCandidateNode> changedDOMRoutes(@Nonnull DataTreeCandidateNode routes);
160
161     /**
162      * Constructs an instance identifier path to routeId.
163      *
164      * @param routesPath YangInstanceIdentifier base path
165      * @param routeId    PathArgument leaf path
166      * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
167      */
168     @Nonnull
169     YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
170             @Nonnull PathArgument routeId);
171
172     /**
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.
175      *
176      * @return True if this is a complex route, false otherwise.
177      */
178     boolean isComplexRoute();
179
180     /**
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.
183      *
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
190      */
191     @Nonnull
192     Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised,
193             @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
194
195     @Nonnull
196     Class<? extends AddressFamily> getAfi();
197
198     @Nonnull
199     Class<? extends SubsequentAddressFamily> getSafi();
200
201     /**
202      * Creates Route Rib out Peer InstanceIdentifier.
203      *
204      * @param ribOutIId   table InstanceIdentifier
205      * @param newRouteKey route key
206      * @return InstanceIdentifier
207      */
208     @Nonnull
209     InstanceIdentifier<R> createRouteIId(
210             @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> ribOutIId,
211             @Nonnull N newRouteKey);
212
213     @Nonnull
214     R createRoute(@Nullable R route, N routeKey, @Nullable PathId pathId, @Nonnull Attributes attributes);
215
216     /**
217      * Construct a PathArgument to an AddPathRoute.
218      *
219      * @param pathId  The path identifier
220      * @param routeKey RouteKey
221      * @return routeId PathArgument + pathId or Null in case Add-path is not supported
222      */
223     @Nullable
224     default Identifier createNewRouteKey(@Nonnull PathId pathId, @Nonnull N routeKey) {
225         return null;
226     }
227
228     /**
229      * Creates Yii for route entry.
230      *
231      * @param ribYii Rib Yii
232      * @param routeKey route key
233      * @return Yii
234      */
235     YangInstanceIdentifier buildRouteAttributeYii(final YangInstanceIdentifier ribYii, PathArgument routeKey);
236
237     interface ApplyRoute {
238         void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
239                 @Nonnull NodeIdentifierWithPredicates routeKey,
240                 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
241     }
242 }