@Test public void testCalculateLspChecksum() throws Exception { result = calculator.calculateLspChecksum(l1Lsp, IsisConstants.CHECKSUMPOSITION, IsisConstants.CHECKSUMPOSITION + 1); assertThat(result[0], is(l1Lsp[IsisConstants.CHECKSUMPOSITION])); assertThat(result[1], is(l1Lsp[IsisConstants.CHECKSUMPOSITION + 1])); }
public byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lspChecksumPos1] = 0; tempLsaByte[lspChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lspBytes != null) { for (int i = 12; 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 - lspChecksumPos1 - 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[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lspChecksumPos1] = 0; tempLsaByte[lspChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lspBytes != null) { for (int i = 12; 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 - lspChecksumPos1 - 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[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lspChecksumPos1] = 0; tempLsaByte[lspChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lspBytes != null) { for (int i = 12; 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 - lspChecksumPos1 - 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[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lspChecksumPos1] = 0; tempLsaByte[lspChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lspBytes != null) { for (int i = 12; 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 - lspChecksumPos1 - 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; }  boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2); byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2); }
ChecksumCalculator { public byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2) { byte[] tempLsaByte = Arrays.copyOf(lspBytes, lspBytes.length); int[] checksumOut = {0, 0}; tempLsaByte[lspChecksumPos1] = 0; tempLsaByte[lspChecksumPos2] = 0; byte[] byteCheckSum = {0, 0}; if (lspBytes != null) { for (int i = 12; 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 - lspChecksumPos1 - 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; }  boolean validateLspCheckSum(byte[] lspPacket, int lspChecksumPos1, int lspChecksumPos2); byte[] calculateLspChecksum(byte[] lspBytes, int lspChecksumPos1, int lspChecksumPos2);  }