CS640 Programming Assignment 1: Packet Blaster

Due: October 22, 2009 by 11:59 PM



Description

For this programming assignment you will write two pieces of code: the "blaster" and the "blastee". The blaster will send variable size UDP packets to a specified host. The blastee will receive these packets, subsequently logging them and printing receipt information. The code must be written in C or C++ using the Linux workstations in 1350, 1351 or 1370 CS. You may also use WAIL to test your assignment (use "FC6-STD" as your OS).

Details + Requirements

The packets which will be sent are to be of the form:

  --------------------------------------------------------------------- ... ---
 |    8 bit     |       32 bit    |    32 bit   |   variable length            |
 | packet type  |      sequence   |    length   |      payload                 |
  --------------------------------------------------------------------- ... ---

A single test run initiated by the blaster program consists of any number of DATA packets (determined by parameters given to the blaster program, described above) followed by an END packet. At the end of a test run, each program should terminate.

The blaster should be invoked in the following way:

 blaster -s <hostname> -p <port> -r <rate> -n <num> -q <seq_no> -l <length> -c <echo>

Additional notes for the parameters:

The blaster must print, for each packet sent to the blastee, the sequence number and the first 4 bytes of the payload on a separate line on the standard output. Upon receipt of an echo packet, it should print on a separate line the sequence number and the first 4 bytes of the payload of the received packet with the label "echo" before the sequence number.

The blastee shall receive the packets which the blaster has sent. It should be invoked in the following way.

 blastee -p <port> -c <echo>
The blastee must:
  1. for each DATA packet received, print to standard output a text line which states the blaster's IP address (in decimal-dot notation), the port on which the packet was received, the packet's size (in bytes), the packet sequence number, the time at which the packet was received (at millisecond resolution), and the first 4 bytes of the payload.
  2. after the END packet is received, print summary information about the test including total packets received, total bytes received, average packets/second, average bytes/second, and duration of the test.

The executable program names must be "blaster" and "blastee". You also must supply a makefile with your source code to produce these binaries. The source code file names are up to you.

Advice

You are advised to start small, adding functionality as your testing succeeds. For example, you can start with a simple blaster which just sends one packet with a null payload. You can then write a simple blastee which tries to decode the packet header and print the origination of the packet. Once this seems correct, try adding more of the required details of the blaster. You might also consider printing status statements after different phases of the program are complete (i.e., "Created socket", "Sent packet", etc.) However, don't let these printf()'s (or cout's) substitute for running a debugger.

When working on your blastee, if you are unsure you are listening on the port you think you are, try running "netstat -u" to see the state of udp sockets on your machine. It won't necessarily tell you which socket you really are bound to, but it will tell you whether or not someone (hopefully you) is bound to a particular port.

Useful manual pages to read are getopt(3), ip(7), udp(7), sendto(2), recvfrom(2), bind(2), and gethostbyname(3) (e.g., "$ man 7 ip".) Read the man pages carefully - they are (usually) very clear on what sorts of return values you should expect and any other caveats with the particular call or subsystem being described. It will really help if you are careful to check return values from any system calls you use.

Something which may or may not be useful to use is to try sending a packet to the "echo" service. It resides at port 7 (for both udp and tcp -- look in "/etc/services" on any unix machine) and will simply send back what ever data you send to it. Writing some test code to do this will give you more experience in working with udp sockets since you must both send and receive from within the same application.

Grading

It is essential that you follow the required packet format and output specification so that your programs can interoperate with our grading versions. To turn in your code, copy your code to the directory

 ~cs640-1/handin/<CS_USERNAME>/P1

Grading will be according to the following schedule:

Points Requirement
20 Your code for blaster and blastee compiles and it is clear from the source that you are not just compiling "helloworld.c". (Something compiles, but that's about it.)
20 Your code sends any sequence of UDP packets from the blaster which are received and printed by the blastee. (Something actually gets sent and received, though the details may or may not be correct.)
10 The blastee can correctly decode incoming packets and prints required details in an intelligible way.
10 The blastee can echo back the received packets, and the blaster correctly receives the echo packets and prints out the required information.
10 You are able to specify the number of packets to send.
10 You are able to specify the rate at which packets are sent and also specify payload size.
10 You are able to generate a sequence number for packets.
10 You are able to generate an END packet and print out summary statistics from blastee.