37 from tc_utils
import *
40 def udp_tx(sock, message, count, lock, verbose=False):
42 :param sock The socket to send to.
43 :param message The message string to sent.
44 :param count The number of datagrams to send.
45 :param lock A semaphore to access the global variable 'gBytesInFlight'.
46 :param verbose Enables verbosity.
51 print(
"The following message of %d bytes will be sent out %d times:\n Message=%s\n" %
52 (len(message), count, message.decode()))
54 startTime = datetime.datetime.now()
56 if gBytesInFlight < 4096:
61 except socket.error
as exc:
63 print(
"[EXCEPTION] Socket error while receiving :: %s" % exc)
67 gBytesInFlight += len(message)
71 endTime = datetime.datetime.now()
72 elapseTime = endTime - startTime;
73 bandwidth = len(message) * 8 * count * 1.0 / (elapseTime.total_seconds() * 1024 * 1024)
74 print(
"[INFO] Sent a total of %d bytes." % (count*len(message)))
75 print(
"##################################################")
76 print(
"#### UDP TX DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
77 print(
"##################################################")
81 def udp_rx(sock, message, count, lock, verbose=False):
83 :param sock The socket to receive from.
84 :param message The expected string message to be received.
85 :param count The number of datagrams to receive.
86 :param lock A semaphore to access the global variable 'gBytesInFlight'.
87 :param verbose, Enables verbosity.
94 startTime = datetime.datetime.now()
95 while rxBytes < count*len(message):
97 data = sock.recv(len(message))
103 if e.errno != errno.EAGAIN
and e.errno != errno.EWOULDBLOCK:
104 print(
'[ERROR] Socket reading error: {}'.format(
str(e)))
108 except socket.error
as exc:
110 print(
"[EXCEPTION] Socket error while receiving :: %s" % exc)
114 gBytesInFlight -= len(data)
120 print(
"Loop=%d | RxBytes=%d" % (loop, rxBytes))
122 print(
"Loop=%d | RxBytes=%d" % (loop, rxBytes))
123 print(
" KO | Received Message=%s" % data.decode())
124 print(
" | Expecting Message=%s" % message)
127 endTime = datetime.datetime.now()
128 elapseTime = endTime - startTime;
129 bandwidth = len(message) * 8 * count * 1.0 / (elapseTime.total_seconds() * 1024 * 1024)
130 print(
"[INFO] Received a total of %d bytes." % rxBytes)
131 print(
"##################################################")
132 print(
"#### UDP RX DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
133 print(
"##################################################")
138 """UDP Tx-Rx Single-Thread Loop.
139 :param sock The socket to send/receive to/from.
140 :param message The message string to sent.
141 :param count The number of datagrams to send.
142 :param verbose Enables verbosity.
145 print(
"[INFO] The following message of %d bytes will be sent out %d times:\n Message=%s\n" %
146 (len(message), count, message.decode()))
150 startTime = datetime.datetime.now()
155 sock.sendall(message)
161 data = sock.recv(len(message))
162 rxByteCnt += len(data)
165 print(
"Loop=%d | RxBytes=%d" % (loop, rxByteCnt))
167 print(
"Loop=%d | RxBytes=%d" % (loop, rxByteCnt))
168 print(
" KO | Received Message=%s" % data.decode())
169 print(
" | Expecting Message=%s" % message)
176 if e.errno != errno.EAGAIN
and e.errno != errno.EWOULDBLOCK:
177 print(
'[ERROR] Socket reading error: {}'.format(
str(e)))
181 except socket.error
as exc:
183 print(
"[EXCEPTION] Socket error while receiving :: %s" % exc)
188 endTime = datetime.datetime.now()
189 elapseTime = endTime - startTime
190 bandwidth = len(message) * 8 * count * 1.0 / (elapseTime.total_seconds() * 1024 * 1024)
191 print(
"[INFO] Transferred a total of %d bytes." % rxByteCnt)
192 print(
"#####################################################")
193 print(
"#### UDP Tx/Rx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
194 print(
"#####################################################")
199 """UDP Tx-Rx Single-Thread Ramp.
200 :param sock The socket to send/receive to/from.
201 :param message The message string to sent.
202 :param count The number of datagrams to send.
203 :param verbose Enables verbosity.
206 print(
"[INFO] The following message of %d bytes will be sent out incrementally %d times:\n Message=%s\n" %
207 (len(message), count, message.decode()))
211 startTime = datetime.datetime.now()
214 while i <= len(message):
215 subMsg = message[0:i]
226 data = sock.recv(len(subMsg))
227 rxByteCnt += len(data)
230 print(
"Loop=%d | RxBytes=%d" % (loop, len(data)))
232 print(
"Loop=%d | RxBytes=%d" % (loop, len(data)))
233 print(
" KO | Received Message=%s" % data.decode())
234 print(
" | Expecting Message=%s" % subMsg)
241 if e.errno != errno.EAGAIN
and e.errno != errno.EWOULDBLOCK:
242 print(
'[ERROR] Socket reading error: {}'.format(
str(e)))
246 except socket.error
as exc:
248 print(
"[EXCEPTION] Socket error while receiving :: %s" % exc)
254 endTime = datetime.datetime.now()
255 elapseTime = endTime - startTime;
256 bandwidth = (rxByteCnt * 8 * count * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
257 megaBytes = (rxByteCnt * 1.0) / (1024 * 1024 * 1.0)
258 print(
"[INFO] Transferred a total of %.1f MB." % megaBytes)
259 print(
"#####################################################")
260 print(
"#### UDP Tx/Rx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
261 print(
"#####################################################")
273 parser = argparse.ArgumentParser(description=
'A script to send/receive UDP data to/from an FPGA module.')
274 parser.add_argument(
'-fi',
'--fpga_ipv4', type=str, default=
'',
275 help=
'The IPv4 address of the FPGA (a.k.a image_ip / e.g. 10.12.200.163)')
276 parser.add_argument(
'-fp',
'--fpga_port', type=int, default=8803,
277 help=
'The UDP port of the FPGA (default is 8803)')
278 parser.add_argument(
'-ii',
'--inst_id', type=int, default=0,
279 help=
'The instance ID assigned by the cloudFPGA Resource Manager (e.g. 42)')
280 parser.add_argument(
'-lc',
'--loop_count', type=int, default=10,
281 help=
'The number of test runs (default is 10)')
282 parser.add_argument(
'-mi',
'--mngr_ipv4', type=str, default=
'10.12.0.132',
283 help=
'The IPv4 address of the cloudFPGA Resource Manager (default is 10.12.0.132)')
284 parser.add_argument(
'-mp',
'--mngr_port', type=int, default=8080,
285 help=
'The TCP port of the cloudFPGA Resource Manager (default is 8080)')
286 parser.add_argument(
'-mt',
'--multi_threading', action=
"store_true",
287 help=
'Enable multi_threading')
288 parser.add_argument(
'-nr',
'--no_restart', action=
"store_true",
289 help=
'Do not restart the FPGA for this run')
290 parser.add_argument(
'-sd',
'--seed', type=int, default=-1,
291 help=
'The initial number to seed the pseudo-random number generator.')
292 parser.add_argument(
'-sz',
'--size', type=int, default=-1,
293 help=
'The size of the datagram to generate.')
294 parser.add_argument(
'-un',
'--user_name', type=str, default=
'',
295 help=
'A user-name as used to log in ZYC2 (.e.g \'fab\')')
296 parser.add_argument(
'-up',
'--user_passwd', type=str, default=
'',
297 help=
'The ZYC2 password attached to the user-name')
298 parser.add_argument(
'-v',
'--verbose', action=
"store_true",
299 help=
'Enable verbosity')
301 args = parser.parse_args()
303 if args.user_name ==
'' or args.user_passwd ==
'':
304 print(
"\nWARNING: You must provide a ZYC2 user name and the corresponding password for this script to execute.\n")
334 if not args.no_restart:
336 print(
"[INFO] *******************************\n")
338 print(
"[INFO] This run is executed without restarting the application.\n")
346 fpgaAssociation = (
str(ipFpga), portFpga)
357 udpSP = portFpga + 49152
358 hostAssociation = (ipSaStr, udpSP)
363 udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
364 except Exception
as exc:
365 print(
"[EXCEPTION] %s" % exc)
381 udpSock.bind(hostAssociation)
382 print(
'Binding the socket address of the HOST to {%s, %d}' % hostAssociation)
383 except Exception
as exc:
384 print(
"[EXCEPTION] %s" % exc)
393 udpSock.connect(fpgaAssociation)
394 except Exception
as exc:
395 print(
"[EXCEPTION] %s" % exc)
398 print(
'\nSuccessful connection with socket address of FPGA at {%s, %d} \n' % fpgaAssociation)
402 udpSock.setblocking(
False)
403 udpSock.settimeout(5)
407 print(
"[INFO] Testcase `%s` is run with:" % (os.path.basename(__file__)))
410 seed = random.randint(0, 100000)
412 print(
"\t\t seed = %d" % seed)
416 size = random.randint(1, UDP_MDS)
419 print(
"[ERROR] The UDP stack does not support the reception of datagrams larger than %d bytes.\n" % UDP_MDS)
421 print(
"\t\t size = %d" % size)
423 count = args.loop_count
424 print(
"\t\t loop = %d" % count)
431 verbose = args.verbose
433 print(
"[INFO] This testcase is sending traffic from HOST-to-FPGA and back from FPGA-to-HOST.")
434 if args.multi_threading:
435 print(
"[INFO] This run is executed in multi-threading mode.\n")
439 lock = threading.Lock()
442 tx_thread = threading.Thread(target=udp_tx, args=(udpSock, message, count, lock, args.verbose))
443 rx_thread = threading.Thread(target=udp_rx, args=(udpSock, message, count, lock, args.verbose))
453 print(
"[INFO] This run is executed in single-threading mode.\n")
def udp_rx(sock, message, count, lock, verbose=False)
def udp_txrx_ramp(sock, message, count, verbose=False)
def udp_tx(sock, message, count, lock, verbose=False)
def udp_txrx_loop(sock, message, count, verbose=False)
def getResourceManagerIpv4(args)
def getResourceManagerPort(args)