cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
tc_utils Namespace Reference

Functions

def num_to_char (num)
 
def str_static_gen (size)
 
def str_rand_gen (size)
 
def getFpgaIpv4 (args)
 
def getFpgaPort (args)
 
def getResourceManagerIpv4 (args)
 
def getResourceManagerPort (args)
 
def getInstanceId (args)
 
def restartApp (instId, ipResMngr, portResMngr, user_name, user_passwd)
 
def pingFpga (ipFpga)
 
def display_throughput (byteCount, elapseTime)
 

Variables

int ACM_OK = 0
 
int ACM_KO = 1
 
int MTU = 1500
 
int MTU_ZYC2 = 1450
 
int IP4_HDR_LEN = 20
 
int TCP_HDR_LEN = 20
 
tuple ZYC2_MSS = (MTU_ZYC2 - 92) & ~0x7
 
int UDP_HDR_LEN = 8
 
tuple UDP_MDS = (MTU_ZYC2 - IP4_HDR_LEN - UDP_HDR_LEN) & ~0x7
 
int RECV_MODE_LSN_PORT = 8800
 
int XMIT_MODE_LSN_PORT = 8801
 
int BIDIR_MODE_LSN_PORT = 8802
 
int ECHO_MODE_LSN_PORT = 8803
 
int IPERF_LSN_PORT = 5001
 
int IPREF3_LSN_PORT = 5201
 

Function Documentation

◆ display_throughput()

def tc_utils.display_throughput (   byteCount,
  elapseTime 
)
Display the throughput in human readable form.
 :param byteCount:  The number of bytes transferred.
 :param elapseTime: The duration of the transfer.
 :return:           Nothing

Definition at line 211 of file tc_utils.py.

211 def display_throughput(byteCount, elapseTime):
212  """Display the throughput in human readable form.
213  :param byteCount: The number of bytes transferred.
214  :param elapseTime: The duration of the transfer.
215  :return: Nothing
216  """
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)
222  else:
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)
226 
227  strMsg = ""
228  if throughput < 1000:
229  strMsg = "#### DONE with throughput = %.1f Mb/s ####" % throughput
230  else:
231  throughput = throughput / 1000
232  strMsg = "#### DONE with throughput = %.1f Gb/s ####" % throughput
233 
234  strHashLine = ""
235  for i in range(0, len(strMsg)):
236  strHashLine += "#"
237 
238  print(strHashLine)
239  print(strMsg)
240  print(strHashLine)
241  print()
242 
243 
def display_throughput(byteCount, elapseTime)
Definition: tc_utils.py:211
Here is the caller graph for this function:

◆ getFpgaIpv4()

def tc_utils.getFpgaIpv4 (   args)
Retrieve the IPv4 address of the FPGA module.
:param args  The options passed as arguments to the script.
:return      The IPv4 address as an 'ipaddress.IPv4Address'.

Definition at line 95 of file tc_utils.py.

95 def getFpgaIpv4(args):
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
100  while True:
101  if args.fpga_ipv4 == '':
102  # Take an IP address from the console
103  print("Enter the IPv4 address of the FPGA module to connect to (e.g. 10.12.200.21)")
104  ipFpgaStr = input()
105  try:
106  ipFpga = ipaddress.ip_address(ipFpgaStr)
107  except ValueError:
108  print('[ERROR] Unrecognized IPv4 address.')
109  else:
110  return ipFpga
111 
112 
def getFpgaIpv4(args)
Definition: tc_utils.py:95
string input
Definition: test.py:9

◆ getFpgaPort()

def tc_utils.getFpgaPort (   args)
Retrieve the UDP listen port of the FPGA.
:param args The options passed as arguments to the script.
:return     The UDP port number as an integer.

Definition at line 113 of file tc_utils.py.

113 def getFpgaPort(args):
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
118  if portFpga != 8803:
119  print("[ERROR] The current version of the cFp_BringUp role always listens on port #8803.\n")
120  exit(1)
121  return portFpga
122 
123 
def getFpgaPort(args)
Definition: tc_utils.py:113

◆ getInstanceId()

