Skip to content
Snippets Groups Projects
Commit 46f8eddc authored by Pierre LALET's avatar Pierre LALET
Browse files

Add tests for fragment() / defragment()

As suggested by @guedou, this adds tests for fragment() and
defragment() functions.
parent 10b43d1b
No related branches found
No related tags found
No related merge requests found
...@@ -4435,3 +4435,32 @@ assert pkt.dst == pkt.real_dst ...@@ -4435,3 +4435,32 @@ assert pkt.dst == pkt.real_dst
assert pkt.src == pkt.real_src assert pkt.src == pkt.real_src
assert pkt.tos == 0 assert pkt.tos == 0
assert pkt.function == 0 assert pkt.function == 0
############
############
+ Test fragment() / defragment() functions
= fragment()
payloadlen, fragsize = 100, 8
assert fragsize % 8 == 0
fragcount = (payloadlen / fragsize) + bool(payloadlen % fragsize)
* create the packet
pkt = IP() / ("X" * payloadlen)
* create the fragments
frags = fragment(pkt, fragsize)
* count the fragments
assert len(frags) == fragcount
* each fragment except the last one should have MF set
assert all(p.flags == 1 for p in frags[:-1])
assert frags[-1].flags == 0
* each fragment except the last one should have a payload of fragsize bytes
assert all(len(p.payload) == 8 for p in frags[:-1])
assert len(frags[-1].payload) == ((payloadlen % fragsize) or fragsize)
= defragment()
defrags = defragment(frags)
* we should have one single packet
assert len(defrags) == 1
* which should be the same as pkt reconstructed
assert defrags[0] == IP(str(pkt))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment