Bump versions by x.y.(z+1)
[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.rev130919.Update;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.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 ChoiceNode emptyRoutes();
45
46     /**
47      * Return the localized identifier of the attributes route member, as expanded
48      * from the route grouping in the specific augmentation of the base routes choice.
49      *
50      * @return The attributes identifier, may not be null.
51      */
52     @Nonnull NodeIdentifier routeAttributesIdentifier();
53
54     /**
55      * Return class object of the Routes Case statement.
56      *
57      * @return Class
58      */
59     @Nonnull Class<? extends Routes> routesCaseClass();
60
61     /**
62      * Return class object of the Routes Container statement.
63      *
64      * @return Class
65      */
66     @Nonnull Class<? extends DataObject> routesContainerClass();
67
68     /**
69      * Return class object of the Routes List statement.
70      *
71      * @return Class
72      */
73     @Nonnull Class<? extends Route> routesListClass();
74
75     @Nonnull ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
76     @Nonnull ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
77
78     /**
79      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
80      * from the DOM model and delete them from RIBs.
81      *
82      * @param tx DOMDataWriteTransaction
83      * @param tablePath YangInstanceIdentifier
84      * @param nlri ContainerNode DOM representation of NLRI in Update message
85      */
86     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri);
87
88
89     /**
90      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
91      * from the DOM model and delete them from RIBs.
92      * <p>
93      * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
94      * Provide {@link NodeIdentifier} with customized "routes" QName.
95      * For default "bgp-rib" RIBs use {@link #deleteRoutes}
96      * </p>
97      *
98      * @param tx DOMDataWriteTransaction
99      * @param tablePath YangInstanceIdentifier
100      * @param nlri ContainerNode DOM representation of NLRI in Update message
101      * @param routesNodeId NodeIdentifier of "routes" data node
102      */
103     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
104
105     /**
106      * Given the NLRI as ContainerNode, this method should extract advertised routes
107      * from the DOM model and put them into RIBs.
108      *
109      * @param tx DOMDataWriteTransaction
110      * @param tablePath YangInstanceIdentifier
111      * @param nlri ContainerNode DOM representation of NLRI in Update message
112      * @param attributes ContainerNode
113      */
114     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
115
116     /**
117      * Given the NLRI as ContainerNode, this method should extract advertised routes
118      * from the DOM model and put them into RIBs.
119      * <p>
120      * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
121      * Provide {@link NodeIdentifier} with customized "routes" QName.
122      * For default "bgp-rib" RIBs use {@link #putRoutes}
123      * </p>
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      * @param routesNodeId NodeIdentifier of "routes" data node
130      */
131     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri,
132             @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
133
134     /**
135      * Returns routes that were modified within this RIB support instance.
136      *
137      * @param routes DataTreeCandidateNode
138      * @return collection of modified nodes or empty collection if no node was modified
139      */
140     @Nonnull Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
141
142     /**
143      * Constructs an instance identifier path to routeId.
144      *
145      * @param routesPath YangInstanceIdentifier base path
146      * @param routeId PathArgument leaf path
147      * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
148      */
149     @Nonnull YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath, @Nonnull PathArgument routeId);
150
151     /**
152      * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
153      * only have their key and attributes, complex routes are those which include more structured data.
154      *
155      * @return True if this is a complex route, false otherwise.
156      */
157     boolean isComplexRoute();
158
159     /**
160      * To send routes out, we'd need to transform the DOM representation of route to
161      * binding-aware format. This needs to be done per each AFI/SAFI.
162      *
163      * @param advertised Collection of advertised routes in DOM format
164      * @param withdrawn Collection of withdrawn routes in DOM format
165      * @param attr Attributes MpReach is part of Attributes so we need to pass
166      *             it as argument, create new AttributesBuilder with existing
167      *             attributes and add MpReach
168      * @return Update message ready to be sent out
169      */
170     @Nonnull Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised, @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
171
172     @Nonnull Class<? extends AddressFamily> getAfi();
173
174     @Nonnull Class<? extends SubsequentAddressFamily> getSafi();
175
176     interface ApplyRoute {
177         void apply(DOMDataWriteTransaction tx, YangInstanceIdentifier base, NodeIdentifierWithPredicates routeKey, DataContainerNode<?> route,
178             ContainerNode attributes);
179     }
180 }