def tc_utils.getInstanceId (   args)
Retrieve the instance Id that was assigned by the cloudFPGA Resource Manager.
:param args The options passed as arguments to the script.
:return     The instance Id as an integer.

Definition at line 153 of file tc_utils.py.

153 def getInstanceId(args):
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
158  while True:
159  if not 1 <= args.inst_id: # Take an instance Id from the console
160  print("Enter the instance Id that was assigned by the cloudFPGA Resource Manager (e.g. 42)")
161  instIdStr = input()
162  try:
163  instId = int(instIdStr)
164  except ValueError:
165  print("ERROR: Bad format for the instance Id.")
166  print("\tEnter a new instance Id > 0.\n")
167  else:
168  break
169  else:
170  break;
171  return instId
172 
173 
def getInstanceId(args)
Definition: tc_utils.py:153

◆ getResourceManagerIpv4()

def tc_utils.getResourceManagerIpv4 (   args)
Retrieve the IPv4 address of the cloudFPGA Resource Manager.
:param args The options passed as arguments to the script.
:return     The IP address as an 'ipaddress.IPv4Address'.

Definition at line 124 of file tc_utils.py.

124 def getResourceManagerIpv4(args):
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
129  while True:
130  if args.mngr_ipv4 == '':
131  # Take an IP address from the console
132  print("Enter the IPv4 address of the cloudFPGA Resource Manager (e.g. 10.12.0.132)")
133  ipResMngrStr = input()
134  try:
135  ipResMngr = ipaddress.ip_address(ipResMngrStr)
136  except ValueError:
137  print('[ERROR] Unrecognized IPv4 address.')
138  else:
139  return ipResMngr
140 
141 
def getResourceManagerIpv4(args)
Definition: tc_utils.py:124

◆ getResourceManagerPort()

def tc_utils.getResourceManagerPort (   args)
Retrieve the TCP port of the cloudFPGA Resource Manager.
:param args The options passed as arguments to the script.
:return     The TCP port number as an integer.

Definition at line 142 of file tc_utils.py.

142 def getResourceManagerPort(args):
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
147  if portMngr != 8080:
148  print("[ERROR] The current version of the cloudFPGA Resource manager always listens on port #8080.\n")
149  exit(1)
150  return portMngr
151 
152 
def getResourceManagerPort(args)
Definition: tc_utils.py:142

◆ num_to_char()

def tc_utils.num_to_char (   num)
 Function to map a number to a character.

Definition at line 70 of file tc_utils.py.

70 def num_to_char(num):
71  """ Function to map a number to a character."""
72  switcher = {
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'
75  }
76  return switcher.get(num, ' ') # ' ' is default
77 
78 
def num_to_char(num)
Definition: tc_utils.py:70
Here is the caller graph for this function:

◆ pingFpga()

def tc_utils.pingFpga (   ipFpga)
Ping an FPGA.
:param ipFpga:  The IPv4 address of the FPGA.
:return:        Nothing

Definition at line 199 of file tc_utils.py.

199 def pingFpga(ipFpga):
200  """Ping an FPGA.
201  :param ipFpga: The IPv4 address of the FPGA.
202  :return: Nothing
203  """
204  print("Now: Trying to \'ping\' the FPGA: ")
205  # Send 2 PINGs and wait 2 seconds max for each of them (for a total max of 4s)
206  rc = os.system("ping -c 2 -W 2 " + str(ipFpga))
207  if rc != 0:
208  print("[ERROR] FPGA does not reply to \'ping\'!")
209  exit(1)
210 
def pingFpga(ipFpga)
Definition: tc_utils.py:199

◆ restartApp()

def tc_utils.restartApp (   instId,
  ipResMngr,
  portResMngr,
  user_name,
  user_passwd 
)
Trigger the role of an FPGA to restart (i.e. perform a SW reset of the role)
:param instId:      The instance Id to restart.
:param ipResMngr:   The IPv4 address of the cF resource manager.
:param portResMngr: The TCP port number of the cF resource manager.
:param user_name:   The user name as used to log in ZYC2.
:param user_passwd: The ZYC2 password attached to the user name.
:return:            Nothing

