DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
wib_packet_sender.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2import socket
3import time
4import math
5import click
6from rich.console import Console
7import fddetdataformats
8
9console = Console()
10
11CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
12@click.command(context_settings=CONTEXT_SETTINGS)
13@click.option('-a','--address', default='127.0.0.1', help='Destination IP address')
14@click.option('-p','--port', default=1234, help='Port number')
15
16
17def cli(address, port):
18 console.log(f"Preparing to send WIB packets to {address}:{port} in a loop.")
19 sock = socket.socket(socket.AF_INET, # Internet
20 socket.SOCK_DGRAM) # UDP
21
22 wf = fddetdataformats.WIBEthFrame()
23 wf.get_daqheader().det_id = 3
24 wf.get_daqheader().stream_id = 0
25 wf.get_daqheader().seq_id = 1
26 wf.get_daqheader().block_length = 0x382
27 wf.get_daqheader().timestamp = 0
28
29 sent_pkts = 0
30 sent_pkts_tot = 0
31 sent_bytes = 0
32 sent_bytes_tot = 0
33 start_time_orig = time.time();
34 start_time = time.time();
35 while True:
36 try:
37 for i in range(0,4):
38 wf.get_daqheader().stream_id = i
39 sock.sendto(wf.get_bytes(), (address, port))
40 sent_pkts +=1
41 sent_pkts_tot +=1
42 sent_bytes += len(wf.get_bytes())
43 sent_bytes_tot += len(wf.get_bytes())
44 if sent_pkts_tot % 100000 == 0:
45 stop_time = time.time()
46 interval = stop_time - start_time
47 console.log(f"Received {sent_pkts} packets: throughput is {sent_bytes*8/(interval*1000000000.):.2f} Gb/s")
48 sent_pkts = 0
49 sent_bytes = 0
50 start_time = stop_time
51
52 wf.get_daqheader().timestamp += (32*64)
53 if wf.get_daqheader().seq_id == 4095:
54 wf.get_daqheader().seq_id = 0
55 else:
56 wf.get_daqheader().seq_id +=1
57
58 except KeyboardInterrupt:
59 break
60 except:
61 continue
62
63 stop_time = time.time();
64 time_seconds = stop_time - start_time_orig
65 console.log(f"Sent {sent_pkts_tot} WIB packets in {time_seconds:.2f} seconds. Throughput = {(sent_bytes_tot*8)/(time_seconds*1000000000.):2f} Gb/s")
66
67if __name__ == '__main__':
68 try:
69 cli(show_default=True, standalone_mode=True)
70 except Exception as e:
71 console.print_exception()
72