Search in sources :

Example 1 with PathAttrNlriDetailsLocalRib

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

use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib 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();
    }
}
Also used : BgpNodeListener(org.onosproject.bgp.controller.BgpNodeListener) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpSessionInfo(org.onosproject.bgp.controller.BgpSessionInfo) BgpId(org.onosproject.bgp.controller.BgpId) BgpNodeLSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4) BgpNodeLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)

Example 3 with PathAttrNlriDetailsLocalRib

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

the class BgpSelectionAlgoTest method selectionAlgoTest6.

/**
 * secondPathAttribute is EBGP than firstPathAttribute is IBGP.
 */
@Test
public void selectionAlgoTest6() throws BgpParseException {
    byte[] peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
    LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
    BgpValueType pathAttribute1;
    byte[] origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute1 = Origin.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute1 = AsPath.read(buffer);
    pathAttributes1.add(pathAttribute1);
    IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    int bgpId = 168427777;
    short locRibAsNum = 100;
    boolean isIbgp = true;
    PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
    attrList1.setIdentifier(0);
    attrList1.setPathAttribute(pathAttributes1);
    attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
    PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);
    peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
    LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
    BgpValueType pathAttribute2;
    origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
    buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute2 = Origin.read(buffer);
    pathAttributes2.add(pathAttribute2);
    asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute2 = AsPath.read(buffer);
    pathAttributes2.add(pathAttribute2);
    ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    bgpId = 536936448;
    locRibAsNum = 200;
    isIbgp = false;
    PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
    attrList2.setIdentifier(0);
    attrList2.setPathAttribute(pathAttributes2);
    attrList2.setProtocolID(ProtocolType.OSPF_V2);
    PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, false, attrList2);
    BgpSelectionAlgo algo = new BgpSelectionAlgo();
    int result = algo.compare(list1, list2);
    assertThat(result, is(-1));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpSelectionAlgo(org.onosproject.bgp.controller.impl.BgpSelectionAlgo) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) IpAddress(org.onlab.packet.IpAddress) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 4 with PathAttrNlriDetailsLocalRib

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

the class BgpSelectionAlgoTest method selectionAlgoTest9.

/**
 * firstPathAttribute and secondPathAttribute are same.
 */
@Test
public void selectionAlgoTest9() throws BgpParseException {
    byte[] peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
    LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
    BgpValueType pathAttribute1;
    byte[] origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute1 = Origin.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute1 = AsPath.read(buffer);
    pathAttributes1.add(pathAttribute1);
    IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    // A0A0A00
    Integer bgpId = 168430080;
    short locRibAsNum = 100;
    boolean isIbgp = false;
    PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
    attrList1.setIdentifier(0);
    attrList1.setPathAttribute(pathAttributes1);
    attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
    PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);
    peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
    LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
    BgpValueType pathAttribute2;
    origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
    buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute2 = Origin.read(buffer);
    pathAttributes2.add(pathAttribute2);
    asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute2 = AsPath.read(buffer);
    pathAttributes2.add(pathAttribute2);
    ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    // A0A0A00
    bgpId = 168430080;
    locRibAsNum = 200;
    isIbgp = false;
    PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
    attrList2.setIdentifier(0);
    attrList2.setPathAttribute(pathAttributes2);
    attrList2.setProtocolID(ProtocolType.OSPF_V2);
    PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList2);
    BgpSelectionAlgo algo = new BgpSelectionAlgo();
    int result = algo.compare(list1, list2);
    assertThat(result, is(0));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpSelectionAlgo(org.onosproject.bgp.controller.impl.BgpSelectionAlgo) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 5 with PathAttrNlriDetailsLocalRib

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

the class BgpSelectionAlgoTest method selectionAlgoTest4.

/**
 * firstPathAttribute has lowest med than secondPathAttribute.
 */
@Test
public void selectionAlgoTest4() throws BgpParseException {
    byte[] peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
    LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
    BgpValueType pathAttribute1;
    byte[] origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute1 = Origin.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] med = new byte[] { (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00 };
    buffer.writeBytes(med);
    pathAttribute1 = Med.read(buffer);
    pathAttributes1.add(pathAttribute1);
    byte[] asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute1 = AsPath.read(buffer);
    pathAttributes1.add(pathAttribute1);
    IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    int bgpId = 168427777;
    short locRibAsNum = 100;
    boolean isIbgp = false;
    PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
    attrList1.setIdentifier(0);
    attrList1.setPathAttribute(pathAttributes1);
    attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
    PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);
    peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
    LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
    BgpValueType pathAttribute2;
    origin = new byte[] { 0x40, 0x01, 0x01, 0x02 };
    buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(origin);
    pathAttribute2 = Origin.read(buffer);
    pathAttributes2.add(pathAttribute2);
    med = new byte[] { (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01 };
    buffer.writeBytes(med);
    pathAttribute2 = Med.read(buffer);
    pathAttributes2.add(pathAttribute2);
    asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
    buffer.writeBytes(asPath);
    pathAttribute2 = AsPath.read(buffer);
    pathAttributes2.add(pathAttribute2);
    ipAddress = IpAddress.valueOf(Version.INET, peerIp);
    bgpId = 536936448;
    locRibAsNum = 200;
    isIbgp = true;
    PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
    attrList2.setIdentifier(0);
    attrList2.setPathAttribute(pathAttributes2);
    attrList2.setProtocolID(ProtocolType.OSPF_V2);
    PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList2);
    BgpSelectionAlgo algo = new BgpSelectionAlgo();
    int result = algo.compare(list1, list2);
    assertThat(result, is(1));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpSelectionAlgo(org.onosproject.bgp.controller.impl.BgpSelectionAlgo) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) IpAddress(org.onlab.packet.IpAddress) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)15 LinkedList (java.util.LinkedList)11 Test (org.junit.Test)11 PathAttrNlriDetails (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails)11 BgpValueType (org.onosproject.bgpio.types.BgpValueType)11 IpAddress (org.onlab.packet.IpAddress)10 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)9 BgpSelectionAlgo (org.onosproject.bgp.controller.impl.BgpSelectionAlgo)9 BgpId (org.onosproject.bgp.controller.BgpId)5 BgpNodeLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)4 BgpSessionInfo (org.onosproject.bgp.controller.BgpSessionInfo)3 InetSocketAddress (java.net.InetSocketAddress)2 Channel (org.jboss.netty.channel.Channel)2 BgpLinkListener (org.onosproject.bgp.controller.BgpLinkListener)2 BgpNodeListener (org.onosproject.bgp.controller.BgpNodeListener)2 BgpPrefixListener (org.onosproject.bgp.controller.BgpPrefixListener)2 BgpLocalRibImpl (org.onosproject.bgp.controller.impl.BgpLocalRibImpl)2 BgpPeerImpl (org.onosproject.bgp.controller.impl.BgpPeerImpl)2 VpnAdjRibIn (org.onosproject.bgp.controller.impl.VpnAdjRibIn)2 BgpLinkLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier)2