35 from tc_utils
import *
38 """UDP Tx Single-Thread Loop.
39 :param sock The socket to send/receive to/from.
40 :param message The message string to sent.
41 :param count The number of datagrams to send.
42 :param verbose Enables verbosity.
45 print(
"[INFO] The following message of %d bytes will be sent out %d times:\n Message=%s\n" %
46 (len(message), count, message.decode()))
50 startTime = datetime.datetime.now()
56 except socket.error
as exc:
58 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
62 txByteCnt += len(message)
64 print(
"Loop=%d | TxBytes=%d" % (loop, txByteCnt))
66 endTime = datetime.datetime.now()
67 elapseTime = endTime - startTime
69 if txByteCnt < 1000000:
70 print(
"[INFO] Transferred a total of %d bytes." % txByteCnt)
71 elif txByteCnt < 1000000000:
72 megaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1.0)
73 print(
"[INFO] Transferred a total of %.1f MB." % megaBytes)
75 gigaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1024 * 1.0)
76 print(
"[INFO] Transferred a total of %.1f GB." % gigaBytes)
78 bandwidth = (txByteCnt * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
79 print(
"#####################################################")
81 print(
"#### UDP Tx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
83 bandwidth = bandwidth / 1000
84 print(
"#### UDP Tx DONE with bandwidth = %2.1f Gb/s ####" % bandwidth)
85 print(
"#####################################################")
90 """UDP Tx Single-Thread Ramp.
91 :param sock The socket to send/receive to/from.
92 :param message The message string to sent.
93 :param count The number of datagrams to send.
94 :param verbose Enables verbosity.
97 print(
"[INFO] The following message of %d bytes will be sent out incrementally %d times:\n Message=%s\n" %
98 (len(message), count, message.decode()))
102 startTime = datetime.datetime.now()
105 while i <= len(message):
106 subMsg = message[0:i]
110 udpSock.sendall(subMsg)
111 except socket.error
as exc:
113 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
117 txByteCnt += len(subMsg)
119 print(
"Loop=%d | TxBytes=%d | Msg=%s" % (loop, len(subMsg), subMsg))
122 endTime = datetime.datetime.now()
123 elapseTime = endTime - startTime
125 if txByteCnt < 1000000:
126 print(
"[INFO] Transferred a total of %d bytes." % txByteCnt)
127 elif txByteCnt < 1000000000:
128 megaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1.0)
129 print(
"[INFO] Transferred a total of %.1f MB." % megaBytes)
131 gigaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1024 * 1.0)
132 print(
"[INFO] Transferred a total of %.1f GB." % gigaBytes)
134 bandwidth = (txByteCnt * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
135 print(
"#####################################################")
137 print(
"#### UDP Tx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
139 bandwidth = bandwidth / 1000
140 print(
"#### UDP Tx DONE with bandwidth = %2.1f Gb/s ####" % bandwidth)
141 print(
"#####################################################")
153 parser = argparse.ArgumentParser(description=
'A script to send UDP data to an FPGA module.')
154 parser.add_argument(
'-fi',
'--fpga_ipv4', type=str, default=
'',
155 help=
'The IPv4 address of the FPGA (a.k.a image_ip / e.g. 10.12.200.163)')
156 parser.add_argument(
'-ii',
'--inst_id', type=int, default=0,
157 help=
'The instance ID assigned by the cloudFPGA Resource Manager (e.g. 42)')
158 parser.add_argument(
'-lc',
'--loop_count', type=int, default=10,
159 help=
'The number of test runs (default is 10)')
160 parser.add_argument(
'-mi',
'--mngr_ipv4', type=str, default=
'10.12.0.132',
161 help=
'The IPv4 address of the cloudFPGA Resource Manager (default is 10.12.0.132)')
162 parser.add_argument(
'-mp',
'--mngr_port', type=int, default=8080,
163 help=
'The TCP port of the cloudFPGA Resource Manager (default is 8080)')
164 parser.add_argument(
'-sd',
'--seed', type=int, default=-1,
165 help=
'The initial number to seed the pseudorandom number generator.')
166 parser.add_argument(
'-sz',
'--size', type=int, default=-1,
167 help=
'The size of the datagram to generate.')
168 parser.add_argument(
'-un',
'--user_name', type=str, default=
'',
169 help=
'A user-name as used to log in ZYC2 (.e.g \'fab\')')
170 parser.add_argument(
'-up',
'--user_passwd', type=str, default=
'',
171 help=
'The ZYC2 password attached to the user-name')
172 parser.add_argument(
'-v',
'--verbose', action=
"store_true",
173 help=
'Enable verbosity')
175 args = parser.parse_args()
177 if args.user_name ==
'' or args.user_passwd ==
'':
178 print(
"\nWARNING: You must provide a ZYC2 user name and the corresponding password for this script to execute.\n")
195 portFpga = RECV_MODE_LSN_PORT
203 restartApp(instId, ipResMngr, portResMngr, args.user_name, args.user_passwd)
211 fpgaAssociation = (
str(ipFpga), portFpga)
222 udpSP = portFpga + 49152
223 hostAssociation = (ipSaStr, udpSP)
228 udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
229 except Exception
as exc:
230 print(
"[EXCEPTION] %s" % exc)
244 udpSock.bind(hostAssociation)
245 print(
'Binding the socket address of the HOST to {%s, %d}' % hostAssociation)
246 except Exception
as exc:
247 print(
"[EXCEPTION] %s" % exc)
256 udpSock.connect(fpgaAssociation)
257 except Exception
as exc:
258 print(
"[EXCEPTION] %s" % exc)
261 print(
'\nSuccessful connection with socket address of FPGA at {%s, %d} \n' % fpgaAssociation)
265 udpSock.setblocking(
False)
266 udpSock.settimeout(5)
270 print(
"[INFO] Testcase `%s` is run with:" % (os.path.basename(__file__)))
273 seed = random.randint(0, 100000)
276 print(
"\t\t seed = %d" % seed)
280 size = random.randint(1, UDP_MDS)
283 print(
"[ERROR] The UDP stack does not support the reception of datagrams larger than %d bytes.\n" % UDP_MDS)
285 print(
"\t\t size = %d" % size)
287 count = args.loop_count
288 print(
"\t\t loop = %d" % count)
295 verbose = args.verbose
299 print(
"[INFO] This testcase is sending traffic from HOST-to-FPGA.")
300 print(
"[INFO] This run is executed in single-threading mode.\n")
def udp_tx_ramp(sock, message, count, verbose=False)
def udp_tx_loop(sock, message, count, verbose=False)
def restartApp(instId, ipResMngr, portResMngr, user_name, user_passwd)
def getResourceManagerIpv4(args)
def getResourceManagerPort(args)