153948ffdf63c0ddc314429fe61b8fdca716b043
[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 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;
30
31 /**
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.
35  */
36 public interface RIBSupport extends AddPathRibSupport {
37     /**
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.
41      *
42      * @return Protocol-specific case in the routes choice, may not be null.
43      */
44     @Nonnull
45     ChoiceNode emptyRoutes();
46
47     /**
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.
50      *
51      * @return The attributes identifier, may not be null.
52      */
53     @Nonnull
54     NodeIdentifier routeAttributesIdentifier();
55
56     /**
57      * Return class object of the Routes Case statement.
58      *
59      * @return Class
60      */
61     @Nonnull
62     Class<? extends Routes> routesCaseClass();
63
64     /**
65      * Return class object of the Routes Container statement.
66      *
67      * @return Class
68      */
69     @Nonnull
70     Class<? extends DataObject> routesContainerClass();
71
72     /**
73      * Return class object of the Routes List statement.
74      *
75      * @return Class
76      */
77     @Nonnull
78     Class<? extends Route> routesListClass();
79
80     @Nonnull
81     ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
82
83     @Nonnull
84     ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
85
86     /**
87      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
88      * from the DOM model and delete them from RIBs.
89      *
90      * @param tx        DOMDataWriteTransaction
91      * @param tablePath YangInstanceIdentifier
92      * @param nlri      ContainerNode DOM representation of NLRI in Update message
93      */
94     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
95             @Nonnull ContainerNode nlri);
96
97
98     /**
99      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
100      * from the DOM model and delete them from RIBs.
101      * <p>
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}
105      * </p>
106      *
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
111      */
112     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
113             @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
114
115     /**
116      * Given the NLRI as ContainerNode, this method should extract advertised routes
117      * from the DOM model and put them into RIBs.
118      *
119      * @param tx         DOMDataWriteTransaction
120      * @param tablePath  YangInstanceIdentifier
121      * @param nlri       ContainerNode DOM representation of NLRI in Update message
122      * @param attributes ContainerNode
123      */
124     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
125             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
126
127     /**
128      * Given the NLRI as ContainerNode, this method should extract advertised routes
129      * from the DOM model and put them into RIBs.
130      * <p>
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}
134      * </p>
135      *
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
141      */
142     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath,
143             @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
144
145     /**
146      * Returns routes that were modified within this RIB support instance.
147      *
148      * @param routes DataTreeCandidateNode
149      * @return collection of modified nodes or empty collection if no node was modified
150      */
151     @Nonnull
152     Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
153
154     /**
155      * Constructs an instance identifier path to routeId.
156      *
157      * @param routesPath YangInstanceIdentifier base path
158      * @param routeId    PathArgument leaf path
159      * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
160      */
161     @Nonnull
162     YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath,
163             @Nonnull PathArgument routeId);
164
165     /**
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.
168      *
169      * @return True if this is a complex route, false otherwise.
170      */
171     boolean isComplexRoute();
172
173     /**
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.
176      *
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
183      */
184     @Nonnull
185     Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised,
186             @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
187
188     @Nonnull
189     Class<? extends AddressFamily> getAfi();
190
191     @Nonnull
192     Class<? extends SubsequentAddressFamily> getSafi();
193
194     /**
195      * Creates Yii for route entry.
196      *
197      * @param ribYii Rib Yii
198      * @param routeKey route key
199      * @return Yii
200      */
201     YangInstanceIdentifier buildRouteAttributeYii(final YangInstanceIdentifier ribYii, PathArgument routeKey);
202
203     interface ApplyRoute {
204         void apply(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier base,
205                 @Nonnull NodeIdentifierWithPredicates routeKey,
206                 @Nonnull DataContainerNode<?> route, ContainerNode attributes);
207     }
208 }