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