Skip to content

Commit 2eb5ebf

Browse files
committed
code cleanup
1 parent 36a2e2d commit 2eb5ebf

File tree

5 files changed

+1251
-17
lines changed

5 files changed

+1251
-17
lines changed

pytcp/tests/integration/test__packet_handler__ip4__tx.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
# Source IP : 10.0.1.7
8484
# Destination IP : 10.0.1.91
8585
#
86-
# Summary: Minimal IPv4 header-only datagram sent to host A on the local LAN.
86+
# Summary: Minimal IPv4 header-only datagram sent by the stack host
87+
# to host A on the local LAN.
8788
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
8889
b"\x00\x14\x00\x00\x00\x00\x40\xff\x63\x8a\x0a\x00\x01\x07\x0a\x00"
8990
b"\x01\x5b"
@@ -138,8 +139,8 @@
138139
# Source IP : 10.0.1.7 (multicast replaced)
139140
# Destination IP : 10.0.1.91
140141
#
141-
# Summary: Multicast source was rewritten to the stack address before emitting the
142-
# minimal IPv4 datagram toward host A.
142+
# Summary: Multicast source rewritten to 10.0.1.7 before unicast delivery
143+
# of the minimal IPv4 frame to host A.
143144
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
144145
b"\x00\x14\x00\x00\x00\x00\x40\xff\x63\x8a\x0a\x00\x01\x07\x0a\x00"
145146
b"\x01\x5b"
@@ -195,8 +196,8 @@
195196
# Source IP : 10.0.1.7 (broadcast replaced)
196197
# Destination IP : 10.0.1.91
197198
#
198-
# Summary: Limited-broadcast source harmonised to the stack address before sending the
199-
# minimal IPv4 frame toward host A.
199+
# Summary: Limited broadcast source normalised to 10.0.1.7 before sending
200+
# the header-only IPv4 packet toward host A.
200201
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
201202
b"\x00\x14\x00\x00\x00\x00\x40\xff\x63\x8a\x0a\x00\x01\x07\x0a\x00"
202203
b"\x01\x5b"
@@ -252,8 +253,8 @@
252253
# Source IP : 10.0.1.7 (network broadcast replaced)
253254
# Destination IP : 10.0.1.91
254255
#
255-
# Summary: Network-broadcast source corrected to the stack address before emitting the
256-
# IPv4 header-only packet to host A.
256+
# Summary: Network broadcast source converted to the stack host prior to
257+
# emitting the minimal IPv4 datagram to host A.
257258
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
258259
b"\x00\x14\x00\x00\x00\x00\x40\xff\x63\x8a\x0a\x00\x01\x07\x0a\x00"
259260
b"\x01\x5b"
@@ -295,8 +296,8 @@
295296
# Source IP : 10.0.1.7 (unspecified replaced)
296297
# Destination IP : 10.0.1.91
297298
#
298-
# Summary: Unspecified source address normalised to the stack host before sending the
299-
# IPv4 header-only packet toward host A.
299+
# Summary: Unspecified source field populated with 10.0.1.7 before
300+
# transmitting the minimal IPv4 frame to host A.
300301
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
301302
b"\x00\x14\x00\x00\x00\x00\x40\xff\x63\x8a\x0a\x00\x01\x07\x0a\x00"
302303
b"\x01\x5b"
@@ -338,8 +339,8 @@
338339
# Source IP : 10.0.1.7 (unspecified replaced)
339340
# Destination IP : 10.0.2.50
340341
#
341-
# Summary: Minimal IPv4 datagram forwarded via the gateway MAC after filling in the
342-
# unspecified source address.
342+
# Summary: Header-only IPv4 datagram forwarded toward host C via the
343+
# gateway after supplying 10.0.1.7 as the source address.
343344
b"\x02\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
344345
b"\x00\x14\x00\x00\x00\x00\x40\xff\x62\xb3\x0a\x00\x01\x07\x0a\x00"
345346
b"\x02\x32"
@@ -408,7 +409,8 @@
408409
# Source IP : 10.0.1.7
409410
# Destination IP : 10.0.1.91
410411
#
411-
# Payload: RawAssembler bytes 0–1479 (reserved protocol, no UDP header).
412+
# Summary: Fragment 1 (bytes 0–1479) begins the reserved-protocol payload
413+
# delivery to host A with MF set.
412414
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
413415
b"\x05\xdc\x00\x01\x20\x00\x40\xff\x3d\xc1\x0a\x00\x01\x07\x0a\x00"
414416
b"\x01\x5b\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43"
@@ -520,7 +522,8 @@
520522
# Source IP : 10.0.1.7
521523
# Destination IP : 10.0.1.91
522524
#
523-
# Payload: RawAssembler bytes 1480–2959.
525+
# Summary: Fragment 2 (bytes 1480–2959) continues the reserved-protocol
526+
# payload stream toward host A with MF still set.
524527
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
525528
b"\x05\xdc\x00\x01\x20\xb9\x40\xff\x3d\x08\x0a\x00\x01\x07\x0a\x00"
526529
b"\x01\x5b\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44"
@@ -632,7 +635,8 @@
632635
# Source IP : 10.0.1.7
633636
# Destination IP : 10.0.1.91
634637
#
635-
# Payload: RawAssembler bytes 2960–4439.
638+
# Summary: Fragment 3 (bytes 2960–4439) keeps MF asserted while extending
639+
# the payload stream destined for host A.
636640
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
637641
b"\x05\xdc\x00\x01\x21\x72\x40\xff\x3c\x4f\x0a\x00\x01\x07\x0a\x00"
638642
b"\x01\x5b\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45"
@@ -744,7 +748,8 @@
744748
# Source IP : 10.0.1.7
745749
# Destination IP : 10.0.1.91
746750
#
747-
# Payload: RawAssembler bytes 4440–5919.
751+
# Summary: Fragment 4 (bytes 4440–5919) transports the penultimate slice
752+
# of payload toward host A with MF still set.
748753
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
749754
b"\x05\xdc\x00\x01\x22\x2b\x40\xff\x3b\x96\x0a\x00\x01\x07\x0a\x00"
750755
b"\x01\x5b\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46"
@@ -856,7 +861,8 @@
856861
# Source IP : 10.0.1.7
857862
# Destination IP : 10.0.1.91
858863
#
859-
# Payload: RawAssembler bytes 5920–6799 completing the datagram.
864+
# Summary: Fragment 5 (bytes 5920–6799) clears MF and delivers the final
865+
# portion required for host A to reassemble the payload.
860866
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
861867
b"\x03\x84\x00\x01\x02\xe4\x40\xff\x5d\x35\x0a\x00\x01\x07\x0a\x00"
862868
b"\x01\x5b\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30"

