use of org.onosproject.bgp.controller.BgpNodeListener in project onos by opennetworkinglab.
the class BgpLocalRibImpl method selectionProcessNode.
/**
* Selection process for local RIB node.
*
* @param nlri NLRI to update
* @param isVpnRib true if VPN local RIB, otherwise false
* @throws BgpParseException throws BGP parse exception
*/
public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
BgpPeerImpl peer;
BgpSessionInfo sessionInfo;
int decisionResult;
boolean containsKey;
BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
/* Here, we are checking if the given node is contained in the AdjacencyRib of any peer
or not. If none of the peer's AdjacencyRib has it, node can be marked for deletion.
*/
boolean shouldDeleteNode = false;
if (nodeTree.containsKey(nodeLsIdentifier)) {
shouldDeleteNode = true;
}
for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
if (nodeTree.containsKey(nodeLsIdentifier)) {
containsKey = (!isVpnRib) ? (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) : (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier));
if (!containsKey) {
continue;
}
sessionInfo = peer.sessionInfo();
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), (!isVpnRib) ? (peer.adjacencyRib().nodeTree().get(nodeLsIdentifier)) : (peer.vpnAdjacencyRib().nodeTree().get(nodeLsIdentifier)));
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
if (decisionResult < 0) {
nodeTree.replace(nodeLsIdentifier, detailsLocRib);
log.debug("Local RIB node updated: {}", detailsLocRib.toString());
}
shouldDeleteNode = false;
}
}
if (shouldDeleteNode) {
log.debug("Local RIB delete node: {}", nodeLsIdentifier.toString());
for (BgpNodeListener l : bgpController.listener()) {
l.deleteNode((BgpNodeLSNlriVer4) nlri);
}
nodeTree.remove(nodeLsIdentifier);
bgpController.notifyTopologyChange();
}
}
use of org.onosproject.bgp.controller.BgpNodeListener in project onos by opennetworkinglab.
the class BgpLocalRibImpl method add.
@Override
public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) throws BgpParseException {
int decisionResult;
log.debug("Add to local RIB {}", details.toString());
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), details);
if (nlri instanceof BgpNodeLSNlriVer4) {
BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
if (nodeTree.containsKey(nodeLsIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
if (decisionResult <= 0) {
for (BgpNodeListener l : bgpController.listener()) {
l.addNode((BgpNodeLSNlriVer4) nlri, details);
}
nodeTree.replace(nodeLsIdentifier, detailsLocRib);
log.debug("Local RIB update node: {}", detailsLocRib.toString());
}
} else {
nodeTree.put(nodeLsIdentifier, detailsLocRib);
for (BgpNodeListener l : bgpController.listener()) {
l.addNode((BgpNodeLSNlriVer4) nlri, details);
}
bgpController.notifyTopologyChange();
log.debug("Local RIB add node: {}", detailsLocRib.toString());
}
} else if (nlri instanceof BgpLinkLsNlriVer4) {
BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
if (linkTree.containsKey(linkLsIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
if (decisionResult <= 0) {
linkTree.replace(linkLsIdentifier, detailsLocRib);
for (BgpLinkListener l : bgpController.linkListener()) {
l.addLink((BgpLinkLsNlriVer4) nlri, details);
}
log.debug("Local RIB update link: {}", detailsLocRib.toString());
}
} else {
linkTree.put(linkLsIdentifier, detailsLocRib);
for (BgpLinkListener l : bgpController.linkListener()) {
l.addLink((BgpLinkLsNlriVer4) nlri, details);
}
bgpController.notifyTopologyChange();
log.debug("Local RIB add link: {}", detailsLocRib.toString());
}
} else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
if (prefixTree.containsKey(prefixIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
if (decisionResult <= 0) {
prefixTree.replace(prefixIdentifier, detailsLocRib);
for (BgpPrefixListener l : bgpController.prefixListener()) {
l.addPrefix((BgpPrefixIPv4LSNlriVer4) nlri, details);
}
log.debug("Local RIB update prefix: {}", detailsLocRib.toString());
}
} else {
prefixTree.put(prefixIdentifier, detailsLocRib);
for (BgpPrefixListener l : bgpController.prefixListener()) {
l.addPrefix((BgpPrefixIPv4LSNlriVer4) nlri, details);
}
log.debug("Local RIB add prefix: {}", detailsLocRib.toString());
}
}
}
Aggregations