use of org.onosproject.bgpio.types.WideCommunityInteger in project onos by opennetworkinglab.
the class WideCommunity method decodeWideCommunityTlv.
/**
* Decode wide community target(s).
*
* @param c channel buffer
* @return target list
* @throws BgpParseException on decode error
*/
public static List<BgpValueType> decodeWideCommunityTlv(ChannelBuffer c) throws BgpParseException {
List<BgpValueType> targetTlv = new ArrayList<>();
while (c.readableBytes() > 0) {
if (c.readableBytes() < TYPE_LENGTH_SIZE) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, c.readableBytes());
}
byte atomType = c.readByte();
short atomLength = c.readShort();
if (c.readableBytes() < atomLength) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, atomLength);
}
if (atomType == WideCommunityIpV4Neighbour.TYPE) {
ChannelBuffer tempBuf = c.readBytes(atomLength);
WideCommunityIpV4Neighbour wideCommAtom = new WideCommunityIpV4Neighbour();
while (tempBuf.readableBytes() > 0) {
wideCommAtom.add(IpAddress.valueOf(tempBuf.readInt()), IpAddress.valueOf(tempBuf.readInt()));
}
targetTlv.add(wideCommAtom);
} else if (atomType == WideCommunityInteger.TYPE) {
ChannelBuffer tempBuf = c.readBytes(atomLength);
List<Integer> integer = new ArrayList<>();
while (tempBuf.readableBytes() > 0) {
integer.add(tempBuf.readInt());
}
targetTlv.add(new WideCommunityInteger(integer));
} else {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, atomLength);
}
}
return targetTlv;
}
use of org.onosproject.bgpio.types.WideCommunityInteger 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