lib/sw_apps/freertos_lwip_udp_perf_server/src/udp_perf_server.c
static void udp_recv_perf_traffic(int sock)
{
	u8_t first = 1;
	u32_t drop_datagrams = 0;
	s32_t recv_id;
	int count;
	char recv_buf[UDP_RECV_BUFSIZE];
	struct sockaddr_in from;
	socklen_t fromlen = sizeof(from);

	while (1) {
		if((count = lwip_recvfrom(sock, recv_buf, UDP_RECV_BUFSIZE, 0,
				(struct sockaddr *)&from, &fromlen)) <= 0) {
			continue;
		}

		/* first, check if the datagram is received in order */
		recv_id = ntohl(*((int *)recv_buf));

		if (first && (recv_id == 0)) {
			/* First packet should always start with recv id 0.
			 * However, If Iperf client is running with parallel
			 * thread, then this condition will also avoid
			 * multiple print of connection header
			 */
			reset_stats();
			/* Print connection statistics */
			print_udp_conn_stats(from);
			first = 0;
		} else if (first) {
			/* Avoid rest of the packets if client
			 * connection is already terminated.
			 */
			continue;
		}

		if (recv_id < 0) {
			u64_t now = sys_now();
			u64_t diff_ms = now - server.start_time;
			/* Send Ack */
			if (sendto(sock, recv_buf, count, 0,
				(struct sockaddr *)&from, fromlen) < 0) {
				xil_printf("Error in write\n\r");
			}

			udp_conn_report(diff_ms, UDP_DONE_SERVER);
			xil_printf("UDP test passed Successfully\n\r");
			first = 1;
			continue;
		}

		/* Update dropped datagrams statistics */
		if (server.expected_datagram_id != recv_id) {
			if (server.expected_datagram_id < recv_id) {
				drop_datagrams =
					recv_id - server.expected_datagram_id;
				server.cnt_dropped_datagrams += drop_datagrams;
				server.i_report.cnt_dropped_datagrams += drop_datagrams;
				server.expected_datagram_id = recv_id + 1;
			} else if (server.expected_datagram_id > recv_id) {
				server.cnt_out_of_order_datagrams++;
			}
		} else {
			server.expected_datagram_id++;
		}

		server.cnt_datagrams++;

		/* Record total bytes for final report */
		server.total_bytes += count;

		if (REPORT_INTERVAL_TIME) {
			u64_t now = sys_now();

			server.i_report.cnt_datagrams++;

			/* Record total bytes for interim report */
			server.i_report.total_bytes += count;
			if (server.i_report.start_time) {
				u64_t diff_ms = now - server.i_report.start_time;

				if (diff_ms >= REPORT_INTERVAL_TIME) {
					udp_conn_report(diff_ms, INTER_REPORT);
					/* Reset Interim report counters */
					server.i_report.start_time = 0;
					server.i_report.total_bytes = 0;
					server.i_report.cnt_datagrams = 0;
					server.i_report.cnt_dropped_datagrams = 0;
				}
			} else {
				/* Save start time for interim report */
				server.i_report.start_time = now;
			}
		}
	}
}
/** Receive data on a udp session */
Receive data on a udp session
Receive data on a udp session
static void udp_recv_perf_traffic(int sock)
{
	u8_t first = 1;
	u32_t drop_datagrams = 0;
	s32_t recv_id;
	int count;
	char recv_buf[UDP_RECV_BUFSIZE];
	struct sockaddr_in from;
	socklen_t fromlen = sizeof(from);
	while (1) {
		if((count = lwip_recvfrom(sock, recv_buf, UDP_RECV_BUFSIZE, 0,
				(struct sockaddr *)&from, &fromlen)) <= 0) {
			continue;
		}
		recv_id = ntohl(*((int *)recv_buf));
		if (first && (recv_id == 0)) {
			reset_stats();
			print_udp_conn_stats(from);
			first = 0;
		} else if (first) {
			continue;
		}
		if (recv_id < 0) {
			u64_t now = sys_now();
			u64_t diff_ms = now - server.start_time;
			if (sendto(sock, recv_buf, count, 0,
				(struct sockaddr *)&from, fromlen) < 0) {
				xil_printf("Error in write\n\r");
			}
			udp_conn_report(diff_ms, UDP_DONE_SERVER);
			xil_printf("UDP test passed Successfully\n\r");
			first = 1;
			continue;
		}
		if (server.expected_datagram_id != recv_id) {
			if (server.expected_datagram_id < recv_id) {
				drop_datagrams =
					recv_id - server.expected_datagram_id;
				server.cnt_dropped_datagrams += drop_datagrams;
				server.i_report.cnt_dropped_datagrams += drop_datagrams;
				server.expected_datagram_id = recv_id + 1;
			} else if (server.expected_datagram_id > recv_id) {
				server.cnt_out_of_order_datagrams++;
			}
		} else {
			server.expected_datagram_id++;
		}
		server.cnt_datagrams++;
		server.total_bytes += count;
		if (REPORT_INTERVAL_TIME) {
			u64_t now = sys_now();
			server.i_report.cnt_datagrams++;
			server.i_report.total_bytes += count;
			if (server.i_report.start_time) {
				u64_t diff_ms = now - server.i_report.start_time;
				if (diff_ms >= REPORT_INTERVAL_TIME) {
					udp_conn_report(diff_ms, INTER_REPORT);
					server.i_report.start_time = 0;
					server.i_report.total_bytes = 0;
					server.i_report.cnt_datagrams = 0;
					server.i_report.cnt_dropped_datagrams = 0;
				}
			} else {
				server.i_report.start_time = now;
			}
		}
	}
}
static void udp_recv_perf_traffic ( int sock ) { u8_t first = 1 ; u32_t drop_datagrams = 0 ; s32_t recv_id ; int count ; char recv_buf [ UDP_RECV_BUFSIZE ] ; struct sockaddr_in from ; socklen_t fromlen = sizeof ( from ) ; while ( 1 ) { if ( ( count = lwip_recvfrom ( sock , recv_buf , UDP_RECV_BUFSIZE , 0 , ( struct sockaddr * ) & from , & fromlen ) ) <= 0 ) { continue ; } recv_id = ntohl ( * ( ( int * ) recv_buf ) ) ; if ( first && ( recv_id == 0 ) ) { reset_stats ( ) ; print_udp_conn_stats ( from ) ; first = 0 ; } else if ( first ) { continue ; } if ( recv_id < 0 ) { u64_t now = sys_now ( ) ; u64_t diff_ms = now - server . start_time ; if ( sendto ( sock , recv_buf , count , 0 , ( struct sockaddr * ) & from , fromlen ) < 0 ) { xil_printf ( " \n \r " ) ; } udp_conn_report ( diff_ms , UDP_DONE_SERVER ) ; xil_printf ( " \n \r " ) ; first = 1 ; continue ; } if ( server . expected_datagram_id != recv_id ) { if ( server . expected_datagram_id < recv_id ) { drop_datagrams = recv_id - server . expected_datagram_id ; server . cnt_dropped_datagrams += drop_datagrams ; server . i_report . cnt_dropped_datagrams += drop_datagrams ; server . expected_datagram_id = recv_id + 1 ; } else if ( server . expected_datagram_id > recv_id ) { server . cnt_out_of_order_datagrams ++ ; } } else { server . expected_datagram_id ++ ; } server . cnt_datagrams ++ ; server . total_bytes += count ; if ( REPORT_INTERVAL_TIME ) { u64_t now = sys_now ( ) ; server . i_report . cnt_datagrams ++ ; server . i_report . total_bytes += count ; if ( server . i_report . start_time ) { u64_t diff_ms = now - server . i_report . start_time ; if ( diff_ms >= REPORT_INTERVAL_TIME ) { udp_conn_report ( diff_ms , INTER_REPORT ) ; server . i_report . start_time = 0 ; server . i_report . total_bytes = 0 ; server . i_report . cnt_datagrams = 0 ; server . i_report . cnt_dropped_datagrams = 0 ; } } else { server . i_report . start_time = now ; } } } }
Receive data on a udp session
Receive data on a udp session
/* first, check if the datagram is received in order */ /* First packet should always start with recv id 0.
			 * However, If Iperf client is running with parallel
			 * thread, then this condition will also avoid
			 * multiple print of connection header
			 */ /* Print connection statistics */ /* Avoid rest of the packets if client
			 * connection is already terminated.
			 */ /* Send Ack */ /* Update dropped datagrams statistics */ /* Record total bytes for final report */ /* Record total bytes for interim report */ /* Reset Interim report counters */ /* Save start time for interim report */