@Test public void testReadFrom() throws Exception { ospfExternalDestination = new OspfExternalDestination(); ospfExternalDestination.setExternalRouterTag(2); ospfExternalDestination.setMetric(100); ospfExternalDestination.setType1orType2Metric(true); externalLsa.addExternalDestination(ospfExternalDestination); ospfExternalDestination1 = new OspfExternalDestination(); ospfExternalDestination.setExternalRouterTag(3); ospfExternalDestination.setMetric(50); ospfExternalDestination.setType1orType2Metric(true); externalLsa.addExternalDestination(ospfExternalDestination1); ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); inputByteArray = createByteForNetworkLsa(); lsaHeader = createLsaHeader(); externalLsa = new ExternalLsa(lsaHeader); channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray); externalLsa.readFrom(channelBuffer); assertThat(externalLsa, is(notNullValue())); }
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)); while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) { OspfExternalDestination externalDestination = new OspfExternalDestination(); int eIsSet = channelBuffer.readByte(); if (eIsSet != 0) { externalDestination.setType1orType2Metric(true); } else { externalDestination.setType1orType2Metric(false); } externalDestination.setMetric(channelBuffer.readUnsignedMedium()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray)); externalDestination.setExternalRouterTag(channelBuffer.readInt()); this.addExternalDestination(externalDestination); } } catch (Exception e) { log.debug("Error::ExternalLSA:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } }
ExternalLsa extends LsaHeader { 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)); while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) { OspfExternalDestination externalDestination = new OspfExternalDestination(); int eIsSet = channelBuffer.readByte(); if (eIsSet != 0) { externalDestination.setType1orType2Metric(true); } else { externalDestination.setType1orType2Metric(false); } externalDestination.setMetric(channelBuffer.readUnsignedMedium()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray)); externalDestination.setExternalRouterTag(channelBuffer.readInt()); this.addExternalDestination(externalDestination); } } catch (Exception e) { log.debug("Error::ExternalLSA:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } } }
ExternalLsa extends LsaHeader { 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)); while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) { OspfExternalDestination externalDestination = new OspfExternalDestination(); int eIsSet = channelBuffer.readByte(); if (eIsSet != 0) { externalDestination.setType1orType2Metric(true); } else { externalDestination.setType1orType2Metric(false); } externalDestination.setMetric(channelBuffer.readUnsignedMedium()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray)); externalDestination.setExternalRouterTag(channelBuffer.readInt()); this.addExternalDestination(externalDestination); } } catch (Exception e) { log.debug("Error::ExternalLSA:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } } ExternalLsa(LsaHeader lsaHeader); }
ExternalLsa extends LsaHeader { 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)); while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) { OspfExternalDestination externalDestination = new OspfExternalDestination(); int eIsSet = channelBuffer.readByte(); if (eIsSet != 0) { externalDestination.setType1orType2Metric(true); } else { externalDestination.setType1orType2Metric(false); } externalDestination.setMetric(channelBuffer.readUnsignedMedium()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray)); externalDestination.setExternalRouterTag(channelBuffer.readInt()); this.addExternalDestination(externalDestination); } } catch (Exception e) { log.debug("Error::ExternalLSA:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } } ExternalLsa(LsaHeader lsaHeader); Ip4Address networkMask(); void setNetworkMask(Ip4Address networkMask); void addExternalDestination(OspfExternalDestination externalDestination); void readFrom(ChannelBuffer channelBuffer); byte[] asBytes(); byte[] getLsaBodyAsByteArray(); @Override OspfLsaType getOspfLsaType(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); }
ExternalLsa extends LsaHeader { 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)); while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) { OspfExternalDestination externalDestination = new OspfExternalDestination(); int eIsSet = channelBuffer.readByte(); if (eIsSet != 0) { externalDestination.setType1orType2Metric(true); } else { externalDestination.setType1orType2Metric(false); } externalDestination.setMetric(channelBuffer.readUnsignedMedium()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray)); externalDestination.setExternalRouterTag(channelBuffer.readInt()); this.addExternalDestination(externalDestination); } } catch (Exception e) { log.debug("Error::ExternalLSA:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } } ExternalLsa(LsaHeader lsaHeader); Ip4Address networkMask(); void setNetworkMask(Ip4Address networkMask); void addExternalDestination(OspfExternalDestination externalDestination); void readFrom(ChannelBuffer channelBuffer); byte[] asBytes(); byte[] getLsaBodyAsByteArray(); @Override OspfLsaType getOspfLsaType(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }