VNS exercises

From Comp519

Jump to: navigation, search

For this tutorial, you will write code to print out the contents of all ARP packets that arrive at your software router.

The following steps are required to accomplish this:

Contents

Make a copy of the provided code

Log on to comp519.cs.rice.edu. Copy the base software router (SCONE = Software Component Of NEtfpga) code from /exports/provided/scone-base/ to somewhere in your home directory.

Make some simple modifications to the provided code

In sr_main.c there is a check to ensure that you have properly installed your router subsystem. Since we will not actually be routing anything for this tutorial, you do not need a router subsystem. You should comment out lines 51-53:

/*
if (sr == 0) {
  printf("Subsystem not initialized\n");
  return 1;
}
*/

We will place all of the code needed for the tutorial in 2 files: tutorial.c and tutorial.h.

You should modify the Makefile to include tutorial.c in SR_BASE_SRCS. You should also 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 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.

Test your code

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

./scone -t topoid -s vns-1.stanford.edu

The value of topoid will be different for each group and announced in the tutorial. Information about each topology is available in /exports/provided/vns-topologies/spring09/.

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!

Views
Personal tools