100% found this document useful (1 vote)
448 views

Programming Assignment 2 Udp Pinger Ver

This programming assignment requires students to write a client program that works with a provided UDP ping server program. The client must send 10 ping messages to the server and calculate statistics like round trip time, packet loss, estimated RTT, deviation RTT, and timeout interval. It must handle packet loss and timeout of requests. The submission must include client and server code, meeting minutes, output screenshots, and an output checker spreadsheet.

Uploaded by

api-479141525
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
448 views

Programming Assignment 2 Udp Pinger Ver

This programming assignment requires students to write a client program that works with a provided UDP ping server program. The client must send 10 ping messages to the server and calculate statistics like round trip time, packet loss, estimated RTT, deviation RTT, and timeout interval. It must handle packet loss and timeout of requests. The submission must include client and server code, meeting minutes, output screenshots, and an output checker spreadsheet.

Uploaded by

api-479141525
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming Assignment 2

CST 311-30, Introduction to Computer Networks, Online Summer A 2020

READ INSTRUCTIONS CAREFULLY BEFORE YOU START THE ASSIGNMENT.

This programming assignment is due on Tuesday, May 26, 2020.

Assignment must be submitted electronically to iLearn on https://ilearn.csumb.edu by 11:59


p.m. on the due date. Late assignments will not be accepted.

This assignment requires you to work with teams assigned to you on the Team Assignment
Document in Week 1. You must also adhere to the instructions on the Programming Process
document.

Follow the steps below to develop and write the client part of a client server application. The
naming convention of the file should be PA2_your_last_names_in_alphabetic_order.py. Put
your names in the program as well. Your client program must work with the server program
given to you below. Your program must have sufficient comments to clearly explain how your
code works.

This assignment is worth 175 points. The grading objectives for the assignment are given below.

UDP Pinger
In this assignment, you will learn the basics of socket programming for UDP in Python. You will
learn how to send and receive datagram packets using UDP sockets and also, how to set a
proper socket timeout. Throughout the assignment, you will gain familiarity with a Ping
application and its usefulness in computing statistics such as packet loss rate.

You will first study a simple Internet ping server written in Python, and implement a
corresponding client. The functionality provided by these programs is similar to the functionality
provided by standard ping programs available in modern operating systems. However, these
programs use a simpler protocol, UDP, rather than the standard Internet Control Message
Protocol (ICMP) to communicate with each other. The ping protocol allows a client machine to
send a packet of data to a remote machine, and have the remote machine return the data back
to the client unchanged (an action referred to as echoing). Among other uses, the ping protocol
allows hosts to determine round-trip times to other machines.

You are given the complete code for the Ping server below. Your task is to write the Ping client.
Server starter Code
The following code fully implements a ping server. You can use the server code given below as
starter code for the assignment. You need to compile and run this code before running your
client program.

In this server code, 30% of the client’s packets are simulated to be lost. You should study this
code carefully, as it will help you write your ping client.

# Server.py

# We will need the following module to generate randomized lost packets

import random

from socket import *

# Create a UDP socket

# Notice the use of SOCK_DGRAM for UDP packets

serverSocket = socket(AF_INET, SOCK_DGRAM)

# Assign IP address and port number to socket

serverSocket.bind(('', 12000))

while True:

# Generate random number in the range of 0 to 10

rand = random.randint(0, 10)

# Receive the client packet along with the address it is coming from

message, address = serverSocket.recvfrom(1024)

# If rand is less is than 4, we consider the packet lost and do not


respond

if rand < 4:

continue

# Otherwise, the server responds

serverSocket.sendto(message, address)

The server sits in an infinite loop listening for incoming UDP packets. When a packet comes in
and if a randomized integer is greater than or equal to 4, the server simply capitalizes the
encapsulated data and sends it back to the client.
Packet Loss
UDP provides applications with an unreliable transport service. Messages may get lost in the
network due to router queue overflows, faulty hardware or some other reasons. Because packet
loss is rare or even non-existent in typical campus networks, the server in this assignment injects
artificial loss to simulate the effects of network packet loss. The server creates a variable
randomized integer which determines whether a particular incoming packet is lost or not.

