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

Functions

def udp_rx_loop (clientSock, serverSock, size, ip_da, udp_dp, count, verbose=False)
 

Variables

 parser = argparse.ArgumentParser(description='A script to receive UDP data from an FPGA module.')
 
 type
 
 str
 
 default
 
 help
 
 int
 
 action
 
 args = parser.parse_args()
 
 ipFpga = getFpgaIpv4(args)
 
 instId = getInstanceId(args)
 
 ipResMngr = getResourceManagerIpv4(args)
 
 portFpgaServer = XMIT_MODE_LSN_PORT
 
 portResMngr = getResourceManagerPort(args)
 
tuple fpgaServerAssociation = (str(ipFpga), portFpgaServer)
 
int dpHost = 2718
 
tuple fpgaClientAssociation = (str(ipFpga), dpHost)
 
 udpClientSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
 udpServerSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 
 hostname = socket.gethostname()
 
 ipHostStr = socket.gethostbyname(hostname)
 
 ip4Str = ni.ifaddresses(itf)[AF_INET][0]['addr']
 
 ipHost = int(ipaddress.IPv4Address(ipHostStr))
 
 seed = args.seed
 
 size = args.size
 
 count = args.loop_count
 

Function Documentation

◆ udp_rx_loop()

def tc_UdpRecv.udp_rx_loop (   clientSock,
  serverSock,
  size,
  ip_da,
  udp_dp,
  count,
  verbose = False 
)
UDP Rx Single-Thread Ramp.
Requests the FPGA to open a new active port and expects to receive 'count' datagrams
  of 'size' bytes. Each datagram is made of the following repetitive pattern
  '48692066726f6d200x464d4b553630210a' which decodes into the string "Hi from FMKU60\n".
:param clientSock The socket to send to.
:param serverSock The socket to receive from.
:param size       The size of the expected segment.
:param ip_da      The destination address of the host.
:param udp_dp     The active destination port number that the FPGA is requested to open.
:param count      The number of datagrams to receive.
:param verbose    Enables verbosity.
:return           None

Definition at line 43 of file tc_UdpRecv.py.

