Process protocol message read partially from the buffer.
Change-Id: I1888dce82bea566796bc222329650582cba5a276
diff --git a/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java b/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java
index 431c621..e9e919c 100755
--- a/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java
+++ b/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java
@@ -48,13 +48,27 @@
HexDump.dump(buffer);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
- List<BgpMessage> msgList = new LinkedList<BgpMessage>();
+ List<BgpMessage> msgList = (List<BgpMessage>) ctx.getAttachment();
- while (buffer.readableBytes() > 0) {
- BgpHeader bgpHeader = new BgpHeader();
- BgpMessage message = reader.readFrom(buffer, bgpHeader);
- msgList.add(message);
+ if (msgList == null) {
+ msgList = new LinkedList<>();
}
- return msgList;
+
+ try {
+ while (buffer.readableBytes() > 0) {
+ buffer.markReaderIndex();
+ BgpHeader bgpHeader = new BgpHeader();
+ BgpMessage message = reader.readFrom(buffer, bgpHeader);
+ msgList.add(message);
+ }
+
+ return msgList;
+ } catch (Exception e) {
+ log.debug("Bgp protocol message decode error");
+ buffer.resetReaderIndex();
+ buffer.discardReadBytes();
+ ctx.setAttachment(msgList);
+ }
+ return null;
}
}
\ No newline at end of file