Client Code
The client should send 10 pings to the server. See the Message Format below for each ping to be
sent to the Server. Also print the message that is sent to the server.

Because UDP is an unreliable protocol, a packet sent from the client to the server may be lost in
the network, or vice versa. For this reason, the client cannot wait indefinitely for a reply to a
ping message. You should get the client to wait up to one second for a reply; if no reply is
received within one second, your client program should assume that the packet was lost during
transmission across the network. You will need to look up the Python documentation to find out
how to set the timeout value on a datagram socket. If the packet is lost, print “Request timed
out”.

The program must calculate the round-trip time for each packet and print it out individually.
Have the client print out the information similar to the output from doing a normal ping
command – see sample output below. Your client software will need to determine and print out
the minimum, maximum, and average RTTs at the end of all pings from the client along with
printing out the number of packets lost and the packet loss rate (in percentage). Then compute
and print the estimated RTT, the DevRTT and the Timeout interval based on the RTT results.

The initial estimated RTT is just the first Sample RTT – the results of your first ping. The initial
DevRTT is first Sample TTT divided by 2. The initial Timeout interval is set to 1 minute. The
formulas for calculating the estimated RTT, DevRTT, and Timeout interval for each succeeding
ping are contained in the slides on the last page of this document and on pages 242-243 of the
textbook.1

Sample output of ping to Google.com


Here is a sample output from a ping of Google 4 times:

Pinging google.com [216.58.195.78] with 32 bytes of data:


Reply from 216.58.195.78: bytes=32 time=13ms TTL=54
Reply from 216.58.195.78: bytes=32 time=14ms TTL=54
Reply from 216.58.195.78: bytes=32 time=16ms TTL=54
Reply from 216.58.195.78: bytes=32 time=13ms TTL=54 Ping
statistics for 216.58.195.78:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate
round trip times in milli-seconds:
Minimum = 13ms, Maximum = 16ms, Average = 14ms

Expected output of your program


Server Output:
Client Output:
Grading Objectives
1. (10 points) Ping messages must be sent using UDP. Server must change the received
message to uppercase before sending the message back to the client.
2. (15 + 15 points) Print the request from client and response from server messages on
both the client and server machines.
3. (8 x 10 points) Calculate and print the following on the client side in milliseconds:
a. Round trip time (RTT) - If the server doesn’t respond, print “Request timed out”.
b. Minimum RTT
c. Maximum RTT
d. Average RTT (Leave out lost packets from average calculation)
e. Estimated RTT. Consider alpha = 0.125. (Look at slides at the end for formulae.)
f. Deviation RTT. Consider beta = 0.25. (Look at slides at the end for formulae.)
g. Timeout Interval (Look at slides at the end for formulae.)
h. Packet loss percentage
4. (20 points) You must write the client code to do the assignment with the calculations in
3 above without the use of a list (or array). Find an efficient and effective use of storage
and program speed.
5. (10 points) Program must be well documented.
6. (25 points) Teamwork:
a. Submission files are in order. (Look at what to hand in below.)
b. Peer evaluation completed.

During development, you should run the Server.py on your machine, and test your client by
sending packets to localhost (or, 127.0.0.1). After you have fully debugged your code, you
should see how your application communicates across the network with the ping server and
ping client running on different machines.

What to Hand in
1. You will hand in the complete client and server code to iLearn.
2. Minutes of the 3 meetings.
3. Screenshots of server and client-side output.
4. Fill in columns B and C with RTTs and lost packets as indicated in the file - Output
Checker. Your outputs in your screenshots must match the outputs calculated in the
Output Checker.

Footnotes:
1. The estimated RTT, DevRTT, and Timeout interval are actually only used with TCP. These
calculations are included in this programming assignment to give you experience working
with these parameters.

You might also like