Search in sources :

Example 16 with MultiProtocolExtnCapabilityTlv

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

BgpValueType (org.onosproject.bgpio.types.BgpValueType)16 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)16 Test (org.junit.Test)13 LinkedList (java.util.LinkedList)10 InetSocketAddress (java.net.InetSocketAddress)9 BgpId (org.onosproject.bgp.controller.BgpId)9 BgpLocalRibImpl (org.onosproject.bgp.controller.impl.BgpLocalRibImpl)9 BgpPeerImpl (org.onosproject.bgp.controller.impl.BgpPeerImpl)9 VpnAdjRibIn (org.onosproject.bgp.controller.impl.VpnAdjRibIn)9 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)9 AdjRibIn (org.onosproject.bgp.controller.impl.AdjRibIn)7 BgpNodeLSIdentifier (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier)7 Channel (org.jboss.netty.channel.Channel)6 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)3 FourOctetAsNumCapabilityTlv (org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv)3 RpdCapabilityTlv (org.onosproject.bgpio.types.RpdCapabilityTlv)3 BgpParseException (org.onosproject.bgpio.exceptions.BgpParseException)2 PathAttrNlriDetails (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails)2 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)2 RouteDistinguisher (org.onosproject.bgpio.types.RouteDistinguisher)2