Definition at line 174 of file tc_utils.py.

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.
181  :return: Nothing
182  """
183  print("\nNow: Requesting the application of FPGA instance #%d to restart." % instId)
184  try:
185  # We must build a request that is formatted as follows:
186  # http://10.12.0.132:8080/instances/13/app_restart?username=fab&password=secret
187  reqUrl = "http://" + str(ipResMngr) + ":" + str(portResMngr) + "/instances/" \
188  + str(instId) + "/app_restart?username=" + user_name \
189  + "&password=" + user_passwd
190  # DEBUG print("Generated request URL = ", reqUrl)
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")
195  print(str(e))
196  exit(1)
197 
198 
def restartApp(instId, ipResMngr, portResMngr, user_name, user_passwd)
Definition: tc_utils.py:174

◆ str_rand_gen()

def tc_utils.str_rand_gen (   size)
Returns an encoded random string of length 'size'.

Definition at line 89 of file tc_utils.py.

89 def str_rand_gen(size):
90  """Returns an encoded random string of length 'size'."""
91  msg = '\n'
92  msg += "".join(random.choice(string.ascii_lowercase + string.digits) for _ in range(size-1))
93  return msg.encode('ascii', 'replace')
94 
def str_rand_gen(size)
Definition: tc_utils.py:89

◆ str_static_gen()

def tc_utils.str_static_gen (   size)
Returns an encoded static string of length 'size'.

Definition at line 79 of file tc_utils.py.

79 def str_static_gen(size):
80  """Returns an encoded static string of length 'size'."""
81  msg = '\n'
82  msg += '__________Hello_World__________'
83  while (len(msg)) < (size):
84  msg += num_to_char(len(msg) % 16)
85  msg = (msg[:size]) if len(msg) > size else msg
86  return msg.encode('ascii', 'replace')
87 
88 
def str_static_gen(size)
Definition: tc_utils.py:79
Here is the call graph for this function:

Variable Documentation

◆ ACM_KO

int tc_utils.ACM_KO = 1

Definition at line 36 of file tc_utils.py.

◆ ACM_OK

int tc_utils.ACM_OK = 0

Definition at line 35 of file tc_utils.py.

◆ BIDIR_MODE_LSN_PORT

int tc_utils.BIDIR_MODE_LSN_PORT = 8802

Definition at line 65 of file tc_utils.py.

◆ ECHO_MODE_LSN_PORT

int tc_utils.ECHO_MODE_LSN_PORT = 8803

Definition at line 66 of file tc_utils.py.

◆ IP4_HDR_LEN

int tc_utils.IP4_HDR_LEN = 20

Definition at line 40 of file tc_utils.py.

◆ IPERF_LSN_PORT

int tc_utils.IPERF_LSN_PORT = 5001

Definition at line 67 of file tc_utils.py.

◆ IPREF3_LSN_PORT

int tc_utils.IPREF3_LSN_PORT = 5201

Definition at line 68 of file tc_utils.py.

◆ MTU

int tc_utils.MTU = 1500

Definition at line 38 of file tc_utils.py.

◆ MTU_ZYC2

int tc_utils.MTU_ZYC2 = 1450

Definition at line 39 of file tc_utils.py.

◆ RECV_MODE_LSN_PORT

int tc_utils.RECV_MODE_LSN_PORT = 8800

Definition at line 63 of file tc_utils.py.

◆ TCP_HDR_LEN

int tc_utils.TCP_HDR_LEN = 20

Definition at line 41 of file tc_utils.py.

◆ UDP_HDR_LEN

int tc_utils.UDP_HDR_LEN = 8

Definition at line 43 of file tc_utils.py.

◆ UDP_MDS

tuple tc_utils.UDP_MDS = (MTU_ZYC2 - IP4_HDR_LEN - UDP_HDR_LEN) & ~0x7

Definition at line 44 of file tc_utils.py.

◆ XMIT_MODE_LSN_PORT

int tc_utils.XMIT_MODE_LSN_PORT = 8801

Definition at line 64 of file tc_utils.py.

◆ ZYC2_MSS

tuple tc_utils.ZYC2_MSS = (MTU_ZYC2 - 92) & ~0x7

Definition at line 42 of file tc_utils.py.