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

Functions

def tcp_tx_loop (sock, message, count, verbose=False)
 
def tcp_tx_slowpace (sock, message, count, pause, verbose=False)
 
def tcp_tx_payload_ramp (sock, message, count, pause=0.0, verbose=False)
 
def tcp_tx_seg_size_ramp (sock, message, count, pause=0.0, verbose=False)
 

Variables

 parser = argparse.ArgumentParser(description='A script to send TCP data to an FPGA module.')
 
 type
 
 str
 
 default
 
 help
 
 int
 
 action
 
 float
 
 args = parser.parse_args()
 
 ipFpga = getFpgaIpv4(args)
 
 instId = getInstanceId(args)
 
 ipResMngr = getResourceManagerIpv4(args)
 
 portFpga = RECV_MODE_LSN_PORT
 
 portResMngr = getResourceManagerPort(args)
 
tuple fpgaAssociation = (str(ipFpga), portFpga)
 
int tcpSP = portFpga + 49152
 
tuple hostAssociation = (ipSaStr, tcpSP)
 
 tcpSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
 seed = args.seed
 
 size = args.size
 
 count = args.loop_count
 
 message = str_rand_gen(size)
 
 verbose = args.verbose
 

Function Documentation

◆ tcp_tx_loop()

def tc_TcpSend.tcp_tx_loop (   sock,
  message,
  count,
  verbose = False 
)
TCP Tx Single-Thread Loop.
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of segments to send.
 :param verbose  Enables verbosity.
 :return         None

Definition at line 38 of file tc_TcpSend.py.

38 def tcp_tx_loop(sock, message, count, verbose=False):
39  """TCP Tx Single-Thread Loop.
40  :param sock The socket to send/receive to/from.
41  :param message The message string to sent.
42  :param count The number of segments to send.
43  :param verbose Enables verbosity.
44  :return None"""
45  if verbose:
46  print("[INFO] The following message of %d bytes will be sent out %d times:\n Message=%s\n"
47  % (len(message), count, message.decode()))
48  nrErr = 0
49  loop = 0
50  txByteCnt = 0
51  startTime = datetime.datetime.now()
52  while loop < count:
53  # Send segment
54  # -------------------
55  try:
56  sock.sendall(message)
57  except socket.error as exc:
58  # Any exception
59  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
60  exit(1)
61  finally:
62  pass
63  txByteCnt += len(message)
64  if verbose:
65  print("Loop=%d | TxBytes=%d" % (loop, txByteCnt))
66  # if loop > 10:
67  # time.sleep(0.1)
68  # input('Hit <Enter> to continue:')
69  loop += 1
70  endTime = datetime.datetime.now()
71  elapseTime = endTime - startTime
72 
73  display_throughput(txByteCnt, elapseTime)
74 
def tcp_tx_loop(sock, message, count, verbose=False)
Definition: tc_TcpSend.py:38
def display_throughput(byteCount, elapseTime)
Definition: tc_utils.py:211
Here is the call graph for this function:

◆ tcp_tx_payload_ramp()

def tc_TcpSend.tcp_tx_payload_ramp (   sock,
  message,
  count,
  pause = 0.0,
  verbose = False 
)
TCP Tx Single-Thread Ramp. Send a buffer of bytes with 64-bit unsigned integer numbers
     ramping up from 1 to len(message).
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of segments to send.
 :param pause    The idle duration between two segments (in seconds)
 :param verbose  Enables verbosity.
 :return         None

Definition at line 116 of file tc_TcpSend.py.

