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

Functions

def udp_tx_loop (sock, message, count, verbose=False)
 
def udp_tx_ramp (sock, message, count, verbose=False)
 

Variables

 parser = argparse.ArgumentParser(description='A script to send UDP data to an FPGA module.')
 
 type
 
 str
 
 default
 
 help
 
 int
 
 action
 
 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 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
 

Function Documentation

◆ udp_tx_loop()

def tc_UdpSend.udp_tx_loop (   sock,
  message,
  count,
  verbose = False 
)
UDP 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 datagrams to send.
 :param verbose  Enables verbosity.
 :return         None

Definition at line 37 of file tc_UdpSend.py.

37 def udp_tx_loop(sock, message, count, verbose=False):
38  """UDP Tx Single-Thread Loop.
39  :param sock The socket to send/receive to/from.
40  :param message The message string to sent.
41  :param count The number of datagrams to send.
42  :param verbose Enables verbosity.
43  :return None"""
44  if verbose:
45  print("[INFO] The following message of %d bytes will be sent out %d times:\n Message=%s\n" %
46  (len(message), count, message.decode()))
47  nrErr = 0
48  loop = 0
49  txByteCnt = 0
50  startTime = datetime.datetime.now()
51  while loop < count:
52  # Send datagram
53  # -------------------
54  try:
55  sock.sendall(message)
56  except socket.error as exc:
57  # Any exception
58  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
59  exit(1)
60  finally:
61  pass
62  txByteCnt += len(message)
63  if verbose:
64  print("Loop=%d | TxBytes=%d" % (loop, txByteCnt))
65  loop += 1
66  endTime = datetime.datetime.now()
67  elapseTime = endTime - startTime
68 
69  if txByteCnt < 1000000:
70  print("[INFO] Transferred a total of %d bytes." % txByteCnt)
71  elif txByteCnt < 1000000000:
72  megaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1.0)
73  print("[INFO] Transferred a total of %.1f MB." % megaBytes)
74  else:
75  gigaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1024 * 1.0)
76  print("[INFO] Transferred a total of %.1f GB." % gigaBytes)
77 
78  bandwidth = (txByteCnt * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
79  print("#####################################################")
80  if bandwidth < 1000:
81  print("#### UDP Tx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
82  else:
83  bandwidth = bandwidth / 1000
84  print("#### UDP Tx DONE with bandwidth = %2.1f Gb/s ####" % bandwidth)
85  print("#####################################################")
86  print()
87 
88 
def udp_tx_loop(sock, message, count, verbose=False)
Definition: tc_UdpSend.py:37

◆ udp_tx_ramp()

def tc_UdpSend.udp_tx_ramp (   sock,
  message,
  count,
  verbose = False 
)
UDP Tx 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 89 of file tc_UdpSend.py.

89 def udp_tx_ramp(sock, message, count, verbose=False):
90  """UDP Tx Single-Thread Ramp.
91  :param sock The socket to send/receive to/from.
92  :param message The message string to sent.
93  :param count The number of datagrams to send.
94  :param verbose Enables verbosity.
95  :return None"""
96  if verbose:
97  print("[INFO] The following message of %d bytes will be sent out incrementally %d times:\n Message=%s\n" %
98  (len(message), count, message.decode()))
99  nrErr = 0
100  loop = 0
101  txByteCnt = 0
102  startTime = datetime.datetime.now()
103  while loop < count:
104  i = 1
105  while i <= len(message):
106  subMsg = message[0:i]
107  # Send datagram
108  # -------------------
109  try:
110  udpSock.sendall(subMsg)
111  except socket.error as exc:
112  # Any exception
113  print("[EXCEPTION] Socket error while transmitting :: %s" % exc)
114  exit(1)
115  finally:
116  pass
117  txByteCnt += len(subMsg)
118  if verbose:
119  print("Loop=%d | TxBytes=%d | Msg=%s" % (loop, len(subMsg), subMsg))
120  i += 1
121  loop += 1
122  endTime = datetime.datetime.now()
123  elapseTime = endTime - startTime
124 
125  if txByteCnt < 1000000:
126  print("[INFO] Transferred a total of %d bytes." % txByteCnt)
127  elif txByteCnt < 1000000000:
128  megaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1.0)
129  print("[INFO] Transferred a total of %.1f MB." % megaBytes)
130  else:
131  gigaBytes = (txByteCnt * 1.0) / (1024 * 1024 * 1024 * 1.0)
132  print("[INFO] Transferred a total of %.1f GB." % gigaBytes)
133 
134  bandwidth = (txByteCnt * 8 * 1.0) / (elapseTime.total_seconds() * 1024 * 1024)
135  print("#####################################################")
136  if bandwidth < 1000:
137  print("#### UDP Tx DONE with bandwidth = %6.1f Mb/s ####" % bandwidth)
138  else:
139  bandwidth = bandwidth / 1000
140  print("#### UDP Tx DONE with bandwidth = %2.1f Gb/s ####" % bandwidth)
141  print("#####################################################")
142  print()
143 
144 
def udp_tx_ramp(sock, message, count, verbose=False)
Definition: tc_UdpSend.py:89

Variable Documentation

◆ action

tc_UdpSend.action

Definition at line 172 of file tc_UdpSend.py.

◆ args

tc_UdpSend.args = parser.parse_args()

Definition at line 175 of file tc_UdpSend.py.

◆ count

tc_UdpSend.count = args.loop_count

Definition at line 287 of file tc_UdpSend.py.

◆ default

tc_UdpSend.default

Definition at line 154 of file tc_UdpSend.py.

◆ fpgaAssociation

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

Definition at line 211 of file tc_UdpSend.py.

◆ help

tc_UdpSend.help

Definition at line 155 of file tc_UdpSend.py.

◆ hostAssociation

tuple tc_UdpSend.hostAssociation = (ipSaStr, udpSP)

Definition at line 223 of file tc_UdpSend.py.

◆ instId

tc_UdpSend.instId = getInstanceId(args)

Definition at line 187 of file tc_UdpSend.py.

◆ int

tc_UdpSend.int

Definition at line 156 of file tc_UdpSend.py.

◆ ipFpga

tc_UdpSend.ipFpga = getFpgaIpv4(args)

Definition at line 183 of file tc_UdpSend.py.

◆ ipResMngr

tc_UdpSend.ipResMngr = getResourceManagerIpv4(args)

Definition at line 191 of file tc_UdpSend.py.

◆ message

tc_UdpSend.message = str_static_gen(size)

Definition at line 291 of file tc_UdpSend.py.

◆ parser

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

MAIN # #

Definition at line 153 of file tc_UdpSend.py.

◆ portFpga

tc_UdpSend.portFpga = RECV_MODE_LSN_PORT

Definition at line 195 of file tc_UdpSend.py.

◆ portResMngr

tc_UdpSend.portResMngr = getResourceManagerPort(args)

Definition at line 199 of file tc_UdpSend.py.

◆ seed

tc_UdpSend.seed = args.seed

Definition at line 271 of file tc_UdpSend.py.

◆ size

tc_UdpSend.size = args.size

Definition at line 278 of file tc_UdpSend.py.

◆ str

tc_UdpSend.str

Definition at line 154 of file tc_UdpSend.py.

◆ type

tc_UdpSend.type

Definition at line 154 of file tc_UdpSend.py.

◆ udpSock

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

Definition at line 228 of file tc_UdpSend.py.

◆ udpSP

int tc_UdpSend.udpSP = portFpga + 49152

Definition at line 222 of file tc_UdpSend.py.

◆ verbose

tc_UdpSend.verbose = args.verbose

Definition at line 295 of file tc_UdpSend.py.