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;
}
Aggregations