pytcp/tests/integration/test__packet_handler__ip6__tx.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@
6363
"ip6__dst": HOST_A__IP6_ADDRESS,
6464
},
6565
"_expected__frames_tx": [
66+
# Ethernet II
67+
# Destination MAC : 02:00:00:00:00:91
68+
# Source MAC : 02:00:00:00:00:07
69+
# Ethertype : 0x86dd (IPv6)
70+
# Frame length : 54 bytes
71+
#
72+
# IPv6
73+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
74+
# Payload Length : 0x0000 (0 bytes)
75+
# Next Header : 255 (Reserved)
76+
# Hop Limit : 64
77+
# Source IP : 2001:db8:0:1::7
78+
# Destination IP : 2001:db8:0:1::91
79+
#
80+
# Summary: Minimal IPv6 header-only datagram sent by the stack host to
81+
# host A on the local LAN.
6682
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
6783
b"\x00\x00\x00\x00\xff\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
6884
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -100,6 +116,22 @@
100116
"ip6__dst": HOST_A__IP6_ADDRESS,
101117
},
102118
"_expected__frames_tx": [
119+
# Ethernet II
120+
# Destination MAC : 02:00:00:00:00:91
121+
# Source MAC : 02:00:00:00:00:07 (multicast source replaced)
122+
# Ethertype : 0x86dd (IPv6)
123+
# Frame length : 54 bytes
124+
#
125+
# IPv6
126+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
127+
# Payload Length : 0x0000 (0 bytes)
128+
# Next Header : 255 (Reserved)
129+
# Hop Limit : 64
130+
# Source IP : 2001:db8:0:1::7 (multicast replaced)
131+
# Destination IP : 2001:db8:0:1::91
132+
#
133+
# Summary: Multicast source address normalised to the stack host before
134+
# emitting the minimal IPv6 datagram toward host A.
103135
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
104136
b"\x00\x00\x00\x00\xff\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
105137
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -138,6 +170,22 @@
138170
"ip6__dst": HOST_A__IP6_ADDRESS,
139171
},
140172
"_expected__frames_tx": [
173+
# Ethernet II
174+
# Destination MAC : 02:00:00:00:00:91
175+
# Source MAC : 02:00:00:00:00:07 (unspecified source filled)
176+
# Ethertype : 0x86dd (IPv6)
177+
# Frame length : 54 bytes
178+
#
179+
# IPv6
180+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
181+
# Payload Length : 0x0000 (0 bytes)
182+
# Next Header : 255 (Reserved)
183+
# Hop Limit : 64
184+
# Source IP : 2001:db8:0:1::7 (unspecified replaced)
185+
# Destination IP : 2001:db8:0:1::91
186+
#
187+
# Summary: Unspecified source address substituted with the stack host before
188+
# dispatching the header-only IPv6 frame to host A.
141189
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
142190
b"\x00\x00\x00\x00\xff\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
143191
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -162,6 +210,22 @@
162210
"ip6__dst": HOST_C__IP6_ADDRESS,
163211
},
164212
"_expected__frames_tx": [
213+
# Ethernet II
214+
# Destination MAC : 02:00:00:00:00:01 (gateway)
215+
# Source MAC : 02:00:00:00:00:07 (unspecified source filled)
216+
# Ethertype : 0x86dd (IPv6)
217+
# Frame length : 54 bytes
218+
#
219+
# IPv6
220+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
221+
# Payload Length : 0x0000 (0 bytes)
222+
# Next Header : 255 (Reserved)
223+
# Hop Limit : 64
224+
# Source IP : 2001:db8:0:1::7 (unspecified replaced)
225+
# Destination IP : 2001:db8:0:2::50
226+
#
227+
# Summary: Header-only IPv6 datagram forwarded via the gateway MAC toward
228+
# external host 2001:db8:0:2::50.
165229
b"\x02\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
166230
b"\x00\x00\x00\x00\xff\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
167231
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x02\x00\x00"

pytcp/tests/integration/test__packet_handler__ip6_frag__tx.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@
6161
"ip6__payload": RawAssembler(raw__payload=b"01234567890ABCDEF" * 400),
6262
},
6363
"_expected__frames_tx": [
64+
# Ethernet II
65+
# Destination MAC : 02:00:00:00:00:91
66+
# Source MAC : 02:00:00:00:00:07
67+
# Ethertype : 0x86dd (IPv6)
68+
# Frame length : 1510 bytes
69+
#
70+
# IPv6
71+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
72+
# Payload Length : 0x05b0 (1456 bytes)
73+
# Next Header : 44 (Fragment)
74+
# Hop Limit : 64
75+
# Source IP : 2001:db8:0:1::7
76+
# Destination IP : 2001:db8:0:1::91
77+
#
78+
# IPv6 Fragment Header (fragment F1)
79+
# Next Header : 255 (No Next Header)
80+
# Fragment Offset: 0
81+
# M Flag : 1 (more fragments follow)
82+
# Identification : 0x00000001
83+
#
84+
# Summary: First fragment launched by the stack host, covering payload bytes
85+
# 0–1447 as it begins delivery of the 6.8 KB raw payload to host A.
6486
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
6587
b"\x00\x00\x05\xb0\x2c\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
6688
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -156,6 +178,28 @@
156178
b"\x46\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44"
157179
b"\x45\x46\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43"
158180
b"\x44\x45\x46\x30\x31\x32",
181+
# Ethernet II
182+
# Destination MAC : 02:00:00:00:00:91
183+
# Source MAC : 02:00:00:00:00:07
184+
# Ethertype : 0x86dd (IPv6)
185+
# Frame length : 1510 bytes
186+
#
187+
# IPv6
188+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
189+
# Payload Length : 0x05b0 (1456 bytes)
190+
# Next Header : 44 (Fragment)
191+
# Hop Limit : 64
192+
# Source IP : 2001:db8:0:1::7
193+
# Destination IP : 2001:db8:0:1::91
194+
#
195+
# IPv6 Fragment Header (fragment F2)
196+
# Next Header : 255 (No Next Header)
197+
# Fragment Offset: 181
198+
# M Flag : 1 (more fragments follow)
199+
# Identification : 0x00000001
200+
#
201+
# Summary: Second fragment carries payload bytes 1448–2895 of the raw data
202+
# stream toward host A, keeping the fragmented flow active.
159203
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
160204
b"\x00\x00\x05\xb0\x2c\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
161205
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -251,6 +295,28 @@
251295
b"\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30"
252296
b"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46"
253297
b"\x30\x31\x32\x33\x34\x35",
298+
# Ethernet II
299+
# Destination MAC : 02:00:00:00:00:91
300+
# Source MAC : 02:00:00:00:00:07
301+
# Ethertype : 0x86dd (IPv6)
302+
# Frame length : 1510 bytes
303+
#
304+
# IPv6
305+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
306+
# Payload Length : 0x05b0 (1456 bytes)
307+
# Next Header : 44 (Fragment)
308+
# Hop Limit : 64
309+
# Source IP : 2001:db8:0:1::7
310+
# Destination IP : 2001:db8:0:1::91
311+
#
312+
# IPv6 Fragment Header (fragment F3)
313+
# Next Header : 255 (No Next Header)
314+
# Fragment Offset: 362
315+
# M Flag : 1 (more fragments follow)
316+
# Identification : 0x00000001
317+
#
318+
# Summary: Mid-sequence fragment transports payload bytes 2896–4343, extending
319+
# the five-frame IPv6 transmission toward host A.
254320
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
255321
b"\x00\x00\x05\xb0\x2c\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
256322
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -346,6 +412,28 @@
346412
b"\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30\x31\x32\x33"
347413
b"\x34\x35\x36\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30\x31\x32"
348414
b"\x33\x34\x35\x36\x37\x38",
415+
# Ethernet II
416+
# Destination MAC : 02:00:00:00:00:91
417+
# Source MAC : 02:00:00:00:00:07
418+
# Ethertype : 0x86dd (IPv6)
419+
# Frame length : 1510 bytes
420+
#
421+
# IPv6
422+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
423+
# Payload Length : 0x05b0 (1456 bytes)
424+
# Next Header : 44 (Fragment)
425+
# Hop Limit : 64
426+
# Source IP : 2001:db8:0:1::7
427+
# Destination IP : 2001:db8:0:1::91
428+
#
429+
# IPv6 Fragment Header (fragment F4)
430+
# Next Header : 255 (No Next Header)
431+
# Fragment Offset: 543
432+
# M Flag : 1 (more fragments follow)
433+
# Identification : 0x00000001
434+
#
435+
# Summary: Penultimate fragment keeps MF set while moving payload bytes
436+
# 4344–5791 of the raw stream toward host A.
349437
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
350438
b"\x00\x00\x05\xb0\x2c\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
351439
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -441,6 +529,28 @@
441529
b"\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30\x31\x32\x33\x34\x35\x36"
442530
b"\x37\x38\x39\x30\x41\x42\x43\x44\x45\x46\x30\x31\x32\x33\x34\x35"
443531
b"\x36\x37\x38\x39\x30\x41",
532+
# Ethernet II
533+
# Destination MAC : 02:00:00:00:00:91
534+
# Source MAC : 02:00:00:00:00:07
535+
# Ethertype : 0x86dd (IPv6)
536+
# Frame length : 1070 bytes
537+
#
538+
# IPv6
539+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
540+
# Payload Length : 0x03f8 (1016 bytes)
541+
# Next Header : 44 (Fragment)
542+
# Hop Limit : 64
543+
# Source IP : 2001:db8:0:1::7
544+
# Destination IP : 2001:db8:0:1::91
545+
#
546+
# IPv6 Fragment Header (fragment F5)
547+
# Next Header : 255 (No Next Header)
548+
# Fragment Offset: 724
549+
# M Flag : 0 (no more fragments)
550+
# Identification : 0x00000001
551+
#
552+
# Summary: Final fragment clears MF and delivers payload bytes 5792–6799 so
553+
# host A can complete reassembly of the raw payload.
444554
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
445555
b"\x00\x00\x03\xf8\x2c\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
446556
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"

0 commit comments

Comments
 (0)