Remove duplicated code for rib support
[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.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
28
29 /**
30  * Interface implemented for AFI/SAFI-specific RIB extensions. The extensions need
31  * to register an implementation of this class and the RIB core then calls into it
32  * to inquire about details specific to that particular model.
33  */
34 public interface RIBSupport extends AddPathRibSupport {
35     /**
36      * Return the table-type-specific empty routes container, as augmented into the
37      * bgp-rib model under /rib/tables/routes choice node. This needs to include all
38      * the skeleton nodes under which the individual routes will be stored.
39      *
40      * @return Protocol-specific case in the routes choice, may not be null.
41      */
42     @Nonnull ChoiceNode emptyRoutes();
43
44     /**
45      * Return the localized identifier of the attributes route member, as expanded
46      * from the route grouping in the specific augmentation of the base routes choice.
47      *
48      * @return The attributes identifier, may not be null.
49      */
50     @Nonnull NodeIdentifier routeAttributesIdentifier();
51
52     /**
53      * Return class object of the Routes Case statement.
54      *
55      * @return Class
56      */
57     @Nonnull Class<? extends Routes> routesCaseClass();
58
59     /**
60      * Return class object of the Routes Container statement.
61      *
62      * @return Class
63      */
64     @Nonnull Class<? extends DataObject> routesContainerClass();
65
66     /**
67      * Return class object of the Routes List statement.
68      *
69      * @return Class
70      */
71     @Nonnull Class<? extends Route> routesListClass();
72
73     @Nonnull ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects();
74     @Nonnull ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects();
75
76     /**
77      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
78      * from the DOM model and delete them from RIBs.
79      *
80      * @param tx DOMDataWriteTransaction
81      * @param tablePath YangInstanceIdentifier
82      * @param nlri ContainerNode DOM representation of NLRI in Update message
83      */
84     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri);
85
86
87     /**
88      * Given the NLRI as ContainerNode, this method should extract withdrawn routes
89      * from the DOM model and delete them from RIBs.
90      * <p>
91      * Use this method when removing routes stored in RIBs out of the "bgp-rib" module.
92      * Provide {@link NodeIdentifier} with customized "routes" QName.
93      * For default "bgp-rib" RIBs use {@link #deleteRoutes}
94      * </p>
95      *
96      * @param tx DOMDataWriteTransaction
97      * @param tablePath YangInstanceIdentifier
98      * @param nlri ContainerNode DOM representation of NLRI in Update message
99      * @param routesNodeId NodeIdentifier of "routes" data node
100      */
101     void deleteRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull NodeIdentifier routesNodeId);
102
103     /**
104      * Given the NLRI as ContainerNode, this method should extract advertised routes
105      * from the DOM model and put them into RIBs.
106      *
107      * @param tx DOMDataWriteTransaction
108      * @param tablePath YangInstanceIdentifier
109      * @param nlri ContainerNode DOM representation of NLRI in Update message
110      * @param attributes ContainerNode
111      */
112     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri, @Nonnull ContainerNode attributes);
113
114     /**
115      * Given the NLRI as ContainerNode, this method should extract advertised routes
116      * from the DOM model and put them into RIBs.
117      * <p>
118      * Use this method when putting routes stored in RIBs out of the "bgp-rib" module.
119      * Provide {@link NodeIdentifier} with customized "routes" QName.
120      * For default "bgp-rib" RIBs use {@link #putRoutes}
121      * </p>
122      *
123      * @param tx DOMDataWriteTransaction
124      * @param tablePath YangInstanceIdentifier
125      * @param nlri ContainerNode DOM representation of NLRI in Update message
126      * @param attributes ContainerNode
127      * @param routesNodeId NodeIdentifier of "routes" data node
128      */
129     void putRoutes(@Nonnull DOMDataWriteTransaction tx, @Nonnull YangInstanceIdentifier tablePath, @Nonnull ContainerNode nlri,
130             @Nonnull ContainerNode attributes, @Nonnull NodeIdentifier routesNodeId);
131
132     /**
133      * Returns routes that were modified within this RIB support instance.
134      *
135      * @param routes DataTreeCandidateNode
136      * @return collection of modified nodes or empty collection if no node was modified
137      */
138     @Nonnull Collection<DataTreeCandidateNode> changedRoutes(@Nonnull DataTreeCandidateNode routes);
139
140     /**
141      * Constructs an instance identifier path to routeId.
142      *
143      * @param routesPath YangInstanceIdentifier base path
144      * @param routeId PathArgument leaf path
145      * @return YangInstanceIdentifier with routesPath + specific RIB support routes path + routeId
146      */
147     @Nonnull YangInstanceIdentifier routePath(@Nonnull YangInstanceIdentifier routesPath, @Nonnull PathArgument routeId);
148
149     /**
150      * Indicate whether this AFI/SAFI combination is a complex route. Simple routes are those which
151      * only have their key and attributes, complex routes are those which include more structured data.
152      *
153      * @return True if this is a complex route, false otherwise.
154      */
155     boolean isComplexRoute();
156
157     /**
158      * To send routes out, we'd need to transform the DOM representation of route to
159      * binding-aware format. This needs to be done per each AFI/SAFI.
160      *
161      * @param advertised Collection of advertised routes in DOM format
162      * @param withdrawn Collection of withdrawn routes in DOM format
163      * @param attr Attributes MpReach is part of Attributes so we need to pass
164      *             it as argument, create new AttributesBuilder with existing
165      *             attributes and add MpReach
166      * @return Update message ready to be sent out
167      */
168     @Nonnull Update buildUpdate(@Nonnull Collection<MapEntryNode> advertised, @Nonnull Collection<MapEntryNode> withdrawn, @Nonnull Attributes attr);
169
170
171     interface ApplyRoute {
172         void apply(DOMDataWriteTransaction tx, YangInstanceIdentifier base, NodeIdentifierWithPredicates routeKey, DataContainerNode<?> route,
173             ContainerNode attributes);
174     }
175 }