@Test public void testReadFrom() throws Exception { ospfPacketHeader = new OspfPacketHeader(); ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1")); ospfPacketHeader.setAuthentication(0); ospfPacketHeader.setAuthType(0); ospfPacketHeader.setChecksum(12345); ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("10.10.10.10")); ospfPacketHeader.setOspfPacLength(56); ospfPacketHeader.setOspftype(1); ospfPacketHeader.setOspfVer(2); ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2")); ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3")); packet = createByteForHelloPacket(); channelBuffer = ChannelBuffers.copiedBuffer(packet); helloPacket.readFrom(channelBuffer); assertThat(helloPacket, is(notNullValue())); assertThat(helloPacket.ospfMessageType(), is(OspfPacketType.HELLO)); }
@Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setNetworkMask(Ip4Address.valueOf(tempByteArray)); this.setHelloInterval(channelBuffer.readShort()); this.setOptions(channelBuffer.readByte()); this.setRouterPriority(channelBuffer.readByte() & 0xff); this.setRouterDeadInterval(channelBuffer.readInt()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setDr(Ip4Address.valueOf(tempByteArray)); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setBdr(Ip4Address.valueOf(tempByteArray)); while (channelBuffer.readableBytes() > 0) { tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addNeighbor(Ip4Address.valueOf(tempByteArray)); } } catch (Exception e) { log.debug("Error::HelloPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } }
HelloPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setNetworkMask(Ip4Address.valueOf(tempByteArray)); this.setHelloInterval(channelBuffer.readShort()); this.setOptions(channelBuffer.readByte()); this.setRouterPriority(channelBuffer.readByte() & 0xff); this.setRouterDeadInterval(channelBuffer.readInt()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setDr(Ip4Address.valueOf(tempByteArray)); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setBdr(Ip4Address.valueOf(tempByteArray)); while (channelBuffer.readableBytes() > 0) { tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addNeighbor(Ip4Address.valueOf(tempByteArray)); } } catch (Exception e) { log.debug("Error::HelloPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } }
HelloPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setNetworkMask(Ip4Address.valueOf(tempByteArray)); this.setHelloInterval(channelBuffer.readShort()); this.setOptions(channelBuffer.readByte()); this.setRouterPriority(channelBuffer.readByte() & 0xff); this.setRouterDeadInterval(channelBuffer.readInt()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setDr(Ip4Address.valueOf(tempByteArray)); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setBdr(Ip4Address.valueOf(tempByteArray)); while (channelBuffer.readableBytes() > 0) { tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addNeighbor(Ip4Address.valueOf(tempByteArray)); } } catch (Exception e) { log.debug("Error::HelloPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } HelloPacket();  HelloPacket(OspfPacketHeader ospfHeader); }
HelloPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setNetworkMask(Ip4Address.valueOf(tempByteArray)); this.setHelloInterval(channelBuffer.readShort()); this.setOptions(channelBuffer.readByte()); this.setRouterPriority(channelBuffer.readByte() & 0xff); this.setRouterDeadInterval(channelBuffer.readInt()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setDr(Ip4Address.valueOf(tempByteArray)); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setBdr(Ip4Address.valueOf(tempByteArray)); while (channelBuffer.readableBytes() > 0) { tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addNeighbor(Ip4Address.valueOf(tempByteArray)); } } catch (Exception e) { log.debug("Error::HelloPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } HelloPacket();  HelloPacket(OspfPacketHeader ospfHeader); Ip4Address networkMask(); void setNetworkMask(Ip4Address networkMask); Ip4Address bdr(); void setBdr(Ip4Address bdr); Ip4Address dr(); void setDr(Ip4Address dr); void addNeighbor(Ip4Address neighborID); boolean containsNeighbour(Ip4Address neighborID); int options(); void setOptions(int options); int routerPriority(); void setRouterPriority(int routerPriority); int helloInterval(); void setHelloInterval(int helloInterval); int routerDeadInterval(); void setRouterDeadInterval(int routerDeadInterval); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getHelloHeaderAsByteArray(); byte[] getHelloBodyAsByteArray(); @Override String toString(); }
HelloPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setNetworkMask(Ip4Address.valueOf(tempByteArray)); this.setHelloInterval(channelBuffer.readShort()); this.setOptions(channelBuffer.readByte()); this.setRouterPriority(channelBuffer.readByte() & 0xff); this.setRouterDeadInterval(channelBuffer.readInt()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setDr(Ip4Address.valueOf(tempByteArray)); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.setBdr(Ip4Address.valueOf(tempByteArray)); while (channelBuffer.readableBytes() > 0) { tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addNeighbor(Ip4Address.valueOf(tempByteArray)); } } catch (Exception e) { log.debug("Error::HelloPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } HelloPacket();  HelloPacket(OspfPacketHeader ospfHeader); Ip4Address networkMask(); void setNetworkMask(Ip4Address networkMask); Ip4Address bdr(); void setBdr(Ip4Address bdr); Ip4Address dr(); void setDr(Ip4Address dr); void addNeighbor(Ip4Address neighborID); boolean containsNeighbour(Ip4Address neighborID); int options(); void setOptions(int options); int routerPriority(); void setRouterPriority(int routerPriority); int helloInterval(); void setHelloInterval(int helloInterval); int routerDeadInterval(); void setRouterDeadInterval(int routerDeadInterval); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getHelloHeaderAsByteArray(); byte[] getHelloBodyAsByteArray(); @Override String toString();  }