@Test public void testDecode() throws Exception { channel = EasyMock.createMock(Channel.class); socketAddress = InetSocketAddress.createUnresolved(id, 7000); byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17); array1 = Bytes.concat(hello, array); channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array)); assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue())); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); if (!channel.isConnected()) { log.info("Channel is not connected."); return null; } IsisMessageReader messageReader = new IsisMessageReader(); List<IsisMessage> isisMessageList = new LinkedList<>(); int dataLength = buffer.readableBytes(); while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); MacAddress sourceMac = getSourceMac(ethernetHeader); ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); int readableBytes = isisDataBuffer.readableBytes(); IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); if (message != null) { if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { message.setSourceMac(sourceMac); isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); MacAddress macAddress = MacAddress.valueOf(macBytes); int interfaceIndex = isisDataBuffer.readByte(); message.setInterfaceMac(macAddress); message.setInterfaceIndex(interfaceIndex); } isisMessageList.add(message); } } return (isisMessageList.size() > 0) ? isisMessageList : null; }
IsisMessageDecoder extends FrameDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); if (!channel.isConnected()) { log.info("Channel is not connected."); return null; } IsisMessageReader messageReader = new IsisMessageReader(); List<IsisMessage> isisMessageList = new LinkedList<>(); int dataLength = buffer.readableBytes(); while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); MacAddress sourceMac = getSourceMac(ethernetHeader); ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); int readableBytes = isisDataBuffer.readableBytes(); IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); if (message != null) { if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { message.setSourceMac(sourceMac); isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); MacAddress macAddress = MacAddress.valueOf(macBytes); int interfaceIndex = isisDataBuffer.readByte(); message.setInterfaceMac(macAddress); message.setInterfaceIndex(interfaceIndex); } isisMessageList.add(message); } } return (isisMessageList.size() > 0) ? isisMessageList : null; } }
IsisMessageDecoder extends FrameDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); if (!channel.isConnected()) { log.info("Channel is not connected."); return null; } IsisMessageReader messageReader = new IsisMessageReader(); List<IsisMessage> isisMessageList = new LinkedList<>(); int dataLength = buffer.readableBytes(); while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); MacAddress sourceMac = getSourceMac(ethernetHeader); ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); int readableBytes = isisDataBuffer.readableBytes(); IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); if (message != null) { if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { message.setSourceMac(sourceMac); isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); MacAddress macAddress = MacAddress.valueOf(macBytes); int interfaceIndex = isisDataBuffer.readByte(); message.setInterfaceMac(macAddress); message.setInterfaceIndex(interfaceIndex); } isisMessageList.add(message); } } return (isisMessageList.size() > 0) ? isisMessageList : null; }  }
IsisMessageDecoder extends FrameDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); if (!channel.isConnected()) { log.info("Channel is not connected."); return null; } IsisMessageReader messageReader = new IsisMessageReader(); List<IsisMessage> isisMessageList = new LinkedList<>(); int dataLength = buffer.readableBytes(); while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); MacAddress sourceMac = getSourceMac(ethernetHeader); ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); int readableBytes = isisDataBuffer.readableBytes(); IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); if (message != null) { if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { message.setSourceMac(sourceMac); isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); MacAddress macAddress = MacAddress.valueOf(macBytes); int interfaceIndex = isisDataBuffer.readByte(); message.setInterfaceMac(macAddress); message.setInterfaceIndex(interfaceIndex); } isisMessageList.add(message); } } return (isisMessageList.size() > 0) ? isisMessageList : null; }   }
IsisMessageDecoder extends FrameDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); if (!channel.isConnected()) { log.info("Channel is not connected."); return null; } IsisMessageReader messageReader = new IsisMessageReader(); List<IsisMessage> isisMessageList = new LinkedList<>(); int dataLength = buffer.readableBytes(); while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); MacAddress sourceMac = getSourceMac(ethernetHeader); ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); int readableBytes = isisDataBuffer.readableBytes(); IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); if (message != null) { if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { message.setSourceMac(sourceMac); isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); MacAddress macAddress = MacAddress.valueOf(macBytes); int interfaceIndex = isisDataBuffer.readByte(); message.setInterfaceMac(macAddress); message.setInterfaceIndex(interfaceIndex); } isisMessageList.add(message); } } return (isisMessageList.size() > 0) ? isisMessageList : null; }    }