@Test public void testIsValidLsaCheckSum4() throws Exception { external = new ExternalLsa(new LsaHeader()); external.setAge(2); external.setOptions(2); external.setLsType(5); external.setLinkStateId("80.212.16.0"); external.setAdvertisingRouter(Ip4Address.valueOf("192.168.170.2")); external.setLsSequenceNo(2147483649L); external.setLsCheckSum(25125); external.setLsPacketLen(36); validate = checksumCalculator.isValidLsaCheckSum(external, external.lsType(), lsaChecksumPos1, lsaChecksumPos2); assertThat(validate, is(false)); }
public boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1, int lsaChecksumPos2) throws Exception { if (lsType == OspfLsaType.ROUTER.value()) { RouterLsa lsa = (RouterLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.NETWORK.value()) { NetworkLsa lsa = (NetworkLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.SUMMARY.value()) { SummaryLsa lsa = (SummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) { AsbrSummaryLsa lsa = (AsbrSummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) { ExternalLsa lsa = (ExternalLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa9 lsa = (OpaqueLsa9) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa10 lsa = (OpaqueLsa10) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) { OpaqueLsa11 lsa = (OpaqueLsa11) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } return false; }
ChecksumCalculator { public boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1, int lsaChecksumPos2) throws Exception { if (lsType == OspfLsaType.ROUTER.value()) { RouterLsa lsa = (RouterLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.NETWORK.value()) { NetworkLsa lsa = (NetworkLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.SUMMARY.value()) { SummaryLsa lsa = (SummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) { AsbrSummaryLsa lsa = (AsbrSummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) { ExternalLsa lsa = (ExternalLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa9 lsa = (OpaqueLsa9) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa10 lsa = (OpaqueLsa10) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) { OpaqueLsa11 lsa = (OpaqueLsa11) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } return false; } }
ChecksumCalculator { public boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1, int lsaChecksumPos2) throws Exception { if (lsType == OspfLsaType.ROUTER.value()) { RouterLsa lsa = (RouterLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.NETWORK.value()) { NetworkLsa lsa = (NetworkLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.SUMMARY.value()) { SummaryLsa lsa = (SummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) { AsbrSummaryLsa lsa = (AsbrSummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) { ExternalLsa lsa = (ExternalLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa9 lsa = (OpaqueLsa9) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa10 lsa = (OpaqueLsa10) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) { OpaqueLsa11 lsa = (OpaqueLsa11) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } return false; }  }
ChecksumCalculator { public boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1, int lsaChecksumPos2) throws Exception { if (lsType == OspfLsaType.ROUTER.value()) { RouterLsa lsa = (RouterLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.NETWORK.value()) { NetworkLsa lsa = (NetworkLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.SUMMARY.value()) { SummaryLsa lsa = (SummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) { AsbrSummaryLsa lsa = (AsbrSummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) { ExternalLsa lsa = (ExternalLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa9 lsa = (OpaqueLsa9) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa10 lsa = (OpaqueLsa10) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) { OpaqueLsa11 lsa = (OpaqueLsa11) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } return false; }  static int convertToSixteenBits(String strToConvert); boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2); boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1,
                                      int lsaChecksumPos2); boolean validateLsaCheckSum(byte[] lsaPacket, int lsaChecksumPos1, int lsaChecksumPos2); boolean validateOspfCheckSum(byte[] ospfPacket, int checksumPos1, int checksumPos2); byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2); byte[] calculateOspfCheckSum(byte[] packet, int checksumPos1, int checksumPos2); }
ChecksumCalculator { public boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1, int lsaChecksumPos2) throws Exception { if (lsType == OspfLsaType.ROUTER.value()) { RouterLsa lsa = (RouterLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.NETWORK.value()) { NetworkLsa lsa = (NetworkLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.SUMMARY.value()) { SummaryLsa lsa = (SummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.ASBR_SUMMARY.value()) { AsbrSummaryLsa lsa = (AsbrSummaryLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.EXTERNAL_LSA.value()) { ExternalLsa lsa = (ExternalLsa) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa9 lsa = (OpaqueLsa9) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) { OpaqueLsa10 lsa = (OpaqueLsa10) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } else if (lsType == OspfLsaType.AS_OPAQUE_LSA.value()) { OpaqueLsa11 lsa = (OpaqueLsa11) ospfLsa; return validateLsaCheckSum(lsa.asBytes(), lsaChecksumPos1, lsaChecksumPos2); } return false; }  static int convertToSixteenBits(String strToConvert); boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2); boolean isValidLsaCheckSum(OspfLsa ospfLsa, int lsType, int lsaChecksumPos1,
                                      int lsaChecksumPos2); boolean validateLsaCheckSum(byte[] lsaPacket, int lsaChecksumPos1, int lsaChecksumPos2); boolean validateOspfCheckSum(byte[] ospfPacket, int checksumPos1, int checksumPos2); byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2); byte[] calculateOspfCheckSum(byte[] packet, int checksumPos1, int checksumPos2);  }