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

Functions

def udp_tx (sock, message, count, lock, verbose=False)
 
def udp_rx (sock, message, count, lock, verbose=False)
 
def udp_txrx_loop (sock, message, count, verbose=False)
 
def udp_txrx_ramp (sock, message, count, verbose=False)
 

Variables

 parser = argparse.ArgumentParser(description='A script to send/receive UDP data to/from an FPGA module.')
 
 type
 
 str
 
 default
 
 help
 
 int
 
 action
 
 args = parser.parse_args()
 
 ipFpga = getFpgaIpv4(args)
 
 instId = getInstanceId(args)
 
 ipResMngr = getResourceManagerIpv4(args)
 
 portFpga = getFpgaPort(args)
 
 portResMngr = getResourceManagerPort(args)
 
tuple fpgaAssociation = (str(ipFpga), portFpga)
 
int udpSP = portFpga + 49152
 
tuple hostAssociation = (ipSaStr, udpSP)
 
 udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
 seed = args.seed
 
 size = args.size
 
 count = args.loop_count
 
 message = str_static_gen(size)
 
 verbose = args.verbose
 
int gBytesInFlight = 0
 
 lock = threading.Lock()
 
 tx_thread = threading.Thread(target=udp_tx, args=(udpSock, message, count, lock, args.verbose))
 
 rx_thread = threading.Thread(target=udp_rx, args=(udpSock, message, count, lock, args.verbose))
 

Function Documentation

◆ udp_rx()

def tc_UdpEcho.udp_rx (   sock,
  message,
  count,
  lock,
  verbose = False 
)
UDP Rx Thread.
 :param sock        The socket to receive from.
 :param message     The expected string message to be received.
 :param count       The number of datagrams to receive.
 :param lock        A semaphore to access the global variable 'gBytesInFlight'.
 :param verbose,    Enables verbosity.
 :return            None

Definition at line 81 of file tc_UdpEcho.py.

81 def udp_rx(sock, message, count, lock, verbose=False):
82  """UDP Rx Thread.
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.
88  :return None"""
89  global gBytesInFlight
90 
91  loop = 0
92  rxBytes = 0
93  nrErr = 0
94  startTime = datetime.datetime.now()
95  while rxBytes < count*len(message):
96  try:
97  data = sock.recv(len(message))
98  except IOError as e:
99  # On non blocking connections - when there are no incoming data, error is going to be raised
100  # Some operating systems will indicate that using AGAIN, and some using WOULDBLOCK error code
101  # We are going to check for both - if one of them - that's expected, means no incoming data,
102  # continue as normal. If we got different error code - something happened
103  if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
104  print('[ERROR] Socket reading error: {}'.format(str(e)))
105  exit(1)
106  # We just did not receive anything
107  continue
108  except socket.error as exc:
109  # Any other exception
110  print("[EXCEPTION] Socket error while receiving :: %s" % exc)
111  exit(1)
112  else:
113  lock.acquire()
114  gBytesInFlight -= len(data)
115  # print("RX - %d" % gBytesInFlight)
116  lock.release()
117  rxBytes += len(data)
118  if data == message:
119  if verbose:
120  print("Loop=%d | RxBytes=%d" % (loop, rxBytes))
121  else:
122  print("Loop=%d | RxBytes=%d" % (loop, rxBytes))
123  print(" KO | Received Message=%s" % data.decode())
124  print(" | Expecting Message=%s" % message)
125  nrErr += 1
126  loop += 1
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("##################################################")
134  print()
135 
136 
def udp_rx(sock, message, count, lock, verbose=False)
Definition: tc_UdpEcho.py:81

◆ udp_tx()

def tc_UdpEcho.udp_tx (   sock,
  message,
  count,
  lock,
  verbose = False 
)
UDP Tx Thread.
:param sock     The socket to send to.
:param message  The message string to sent.
:param count    The number of datagrams to send.
:param lock     A semaphore to access the global variable 'gBytesInFlight'.
:param verbose  Enables verbosity.
:return         None

Definition at line 40 of file tc_UdpEcho.py.

