Search in sources :

Example 1 with BgpLinkLSIdentifier

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

the class BgpControllerImplTest method testBgpUpdateMessage3.

/**
 * Peer1 has Link NLRI (MpReach).
 */
@Test
public void testBgpUpdateMessage3() throws InterruptedException, TestUtilsException {
    // Initiate the connections
    peer1.peerChannelHandler.asNumber = 200;
    peer1.peerChannelHandler.version = 4;
    peer1.peerChannelHandler.holdTime = 120;
    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.10", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer1
    BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.10"));
    BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    LinkedList<BgpValueType> localNodeSubTlvs = new LinkedList<>();
    LinkedList<BgpValueType> remoteNodeSubTlvs = new LinkedList<>();
    BgpValueType tlv = AutonomousSystemTlv.of(2222);
    localNodeSubTlvs.add(tlv);
    remoteNodeSubTlvs.add(tlv);
    tlv = BgpLSIdentifierTlv.of(33686018);
    localNodeSubTlvs.add(tlv);
    remoteNodeSubTlvs.add(tlv);
    byte[] isoNodeID = new byte[] { 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 };
    tlv = IsIsPseudonode.of(isoNodeID, (byte) 0x03);
    localNodeSubTlvs.add(tlv);
    isoNodeID = new byte[] { 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 };
    tlv = IsIsNonPseudonode.of(isoNodeID);
    remoteNodeSubTlvs.add(tlv);
    NodeDescriptors localNodeDes = new NodeDescriptors(localNodeSubTlvs, (short) 0x1b, (short) 256);
    NodeDescriptors remoteNodeDes = new NodeDescriptors(remoteNodeSubTlvs, (short) 0x1a, (short) 0x101);
    LinkedList<BgpValueType> linkDescriptor = new LinkedList<>();
    tlv = IPv4AddressTlv.of(Ip4Address.valueOf("2.2.2.2"), (short) 0x103);
    linkDescriptor.add(tlv);
    BgpLinkLSIdentifier key = new BgpLinkLSIdentifier(localNodeDes, remoteNodeDes, linkDescriptor);
    TimeUnit.MILLISECONDS.sleep(200);
    AdjRibIn adj = peer.adjRib();
    // In Adj-RIB, linkTree should contain specified key
    assertThat(adj.linkTree().containsKey(key), is(true));
    BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
    TimeUnit.MILLISECONDS.sleep(200);
    // In Local-RIB, linkTree should contain specified key
    assertThat(obj.linkTree().containsKey(key), is(true));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) 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) BgpId(org.onosproject.bgp.controller.BgpId) VpnAdjRibIn(org.onosproject.bgp.controller.impl.VpnAdjRibIn) AdjRibIn(org.onosproject.bgp.controller.impl.AdjRibIn) BgpLinkLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier) Test(org.junit.Test)

Example 2 with BgpLinkLSIdentifier

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

the class BgpLocalRibImpl method localRibUpdateLink.

/**
 * Update localRIB link based on available peer adjacency RIB.
 *
 * @param o adjacency-in/VPN adjacency-in
 * @throws BgpParseException BGP parse exceptions
 */
public void localRibUpdateLink(Object o) throws BgpParseException {
    if (o instanceof AdjRibIn) {
        AdjRibIn adjRib = (AdjRibIn) o;
        log.debug("Update local RIB link.");
        Set<BgpLinkLSIdentifier> linkKeys = adjRib.linkTree().keySet();
        for (BgpLinkLSIdentifier key : linkKeys) {
            PathAttrNlriDetails pathAttrNlri = adjRib.linkTree().get(key);
            BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), pathAttrNlri.identifier(), key, null, false);
            decisionProcess(linkNlri);
        }
    }
    if (o instanceof VpnAdjRibIn) {
        VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
        log.debug("Update local RIB VPN link");
        Set<RouteDistinguisher> linkKeysVpn = vpnAdjRib.vpnLinkTree().keySet();
        Map<BgpLinkLSIdentifier, PathAttrNlriDetails> link;
        for (RouteDistinguisher keyVpnLink : linkKeysVpn) {
            link = vpnAdjRib.vpnLinkTree().get(keyVpnLink);
            Set<BgpLinkLSIdentifier> vpnLinkKeys = link.keySet();
            for (BgpLinkLSIdentifier key : vpnLinkKeys) {
                PathAttrNlriDetails pathAttrNlri = vpnAdjRib.linkTree().get(key);
                BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), pathAttrNlri.identifier(), key, keyVpnLink, true);
                decisionProcess(linkNlri, keyVpnLink);
            }
        }
    }
}
Also used : PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) RouteDistinguisher(org.onosproject.bgpio.types.RouteDistinguisher) BgpLinkLsNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4) BgpLinkLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier)

Example 3 with BgpLinkLSIdentifier

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

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

the class BgpLocalRibImpl method selectionProcessLink.

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

Aggregations

BgpLinkLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier)4 BgpLinkLsNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4)3 BgpId (org.onosproject.bgp.controller.BgpId)2 BgpLinkListener (org.onosproject.bgp.controller.BgpLinkListener)2 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)2 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 BgpNodeListener (org.onosproject.bgp.controller.BgpNodeListener)1 BgpPrefixListener (org.onosproject.bgp.controller.BgpPrefixListener)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 BgpNodeLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)1 BgpNodeLSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4)1 BgpPrefixIPv4LSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4)1 BgpPrefixLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier)1 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)1