Committed by
Gerrit Code Review
[ONOS-2602]Implement Adajacency RIB table
Change-Id: If51a88836c8e58cec3127f8489107892357ba78b
Showing
2 changed files
with
341 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import java.util.Map; | ||
20 | +import java.util.TreeMap; | ||
21 | + | ||
22 | +import org.onosproject.bgpio.protocol.BGPLSNlri; | ||
23 | +import org.onosproject.bgpio.protocol.linkstate.BGPLinkLSIdentifier; | ||
24 | +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | ||
25 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier; | ||
26 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; | ||
27 | +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; | ||
28 | +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixLSIdentifier; | ||
29 | +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; | ||
30 | + | ||
31 | +import com.google.common.base.MoreObjects; | ||
32 | + | ||
33 | +/** | ||
34 | + * Implementation of Adj-RIB-In for each peer. | ||
35 | + */ | ||
36 | +public class AdjRibIn { | ||
37 | + private Map<BGPNodeLSIdentifier, PathAttrNlriDetails> nodeTree = new TreeMap<>(); | ||
38 | + private Map<BGPLinkLSIdentifier, PathAttrNlriDetails> linkTree = new TreeMap<>(); | ||
39 | + private Map<BGPPrefixLSIdentifier, PathAttrNlriDetails> prefixTree = new TreeMap<>(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns the adjacency node. | ||
43 | + * | ||
44 | + * @return node adjacency RIB node | ||
45 | + */ | ||
46 | + public Map<BGPNodeLSIdentifier, PathAttrNlriDetails> nodeTree() { | ||
47 | + return nodeTree; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Returns the adjacency link. | ||
52 | + * | ||
53 | + * @return link adjacency RIB node | ||
54 | + */ | ||
55 | + public Map<BGPLinkLSIdentifier, PathAttrNlriDetails> linkTree() { | ||
56 | + return linkTree; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Returns the adjacency prefix. | ||
61 | + * | ||
62 | + * @return prefix adjacency RIB node | ||
63 | + */ | ||
64 | + public Map<BGPPrefixLSIdentifier, PathAttrNlriDetails> prefixTree() { | ||
65 | + return prefixTree; | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Update nlri identifier into the tree if nlri identifier exists in tree otherwise add this to the tree. | ||
70 | + * | ||
71 | + * @param nlri NLRI Info | ||
72 | + * @param details has pathattribute , protocolID and identifier | ||
73 | + */ | ||
74 | + public void add(BGPLSNlri nlri, PathAttrNlriDetails details) { | ||
75 | + if (nlri instanceof BGPNodeLSNlriVer4) { | ||
76 | + BGPNodeLSIdentifier nodeLSIdentifier = ((BGPNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); | ||
77 | + if (nodeTree.containsKey(nodeLSIdentifier)) { | ||
78 | + nodeTree.replace(nodeLSIdentifier, details); | ||
79 | + } else { | ||
80 | + nodeTree.put(nodeLSIdentifier, details); | ||
81 | + } | ||
82 | + } else if (nlri instanceof BgpLinkLsNlriVer4) { | ||
83 | + BGPLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); | ||
84 | + if (linkTree.containsKey(linkLSIdentifier)) { | ||
85 | + linkTree.replace(linkLSIdentifier, details); | ||
86 | + } else { | ||
87 | + linkTree.put(linkLSIdentifier, details); | ||
88 | + } | ||
89 | + } else if (nlri instanceof BGPPrefixIPv4LSNlriVer4) { | ||
90 | + BGPPrefixLSIdentifier prefixIdentifier = ((BGPPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); | ||
91 | + if (prefixTree.containsKey(prefixIdentifier)) { | ||
92 | + prefixTree.replace(prefixIdentifier, details); | ||
93 | + } else { | ||
94 | + prefixTree.put(prefixIdentifier, details); | ||
95 | + } | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Removes nlri identifier if it exists in the adjacency tree. | ||
101 | + * | ||
102 | + * @param nlri NLRI Info | ||
103 | + */ | ||
104 | + public void remove(BGPLSNlri nlri) { | ||
105 | + if (nlri instanceof BGPNodeLSNlriVer4) { | ||
106 | + BGPNodeLSIdentifier nodeLSIdentifier = ((BGPNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); | ||
107 | + if (nodeTree.containsKey(nodeLSIdentifier)) { | ||
108 | + nodeTree.remove(nodeLSIdentifier); | ||
109 | + } | ||
110 | + } else if (nlri instanceof BgpLinkLsNlriVer4) { | ||
111 | + BGPLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); | ||
112 | + if (linkTree.containsKey(linkLSIdentifier)) { | ||
113 | + linkTree.remove(linkLSIdentifier); | ||
114 | + } | ||
115 | + } else if (nlri instanceof BGPPrefixIPv4LSNlriVer4) { | ||
116 | + BGPPrefixLSIdentifier prefixIdentifier = ((BGPPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); | ||
117 | + if (prefixTree.containsKey(prefixIdentifier)) { | ||
118 | + prefixTree.remove(prefixIdentifier); | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public String toString() { | ||
125 | + return MoreObjects.toStringHelper(getClass()) | ||
126 | + .omitNullValues() | ||
127 | + .add("nodeTree", nodeTree) | ||
128 | + .add("linkTree", linkTree) | ||
129 | + .add("prefixTree", prefixTree) | ||
130 | + .toString(); | ||
131 | + } | ||
132 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import java.util.Map; | ||
20 | +import java.util.TreeMap; | ||
21 | + | ||
22 | +import org.onosproject.bgpio.protocol.BGPLSNlri; | ||
23 | +import org.onosproject.bgpio.protocol.linkstate.BGPLinkLSIdentifier; | ||
24 | +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | ||
25 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier; | ||
26 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; | ||
27 | +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; | ||
28 | +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixLSIdentifier; | ||
29 | +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; | ||
30 | +import org.onosproject.bgpio.types.RouteDistinguisher; | ||
31 | + | ||
32 | +import com.google.common.base.MoreObjects; | ||
33 | + | ||
34 | +/** | ||
35 | + * Implementation of Adj-RIB-In with VPN for each peer. | ||
36 | + */ | ||
37 | +public class VpnAdjRibIn { | ||
38 | + private Map<BGPNodeLSIdentifier, PathAttrNlriDetails> nodeTree = new TreeMap<>(); | ||
39 | + private Map<BGPLinkLSIdentifier, PathAttrNlriDetails> linkTree = new TreeMap<>(); | ||
40 | + private Map<BGPPrefixLSIdentifier, PathAttrNlriDetails> prefixTree = new TreeMap<>(); | ||
41 | + | ||
42 | + private Map<RouteDistinguisher, Map<BGPNodeLSIdentifier, PathAttrNlriDetails>> vpnNodeTree | ||
43 | + = new TreeMap<>(); | ||
44 | + private Map<RouteDistinguisher, Map<BGPLinkLSIdentifier, PathAttrNlriDetails>> vpnLinkTree | ||
45 | + = new TreeMap<>(); | ||
46 | + private Map<RouteDistinguisher, Map<BGPPrefixLSIdentifier, PathAttrNlriDetails>> vpnPrefixTree | ||
47 | + = new TreeMap<>(); | ||
48 | + /** | ||
49 | + * Returns the adjacency node. | ||
50 | + * | ||
51 | + * @return node adjacency RIB node | ||
52 | + */ | ||
53 | + public Map<BGPNodeLSIdentifier, PathAttrNlriDetails> nodeTree() { | ||
54 | + return nodeTree; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the adjacency link. | ||
59 | + * | ||
60 | + * @return link adjacency RIB node | ||
61 | + */ | ||
62 | + public Map<BGPLinkLSIdentifier, PathAttrNlriDetails> linkTree() { | ||
63 | + return linkTree; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Returns the adjacency prefix. | ||
68 | + * | ||
69 | + * @return prefix adjacency RIB node | ||
70 | + */ | ||
71 | + public Map<BGPPrefixLSIdentifier, PathAttrNlriDetails> prefixTree() { | ||
72 | + return prefixTree; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Returns the adjacency vpnNode. | ||
77 | + * | ||
78 | + * @return vpnNode adjacency RIB node | ||
79 | + */ | ||
80 | + public Map<RouteDistinguisher, Map<BGPNodeLSIdentifier, PathAttrNlriDetails>> vpnNodeTree() { | ||
81 | + return vpnNodeTree; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Returns the adjacency vpnLink. | ||
86 | + * | ||
87 | + * @return vpnLink adjacency RIB node | ||
88 | + */ | ||
89 | + public Map<RouteDistinguisher, Map<BGPLinkLSIdentifier, PathAttrNlriDetails>> vpnLinkTree() { | ||
90 | + return vpnLinkTree; | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * Returns the adjacency vpnPrefix. | ||
95 | + * | ||
96 | + * @return vpnPrefix adjacency RIB node | ||
97 | + */ | ||
98 | + public Map<RouteDistinguisher, Map<BGPPrefixLSIdentifier, PathAttrNlriDetails>> vpnPrefixTree() { | ||
99 | + return vpnPrefixTree; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Update vpn nlri identifier into the tree if nlri identifier exists in tree otherwise add this to the tree. | ||
104 | + * | ||
105 | + * @param nlri NLRI info | ||
106 | + * @param details has pathattribute , protocolID and identifier | ||
107 | + */ | ||
108 | + public void add(BGPLSNlri nlri, PathAttrNlriDetails details) { | ||
109 | + if (nlri instanceof BGPNodeLSNlriVer4) { | ||
110 | + BGPNodeLSIdentifier nodeLSIdentifier = ((BGPNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); | ||
111 | + if (nodeTree.containsKey(nodeLSIdentifier)) { | ||
112 | + nodeTree.replace(nodeLSIdentifier, details); | ||
113 | + } else { | ||
114 | + nodeTree.put(nodeLSIdentifier, details); | ||
115 | + } | ||
116 | + } else if (nlri instanceof BgpLinkLsNlriVer4) { | ||
117 | + BGPLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); | ||
118 | + if (linkTree.containsKey(linkLSIdentifier)) { | ||
119 | + linkTree.replace(linkLSIdentifier, details); | ||
120 | + } else { | ||
121 | + linkTree.put(linkLSIdentifier, details); | ||
122 | + } | ||
123 | + } else if (nlri instanceof BGPPrefixIPv4LSNlriVer4) { | ||
124 | + BGPPrefixLSIdentifier prefixIdentifier = ((BGPPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); | ||
125 | + if (prefixTree.containsKey(prefixIdentifier)) { | ||
126 | + prefixTree.replace(prefixIdentifier, details); | ||
127 | + } else { | ||
128 | + prefixTree.put(prefixIdentifier, details); | ||
129 | + } | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Update nlri identifier mapped with route distinguisher if it exists in tree otherwise add nlri infomation mapped | ||
135 | + * to respective route distinguisher in tree. | ||
136 | + * | ||
137 | + * @param nlri NLRI info | ||
138 | + * @param details has pathattribute , protocolID and identifier | ||
139 | + * @param routeDistinguisher unique for for each vpn | ||
140 | + */ | ||
141 | + public void addVpn(BGPLSNlri nlri, PathAttrNlriDetails details, RouteDistinguisher routeDistinguisher) { | ||
142 | + add(nlri, details); | ||
143 | + if (nlri instanceof BGPNodeLSNlriVer4) { | ||
144 | + if (!vpnNodeTree.containsKey(routeDistinguisher)) { | ||
145 | + vpnNodeTree.put(routeDistinguisher, nodeTree); | ||
146 | + } | ||
147 | + } else if (nlri instanceof BgpLinkLsNlriVer4) { | ||
148 | + if (!vpnLinkTree.containsKey(routeDistinguisher)) { | ||
149 | + vpnLinkTree.put(routeDistinguisher, linkTree); | ||
150 | + } | ||
151 | + } else if (nlri instanceof BGPPrefixIPv4LSNlriVer4) { | ||
152 | + if (!vpnPrefixTree.containsKey(routeDistinguisher)) { | ||
153 | + vpnPrefixTree.put(routeDistinguisher, prefixTree); | ||
154 | + } | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Removes vpn nlri identifier mapped to route distinguisher if it exists in tree. | ||
160 | + * | ||
161 | + * @param nlri NLRI Info | ||
162 | + * @param routeDistinguisher unique for for each vpn | ||
163 | + */ | ||
164 | + public void removeVpn(BGPLSNlri nlri, RouteDistinguisher routeDistinguisher) { | ||
165 | + if (nlri instanceof BGPNodeLSNlriVer4) { | ||
166 | + if (vpnNodeTree.containsKey(routeDistinguisher)) { | ||
167 | + BGPNodeLSIdentifier nodeLSIdentifier = ((BGPNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); | ||
168 | + if (nodeTree.containsKey(nodeLSIdentifier)) { | ||
169 | + nodeTree.remove(nodeLSIdentifier); | ||
170 | + } | ||
171 | + if ((vpnNodeTree.get(routeDistinguisher)).isEmpty()) { | ||
172 | + vpnNodeTree.remove(routeDistinguisher); | ||
173 | + } | ||
174 | + } | ||
175 | + } else if (nlri instanceof BgpLinkLsNlriVer4) { | ||
176 | + if (vpnLinkTree.containsKey(routeDistinguisher)) { | ||
177 | + BGPLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); | ||
178 | + if (linkTree.containsKey(linkLSIdentifier)) { | ||
179 | + linkTree.remove(linkLSIdentifier); | ||
180 | + } | ||
181 | + if ((vpnLinkTree.get(routeDistinguisher)).isEmpty()) { | ||
182 | + vpnLinkTree.remove(routeDistinguisher); | ||
183 | + } | ||
184 | + } | ||
185 | + } else if (nlri instanceof BGPPrefixIPv4LSNlriVer4) { | ||
186 | + if (vpnPrefixTree.containsKey(routeDistinguisher)) { | ||
187 | + BGPPrefixLSIdentifier prefixIdentifier = ((BGPPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); | ||
188 | + if (prefixTree.containsKey(prefixIdentifier)) { | ||
189 | + prefixTree.remove(prefixIdentifier); | ||
190 | + } | ||
191 | + if ((vpnPrefixTree.get(routeDistinguisher)).isEmpty()) { | ||
192 | + vpnPrefixTree.remove(routeDistinguisher); | ||
193 | + } | ||
194 | + } | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + @Override | ||
199 | + public String toString() { | ||
200 | + return MoreObjects.toStringHelper(getClass()) | ||
201 | + .omitNullValues().add("nodeTree", nodeTree) | ||
202 | + .add("linkTree", linkTree) | ||
203 | + .add("prefixTree", prefixTree) | ||
204 | + .add("vpnNodeTree", vpnNodeTree) | ||
205 | + .add("vpnLinkTree", vpnLinkTree) | ||
206 | + .add("vpnPrefixTree", vpnPrefixTree) | ||
207 | + .toString(); | ||
208 | + } | ||
209 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment