Search in sources :

Example 6 with PathAttrNlriDetails

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

the class BgpSelectionAlgoTest method selectionAlgoTest7.

/**
 * firstPathAttribute has lower BGPID than secondPathAttribute.
 */
@Test
public void selectionAlgoTest7() 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[] { 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);
    // B0A0A00
    bgpId = 185207296;
    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(1));
}
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 7 with PathAttrNlriDetails

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

the class BgpSelectionAlgoTest method selectionAlgoTest8.

/**
 * secondPathAttribute has lowest peer address than firstPathAttribute.
 */
@Test
public void selectionAlgoTest8() throws BgpParseException {
    byte[] peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
    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(-1));
}
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 8 with PathAttrNlriDetails

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

the class BgpControllerImplTest method testBgpUpdateMessage4.

/**
 * Peer1 has Node NLRI and Peer2 has Node NLRI with different MpReach and MpUnReach with VPN.
 */
@Test
public void testBgpUpdateMessage4() throws InterruptedException {
    // Initiate the connections
    peer1.peerChannelHandler.asNumber = 200;
    peer1.peerChannelHandler.version = 4;
    peer1.peerChannelHandler.holdTime = 120;
    short afi = 16388;
    byte res = 0;
    byte safi = (byte) 0x80;
    bgpControllerImpl.getConfig().setLsCapability(true);
    BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
    peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
    Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.35", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer1
    IpAddress ipAddress = IpAddress.valueOf("127.0.0.35");
    BgpId bgpId = new BgpId(ipAddress);
    BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    LinkedList<BgpValueType> subTlvs1 = new LinkedList<>();
    LinkedList<BgpValueType> subTlvs = new LinkedList<>();
    BgpValueType tlv = AutonomousSystemTlv.of(2478);
    subTlvs.add(tlv);
    tlv = BgpLSIdentifierTlv.of(33686018);
    subTlvs.add(tlv);
    NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256);
    BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes);
    RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A);
    VpnAdjRibIn vpnAdj = peer.vpnAdjRib();
    // In Adj-RIB, vpnNodeTree should contain rd
    assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
    Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd);
    // In Adj-RIB, vpnNodeTree should contain rd key which contains specified value
    assertThat(treeValue.containsKey(key), is(true));
    BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
    // In Local-RIB, vpnNodeTree should contain rd
    assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
    Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd);
    // In Local-RIB, vpnNodeTree should contain rd key which contains specified value
    assertThat(value.containsKey(key), is(true));
    peer2.peerChannelHandler.asNumber = 200;
    peer2.peerChannelHandler.version = 4;
    peer2.peerChannelHandler.holdTime = 120;
    bgpControllerImpl.getConfig().setLsCapability(true);
    tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
    peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
    peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.40", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer2
    bgpId = new BgpId(IpAddress.valueOf("127.0.0.40"));
    peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    tlv = AutonomousSystemTlv.of(686);
    subTlvs1.add(tlv);
    tlv = BgpLSIdentifierTlv.of(33686018);
    subTlvs1.add(tlv);
    nodeDes = new NodeDescriptors(subTlvs1, (short) 0x10, (short) 256);
    key = new BgpNodeLSIdentifier(nodeDes);
    vpnAdj = peer.vpnAdjRib();
    // In Adj-RIB, vpnNodeTree should contain rd
    assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
    treeValue = vpnAdj.vpnNodeTree().get(rd);
    // In Adj-RIB, vpnNodeTree should contain rd key which contains specified value
    assertThat(treeValue.containsKey(key), is(true));
    // Disconnect peer1
    channel.disconnect();
    channel.close();
    obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
    // In Local-RIB, vpnNodeTree should contain rd
    assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
    value = obj.vpnNodeTree().get(rd);
    // In Local-RIB, vpnNodeTree should contain rd key which contains specified value
    assertThat(value.containsKey(key), is(true));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpPeerImpl(org.onosproject.bgp.controller.impl.BgpPeerImpl) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpLocalRibImpl(org.onosproject.bgp.controller.impl.BgpLocalRibImpl) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) RouteDistinguisher(org.onosproject.bgpio.types.RouteDistinguisher) NodeDescriptors(org.onosproject.bgpio.protocol.linkstate.NodeDescriptors) BgpNodeLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier) LinkedList(java.util.LinkedList) VpnAdjRibIn(org.onosproject.bgp.controller.impl.VpnAdjRibIn) BgpId(org.onosproject.bgp.controller.BgpId) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 9 with PathAttrNlriDetails

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

