@Test public void testIsValidOspfCheckSum() throws Exception { hello = new HelloPacket(); hello.setOspfVer(2); hello.setOspftype(1); hello.setOspfPacLength(172); hello.setRouterId(Ip4Address.valueOf("192.168.170.3")); hello.setAreaId(Ip4Address.valueOf("0.0.0.1")); hello.setChecksum(5537); hello.setAuthType(0); hello.setAuthentication(0); validate = checksumCalculator.isValidOspfCheckSum(hello, ospfChecksumPos1, ospfChecksumPos2); assertThat(validate, is(false)); lsack = new LsAcknowledge(); lsack.setOspfVer(2); lsack.setOspftype(5); lsack.setOspfPacLength(172); lsack.setRouterId(Ip4Address.valueOf("192.168.170.3")); lsack.setAreaId(Ip4Address.valueOf("0.0.0.1")); lsack.setChecksum(37537); lsack.setAuthType(0); lsack.setAuthentication(0); validate = checksumCalculator.isValidOspfCheckSum(lsack, ospfChecksumPos1, ospfChecksumPos2); assertThat(validate, is(true)); message = new LsUpdate(); message.setOspfVer(2); message.setOspftype(5); message.setOspfPacLength(172); message.setRouterId(Ip4Address.valueOf("192.168.170.3")); message.setAreaId(Ip4Address.valueOf("0.0.0.1")); message.setChecksum(37537); message.setAuthType(0); message.setAuthentication(0); validate = checksumCalculator.isValidOspfCheckSum(message, ospfChecksumPos1, ospfChecksumPos2); assertThat(validate, is(true)); message1 = new DdPacket(); message1.setOspfVer(2); message1.setOspftype(5); message1.setOspfPacLength(172); message1.setRouterId(Ip4Address.valueOf("192.168.170.3")); message1.setAreaId(Ip4Address.valueOf("0.0.0.1")); message1.setChecksum(37537); message1.setAuthType(0); message1.setAuthentication(0); validate = checksumCalculator.isValidOspfCheckSum(message1, ospfChecksumPos1, ospfChecksumPos2); assertThat(validate, is(true)); message2 = new LsRequest(); message2.setOspfVer(2); message2.setOspftype(5); message2.setOspfPacLength(172); message2.setRouterId(Ip4Address.valueOf("192.168.170.3")); message2.setAreaId(Ip4Address.valueOf("0.0.0.1")); message2.setChecksum(37537); message2.setAuthType(0); message2.setAuthentication(0); validate = checksumCalculator.isValidOspfCheckSum(message2, ospfChecksumPos1, ospfChecksumPos2); assertThat(validate, is(true)); }
public boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2) { switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: ospfMessage = (HelloPacket) ospfMessage; break; case OspfParameters.DD: ospfMessage = (DdPacket) ospfMessage; break; case OspfParameters.LSREQUEST: ospfMessage = (LsRequest) ospfMessage; break; case OspfParameters.LSUPDATE: ospfMessage = (LsUpdate) ospfMessage; break; case OspfParameters.LSACK: ospfMessage = (LsAcknowledge) ospfMessage; break; default: break; } byte[] messageAsBytes = ospfMessage.asBytes(); return validateOspfCheckSum(messageAsBytes, checksumPos1, checksumPos2); }
ChecksumCalculator { public boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2) { switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: ospfMessage = (HelloPacket) ospfMessage; break; case OspfParameters.DD: ospfMessage = (DdPacket) ospfMessage; break; case OspfParameters.LSREQUEST: ospfMessage = (LsRequest) ospfMessage; break; case OspfParameters.LSUPDATE: ospfMessage = (LsUpdate) ospfMessage; break; case OspfParameters.LSACK: ospfMessage = (LsAcknowledge) ospfMessage; break; default: break; } byte[] messageAsBytes = ospfMessage.asBytes(); return validateOspfCheckSum(messageAsBytes, checksumPos1, checksumPos2); } }
ChecksumCalculator { public boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2) { switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: ospfMessage = (HelloPacket) ospfMessage; break; case OspfParameters.DD: ospfMessage = (DdPacket) ospfMessage; break; case OspfParameters.LSREQUEST: ospfMessage = (LsRequest) ospfMessage; break; case OspfParameters.LSUPDATE: ospfMessage = (LsUpdate) ospfMessage; break; case OspfParameters.LSACK: ospfMessage = (LsAcknowledge) ospfMessage; break; default: break; } byte[] messageAsBytes = ospfMessage.asBytes(); return validateOspfCheckSum(messageAsBytes, checksumPos1, checksumPos2); }  }
ChecksumCalculator { public boolean isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2) { switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: ospfMessage = (HelloPacket) ospfMessage; break; case OspfParameters.DD: ospfMessage = (DdPacket) ospfMessage; break; case OspfParameters.LSREQUEST: ospfMessage = (LsRequest) ospfMessage; break; case OspfParameters.LSUPDATE: ospfMessage = (LsUpdate) ospfMessage; break; case OspfParameters.LSACK: ospfMessage = (LsAcknowledge) ospfMessage; break; default: break; } byte[] messageAsBytes = ospfMessage.asBytes(); return validateOspfCheckSum(messageAsBytes, checksumPos1, checksumPos2); }  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 isValidOspfCheckSum(OspfMessage ospfMessage, int checksumPos1, int checksumPos2) { switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: ospfMessage = (HelloPacket) ospfMessage; break; case OspfParameters.DD: ospfMessage = (DdPacket) ospfMessage; break; case OspfParameters.LSREQUEST: ospfMessage = (LsRequest) ospfMessage; break; case OspfParameters.LSUPDATE: ospfMessage = (LsUpdate) ospfMessage; break; case OspfParameters.LSACK: ospfMessage = (LsAcknowledge) ospfMessage; break; default: break; } byte[] messageAsBytes = ospfMessage.asBytes(); return validateOspfCheckSum(messageAsBytes, checksumPos1, checksumPos2); }  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);  }