40 def udp_tx(sock, message, count, lock, verbose=False):
41  """UDP Tx Thread.
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.
47  :return None"""
48  global gBytesInFlight
49 
50  if verbose:
51  print("The following message of %d bytes will be sent out %d times:\n Message=%s\n" %
52  (len(message), count, message.decode()))
53  loop = 0
54  startTime = datetime.datetime.now()
55  while loop < count:
56  if gBytesInFlight < 4096:
57  # FYI - UDP does not provide any flow-control.
58  # If we push bytes into the FPGA faster than we drain, some bytes might be dropped.
59  try:
60  sock.sendall(message)
61  except socket.error as exc:
62  # Any exception
63  print("[EXCEPTION] Socket error while receiving :: %s" % exc)
64  exit(1)
65  else:
66  lock.acquire()
67  gBytesInFlight += len(message)
68  # print("TX - %d" % gBytesInFlight)
69  lock.release()
70  loop += 1
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("##################################################")
78  print()
79 
80 
def udp_tx(sock, message, count, lock, verbose=False)
Definition: tc_UdpEcho.py:40

◆ udp_txrx_loop()

def tc_UdpEcho.udp_txrx_loop (   sock,
  message,
  count,
  verbose = False 
)
UDP Tx-Rx Single-Thread Loop.
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of datagrams to send.
 :param verbose  Enables verbosity.
 :return         None

Definition at line 137 of file tc_UdpEcho.py.

137 def udp_txrx_loop(sock, message, count, verbose=False):
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.
143  :return None"""
144  if verbose:
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()))
147  nrErr = 0
148  loop = 0
149  rxByteCnt = 0
150  startTime = datetime.datetime.now()
151  while loop < count:
152  # Send datagram
153  # -------------------
154  try:
155  sock.sendall(message)
156  finally:
157  pass
158  # Receive datagram
159  # -------------------
160  try:
161  data = sock.recv(len(message))
162  rxByteCnt += len(data)
163  if data == message:
164  if verbose:
165  print("Loop=%d | RxBytes=%d" % (loop, rxByteCnt))
166  else:
167  print("Loop=%d | RxBytes=%d" % (loop, rxByteCnt))
168  print(" KO | Received Message=%s" % data.decode())
169  print(" | Expecting Message=%s" % message)
170  nrErr += 1
171  except IOError as e:
172  # On non blocking connections - when there are no incoming data, error is going to be raised
173  # Some operating systems will indicate that using AGAIN, and some using WOULDBLOCK error code
174  # We are going to check for both - if one of them - that's expected, means no incoming data,
175  # continue as normal. If we got different error code - something happened
176  if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
177  print('[ERROR] Socket reading error: {}'.format(str(e)))
178  exit(1)
179  # We just did not receive anything
180  continue
181  except socket.error as exc:
182  # Any other exception
183  print("[EXCEPTION] Socket error while receiving :: %s" % exc)
184  # exit(1)
185  finally:
186  pass
187  loop += 1
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("#####################################################")
195  print()
196 
197 
def udp_txrx_loop(sock, message, count, verbose=False)
Definition: tc_UdpEcho.py:137

◆ udp_txrx_ramp()

def tc_UdpEcho.udp_txrx_ramp (   sock,
  message,
  count,
  verbose = False 
)
UDP Tx-Rx Single-Thread Ramp.
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of datagrams to send.
 :param verbose  Enables verbosity.
 :return         None

Definition at line 198 of file tc_UdpEcho.py.

198 def udp_txrx_ramp(sock, message, count, verbose=False):
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.
204  :return None"""
205  if verbose:
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()))
208  nrErr = 0
209  loop = 0
210  rxByteCnt = 0
211  startTime = datetime.datetime.now()
212  while loop < count:
213  i = 1
214  while i <= len(message):
215  subMsg = message[0:i]
216 
217  # Send datagram
218  # -------------------
219  try:
220  sock.sendall(subMsg)
221  finally:
222  pass
223  # Receive datagram
224  # -------------------
225  try:
226  data = sock.recv(len(subMsg))
227  rxByteCnt += len(data)
228  if data == subMsg:
229  if verbose:
230  print("Loop=%d | RxBytes=%d" % (loop, len(data)))
231  else:
232  print("Loop=%d | RxBytes=%d" % (loop, len(data)))
233  print(" KO | Received Message=%s" % data.decode())
234  print(" | Expecting Message=%s" % subMsg)
235  nrErr += 1
236  except IOError as e:
237  # On non blocking connections - when there are no incoming data, error is going to be raised
238  # Some operating systems will indicate that using AGAIN, and some using WOULDBLOCK error code
239  # We are going to check for both - if one of them - that's expected, means no incoming data,
240  # continue as normal. If we got different error code - something happened
241  if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
242  print('[ERROR] Socket reading error: {}'.format(str(e)))
243  exit(1)
244  # We just did not receive anything
245  continue
246  except socket.error as exc:
247  # Any other exception
248  print("[EXCEPTION] Socket error while receiving :: %s" % exc)
249  # exit(1)
250  finally:
251  pass
252  i += 1
253  loop += 1
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("#####################################################")
262  print()
263 
264 
def udp_txrx_ramp(sock, message, count, verbose=False)
Definition: tc_UdpEcho.py:198

