Message Protocol (ICMP) to communicate with each other

Programming Assignment: UDP Ping Lab
In this lab, you will learn the basics of socket programming for UDP in C. You will learn how to
send and receive datagram packets using UDP sockets and also, how to set a proper socket
timeout. Throughout the lab, 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 in C. 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
in C. You must test your code in CSIL. That is where we will grade your program.
Server Code
The following code fully implements a ping server. You need to compile and run this code before
running your client program. You do not need to modify this code.
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.
# UDPPingerServer.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 returns the
encapsulated data 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 lab 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
You should write the client so that it sends 10 ping requests to the server, separated by approximately
one second. Each message contains a payload of data that includes the keyword PING, a sequence
number, and a timestamp. After sending each packet, the client waits up to one second to receive a
reply. If one seconds goes by without a reply from the server, then the client assumes that its packet or
the server's reply packet has been lost in the network.
You should write the client so that it starts with the following command:
PingClient host port
where host is the name of the computer the server is running on and port is the port number it is
listening to. Note that you can run the client and server either on different machines or on the same
machine.
The client should send 10 pings 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 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 C documentation for DatagramSocket to find out how to set the timeout value on a datagram
socket.
During development, you should run the UDPPingerServer.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 in CSIL.
Message Format
The ping messages in this lab are formatted in a simple way. The client message is one line,
consisting of ASCII characters in the following format:
PING sequence_number time
where sequence_number starts at 1 and progresses to 10 for each successive ping message sent by
the client, and time is the time when the client sends the message.
Client Output
Your client should produce output modeled after the actual ping command. To see the ping command
output, type ping <hostname>. For example, ping www.google.com, or ping csil-01.
Similar to the output you see from this command, your output should be in the following format:
PING received from machine_name: seq#=X time=Y ms
where X is the sequence number of the received packet and Y is the RTT in milliseconds. As your
client terminates after it receives the tenth ping response (or timeout), it should print the following:
--- ping statistics --- X packets transmitted, Y received, Z% packet loss rtt min/avg/max = MIN AVG
MAX ms
where X is the number of packets transmitted, Y is the number of packets received, and Z is the
percent that were lost. To produce the last line of output you will need to calculate the minimum,
average, and maximum RTTs and fill in the appropriate values.
What to Hand in
You will hand in the complete client code (named PingClient.c) and a Makefile that compiles
your program. 

Comments

Popular posts from this blog

Create Thread”. Do not create a new forum.

Discuss the notion that firms should stop doing business with customers who constantly generate losses versus the notion that the customer is always right.

Access AHIMA: What is Health Information