Search in sources :

Example 51 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType 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 52 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType 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 53 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.

the class BgpFlowSpecNlri method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof BgpFlowSpecNlri) {
        int countObjSubTlv = 0;
        int countOtherSubTlv = 0;
        boolean isCommonSubTlv = true;
        BgpFlowSpecNlri other = (BgpFlowSpecNlri) obj;
        Iterator<BgpValueType> objListIterator = other.flowSpecComponents.iterator();
        countOtherSubTlv = other.flowSpecComponents.size();
        countObjSubTlv = flowSpecComponents.size();
        if (countObjSubTlv != countOtherSubTlv) {
            return false;
        } else {
            while (objListIterator.hasNext() && isCommonSubTlv) {
                BgpValueType subTlv = objListIterator.next();
                if (flowSpecComponents.contains(subTlv) && other.flowSpecComponents.contains(subTlv)) {
                    isCommonSubTlv = Objects.equals(flowSpecComponents.get(flowSpecComponents.indexOf(subTlv)), other.flowSpecComponents.get(other.flowSpecComponents.indexOf(subTlv)));
                } else {
                    isCommonSubTlv = false;
                }
            }
            return isCommonSubTlv;
        }
    }
    return false;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Example 54 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.

the class BgpFlowSpecNlri method updateBufferIdenticalFlowTypes.

/**
 * Update buffer with identical flow types.
 *
 * @param cb channel buffer
 * @param bgpFlowSpecNlri flow specification
 */
public static void updateBufferIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) {
    List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
    while (listIterator.hasNext()) {
        ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer();
        int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex();
        BgpValueType tlv = listIterator.next();
        writeFlowType(tlv, flowSpecTmpBuff);
        /* RFC 5575: section 4,  If the NLRI length value is smaller than 240 (0xf0 hex), the length
                                     field can be encoded as a single octet.  Otherwise, it is encoded as
                                     an extended-length 2-octet values */
        int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx;
        if (len >= FLOW_SPEC_LEN) {
            cb.writeShort(len);
        } else {
            cb.writeByte(len);
        }
        // Copy from bynamic buffer to channel buffer
        cb.writeBytes(flowSpecTmpBuff);
    }
    return;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 55 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.

the class BgpFlowSpecNlri method updateBufferNonIdenticalFlowTypes.

/**
 * Update buffer with non-identical flow types.
 *
 * @param cb channel buffer
 * @param bgpFlowSpecNlri flow specification
 */
public static void updateBufferNonIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) {
    ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer();
    List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
    int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex();
    flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    listIterator = flowSpec.listIterator();
    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        writeFlowType(tlv, flowSpecTmpBuff);
    }
    /* RFC 5575: section 4,  If the NLRI length value is smaller than 240 (0xf0 hex), the length
                                 field can be encoded as a single octet.  Otherwise, it is encoded as
                                 an extended-length 2-octet values */
    int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx;
    if (len >= FLOW_SPEC_LEN) {
        cb.writeShort(len);
    } else {
        cb.writeByte(len);
    }
    // Copy from bynamic buffer to channel buffer
    cb.writeBytes(flowSpecTmpBuff);
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)83 Test (org.junit.Test)57 LinkedList (java.util.LinkedList)52 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)50 BgpHeader (org.onosproject.bgpio.types.BgpHeader)33 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)31 AsPath (org.onosproject.bgpio.types.AsPath)29 Origin (org.onosproject.bgpio.types.Origin)29 Med (org.onosproject.bgpio.types.Med)27 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)26 OriginType (org.onosproject.bgpio.types.Origin.OriginType)26 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)24 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)24 IpPrefix (org.onlab.packet.IpPrefix)21 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)16 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)13 Ip4Address (org.onlab.packet.Ip4Address)12 PathAttrNlriDetails (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails)11 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)11 IpAddress (org.onlab.packet.IpAddress)10