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:
This will make router run the
tb-set-node-startcmd $router /proj/pid/router-startup
router-startup
script
from you project directory. That script looks like:
These commands ensure that the router node will forward IP packets.
Note the use of
#!/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
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:
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
tb-set-node-startcmd $client /proj/pid/clientroutecmd
tb-set-node-startcmd $server /proj/pid/serverroutecmd
clientroutecmd
that looks like this:
Similarly, to add a route (on server) to interface 0 of the client
through router, you would use this
#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
sudo route add server-0 router
else
sudo route add server-0 gw router
fi
exit 0
serverroutecmd
script:
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.
#!/bin/sh
if [ `uname` = "FreeBSD" ]
then
sudo route add client-0 router
else
sudo route add client-0 gw router
fi
exit 0
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:
You might be tempted to just set the default route for each node to
#!/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
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:
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-node-startcmd $clientA {/proj/pid/router-startup router0}
tb-set-node-startcmd $clientB {/proj/pid/router-startup router1}
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:
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.
#!/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/pid/gated.conf
exit 0