@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(4); ospfPacketHeader.setOspfVer(2); ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2")); ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3")); lsUpdate = new LsUpdate(ospfPacketHeader); result1 = createLsUpdatePacket(); channelBuffer = ChannelBuffers.copiedBuffer(result1); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet1); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet2); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet3); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet4); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet5); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet6); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet7); lsUpdate.readFrom(channelBuffer); channelBuffer = ChannelBuffers.copiedBuffer(packet8); lsUpdate.readFrom(channelBuffer); assertThat(lsUpdate, is(notNullValue())); assertThat(lsUpdate.ospfMessageType(), is(OspfPacketType.LSUPDATE)); }
@Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setNumberOfLsa(channelBuffer.readInt()); while (channelBuffer.readableBytes() > OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); int lsaLength = header.lsPacketLen(); int lsType = header.lsType(); switch (lsType) { case OspfParameters.LINK_LOCAL_OPAQUE_LSA: OpaqueLsa9 opaqueLsa9 = new OpaqueLsa9((OpaqueLsaHeader) header); opaqueLsa9.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa9); break; case OspfParameters.AREA_LOCAL_OPAQUE_LSA: OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10((OpaqueLsaHeader) header); opaqueLsa10.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa10); break; case OspfParameters.AS_OPAQUE_LSA: OpaqueLsa11 opaqueLsa11 = new OpaqueLsa11((OpaqueLsaHeader) header); opaqueLsa11.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa11); break; case OspfParameters.ROUTER: RouterLsa routerLsa = new RouterLsa(header); routerLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(routerLsa); break; case OspfParameters.NETWORK: NetworkLsa networkLsa = new NetworkLsa(header); networkLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(networkLsa); break; case OspfParameters.ASBR_SUMMARY: AsbrSummaryLsa asbrSummaryLsa = new AsbrSummaryLsa(header); asbrSummaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(asbrSummaryLsa); break; case OspfParameters.SUMMARY: SummaryLsa summaryLsa = new SummaryLsa(header); summaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(summaryLsa); break; case OspfParameters.EXTERNAL_LSA: ExternalLsa externalLsa = new ExternalLsa(header); externalLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(externalLsa); break; default: log.debug("LSUpdate::readLsUpdateBody::UnKnown LS Type: {}", lsType); break; } } } catch (Exception e) { log.debug("Error::LsUpdate:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } }
LsUpdate extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setNumberOfLsa(channelBuffer.readInt()); while (channelBuffer.readableBytes() > OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); int lsaLength = header.lsPacketLen(); int lsType = header.lsType(); switch (lsType) { case OspfParameters.LINK_LOCAL_OPAQUE_LSA: OpaqueLsa9 opaqueLsa9 = new OpaqueLsa9((OpaqueLsaHeader) header); opaqueLsa9.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa9); break; case OspfParameters.AREA_LOCAL_OPAQUE_LSA: OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10((OpaqueLsaHeader) header); opaqueLsa10.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa10); break; case OspfParameters.AS_OPAQUE_LSA: OpaqueLsa11 opaqueLsa11 = new OpaqueLsa11((OpaqueLsaHeader) header); opaqueLsa11.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa11); break; case OspfParameters.ROUTER: RouterLsa routerLsa = new RouterLsa(header); routerLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(routerLsa); break; case OspfParameters.NETWORK: NetworkLsa networkLsa = new NetworkLsa(header); networkLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(networkLsa); break; case OspfParameters.ASBR_SUMMARY: AsbrSummaryLsa asbrSummaryLsa = new AsbrSummaryLsa(header); asbrSummaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(asbrSummaryLsa); break; case OspfParameters.SUMMARY: SummaryLsa summaryLsa = new SummaryLsa(header); summaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(summaryLsa); break; case OspfParameters.EXTERNAL_LSA: ExternalLsa externalLsa = new ExternalLsa(header); externalLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(externalLsa); break; default: log.debug("LSUpdate::readLsUpdateBody::UnKnown LS Type: {}", lsType); break; } } } catch (Exception e) { log.debug("Error::LsUpdate:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } }
LsUpdate extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setNumberOfLsa(channelBuffer.readInt()); while (channelBuffer.readableBytes() > OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); int lsaLength = header.lsPacketLen(); int lsType = header.lsType(); switch (lsType) { case OspfParameters.LINK_LOCAL_OPAQUE_LSA: OpaqueLsa9 opaqueLsa9 = new OpaqueLsa9((OpaqueLsaHeader) header); opaqueLsa9.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa9); break; case OspfParameters.AREA_LOCAL_OPAQUE_LSA: OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10((OpaqueLsaHeader) header); opaqueLsa10.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa10); break; case OspfParameters.AS_OPAQUE_LSA: OpaqueLsa11 opaqueLsa11 = new OpaqueLsa11((OpaqueLsaHeader) header); opaqueLsa11.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa11); break; case OspfParameters.ROUTER: RouterLsa routerLsa = new RouterLsa(header); routerLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(routerLsa); break; case OspfParameters.NETWORK: NetworkLsa networkLsa = new NetworkLsa(header); networkLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(networkLsa); break; case OspfParameters.ASBR_SUMMARY: AsbrSummaryLsa asbrSummaryLsa = new AsbrSummaryLsa(header); asbrSummaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(asbrSummaryLsa); break; case OspfParameters.SUMMARY: SummaryLsa summaryLsa = new SummaryLsa(header); summaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(summaryLsa); break; case OspfParameters.EXTERNAL_LSA: ExternalLsa externalLsa = new ExternalLsa(header); externalLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(externalLsa); break; default: log.debug("LSUpdate::readLsUpdateBody::UnKnown LS Type: {}", lsType); break; } } } catch (Exception e) { log.debug("Error::LsUpdate:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } LsUpdate();  LsUpdate(OspfPacketHeader ospfHeader); }
LsUpdate extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setNumberOfLsa(channelBuffer.readInt()); while (channelBuffer.readableBytes() > OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); int lsaLength = header.lsPacketLen(); int lsType = header.lsType(); switch (lsType) { case OspfParameters.LINK_LOCAL_OPAQUE_LSA: OpaqueLsa9 opaqueLsa9 = new OpaqueLsa9((OpaqueLsaHeader) header); opaqueLsa9.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa9); break; case OspfParameters.AREA_LOCAL_OPAQUE_LSA: OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10((OpaqueLsaHeader) header); opaqueLsa10.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa10); break; case OspfParameters.AS_OPAQUE_LSA: OpaqueLsa11 opaqueLsa11 = new OpaqueLsa11((OpaqueLsaHeader) header); opaqueLsa11.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa11); break; case OspfParameters.ROUTER: RouterLsa routerLsa = new RouterLsa(header); routerLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(routerLsa); break; case OspfParameters.NETWORK: NetworkLsa networkLsa = new NetworkLsa(header); networkLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(networkLsa); break; case OspfParameters.ASBR_SUMMARY: AsbrSummaryLsa asbrSummaryLsa = new AsbrSummaryLsa(header); asbrSummaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(asbrSummaryLsa); break; case OspfParameters.SUMMARY: SummaryLsa summaryLsa = new SummaryLsa(header); summaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(summaryLsa); break; case OspfParameters.EXTERNAL_LSA: ExternalLsa externalLsa = new ExternalLsa(header); externalLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(externalLsa); break; default: log.debug("LSUpdate::readLsUpdateBody::UnKnown LS Type: {}", lsType); break; } } } catch (Exception e) { log.debug("Error::LsUpdate:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } LsUpdate();  LsUpdate(OspfPacketHeader ospfHeader); List getLsaList(); void addLsa(OspfLsa lsa); int noLsa(); void setNumberOfLsa(int numberOfLsa); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getLsuHeaderAsByteArray(); byte[] getLsuBodyAsByteArray(); @Override String toString(); }
LsUpdate extends OspfPacketHeader { @Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { try { this.setNumberOfLsa(channelBuffer.readInt()); while (channelBuffer.readableBytes() > OspfUtil.LSA_HEADER_LENGTH) { LsaHeader header = OspfUtil.readLsaHeader(channelBuffer.readBytes(OspfUtil.LSA_HEADER_LENGTH)); int lsaLength = header.lsPacketLen(); int lsType = header.lsType(); switch (lsType) { case OspfParameters.LINK_LOCAL_OPAQUE_LSA: OpaqueLsa9 opaqueLsa9 = new OpaqueLsa9((OpaqueLsaHeader) header); opaqueLsa9.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa9); break; case OspfParameters.AREA_LOCAL_OPAQUE_LSA: OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10((OpaqueLsaHeader) header); opaqueLsa10.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa10); break; case OspfParameters.AS_OPAQUE_LSA: OpaqueLsa11 opaqueLsa11 = new OpaqueLsa11((OpaqueLsaHeader) header); opaqueLsa11.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(opaqueLsa11); break; case OspfParameters.ROUTER: RouterLsa routerLsa = new RouterLsa(header); routerLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(routerLsa); break; case OspfParameters.NETWORK: NetworkLsa networkLsa = new NetworkLsa(header); networkLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(networkLsa); break; case OspfParameters.ASBR_SUMMARY: AsbrSummaryLsa asbrSummaryLsa = new AsbrSummaryLsa(header); asbrSummaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(asbrSummaryLsa); break; case OspfParameters.SUMMARY: SummaryLsa summaryLsa = new SummaryLsa(header); summaryLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(summaryLsa); break; case OspfParameters.EXTERNAL_LSA: ExternalLsa externalLsa = new ExternalLsa(header); externalLsa.readFrom(channelBuffer.readBytes(lsaLength - OspfUtil.LSA_HEADER_LENGTH)); addLsa(externalLsa); break; default: log.debug("LSUpdate::readLsUpdateBody::UnKnown LS Type: {}", lsType); break; } } } catch (Exception e) { log.debug("Error::LsUpdate:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH); } } LsUpdate();  LsUpdate(OspfPacketHeader ospfHeader); List getLsaList(); void addLsa(OspfLsa lsa); int noLsa(); void setNumberOfLsa(int numberOfLsa); @Override OspfPacketType ospfMessageType(); @Override void readFrom(ChannelBuffer channelBuffer); @Override byte[] asBytes(); byte[] getLsuHeaderAsByteArray(); byte[] getLsuBodyAsByteArray(); @Override String toString();  }