Variable Documentation

◆ action

tc_UdpEcho.action

Definition at line 286 of file tc_UdpEcho.py.

◆ args

tc_UdpEcho.args = parser.parse_args()

Definition at line 301 of file tc_UdpEcho.py.

◆ count

tc_UdpEcho.count = args.loop_count

Definition at line 423 of file tc_UdpEcho.py.

◆ default

tc_UdpEcho.default

Definition at line 274 of file tc_UdpEcho.py.

◆ fpgaAssociation

tuple tc_UdpEcho.fpgaAssociation = (str(ipFpga), portFpga)

Definition at line 346 of file tc_UdpEcho.py.

◆ gBytesInFlight

int tc_UdpEcho.gBytesInFlight = 0

Definition at line 437 of file tc_UdpEcho.py.

◆ help

tc_UdpEcho.help

Definition at line 275 of file tc_UdpEcho.py.

◆ hostAssociation

tuple tc_UdpEcho.hostAssociation = (ipSaStr, udpSP)

Definition at line 358 of file tc_UdpEcho.py.

◆ instId

tc_UdpEcho.instId = getInstanceId(args)

Definition at line 313 of file tc_UdpEcho.py.

◆ int

tc_UdpEcho.int

Definition at line 276 of file tc_UdpEcho.py.

◆ ipFpga

tc_UdpEcho.ipFpga = getFpgaIpv4(args)

Definition at line 309 of file tc_UdpEcho.py.

◆ ipResMngr

tc_UdpEcho.ipResMngr = getResourceManagerIpv4(args)

Definition at line 317 of file tc_UdpEcho.py.

◆ lock

tc_UdpEcho.lock = threading.Lock()

Definition at line 439 of file tc_UdpEcho.py.

◆ message

tc_UdpEcho.message = str_static_gen(size)

Definition at line 427 of file tc_UdpEcho.py.

◆ parser

tc_UdpEcho.parser = argparse.ArgumentParser(description='A script to send/receive UDP data to/from an FPGA module.')
                                        #

MAIN # #

Definition at line 273 of file tc_UdpEcho.py.

◆ portFpga

tc_UdpEcho.portFpga = getFpgaPort(args)

Definition at line 321 of file tc_UdpEcho.py.

◆ portResMngr

tc_UdpEcho.portResMngr = getResourceManagerPort(args)

Definition at line 325 of file tc_UdpEcho.py.

◆ rx_thread

tc_UdpEcho.rx_thread = threading.Thread(target=udp_rx, args=(udpSock, message, count, lock, args.verbose))

Definition at line 443 of file tc_UdpEcho.py.

◆ seed

tc_UdpEcho.seed = args.seed

Definition at line 408 of file tc_UdpEcho.py.

◆ size

tc_UdpEcho.size = args.size

Definition at line 414 of file tc_UdpEcho.py.

◆ str

tc_UdpEcho.str

Definition at line 274 of file tc_UdpEcho.py.

◆ tx_thread

tc_UdpEcho.tx_thread = threading.Thread(target=udp_tx, args=(udpSock, message, count, lock, args.verbose))

Definition at line 442 of file tc_UdpEcho.py.

◆ type

tc_UdpEcho.type

Definition at line 274 of file tc_UdpEcho.py.

◆ udpSock

tc_UdpEcho.udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Definition at line 363 of file tc_UdpEcho.py.

◆ udpSP

int tc_UdpEcho.udpSP = portFpga + 49152

Definition at line 357 of file tc_UdpEcho.py.

◆ verbose

tc_UdpEcho.verbose = args.verbose

Definition at line 431 of file tc_UdpEcho.py.