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

Functions

def tcp_rx_loop (clientSock, serverSock, size, ip_da, tcp_dp, count, verbose=False)
 

Variables

 parser = argparse.ArgumentParser(description='A script to receive TCP 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)
 
 tcpClientSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 hostname = socket.gethostname()
 
 ipHostStr = socket.gethostbyname(hostname)
 
 ipHost = int(ipaddress.IPv4Address(ipHostStr))
 
int dpHost = 2718
 
tuple hostListenAssociation = (str(ipHostStr), dpHost)
 
 tcpListenSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 reqMsgAsBytes = struct.pack(">IHH", ipHost, dpHost, 0)
 
 tcpServerSock
 
 fpgaClientAssociation
 
 seed = args.seed
 
 size = args.size
 
 count = args.loop_count
 
 verbose = args.verbose
 

Function Documentation

◆ tcp_rx_loop()

def tc_TcpTest.tcp_rx_loop (   clientSock,
  serverSock,
  size,
  ip_da,
  tcp_dp,
  count,
  verbose = False 
)
TCP Rx Single-Thread Ramp.
 Requests the FPGA to open a new active port and expects to receive 'count' segments
  of 'size' bytes. Each segment 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 tcp_dp     The active destination port number that the FPGA is requested to open.
 :param count      The number of segments to receive.
 :param verbose    Enables verbosity.
 :return           None

Definition at line 41 of file tc_TcpTest.py.

41 def tcp_rx_loop(clientSock, serverSock, size, ip_da, tcp_dp, count, verbose=False):
42  """TCP Rx Single-Thread Ramp.
43  Requests the FPGA to open a new active port and expects to receive 'count' segments
44  of 'size' bytes. Each segment is made of the following repetitive pattern
45  '48692066726f6d200x464d4b553630210a' which decodes into the string "Hi from FMKU60\n".
46  :param clientSock The socket to send to.
47  :param serverSock The socket to receive from.
48  :param size The size of the expected segment.
49  :param ip_da The destination address of the host.
50  :param tcp_dp The active destination port number that the FPGA is requested to open.
51  :param count The number of segments to receive.
52  :param verbose Enables verbosity.
53  :return None"""
54  if verbose:
55  print("[INFO] Requesting the FPGA to send %d segments of %d bytes on TCP port number %d." % (count, size, tcp_dp))
56  nrErr = 0
57  loop = 0
58  totalReceivedBytes = 0
59 
60  # Set the client and server sockets non-blocking
61  # -----------------------------------------------
62  clientSock.settimeout(5)
63  clientSock.setblocking(False)
64  serverSock.settimeout(5)
65  serverSock.setblocking(False)
66 
67  # Request the test to generate a segment of length='size' and to send it to socket={ip_da, tcp_dp}
68  # by sending 'ip_da', 'tcp_dp' and 'size' to the FPGA.
69  # Turn the 'ip_da' into an unsigned int binary and 'tcp_dp' and 'size' into an unsigned short binary data.
70  reqMsgAsBytes = struct.pack(">IHH", ip_da, tcp_dp, size)
71  if verbose:
72  print("[DEBUG] >>> reqMsgAsBytes = %s" % reqMsgAsBytes)
73 
74  startTime = datetime.datetime.now()
75  while loop < count:
76  # SEND message length request to FPGA
77  # ------------------------------------
78  try:
79  clientSock.sendall(reqMsgAsBytes)
80  except socket.error as exception:
81  # Any exception
82  print("[EXCEPTION] Socket error while transmitting :: %s" % exception)
83  exit(1)
84  finally:
85  pass
86 
87  # RECEIVE message length bytes from FPGA
88  # ---------------------------------------
89  currRxByteCnt = 0
90  while currRxByteCnt < size:
91  try:
92  data = serverSock.recv(MTU)
93  except IOError as e:
94  # On non blocking connections - when there are no incoming data, error is going to be raised
95  # Some operating systems will indicate that using AGAIN, and some using WOULDBLOCK error code
96  # We are going to check for both - if one of them - that's expected, means no incoming data,
97  # continue as normal. If we got different error code - something happened
98  if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
99  print('[ERROR] Socket reading error: {}'.format(str(e)))
100  exit(1)
101  # We just did not receive anything
102  if verbose:
103  print("[DEBUG] So far we received %d bytes out of %d." % (currRxByteCnt, size))
104  continue
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("#### TCP Rx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
134  else:
135  bandwidth = bandwidth / 1000
136  print("#### TCP Rx DONE with bandwidth = %2.1f Gb/s ####" % bandwidth)
137  if (totalReceivedBytes != (size * count)):
138  print("#### [WARNING] TCP data loss = %.1f%%" % (1 - (totalReceivedBytes) / (size * count)))
139  print("#####################################################")
140  print()
141 
142 
def tcp_rx_loop(clientSock, serverSock, size, ip_da, tcp_dp, count, verbose=False)
Definition: tc_TcpTest.py:41

Variable Documentation

◆ action

tc_TcpTest.action

Definition at line 170 of file tc_TcpTest.py.

◆ args

tc_TcpTest.args = parser.parse_args()

Definition at line 173 of file tc_TcpTest.py.

◆ count

tc_TcpTest.count = args.loop_count

Definition at line 307 of file tc_TcpTest.py.

◆ default

tc_TcpTest.default

Definition at line 152 of file tc_TcpTest.py.

◆ dpHost

int tc_TcpTest.dpHost = 2718

Definition at line 240 of file tc_TcpTest.py.

◆ fpgaClientAssociation

tc_TcpTest.fpgaClientAssociation

Definition at line 284 of file tc_TcpTest.py.

◆ fpgaServerAssociation

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

Definition at line 209 of file tc_TcpTest.py.

◆ help

tc_TcpTest.help

Definition at line 153 of file tc_TcpTest.py.

◆ hostListenAssociation

tuple tc_TcpTest.hostListenAssociation = (str(ipHostStr), dpHost)

Definition at line 241 of file tc_TcpTest.py.

◆ hostname

tc_TcpTest.hostname = socket.gethostname()

Definition at line 232 of file tc_TcpTest.py.

◆ instId

tc_TcpTest.instId = getInstanceId(args)

Definition at line 185 of file tc_TcpTest.py.

◆ int

tc_TcpTest.int

Definition at line 154 of file tc_TcpTest.py.

◆ ipFpga

tc_TcpTest.ipFpga = getFpgaIpv4(args)

Definition at line 181 of file tc_TcpTest.py.

◆ ipHost

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

Definition at line 237 of file tc_TcpTest.py.

◆ ipHostStr

tc_TcpTest.ipHostStr = socket.gethostbyname(hostname)

Definition at line 233 of file tc_TcpTest.py.

◆ ipResMngr

tc_TcpTest.ipResMngr = getResourceManagerIpv4(args)

Definition at line 189 of file tc_TcpTest.py.

◆ parser

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

MAIN # #

Definition at line 151 of file tc_TcpTest.py.

◆ portFpgaServer

tc_TcpTest.portFpgaServer = XMIT_MODE_LSN_PORT

Definition at line 193 of file tc_TcpTest.py.

◆ portResMngr

tc_TcpTest.portResMngr = getResourceManagerPort(args)

Definition at line 197 of file tc_TcpTest.py.

◆ reqMsgAsBytes

tc_TcpTest.reqMsgAsBytes = struct.pack(">IHH", ipHost, dpHost, 0)

Definition at line 269 of file tc_TcpTest.py.

◆ seed

tc_TcpTest.seed = args.seed

Definition at line 292 of file tc_TcpTest.py.

◆ size

tc_TcpTest.size = args.size

Definition at line 298 of file tc_TcpTest.py.

◆ str

tc_TcpTest.str

Definition at line 152 of file tc_TcpTest.py.

◆ tcpClientSock

tc_TcpTest.tcpClientSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Definition at line 214 of file tc_TcpTest.py.

◆ tcpListenSock

tc_TcpTest.tcpListenSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Definition at line 246 of file tc_TcpTest.py.

◆ tcpServerSock

tc_TcpTest.tcpServerSock

Definition at line 284 of file tc_TcpTest.py.

◆ type

tc_TcpTest.type

Definition at line 152 of file tc_TcpTest.py.

◆ verbose

tc_TcpTest.verbose = args.verbose

Definition at line 310 of file tc_TcpTest.py.