Shashikanth VH | 3fe3798 | 2015-11-30 11:50:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 | |
| 14 | package org.onosproject.bgp.controller.impl; |
| 15 | |
| 16 | import java.util.Map; |
| 17 | import java.util.Set; |
| 18 | import java.util.TreeMap; |
| 19 | |
| 20 | import org.onosproject.bgp.controller.BgpController; |
| 21 | import org.onosproject.bgp.controller.BgpId; |
| 22 | import org.onosproject.bgp.controller.BgpLocalRib; |
| 23 | import org.onosproject.bgp.controller.BgpNodeListener; |
| 24 | import org.onosproject.bgp.controller.BgpSessionInfo; |
| 25 | import org.onosproject.bgpio.protocol.BgpLSNlri; |
| 26 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier; |
| 27 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
| 28 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; |
| 29 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
| 30 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; |
| 31 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier; |
| 32 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
| 33 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib; |
| 34 | import org.onosproject.bgpio.types.RouteDistinguisher; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
| 38 | import static com.google.common.base.Preconditions.checkNotNull; |
| 39 | import com.google.common.base.MoreObjects; |
| 40 | |
| 41 | /** |
| 42 | * Implementation of local RIB. |
| 43 | */ |
| 44 | public class BgpLocalRibImpl implements BgpLocalRib { |
| 45 | |
| 46 | private static final Logger log = LoggerFactory.getLogger(BgpLocalRibImpl.class); |
| 47 | private BgpController bgpController; |
| 48 | |
| 49 | private Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> nodeTree = new TreeMap<>(); |
| 50 | private Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib> linkTree = new TreeMap<>(); |
| 51 | private Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib> prefixTree = new TreeMap<>(); |
| 52 | |
| 53 | private Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnNodeTree |
| 54 | = new TreeMap<>(); |
| 55 | private Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnLinkTree |
| 56 | = new TreeMap<>(); |
| 57 | private Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnPrefixTree |
| 58 | = new TreeMap<>(); |
| 59 | |
| 60 | public BgpLocalRibImpl(BgpController bgpController) { |
| 61 | this.bgpController = bgpController; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Gets node NLRI tree. |
| 66 | * |
| 67 | * @return node tree |
| 68 | */ |
| 69 | public Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> nodeTree() { |
| 70 | return nodeTree; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Gets link NLRI tree. |
| 75 | * |
| 76 | * @return link tree |
| 77 | */ |
| 78 | public Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib> linkTree() { |
| 79 | return linkTree; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Gets prefix NLRI tree. |
| 84 | * |
| 85 | * @return prefix tree |
| 86 | */ |
| 87 | public Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib> prefixTree() { |
| 88 | return prefixTree; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets VPN node NLRI tree. |
| 93 | * |
| 94 | * @return vpn node NLRI tree |
| 95 | */ |
| 96 | public Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnNodeTree() { |
| 97 | return vpnNodeTree; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Gets VPN link NLRI tree. |
| 102 | * |
| 103 | * @return vpn link NLRI Tree |
| 104 | */ |
| 105 | public Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnLinkTree() { |
| 106 | return vpnLinkTree; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Gets VPN prefix NLRI tree. |
| 111 | * |
| 112 | * @return vpn prefix NLRI Tree |
| 113 | */ |
| 114 | public Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetailsLocalRib>> vpnPrefixTree() { |
| 115 | return vpnPrefixTree; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) { |
| 120 | int decisionResult; |
| 121 | |
| 122 | log.debug("Add to local RIB {}", details.toString()); |
| 123 | |
| 124 | PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib( |
| 125 | sessionInfo.remoteBgpId().ipAddress(), |
| 126 | sessionInfo.remoteBgpIdentifier(), |
| 127 | sessionInfo.remoteBgpASNum(), |
| 128 | sessionInfo.isIbgpSession(), details); |
| 129 | if (nlri instanceof BgpNodeLSNlriVer4) { |
| 130 | BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); |
| 131 | if (nodeTree.containsKey(nodeLsIdentifier)) { |
| 132 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 133 | // Compare local RIB entry with the current attribute |
| 134 | decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib); |
| 135 | if (decisionResult < 0) { |
| 136 | nodeTree.replace(nodeLsIdentifier, detailsLocRib); |
| 137 | log.debug("Local RIB update node: {}", detailsLocRib.toString()); |
| 138 | } |
| 139 | } else { |
| 140 | nodeTree.put(nodeLsIdentifier, detailsLocRib); |
| 141 | for (BgpNodeListener l : bgpController.listener()) { |
| 142 | l.addNode((BgpNodeLSNlriVer4) nlri); |
| 143 | } |
| 144 | log.debug("Local RIB ad node: {}", detailsLocRib.toString()); |
| 145 | } |
| 146 | } else if (nlri instanceof BgpLinkLsNlriVer4) { |
| 147 | BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); |
| 148 | if (linkTree.containsKey(linkLsIdentifier)) { |
| 149 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 150 | // Compare local RIB entry with the current attribute |
| 151 | decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib); |
| 152 | if (decisionResult < 0) { |
| 153 | linkTree.replace(linkLsIdentifier, detailsLocRib); |
| 154 | log.debug("Local RIB update link: {}", detailsLocRib.toString()); |
| 155 | } |
| 156 | } else { |
| 157 | linkTree.put(linkLsIdentifier, detailsLocRib); |
| 158 | log.debug("Local RIB add link: {}", detailsLocRib.toString()); |
| 159 | } |
| 160 | } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) { |
| 161 | BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); |
| 162 | if (prefixTree.containsKey(prefixIdentifier)) { |
| 163 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 164 | // Compare local RIB entry with the current attribute |
| 165 | decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib); |
| 166 | if (decisionResult < 0) { |
| 167 | prefixTree.replace(prefixIdentifier, detailsLocRib); |
| 168 | log.debug("Local RIB update prefix: {}", detailsLocRib.toString()); |
| 169 | } |
| 170 | } else { |
| 171 | prefixTree.put(prefixIdentifier, detailsLocRib); |
| 172 | log.debug("Local RIB add prefix: {}", detailsLocRib.toString()); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public void delete(BgpLSNlri nlri) { |
| 179 | log.debug("Delete from local RIB."); |
| 180 | |
| 181 | // Update local RIB |
| 182 | decisionProcess(nlri); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Update local RIB based on selection algorithm. |
| 187 | * |
| 188 | * @param nlri NLRI to update |
| 189 | */ |
| 190 | public void decisionProcess(BgpLSNlri nlri) { |
| 191 | checkNotNull(nlri); |
| 192 | if (nlri instanceof BgpNodeLSNlriVer4) { |
| 193 | selectionProcessNode(nlri, false); |
| 194 | } else if (nlri instanceof BgpLinkLsNlriVer4) { |
| 195 | selectionProcessLink(nlri, false); |
| 196 | } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) { |
| 197 | selectionProcessPrefix(nlri, false); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Update VPN local RIB . |
| 203 | * |
| 204 | * @param nlri NLRI to update |
| 205 | * @param routeDistinguisher VPN id to update |
| 206 | */ |
| 207 | public void decisionProcess(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) { |
| 208 | checkNotNull(nlri); |
| 209 | if (nlri instanceof BgpNodeLSNlriVer4) { |
| 210 | if (vpnNodeTree.containsKey(routeDistinguisher)) { |
| 211 | selectionProcessNode(nlri, true); |
| 212 | if (nodeTree.size() == 0) { |
| 213 | vpnNodeTree.remove(routeDistinguisher); |
| 214 | } |
| 215 | } |
| 216 | } else if (nlri instanceof BgpLinkLsNlriVer4) { |
| 217 | if (vpnLinkTree.containsKey(routeDistinguisher)) { |
| 218 | selectionProcessLink(nlri, true); |
| 219 | if (linkTree.size() == 0) { |
| 220 | vpnLinkTree.remove(routeDistinguisher); |
| 221 | } |
| 222 | } |
| 223 | } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) { |
| 224 | if (vpnPrefixTree.containsKey(routeDistinguisher)) { |
| 225 | selectionProcessPrefix(nlri, true); |
| 226 | if (prefixTree.size() == 0) { |
| 227 | vpnPrefixTree.remove(routeDistinguisher); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Selection process for local RIB node. |
| 235 | * |
| 236 | * @param nlri NLRI to update |
| 237 | * @param isVpnRib true if VPN local RIB, otherwise false |
| 238 | */ |
| 239 | public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) { |
| 240 | BgpPeerImpl peer; |
| 241 | BgpSessionInfo sessionInfo; |
| 242 | int decisionResult; |
| 243 | boolean containsKey; |
| 244 | |
| 245 | BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors(); |
| 246 | |
| 247 | if (nodeTree.containsKey(nodeLsIdentifier)) { |
| 248 | for (BgpNodeListener l : bgpController.listener()) { |
| 249 | l.deleteNode((BgpNodeLSNlriVer4) nlri); |
| 250 | } |
| 251 | log.debug("Local RIB delete node: {}", nodeLsIdentifier.toString()); |
| 252 | nodeTree.remove(nodeLsIdentifier); |
| 253 | } |
| 254 | |
| 255 | for (BgpId bgpId : bgpController.connectedPeers().keySet()) { |
| 256 | peer = (BgpPeerImpl) (bgpController.getPeer(bgpId)); |
| 257 | |
| 258 | if (nodeTree.containsKey(nodeLsIdentifier)) { |
| 259 | containsKey = (!isVpnRib) ? (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) : |
| 260 | (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier)); |
| 261 | |
| 262 | if (!containsKey) { |
| 263 | continue; |
| 264 | } |
| 265 | sessionInfo = peer.sessionInfo(); |
| 266 | PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib( |
| 267 | sessionInfo.remoteBgpId().ipAddress(), |
| 268 | sessionInfo.remoteBgpIdentifier(), |
| 269 | sessionInfo.remoteBgpASNum(), |
| 270 | sessionInfo.isIbgpSession(), |
| 271 | (!isVpnRib) ? |
| 272 | (peer.adjacencyRib().nodeTree() |
| 273 | .get(nodeLsIdentifier)) : |
| 274 | (peer.vpnAdjacencyRib().nodeTree() |
| 275 | .get(nodeLsIdentifier))); |
| 276 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 277 | decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib); |
| 278 | if (decisionResult < 0) { |
| 279 | nodeTree.replace(nodeLsIdentifier, detailsLocRib); |
| 280 | log.debug("Local RIB node updated: {}", detailsLocRib.toString()); |
| 281 | } |
| 282 | } else { |
| 283 | if (!isVpnRib) { |
| 284 | if (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) { |
| 285 | add(peer.sessionInfo(), nlri, peer.adjacencyRib().nodeTree().get(nodeLsIdentifier)); |
| 286 | } |
| 287 | } else { |
| 288 | if (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) { |
| 289 | add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().nodeTree().get(nodeLsIdentifier)); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Selection process for local RIB link. |
| 298 | * |
| 299 | * @param nlri NLRI to update |
| 300 | * @param isVpnRib true if VPN local RIB, otherwise false |
| 301 | */ |
| 302 | public void selectionProcessLink(BgpLSNlri nlri, boolean isVpnRib) { |
| 303 | BgpPeerImpl peer; |
| 304 | BgpSessionInfo sessionInfo; |
| 305 | int decisionResult; |
| 306 | boolean containsKey; |
| 307 | |
| 308 | BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier(); |
| 309 | |
| 310 | if (linkTree.containsKey(linkLsIdentifier)) { |
| 311 | log.debug("Local RIB remove link: {}", linkLsIdentifier.toString()); |
| 312 | linkTree.remove(linkLsIdentifier); |
| 313 | } |
| 314 | |
| 315 | for (BgpId bgpId : bgpController.connectedPeers().keySet()) { |
| 316 | peer = (BgpPeerImpl) (bgpController.getPeer(bgpId)); |
| 317 | |
| 318 | if (linkTree.containsKey(linkLsIdentifier)) { |
| 319 | |
| 320 | containsKey = (!isVpnRib) ? (peer.adjacencyRib().linkTree().containsKey(linkLsIdentifier)) : |
| 321 | (peer.vpnAdjacencyRib().linkTree().containsKey(linkLsIdentifier)); |
| 322 | |
| 323 | if (!containsKey) { |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | sessionInfo = peer.sessionInfo(); |
| 328 | |
| 329 | PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib( |
| 330 | sessionInfo.remoteBgpId().ipAddress(), |
| 331 | sessionInfo.remoteBgpIdentifier(), |
| 332 | sessionInfo.remoteBgpASNum(), |
| 333 | sessionInfo.isIbgpSession(), |
| 334 | ((!isVpnRib) ? |
| 335 | (peer.adjacencyRib().linkTree().get(linkLsIdentifier)) : |
| 336 | (peer.vpnAdjacencyRib().linkTree() |
| 337 | .get(linkLsIdentifier)))); |
| 338 | |
| 339 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 340 | decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib); |
| 341 | if (decisionResult < 0) { |
| 342 | linkTree.replace(linkLsIdentifier, detailsLocRib); |
| 343 | log.debug("Local RIB link updated: {}", detailsLocRib.toString()); |
| 344 | } |
| 345 | } else { |
| 346 | if (!isVpnRib) { |
| 347 | if (peer.adjacencyRib().linkTree().containsKey(linkLsIdentifier)) { |
| 348 | add(peer.sessionInfo(), nlri, peer.adjacencyRib().linkTree().get(linkLsIdentifier)); |
| 349 | } |
| 350 | } else { |
| 351 | if (peer.vpnAdjacencyRib().linkTree().containsKey(linkLsIdentifier)) { |
| 352 | add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().linkTree().get(linkLsIdentifier)); |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Selection process for local RIB prefix. |
| 361 | * |
| 362 | * @param nlri NLRI to update |
| 363 | * @param isVpnRib true if VPN local RIB, otherwise false |
| 364 | */ |
| 365 | public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) { |
| 366 | BgpPeerImpl peer; |
| 367 | BgpSessionInfo sessionInfo; |
| 368 | int decisionResult; |
| 369 | boolean containsKey; |
| 370 | |
| 371 | BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier(); |
| 372 | if (prefixTree.containsKey(prefixIdentifier)) { |
| 373 | log.debug("Local RIB remove prefix: {}", prefixIdentifier.toString()); |
| 374 | prefixTree.remove(prefixIdentifier); |
| 375 | } |
| 376 | |
| 377 | for (BgpId bgpId : bgpController.connectedPeers().keySet()) { |
| 378 | peer = (BgpPeerImpl) (bgpController.getPeer(bgpId)); |
| 379 | |
| 380 | if (prefixTree.containsKey(prefixIdentifier)) { |
| 381 | |
| 382 | containsKey = (!isVpnRib) ? (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) : |
| 383 | (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier)); |
| 384 | if (!containsKey) { |
| 385 | continue; |
| 386 | } |
| 387 | sessionInfo = peer.sessionInfo(); |
| 388 | |
| 389 | PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib( |
| 390 | sessionInfo.remoteBgpId().ipAddress(), |
| 391 | sessionInfo.remoteBgpIdentifier(), |
| 392 | sessionInfo.remoteBgpASNum(), |
| 393 | sessionInfo.isIbgpSession(), |
| 394 | ((!isVpnRib) ? |
| 395 | (peer.adjacencyRib().prefixTree() |
| 396 | .get(prefixIdentifier)) : |
| 397 | (peer.vpnAdjacencyRib().prefixTree() |
| 398 | .get(prefixIdentifier)))); |
| 399 | |
| 400 | BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); |
| 401 | decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib); |
| 402 | if (decisionResult < 0) { |
| 403 | prefixTree.replace(prefixIdentifier, detailsLocRib); |
| 404 | log.debug("local RIB prefix updated: {}", detailsLocRib.toString()); |
| 405 | } |
| 406 | } else { |
| 407 | if (!isVpnRib) { |
| 408 | if (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) { |
| 409 | add(peer.sessionInfo(), nlri, peer.adjacencyRib().prefixTree().get(prefixIdentifier)); |
| 410 | } else { |
| 411 | if (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier)) { |
| 412 | add(peer.sessionInfo(), nlri, peer.vpnAdjacencyRib().prefixTree().get(prefixIdentifier)); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details, |
| 422 | RouteDistinguisher routeDistinguisher) { |
| 423 | add(sessionInfo, nlri, details); |
| 424 | if (nlri instanceof BgpNodeLSNlriVer4) { |
| 425 | if (!vpnNodeTree.containsKey(routeDistinguisher)) { |
| 426 | vpnNodeTree.put(routeDistinguisher, nodeTree); |
| 427 | } |
| 428 | } else if (nlri instanceof BgpLinkLsNlriVer4) { |
| 429 | if (!vpnLinkTree.containsKey(routeDistinguisher)) { |
| 430 | vpnLinkTree.put(routeDistinguisher, linkTree); |
| 431 | } |
| 432 | } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) { |
| 433 | if (!vpnPrefixTree.containsKey(routeDistinguisher)) { |
| 434 | vpnPrefixTree.put(routeDistinguisher, prefixTree); |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) { |
| 441 | // Update local RIB |
| 442 | decisionProcess(nlri, routeDistinguisher); |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Update local RIB node based on avaliable peer adjacency RIB. |
| 447 | * |
| 448 | * @param o adjacency-in/VPN adjacency-in |
| 449 | */ |
| 450 | public void localRIBUpdateNode(Object o) { |
| 451 | |
| 452 | if (o instanceof AdjRibIn) { |
| 453 | AdjRibIn adjRib = (AdjRibIn) o; |
| 454 | log.debug("Update local RIB node."); |
| 455 | |
| 456 | Set<BgpNodeLSIdentifier> nodeKeys = adjRib.nodeTree().keySet(); |
| 457 | for (BgpNodeLSIdentifier key : nodeKeys) { |
| 458 | PathAttrNlriDetails pathAttrNlri = adjRib.nodeTree().get(key); |
| 459 | |
| 460 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri |
| 461 | .protocolID().getType(), key, false, null); |
| 462 | decisionProcess(nodeNlri); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | if (o instanceof VpnAdjRibIn) { |
| 467 | VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o; |
| 468 | log.debug("Update local RIB VPN node."); |
| 469 | Set<RouteDistinguisher> nodeKeysVpn = vpnAdjRib.vpnNodeTree().keySet(); |
| 470 | Map<BgpNodeLSIdentifier, PathAttrNlriDetails> node; |
| 471 | for (RouteDistinguisher keyVpnNode : nodeKeysVpn) { |
| 472 | node = vpnAdjRib.vpnNodeTree().get(keyVpnNode); |
| 473 | |
| 474 | Set<BgpNodeLSIdentifier> vpnNodeKeys = node.keySet(); |
| 475 | for (BgpNodeLSIdentifier key : vpnNodeKeys) { |
| 476 | PathAttrNlriDetails pathAttrNlri = vpnAdjRib.nodeTree().get(key); |
| 477 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(pathAttrNlri.identifier(), |
| 478 | pathAttrNlri.protocolID().getType(), |
| 479 | key, true, keyVpnNode); |
| 480 | decisionProcess(nodeNlri, keyVpnNode); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Update localRIB link based on avaliable peer adjacency RIB. |
| 488 | * |
| 489 | * @param o adjacency-in/VPN adjacency-in |
| 490 | */ |
| 491 | public void localRIBUpdateLink(Object o) { |
| 492 | |
| 493 | if (o instanceof AdjRibIn) { |
| 494 | AdjRibIn adjRib = (AdjRibIn) o; |
| 495 | log.debug("Update local RIB link."); |
| 496 | |
| 497 | Set<BgpLinkLSIdentifier> linkKeys = adjRib.linkTree().keySet(); |
| 498 | for (BgpLinkLSIdentifier key : linkKeys) { |
| 499 | PathAttrNlriDetails pathAttrNlri = adjRib.linkTree().get(key); |
| 500 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), |
| 501 | pathAttrNlri.identifier(), key, null, false); |
| 502 | decisionProcess(linkNlri); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | if (o instanceof VpnAdjRibIn) { |
| 507 | VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o; |
| 508 | log.debug("Update local RIB VPN link"); |
| 509 | |
| 510 | Set<RouteDistinguisher> linkKeysVpn = vpnAdjRib.vpnLinkTree().keySet(); |
| 511 | Map<BgpLinkLSIdentifier, PathAttrNlriDetails> link; |
| 512 | for (RouteDistinguisher keyVpnLink : linkKeysVpn) { |
| 513 | link = vpnAdjRib.vpnLinkTree().get(keyVpnLink); |
| 514 | |
| 515 | Set<BgpLinkLSIdentifier> vpnLinkKeys = link.keySet(); |
| 516 | for (BgpLinkLSIdentifier key : vpnLinkKeys) { |
| 517 | PathAttrNlriDetails pathAttrNlri = vpnAdjRib.linkTree().get(key); |
| 518 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), |
| 519 | pathAttrNlri.identifier(), key, keyVpnLink, |
| 520 | true); |
| 521 | decisionProcess(linkNlri, keyVpnLink); |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Update localRIB prefix based on avaliable peer adjacency RIB. |
| 529 | * |
| 530 | * @param o instance of adjacency-in/VPN adjacency-in |
| 531 | */ |
| 532 | public void localRIBUpdatePrefix(Object o) { |
| 533 | |
| 534 | if (o instanceof AdjRibIn) { |
| 535 | AdjRibIn adjRib = (AdjRibIn) o; |
| 536 | log.debug("Update local RIB prefix."); |
| 537 | |
| 538 | Set<BgpPrefixLSIdentifier> prefixKeys = adjRib.prefixTree().keySet(); |
| 539 | for (BgpPrefixLSIdentifier key : prefixKeys) { |
| 540 | PathAttrNlriDetails pathAttrNlri = adjRib.prefixTree().get(key); |
| 541 | BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4( |
| 542 | pathAttrNlri.identifier(), |
| 543 | pathAttrNlri.protocolID().getType(), |
| 544 | key, null, false); |
| 545 | decisionProcess(prefixNlri); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (o instanceof VpnAdjRibIn) { |
| 550 | VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o; |
| 551 | log.debug("Update local RIB VPN prefix."); |
| 552 | |
| 553 | Set<RouteDistinguisher> prefixKeysVpn = vpnAdjRib.vpnPrefixTree().keySet(); |
| 554 | Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefix; |
| 555 | for (RouteDistinguisher keyVpnPrefix : prefixKeysVpn) { |
| 556 | prefix = vpnAdjRib.vpnPrefixTree().get(keyVpnPrefix); |
| 557 | |
| 558 | Set<BgpPrefixLSIdentifier> vpnPrefixKeys = prefix.keySet(); |
| 559 | for (BgpPrefixLSIdentifier key : vpnPrefixKeys) { |
| 560 | PathAttrNlriDetails pathAttrNlri = vpnAdjRib.prefixTree().get(key); |
| 561 | BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(), |
| 562 | pathAttrNlri.protocolID() |
| 563 | .getType(), key, |
| 564 | keyVpnPrefix, true); |
| 565 | decisionProcess(prefixNlri, keyVpnPrefix); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Update localRIB. |
| 573 | * |
| 574 | * @param adjRibIn adjacency RIB-in |
| 575 | */ |
| 576 | public void localRIBUpdate(AdjRibIn adjRibIn) { |
| 577 | log.debug("Update local RIB."); |
| 578 | |
| 579 | localRIBUpdateNode(adjRibIn); |
| 580 | localRIBUpdateLink(adjRibIn); |
| 581 | localRIBUpdatePrefix(adjRibIn); |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Update localRIB. |
| 586 | * |
| 587 | * @param vpnAdjRibIn VPN adjacency RIB-in |
| 588 | */ |
| 589 | public void localRIBUpdate(VpnAdjRibIn vpnAdjRibIn) { |
| 590 | log.debug("Update VPN local RIB."); |
| 591 | |
| 592 | localRIBUpdateNode(vpnAdjRibIn); |
| 593 | localRIBUpdateLink(vpnAdjRibIn); |
| 594 | localRIBUpdatePrefix(vpnAdjRibIn); |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | public String toString() { |
| 599 | return MoreObjects.toStringHelper(getClass()).omitNullValues().add("nodeTree", nodeTree) |
| 600 | .add("linkTree", linkTree).add("prefixTree", prefixTree).add("vpnNodeTree", vpnNodeTree) |
| 601 | .add("vpnLinkTree", vpnLinkTree).add("vpnPrefixTree", vpnPrefixTree).toString(); |
| 602 | } |
| 603 | } |