= HowTo test netsukuku daemon using NetKit = A way to test the Netsukuku behaviour (if you don't have a considerable network infrastructure with a conspicuous number of computer) can be to run it on {{{Netkit}}}. The purpose of this page is to collect informations that can help newcomers to prepare an environment where simulate some network topology, whose hosts can run ''ntkd'' daemon. == Prepare a virtual machine to run ntkd == We will install the latest version of Netkit (core version 2.6 - file system 5.0 - kernel version 2.7). <
> Follow the instruction here [[http://wiki.netkit.org/index.php/Main_Page]]. Once installed, you can see that the virtual machines have a Debian-based operative system. <
> Thus we can use {{{apt-get}}} to install on them the software and the dependecies needed. So, our host system must be connected to Internet. We must also make sure to have enough space in the virtual disk. === Increase the virtual machine disk space === Each virtual machine has a virtual disk. This disk is described by a template file that don't must be altered, and from another file that contains only some differences from this template file. The template file is located into the Netkit installation directory (i.e. $NETKIT_HOME), under the directory "fs". It is named "netkit-fs". Indeed, it is just a symbolic link to the file netkit-fs-i386-F5.0. <
> {{{ luca@luca-laptop:~$ cd $NETKIT_HOME/fs luca@luca-laptop:~/netkit/fs$ ls -l netkit-fs lrwxrwxrwx 1 luca luca 2 2009-09-11 22:52 netkit-fs -> netkit-fs-i386-F5.0 }}} The disk space of this file is of 1 GB, too little for our needs. Let's see how to expand it. Let's copy, for safety, the original file. <
> Using the command "ls -ls" we can see the declared dimension of the disk and the actual space on it. <
> This two values differs in the so-called sparse-file, like the disk image that are not "full". {{{ luca@luca-laptop:~/netkit/fs$ cp netkit-fs-i386-F5.0 backing luca@luca-laptop:~/netkit/fs$ ls -ls backing 1048584 -rw-r--r-- 1 luca luca 1073741824 2009-09-10 15:46 backing }}} Increase the declared dimension to 2 GB. {{{ luca@luca-laptop:~/netkit/fs$ dd if=/dev/zero of=backing bs=1 count=1 seek=2G 1+0 records in 1+0 records out 1 byte (1 B) copied, 9.9803e-05 s, 10.0 kB/s luca@luca-laptop:~/netkit/fs$ ls -ls backing 1048588 -rw-r--r-- 1 luca luca 2147483649 2009-09-10 15:47 backing }}} Let's expand the partition situated into this virtual disk image. {{{ luca@luca-laptop:~/netkit/fs$ sudo losetup /dev/loop0 backing luca@luca-laptop:~/netkit/fs$ sudo fdisk /dev/loop0 The number of cylinders for this disk is set to 66576. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) }}} The u command say that we want as unit the sector, instead of cilinder {{{ Command (m for help): u Changing display/entry units to sectors }}} The p command shows the disk information. {{{ Command (m for help): p Disk /dev/loop0: 2147 MB, 2147483648 bytes 1 heads, 63 sectors/track, 66576 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/loop0p1 * 64 2097143 1048540 83 Linux }}} We note that the partition begins at the sector 64. We must use later this value. <
> We delete this partition and recreate another larger one. <
> We will use 64 as start and the default as end. <
> d to delete, n to create, p for primary partition, 1 for partition number, 64 for start, when we asked for an end. {{{ Command (m for help): d Selected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First sector (63-4194303, default 63): 64 Last sector, +sectors or +size{K,M,G} (64-4194303, default 4194303): Using default value 4194303 }}} The p command shows disk information. {{{ Command (m for help): p Disk /dev/loop0: 2147 MB, 2147483648 bytes 1 heads, 63 sectors/track, 66576 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/loop0p1 64 4194303 2097120 83 Linux }}} The a command make the partition bootable. {{{ Command (m for help): a Partition number (1-4): 1 Command (m for help): p Disk /dev/loop0: 2147 MB, 2147483648 bytes 1 heads, 63 sectors/track, 66576 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/loop0p1 * 64 4194303 2097120 83 Linux }}} The w command saves and exit. {{{ Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 22: Invalid argument. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. }}} We can ignore that warning. Now we can remove the association to /dev/loop0 {{{ luca@luca-laptop:~/netkit/fs$ sudo losetup -d /dev/loop0 }}} Now let's make a calculation. Our partition begins at the sector 64 and each sector (like said by fdisk) is of 512 bytes. <
> Thus the partition begins to an offset of 64*512=32768 bytes. <
> Let's associate this partition to /dev/loop0 using the following command: {{{ luca@luca-laptop:~/netkit/fs$ sudo losetup --offset 32768 /dev/loop0 backing }}} Type fschk, a resize and an fschk. They are usefull to make effective the new allocation. {{{ luca@luca-laptop:~/netkit/fs$ sudo e2fsck -f /dev/loop0 e2fsck 1.41.4 (27-Jan-2009) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 3A: Optimizing directories Pass 4: Checking reference counts Pass 5: Checking group summary information nkfs-i386-F5.0: ***** FILE SYSTEM WAS MODIFIED ***** nkfs-i386-F5.0: 39840/65536 files (2.2% non-contiguous), 725259/1048540 blocks luca@luca-laptop:~/netkit/fs$ sudo resize2fs -f /dev/loop0 resize2fs 1.41.4 (27-Jan-2009) Resizing the filesystem on /dev/loop0 to 2097120 (1k) blocks. The filesystem on /dev/loop0 is now 2097120 blocks long. luca@luca-laptop:~/netkit/fs$ sudo e2fsck -f /dev/loop0 e2fsck 1.41.4 (27-Jan-2009) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information nkfs-i386-F5.0: 39840/131072 files (2.2% non-contiguous), 742160/2097120 blocks }}} Again, let's remove the association to /dev/loop0 {{{ luca@luca-laptop:~/netkit/fs$ sudo losetup -d /dev/loop0 }}} The obtained backing file can be used like a template for Netkit virtual machines. <
> We can do it in two different ways. The first one is that to add this two parameters every time we start a virtual machine: <
> {{{ -m /path/to/file/backing}}} <
> {{{ --append=root=98:1}}} The second one is to replace the simbolic link "netkit-fs" to the original netkit-fs-i386-F5.0 file with another one pointing to our new file. <
> Here, both parameters can be omitted. In the rest of this document we suppose that has been selected this second way. === Installing packages from Internet === Be sure to have the root password of host system. I don't mean our password with which we can use "sudo"; but the real password of user root. <
> Let's type "su -" that ask us the root password. <
> After this test, exit from the root prompt shell and return to the user one. In our system terminal, we will move into an empty directory created for this tests. Let's type the command: {{{ luca@luca-laptop:~$ mkdir test-ntkd luca@luca-laptop:~$ cd test-ntkd/ luca@luca-laptop:~/test-ntkd$ vstart pc1 --eth0=tap,10.0.0.1,10.0.0.2 --mem=128 }}} Now we are asked for the root password. This method used to start the virtual machine let us to use Internet within it. Furthermore, it's needed to upgrade the memory to 128 MB, to make the installation process working. Maybe you need to execute this following commands too, to let the virtual system baits on the Internet. {{{ luca@luca-laptop:~/test-ntkd$ sudo ifconfig nk_tap_$(whoami) 10.0.0.1 netmask 255.255.255.0 up luca@luca-laptop:~/test-ntkd$ sudo iptables -t nat -A POSTROUTING -s 10.0.0.2 -j MASQUERADE luca@luca-laptop:~/test-ntkd$ sudo iptables -A FORWARD -i nk_tap_+ -j ACCEPT }}} We need a DNS server. We can use opendns (208.67.222.222) if we don't have one. Into the host system we need to edit {{{/etc/resolv.conf}}} adding this line: {{{ nameserver 208.67.222.222 }}} Now we should be able to surf from host system. Try with "ping www.ubuntu.com". If everything works let's type this commands to get the needed packages. {{{ pc1:~# apt-get update }}} If during the update appears a messege like: {{{ W: GPG error: http://ftp.it.debian.org unstable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 9AA38DCD55BE302B W: You may want to run apt-get update to correct these problems }}} then the apt doesn't have the public key with that identifier. <
> The important part are the last 8 hex digits, for example {{{55BE302B}}}. <
> Type the following commands, replacing the last 8 digits: {{{ pc1:~# gpg --keyserver keyserver.ubuntu.com --recv-keys 55BE302B gpg: requesting key 55BE302B from hkp server subkeys.pgp.net gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 55BE302B: public key "Debian Archive Automatic Signing Key (5.0/lenny) " imported gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) pc1:~# gpg --export --armor 55BE302B | apt-key add - OK }}} then restart the update. {{{ pc1:~# apt-get update }}} Let's go. <
> '''NOTE:''' the build-essential package require some user interactions. {{{ pc1:~# apt-get install build-essential pc1:~# apt-get install subversion pc1:~# apt-get install swig pc1:~# apt-get install openssl libssl-dev }}} The following commands creates some symbolic link needed for the next installations. {{{ pc1:~# cd /usr/lib pc1:/usr/lib# ln -s libcrypto.so.0.9.8 libcrypto.so.0 pc1:/usr/lib# ln -s libssl.so.0.9.8 libssl.so.0 }}} Now we install Stackless Python. <
> Always into the virtual machine, let's type: {{{ pc1:/usr/lib# cd pc1:~# wget http://www.stackless.com/binaries/stackless-262-export.tar.bz2 pc1:~# tar xf stackless-262-export.tar.bz2 pc1:~# cd stackless-262 pc1:~/stackless-2.6.2# mkdir -p /opt/stackless pc1:~/stackless-2.6.2# ./configure --prefix=/opt/stackless pc1:~/stackless-2.6.2# make pc1:~/stackless-2.6.2# make altinstall }}} Now we install {{{M2Crypto}}}. Download it from [[http://chandlerproject.org/Projects/MeTooCrypto#Downloads]] and unpack it into the virtual machine. <
> From the virtual machine, into the M2Crypto directory unpacked from {{{M2Crypto-0.20.1.tar.gz}}}, type: {{{ pc1:~/M2Crypto-0.20.1# /opt/stackless/bin/python2.6 setup.py build pc1:~/M2Crypto-0.20.1# /opt/stackless/bin/python2.6 setup.py install }}} Then install {{{dnspython}}} too. <
> From virtual machine, let's type: {{{ pc1:~/M2Crypto-0.20.1# cd pc1:~# wget http://www.dnspython.org/kits/1.7.1/dnspython-1.7.1.tar.gz pc1:~# tar xf dnspython-1.7.1.tar.gz pc1:~# cd dnspython-1.7.1 pc1:~/dnspython-1.7.1# /opt/stackless/bin/python2.6 setup.py build pc1:~/dnspython-1.7.1# /opt/stackless/bin/python2.6 setup.py install }}} We DON'T install Netsukuku; we can use the one installed into our system working directory of the host system. Let's stop the virtual machine typing: {{{ pc1:~# halt }}} Then, we can see that into our system, inside the directory where we started the virtual machine, there's a file named {{{pc1.disk}}}. === Make changes to the template file === Starting from the template file and from the file of differences it's possible to create a new template file. From our system terminal let's type: {{{ luca@luca-laptop:~/test-ntkd$ uml_moo -b pc1.disk }}} {{{uml_moo}}} is part of the User Mode Linux (UML) software. <
> The first parameter passed is the backing file that we are using. Referring to this guide, it is the file expanded to 2 GB located into the directory netkit/fs. <
> The second parameter is the diffential file produced starting the virtual machine "pc1". This differences represent the installations done. <
> The third parameter is the name of the new file that we could use as template for other virtual machine. Again, now that we have the new template with 2 GB of disk space and with the needed packages installed, we can use it in this two ways: adding parameters every time: <
> {{{ -m /path/to/file/newbacking}}} <
> {{{ --append=root=98:1}}} <
> or replacing the symbolic link "netkit/fs/netkit-fs" with another pointing to our new file. <
> Here we suppose that has been selected this second method. Anyway, delete the file pc1.disk that uses the old template file. {{{ luca@luca-laptop:~/test-ntkd$ rm pc1.disk }}} == Start the virtual machine and testing ntkd == When we run the virtual machine, we don't need a virtual network interface connected to the Internet, but one or more virtual interfaces linked to a virtual "collision domain". The following command: {{{ luca@luca-laptop:~/test-ntkd$ vstart pc1 --eth0=A --eth1=B --mem=64 }}} start a virtual machine with two virtual network interfaces (eth0 and eth1) linked to two different collision domains, "A" and "B". This interfaces are not initialized from the operative system running into the virtual machines. This is the optimal situation to verify that the daemon ntkd make them actually used. === A simple network topology === Suppose we want to try this network topology: {{{ Collision Domain A | V pc1 ------------- pc2 \ / \ / Collision Domain \ / Collision Domain B ----> \ / <----- C \ / \ / pc3 }}} We can do it with the following command: {{{ luca@luca-laptop:~/test-ntkd$ vstart pc1 --eth0=A --eth1=B --mem=64 luca@luca-laptop:~/test-ntkd$ vstart pc2 --eth0=A --eth1=C --mem=64 luca@luca-laptop:~/test-ntkd$ vstart pc3 --eth0=B --eth1=C --mem=64 }}} Three virtual machines are started and we can see them in three differente windows. Download into our system the current version of Netsukuku. <
> Add a symbolic link into our home. {{{ luca@luca-laptop:~/test-ntkd$ cd luca@luca-laptop:~$ ln -s path/to/netsukuku_trunk netsukuku }}} So {{{~/netsukuku/pyntk}}} is the directory containing the python version of Netsukuku. From the console of each started virtual machine let's type this commands: {{{ pc1:~# cd /hosthome/netsukuku/pyntk pc1:/hosthome/netsukuku/pyntk# /opt/stackless/bin/python2.6 ntkd -i eth0 eth1 -vvvv }}} Now we have a basic environment to test Netsukuku. <
> Into the repository there are some scripts too that are usefull to create complex environment. In this way it is possible to reproduce automatically some specific situations to debug and produce logs that are can help during the debugging and development process. <
> A page that explains the usage of this scripts is [[../ScriptsWithNetkit|here]].