aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorJuraj Sloboda <jsloboda@cisco.com>2016-02-25 16:03:51 +0100
committerGerrit Code Review <gerrit@fd.io>2016-02-27 09:07:56 +0000
commitbc4d98a34af3f26a1c9264758186189f15513a7e (patch)
tree40be5b38e26dc98eb06fef41eced0b07a9f74251 /resources/libraries/python
parent994580369f92db56c79bab13c75180c9f38b9187 (diff)
Fix checksum comparison in traffic scripts
Change-Id: Ibeff7c790ed4aba8b3a0534681912d0d5b826dbb Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/PacketVerifier.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/resources/libraries/python/PacketVerifier.py b/resources/libraries/python/PacketVerifier.py
index 9af14e3dce..45fab6a7c6 100644
--- a/resources/libraries/python/PacketVerifier.py
+++ b/resources/libraries/python/PacketVerifier.py
@@ -73,7 +73,7 @@ from scapy.all import Ether, ARP, Packet
from scapy.layers.inet6 import IPv6
__all__ = ['RxQueue', 'TxQueue', 'Interface', 'create_gratuitous_arp_request',
- 'auto_pad']
+ 'auto_pad', 'checksum_equal']
# TODO: http://stackoverflow.com/questions/320232/ensuring-subprocesses-are-dead-on-exiting-python-program
@@ -305,3 +305,25 @@ def auto_pad(packet):
padded += ('\0' * (60 - len(padded)))
return padded
+
+def checksum_equal(chksum1, chksum2):
+ """Compares two checksums in one's complement notation.
+
+ Checksums to be compared are calculated as 16 bit one's complement of the
+ one's complement sum of 16 bit words of some buffer.
+ In one's complement notation 0x0000 (positive zero) and 0xFFFF
+ (negative zero) are equivalent.
+
+ :param chksum1: First checksum.
+ :param chksum2: Second checksum.
+ :type chksum1: uint16
+ :type chksum2: uint16
+
+ :return: True if checksums are equivalent, False otherwise.
+ :rtype: boolean
+ """
+ if chksum1 == 0xFFFF:
+ chksum1 = 0
+ if chksum2 == 0xFFFF:
+ chksum2 = 0
+ return chksum1 == chksum2