116 def tcp_tx_payload_ramp(sock, message, count, pause=0.0, verbose=False):
117  """TCP Tx Single-Thread Ramp. Send a buffer of bytes with 64-bit unsigned integer numbers
118  ramping up from 1 to len(message).
119  :param sock The socket to send/receive to/from.
120  :param message The message string to sent.
121  :param count The number of segments to send.
122  :param pause The idle duration between two segments (in seconds)
123  :param verbose Enables verbosity.
124  :return None"""
125  strStream = ""
126  size = len(message) * count
127  if size <= 8:
128  for i in range(0, size-1):
129  strStream += '0'
130  else:
131  rampSize = int(size/8)
132  for i in range(0, rampSize):
133  strTmp = "{:08d}".format(i)
134  # Swap the generated 8 bytes
135  strStream += strTmp[7]
136  strStream += strTmp[6]
137  strStream += strTmp[5]
138  strStream += strTmp[4]
139  strStream += strTmp[3]
140  strStream += strTmp[2]
141  strStream += strTmp[1]
142  strStream += strTmp[0]
143  for i in range(0, int(size % 8)):
144  strStream += 'E'
145  bytStream = strStream.encode()
146 
147  if verbose:
148  print("[INFO] The following stream of %d bytes will be sent out:\n Message=%s\n" %
149  (len(message), bytStream.decode()))
150 
151  startTime = datetime.datetime.now()
152 
153  if pause == 0.0:
154  # --------------------------------
155  # Send the entire stream at once
156  # --------------------------------
157  try:
158  sock.sendall(bytStream)
159  except socket.error as exc:
160  # Any exception
161  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
162  exit(1)
163  finally:
164  pass
165  else:
166  # --------------------------------------
167  # Send the stream in pieces of 8 bytes.
168  # The use of a 'pause' enforces the TCP 'PSH'
169  # --------------------------------------
170  for i in range(0, rampSize):
171  subStr = bytStream[i*8: i*8+8]
172  try:
173  sock.sendall(subStr)
174  except socket.error as exc:
175  # Any exception
176  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
177  exit(1)
178  finally:
179  pass
180  time.sleep(pause)
181  if size % 8:
182  subStr = bytStream[(size/8)*8: (size/8)*8 + (size % 8)]
183  try:
184  sock.sendall(subStr)
185  except socket.error as exc:
186  # Any exception
187  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
188  exit(1)
189  finally:
190  pass
191  time.sleep(pause)
192 
193  endTime = datetime.datetime.now()
194  elapseTime = endTime - startTime
195 
196  txByteCnt = len(message) * count
197  display_throughput(txByteCnt, elapseTime)
198 
def tcp_tx_payload_ramp(sock, message, count, pause=0.0, verbose=False)
Definition: tc_TcpSend.py:116
Here is the call graph for this function:

◆ tcp_tx_seg_size_ramp()

def tc_TcpSend.tcp_tx_seg_size_ramp (   sock,
  message,
  count,
  pause = 0.0,
  verbose = False 
)
Send a ramp of increasing segment sizes starting from 1 bytes up to len(message).
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of segments to send.
 :param pause    The idle duration between two segments (in seconds)
 :param verbose  Enables verbosity.
 :return         None

Definition at line 199 of file tc_TcpSend.py.

199 def tcp_tx_seg_size_ramp(sock, message, count, pause=0.0, verbose=False):
200  """Send a ramp of increasing segment sizes starting from 1 bytes up to len(message).
201  :param sock The socket to send/receive to/from.
202  :param message The message string to sent.
203  :param count The number of segments to send.
204  :param pause The idle duration between two segments (in seconds)
205  :param verbose Enables verbosity.
206  :return None"""
207 
208  nrErr = 0
209  loop = 0
210  txByteCnt = 0
211  startTime = datetime.datetime.now()
212 
213  while loop < count:
214  for i in range(1, len(message)):
215  # Send segment of length 'i'
216  subMsg = message[0: i]
217  try:
218  sock.sendall(subMsg)
219  except socket.error as exc:
220  # Any exception
221  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
222  exit(1)
223  finally:
224  pass
225  txByteCnt += len(message)
226  if verbose:
227  print("Loop=%4.4d | SegmentLength=%4.4d" % (loop, i))
228  if pause != 0.0:
229  time.sleep(pause)
230  loop += 1
231 
232  endTime = datetime.datetime.now()
233  elapseTime = endTime - startTime
234 
235  display_throughput(txByteCnt, elapseTime)
236 
237 
def tcp_tx_seg_size_ramp(sock, message, count, pause=0.0, verbose=False)
Definition: tc_TcpSend.py:199
Here is the call graph for this function:

◆ tcp_tx_slowpace()

def tc_TcpSend.tcp_tx_slowpace (   sock,
  message,
  count,
  pause,
  verbose = False 
)
TCP Tx test at reduce speed (by inserting a sleep duration in between two transmissions)
 :param sock     The socket to send/receive to/from.
 :param message  The message string to sent.
 :param count    The number of segments to send.
 :param pause    The idle duration between two segments (in seconds)
 :param verbose  Enables verbosity.
 :return         None

Definition at line 75 of file tc_TcpSend.py.

