Search in sources :

Example 1 with BgpPrefixLSIdentifier

use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier 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 BgpPrefixLSIdentifier

use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.

the class BgpControllerImplTest method testBgpUpdateMessage8.

/**
 * Peer1 has Prefix NLRI (MpReach).
 */
@Test
public void testBgpUpdateMessage8() throws InterruptedException {
    // Initiate the connections
    peer1.peerChannelHandler.asNumber = 200;
    peer1.peerChannelHandler.version = 4;
    peer1.peerChannelHandler.holdTime = 150;
    short afi = 16388;
    byte res = 0;
    byte safi = 71;
    bgpControllerImpl.getConfig().setLsCapability(true);
    BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
    peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
    peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.20", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer1
    BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.20"));
    BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    LinkedList<BgpValueType> subTlvs = new LinkedList<>();
    BgpValueType tlv = AutonomousSystemTlv.of(2222);
    subTlvs.add(tlv);
    tlv = BgpLSIdentifierTlv.of(33686018);
    subTlvs.add(tlv);
    byte[] isoNodeID = new byte[] { 0x19, 0x21, 0x68, 0x07, 0x70, 0x01 };
    tlv = IsIsNonPseudonode.of(isoNodeID);
    subTlvs.add(tlv);
    NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x1a, (short) 256);
    LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>();
    byte[] prefix = new byte[] { 0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01 };
    ChannelBuffer tempCb = ChannelBuffers.dynamicBuffer();
    tempCb.writeBytes(prefix);
    tlv = IPReachabilityInformationTlv.read(tempCb, (short) 5);
    prefixDescriptor.add(tlv);
    BgpPrefixLSIdentifier key = new BgpPrefixLSIdentifier(nodeDes, prefixDescriptor);
    AdjRibIn adj = peer.adjRib();
    // In Adj-RIB, prefixTree should contain specified key
    assertThat(adj.prefixTree().containsKey(key), is(true));
    BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
    // In Local-RIB, prefixTree should contain specified key
    assertThat(obj.prefixTree().containsKey(key), is(true));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpPrefixLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier) BgpPeerImpl(org.onosproject.bgp.controller.impl.BgpPeerImpl) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpLocalRibImpl(org.onosproject.bgp.controller.impl.BgpLocalRibImpl) InetSocketAddress(java.net.InetSocketAddress) NodeDescriptors(org.onosproject.bgpio.protocol.linkstate.NodeDescriptors) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) BgpId(org.onosproject.bgp.controller.BgpId) VpnAdjRibIn(org.onosproject.bgp.controller.impl.VpnAdjRibIn) AdjRibIn(org.onosproject.bgp.controller.impl.AdjRibIn) Test(org.junit.Test)

Example 3 with BgpPrefixLSIdentifier

use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier 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)

Example 4 with BgpPrefixLSIdentifier

use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.

the class BgpLocalRibImpl method localRibUpdatePrefix.

/**
 * Update localRIB prefix based on available peer adjacency RIB.
 *
 * @param o instance of adjacency-in/VPN adjacency-in
 * @throws BgpParseException BGP parse exception
 */
public void localRibUpdatePrefix(Object o) throws BgpParseException {
    if (o instanceof AdjRibIn) {
        AdjRibIn adjRib = (AdjRibIn) o;
        log.debug("Update local RIB prefix.");
        Set<BgpPrefixLSIdentifier> prefixKeys = adjRib.prefixTree().keySet();
        for (BgpPrefixLSIdentifier key : prefixKeys) {
            PathAttrNlriDetails pathAttrNlri = adjRib.prefixTree().get(key);
            BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri.protocolID().getType(), key, null, false);
            decisionProcess(prefixNlri);
        }
    }
    if (o instanceof VpnAdjRibIn) {
        VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
        log.debug("Update local RIB VPN prefix.");
        Set<RouteDistinguisher> prefixKeysVpn = vpnAdjRib.vpnPrefixTree().keySet();
        Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefix;
        for (RouteDistinguisher keyVpnPrefix : prefixKeysVpn) {
            prefix = vpnAdjRib.vpnPrefixTree().get(keyVpnPrefix);
            Set<BgpPrefixLSIdentifier> vpnPrefixKeys = prefix.keySet();
            for (BgpPrefixLSIdentifier key : vpnPrefixKeys) {
                PathAttrNlriDetails pathAttrNlri = vpnAdjRib.prefixTree().get(key);
                BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri.protocolID().getType(), key, keyVpnPrefix, true);
                decisionProcess(prefixNlri, keyVpnPrefix);
            }
        }
    }
}
Also used : BgpPrefixLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier) BgpPrefixIPv4LSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) RouteDistinguisher(org.onosproject.bgpio.types.RouteDistinguisher)

Aggregations

BgpPrefixLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier)4 BgpPrefixIPv4LSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4)3 BgpId (org.onosproject.bgp.controller.BgpId)2 BgpPrefixListener (org.onosproject.bgp.controller.BgpPrefixListener)2 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)2 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 Test (org.junit.Test)1 BgpLinkListener (org.onosproject.bgp.controller.BgpLinkListener)1 BgpNodeListener (org.onosproject.bgp.controller.BgpNodeListener)1 BgpSessionInfo (org.onosproject.bgp.controller.BgpSessionInfo)1 AdjRibIn (org.onosproject.bgp.controller.impl.AdjRibIn)1 BgpLocalRibImpl (org.onosproject.bgp.controller.impl.BgpLocalRibImpl)1 BgpPeerImpl (org.onosproject.bgp.controller.impl.BgpPeerImpl)1 VpnAdjRibIn (org.onosproject.bgp.controller.impl.VpnAdjRibIn)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