Search in sources :

Example 81 with BgpValueType

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

the class BgpOpenMsgVer4 method packCapabilityTlv.

/**
 * returns length of capability tlvs.
 *
 * @param cb of type channel buffer
 * @param message of type BGPOpenMsgVer4
 * @return capParaLen of open message
 */
protected int packCapabilityTlv(ChannelBuffer cb, BgpOpenMsgVer4 message) {
    int startIndex = cb.writerIndex();
    int capParaLen = 0;
    int capParaLenIndex = 0;
    LinkedList<BgpValueType> capabilityTlv = message.capabilityTlv;
    ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
    if (listIterator.hasNext()) {
        // Set optional parameter type as 2
        cb.writeByte(OPT_PARA_TYPE_CAPABILITY);
        // Store the index of capability parameter length and update length at the end
        capParaLenIndex = cb.writerIndex();
        // Set capability parameter length as 0
        cb.writeByte(0);
        // Update the startIndex to know the length of capability tlv
        startIndex = cb.writerIndex();
    }
    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        if (tlv == null) {
            log.debug("Warning: TLV is null from CapabilityTlv list");
            continue;
        }
        tlv.write(cb);
    }
    capParaLen = cb.writerIndex() - startIndex;
    if (capParaLen != 0) {
        // Update capability parameter length
        cb.setByte(capParaLenIndex, (byte) capParaLen);
    }
    return capParaLen;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Example 82 with BgpValueType

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

the class BgpOpenMsgVer4 method parseCapabilityTlv.

/**
 * Parsing capabilities.
 *
 * @param cb of type channel buffer
 * @return capabilityTlv of open message
 * @throws BgpParseException while parsing capabilities
 */
protected static LinkedList<BgpValueType> parseCapabilityTlv(ChannelBuffer cb) throws BgpParseException {
    LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
    while (cb.readableBytes() > 0) {
        BgpValueType tlv;
        short type = cb.readByte();
        short length = cb.readByte();
        switch(type) {
            case FourOctetAsNumCapabilityTlv.TYPE:
                log.debug("FourOctetAsNumCapabilityTlv");
                if (FourOctetAsNumCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for FourOctetAsNumCapabilityTlv.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("Four octet as num tlv length" + " is more than readableBytes.");
                }
                int as4Num = cb.readInt();
                tlv = new FourOctetAsNumCapabilityTlv(as4Num);
                break;
            case RpdCapabilityTlv.TYPE:
                log.debug("RpdCapability");
                if (RpdCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for RpdCapability.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("Four octet as num TLV length" + " is more than readableBytes.");
                }
                short rpdAfi = cb.readShort();
                byte rpdAsafi = cb.readByte();
                byte sendReceive = cb.readByte();
                tlv = new RpdCapabilityTlv(sendReceive);
                break;
            case MultiProtocolExtnCapabilityTlv.TYPE:
                log.debug("MultiProtocolExtnCapabilityTlv");
                if (MultiProtocolExtnCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for MultiProtocolExtnCapabilityTlv.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("BGP LS tlv length is more than readableBytes.");
                }
                short afi = cb.readShort();
                byte res = cb.readByte();
                byte safi = cb.readByte();
                tlv = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
                break;
            case RouteRefreshCapabilityTlv.TYPE:
                log.debug("RouteRefreshCapabilityTlv");
                if (RouteRefreshCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for RouteRefreshCapabilityTlv.");
                }
                tlv = new RouteRefreshCapabilityTlv(true);
                break;
            default:
                log.debug("Warning: Unsupported TLV: " + type);
                cb.skipBytes(length);
                continue;
        }
        capabilityTlv.add(tlv);
    }
    return capabilityTlv;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) RouteRefreshCapabilityTlv(org.onosproject.bgpio.types.RouteRefreshCapabilityTlv) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) FourOctetAsNumCapabilityTlv(org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv) RpdCapabilityTlv(org.onosproject.bgpio.types.RpdCapabilityTlv) LinkedList(java.util.LinkedList)

Example 83 with BgpValueType

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

the class WideCommunity method encodeWideCommunityTlv.

/**
 * Encode wide community target(s).
 *
 * @param c channel buffer
 * @param targetTlv wide community include/exclude target
 */
public static void encodeWideCommunityTlv(ChannelBuffer c, List<BgpValueType> targetTlv) {
    /*
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         |  IPV4Neig(8)  |   Length:                   8 |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         | local                                               10101010  |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         | remote                                              10101010  |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * */
    List<BgpValueType> target = targetTlv;
    if (target == null) {
        log.debug("target is null");
        return;
    }
    Iterator<BgpValueType> listIterator = targetTlv.iterator();
    while (listIterator.hasNext()) {
        BgpValueType attr = listIterator.next();
        if (attr instanceof WideCommunityIpV4Neighbour) {
            WideCommunityIpV4Neighbour ipv4Neig = (WideCommunityIpV4Neighbour) attr;
            ipv4Neig.write(c);
        } else if (attr instanceof WideCommunityInteger) {
            WideCommunityInteger integer = (WideCommunityInteger) attr;
            integer.write(c);
        }
    }
    return;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) WideCommunityInteger(org.onosproject.bgpio.types.WideCommunityInteger) WideCommunityIpV4Neighbour(org.onosproject.bgpio.types.WideCommunityIpV4Neighbour)

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