35 from tc_utils
import *
39 """TCP Tx Single-Thread Loop.
40 :param sock The socket to send/receive to/from.
41 :param message The message string to sent.
42 :param count The number of segments to send.
43 :param verbose Enables verbosity.
46 print(
"[INFO] The following message of %d bytes will be sent out %d times:\n Message=%s\n"
47 % (len(message), count, message.decode()))
51 startTime = datetime.datetime.now()
57 except socket.error
as exc:
59 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
63 txByteCnt += len(message)
65 print(
"Loop=%d | TxBytes=%d" % (loop, txByteCnt))
70 endTime = datetime.datetime.now()
71 elapseTime = endTime - startTime
76 """TCP Tx test at reduce speed (by inserting a sleep duration in between two transmissions)
77 :param sock The socket to send/receive to/from.
78 :param message The message string to sent.
79 :param count The number of segments to send.
80 :param pause The idle duration between two segments (in seconds)
81 :param verbose Enables verbosity.
84 print(
"[INFO] TCP-TX-SLOW-PACE: The following message of %d bytes will be sent out %d times"
85 " with an inter-gap time of %f seconds:\n Message=%s\n" %
86 (len(message), count, pause, message.decode()))
91 startTime = datetime.datetime.now()
97 except socket.error
as exc:
99 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
103 txWinByteCnt += len(message)
104 totalByteCnt += len(message)
106 print(
"Loop=%6d | TotalTxBytes=%6d | Pause=%4f sec" % (loop+1, totalByteCnt, pause))
110 endTime = datetime.datetime.now()
111 elapseTime = endTime - startTime
117 """TCP Tx Single-Thread Ramp. Send a buffer of bytes with 64-bit unsigned integer numbers
118 ramping up from 1 to len(message).
119 :param sock The socket to send/receive to/from.
120 :param message The message string to sent.
121 :param count The number of segments to send.
122 :param pause The idle duration between two segments (in seconds)
123 :param verbose Enables verbosity.
126 size = len(message) * count
128 for i
in range(0, size-1):
131 rampSize =
int(size/8)
132 for i
in range(0, rampSize):
133 strTmp =
"{:08d}".format(i)
135 strStream += strTmp[7]
136 strStream += strTmp[6]
137 strStream += strTmp[5]
138 strStream += strTmp[4]
139 strStream += strTmp[3]
140 strStream += strTmp[2]
141 strStream += strTmp[1]
142 strStream += strTmp[0]
143 for i
in range(0,
int(size % 8)):
145 bytStream = strStream.encode()
148 print(
"[INFO] The following stream of %d bytes will be sent out:\n Message=%s\n" %
149 (len(message), bytStream.decode()))
151 startTime = datetime.datetime.now()
158 sock.sendall(bytStream)
159 except socket.error
as exc:
161 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
170 for i
in range(0, rampSize):
171 subStr = bytStream[i*8: i*8+8]
174 except socket.error
as exc:
176 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
182 subStr = bytStream[(size/8)*8: (size/8)*8 + (size % 8)]
185 except socket.error
as exc:
187 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
193 endTime = datetime.datetime.now()
194 elapseTime = endTime - startTime
196 txByteCnt = len(message) * count
200 """Send a ramp of increasing segment sizes starting from 1 bytes up to len(message).
201 :param sock The socket to send/receive to/from.
202 :param message The message string to sent.
203 :param count The number of segments to send.
204 :param pause The idle duration between two segments (in seconds)
205 :param verbose Enables verbosity.
211 startTime = datetime.datetime.now()
214 for i
in range(1, len(message)):
216 subMsg = message[0: i]
219 except socket.error
as exc:
221 print(
"[EXCEPTION] Socket error while transmitting :: %s" % exc)
225 txByteCnt += len(message)
227 print(
"Loop=%4.4d | SegmentLength=%4.4d" % (loop, i))
232 endTime = datetime.datetime.now()
233 elapseTime = endTime - startTime
246 parser = argparse.ArgumentParser(description=
'A script to send TCP data to an FPGA module.')
247 parser.add_argument(
'-fi',
'--fpga_ipv4', type=str, default=
'',
248 help=
'The IPv4 address of the FPGA (a.k.a image_ip / e.g. 10.12.200.163)')
249 parser.add_argument(
'-ii',
'--inst_id', type=int, default=0,
250 help=
'The instance ID assigned by the cloudFPGA Resource Manager (e.g. 42)')
251 parser.add_argument(
'-lc',
'--loop_count', type=int, default=10,
252 help=
'The number of test runs (default is 10)')
253 parser.add_argument(
'-mi',
'--mngr_ipv4', type=str, default=
'10.12.0.132',
254 help=
'The IPv4 address of the cloudFPGA Resource Manager (default 10.12.0.132)')
255 parser.add_argument(
'-mp',
'--mngr_port', type=int, default=8080,
256 help=
'The TCP port of the cloudFPGA Resource Manager (default is 8080)')
257 parser.add_argument(
'-nr',
'--no_reset', action=
"store_true",
258 help=
'Do not reset the application role')
259 parser.add_argument(
'-sd',
'--seed', type=int, default=-1,
260 help=
'The initial number to seed the pseudorandom number generator.')
261 parser.add_argument(
'-st',
'--sleep_time', type=float, default=0.0,
262 help=
'Enforce a sleep time in between two segments (in seconds)')
263 parser.add_argument(
'-sz',
'--size', type=int, default=-1,
264 help=
'The size of the datagram to generate.')
265 parser.add_argument(
'-un',
'--user_name', type=str, default=
'',
266 help=
'A user-name as used to log in ZYC2 (.e.g \'fab\')')
267 parser.add_argument(
'-up',
'--user_passwd', type=str, default=
'',
268 help=
'The ZYC2 password attached to the user-name')
269 parser.add_argument(
'-v',
'--verbose', action=
"store_true",
270 help=
'Enable verbosity')
272 args = parser.parse_args()
274 if args.user_name ==
'' or args.user_passwd ==
'':
275 print(
"\nWARNING: You must provide a ZYC2 user name and the corresponding password for this "
276 "script to execute.\n")
293 portFpga = RECV_MODE_LSN_PORT
301 if not args.no_reset:
302 restartApp(instId, ipResMngr, portResMngr, args.user_name, args.user_passwd)
310 fpgaAssociation = (
str(ipFpga), portFpga)
321 tcpSP = portFpga + 49152
322 hostAssociation = (ipSaStr, tcpSP)
327 tcpSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
328 except Exception
as exc:
329 print(
"[EXCEPTION] %s" % exc)
334 tcpSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
335 tcpSock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY,
True)
343 tcpSock.bind(hostAssociation)
344 print(
'Binding the socket address of the HOST to {%s, %d}' % hostAssociation)
345 except Exception
as exc:
346 print(
"[EXCEPTION] %s" % exc)
352 tcpSock.connect(fpgaAssociation)
353 except Exception
as exc:
354 print(
"[EXCEPTION] %s" % exc)
357 print(
'\nSuccessful connection with socket address of FPGA at {%s, %d} \n' % fpgaAssociation)
361 tcpSock.setblocking(
False)
362 tcpSock.settimeout(5)
366 print(
"[INFO] Testcase `%s` is run with:" % (os.path.basename(__file__)))
369 seed = random.randint(0, 100000)
371 print(
"\t\t seed = %d" % seed)
375 size = random.randint(1, ZYC2_MSS)
376 elif size > ZYC2_MSS:
378 print(
"[ERROR] This test-case expects the transfer of segment which are less or equal to MSS "
379 "(.i.e %d bytes).\n" % ZYC2_MSS)
381 print(
"\t\t size = %d" % size)
383 count = args.loop_count
384 print(
"\t\t loop = %d" % count)
391 verbose = args.verbose
395 print(
"[INFO] This testcase is sending traffic from HOST-to-FPGA. ")
396 print(
"[INFO] It is run in single-threading mode.\n")
405 if args.sleep_time > 0.0:
407 tcp_tx_slowpace(tcpSock, message, count, args.sleep_time, args.verbose)
def tcp_tx_loop(sock, message, count, verbose=False)
def tcp_tx_seg_size_ramp(sock, message, count, pause=0.0, verbose=False)
def tcp_tx_payload_ramp(sock, message, count, pause=0.0, verbose=False)
def tcp_tx_slowpace(sock, message, count, pause, verbose=False)
def restartApp(instId, ipResMngr, portResMngr, user_name, user_passwd)
def getResourceManagerIpv4(args)
def display_throughput(byteCount, elapseTime)
def getResourceManagerPort(args)