Computer Networks Programming Assignment 1
Fall 2017
Due: 16 October 2017
We’re going to build a simulated switched network and have a little simulated fun. In
the first part of the assignment, we’ll just do some file parsing to create our network of hosts
and 4-port switches. In the second part, we’ll send some datagrams and have the switches
print out some messages to the screen as events occur (e.g., “SW2: Received packet for
host B. Forwarding out interface 3.”). In the third part, we will add in the ability to build
virtual circuits.
1 Building the Network
To keep the network simple, we will only include two types of devices: hosts and 4-port
switches. Our file format will be as simple as possible while allowing us to express every-
thing we need to express. Everything should go into a file called [Link].
1.1 Specifying the Hosts
This is the easiest part. The input file will simply say:
hosts = x
Obviously, replace x with an integer value. Start naming the hosts as “Host 0”, then “Host
1” and so on. There is nothing else to specify about the hosts in the input file.
1.2 Specifying the Switches
This part is similar to specifying the hosts:
switches = y
Again, replace y with an integer. The switches will be named from 0–y-1. Switches need
to be connected to something, so we need to start linking things up.
1
1.3 Making the Connections
Now our input file needs to make the connections between the devices. There is probably
not an easy way to do this, so we will try to make the syntax as low-impact as possible.
Shown below are two representative examples:
SW1[1] = SW2
SW2[3] = H0
The first line indicates that interface 1 of Switch 1 is connected to Switch 2. (Note that
we don’t care what interface on SW2 we’re connected to.) Switches are referred to as SWx ,
where x is an appropriate integer. Similarly, hosts are referred to as Hx , again with x as an
appropriate integer. Note: You can assume that the files will always be properly formatted.
It’s always a good idea to build your code to be robust, but in a short assignment like this,
let’s focus on the basic functionality first.)
1.4 A Complete Example
Shown in Figure 1 is the same network from the Lecture we’ve used to discuss virtual
circuits and basic datagram forwarding, but I’ve renamed and renumbered the devices
consistent with the notation for this assignment.
hosts = 10
switches = 4
SW0[0] = H3
SW0[1] = SW1
SW0[2] = H0
SW0[3] = H2
SW1[0] = SW2
SW1[1] = SW3
SW1[2] = SW1
SW1[3] = H4
SW2[0] = SW1
SW2[1] = H9
SW2[2] = H8
SW2[3] = H1
SW3[0] = H7
SW3[1] = H6
SW3[2] = H5
SW3[4] = SW2
2
Figure 1: A Sample Network
3
1.5 Some Notes
It is entirely up to you how you build and store the network. I would imagine defining a
object for hosts and another for switches, then storing those in an array or hash table. You
might choose explicit connections via pointer/reference or just another array/hash that
functions as a lookup table. We won’t explicitly connect a host up to a switch, because
that’s not how it works in real life. The device doesn’t know what the path looks like from
the source to the destination. The abstraction is that it is a direct connection. However,
you can register the switch as being connected to a particular host when you’re building
the virtual network.
2 Sending Packets
Now the input file ceases to specify the network topology and instead gives commands to
the devices. These can be interpreted serially; no threading or multi-process code is needed
for this assignment. Let’s keep the syntax simple:
P0-4
This indicates that a Packet is being sent from Host 0 to Host 4. It is up to the switches
to forward this packet to the destination. Here is a suggested way of dealing with this,
expressed in pseudocode:
1. currPacket = read(inputFile)
2. print “Packet starting at Host $sourceHost”
3. currSwitch = switch connected to $sourceHost
4. while currSwitch != switch connected to $destinationHost
5. nextSwitch = [Link]($destinationHost)
6. print “Switch $currSwitch forwarding packet to Switch $nextSwitch on interface $out-
goingInt”
7. currSwitch = nextSwitch
8. print “Packet delivered to $destinationHost”
In our example above, the following printout would appear:
Packet starting at Host 0
Switch 0 forwarding packet to Switch 1 on interface 1
Packet delivered to Host 4
Keep reading the file until there are no more packets to deliver.
4
3 Virtual Circuits
If you have a working version of packet delivery, building virtual circuits will be a simple
adaptation. The input file will specify:
V0-4
This indicates a Virtual circuit should be established between Host 0 and Host 4. Use a
similar algorithm for delivering packets to establish the VC. Remember that the message
goes all the way from the source to the destination and then back again. The printout for
establishing the example VC above would be:
Circuit requested by Host 0
Switch 0 creating circuit with incoming interface 3 and outgoing interface 1
Switch 1 creating circuit with incoming interface 3 and outgoing interface 2
Host 4 requests incoming VCI 0
Switch 1 requests incoming VCI 0
Switch 0 requests incoming VCI 0
Circuit established
4 Submission and Testing
4.1 Language
You are free to choose from any language that you are comfortable with, but preference
should be shown to the C/C++/C# family, Java and Python. If you really want to use
another language, please run it by me first. Ideally, whatever you use should be able to be
compiled and run on a Mac, a standard campus Windows machine or the CS lab machines.
4.2 Submission
If you submit a C/C++ program, it would be nice to have a makefile. If you use Java, an
Eclipse project is nice as well. If there is something special that needs to be done to make
sure the program compiles/runs, put it in a README file. Submit everything to Canvas,
including input files.
4.3 Testing
You will be provided with two test input files. One describes a very small, simple network
with just a couple of packets. The second will be a much more complex network with a lot
of packets and multiple virtual circuits. I will also create one medium-sized network to be
sure your program can handle arbitrary inputs.
5
5 Grading
Part 1 is worth 50 points. It is obviously difficult to grade this section in isolation, so
getting these points requires successfully transmitting packets in part 2. Demonstrating
proper transmission of packets in Part 2 is worth 75 points (approximately 75 points for
each test case). Successfully building virtual circuits is worth another 75 points (again, 25
points per test).
If your code fails to compile, I will give you a 0, and alert you of the failure. Prompt
responses to this email will make sure you still get some points.