aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--resources/libraries/python/PacketVerifier.py24
-rwxr-xr-xresources/traffic_scripts/icmpv6_echo.py5
-rwxr-xr-xresources/traffic_scripts/icmpv6_echo_req_resp.py7
-rwxr-xr-xresources/traffic_scripts/ipv4_sweep_ping.py4
-rwxr-xr-xresources/traffic_scripts/ipv6_ns.py5
-rwxr-xr-xresources/traffic_scripts/ipv6_sweep_ping.py5
6 files changed, 38 insertions, 12 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
diff --git a/resources/traffic_scripts/icmpv6_echo.py b/resources/traffic_scripts/icmpv6_echo.py
index 09198abe00..4bf573a1f1 100755
--- a/resources/traffic_scripts/icmpv6_echo.py
+++ b/resources/traffic_scripts/icmpv6_echo.py
@@ -18,7 +18,8 @@
import sys
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
-from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
+from resources.libraries.python.PacketVerifier import RxQueue, TxQueue,\
+ checksum_equal
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
from scapy.layers.inet6 import IPv6, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr
from scapy.layers.inet6 import ICMPv6EchoRequest, ICMPv6EchoReply
@@ -83,7 +84,7 @@ def main():
cksum = icmpv6.cksum
del icmpv6.cksum
tmp = ICMPv6EchoReply(str(icmpv6))
- if tmp.cksum != cksum:
+ if not checksum_equal(tmp.cksum, cksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))
diff --git a/resources/traffic_scripts/icmpv6_echo_req_resp.py b/resources/traffic_scripts/icmpv6_echo_req_resp.py
index 582114cb28..c2cc4d20a0 100755
--- a/resources/traffic_scripts/icmpv6_echo_req_resp.py
+++ b/resources/traffic_scripts/icmpv6_echo_req_resp.py
@@ -19,7 +19,8 @@
import sys
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
-from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
+from resources.libraries.python.PacketVerifier import RxQueue, TxQueue,\
+ checksum_equal
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
from scapy.layers.inet6 import IPv6, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr
from scapy.layers.inet6 import ICMPv6EchoRequest, ICMPv6EchoReply
@@ -104,7 +105,7 @@ def main():
cksum = icmpv6.cksum
del icmpv6.cksum
tmp = ICMPv6EchoRequest(str(icmpv6))
- if tmp.cksum != cksum:
+ if not checksum_equal(tmp.cksum, cksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))
@@ -149,7 +150,7 @@ def main():
cksum = icmpv6.cksum
del icmpv6.cksum
tmp = ICMPv6EchoReply(str(icmpv6))
- if tmp.cksum != cksum:
+ if not checksum_equal(tmp.cksum, cksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))
diff --git a/resources/traffic_scripts/ipv4_sweep_ping.py b/resources/traffic_scripts/ipv4_sweep_ping.py
index f7ce5cd943..cd332d0391 100755
--- a/resources/traffic_scripts/ipv4_sweep_ping.py
+++ b/resources/traffic_scripts/ipv4_sweep_ping.py
@@ -20,7 +20,7 @@ import logging
import os
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from resources.libraries.python.PacketVerifier import RxQueue, TxQueue,\
- auto_pad, create_gratuitous_arp_request
+ auto_pad, create_gratuitous_arp_request, checksum_equal
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
from scapy.layers.inet import IP, ICMP
from scapy.all import Ether, Raw
@@ -90,7 +90,7 @@ def main():
chksum = icmpv4.chksum
del icmpv4.chksum
tmp = ICMP(str(icmpv4))
- if tmp.chksum != chksum:
+ if not checksum_equal(tmp.chksum, chksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(chksum, tmp.chksum))
diff --git a/resources/traffic_scripts/ipv6_ns.py b/resources/traffic_scripts/ipv6_ns.py
index cfdca41ec9..70c6ab445a 100755
--- a/resources/traffic_scripts/ipv6_ns.py
+++ b/resources/traffic_scripts/ipv6_ns.py
@@ -18,7 +18,8 @@
import sys
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
-from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
+from resources.libraries.python.PacketVerifier import RxQueue, TxQueue,\
+ checksum_equal
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
from scapy.layers.inet6 import IPv6, ICMPv6ND_NA, ICMPv6ND_NS
from scapy.layers.inet6 import ICMPv6NDOptDstLLAddr, ICMPv6NDOptSrcLLAddr
@@ -86,7 +87,7 @@ def main():
cksum = icmpv6_na.cksum
del icmpv6_na.cksum
tmp = ICMPv6ND_NA(str(icmpv6_na))
- if tmp.cksum != cksum:
+ if not checksum_equal(tmp.cksum, cksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))
diff --git a/resources/traffic_scripts/ipv6_sweep_ping.py b/resources/traffic_scripts/ipv6_sweep_ping.py
index cf7dc9e6bc..da14c5d8ad 100755
--- a/resources/traffic_scripts/ipv6_sweep_ping.py
+++ b/resources/traffic_scripts/ipv6_sweep_ping.py
@@ -19,7 +19,8 @@ import sys
import logging
import os
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
-from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
+from resources.libraries.python.PacketVerifier import RxQueue, TxQueue,\
+ checksum_equal
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
from scapy.layers.inet6 import IPv6, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr
from scapy.layers.inet6 import ICMPv6EchoRequest, ICMPv6EchoReply
@@ -94,7 +95,7 @@ def main():
cksum = icmpv6.cksum
del icmpv6.cksum
tmp = ICMPv6EchoReply(str(icmpv6))
- if tmp.cksum != cksum:
+ if not checksum_equal(tmp.cksum, cksum):
raise RuntimeError(
'Invalid checksum {0} should be {1}'.format(cksum, tmp.cksum))