You are here: Home / Past Courses / Spring 2011 - ECPE 293B / Tutorials / VNS Exercises

VNS Exercises

The objective of this tutorial is to print out the contents of all ARP packets that arrive at your software router.

The following steps are required to accomplish this:

Make a copy of the provided code

Log on to ecs-network.serv.pacific.edu. Copy the base software router (SCONE = Software Component ONEtfpga) code from /exports/provided/scone-base/ to somewhere in your home directory.

cp -R /exports/provided/scone-base ~/

 

Make some simple modifications to the provided code

We will place all of the code needed for the tutorial in 2 files: tutorial.c and tutorial.h. To make sure this file is compiled, you should modify the Makefile to include tutorial.c in SR_SRCS_BASE. In addition, you should add the following line to the top of sr_integration.c:

#include "tutorial.h"

 

Create an empty function to print ARP packets

Create tutorial.h with the following skeleton:

#ifndef TUTORIAL_H
#define TUTORIAL_H

#include "sr_base_internal.h"
#include <stdint.h>

void tutorial_input(struct sr_instance *sr,                                     
                    const uint8_t *packet /* borrowed */,                       
                    unsigned int len,                                           
                    const char *interface /* borrowed */);                      

#endif /* TUTORIAL_H */ 

The tutorial_input function is what you will use to print out received ARP packets. It takes an instance of the software router (sr), the received packet (packet), the packet length (len), and the name of the interface on which the packet arrived (interface). In the scone code, by convention, we will label function arguments for which the caller is responsible for memory allocation/deallocation as "borrowed". The implications of this are twofold:

  1. You should never save a pointer to a borrowed argument across procedure calls (in your router subsystem, for example), as you do not know if it will remain allocated. If you need to save it, you must make a copy of the data.
  2. You should never call free on a borrowed argument, as the caller is responsible for doing so, and may actually still need the data.

You should then create the file tutorial.c with the following skeleton:

#include "tutorial.h"
#include <stdio.h>
#include <arpa/inet.h>

void tutorial_input(struct sr_instance *sr,
                    const uint8_t *packet /* borrowed */,
                    unsigned int len,
                    const char *interface /* borrowed */)
{
}

 

Call your function to print ARP packets

In scone, whenever a packet arrives, the function sr_integ_input in sr_integration.c is called. You should modify this function to call your tutorial_input function.

 

Write whatever code is necessary to print ARP packets

You should now write the code for your tutorial_input function to print out information on ARP packets that arrive at your software router. To accomplish this, we suggest you do the following things:

  1. Define ethhdr and arphdr structures. Make use of Network Sorcery!
  2. Cast packet to type (ethhdr *) and check that the Ethernet type is ARP.
  3. Cast packet with the appropriate offset to type (arphdr *).
  4. Print out the fields of the ARP packet (including all Ethernet and ARP headers). Be sure to use ntohs for all 16-bit fields and inet_ntop to convert IP addresses to strings.

 

Compile your code

make

 

Test your code

Once your code compiles, it can be run as follows:

./sr -t <topid> -s vns-1.stanford.edu -u <vns-user-name>       # Optional arguments: -a <authKeyFile> -r <rtableFile> -l <logfile>

You will need the following items in order to connect to VNS:

  • User account: Each group has been assigned a unique VNS topology.  Look at the Groups page and note your VNS topology ID, VNS user ID, and VNS password.
  • Authentication key file: Login to the VNS management website using your VNS account information and click on the Your Profile link.  Note the Auth key shown on the page.  Create a new file called auth_key in your software router directory, and paste in the contents of the box labeled "Simulation Auth Key" on the website.  (The filename must be auth_key exactly, or else use the -a argument to specify your own file name).
  • Routing table: While at the VNS website Your Profile page, click on the topology link assigned to your group.  Save the contents of the "Topology Routing Table" link to a new file called rtable in your software router directory.  (The filename must be rtable exactly, or else use the -r argument to specify your own file name).   While the routing table is not technically needed for this tutorial, you will definitely need it for the software router project.

To see a diagram of the VNS topology assigned to your group, including key IP addresses, view the Topology README link.

You are very likely to receive ARP requests from other running systems in VNS. If you do not, you can ping your software router to create some (details will be provided in the tutorial).

You should see a printout of ARP packets that arrive at your router!

View in Wireshark

The VNS framework can optionally log all packets received and sent by your application.  To enable this feature, add the -l logfile.dat argument when running your program.  You can then open this file with Wireshark and view the packets in detail.

wireshark logfile.dat &

Tip: If you get an error while launching Wireshark, it is due to modifications you made to your .bashrc file earlier this semester, specifically including a script necessary to run the Xilinx tools. That script specifies that some (old) libraries be used instead of standard system libraries that are compatible with Wireshark.  To stop searching those libraries, type this before running Wireshark:

unset LD_LIBRARY_PATH