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