43 def udp_rx_loop(clientSock, serverSock, size, ip_da, udp_dp, count, verbose=False):
44  """UDP Rx Single-Thread Ramp.
45  Requests the FPGA to open a new active port and expects to receive 'count' datagrams
46  of 'size' bytes. Each datagram is made of the following repetitive pattern
47  '48692066726f6d200x464d4b553630210a' which decodes into the string "Hi from FMKU60\n".
48  :param clientSock The socket to send to.
49  :param serverSock The socket to receive from.
50  :param size The size of the expected segment.
51  :param ip_da The destination address of the host.
52  :param udp_dp The active destination port number that the FPGA is requested to open.
53  :param count The number of datagrams to receive.
54  :param verbose Enables verbosity.
55  :return None"""
56  if verbose:
57  print("[INFO] Requesting the FPGA to send %d datagrams of %d bytes.\n" % (count, size))
58  nrErr = 0
59  loop = 0
60  totalReceivedBytes = 0
61 
62  # Set the server socket non-blocking
63  # --------------------------------------
64  serverSock.setblocking(False)
65  serverSock.settimeout(5)
66 
67  # Request the test to generate a datagram of length='size' and to send it to
68  # socket={ip_da, tcp_dp}. This is done by sending 'ip_da', 'tcp_dp' and 'size'
69  # to the FPGA UDP_DP=8801 while turning the 'ip_da' into an unsigned int binary
70  # and 'tcp_dp' and 'size' into an unsigned short binary data.
71  reqMsgAsBytes = struct.pack(">IHH", ip_da, udp_dp, size)
72  if verbose:
73  print("\n\n[DEBUG] reqMsgAsBytes = %s" % reqMsgAsBytes)
74 
75  startTime = datetime.datetime.now()
76  while loop < count:
77  # SEND message length request to FPGA
78  # ------------------------------------
79  try:
80  clientSock.sendall(reqMsgAsBytes)
81  except socket.error as exc:
82  # Any exception
83  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
84  exit(1)
85  finally:
86  pass
87 
88  # RECEIVE message length bytes from FPGA
89  # ---------------------------------------
90  currRxByteCnt = 0
91  while currRxByteCnt < size:
92  try:
93  data = serverSock.recv(MTU)
94  except IOError as e:
95  # On non blocking connections - when there are no incoming data, error is going to be raised
96  # Some operating systems will indicate that using AGAIN, and some using WOULDBLOCK error code
97  # We are going to check for both - if one of them - that's expected, means no incoming data,
98  # continue as normal. If we got different error code - something happened
99  if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
100  print("[ERROR] Socket reading error: {}".format(str(e)))
101  # We just did not receive anything
102  print("\t[INFO] So far we received %d bytes out of %d." % (currRxByteCnt, size))
103  count = loop
104  break
105  except socket.error as exc:
106  # Any other exception
107  print("[EXCEPTION] Socket error while receiving :: %s" % exc)
108  exit(1)
109  else:
110  currRxByteCnt += len(data)
111  if verbose:
112  print("[INFO] Loop=%d | RxBytes=%d | RxData=%s\n" % (loop, len(data), data))
113  # [FIXME-TODO: assess the stream of received bytes]
114  finally:
115  pass
116  totalReceivedBytes += currRxByteCnt;
117  loop += 1
118  endTime = datetime.datetime.now()
119  elapseTime = endTime - startTime
120 
121  if totalReceivedBytes < 1000000:
122  print("[INFO] Received a total of %d bytes." % totalReceivedBytes)
123  elif totalReceivedBytes < 1000000000:
124  megaBytes = (totalReceivedBytes * 1.0) / (1024 * 1024 * 1.0)
125  print("[INFO] Received a total of %.1f MB." % megaBytes)
126  else:
127  gigaBytes = (totalReceivedBytes * 1.0) / (1024 * 1024 * 1024 * 1.0)
128  print("[INFO] Transferred a total of %.1f GB." % gigaBytes)
129 
130  bandwidth = (totalReceivedBytes * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
131  print("#####################################################")
132  if bandwidth < 1000:
133  print("#### UDP Rx DONE with bandwidth = %6.1f Mb/s " % bandwidth)
134  else:
135  bandwidth = bandwidth / 1000
136  print("#### UDP Rx DONE with bandwidth = %2.1f Gb/s " % bandwidth)
137  if (totalReceivedBytes != (size * count)):
138  print("#### [WARNING] UDP data loss = %.1f%%" % (1-(totalReceivedBytes)/(size*count)))
139  print("#####################################################")
140  print()
141 
142 
def udp_rx_loop(clientSock, serverSock, size, ip_da, udp_dp, count, verbose=False)
Definition: tc_UdpRecv.py:43

Variable Documentation

◆ action

tc_UdpRecv.action

Definition at line 170 of file tc_UdpRecv.py.

◆ args

tc_UdpRecv.args = parser.parse_args()

Definition at line 173 of file tc_UdpRecv.py.

◆ count

tc_UdpRecv.count = args.loop_count

Definition at line 311 of file tc_UdpRecv.py.

◆ default

tc_UdpRecv.default

Definition at line 152 of file tc_UdpRecv.py.

◆ dpHost

int tc_UdpRecv.dpHost = 2718

Definition at line 213 of file tc_UdpRecv.py.

◆ fpgaClientAssociation

tuple tc_UdpRecv.fpgaClientAssociation = (str(ipFpga), dpHost)

Definition at line 214 of file tc_UdpRecv.py.

◆ fpgaServerAssociation

tuple tc_UdpRecv.fpgaServerAssociation = (str(ipFpga), portFpgaServer)

Definition at line 209 of file tc_UdpRecv.py.

◆ help

tc_UdpRecv.help

Definition at line 153 of file tc_UdpRecv.py.

◆ hostname

tc_UdpRecv.hostname = socket.gethostname()

Definition at line 249 of file tc_UdpRecv.py.

◆ instId

tc_UdpRecv.instId = getInstanceId(args)

Definition at line 185 of file tc_UdpRecv.py.

◆ int

tc_UdpRecv.int

Definition at line 154 of file tc_UdpRecv.py.

◆ ip4Str

tc_UdpRecv.ip4Str = ni.ifaddresses(itf)[AF_INET][0]['addr']

Definition at line 256 of file tc_UdpRecv.py.

◆ ipFpga

tc_UdpRecv.ipFpga = getFpgaIpv4(args)

Definition at line 181 of file tc_UdpRecv.py.

◆ ipHost

tc_UdpRecv.ipHost = int(ipaddress.IPv4Address(ipHostStr))

Definition at line 265 of file tc_UdpRecv.py.

◆ ipHostStr

string tc_UdpRecv.ipHostStr = socket.gethostbyname(hostname)

Definition at line 250 of file tc_UdpRecv.py.

◆ ipResMngr

tc_UdpRecv.ipResMngr = getResourceManagerIpv4(args)

Definition at line 189 of file tc_UdpRecv.py.

◆ parser

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

MAIN # #

Definition at line 151 of file tc_UdpRecv.py.

◆ portFpgaServer

tc_UdpRecv.portFpgaServer = XMIT_MODE_LSN_PORT

Definition at line 193 of file tc_UdpRecv.py.

◆ portResMngr

tc_UdpRecv.portResMngr = getResourceManagerPort(args)

Definition at line 197 of file tc_UdpRecv.py.

◆ seed

tc_UdpRecv.seed = args.seed

Definition at line 296 of file tc_UdpRecv.py.

◆ size

tc_UdpRecv.size = args.size

Definition at line 302 of file tc_UdpRecv.py.

◆ str

tc_UdpRecv.str

Definition at line 152 of file tc_UdpRecv.py.

◆ type

tc_UdpRecv.type

Definition at line 152 of file tc_UdpRecv.py.

◆ udpClientSock

tc_UdpRecv.udpClientSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Definition at line 219 of file tc_UdpRecv.py.

◆ udpServerSock

tc_UdpRecv.udpServerSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Definition at line 228 of file tc_UdpRecv.py.