@Test public void testReadFromBuffer() throws Exception { channelBuffer = ChannelBuffers.copiedBuffer(helloP2P); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(P2PHelloPdu.class))); channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(L1L2HelloPdu.class))); byte[] tlv1 = Bytes.concat(l1Lsp, (IsisUtil.getPaddingTlvs(l1Lsp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(LsPdu.class))); tlv1 = Bytes.concat(csnp, (IsisUtil.getPaddingTlvs(csnp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(Csnp.class))); tlv1 = Bytes.concat(psnp, (IsisUtil.getPaddingTlvs(psnp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(Psnp.class))); }
public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { int dataLength = channelBuffer.readableBytes(); log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { log.debug("Packet should have minimum length..."); throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); } IsisHeader isisHeader = getIsisHeader(channelBuffer); int totalLength = 0; IsisMessage isisMessage = null; switch (isisHeader.isisPduType()) { case L1HELLOPDU: case L2HELLOPDU: isisMessage = new L1L2HelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case P2PHELLOPDU: isisMessage = new P2PHelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case L1LSPDU: case L2LSPDU: isisMessage = new LsPdu(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1CSNP: case L2CSNP: isisMessage = new Csnp(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1PSNP: case L2PSNP: isisMessage = new Psnp(isisHeader); totalLength = channelBuffer.getShort(8); break; default: log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); break; } if (isisMessage != null) { try { int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); } catch (Exception e) { throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, IsisErrorType.BAD_MESSAGE); } } return isisMessage; }
IsisMessageReader { public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { int dataLength = channelBuffer.readableBytes(); log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { log.debug("Packet should have minimum length..."); throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); } IsisHeader isisHeader = getIsisHeader(channelBuffer); int totalLength = 0; IsisMessage isisMessage = null; switch (isisHeader.isisPduType()) { case L1HELLOPDU: case L2HELLOPDU: isisMessage = new L1L2HelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case P2PHELLOPDU: isisMessage = new P2PHelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case L1LSPDU: case L2LSPDU: isisMessage = new LsPdu(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1CSNP: case L2CSNP: isisMessage = new Csnp(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1PSNP: case L2PSNP: isisMessage = new Psnp(isisHeader); totalLength = channelBuffer.getShort(8); break; default: log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); break; } if (isisMessage != null) { try { int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); } catch (Exception e) { throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, IsisErrorType.BAD_MESSAGE); } } return isisMessage; } }
IsisMessageReader { public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { int dataLength = channelBuffer.readableBytes(); log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { log.debug("Packet should have minimum length..."); throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); } IsisHeader isisHeader = getIsisHeader(channelBuffer); int totalLength = 0; IsisMessage isisMessage = null; switch (isisHeader.isisPduType()) { case L1HELLOPDU: case L2HELLOPDU: isisMessage = new L1L2HelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case P2PHELLOPDU: isisMessage = new P2PHelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case L1LSPDU: case L2LSPDU: isisMessage = new LsPdu(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1CSNP: case L2CSNP: isisMessage = new Csnp(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1PSNP: case L2PSNP: isisMessage = new Psnp(isisHeader); totalLength = channelBuffer.getShort(8); break; default: log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); break; } if (isisMessage != null) { try { int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); } catch (Exception e) { throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, IsisErrorType.BAD_MESSAGE); } } return isisMessage; }  }
IsisMessageReader { public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { int dataLength = channelBuffer.readableBytes(); log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { log.debug("Packet should have minimum length..."); throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); } IsisHeader isisHeader = getIsisHeader(channelBuffer); int totalLength = 0; IsisMessage isisMessage = null; switch (isisHeader.isisPduType()) { case L1HELLOPDU: case L2HELLOPDU: isisMessage = new L1L2HelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case P2PHELLOPDU: isisMessage = new P2PHelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case L1LSPDU: case L2LSPDU: isisMessage = new LsPdu(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1CSNP: case L2CSNP: isisMessage = new Csnp(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1PSNP: case L2PSNP: isisMessage = new Psnp(isisHeader); totalLength = channelBuffer.getShort(8); break; default: log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); break; } if (isisMessage != null) { try { int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); } catch (Exception e) { throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, IsisErrorType.BAD_MESSAGE); } } return isisMessage; }  IsisMessage readFromBuffer(ChannelBuffer channelBuffer); }
IsisMessageReader { public IsisMessage readFromBuffer(ChannelBuffer channelBuffer) throws Exception { int dataLength = channelBuffer.readableBytes(); log.debug("IsisMessageReader::readFromBuffer Data length {}", dataLength); if (channelBuffer.readableBytes() < IsisConstants.PDU_LENGTH) { log.debug("Packet should have minimum length..."); throw new IsisParseException(IsisErrorType.MESSAGE_HEADER_ERROR, IsisErrorType.BAD_MESSAGE_LENGTH); } IsisHeader isisHeader = getIsisHeader(channelBuffer); int totalLength = 0; IsisMessage isisMessage = null; switch (isisHeader.isisPduType()) { case L1HELLOPDU: case L2HELLOPDU: isisMessage = new L1L2HelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case P2PHELLOPDU: isisMessage = new P2PHelloPdu(isisHeader); totalLength = channelBuffer.getShort(IsisConstants.PDULENGTHPOSITION); break; case L1LSPDU: case L2LSPDU: isisMessage = new LsPdu(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1CSNP: case L2CSNP: isisMessage = new Csnp(isisHeader); totalLength = channelBuffer.getShort(8); break; case L1PSNP: case L2PSNP: isisMessage = new Psnp(isisHeader); totalLength = channelBuffer.getShort(8); break; default: log.debug("Message Reader[Decoder] - Unknown PDU type..!!!"); break; } if (isisMessage != null) { try { int bodyLength = totalLength - IsisConstants.COMMONHEADERLENGTH; isisMessage.readFrom(channelBuffer.readBytes(bodyLength)); } catch (Exception e) { throw new IsisParseException(IsisErrorType.ISIS_MESSAGE_ERROR, IsisErrorType.BAD_MESSAGE); } } return isisMessage; }  IsisMessage readFromBuffer(ChannelBuffer channelBuffer);  }