Project 01 In Project 01, you need to implement NetProbe. More specifically, you need to implement the following functions:
• Host mode
• Receive function for TCP (stream socket)
• Send function for TCP
• Receive function for UDP (Datagram socket)
• Send function for UDP
Sample code is provided at references:
• TCP: https://www.binarytides.com/winsock-socket-programming-tutorial/
• UDP: https://www.binarytides.com/programming-udp-sockets-c-linux/
Input parameters You need to get the following statistics
• stat
• pktsize
• pktrate
• pktnum
• sbufsize: sender buffer size
• rbufsize: receiver buffer size
• lhost: reciever’s local host (hostname or IP)
• lport: reciever’s listen port number
• rhost: sender’s remote host
• rport: sender’s remote port number
• proto: TCP/UDP
Input parameters Set buffer size (sbufsize, rbufsize)
• Call setsockopt (refer p.69)
Server parameter: (lhost, lport)
• Used for server (receiver) bind address
Client parameter: (rhost, rport)
• Used for client (sender) connect
Input parameters (stat)
• Display time, of the statistics
pktnum
• Number of message in application layer (NOT number of packet!!!!)
• For UDP: Number of message = Number of packet
• For TCP: A message is split into multiple packet.
pktsize
• Which is also the message size (Not the packet size!!!)
• For UDP: Number of message = Number of packet
• For TCP: A message is split into multiple packet.
• Do not mix these two.
Output statistics You need to get the following statistics
• Elapsed: which is “-stat’, the rest is during “-stat” ms
• Pkts: number of packet send/recv
• Lost: number/ratio of packet loss, note that only UDP receiver side need “Lost”
• Rate: Throughput
• Jitter: Inter packet arrival time variation
TCP (stream) Receive function
Here I will use TCP receive as an example to tell you how to calculate the statistics
Sample code:
TCP (stream) Receive function
Got time in milliseconds:
• My method is use clock_t in “time.h”
Sample code:
clock_t current_clock, previous_clock = clock();
while (true) {
double time_cost = (double)(current_clock - previous_clock) / CLOCKS_PER_SEC;
cum_time_cost = cum_time_cost + time_cost;
if (cum_time_cost > “-stat”){
// print your statistic messages
}
}
TCP (stream) Receive function Record the statistic:
• Use variable to record the number of packet, and the total received size
Sample code:
double cum_time_cost = 0, cum_bytes_recv = 0, total_time_cost = 0;
int recv_size, cum_packet_number = 0, cum_receive_size = 0, total_packet_number = 0;
while(…){
int recv_size = recv(sockfd_serve_client, peer_data, fetch_size, 0);
cum_receive_size = cum_receive_size + recv_size;
cum_packet_number++;
}