MVPN RFC6514 Extendend communities
[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.rev180329.Update;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.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.rev180329.AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.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;
36
37 /**
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.
41  */
42 public interface RIBSupport<R extends Route, N extends Identifier> extends AddPathRibSupport {
43     /**
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.
47      *
48      * @return Protocol-specific case in the routes choice, may not be null.
49      */
50     @Nonnull
51     ChoiceNode emptyRoutes();
52
53     /**
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.
56      *
57      * @return The attributes identifier, may not be null.
58      */
59     @Nonnull
60     NodeIdentifier routeAttributesIdentifier();
61
62     /**
63      * Return class object of the Routes Case statement.
64      *
65      * @return Class
66      */
67     @Nonnull
68     Class<? extends Routes> routesCaseClass();
69
70     /**
71      * Return class object of the Routes Container statement.
72      *
73      * @return Class
74      */
75     @Nonnull
76     Class<? extends DataObject> routesContainerClass();
77
78     /**
79      * Return class object of the Routes List statement.
80      *
81      * @return Class
82      */
83     @Nonnull
84     Class<? extends Route> routesListClass();
85
86     @Nonnull
87     ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
88
89     @Nonnull
90     ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
91
92     /**
93      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
94      * from the DOM model and delete them from RIBs.
95      *
96      * @param tx        DOMDataWriteTransaction
97      * @param tablePath YangInstanceIdentifier
98      * @param nlri      ContainerNode DOM representation of NLRI in Update message
99      */
100     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
101             @Nonnull ContainerNode nlri);
102
103
104     /**
105      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
106      * from the DOM model and delete them from RIBs.
107      * <p>
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}
111      * </p>
112      *
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
117      */
118     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
119             @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
120
121     /**
122      * Given the NLRI as ContainerNode, this method should extract advertised routes
123      * from the DOM model and put them into RIBs.
124      *
125      * @param tx         DOMDataWriteTransaction
126      * @param tablePath  YangInstanceIdentifier
127      * @param nlri       ContainerNode DOM representation of NLRI in Update message
128      * @param attributes ContainerNode
129      */
130     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
131             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
132
133     /**
134      * Given the NLRI as ContainerNode, this method should extract advertised routes
135      * from the DOM model and put them into RIBs.
136      * <p>
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}
140      * </p>
141      *
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
147      */
148     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
149             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
150
151     /**
152      * Returns routes that were modified within this RIB support instance.
153      *
154      * @param routes DataTreeCandidateNode
155      * @return collection of modified nodes or empty collection if no node was modified
156      */
157     @Nonnull
158     Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
159
160     /**
161      * Constructs an instance identifier path to routeId.
162      *
163      * @param routesPath YangInstanceIdentifier base path
164      * @param routeId    PathArgument leaf path
165      * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
166      */
167     @Nonnull
168     YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
169             @Nonnull PathArgument routeId);
170
171     /**
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.
174      *
175      * @return True if this is a complex route, false otherwise.
176      * @deprecated All routes are complex.
177      */
178     @Deprecated
179     boolean isComplexRoute();
180
181     /**
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.
184      *
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
191      */
192     @Nonnull
193     Update buildUpdate(
194             @Nonnull Collection<MapEntryNode> advertised,
195             @Nonnull Collection<MapEntryNode> withdrawn,
196             @Nonnull Attributes attr);
197
198     @Nonnull
199     Class<? extends AddressFamily> getAfi();
200
201     @Nonnull
202     Class<? extends SubsequentAddressFamily> getSafi();
203
204     /**
205      * Creates Route table Peer InstanceIdentifier.
206      *
207      * @param tableKey    table InstanceIdentifier
208      * @param newRouteKey route key
209      * @return InstanceIdentifier
210      */
211     @Nonnull
212     InstanceIdentifier<R> createRouteIdentifier(
213             @Nonnull KeyedInstanceIdentifier<Tables, TablesKey> tableKey,
214             @Nonnull N newRouteKey);
215
216     /**
217      * Creates a route with new path Id and attributes.
218      *
219      * @param route route
220      * @param routeKey route key
221      * @param pathId new path Id
222      * @param attributes route attributes
223      * @return Route List key
224      */
225     @Nonnull
226     R createRoute(@Nullable R route, String routeKey, @Nullable long pathId, @Nonnull Attributes attributes);
227
228     interface ApplyRoute {
229         void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
230                 @Nonnull NodeIdentifierWithPredicates routeKey,
231                 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
232     }
233
234     /**
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.
238      *
239      * @return Protocol-specific case in the routes choice, may not be null.
240      */
241     @Nonnull
242     Routes emptyRoutesContainer();
243
244
245     /**
246      * Construct a Route List Key using new path Id for Families.
247      *
248      * @param pathId   The path identifier
249      * @param routeKey RouteKey
250      * @return route list Key (RouteKey + pathId)
251      */
252     @Nonnull
253     N createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey);
254 }