Search in sources :

Example 1 with BgpPrefixListener

use of org.onosproject.bgp.controller.BgpPrefixListener in project onos by opennetworkinglab.

the class BgpLocalRibImpl method selectionProcessPrefix.

/**
 * Selection process for local RIB prefix.
 *
 * @param nlri NLRI to update
 * @param isVpnRib true if VPN local RIB, otherwise false
 * @throws BgpParseException BGP parse exception
 */
public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
    BgpPeerImpl peer;
    BgpSessionInfo sessionInfo;
    int decisionResult;
    boolean containsKey;
    BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
    /* Here, we are checking if the given prefix is contained in the AdjacencyRib of any peer
           or not. If none of the peer's AdjacencyRib has it, prefix can be marked for deletion.
         */
    boolean shouldDeletePrefix = false;
    if (prefixTree.containsKey(prefixIdentifier)) {
        shouldDeletePrefix = true;
    }
    for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
        peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
        if (prefixTree.containsKey(prefixIdentifier)) {
            containsKey = (!isVpnRib) ? (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) : (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier));
            if (!containsKey) {
                continue;
            }
            sessionInfo = peer.sessionInfo();
            PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), ((!isVpnRib) ? (peer.adjacencyRib().prefixTree().get(prefixIdentifier)) : (peer.vpnAdjacencyRib().prefixTree().get(prefixIdentifier))));
            BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
            decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
            if (decisionResult < 0) {
                prefixTree.replace(prefixIdentifier, detailsLocRib);
                log.debug("Local RIB prefix updated: {}", detailsLocRib.toString());
            }
            shouldDeletePrefix = false;
        }
        if (shouldDeletePrefix) {
            log.debug("Local RIB remove prefix: {}", prefixIdentifier.toString());
            for (BgpPrefixListener l : bgpController.prefixListener()) {
                l.deletePrefix((BgpPrefixIPv4LSNlriVer4) nlri);
            }
            prefixTree.remove(prefixIdentifier);
        }
    }
}
Also used : BgpPrefixListener(org.onosproject.bgp.controller.BgpPrefixListener) BgpPrefixLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpSessionInfo(org.onosproject.bgp.controller.BgpSessionInfo) BgpId(org.onosproject.bgp.controller.BgpId) BgpPrefixIPv4LSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4)

Example 2 with BgpPrefixListener

use of org.onosproject.bgp.controller.BgpPrefixListener 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());
        }
    }
}
Also used : BgpNodeListener(org.onosproject.bgp.controller.BgpNodeListener) BgpPrefixListener(org.onosproject.bgp.controller.BgpPrefixListener) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpPrefixLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier) BgpLinkListener(org.onosproject.bgp.controller.BgpLinkListener) BgpNodeLSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4) BgpPrefixIPv4LSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4) BgpNodeLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier) BgpLinkLsNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4) BgpLinkLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier)

Aggregations

BgpPrefixListener (org.onosproject.bgp.controller.BgpPrefixListener)2 BgpPrefixIPv4LSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4)2 BgpPrefixLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier)2 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)2 BgpId (org.onosproject.bgp.controller.BgpId)1 BgpLinkListener (org.onosproject.bgp.controller.BgpLinkListener)1 BgpNodeListener (org.onosproject.bgp.controller.BgpNodeListener)1 BgpSessionInfo (org.onosproject.bgp.controller.BgpSessionInfo)1 BgpLinkLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier)1 BgpLinkLsNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4)1 BgpNodeLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)1 BgpNodeLSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4)1