@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(2); ospfPacketHeader.setOspfVer(2); ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2")); ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3")); ddPacket.setIsOpaqueCapable(true); ddPacket.setOptions(66); ddPacket = new DdPacket(ospfPacketHeader); packet = createByteForDdPacket(); channelBuffer = ChannelBuffers.copiedBuffer(packet); ddPacket.readFrom(channelBuffer); assertThat(ddPacket, is(notNullValue())); assertThat(ddPacket.ospfMessageType(), is(OspfPacketType.DD)); }
@Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setImtu(channelBuffer.readShort()); int options = channelBuffer.readByte(); String obit = Integer.toHexString(options); if (obit.length() == 1) { obit = "0" + obit; } String toBinary = Integer.toBinaryString(Integer.parseInt(new Character(obit.charAt(0)).toString())); if (toBinary.length() == 1) { toBinary = "000" + toBinary; } else if (toBinary.length() == 2) { toBinary = "00" + toBinary; } else if (toBinary.length() == 3) { toBinary = "0" + toBinary; } if (Integer.parseInt(new Character(toBinary.charAt(1)).toString()) == 1) { this.setIsOpaqueCapable(true); } this.setOptions(options); this.setIms(channelBuffer.readByte()); String strIms = Integer.toBinaryString(this.ims()); if (strIms.length() == 3) { this.setIsInitialize(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(1)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(2)))); } else if (strIms.length() == 2) { this.setIsInitialize(0); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(1)))); } else if (strIms.length() == 1) { this.setIsInitialize(0); this.setIsMore(0); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(0)))); } this.setSequenceNo(channelBuffer.readInt()); while (channelBuffer.readableBytes() >= OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); addLsaHeader(header); } } catch (Exception e) { log.debug("Error::DdPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } }
DdPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setImtu(channelBuffer.readShort()); int options = channelBuffer.readByte(); String obit = Integer.toHexString(options); if (obit.length() == 1) { obit = "0" + obit; } String toBinary = Integer.toBinaryString(Integer.parseInt(new Character(obit.charAt(0)).toString())); if (toBinary.length() == 1) { toBinary = "000" + toBinary; } else if (toBinary.length() == 2) { toBinary = "00" + toBinary; } else if (toBinary.length() == 3) { toBinary = "0" + toBinary; } if (Integer.parseInt(new Character(toBinary.charAt(1)).toString()) == 1) { this.setIsOpaqueCapable(true); } this.setOptions(options); this.setIms(channelBuffer.readByte()); String strIms = Integer.toBinaryString(this.ims()); if (strIms.length() == 3) { this.setIsInitialize(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(1)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(2)))); } else if (strIms.length() == 2) { this.setIsInitialize(0); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(1)))); } else if (strIms.length() == 1) { this.setIsInitialize(0); this.setIsMore(0); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(0)))); } this.setSequenceNo(channelBuffer.readInt()); while (channelBuffer.readableBytes() >= OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); addLsaHeader(header); } } catch (Exception e) { log.debug("Error::DdPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } }
DdPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setImtu(channelBuffer.readShort()); int options = channelBuffer.readByte(); String obit = Integer.toHexString(options); if (obit.length() == 1) { obit = "0" + obit; } String toBinary = Integer.toBinaryString(Integer.parseInt(new Character(obit.charAt(0)).toString())); if (toBinary.length() == 1) { toBinary = "000" + toBinary; } else if (toBinary.length() == 2) { toBinary = "00" + toBinary; } else if (toBinary.length() == 3) { toBinary = "0" + toBinary; } if (Integer.parseInt(new Character(toBinary.charAt(1)).toString()) == 1) { this.setIsOpaqueCapable(true); } this.setOptions(options); this.setIms(channelBuffer.readByte()); String strIms = Integer.toBinaryString(this.ims()); if (strIms.length() == 3) { this.setIsInitialize(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(1)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(2)))); } else if (strIms.length() == 2) { this.setIsInitialize(0); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(1)))); } else if (strIms.length() == 1) { this.setIsInitialize(0); this.setIsMore(0); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(0)))); } this.setSequenceNo(channelBuffer.readInt()); while (channelBuffer.readableBytes() >= OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); addLsaHeader(header); } } catch (Exception e) { log.debug("Error::DdPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } DdPacket();  DdPacket(OspfPacketHeader ospfHeader); }
DdPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setImtu(channelBuffer.readShort()); int options = channelBuffer.readByte(); String obit = Integer.toHexString(options); if (obit.length() == 1) { obit = "0" + obit; } String toBinary = Integer.toBinaryString(Integer.parseInt(new Character(obit.charAt(0)).toString())); if (toBinary.length() == 1) { toBinary = "000" + toBinary; } else if (toBinary.length() == 2) { toBinary = "00" + toBinary; } else if (toBinary.length() == 3) { toBinary = "0" + toBinary; } if (Integer.parseInt(new Character(toBinary.charAt(1)).toString()) == 1) { this.setIsOpaqueCapable(true); } this.setOptions(options); this.setIms(channelBuffer.readByte()); String strIms = Integer.toBinaryString(this.ims()); if (strIms.length() == 3) { this.setIsInitialize(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(1)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(2)))); } else if (strIms.length() == 2) { this.setIsInitialize(0); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(1)))); } else if (strIms.length() == 1) { this.setIsInitialize(0); this.setIsMore(0); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(0)))); } this.setSequenceNo(channelBuffer.readInt()); while (channelBuffer.readableBytes() >= OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); addLsaHeader(header); } } catch (Exception e) { log.debug("Error::DdPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } DdPacket();  DdPacket(OspfPacketHeader ospfHeader); boolean isOpaqueCapable(); void setIsOpaqueCapable(boolean isOpaqueCapable); int ims(); void setIms(int ims); int isMaster(); void setIsMaster(int isMaster); int isInitialize(); void setIsInitialize(int isInitialize); int isMore(); void setIsMore(int isMore); int imtu(); void setImtu(int imtu); int options(); void setOptions(int options); long sequenceNo(); void setSequenceNo(long sequenceNo); List<LsaHeader> getLsaHeaderList(); void addLsaHeader(LsaHeader lsaHeader); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getDdHeaderAsByteArray(); byte[] getDdBodyAsByteArray(); @Override String toString(); }
DdPacket extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setImtu(channelBuffer.readShort()); int options = channelBuffer.readByte(); String obit = Integer.toHexString(options); if (obit.length() == 1) { obit = "0" + obit; } String toBinary = Integer.toBinaryString(Integer.parseInt(new Character(obit.charAt(0)).toString())); if (toBinary.length() == 1) { toBinary = "000" + toBinary; } else if (toBinary.length() == 2) { toBinary = "00" + toBinary; } else if (toBinary.length() == 3) { toBinary = "0" + toBinary; } if (Integer.parseInt(new Character(toBinary.charAt(1)).toString()) == 1) { this.setIsOpaqueCapable(true); } this.setOptions(options); this.setIms(channelBuffer.readByte()); String strIms = Integer.toBinaryString(this.ims()); if (strIms.length() == 3) { this.setIsInitialize(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(1)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(2)))); } else if (strIms.length() == 2) { this.setIsInitialize(0); this.setIsMore(Integer.parseInt(Character.toString(strIms.charAt(0)))); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(1)))); } else if (strIms.length() == 1) { this.setIsInitialize(0); this.setIsMore(0); this.setIsMaster(Integer.parseInt(Character.toString(strIms.charAt(0)))); } this.setSequenceNo(channelBuffer.readInt()); while (channelBuffer.readableBytes() >= OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); addLsaHeader(header); } } catch (Exception e) { log.debug("Error::DdPacket:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } DdPacket();  DdPacket(OspfPacketHeader ospfHeader); boolean isOpaqueCapable(); void setIsOpaqueCapable(boolean isOpaqueCapable); int ims(); void setIms(int ims); int isMaster(); void setIsMaster(int isMaster); int isInitialize(); void setIsInitialize(int isInitialize); int isMore(); void setIsMore(int isMore); int imtu(); void setImtu(int imtu); int options(); void setOptions(int options); long sequenceNo(); void setSequenceNo(long sequenceNo); List<LsaHeader> getLsaHeaderList(); void addLsaHeader(LsaHeader lsaHeader); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getDdHeaderAsByteArray(); byte[] getDdBodyAsByteArray(); @Override String toString();  }