Skip to content

Commit 5309fcc

Browse files
committed
iperf3: Fix server UDP mode.
The main issues were: - incorrect magic response value - should be using sendto instead of send for UDP Signed-off-by: Damien George <[email protected]>
1 parent 2536a3d commit 5309fcc

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

python-ecosys/iperf3/iperf3.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,21 @@ def server_once():
260260
s_data, addr = s_listen.accept()
261261
print("Accepted connection:", addr)
262262
recvn(s_data, COOKIE_SIZE)
263+
udp = False
264+
udp_packet_id = 0
265+
udp_interval = None
266+
udp_last_send = None
263267
elif param.get("udp", False):
264268
# Close TCP connection and open UDP "connection"
265269
s_listen.close()
266270
s_data = socket.socket(ai[0], socket.SOCK_DGRAM)
267271
s_data.bind(ai[-1])
268272
data, addr = s_data.recvfrom(4)
269-
s_data.sendto(b"\x12\x34\x56\x78", addr)
273+
s_data.sendto(struct.pack("<I", 987654321), addr)
274+
udp_interval = 1000000 * 8 * param["len"] // param["bandwidth"]
275+
udp = True
276+
udp_packet_id = 0
277+
udp_last_send = ticks_us() - udp_interval
270278
else:
271279
assert False
272280

@@ -296,16 +304,21 @@ def server_once():
296304
if cmd == TEST_END:
297305
running = False
298306
elif pollable_is_sock(pollable, s_data):
299-
if reverse:
300-
n = s_data.send(data_buf)
301-
stats.add_bytes(n)
302-
else:
303-
recvninto(s_data, data_buf)
304-
stats.add_bytes(len(data_buf))
307+
udp_last_send, udp_packet_id = _transfer(
308+
udp,
309+
not reverse,
310+
addr,
311+
s_data,
312+
data_buf,
313+
udp_last_send,
314+
udp_packet_id,
315+
udp_interval,
316+
stats,
317+
)
305318
stats.update()
306319

307320
# Need to continue writing so other side doesn't get blocked waiting for data
308-
if reverse:
321+
if reverse and not udp:
309322
while True:
310323
for pollable in poll.poll(0):
311324
if pollable_is_sock(pollable, s_data):

python-ecosys/iperf3/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.1.4", pypi="iperf3", pypi_publish="uiperf3")
1+
metadata(version="0.1.5", pypi="iperf3", pypi_publish="uiperf3")
22

33
module("iperf3.py")

0 commit comments

Comments
 (0)