Committed by
Gerrit Code Review
[ONOS-2606] Bgp local RIB implementation.
Change-Id: I39eadec95fa1e1328c73efabb2a50bb438075809
Showing
7 changed files
with
755 additions
and
8 deletions
| ... | @@ -95,6 +95,20 @@ public interface BgpController { | ... | @@ -95,6 +95,20 @@ public interface BgpController { |
| 95 | int connectedPeerCount(); | 95 | int connectedPeerCount(); |
| 96 | 96 | ||
| 97 | /** | 97 | /** |
| 98 | + * Return BGP local RIB instance with VPN. | ||
| 99 | + * | ||
| 100 | + * @return BGPLocalRibImpl local RIB with VPN | ||
| 101 | + */ | ||
| 102 | + BgpLocalRib bgpLocalRibVpn(); | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Return BGP local RIB instance. | ||
| 106 | + * | ||
| 107 | + * @return BGPLocalRibImpl local RIB | ||
| 108 | + */ | ||
| 109 | + BgpLocalRib bgpLocalRib(); | ||
| 110 | + | ||
| 111 | + /** | ||
| 98 | * Return BGP peer manager. | 112 | * Return BGP peer manager. |
| 99 | * | 113 | * |
| 100 | * @return BGPPeerManager peer manager instance | 114 | * @return BGPPeerManager peer manager instance | ... | ... |
| ... | @@ -440,7 +440,9 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler { | ... | @@ -440,7 +440,9 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler { |
| 440 | // which we obviously don't want. | 440 | // which we obviously don't want. |
| 441 | log.debug("{}:removal called", getPeerInfoString()); | 441 | log.debug("{}:removal called", getPeerInfoString()); |
| 442 | if (bgpPeer != null) { | 442 | if (bgpPeer != null) { |
| 443 | + BgpPeerImpl peer = (BgpPeerImpl) bgpPeer; | ||
| 443 | peerManager.removeConnectedPeer(thisbgpId); | 444 | peerManager.removeConnectedPeer(thisbgpId); |
| 445 | + peer.updateLocalRIBOnPeerDisconnect(); | ||
| 444 | } | 446 | } |
| 445 | 447 | ||
| 446 | // Retry connection if connection is lost to bgp speaker/peer | 448 | // Retry connection if connection is lost to bgp speaker/peer | ... | ... |
| ... | @@ -21,8 +21,14 @@ import java.util.Set; | ... | @@ -21,8 +21,14 @@ import java.util.Set; |
| 21 | import java.util.TreeMap; | 21 | import java.util.TreeMap; |
| 22 | 22 | ||
| 23 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
| 24 | +import org.onlab.packet.IpAddress; | ||
| 24 | import org.onosproject.bgp.controller.BgpCfg; | 25 | import org.onosproject.bgp.controller.BgpCfg; |
| 26 | +import org.onosproject.bgp.controller.BgpConnectPeer; | ||
| 27 | +import org.onosproject.bgp.controller.BgpController; | ||
| 28 | +import org.onosproject.bgp.controller.BgpId; | ||
| 29 | +import org.onosproject.bgp.controller.BgpPeer; | ||
| 25 | import org.onosproject.bgp.controller.BgpPeerCfg; | 30 | import org.onosproject.bgp.controller.BgpPeerCfg; |
| 31 | +import org.onosproject.bgp.controller.impl.BgpControllerImpl.BgpPeerManagerImpl; | ||
| 26 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; | 33 | import org.slf4j.LoggerFactory; |
| 28 | 34 | ||
| ... | @@ -48,12 +54,16 @@ public class BgpConfig implements BgpCfg { | ... | @@ -48,12 +54,16 @@ public class BgpConfig implements BgpCfg { |
| 48 | 54 | ||
| 49 | private Ip4Address routerId = null; | 55 | private Ip4Address routerId = null; |
| 50 | private TreeMap<String, BgpPeerCfg> bgpPeerTree = new TreeMap<>(); | 56 | private TreeMap<String, BgpPeerCfg> bgpPeerTree = new TreeMap<>(); |
| 57 | + private BgpConnectPeer connectPeer; | ||
| 58 | + private BgpPeerManagerImpl peerManager; | ||
| 59 | + private BgpController bgpController; | ||
| 51 | 60 | ||
| 52 | - /** | 61 | + /* |
| 53 | * Constructor to initialize the values. | 62 | * Constructor to initialize the values. |
| 54 | */ | 63 | */ |
| 55 | - public BgpConfig() { | 64 | + public BgpConfig(BgpController bgpController) { |
| 56 | - | 65 | + this.bgpController = bgpController; |
| 66 | + this.peerManager = (BgpPeerManagerImpl) bgpController.peerManager(); | ||
| 57 | this.holdTime = DEFAULT_HOLD_TIMER; | 67 | this.holdTime = DEFAULT_HOLD_TIMER; |
| 58 | this.maxConnRetryTime = DEFAULT_CONN_RETRY_TIME; | 68 | this.maxConnRetryTime = DEFAULT_CONN_RETRY_TIME; |
| 59 | this.maxConnRetryCount = DEFAULT_CONN_RETRY_COUNT; | 69 | this.maxConnRetryCount = DEFAULT_CONN_RETRY_COUNT; |
| ... | @@ -172,7 +182,12 @@ public class BgpConfig implements BgpCfg { | ... | @@ -172,7 +182,12 @@ public class BgpConfig implements BgpCfg { |
| 172 | 182 | ||
| 173 | if (lspeer != null) { | 183 | if (lspeer != null) { |
| 174 | lspeer.setSelfInnitConnection(true); | 184 | lspeer.setSelfInnitConnection(true); |
| 175 | - // TODO: initiate peer connection | 185 | + |
| 186 | + if (lspeer.connectPeer() == null) { | ||
| 187 | + connectPeer = new BgpConnectPeerImpl(bgpController, routerid, Controller.getBgpPortNum()); | ||
| 188 | + lspeer.setConnectPeer(connectPeer); | ||
| 189 | + connectPeer.connectPeer(); | ||
| 190 | + } | ||
| 176 | return true; | 191 | return true; |
| 177 | } | 192 | } |
| 178 | 193 | ||
| ... | @@ -185,7 +200,6 @@ public class BgpConfig implements BgpCfg { | ... | @@ -185,7 +200,6 @@ public class BgpConfig implements BgpCfg { |
| 185 | 200 | ||
| 186 | if (lspeer != null) { | 201 | if (lspeer != null) { |
| 187 | 202 | ||
| 188 | - //TODO DISCONNECT PEER | ||
| 189 | disconnectPeer(routerid); | 203 | disconnectPeer(routerid); |
| 190 | lspeer.setSelfInnitConnection(false); | 204 | lspeer.setSelfInnitConnection(false); |
| 191 | lspeer = this.bgpPeerTree.remove(routerid); | 205 | lspeer = this.bgpPeerTree.remove(routerid); |
| ... | @@ -204,7 +218,12 @@ public class BgpConfig implements BgpCfg { | ... | @@ -204,7 +218,12 @@ public class BgpConfig implements BgpCfg { |
| 204 | 218 | ||
| 205 | if (lspeer != null) { | 219 | if (lspeer != null) { |
| 206 | 220 | ||
| 207 | - //TODO DISCONNECT PEER | 221 | + BgpPeer disconnPeer = peerManager.getPeer(BgpId.bgpId(IpAddress.valueOf(routerid))); |
| 222 | + if (disconnPeer != null) { | ||
| 223 | + // TODO: send notification peer deconfigured | ||
| 224 | + disconnPeer.disconnectPeer(); | ||
| 225 | + } | ||
| 226 | + lspeer.connectPeer().disconnectPeer(); | ||
| 208 | lspeer.setState(BgpPeerCfg.State.IDLE); | 227 | lspeer.setState(BgpPeerCfg.State.IDLE); |
| 209 | lspeer.setSelfInnitConnection(false); | 228 | lspeer.setSelfInnitConnection(false); |
| 210 | log.debug("Disconnected : " + routerid + " successfully"); | 229 | log.debug("Disconnected : " + routerid + " successfully"); | ... | ... |
| ... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.bgp.controller.impl; | 17 | package org.onosproject.bgp.controller.impl; |
| 18 | 18 | ||
| 19 | +import java.util.Iterator; | ||
| 20 | +import java.util.List; | ||
| 19 | import java.util.Set; | 21 | import java.util.Set; |
| 20 | import java.util.concurrent.ConcurrentHashMap; | 22 | import java.util.concurrent.ConcurrentHashMap; |
| 21 | import java.util.concurrent.CopyOnWriteArraySet; | 23 | import java.util.concurrent.CopyOnWriteArraySet; |
| ... | @@ -29,11 +31,16 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -29,11 +31,16 @@ import org.apache.felix.scr.annotations.Service; |
| 29 | import org.onosproject.bgp.controller.BgpCfg; | 31 | import org.onosproject.bgp.controller.BgpCfg; |
| 30 | import org.onosproject.bgp.controller.BgpController; | 32 | import org.onosproject.bgp.controller.BgpController; |
| 31 | import org.onosproject.bgp.controller.BgpId; | 33 | import org.onosproject.bgp.controller.BgpId; |
| 34 | +import org.onosproject.bgp.controller.BgpLocalRib; | ||
| 32 | import org.onosproject.bgp.controller.BgpPeer; | 35 | import org.onosproject.bgp.controller.BgpPeer; |
| 33 | import org.onosproject.bgp.controller.BgpNodeListener; | 36 | import org.onosproject.bgp.controller.BgpNodeListener; |
| 34 | import org.onosproject.bgp.controller.BgpPeerManager; | 37 | import org.onosproject.bgp.controller.BgpPeerManager; |
| 35 | import org.onosproject.bgpio.exceptions.BgpParseException; | 38 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| 36 | import org.onosproject.bgpio.protocol.BgpMessage; | 39 | import org.onosproject.bgpio.protocol.BgpMessage; |
| 40 | +import org.onosproject.bgpio.protocol.BgpUpdateMsg; | ||
| 41 | +import org.onosproject.bgpio.types.BgpValueType; | ||
| 42 | +import org.onosproject.bgpio.types.MpReachNlri; | ||
| 43 | +import org.onosproject.bgpio.types.MpUnReachNlri; | ||
| 37 | import org.slf4j.Logger; | 44 | import org.slf4j.Logger; |
| 38 | import org.slf4j.LoggerFactory; | 45 | import org.slf4j.LoggerFactory; |
| 39 | 46 | ||
| ... | @@ -47,11 +54,14 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -47,11 +54,14 @@ public class BgpControllerImpl implements BgpController { |
| 47 | 54 | ||
| 48 | protected BgpPeerManagerImpl peerManager = new BgpPeerManagerImpl(); | 55 | protected BgpPeerManagerImpl peerManager = new BgpPeerManagerImpl(); |
| 49 | 56 | ||
| 57 | + private BgpLocalRib bgplocalRIB = new BgpLocalRibImpl(this); | ||
| 58 | + private BgpLocalRib bgplocalRIBVpn = new BgpLocalRibImpl(this); | ||
| 59 | + | ||
| 50 | protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>(); | 60 | protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>(); |
| 51 | 61 | ||
| 52 | final Controller ctrl = new Controller(this); | 62 | final Controller ctrl = new Controller(this); |
| 53 | 63 | ||
| 54 | - private BgpConfig bgpconfig = new BgpConfig(); | 64 | + private BgpConfig bgpconfig = new BgpConfig(this); |
| 55 | 65 | ||
| 56 | @Activate | 66 | @Activate |
| 57 | public void activate() { | 67 | public void activate() { |
| ... | @@ -100,6 +110,8 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -100,6 +110,8 @@ public class BgpControllerImpl implements BgpController { |
| 100 | @Override | 110 | @Override |
| 101 | public void processBGPPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException { | 111 | public void processBGPPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException { |
| 102 | 112 | ||
| 113 | + BgpPeer peer = getPeer(bgpId); | ||
| 114 | + | ||
| 103 | switch (msg.getType()) { | 115 | switch (msg.getType()) { |
| 104 | case OPEN: | 116 | case OPEN: |
| 105 | // TODO: Process Open message | 117 | // TODO: Process Open message |
| ... | @@ -111,7 +123,23 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -111,7 +123,23 @@ public class BgpControllerImpl implements BgpController { |
| 111 | // TODO: Process notificatoin message | 123 | // TODO: Process notificatoin message |
| 112 | break; | 124 | break; |
| 113 | case UPDATE: | 125 | case UPDATE: |
| 114 | - // TODO: Process update message | 126 | + BgpUpdateMsg updateMsg = (BgpUpdateMsg) msg; |
| 127 | + List<BgpValueType> pathAttr = updateMsg.bgpPathAttributes().pathAttributes(); | ||
| 128 | + if (pathAttr == null) { | ||
| 129 | + log.debug("llPathAttr is null, cannot process update message"); | ||
| 130 | + break; | ||
| 131 | + } | ||
| 132 | + Iterator<BgpValueType> listIterator = pathAttr.iterator(); | ||
| 133 | + boolean isLinkstate = false; | ||
| 134 | + while (listIterator.hasNext()) { | ||
| 135 | + BgpValueType attr = listIterator.next(); | ||
| 136 | + if ((attr instanceof MpReachNlri) || (attr instanceof MpUnReachNlri)) { | ||
| 137 | + isLinkstate = true; | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + if (isLinkstate) { | ||
| 141 | + peer.buildAdjRibIn(pathAttr); | ||
| 142 | + } | ||
| 115 | break; | 143 | break; |
| 116 | default: | 144 | default: |
| 117 | // TODO: Process other message | 145 | // TODO: Process other message |
| ... | @@ -215,4 +243,24 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -215,4 +243,24 @@ public class BgpControllerImpl implements BgpController { |
| 215 | public int connectedPeerCount() { | 243 | public int connectedPeerCount() { |
| 216 | return connectedPeers.size(); | 244 | return connectedPeers.size(); |
| 217 | } | 245 | } |
| 246 | + | ||
| 247 | + /** | ||
| 248 | + * Gets the BGP local RIB. | ||
| 249 | + * | ||
| 250 | + * @return bgplocalRIB BGP local RIB. | ||
| 251 | + */ | ||
| 252 | + @Override | ||
| 253 | + public BgpLocalRib bgpLocalRib() { | ||
| 254 | + return bgplocalRIB; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + /** | ||
| 258 | + * Gets the BGP local RIB with VPN. | ||
| 259 | + * | ||
| 260 | + * @return bgplocalRIBVpn BGP VPN local RIB . | ||
| 261 | + */ | ||
| 262 | + @Override | ||
| 263 | + public BgpLocalRib bgpLocalRibVpn() { | ||
| 264 | + return bgplocalRIBVpn; | ||
| 265 | + } | ||
| 218 | } | 266 | } | ... | ... |
| 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 | +} |
| ... | @@ -28,6 +28,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -28,6 +28,7 @@ import org.onlab.packet.IpAddress; |
| 28 | import org.onosproject.bgp.controller.BgpController; | 28 | import org.onosproject.bgp.controller.BgpController; |
| 29 | import org.onosproject.bgp.controller.BgpPeer; | 29 | import org.onosproject.bgp.controller.BgpPeer; |
| 30 | import org.onosproject.bgp.controller.BgpSessionInfo; | 30 | import org.onosproject.bgp.controller.BgpSessionInfo; |
| 31 | +import org.onosproject.bgp.controller.BgpLocalRib; | ||
| 31 | import org.onosproject.bgpio.exceptions.BgpParseException; | 32 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| 32 | import org.onosproject.bgpio.protocol.BgpFactories; | 33 | import org.onosproject.bgpio.protocol.BgpFactories; |
| 33 | import org.onosproject.bgpio.protocol.BgpFactory; | 34 | import org.onosproject.bgpio.protocol.BgpFactory; |
| ... | @@ -61,9 +62,28 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -61,9 +62,28 @@ public class BgpPeerImpl implements BgpPeer { |
| 61 | protected boolean isHandShakeComplete = false; | 62 | protected boolean isHandShakeComplete = false; |
| 62 | private BgpSessionInfo sessionInfo; | 63 | private BgpSessionInfo sessionInfo; |
| 63 | private BgpPacketStatsImpl pktStats; | 64 | private BgpPacketStatsImpl pktStats; |
| 65 | + private BgpLocalRib bgplocalRIB; | ||
| 66 | + private BgpLocalRib bgplocalRIBVpn; | ||
| 64 | private AdjRibIn adjRib; | 67 | private AdjRibIn adjRib; |
| 65 | private VpnAdjRibIn vpnAdjRib; | 68 | private VpnAdjRibIn vpnAdjRib; |
| 66 | 69 | ||
| 70 | + /** | ||
| 71 | + * Return the adjacency RIB-IN. | ||
| 72 | + * | ||
| 73 | + * @return adjRib the adjacency RIB-IN | ||
| 74 | + */ | ||
| 75 | + public AdjRibIn adjacencyRib() { | ||
| 76 | + return adjRib; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * Return the adjacency RIB-IN with VPN. | ||
| 81 | + * | ||
| 82 | + * @return vpnAdjRib the adjacency RIB-IN with VPN | ||
| 83 | + */ | ||
| 84 | + public VpnAdjRibIn vpnAdjacencyRib() { | ||
| 85 | + return vpnAdjRib; | ||
| 86 | + } | ||
| 67 | 87 | ||
| 68 | @Override | 88 | @Override |
| 69 | public BgpSessionInfo sessionInfo() { | 89 | public BgpSessionInfo sessionInfo() { |
| ... | @@ -81,6 +101,8 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -81,6 +101,8 @@ public class BgpPeerImpl implements BgpPeer { |
| 81 | this.bgpController = bgpController; | 101 | this.bgpController = bgpController; |
| 82 | this.sessionInfo = sessionInfo; | 102 | this.sessionInfo = sessionInfo; |
| 83 | this.pktStats = pktStats; | 103 | this.pktStats = pktStats; |
| 104 | + this.bgplocalRIB = bgpController.bgpLocalRib(); | ||
| 105 | + this.bgplocalRIBVpn = bgpController.bgpLocalRibVpn(); | ||
| 84 | this.adjRib = new AdjRibIn(); | 106 | this.adjRib = new AdjRibIn(); |
| 85 | this.vpnAdjRib = new VpnAdjRibIn(); | 107 | this.vpnAdjRib = new VpnAdjRibIn(); |
| 86 | } | 108 | } |
| ... | @@ -119,22 +141,31 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -119,22 +141,31 @@ public class BgpPeerImpl implements BgpPeer { |
| 119 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); | 141 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); |
| 120 | if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) { | 142 | if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) { |
| 121 | adjRib.add(nlriInfo, details); | 143 | adjRib.add(nlriInfo, details); |
| 144 | + bgplocalRIB.add(sessionInfo(), nlriInfo, details); | ||
| 122 | } else { | 145 | } else { |
| 123 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); | 146 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 147 | + bgplocalRIBVpn.add(sessionInfo(), nlriInfo, details, | ||
| 148 | + ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 124 | } | 149 | } |
| 125 | } else if (nlriInfo instanceof BgpLinkLsNlriVer4) { | 150 | } else if (nlriInfo instanceof BgpLinkLsNlriVer4) { |
| 126 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); | 151 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); |
| 127 | if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) { | 152 | if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) { |
| 128 | adjRib.add(nlriInfo, details); | 153 | adjRib.add(nlriInfo, details); |
| 154 | + bgplocalRIB.add(sessionInfo(), nlriInfo, details); | ||
| 129 | } else { | 155 | } else { |
| 130 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); | 156 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 157 | + bgplocalRIBVpn.add(sessionInfo(), nlriInfo, details, | ||
| 158 | + ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 131 | } | 159 | } |
| 132 | } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) { | 160 | } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) { |
| 133 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); | 161 | PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr); |
| 134 | if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) { | 162 | if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) { |
| 135 | adjRib.add(nlriInfo, details); | 163 | adjRib.add(nlriInfo, details); |
| 164 | + bgplocalRIB.add(sessionInfo(), nlriInfo, details); | ||
| 136 | } else { | 165 | } else { |
| 137 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); | 166 | vpnAdjRib.addVpn(nlriInfo, details, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 167 | + bgplocalRIBVpn.add(sessionInfo(), nlriInfo, details, | ||
| 168 | + ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 138 | } | 169 | } |
| 139 | } | 170 | } |
| 140 | } | 171 | } |
| ... | @@ -170,20 +201,26 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -170,20 +201,26 @@ public class BgpPeerImpl implements BgpPeer { |
| 170 | if (nlriInfo instanceof BgpNodeLSNlriVer4) { | 201 | if (nlriInfo instanceof BgpNodeLSNlriVer4) { |
| 171 | if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) { | 202 | if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) { |
| 172 | adjRib.remove(nlriInfo); | 203 | adjRib.remove(nlriInfo); |
| 204 | + bgplocalRIB.delete(nlriInfo); | ||
| 173 | } else { | 205 | } else { |
| 174 | vpnAdjRib.removeVpn(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); | 206 | vpnAdjRib.removeVpn(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 207 | + bgplocalRIBVpn.delete(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 175 | } | 208 | } |
| 176 | } else if (nlriInfo instanceof BgpLinkLsNlriVer4) { | 209 | } else if (nlriInfo instanceof BgpLinkLsNlriVer4) { |
| 177 | if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) { | 210 | if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) { |
| 178 | adjRib.remove(nlriInfo); | 211 | adjRib.remove(nlriInfo); |
| 212 | + bgplocalRIB.delete(nlriInfo); | ||
| 179 | } else { | 213 | } else { |
| 180 | vpnAdjRib.removeVpn(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); | 214 | vpnAdjRib.removeVpn(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 215 | + bgplocalRIBVpn.delete(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 181 | } | 216 | } |
| 182 | } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) { | 217 | } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) { |
| 183 | if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) { | 218 | if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) { |
| 184 | adjRib.remove(nlriInfo); | 219 | adjRib.remove(nlriInfo); |
| 220 | + bgplocalRIB.delete(nlriInfo); | ||
| 185 | } else { | 221 | } else { |
| 186 | vpnAdjRib.removeVpn(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); | 222 | vpnAdjRib.removeVpn(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); |
| 223 | + bgplocalRIBVpn.delete(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher()); | ||
| 187 | } | 224 | } |
| 188 | } | 225 | } |
| 189 | } | 226 | } |
| ... | @@ -207,6 +244,18 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -207,6 +244,18 @@ public class BgpPeerImpl implements BgpPeer { |
| 207 | return vpnAdjRib; | 244 | return vpnAdjRib; |
| 208 | } | 245 | } |
| 209 | 246 | ||
| 247 | + /** | ||
| 248 | + * Update localRIB on peer disconnect. | ||
| 249 | + * | ||
| 250 | + */ | ||
| 251 | + public void updateLocalRIBOnPeerDisconnect() { | ||
| 252 | + BgpLocalRibImpl localRib = (BgpLocalRibImpl) bgplocalRIB; | ||
| 253 | + BgpLocalRibImpl localRibVpn = (BgpLocalRibImpl) bgplocalRIBVpn; | ||
| 254 | + | ||
| 255 | + localRib.localRIBUpdate(adjacencyRib()); | ||
| 256 | + localRibVpn.localRIBUpdate(vpnAdjacencyRib()); | ||
| 257 | + } | ||
| 258 | + | ||
| 210 | // ************************ | 259 | // ************************ |
| 211 | // Channel related | 260 | // Channel related |
| 212 | // ************************ | 261 | // ************************ | ... | ... |
| ... | @@ -31,6 +31,7 @@ import org.onosproject.bgp.controller.BgpCfg; | ... | @@ -31,6 +31,7 @@ import org.onosproject.bgp.controller.BgpCfg; |
| 31 | import org.onosproject.bgp.controller.BgpController; | 31 | import org.onosproject.bgp.controller.BgpController; |
| 32 | import org.onosproject.bgp.controller.BgpId; | 32 | import org.onosproject.bgp.controller.BgpId; |
| 33 | import org.onosproject.bgp.controller.BgpPeer; | 33 | import org.onosproject.bgp.controller.BgpPeer; |
| 34 | +import org.onosproject.bgp.controller.BgpLocalRib; | ||
| 34 | import org.onosproject.bgp.controller.BgpNodeListener; | 35 | import org.onosproject.bgp.controller.BgpNodeListener; |
| 35 | import org.onosproject.bgp.controller.BgpPeerManager; | 36 | import org.onosproject.bgp.controller.BgpPeerManager; |
| 36 | import org.onosproject.bgpio.exceptions.BgpParseException; | 37 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| ... | @@ -208,6 +209,17 @@ public class BgpTopologyProviderTest { | ... | @@ -208,6 +209,17 @@ public class BgpTopologyProviderTest { |
| 208 | return 0; | 209 | return 0; |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 212 | + @Override | ||
| 213 | + public BgpLocalRib bgpLocalRibVpn() { | ||
| 214 | + // TODO Auto-generated method stub | ||
| 215 | + return null; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + @Override | ||
| 219 | + public BgpLocalRib bgpLocalRib() { | ||
| 220 | + // TODO Auto-generated method stub | ||
| 221 | + return null; | ||
| 222 | + } | ||
| 211 | 223 | ||
| 212 | @Override | 224 | @Override |
| 213 | public BgpPeerManager peerManager() { | 225 | public BgpPeerManager peerManager() { | ... | ... |
-
Please register or login to post a comment