Search in sources :

Example 1 with RouteRefreshCapabilityTlv

use of org.onosproject.bgpio.types.RouteRefreshCapabilityTlv 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)

Aggregations

LinkedList (java.util.LinkedList)1 BgpParseException (org.onosproject.bgpio.exceptions.BgpParseException)1 BgpValueType (org.onosproject.bgpio.types.BgpValueType)1 FourOctetAsNumCapabilityTlv (org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv)1 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)1 RouteRefreshCapabilityTlv (org.onosproject.bgpio.types.RouteRefreshCapabilityTlv)1 RpdCapabilityTlv (org.onosproject.bgpio.types.RpdCapabilityTlv)1