CS244E Assignment 1

This assignment is an introduction to Click programming. It will get you started with writing a Click configuration, introduce you to many of Click’s elements, and show you how Click configurations can be made scriptable. Finally, you will write your own routing component to route packet in network.

The first 8 parts of this assignment and much of the installation instructions have been taken as is from the tutorial on Click’s website.

Getting Click

Obtain the click source code and compile and install it:

$ cd ~
$ cvs -z5 -d :pserver:anonymous@read.cs.ucla.edu:22401/git/click co -d click master
...
$ cd click
$ ./configure --prefix=$HOME --enable-analysis --enable-test
...
$ make install
$ ~/bin/click conf/test.click
ok:   40 | 45000028 00000000 401177c3 01000001 02000002 13691369
ok:   40 | 45000028 00000000 401177c3 01000001 02000002 13691369
ok:   40 | 45000028 00000000 401177c3 01000001 02000002 13691369
ok:   40 | 45000028 00000000 401177c3 01000001 02000002 13691369
ok:   40 | 45000028 00000000 401177c3 01000001 02000002 13691369

The –prefix=$HOME configuration switch causes Click to install into your home directory. To run the Click driver and read its manual pages, you’ll need to add $HOME/bin and $HOME/man to your PATH and MANPATH environment variables, respectively. Alternatively, if you have root privilege on your machine, you can install Click in /usr/local, /usr/local/click, or wherever you’d like.

The –enable-analysis and –enable-test configuration switches turn on support for two necessary sub-packages, including trace analysis and regression test elements.

If you get a bus error when running Click on a Solaris or other non-x86 machine, try running your configuration through click-align: “click-align config.click | click”.

Now, download and unpack click-tutorial1.tar.gz. You will do your work in the click-tutorial1 directory.

Problems

You can check your work on most of the problems by running make grade.

1. Trace files [2 points]. Create a router configuration file called prob1.click that reads packets from the tcpdump trace file ‘f1a.dump’ and writes those packets unchanged to the tcpdump trace file ‘f1b.dump’. The Click driver should exit when f1a.dump is out of packets.

Notes and hints: tcpdump is the canonical program for reading and storing packet traces. It can store packets read from Ethernets, ATM networks, and many other types of links. A tcpdump file’s link type is called its encapsulation. We will be dealing only with raw IP encapsulation, where the files have no link-level headers: the first bytes in each packet will be an IPv4 header.

2. Routing [2 points]. Create a router configuration file called prob2.click that reads packets from the tcpdump trace file ‘f2a.dump’ and routes those packets using the following routing table:

Destination prefixOutput trace file
131.0.0.08 f2b.dump
131.179.0.016 f2c.dump
18.0.0.0/8 f2d.dump
All others f2e.dump


3. Error checking [3 points]. Create a router configuration file called prob3.click, based on prob2.click. The configuration should read from ‘f3a.dump’ and write to ‘f3*.dump’. But this time, you should check for the following six kinds of errors, in this order.

Problem Action
Invalid IP header or checksum Discard packet
Invalid TCP header or checksum Discard packet
Invalid UDP header or checksum Discard packet
Invalid ICMP header or checksum Discard packet
Expired IP TTL Generate appropriate ICMP error message, send message to ‘f3f.dump
Packet longer than 1500 bytes Discard packet


4. Handlers [2 points]. Create a router configuration file called prob4.click, based on prob3.click. It should read from ‘f4a.dump’ and write to ‘f4*.dump’. But this time, in addition to checking for errors, running the configuration should generate a file ‘f4.drops’ containing the following 6 lines:

1. The number of packets with invalid IP headers or checksums;
2. The number of packets with invalid TCP headers or checksums;
3. The number of packets with invalid UDP headers or checksums;
4. The number of packets with invalid ICMP headers or checksums;
5. The number of packets with expired IP TTLs; and
6. The number of packets longer than 1500 bytes.

Each packet will show up in at most one of these counts.

Hint: Check out the Script element.

5. Compound elements [3 points]. Create a partial router configuration file called prob5.click. This file should define a compound element named ‘ErrorChecker’ with one input and one output that implements all the error checks from Problem 3. All erroneous packets should be dropped (not written to a file).

6. Compound element overloading [3 points]. Create a partial router configuration file called prob6.click, based on prob5.click. This time, the ErrorChecker compound element should support three different use patterns. If it is used with one input and one output, it should behave like in Problem 5. If it is used with one input and two outputs, then all erroneous packets should be emitted on the second output (not dropped). If it is used with one input and seven outputs, then the first output is for correct packets, and the following six outputs are used for the six different errors.