the class BgpControllerImplTest method testBgpUpdateMessage9.

/**
 * Peer1 has Node NLRI (MpReach) and Peer2 has node NLRI with different MpReach
 * and MpUnReach with IsIsNonPseudonode.
 */
@Test
public void testBgpUpdateMessage9() throws InterruptedException {
    // Initiate the connections
    peer1.peerChannelHandler.asNumber = 200;
    peer1.peerChannelHandler.version = 4;
    peer1.peerChannelHandler.holdTime = 120;
    short afi = 16388;
    byte res = 0;
    byte safi = (byte) 0x80;
    bgpControllerImpl.getConfig().setLsCapability(true);
    BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
    peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
    Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.30", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer1
    BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.30"));
    BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    LinkedList<BgpValueType> subTlvs = new LinkedList<>();
    BgpValueType tlv = AutonomousSystemTlv.of(2478);
    subTlvs.add(tlv);
    tlv = BgpLSIdentifierTlv.of(33686018);
    subTlvs.add(tlv);
    NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256);
    BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes);
    RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A);
    VpnAdjRibIn vpnAdj = peer.vpnAdjRib();
    // In Adj-RIB, vpnNodeTree should contain specified rd
    assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
    Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd);
    // In Adj-RIB, vpnNodeTree should contain specified rd with specified value
    assertThat(treeValue.containsKey(key), is(true));
    BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
    // In Local-RIB, vpnNodeTree should contain specified rd
    assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
    Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd);
    // In Local-RIB, vpnNodeTree should contain specified rd with specified value
    assertThat(value.containsKey(key), is(true));
    peer2.peerChannelHandler.asNumber = 200;
    peer2.peerChannelHandler.version = 4;
    peer2.peerChannelHandler.holdTime = 120;
    bgpControllerImpl.getConfig().setLsCapability(true);
    tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
    peer2.peerChannelHandler.capabilityTlv.add(tempTlv1);
    peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.50", 0));
    TimeUnit.MILLISECONDS.sleep(1000);
    // Get peer2
    bgpId = new BgpId(IpAddress.valueOf("127.0.0.50"));
    peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
    key = new BgpNodeLSIdentifier(nodeDes);
    vpnAdj = peer.vpnAdjRib();
    // In Adj-RIB, vpnNodeTree should be empty
    assertThat(vpnAdj.vpnNodeTree().isEmpty(), is(true));
    // peer1 disconnects
    channel.disconnect();
    channel.close();
    obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
    TimeUnit.MILLISECONDS.sleep(200);
    // In Local-RIB, vpnNodeTree should be empty
    assertThat(obj.vpnNodeTree().isEmpty(), is(true));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) PathAttrNlriDetailsLocalRib(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib) BgpPeerImpl(org.onosproject.bgp.controller.impl.BgpPeerImpl) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpLocalRibImpl(org.onosproject.bgp.controller.impl.BgpLocalRibImpl) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) RouteDistinguisher(org.onosproject.bgpio.types.RouteDistinguisher) NodeDescriptors(org.onosproject.bgpio.protocol.linkstate.NodeDescriptors) BgpNodeLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier) LinkedList(java.util.LinkedList) VpnAdjRibIn(org.onosproject.bgp.controller.impl.VpnAdjRibIn) BgpId(org.onosproject.bgp.controller.BgpId) PathAttrNlriDetails(org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails) Test(org.junit.Test)

Example 10 with PathAttrNlriDetails

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

Aggregations

PathAttrNlriDetails (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails)16 LinkedList (java.util.LinkedList)11 Test (org.junit.Test)11 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)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 RouteDistinguisher (org.onosproject.bgpio.types.RouteDistinguisher)5 BgpNodeLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)3 InetSocketAddress (java.net.InetSocketAddress)2 Channel (org.jboss.netty.channel.Channel)2 BgpId (org.onosproject.bgp.controller.BgpId)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 BgpLinkLsNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4)2 BgpNodeLSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4)2 BgpPrefixIPv4LSNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4)2 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)2