42 ZYC2_MSS = (MTU_ZYC2 - 92) & ~0x7
44 UDP_MDS = (MTU_ZYC2 - IP4_HDR_LEN - UDP_HDR_LEN) & ~0x7
63 RECV_MODE_LSN_PORT = 8800
64 XMIT_MODE_LSN_PORT = 8801
65 BIDIR_MODE_LSN_PORT = 8802
66 ECHO_MODE_LSN_PORT = 8803
68 IPREF3_LSN_PORT = 5201
71 """ Function to map a number to a character."""
73 0:
'0', 1:
'1', 2:
'2', 3:
'3', 4:
'4', 5:
'5', 6:
'6', 7:
'7',
74 8:
'8', 9:
'9', 10:
'a', 11:
'b', 12:
'c', 13:
'd', 14:
'e', 15:
'f'
76 return switcher.get(num,
' ')
80 """Returns an encoded static string of length 'size'."""
82 msg +=
'__________Hello_World__________'
83 while (len(msg)) < (size):
85 msg = (msg[:size])
if len(msg) > size
else msg
86 return msg.encode(
'ascii',
'replace')
90 """Returns an encoded random string of length 'size'."""
92 msg +=
"".join(random.choice(string.ascii_lowercase + string.digits)
for _
in range(size-1))
93 return msg.encode(
'ascii',
'replace')
96 """Retrieve the IPv4 address of the FPGA module.
97 :param args The options passed as arguments to the script.
98 :return The IPv4 address as an 'ipaddress.IPv4Address'."""
99 ipFpgaStr = args.fpga_ipv4
101 if args.fpga_ipv4 ==
'':
103 print(
"Enter the IPv4 address of the FPGA module to connect to (e.g. 10.12.200.21)")
106 ipFpga = ipaddress.ip_address(ipFpgaStr)
108 print(
'[ERROR] Unrecognized IPv4 address.')
114 """Retrieve the UDP listen port of the FPGA.
115 :param args The options passed as arguments to the script.
116 :return The UDP port number as an integer."""
117 portFpga = args.fpga_port
119 print(
"[ERROR] The current version of the cFp_BringUp role always listens on port #8803.\n")
125 """Retrieve the IPv4 address of the cloudFPGA Resource Manager.
126 :param args The options passed as arguments to the script.
127 :return The IP address as an 'ipaddress.IPv4Address'."""
128 ipResMngrStr = args.mngr_ipv4
130 if args.mngr_ipv4 ==
'':
132 print(
"Enter the IPv4 address of the cloudFPGA Resource Manager (e.g. 10.12.0.132)")
133 ipResMngrStr =
input()
135 ipResMngr = ipaddress.ip_address(ipResMngrStr)
137 print(
'[ERROR] Unrecognized IPv4 address.')
143 """Retrieve the TCP port of the cloudFPGA Resource Manager.
144 :param args The options passed as arguments to the script.
145 :return The TCP port number as an integer."""
146 portMngr = args.mngr_port
148 print(
"[ERROR] The current version of the cloudFPGA Resource manager always listens on port #8080.\n")
154 """Retrieve the instance Id that was assigned by the cloudFPGA Resource Manager.
155 :param args The options passed as arguments to the script.
156 :return The instance Id as an integer."""
157 instId = args.inst_id
159 if not 1 <= args.inst_id:
160 print(
"Enter the instance Id that was assigned by the cloudFPGA Resource Manager (e.g. 42)")
163 instId =
int(instIdStr)
165 print(
"ERROR: Bad format for the instance Id.")
166 print(
"\tEnter a new instance Id > 0.\n")
174 def restartApp(instId, ipResMngr, portResMngr, user_name, user_passwd):
175 """Trigger the role of an FPGA to restart (i.e. perform a SW reset of the role)
176 :param instId: The instance Id to restart.
177 :param ipResMngr: The IPv4 address of the cF resource manager.
178 :param portResMngr: The TCP port number of the cF resource manager.
179 :param user_name: The user name as used to log in ZYC2.
180 :param user_passwd: The ZYC2 password attached to the user name.
183 print(
"\nNow: Requesting the application of FPGA instance #%d to restart." % instId)
187 reqUrl =
"http://" +
str(ipResMngr) +
":" +
str(portResMngr) +
"/instances/" \
188 +
str(instId) +
"/app_restart?username=" + user_name \
189 +
"&password=" + user_passwd
191 r1 = requests.patch(reqUrl)
192 print(r1.content.decode(
'ascii'))
193 except Exception
as e:
194 print(
"ERROR: Failed to reset the FPGA role")
201 :param ipFpga: The IPv4 address of the FPGA.
204 print(
"Now: Trying to \'ping\' the FPGA: ")
206 rc = os.system(
"ping -c 2 -W 2 " +
str(ipFpga))
208 print(
"[ERROR] FPGA does not reply to \'ping\'!")
212 """Display the throughput in human readable form.
213 :param byteCount: The number of bytes transferred.
214 :param elapseTime: The duration of the transfer.
217 if byteCount < 1000000:
218 print(
"[INFO] Transferred a total of %d bytes." % byteCount)
219 elif byteCount < 1000000000:
220 megaBytes = (byteCount * 1.0) / (1024 * 1024 * 1.0)
221 print(
"[INFO] Transferred a total of %.1f MB." % megaBytes)
223 gigaBytes = (byteCount * 1.0) / (1024 * 1024 * 1024 * 1.0)
224 print(
"[INFO] Transferred a total of %.1f GB." % gigaBytes)
225 throughput = (byteCount * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
228 if throughput < 1000:
229 strMsg =
"#### DONE with throughput = %.1f Mb/s ####" % throughput
231 throughput = throughput / 1000
232 strMsg =
"#### DONE with throughput = %.1f Gb/s ####" % throughput
235 for i
in range(0, len(strMsg)):
def restartApp(instId, ipResMngr, portResMngr, user_name, user_passwd)
def getResourceManagerIpv4(args)
def display_throughput(byteCount, elapseTime)
def getResourceManagerPort(args)