X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2FICMP.java;h=987394402d7157f44a011c3d16ab77308855d8a6;hp=b2a1cfe8c2824b8bfab8a4b737d949e9d67df446;hb=0a68f99edafff87254cd2ea0e758ce9fdbc6c61f;hpb=67a8679ab2eb3ad8d7914756e844243eac3cbd32 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 b2a1cfe8c2..987394402d 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 @@ -1,6 +1,6 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -79,6 +79,15 @@ public class ICMP extends Packet { return this; } + /** + * Returns the type field of the current ICMP packet + * + * @return The type code of the current ICMP packet + */ + public byte getType() { + return BitBufferHelper.getByte(fieldValues.get(TYPE)); + } + /** * Sets the ICMP code (type subtype) for the current ICMP object instance * @@ -92,6 +101,15 @@ public class ICMP extends Packet { return this; } + /** + * Gets the ICMP code (type subtype) for the current ICMP object instance + * + * @return The ICMP message type subtype + */ + public byte getCode() { + return BitBufferHelper.getByte(fieldValues.get(CODE)); + } + /** * Sets the ICMP checksum for the current ICMP object instance * @param short - checksum @@ -104,7 +122,7 @@ public class ICMP extends Packet { } /** - * Sets the ICMP identifier for the current ICMP object instance + * Sets the ICMP identifier for the current ICMP object instance * @param short - identifier * @return ICMP */ @@ -114,6 +132,16 @@ public class ICMP extends Packet { return this; } + /** + * Gets the ICMP identifier of the current ICMP object instance + * + * @return short - identifier + */ + + public short getIdentifier() { + return BitBufferHelper.getShort(fieldValues.get(IDENTIFIER)); + } + /** * Sets the ICMP sequence number for the current ICMP object instance * @param short - seqNumber @@ -125,6 +153,16 @@ public class ICMP extends Packet { return this; } + /** + * Gets the ICMP sequence number of the current ICMP object instance + * + * @return short - seqNumber + */ + + public short getSequenceNumber() { + return BitBufferHelper.getShort(fieldValues.get(SEQNUMBER)); + } + /** * Gets the header size in bits * @return The ICMP header size in bits @@ -152,8 +190,9 @@ public class ICMP extends Packet { end += rawPayload.length; } int checksumStartByte = start + getfieldOffset(CHECKSUM) / NetUtils.NumBitsInAByte; + int even = end & ~1; - for (int i = start; i <= (end - 1); i = i + 2) { + for (int i = start; i < even; i = i + 2) { // Skip, if the current bytes are checkSum bytes if (i == checksumStartByte) { continue; @@ -161,7 +200,13 @@ public class ICMP extends Packet { wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF); sum = sum + wordData; } - carry = (sum >> 16) & 0xFF; + if (even < end) { + // Add the last octet with zero padding. + wordData = (data[even] << 8) & 0xFF00; + sum = sum + wordData; + } + + carry = sum >>> 16; finalSum = (sum & 0xFFFF) + carry; return (short) ~((short) finalSum & 0xFFFF); }