Tutorial 04 - IE Course Webpage

11
Tutorial 04 ZHANG Yuming [email protected] Week 04

Transcript of Tutorial 04 - IE Course Webpage

Tutorial 04 ZHANG Yuming

[email protected]

Week 04

Overview

This tutorial give hint of the coding for Project 01.

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++;

}

TCP (stream) Receive function Print statistics:

Sample code:

double throughput = (cum_bytes_recv * 8) / (cum_time_cost * 1000000);

printf("Receiver: [Elapsed] %.2f ms, [Pkts] %d, [Rate] %.2f Mbps\n", cum_time_cost * 1000, cum_packet_number,

throughput);