X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2FICMP.java;h=5075e58281132a4404ab8473be01e05ea5305115;hb=31045ff2b7b0106f7e7ef7198bed882131127f81;hp=0429c0dd279e1231ace4a0bfd7c6b880163101ba;hpb=e2f7aaa41e482815ca1d4495eb85c8653cd903ab;p=controller.git diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java index 0429c0dd27..5075e58281 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java @@ -68,7 +68,7 @@ public class ICMP extends Packet { /** * Sets the type for the current ICMP message - * + * * @param type * The ICMP message type * @return This ICMP object @@ -81,7 +81,7 @@ public class ICMP extends Packet { /** * Sets the ICMP code (type subtype) for the current ICMP object instance - * + * * @param code * The ICMP message type subtype * @return This ICMP object @@ -136,7 +136,7 @@ public class ICMP extends Packet { /** * Computes the ICMP checksum on the serialized ICMP message - * + * * @param serialized * The data stream * @param start @@ -146,6 +146,7 @@ public class ICMP extends Packet { */ short computeChecksum(byte[] data, int start) { int sum = 0, carry = 0, finalSum = 0; + int wordData; int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte + rawPayload.length; int checksumStartByte = start + getfieldOffset(CHECKSUM) @@ -156,12 +157,8 @@ public class ICMP extends Packet { if (i == checksumStartByte) { continue; } - StringBuffer sbuffer = new StringBuffer(); - sbuffer.append(String.format("%02X", data[i])); - if (i < (data.length - 1)) { - sbuffer.append(String.format("%02X", data[i + 1])); - } - sum += Integer.valueOf(sbuffer.toString(), 16); + wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF); + sum = sum + wordData; } carry = (sum >> 16) & 0xFF; finalSum = (sum & 0xFFFF) + carry;