Skip to content

Commit 7efb55b

Browse files
committed
code cleanup
1 parent 2eb5ebf commit 7efb55b

File tree

2 files changed

+288
-0
lines changed

2 files changed

+288
-0
lines changed

pytcp/tests/integration/test__packet_handler__udp__rx.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,65 @@
4949
{
5050
"_description": "Ethernet/IPv4/UDP to closed port",
5151
"_frames_rx": [
52+
# Ethernet II
53+
# Destination MAC : 02:00:00:00:00:07
54+
# Source MAC : 02:00:00:00:00:91
55+
# Ethertype : 0x0800 (IPv4)
56+
# Frame length : 77 bytes
57+
#
58+
# IPv4
59+
# Version / IHL : 4 / 5
60+
# DSCP / ECN : 0x00
61+
# Total Length : 0x003f (63 bytes)
62+
# Identification : 0x0001
63+
# Flags / Offset : 0x0000
64+
# TTL : 64
65+
# Protocol : 17 (UDP)
66+
# Header Checksum : 0x644c
67+
# Source IP : 10.0.1.91
68+
# Destination IP : 10.0.1.7
69+
#
70+
# UDP
71+
# Source Port : 1000
72+
# Destination Port: 2000
73+
# Length : 0x002b (43 bytes)
74+
# Checksum : 0xa210
75+
# Payload : "Test UDP packet sent to closed port"
76+
#
77+
# Summary: UDP datagram from host A to an unopened port on the stack.
5278
b"\x02\x00\x00\x00\x00\x07\x02\x00\x00\x00\x00\x91\x08\x00\x45\x00"
5379
b"\x00\x3f\x00\x01\x00\x00\x40\x11\x64\x4c\x0a\x00\x01\x5b\x0a\x00"
5480
b"\x01\x07\x03\xe8\x07\xd0\x00\x2b\xa2\x10\x54\x65\x73\x74\x20\x55"
5581
b"\x44\x50\x20\x70\x61\x63\x6b\x65\x74\x20\x73\x65\x6e\x74\x20\x74"
5682
b"\x6f\x20\x63\x6c\x6f\x73\x65\x64\x20\x70\x6f\x72\x74",
5783
],
5884
"_expected__frames_tx": [
85+
# Ethernet II
86+
# Destination MAC : 02:00:00:00:00:91
87+
# Source MAC : 02:00:00:00:00:07
88+
# Ethertype : 0x0800 (IPv4)
89+
# Frame length : 105 bytes
90+
#
91+
# IPv4
92+
# Version / IHL : 4 / 5
93+
# DSCP / ECN : 0x00
94+
# Total Length : 0x005b (91 bytes)
95+
# Identification : 0x0000
96+
# Flags / Offset : 0x0000
97+
# TTL : 64
98+
# Protocol : 1 (ICMP)
99+
# Header Checksum : 0x6441
100+
# Source IP : 10.0.1.7
101+
# Destination IP : 10.0.1.91
102+
#
103+
# ICMPv4
104+
# Type / Code : 3 / 3 (Destination Unreachable - Port Unreachable)
105+
# Checksum : 0x139b
106+
# Unused : 0x00000000
107+
# Quoted IP Header: Original IPv4 header + first 8 bytes of UDP payload
108+
#
109+
# Summary: ICMPv4 Port Unreachable generated in response to the closed-port
110+
# UDP probe.
59111
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
60112
b"\x00\x5b\x00\x00\x00\x00\x40\x01\x64\x41\x0a\x00\x01\x07\x0a\x00"
61113
b"\x01\x5b\x03\x03\x13\x9b\x00\x00\x00\x00\x45\x00\x00\x3f\x00\x01"
@@ -86,6 +138,28 @@
86138
{
87139
"_description": "Ethernet/IPv6/UDP to closed port",
88140
"_frames_rx": [
141+
# Ethernet II
142+
# Destination MAC : 02:00:00:00:00:07
143+
# Source MAC : 02:00:00:00:00:91
144+
# Ethertype : 0x86dd (IPv6)
145+
# Frame length : 97 bytes
146+
#
147+
# IPv6
148+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
149+
# Payload Length : 0x002b (43 bytes)
150+
# Next Header : 17 (UDP)
151+
# Hop Limit : 64
152+
# Source IP : 2001:db8:0:1::91
153+
# Destination IP : 2001:db8:0:1::7
154+
#
155+
# UDP
156+
# Source Port : 1000
157+
# Destination Port: 2000
158+
# Length : 0x002b (43 bytes)
159+
# Checksum : 0x5c66
160+
# Payload : "Test UDP packet sent to closed port"
161+
#
162+
# Summary: IPv6 UDP probe targeting an unopened port.
89163
b"\x02\x00\x00\x00\x00\x07\x02\x00\x00\x00\x00\x91\x86\xdd\x60\x00"
90164
b"\x00\x00\x00\x2b\x11\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
91165
b"\x00\x00\x00\x00\x00\x91\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -95,6 +169,27 @@
95169
b"\x74",
96170
],
97171
"_expected__frames_tx": [
172+
# Ethernet II
173+
# Destination MAC : 02:00:00:00:00:91
174+
# Source MAC : 02:00:00:00:00:07
175+
# Ethertype : 0x86dd (IPv6)
176+
# Frame length : 145 bytes
177+
#
178+
# IPv6
179+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
180+
# Payload Length : 0x005b (91 bytes)
181+
# Next Header : 58 (ICMPv6)
182+
# Hop Limit : 64
183+
# Source IP : 2001:db8:0:1::7
184+
# Destination IP : 2001:db8:0:1::91
185+
#
186+
# ICMPv6
187+
# Type / Code : 1 / 4 (Destination Unreachable - Port Unreachable)
188+
# Checksum : 0x312b
189+
# Assembled Data : Original IPv6 header + first 8 bytes of UDP payload
190+
#
191+
# Summary: ICMPv6 Port Unreachable response quoting the triggering UDP
192+
# packet.
98193
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
99194
b"\x00\x00\x00\x5b\x3a\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
100195
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -128,12 +223,64 @@
128223
{
129224
"_description": "Ethernet/IPv4/UDP Echo",
130225
"_frames_rx": [
226+
# Ethernet II
227+
# Destination MAC : 02:00:00:00:00:07
228+
# Source MAC : 02:00:00:00:00:91
229+
# Ethertype : 0x0800 (IPv4)
230+
# Frame length : 53 bytes
231+
#
232+
# IPv4
233+
# Version / IHL : 4 / 5
234+
# DSCP / ECN : 0x00
235+
# Total Length : 0x0027 (39 bytes)
236+
# Identification : 0x0001
237+
# Flags / Offset : 0x0000
238+
# TTL : 64
239+
# Protocol : 17 (UDP)
240+
# Header Checksum : 0x6464
241+
# Source IP : 10.0.1.91
242+
# Destination IP : 10.0.1.7
243+
#
244+
# UDP
245+
# Source Port : 5527
246+
# Destination Port: 7 (Echo)
247+
# Length : 0x0013 (19 bytes)
248+
# Checksum : 0x813f
249+
# Payload : "Tom Tit Tot"
250+
#
251+
# Summary: UDP echo request arriving from host A.
131252
b"\x02\x00\x00\x00\x00\x07\x02\x00\x00\x00\x00\x91\x08\x00\x45\x00"
132253
b"\x00\x27\x00\x01\x00\x00\x40\x11\x64\x64\x0a\x00\x01\x5b\x0a\x00"
133254
b"\x01\x07\x15\x97\x00\x07\x00\x13\x81\x3f\x54\x6f\x6d\x20\x54\x69"
134255
b"\x74\x20\x54\x6f\x74",
135256
],
136257
"_expected__frames_tx": [
258+
# Ethernet II
259+
# Destination MAC : 02:00:00:00:00:91
260+
# Source MAC : 02:00:00:00:00:07
261+
# Ethertype : 0x0800 (IPv4)
262+
# Frame length : 53 bytes
263+
#
264+
# IPv4
265+
# Version / IHL : 4 / 5
266+
# DSCP / ECN : 0x00
267+
# Total Length : 0x0027 (39 bytes)
268+
# Identification : 0x0000
269+
# Flags / Offset : 0x0000
270+
# TTL : 64
271+
# Protocol : 17 (UDP)
272+
# Header Checksum : 0x6465
273+
# Source IP : 10.0.1.7
274+
# Destination IP : 10.0.1.91
275+
#
276+
# UDP
277+
# Source Port : 7
278+
# Destination Port: 5527
279+
# Length : 0x0013 (19 bytes)
280+
# Checksum : 0x813f
281+
# Payload : "Tom Tit Tot"
282+
#
283+
# Summary: UDP echo reply mirroring the original payload back to host A.
137284
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
138285
b"\x00\x27\x00\x00\x00\x00\x40\x11\x64\x65\x0a\x00\x01\x07\x0a\x00"
139286
b"\x01\x5b\x00\x07\x15\x97\x00\x13\x81\x3f\x54\x6f\x6d\x20\x54\x69"
@@ -161,13 +308,57 @@
161308
{
162309
"_description": "Ethernet/IPv6/UDP Echo",
163310
"_frames_rx": [
311+
# Ethernet II
312+
# Destination MAC : 02:00:00:00:00:07
313+
# Source MAC : 02:00:00:00:00:91
314+
# Ethertype : 0x86dd (IPv6)
315+
# Frame length : 73 bytes
316+
#
317+
# IPv6
318+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
319+
# Payload Length : 0x0013 (19 bytes)
320+
# Next Header : 17 (UDP)
321+
# Hop Limit : 64
322+
# Source IP : 2001:db8:0:1::91
323+
# Destination IP : 2001:db8:0:1::7
324+
#
325+
# UDP
326+
# Source Port : 5527
327+
# Destination Port: 7
328+
# Length : 0x0013 (19 bytes)
329+
# Checksum : 0x3b95
330+
# Payload : "Tom Tit Tot"
331+
#
332+
# Summary: IPv6 UDP echo request from host A.
164333
b"\x02\x00\x00\x00\x00\x07\x02\x00\x00\x00\x00\x91\x86\xdd\x60\x00"
165334
b"\x00\x00\x00\x13\x11\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
166335
b"\x00\x00\x00\x00\x00\x91\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
167336
b"\x00\x00\x00\x00\x00\x07\x15\x97\x00\x07\x00\x13\x3b\x95\x54\x6f"
168337
b"\x6d\x20\x54\x69\x74\x20\x54\x6f\x74",
169338
],
170339
"_expected__frames_tx": [
340+
# Ethernet II
341+
# Destination MAC : 02:00:00:00:00:91
342+
# Source MAC : 02:00:00:00:00:07
343+
# Ethertype : 0x86dd (IPv6)
344+
# Frame length : 73 bytes
345+
#
346+
# IPv6
347+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
348+
# Payload Length : 0x0013 (19 bytes)
349+
# Next Header : 17 (UDP)
350+
# Hop Limit : 64
351+
# Source IP : 2001:db8:0:1::7
352+
# Destination IP : 2001:db8:0:1::91
353+
#
354+
# UDP
355+
# Source Port : 7
356+
# Destination Port: 5527
357+
# Length : 0x0013 (19 bytes)
358+
# Checksum : 0x3b95
359+
# Payload : "Tom Tit Tot"
360+
#
361+
# Summary: IPv6 UDP echo reply returning the payload to host A.
171362
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
172363
b"\x00\x00\x00\x13\x11\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
173364
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"

pytcp/tests/integration/test__packet_handler__udp__tx.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@
6363
"udp__dport": 2000,
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 : 0x0800 (IPv4)
70+
# Frame length : 42 bytes
71+
#
72+
# IPv4
73+
# Version / IHL : 4 / 5
74+
# DSCP / ECN : 0x00
75+
# Total Length : 0x001c (28 bytes)
76+
# Identification : 0x0000
77+
# Flags / Offset : 0x0000
78+
# TTL : 64
79+
# Protocol : 17 (UDP)
80+
# Header Checksum : 0x6470
81+
# Source IP : 10.0.1.7
82+
# Destination IP : 10.0.1.91
83+
#
84+
# UDP
85+
# Source Port : 1000
86+
# Destination Port: 2000
87+
# Length : 0x0008 (8 bytes)
88+
# Checksum : 0xddc4
89+
#
90+
# Summary: Minimal UDP datagram with no payload transmitted from the stack
91+
# host to host A.
6692
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
6793
b"\x00\x1c\x00\x00\x00\x00\x40\x11\x64\x70\x0a\x00\x01\x07\x0a\x00"
6894
b"\x01\x5b\x03\xe8\x07\xd0\x00\x08\xdd\xc4"
@@ -90,6 +116,33 @@
90116
"udp__payload": b"01234567890ABCDEF" * 50,
91117
},
92118
"_expected__frames_tx": [
119+
# Ethernet II
120+
# Destination MAC : 02:00:00:00:00:91
121+
# Source MAC : 02:00:00:00:00:07
122+
# Ethertype : 0x0800 (IPv4)
123+
# Frame length : 892 bytes
124+
#
125+
# IPv4
126+
# Version / IHL : 4 / 5
127+
# DSCP / ECN : 0x00
128+
# Total Length : 0x036e (878 bytes)
129+
# Identification : 0x0000
130+
# Flags / Offset : 0x0000
131+
# TTL : 64
132+
# Protocol : 17 (UDP)
133+
# Header Checksum : 0x611e
134+
# Source IP : 10.0.1.7
135+
# Destination IP : 10.0.1.91
136+
#
137+
# UDP
138+
# Source Port : 1000
139+
# Destination Port: 2000
140+
# Length : 0x035a (858 bytes)
141+
# Checksum : 0xf53e
142+
# Payload : 850 bytes ("01234567890ABCDEF" repeated)
143+
#
144+
# Summary: Large IPv4 UDP payload example, carrying the generated raw data
145+
# towards host A.
93146
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x08\x00\x45\x00"
94147
b"\x03\x6e\x00\x00\x00\x00\x40\x11\x61\x1e\x0a\x00\x01\x07\x0a\x00"
95148
b"\x01\x5b\x03\xe8\x07\xd0\x03\x5a\xf5\x3e\x30\x31\x32\x33\x34\x35"
@@ -169,6 +222,27 @@
169222
"udp__dport": 2000,
170223
},
171224
"_expected__frames_tx": [
225+
# Ethernet II
226+
# Destination MAC : 02:00:00:00:00:91
227+
# Source MAC : 02:00:00:00:00:07
228+
# Ethertype : 0x86dd (IPv6)
229+
# Frame length : 62 bytes
230+
#
231+
# IPv6
232+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
233+
# Payload Length : 0x0008 (8 bytes)
234+
# Next Header : 17 (UDP)
235+
# Hop Limit : 64
236+
# Source IP : 2001:db8:0:1::7
237+
# Destination IP : 2001:db8:0:1::91
238+
#
239+
# UDP
240+
# Source Port : 1000
241+
# Destination Port: 2000
242+
# Length : 0x0008
243+
# Checksum : 0x981a
244+
#
245+
# Summary: Minimal IPv6 UDP datagram with no payload sent to host A.
172246
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
173247
b"\x00\x00\x00\x08\x11\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
174248
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
@@ -197,6 +271,29 @@
197271
"udp__payload": b"01234567890ABCDEF" * 50,
198272
},
199273
"_expected__frames_tx": [
274+
# Ethernet II
275+
# Destination MAC : 02:00:00:00:00:91
276+
# Source MAC : 02:00:00:00:00:07
277+
# Ethertype : 0x86dd (IPv6)
278+
# Frame length : 912 bytes
279+
#
280+
# IPv6
281+
# Version / Traffic Class / Flow Label : 6 / 0x00 / 0x00000
282+
# Payload Length : 0x035a (858 bytes)
283+
# Next Header : 17 (UDP)
284+
# Hop Limit : 64
285+
# Source IP : 2001:db8:0:1::7
286+
# Destination IP : 2001:db8:0:1::91
287+
#
288+
# UDP
289+
# Source Port : 1000
290+
# Destination Port: 2000
291+
# Length : 0x035a (858 bytes)
292+
# Checksum : 0xaf94
293+
# Payload : 850 bytes ("01234567890ABCDEF" repeated)
294+
#
295+
# Summary: IPv6 UDP payload counterpart matching the IPv4 large-payload
296+
# scenario.
200297
b"\x02\x00\x00\x00\x00\x91\x02\x00\x00\x00\x00\x07\x86\xdd\x60\x00"
201298
b"\x00\x00\x03\x5a\x11\x40\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"
202299
b"\x00\x00\x00\x00\x00\x07\x20\x01\x0d\xb8\x00\x00\x00\x01\x00\x00"

0 commit comments

Comments
 (0)