Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Wiki / Routing

Routing

Do It Yourself Routing Tutorial

Do It Yourself Routing Tutorial

If you really want to setup and manage routing entirely by yourself, you can use the tb-set-node-startcmd command in your NS file to specify a per-node script in your home directory to set up routing at boot time. You can use this startup script to setup either static routes or to fire up a routing daemon. We do not recommend this approach anymore, but it is there if you need more control over your routing than we provide. The following examples illustrate this approach.

The simplest topology requiring routing is one in which two nodes, client and server are each connected via a single link to router. In order to get router to correctly forward packets between client and server, you would add this line to your NS file:

tb-set-node-startcmd $router /proj/myproj/router-startup

This will make router run the router-startup script from you project directory. That script looks like:

#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
    sudo sysctl -w net.inet.ip.forwarding=1
    sudo sysctl -w net.inet.ip.fastforwarding=1
else
    sudo sysctl -w net.ipv4.conf.all.forwarding=1
fi
exit 0

These commands ensure that the router node will forward IP packets. Note the use of sudo which is necessary since startup scripts run as you and not as root. Now to get client and server to talk to each other through this router, you would add these lines to your NS file:

tb-set-node-startcmd $client /proj/myproj/clientroutecmd
tb-set-node-startcmd $server /proj/myproj/serverroutecmd

This will have the client and the server each call a small script to set up routes. To add a route (on client) to interface 0 of the server through router, you would run a script called clientroutecmd that looks like this:

#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
    sudo route add server-0 router
else
    sudo route add server-0 gw router
fi
exit 0

Similarly, to add a route (on server) to interface 0 of the client through router, you would use this serverroutecmd script:

#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
    sudo route add client-0 router
else
    sudo route add client-0 gw router
fi
exit 0

That should do it. You will now have a router node that really routes and forwards packets, and a client and a server that know how to talk to each other through a gateway router. Note that this setup can be generalized to work for any topology where all nodes are directly connected to a single router node. However, every node would need a custom script with a route add command for every other node or you would need to use a subnet route as in the next example.

In complex topologies with multiple routers, each end node will need a route to the entire experimental network, through its local router. For FreeBSD, this is done with:

#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
    sudo route add -net 10.1.0.0 -netmask 255.255.0.0 myrouter
else
    sudo route add -net 10.1.0.0 netmask 255.255.0.0 gw myrouter
fi
exit 0

You might be tempted to just set the default route for each node to myrouter, but be aware that such a route would prevent you from contacting the outside world. The default route must be set to use the control network interface.

You can make a single script that will handle all end nodes, by replacing myrouter in the above commands with $1, and specifying the router in your NS file:

tb-set-node-startcmd $clientA {/proj/myproj/router-startup router0}
tb-set-node-startcmd $clientB {/proj/myproj/router-startup router1}

For multiple routers, the startup script for each router will need to contain a set of routes for all subnets it is not directly connected to. This will differ, depending on the topology you are using. To make this task easier, you can use the tb-set-ip command in your NS file, so that you know which subnets will be assigned to which nodes.

If you want to enable dynamic routing, you can also use the startup script to fire off a routing daemon. A startup script might look like:

#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
    sudo sysctl -w net.inet.ip.forwarding=1
    sudo sysctl -w net.inet.ip.fastforwarding=1
else
    sudo sysctl -w net.ipv4.conf.all.forwarding=1
fi
sudo gated -f /proj/myproj/gated.conf
exit 0

One complication of using a routing daemon, is that you need to avoid using the control network interface in the configuration. Since every node in the testbed is directly connected to the control network LAN, a naive routing daemon configuration will discover that any node is just one hop away via the control network and all inter-node traffic will be routed via that interface. See one of the installed /etc/testbed/gated*.conf files for an example of how to avoid this pitfall.