blob: 4f2735f87d4a923f78481aa1d7810cea056b2e45 [file] [log] [blame]
Shashikanth VH3fe37982015-11-30 11:50:07 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Shashikanth VH3fe37982015-11-30 11:50:07 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
12 */
13
14package org.onosproject.bgp.controller.impl;
15
Jonathan Hart51539b82015-10-29 09:53:04 -070016import com.google.common.base.MoreObjects;
Priyanka Bfc51c952016-03-26 14:30:33 +053017
Shashikanth VH3fe37982015-11-30 11:50:07 +053018import org.onosproject.bgp.controller.BgpController;
19import org.onosproject.bgp.controller.BgpId;
Priyanka Bfc51c952016-03-26 14:30:33 +053020import org.onosproject.bgp.controller.BgpLinkListener;
Shashikanth VH3fe37982015-11-30 11:50:07 +053021import org.onosproject.bgp.controller.BgpLocalRib;
22import org.onosproject.bgp.controller.BgpNodeListener;
23import org.onosproject.bgp.controller.BgpSessionInfo;
Priyanka Bfc51c952016-03-26 14:30:33 +053024import org.onosproject.bgpio.exceptions.BgpParseException;
Shashikanth VH3fe37982015-11-30 11:50:07 +053025import org.onosproject.bgpio.protocol.BgpLSNlri;
26import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
27import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
28import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
29import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
30import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
31import org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier;
32import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
33import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib;
34import org.onosproject.bgpio.types.RouteDistinguisher;
35import org.slf4j.Logger;
36import org.slf4j.LoggerFactory;
37
Jonathan Hart51539b82015-10-29 09:53:04 -070038import java.util.Map;
39import java.util.Set;
40import java.util.TreeMap;
41
Shashikanth VH3fe37982015-11-30 11:50:07 +053042import static com.google.common.base.Preconditions.checkNotNull;
Shashikanth VH3fe37982015-11-30 11:50:07 +053043
44/**
45 * Implementation of local RIB.
46 */
47public class BgpLocalRibImpl implements BgpLocalRib {
48
49 private static final Logger log = LoggerFactory.getLogger(BgpLocalRibImpl.class);
50 private BgpController bgpController;
51
52 private Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> nodeTree = new TreeMap<>();
53 private Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib> linkTree = new TreeMap<>();
54 private Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib> prefixTree = new TreeMap<>();
55
56 private Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnNodeTree
57 = new TreeMap<>();
58 private Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnLinkTree
59 = new TreeMap<>();
60 private Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnPrefixTree
61 = new TreeMap<>();
62
63 public BgpLocalRibImpl(BgpController bgpController) {
64 this.bgpController = bgpController;
65 }
66
67 /**
68 * Gets node NLRI tree.
69 *
70 * @return node tree
71 */
72 public Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> nodeTree() {
73 return nodeTree;
74 }
75
76 /**
77 * Gets link NLRI tree.
78 *
79 * @return link tree
80 */
81 public Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib> linkTree() {
82 return linkTree;
83 }
84
85 /**
86 * Gets prefix NLRI tree.
87 *
88 * @return prefix tree
89 */
90 public Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib> prefixTree() {
91 return prefixTree;
92 }
93
94 /**
95 * Gets VPN node NLRI tree.
96 *
97 * @return vpn node NLRI tree
98 */
99 public Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnNodeTree() {
100 return vpnNodeTree;
101 }
102
103 /**
104 * Gets VPN link NLRI tree.
105 *
106 * @return vpn link NLRI Tree
107 */
108 public Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnLinkTree() {
109 return vpnLinkTree;
110 }
111
112 /**
113 * Gets VPN prefix NLRI tree.
114 *
115 * @return vpn prefix NLRI Tree
116 */
117 public Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnPrefixTree() {
118 return vpnPrefixTree;
119 }
120
121 @Override
Priyanka Bfc51c952016-03-26 14:30:33 +0530122 public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530123 int decisionResult;
124
125 log.debug("Add to local RIB {}", details.toString());
126
127 PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(
128 sessionInfo.remoteBgpId().ipAddress(),
129 sessionInfo.remoteBgpIdentifier(),
130 sessionInfo.remoteBgpASNum(),
131 sessionInfo.isIbgpSession(), details);
132 if (nlri instanceof BgpNodeLSNlriVer4) {
133 BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
134 if (nodeTree.containsKey(nodeLsIdentifier)) {
135 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
136 // Compare local RIB entry with the current attribute
137 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
138 if (decisionResult < 0) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530139 for (BgpNodeListener l : bgpController.listener()) {
140 l.addNode((BgpNodeLSNlriVer4) nlri, details);
141 }
Shashikanth VH3fe37982015-11-30 11:50:07 +0530142 nodeTree.replace(nodeLsIdentifier, detailsLocRib);
143 log.debug("Local RIB update node: {}", detailsLocRib.toString());
144 }
145 } else {
146 nodeTree.put(nodeLsIdentifier, detailsLocRib);
147 for (BgpNodeListener l : bgpController.listener()) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530148 l.addNode((BgpNodeLSNlriVer4) nlri, details);
Shashikanth VH3fe37982015-11-30 11:50:07 +0530149 }
150 log.debug("Local RIB ad node: {}", detailsLocRib.toString());
151 }
152 } else if (nlri instanceof BgpLinkLsNlriVer4) {
153 BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
154 if (linkTree.containsKey(linkLsIdentifier)) {
155 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
156 // Compare local RIB entry with the current attribute
157 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
158 if (decisionResult < 0) {
159 linkTree.replace(linkLsIdentifier, detailsLocRib);
Priyanka Bfc51c952016-03-26 14:30:33 +0530160 for (BgpLinkListener l : bgpController.linkListener()) {
161 l.addLink((BgpLinkLsNlriVer4) nlri, details);
162 }
Shashikanth VH3fe37982015-11-30 11:50:07 +0530163 log.debug("Local RIB update link: {}", detailsLocRib.toString());
164 }
165 } else {
166 linkTree.put(linkLsIdentifier, detailsLocRib);
Priyanka Bfc51c952016-03-26 14:30:33 +0530167 for (BgpLinkListener l : bgpController.linkListener()) {
168 l.addLink((BgpLinkLsNlriVer4) nlri, details);
169 }
Shashikanth VH3fe37982015-11-30 11:50:07 +0530170 log.debug("Local RIB add link: {}", detailsLocRib.toString());
171 }
172 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
173 BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
174 if (prefixTree.containsKey(prefixIdentifier)) {
175 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
176 // Compare local RIB entry with the current attribute
177 decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
178 if (decisionResult < 0) {
179 prefixTree.replace(prefixIdentifier, detailsLocRib);
180 log.debug("Local RIB update prefix: {}", detailsLocRib.toString());
181 }
182 } else {
183 prefixTree.put(prefixIdentifier, detailsLocRib);
184 log.debug("Local RIB add prefix: {}", detailsLocRib.toString());
185 }
186 }
187 }
188
189 @Override
Priyanka Bfc51c952016-03-26 14:30:33 +0530190 public void delete(BgpLSNlri nlri) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530191 log.debug("Delete from local RIB.");
192
193 // Update local RIB
194 decisionProcess(nlri);
195 }
196
197 /**
198 * Update local RIB based on selection algorithm.
199 *
200 * @param nlri NLRI to update
Priyanka Bfc51c952016-03-26 14:30:33 +0530201 * @throws BgpParseException while updating to local RIB
Shashikanth VH3fe37982015-11-30 11:50:07 +0530202 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530203 public void decisionProcess(BgpLSNlri nlri) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530204 checkNotNull(nlri);
205 if (nlri instanceof BgpNodeLSNlriVer4) {
206 selectionProcessNode(nlri, false);
207 } else if (nlri instanceof BgpLinkLsNlriVer4) {
208 selectionProcessLink(nlri, false);
209 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
210 selectionProcessPrefix(nlri, false);
211 }
212 }
213
214 /**
215 * Update VPN local RIB .
216 *
217 * @param nlri NLRI to update
218 * @param routeDistinguisher VPN id to update
Priyanka Bfc51c952016-03-26 14:30:33 +0530219 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530220 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530221 public void decisionProcess(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530222 checkNotNull(nlri);
223 if (nlri instanceof BgpNodeLSNlriVer4) {
224 if (vpnNodeTree.containsKey(routeDistinguisher)) {
225 selectionProcessNode(nlri, true);
226 if (nodeTree.size() == 0) {
227 vpnNodeTree.remove(routeDistinguisher);
228 }
229 }
230 } else if (nlri instanceof BgpLinkLsNlriVer4) {
231 if (vpnLinkTree.containsKey(routeDistinguisher)) {
232 selectionProcessLink(nlri, true);
233 if (linkTree.size() == 0) {
234 vpnLinkTree.remove(routeDistinguisher);
235 }
236 }
237 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
238 if (vpnPrefixTree.containsKey(routeDistinguisher)) {
239 selectionProcessPrefix(nlri, true);
240 if (prefixTree.size() == 0) {
241 vpnPrefixTree.remove(routeDistinguisher);
242 }
243 }
244 }
245 }
246
247 /**
248 * Selection process for local RIB node.
249 *
250 * @param nlri NLRI to update
251 * @param isVpnRib true if VPN local RIB, otherwise false
Priyanka Bfc51c952016-03-26 14:30:33 +0530252 * @throws BgpParseException throws BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530253 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530254 public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530255 BgpPeerImpl peer;
256 BgpSessionInfo sessionInfo;
257 int decisionResult;
258 boolean containsKey;
259
260 BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
261
262 if (nodeTree.containsKey(nodeLsIdentifier)) {
263 for (BgpNodeListener l : bgpController.listener()) {
264 l.deleteNode((BgpNodeLSNlriVer4) nlri);
265 }
266 log.debug("Local RIB delete node: {}", nodeLsIdentifier.toString());
267 nodeTree.remove(nodeLsIdentifier);
268 }
269
270 for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
271 peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
272
273 if (nodeTree.containsKey(nodeLsIdentifier)) {
274 containsKey = (!isVpnRib) ? (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) :
275 (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier));
276
277 if (!containsKey) {
278 continue;
279 }
280 sessionInfo = peer.sessionInfo();
281 PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(
282 sessionInfo.remoteBgpId().ipAddress(),
283 sessionInfo.remoteBgpIdentifier(),
284 sessionInfo.remoteBgpASNum(),
285 sessionInfo.isIbgpSession(),
286 (!isVpnRib) ?
287 (peer.adjacencyRib().nodeTree()
288 .get(nodeLsIdentifier)) :
289 (peer.vpnAdjacencyRib().nodeTree()
290 .get(nodeLsIdentifier)));
291 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
292 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
293 if (decisionResult < 0) {
294 nodeTree.replace(nodeLsIdentifier, detailsLocRib);
295 log.debug("Local RIB node updated: {}", detailsLocRib.toString());
296 }
297 } else {
298 if (!isVpnRib) {
299 if (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) {
300 add(peer.sessionInfo(), nlri, peer.adjacencyRib().nodeTree().get(nodeLsIdentifier));
301 }
302 } else {
303 if (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) {
304 add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().nodeTree().get(nodeLsIdentifier));
305 }
306 }
307 }
308 }
309 }
310
311 /**
312 * Selection process for local RIB link.
313 *
314 * @param nlri NLRI to update
315 * @param isVpnRib true if VPN local RIB, otherwise false
Priyanka Bfc51c952016-03-26 14:30:33 +0530316 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530317 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530318 public void selectionProcessLink(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530319 BgpPeerImpl peer;
320 BgpSessionInfo sessionInfo;
321 int decisionResult;
322 boolean containsKey;
323
324 BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
325
326 if (linkTree.containsKey(linkLsIdentifier)) {
327 log.debug("Local RIB remove link: {}", linkLsIdentifier.toString());
Priyanka Bfc51c952016-03-26 14:30:33 +0530328 for (BgpLinkListener l : bgpController.linkListener()) {
329 l.deleteLink((BgpLinkLsNlriVer4) nlri);
330 }
Shashikanth VH3fe37982015-11-30 11:50:07 +0530331 linkTree.remove(linkLsIdentifier);
332 }
333
334 for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
335 peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
336
337 if (linkTree.containsKey(linkLsIdentifier)) {
338
339 containsKey = (!isVpnRib) ? (peer.adjacencyRib().linkTree().containsKey(linkLsIdentifier)) :
340 (peer.vpnAdjacencyRib().linkTree().containsKey(linkLsIdentifier));
341
342 if (!containsKey) {
343 continue;
344 }
345
346 sessionInfo = peer.sessionInfo();
347
348 PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(
349 sessionInfo.remoteBgpId().ipAddress(),
350 sessionInfo.remoteBgpIdentifier(),
351 sessionInfo.remoteBgpASNum(),
352 sessionInfo.isIbgpSession(),
353 ((!isVpnRib) ?
354 (peer.adjacencyRib().linkTree().get(linkLsIdentifier)) :
355 (peer.vpnAdjacencyRib().linkTree()
356 .get(linkLsIdentifier))));
357
358 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
359 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
360 if (decisionResult < 0) {
361 linkTree.replace(linkLsIdentifier, detailsLocRib);
362 log.debug("Local RIB link updated: {}", detailsLocRib.toString());
363 }
364 } else {
365 if (!isVpnRib) {
366 if (peer.adjacencyRib().linkTree().containsKey(linkLsIdentifier)) {
367 add(peer.sessionInfo(), nlri, peer.adjacencyRib().linkTree().get(linkLsIdentifier));
368 }
369 } else {
370 if (peer.vpnAdjacencyRib().linkTree().containsKey(linkLsIdentifier)) {
371 add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().linkTree().get(linkLsIdentifier));
372 }
373 }
374 }
375 }
376 }
377
378 /**
379 * Selection process for local RIB prefix.
380 *
381 * @param nlri NLRI to update
382 * @param isVpnRib true if VPN local RIB, otherwise false
Priyanka Bfc51c952016-03-26 14:30:33 +0530383 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530384 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530385 public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530386 BgpPeerImpl peer;
387 BgpSessionInfo sessionInfo;
388 int decisionResult;
389 boolean containsKey;
390
391 BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
392 if (prefixTree.containsKey(prefixIdentifier)) {
393 log.debug("Local RIB remove prefix: {}", prefixIdentifier.toString());
394 prefixTree.remove(prefixIdentifier);
395 }
396
397 for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
398 peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
399
400 if (prefixTree.containsKey(prefixIdentifier)) {
401
402 containsKey = (!isVpnRib) ? (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) :
403 (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier));
404 if (!containsKey) {
405 continue;
406 }
407 sessionInfo = peer.sessionInfo();
408
409 PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(
410 sessionInfo.remoteBgpId().ipAddress(),
411 sessionInfo.remoteBgpIdentifier(),
412 sessionInfo.remoteBgpASNum(),
413 sessionInfo.isIbgpSession(),
414 ((!isVpnRib) ?
415 (peer.adjacencyRib().prefixTree()
416 .get(prefixIdentifier)) :
417 (peer.vpnAdjacencyRib().prefixTree()
418 .get(prefixIdentifier))));
419
420 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
421 decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
422 if (decisionResult < 0) {
423 prefixTree.replace(prefixIdentifier, detailsLocRib);
424 log.debug("local RIB prefix updated: {}", detailsLocRib.toString());
425 }
426 } else {
427 if (!isVpnRib) {
428 if (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) {
429 add(peer.sessionInfo(), nlri, peer.adjacencyRib().prefixTree().get(prefixIdentifier));
430 } else {
431 if (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier)) {
432 add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().prefixTree().get(prefixIdentifier));
433 }
434 }
435 }
436 }
437 }
438 }
439
440 @Override
441 public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details,
Priyanka Bfc51c952016-03-26 14:30:33 +0530442 RouteDistinguisher routeDistinguisher) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530443 add(sessionInfo, nlri, details);
444 if (nlri instanceof BgpNodeLSNlriVer4) {
445 if (!vpnNodeTree.containsKey(routeDistinguisher)) {
446 vpnNodeTree.put(routeDistinguisher, nodeTree);
447 }
448 } else if (nlri instanceof BgpLinkLsNlriVer4) {
449 if (!vpnLinkTree.containsKey(routeDistinguisher)) {
450 vpnLinkTree.put(routeDistinguisher, linkTree);
451 }
452 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
453 if (!vpnPrefixTree.containsKey(routeDistinguisher)) {
454 vpnPrefixTree.put(routeDistinguisher, prefixTree);
455 }
456 }
457 }
458
459 @Override
Priyanka Bfc51c952016-03-26 14:30:33 +0530460 public void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530461 // Update local RIB
462 decisionProcess(nlri, routeDistinguisher);
463 }
464
465 /**
466 * Update local RIB node based on avaliable peer adjacency RIB.
467 *
468 * @param o adjacency-in/VPN adjacency-in
Priyanka Bfc51c952016-03-26 14:30:33 +0530469 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530470 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530471 public void localRibUpdateNode(Object o) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530472
473 if (o instanceof AdjRibIn) {
474 AdjRibIn adjRib = (AdjRibIn) o;
475 log.debug("Update local RIB node.");
476
477 Set<BgpNodeLSIdentifier> nodeKeys = adjRib.nodeTree().keySet();
478 for (BgpNodeLSIdentifier key : nodeKeys) {
479 PathAttrNlriDetails pathAttrNlri = adjRib.nodeTree().get(key);
480
481 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri
482 .protocolID().getType(), key, false, null);
483 decisionProcess(nodeNlri);
484 }
485 }
486
487 if (o instanceof VpnAdjRibIn) {
488 VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
489 log.debug("Update local RIB VPN node.");
490 Set<RouteDistinguisher> nodeKeysVpn = vpnAdjRib.vpnNodeTree().keySet();
491 Map<BgpNodeLSIdentifier, PathAttrNlriDetails> node;
492 for (RouteDistinguisher keyVpnNode : nodeKeysVpn) {
493 node = vpnAdjRib.vpnNodeTree().get(keyVpnNode);
494
495 Set<BgpNodeLSIdentifier> vpnNodeKeys = node.keySet();
496 for (BgpNodeLSIdentifier key : vpnNodeKeys) {
497 PathAttrNlriDetails pathAttrNlri = vpnAdjRib.nodeTree().get(key);
498 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(pathAttrNlri.identifier(),
499 pathAttrNlri.protocolID().getType(),
500 key, true, keyVpnNode);
501 decisionProcess(nodeNlri, keyVpnNode);
502 }
503 }
504 }
505 }
506
507 /**
508 * Update localRIB link based on avaliable peer adjacency RIB.
509 *
510 * @param o adjacency-in/VPN adjacency-in
Priyanka Bfc51c952016-03-26 14:30:33 +0530511 * @throws BgpParseException BGP parse exceptions
Shashikanth VH3fe37982015-11-30 11:50:07 +0530512 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530513 public void localRibUpdateLink(Object o) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530514
515 if (o instanceof AdjRibIn) {
516 AdjRibIn adjRib = (AdjRibIn) o;
517 log.debug("Update local RIB link.");
518
519 Set<BgpLinkLSIdentifier> linkKeys = adjRib.linkTree().keySet();
520 for (BgpLinkLSIdentifier key : linkKeys) {
521 PathAttrNlriDetails pathAttrNlri = adjRib.linkTree().get(key);
522 BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(),
523 pathAttrNlri.identifier(), key, null, false);
524 decisionProcess(linkNlri);
525 }
526 }
527
528 if (o instanceof VpnAdjRibIn) {
529 VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
530 log.debug("Update local RIB VPN link");
531
532 Set<RouteDistinguisher> linkKeysVpn = vpnAdjRib.vpnLinkTree().keySet();
533 Map<BgpLinkLSIdentifier, PathAttrNlriDetails> link;
534 for (RouteDistinguisher keyVpnLink : linkKeysVpn) {
535 link = vpnAdjRib.vpnLinkTree().get(keyVpnLink);
536
537 Set<BgpLinkLSIdentifier> vpnLinkKeys = link.keySet();
538 for (BgpLinkLSIdentifier key : vpnLinkKeys) {
539 PathAttrNlriDetails pathAttrNlri = vpnAdjRib.linkTree().get(key);
540 BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(),
541 pathAttrNlri.identifier(), key, keyVpnLink,
542 true);
543 decisionProcess(linkNlri, keyVpnLink);
544 }
545 }
546 }
547 }
548
549 /**
550 * Update localRIB prefix based on avaliable peer adjacency RIB.
551 *
552 * @param o instance of adjacency-in/VPN adjacency-in
Priyanka Bfc51c952016-03-26 14:30:33 +0530553 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530554 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530555 public void localRibUpdatePrefix(Object o) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530556
557 if (o instanceof AdjRibIn) {
558 AdjRibIn adjRib = (AdjRibIn) o;
559 log.debug("Update local RIB prefix.");
560
561 Set<BgpPrefixLSIdentifier> prefixKeys = adjRib.prefixTree().keySet();
562 for (BgpPrefixLSIdentifier key : prefixKeys) {
563 PathAttrNlriDetails pathAttrNlri = adjRib.prefixTree().get(key);
564 BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(
565 pathAttrNlri.identifier(),
566 pathAttrNlri.protocolID().getType(),
567 key, null, false);
568 decisionProcess(prefixNlri);
569 }
570 }
571
572 if (o instanceof VpnAdjRibIn) {
573 VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
574 log.debug("Update local RIB VPN prefix.");
575
576 Set<RouteDistinguisher> prefixKeysVpn = vpnAdjRib.vpnPrefixTree().keySet();
577 Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefix;
578 for (RouteDistinguisher keyVpnPrefix : prefixKeysVpn) {
579 prefix = vpnAdjRib.vpnPrefixTree().get(keyVpnPrefix);
580
581 Set<BgpPrefixLSIdentifier> vpnPrefixKeys = prefix.keySet();
582 for (BgpPrefixLSIdentifier key : vpnPrefixKeys) {
583 PathAttrNlriDetails pathAttrNlri = vpnAdjRib.prefixTree().get(key);
584 BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(),
585 pathAttrNlri.protocolID()
586 .getType(), key,
587 keyVpnPrefix, true);
588 decisionProcess(prefixNlri, keyVpnPrefix);
589 }
590 }
591 }
592 }
593
594 /**
595 * Update localRIB.
596 *
597 * @param adjRibIn adjacency RIB-in
Priyanka Bfc51c952016-03-26 14:30:33 +0530598 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530599 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530600 public void localRibUpdate(AdjRibIn adjRibIn) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530601 log.debug("Update local RIB.");
602
Jonathan Hart51539b82015-10-29 09:53:04 -0700603 localRibUpdateNode(adjRibIn);
604 localRibUpdateLink(adjRibIn);
605 localRibUpdatePrefix(adjRibIn);
Shashikanth VH3fe37982015-11-30 11:50:07 +0530606 }
607
608 /**
609 * Update localRIB.
610 *
611 * @param vpnAdjRibIn VPN adjacency RIB-in
Priyanka Bfc51c952016-03-26 14:30:33 +0530612 * @throws BgpParseException BGP parse exception
Shashikanth VH3fe37982015-11-30 11:50:07 +0530613 */
Priyanka Bfc51c952016-03-26 14:30:33 +0530614 public void localRibUpdate(VpnAdjRibIn vpnAdjRibIn) throws BgpParseException {
Shashikanth VH3fe37982015-11-30 11:50:07 +0530615 log.debug("Update VPN local RIB.");
616
Jonathan Hart51539b82015-10-29 09:53:04 -0700617 localRibUpdateNode(vpnAdjRibIn);
618 localRibUpdateLink(vpnAdjRibIn);
619 localRibUpdatePrefix(vpnAdjRibIn);
Shashikanth VH3fe37982015-11-30 11:50:07 +0530620 }
621
622 @Override
623 public String toString() {
624 return MoreObjects.toStringHelper(getClass()).omitNullValues().add("nodeTree", nodeTree)
625 .add("linkTree", linkTree).add("prefixTree", prefixTree).add("vpnNodeTree", vpnNodeTree)
626 .add("vpnLinkTree", vpnLinkTree).add("vpnPrefixTree", vpnPrefixTree).toString();
627 }
628}