7. Scheduling [5 points]. Create a router configuration file called prob7.click. It should read packets from ‘f7a.dump’, maintaining the timing of the dump file. (This means that if two adjacent packets in the dump file have timestamps that are 0.5 seconds apart, the packets will be emitted into the configuration 0.5 seconds apart.) The packets should be written into ‘f7b.dump’, except that:

Note: Add the line “DriverManager(pause, wait 2s)” at the end of your .click file to give click time to flush all packets.

8. More error handling [2 points]. Add error handling à la Problem 4 to the configuration of Problem 7. The router configuration file should be called prob8.click, it should read from ‘f8a.dump’ and write to ‘f8b.dump’, it should discard IP TTL-expired packets rather than generate errors, and ‘f8.drops’ should report any packets dropped from queues after the errors already mentioned.

9. Writing your own Source routing element [10 points]. For this part, you will implement a forwarding element that will accept packets from a packet generator element. These packets have a source route embedded in them. The objective is to strip the head of the source route at each hop in the route and deliver the packet to the destination. This part uses a separate ns simulation environment wwith click, and the packets’ source route is the same format as the Srcr protocol. You can refer to the Srcr code and the Roofnet paper for the packet format, but you should write your own code for parsing and modifying the packets. For setting this environment up, use the following instructions:

1. Download ns_cs244e.tar.gz using “wget http://sing.stanford.edu/mayank/ns_cs244e.tar.gz
2. untar the file in a local directory say <ns_location>
3. cd <ns_location>/ns_cs244e/click_ns_src
4. run “./myconfigure
5. run “make install
6. cd ../ns-allinone-2.30
7. run “./install
8. find out which shell you are using: run “ps -p $$” on the terminal
8.1 If you use bash, add the following to your ~/.bashrc

export PATH=<ns_location>/ns_cs244e/ns-allinone-2.30/bin:<ns_location>/ns_cs244e/ns-allinone-2.30/tcl8.4.18/unix:<ns_location>/ns_cs244e/ns-allinone-2.30/tk8.4.18/unix:$PATH
export LD_LIBRARY_PATH=<ns_location>/ns_cs244e/click_ns_src/ns:<ns_location>/ns_cs244e/ns-allinone-2.30/otcl-1.13:<ns_location>/ns_cs244e/ns-allinone-2.30/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=<ns_location>/ns_cs244e/ns-allinone-2.30/tcl8.4.18/library:$TCL_LIBRARY

8.2 If you use csh/tcsh, add the following to your  /.cshrc or  /.tcshrc

setenv PATH <ns_location>/ns_cs244e/ns-allinone-2.30/bin:<ns_location>/ns_cs244e/ns-allinone-2.30/tcl8.4.18/unix:<ns_location>/ns_cs244e/ns-allinone-2.30/tk8.4.18/unix:$PATH
setenv LD_LIBRARY_PATH <ns_location>/ns_cs244e/click_ns_src/ns:<ns_location>/ns_cs244e/ns-allinone-2.30/otcl-1.13:<ns_location>/ns_cs244e/ns-allinone-2.30/lib
setenv TCL_LIBRARY <ns_location>/ns_cs244e/ns-allinone-2.30/tcl8.4.18/library

9. cd ../run_dir
10. run “ns ns_test.tcl 2” if you see log messages with the last line starting with “end of trace file …”, things are fine.

Now, for writing the source routing code, you need to write to an element named cs244e_forwarder. The template code for this element is in the elements/cs244e folder. You have to complete the .cc file. The .hh file is already complete. This element should have the following properties:

Once you have the code ready, re-configure click by running ./myconfigure_assign in the click_ns_src directory. Then run make. Then go to the run_dir directory. Run “ns test.tcl 20” to check your code. This tcl file loads source routing packets from a trace and tries to route them using your forwarder code. The output log will have all MAC layer transmit and receive packets and the logs for packets generated at source and successfully delivered at destinations. Use this log to debug your code. The expected output log for comparison is test.log.

Handing in

Your handin to assignment 1 should be gzipped tarball of a directory cs244e-suid, where suid is your SUID. This directory should contain both the click-tutorial1 and the cs244e (from elements) folders. The tarball must be named cs244e-suid.tgz, where suid is your SUID. You should hand in the assignment by emailing it to both the instructor and TA.