[ONOS-3857] BGP flow specification components encode and decode test.
Change-Id: I2830cd4d26ca044332a16845643ea99e11381209
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
index 0931773..076d8dd 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -154,63 +154,65 @@
&& ((safi == Constants.SAFI_FLOWSPEC_VALUE)
|| (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
List<BgpValueType> flowSpecComponents = new LinkedList<>();
- BgpValueType flowSpecComponent = null;
- short totNlriLen = tempCb.getByte(tempCb.readerIndex());
- if (totNlriLen >= FLOW_SPEC_LEN) {
- totNlriLen = tempCb.readShort();
- } else {
- totNlriLen = tempCb.readByte();
- }
- if (tempCb.readableBytes() < totNlriLen) {
- Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
- BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
- }
- tempBuf = tempCb.readBytes(totNlriLen);
- while (tempBuf.readableBytes() > 0) {
- short type = tempBuf.readByte();
- switch (type) {
- case Constants.BGP_FLOWSPEC_DST_PREFIX:
- flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_SRC_PREFIX:
- flowSpecComponent = BgpFsSourcePrefix.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_IP_PROTO:
- flowSpecComponent = BgpFsIpProtocol.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_PORT:
- flowSpecComponent = BgpFsPortNum.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_DST_PORT:
- flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_SRC_PORT:
- flowSpecComponent = BgpFsSourcePortNum.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_ICMP_TP:
- flowSpecComponent = BgpFsIcmpType.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_ICMP_CD:
- flowSpecComponent = BgpFsIcmpType.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_TCP_FLAGS:
- flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_PCK_LEN:
- flowSpecComponent = BgpFsPacketLength.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_DSCP:
- flowSpecComponent = BgpFsDscpValue.read(tempBuf);
- break;
- case Constants.BGP_FLOWSPEC_FRAGMENT:
- flowSpecComponent = BgpFsFragment.read(tempBuf);
- break;
- default:
- log.debug("flow spec type not supported" + type);
- break;
+ if (tempCb.readableBytes() > 0) {
+ BgpValueType flowSpecComponent = null;
+ short totNlriLen = tempCb.getByte(tempCb.readerIndex());
+ if (totNlriLen >= FLOW_SPEC_LEN) {
+ totNlriLen = tempCb.readShort();
+ } else {
+ totNlriLen = tempCb.readByte();
}
- flowSpecComponents.add(flowSpecComponent);
+ if (tempCb.readableBytes() < totNlriLen) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ }
+ tempBuf = tempCb.readBytes(totNlriLen);
+ while (tempBuf.readableBytes() > 0) {
+ short type = tempBuf.readByte();
+ switch (type) {
+ case Constants.BGP_FLOWSPEC_DST_PREFIX:
+ flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_SRC_PREFIX:
+ flowSpecComponent = BgpFsSourcePrefix.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_IP_PROTO:
+ flowSpecComponent = BgpFsIpProtocol.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_PORT:
+ flowSpecComponent = BgpFsPortNum.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_DST_PORT:
+ flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_SRC_PORT:
+ flowSpecComponent = BgpFsSourcePortNum.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_ICMP_TP:
+ flowSpecComponent = BgpFsIcmpType.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_ICMP_CD:
+ flowSpecComponent = BgpFsIcmpType.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_TCP_FLAGS:
+ flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_PCK_LEN:
+ flowSpecComponent = BgpFsPacketLength.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_DSCP:
+ flowSpecComponent = BgpFsDscpValue.read(tempBuf);
+ break;
+ case Constants.BGP_FLOWSPEC_FRAGMENT:
+ flowSpecComponent = BgpFsFragment.read(tempBuf);
+ break;
+ default:
+ log.debug("flow spec type not supported" + type);
+ break;
+ }
+ flowSpecComponents.add(flowSpecComponent);
+ }
}
return new MpUnReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi);
} else {