75 def tcp_tx_slowpace(sock, message, count, pause, verbose=False):
76  """TCP Tx test at reduce speed (by inserting a sleep duration in between two transmissions)
77  :param sock The socket to send/receive to/from.
78  :param message The message string to sent.
79  :param count The number of segments to send.
80  :param pause The idle duration between two segments (in seconds)
81  :param verbose Enables verbosity.
82  :return None"""
83  if verbose:
84  print("[INFO] TCP-TX-SLOW-PACE: The following message of %d bytes will be sent out %d times"
85  " with an inter-gap time of %f seconds:\n Message=%s\n" %
86  (len(message), count, pause, message.decode()))
87  nrErr = 0
88  loop = 0
89  totalByteCnt = 0
90  txWinByteCnt = 0
91  startTime = datetime.datetime.now()
92  while loop < count:
93  # Send segment
94  # -------------------
95  try:
96  sock.sendall(message)
97  except socket.error as exc:
98  # Any exception
99  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
100  exit(1)
101  finally:
102  pass
103  txWinByteCnt += len(message)
104  totalByteCnt += len(message)
105  if verbose:
106  print("Loop=%6d | TotalTxBytes=%6d | Pause=%4f sec" % (loop+1, totalByteCnt, pause))
107  time.sleep(pause)
108  txWinByteCnt = 0
109  loop += 1
110  endTime = datetime.datetime.now()
111  elapseTime = endTime - startTime
112 
113  display_throughput(totalByteCnt, elapseTime)
114 
115 
def tcp_tx_slowpace(sock, message, count, pause, verbose=False)
Definition: tc_TcpSend.py:75
Here is the call graph for this function:

Variable Documentation

◆ action

tc_TcpSend.action

Definition at line 257 of file tc_TcpSend.py.

◆ args

tc_TcpSend.args = parser.parse_args()

Definition at line 272 of file tc_TcpSend.py.

◆ count

tc_TcpSend.count = args.loop_count

Definition at line 383 of file tc_TcpSend.py.

◆ default

tc_TcpSend.default

Definition at line 247 of file tc_TcpSend.py.

◆ float

tc_TcpSend.float

Definition at line 261 of file tc_TcpSend.py.

◆ fpgaAssociation

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

Definition at line 310 of file tc_TcpSend.py.

◆ help

tc_TcpSend.help

Definition at line 248 of file tc_TcpSend.py.

◆ hostAssociation

tuple tc_TcpSend.hostAssociation = (ipSaStr, tcpSP)

Definition at line 322 of file tc_TcpSend.py.

◆ instId

tc_TcpSend.instId = getInstanceId(args)

Definition at line 285 of file tc_TcpSend.py.

◆ int

tc_TcpSend.int

Definition at line 249 of file tc_TcpSend.py.

◆ ipFpga

tc_TcpSend.ipFpga = getFpgaIpv4(args)

Definition at line 281 of file tc_TcpSend.py.

◆ ipResMngr

tc_TcpSend.ipResMngr = getResourceManagerIpv4(args)

Definition at line 289 of file tc_TcpSend.py.

◆ message

string tc_TcpSend.message = str_rand_gen(size)

Definition at line 387 of file tc_TcpSend.py.

◆ parser

tc_TcpSend.parser = argparse.ArgumentParser(description='A script to send TCP data to an FPGA module.')
                                        #

MAIN # #

Definition at line 246 of file tc_TcpSend.py.

◆ portFpga

tc_TcpSend.portFpga = RECV_MODE_LSN_PORT

Definition at line 293 of file tc_TcpSend.py.

◆ portResMngr

tc_TcpSend.portResMngr = getResourceManagerPort(args)

Definition at line 297 of file tc_TcpSend.py.

◆ seed

tc_TcpSend.seed = args.seed

Definition at line 367 of file tc_TcpSend.py.

◆ size

tc_TcpSend.size = args.size

Definition at line 373 of file tc_TcpSend.py.

◆ str

tc_TcpSend.str

Definition at line 247 of file tc_TcpSend.py.

◆ tcpSock

tc_TcpSend.tcpSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

Definition at line 327 of file tc_TcpSend.py.

◆ tcpSP

int tc_TcpSend.tcpSP = portFpga + 49152

Definition at line 321 of file tc_TcpSend.py.

◆ type

tc_TcpSend.type

Definition at line 247 of file tc_TcpSend.py.

◆ verbose

tc_TcpSend.verbose = args.verbose

Definition at line 391 of file tc_TcpSend.py.