@Test public void testCalculateLsaChecksum() throws Exception { result = checksumCalculator.calculateLsaChecksum(rlsa, lsaChecksumPos1, lsaChecksumPos2); assertThat(result, is(notNullValue())); }
public byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lsaBytes, lsaBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lsaChecksumPos1] = 0; tempLsaByte[lsaChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lsaBytes != null) { for (int i = 2; i < tempLsaByte.length; i++) { checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF); checksumOut[1] = checksumOut[1] + checksumOut[0]; } checksumOut[0] = checksumOut[0] % 255; checksumOut[1] = checksumOut[1] % 255; } int byte1 = (int) ((tempLsaByte.length - lsaChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255; if (byte1 <= 0) { byte1 += 255; } int byte2 = 510 - checksumOut[0] - byte1; if (byte2 > 255) { byte2 -= 255; } byteCheckSum[0] = (byte) byte1; byteCheckSum[1] = (byte) byte2; return byteCheckSum; }
ChecksumCalculator { public byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lsaBytes, lsaBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lsaChecksumPos1] = 0; tempLsaByte[lsaChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lsaBytes != null) { for (int i = 2; i < tempLsaByte.length; i++) { checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF); checksumOut[1] = checksumOut[1] + checksumOut[0]; } checksumOut[0] = checksumOut[0] % 255; checksumOut[1] = checksumOut[1] % 255; } int byte1 = (int) ((tempLsaByte.length - lsaChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255; if (byte1 <= 0) { byte1 += 255; } int byte2 = 510 - checksumOut[0] - byte1; if (byte2 > 255) { byte2 -= 255; } byteCheckSum[0] = (byte) byte1; byteCheckSum[1] = (byte) byte2; return byteCheckSum; } }
ChecksumCalculator { public byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lsaBytes, lsaBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lsaChecksumPos1] = 0; tempLsaByte[lsaChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lsaBytes != null) { for (int i = 2; i < tempLsaByte.length; i++) { checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF); checksumOut[1] = checksumOut[1] + checksumOut[0]; } checksumOut[0] = checksumOut[0] % 255; checksumOut[1] = checksumOut[1] % 255; } int byte1 = (int) ((tempLsaByte.length - lsaChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255; if (byte1 <= 0) { byte1 += 255; } int byte2 = 510 - checksumOut[0] - byte1; if (byte2 > 255) { byte2 -= 255; } byteCheckSum[0] = (byte) byte1; byteCheckSum[1] = (byte) byte2; return byteCheckSum; }  }
ChecksumCalculator { public byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lsaBytes, lsaBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lsaChecksumPos1] = 0; tempLsaByte[lsaChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lsaBytes != null) { for (int i = 2; i < tempLsaByte.length; i++) { checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF); checksumOut[1] = checksumOut[1] + checksumOut[0]; } checksumOut[0] = checksumOut[0] % 255; checksumOut[1] = checksumOut[1] % 255; } int byte1 = (int) ((tempLsaByte.length - lsaChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255; if (byte1 <= 0) { byte1 += 255; } int byte2 = 510 - checksumOut[0] - byte1; if (byte2 > 255) { byte2 -= 255; } byteCheckSum[0] = (byte) byte1; byteCheckSum[1] = (byte) byte2; return byteCheckSum; }  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 byte[] calculateLsaChecksum(byte[] lsaBytes, int lsaChecksumPos1, int lsaChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lsaBytes, lsaBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lsaChecksumPos1] = 0; tempLsaByte[lsaChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lsaBytes != null) { for (int i = 2; i < tempLsaByte.length; i++) { checksumOut[0] = checksumOut[0] + ((int) tempLsaByte[i] & 0xFF); checksumOut[1] = checksumOut[1] + checksumOut[0]; } checksumOut[0] = checksumOut[0] % 255; checksumOut[1] = checksumOut[1] % 255; } int byte1 = (int) ((tempLsaByte.length - lsaChecksumPos1 - 1) * checksumOut[0] - checksumOut[1]) % 255; if (byte1 <= 0) { byte1 += 255; } int byte2 = 510 - checksumOut[0] - byte1; if (byte2 > 255) { byte2 -= 255; } byteCheckSum[0] = (byte) byte1; byteCheckSum[1] = (byte) byte2; return byteCheckSum; }  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);  }