79 unsigned int timeout_count;
80 unsigned int idle_count;
82 double t_display_timer;
98 uint16_t bindex_next_expected;
99 uint16_t packet_crc_scratch;
102 uint32_t packet_count;
103 uint32_t packet_count_dropped;
104 uint32_t packet_count_crc_err;
105 uint32_t packet_count_runt;
106 uint32_t data_accumulator=0;
107 double initial_t,final_t;
109 double data_rate_min,data_rate_max;
110 double data_rate_avg;
111 double data_rate_accumulator;
112 uint32_t data_rate_count;
116 double ref_t,new_t,delta_t;
117 double t_accumulator,t_count;
118 double t_min,t_max,t_avg;
143 data_rate_min=99999999;
145 data_rate_accumulator=0;
153 bindex_next_expected = 0;
154 packet_count_dropped = 0;
155 packet_count_crc_err = 0;
156 packet_count_runt = 0;
162 printf(
"Packet Size [bytes]\tSpeed [bytes/sec]\tRX Time[us]\tPackets Received\tPacket Drops\tPacket CRC Errors\tPacket Runts\tBytes Received\tData Rate: Min [bytes/sec]\tData Rate: Average [bytes/sec]\tData Rate: Max [bytes/sec]\tInter-Packet Delay: Min [us]\tInter-Packet Delay: Avg [us]\tInter-Packet Delay: Max [us]\n");
176 printf(
"Err: Unable to open connection to [%s:%d]\n",
address,
port);
179 if(!quietmode) printf(
"Netperf Listen is now listening on port %d...\n\n",
port);
185 received = recvfrom( chan.
cudp, (
char *)buf1,
BUFSIZE, 0, (
struct sockaddr*) &chan.
caddr, (socklen_t*) &fromlen);
192 if(!quietmode) printf(
"[Idle %d...%d]\n",idle_count, received);
193 if(!quietmode) fflush(stdout);
195 if(idle_count >= timeout_count && firstpacket ==
true)
197 if(!quietmode) printf(
"Idle timeout after activity, exiting.\n\n");
203 data_rate = data_accumulator / ( (final_t - initial_t) / 1000000);
206 if(!quietmode) printf(
"Final Report: \n");
210 t_avg = t_accumulator / t_count;
216 printf(
"%.0f\t%d\t%d\t%d\t%d\t%.0f\t%.0f\n",(final_t-initial_t),packet_count,packet_count_dropped,packet_count_crc_err,data_accumulator,data_rate,t_avg);
229 delta_t = new_t - ref_t;
231 if (delta_t < t_min) t_min = delta_t;
232 if (delta_t > t_max) t_max = delta_t;
233 t_accumulator += delta_t;
235 t_avg = t_accumulator / t_count;
239 strncpy(buf2,(
const char *)buf1,
INFO_SIZE);
241 sscanf((
char *)buf2,
"%lf %hu %hx %hu",&cmjd,&bindex,&crc,&bsize);
244 printf(
"Packet: %f, %hu, %hx, %hu\n", cmjd, bindex, crc, bsize);
245 printf(
"PACKET: %s\n",buf2);
251 if(bindex != bindex_next_expected)
253 packet_count_dropped+=(bindex - bindex_next_expected);
254 if (!quietmode) printf(
"\nError: Index Received: %u, Index Expected: %u, Missed %d packets\n", bindex, bindex_next_expected, bindex-bindex_next_expected);
256 bindex_next_expected = bindex + 1;
274 if (received < bsize)
277 if (!quietmode) printf(
"\nError: Bytes dropped: packet %d expected %u received %u\n", bindex_next_expected, bsize, received);
283 if (crc != packet_crc_scratch)
285 packet_count_crc_err++;
286 if (!quietmode) printf(
"\nError: Index %d has bad CRC when comparing packet %x to calc %x. \n",bindex, crc, packet_crc_scratch);
288 if (
debug_verbose)printf(
"\nIndex %d packet %x calc %x \n",bindex, crc, packet_crc_scratch);
295 data_accumulator += received;
299 t_display_timer += delta_t;
305 initial_t = data_ref_t = new_t;
307 t_display_timer = 0 ;
308 data_accumulator -= received;
315 if (t_display_timer > 1000000) {
317 t_display_timer -= 1000000;
320 data_rate = (data_accumulator) / ((new_t - data_ref_t) / 1000000) ;
321 data_rate_accumulator += data_rate;
323 data_rate_avg = data_rate_accumulator / data_rate_count;
324 if (data_rate < data_rate_min) data_rate_min = data_rate;
325 if (data_rate > data_rate_max) data_rate_max = data_rate;
330 printf(
"%d packets: DRate(1s/Avg): %.1f/%.1f [Bytes/s], I-P Time (Min/Avg/Max): %.0f/%.0f/%.0f [us]\n",packet_count,data_rate,data_rate_avg,t_min,t_avg,t_max);
static double cmjd
Definition: agent_monitor.cpp:121
Agent socket using Unicast UDP.
bool debug_verbose
Definition: netperf_listen.cpp:68
uint16_t bsize
Definition: netperf_listen.cpp:71
int iretn
Definition: rw_test.cpp:37
png_uint_32 crc
Definition: png.c:2173
#define BUFSIZE
Definition: netperf_listen.cpp:64
char address[]
Definition: netperf_listen.cpp:69
int32_t cudp
Definition: socketlib.h:120
#define INFO_SIZE
Definition: netperf_listen.cpp:65
Definition: socketlib.h:115
struct sockaddr_in caddr
Definition: socketlib.h:122
#define SOCKET_BLOCKING
Blocking Agent.
Definition: socketlib.h:78
uint16_t slip_calc_crc(uint8_t *buf, uint16_t size)
Calculate CRC-16-CCITT.
Definition: sliplib.cpp:322
#define SOCKET_LISTEN
Listen followed by optional talk (recvfrom INADDRANY)
Definition: socketlib.h:84
int32_t socket_open(socket_channel *channel, NetworkType ntype, const char *address, uint16_t port, uint16_t role, bool blocking, uint32_t usectimeo, uint32_t rcvbuf, uint32_t sndbuf)
Open UDP socket.
Definition: socketlib.cpp:51
uint16_t port
Definition: netperf_listen.cpp:70
#define CURRENT_TIME_us
Definition: netperf_listen.cpp:66