NEmu

Network Emulator for Mobile Universes

Tutorial - Setup a home network

You may be interested in creating a customized virtual network with heterogeneous virtual machines and operating systems (Android, Linux, Windows, etc.) in order to reproduce a home based network (with a router box) like the following one:

homenet

Configuration

First of all, you should setup a base virtual file system for each of your desired operating systems. After this step, a NEmu script for your virtual network should be like this one:

InitNemu(session='myhomenet')

VHostConf('base', enable_kvm=None, localtime=None, k='fr'
                , cpu='core2duo', display='sdl', vga='std')

VHost('alice', conf='base', hds=[VFs('windows8.img', 'cow', tag='alice.img')]
                          , nics=[VNic()], m=2048)

VHost('bob', conf='base', hds=[VFs('android4.img', 'cow', tag='bob.img')]
                        , nics=[VNic(model='pcnet')], m=256)

VHost('calvin', conf='base', hds=[VFs('win7.img', 'cow', tag='calvin.img')]
                           , nics=[VNic()], m=2048)

VHost('dean', conf='base', hds=[VFs('debian7.img', 'cow', tag='dean.img')]
                         , nics=[VNic()], m=1024)

VRouter('box', nics=[VNic(), VNic()], services=[
                Service('ipforward'),
                Service('ifup', '1:192.168.0.1'),
                Service('gateway', 0),
                Service('masquerade', ipsrc='192.168.0.0/24'),
                Service('dnsmasq', domain='local', net='192.168.0.0/24',
                       start='192.168.0.10', end='192.168.0.20', ifaces=[1])]
             , enable_kvm=None, localtime=None, k='fr'
             , display='sdl', vga='std')

VSlirp('slirp', net='192.160.0.0/24')

VSwitch('link', niface=5)

Link(client='router:0', core='slirp')
Link(client='router:1', core='link:0')
Link(client='alice', core='link:1')
Link(client='bob', core='link:2')
Link(client='calvin', core='link:3')
Link(client='dean', core='link:4')

The first line is the initialization of the NEmu session.

The VHostConf line is a common configuration for our virtual machines. This common configuration is setup with a French keyboard and an Intel Core 2 Duo processor. We choose to activate the KVM hardware acceleration in order to improve the performances of our virtual machines. The SDL library is used to display the window of virtual machines. The localtime option enables a synchronization between the real and virtual clocks.

All of our virtual machines (alice, bob, calvin and dean) are setup with the previous common configuration.

A VRouter, called box, is also setup with 2 network interface cards, IP forward enabled and a DHCP/DNS server on the sub-net local:192.168.0.0/24. The NAT masquerading is also activated as a standard home network box.

We setup a VSlirp in order to enable an Internet connection on the sub-net 192.160.0.0/24.

We also setup a VSwitch in order to connect all of our virtual nodes.

Finally, we link the virtual router to the slirp, and each of virtual nodes to the switch.

That's all for the configuration !
 

And action !

We start NEmu in interactive mode after loading the previous script:

$ nemu -f script.py -i
...
[nemu]~> 

Then, we start the virtual network:

[nemu]~> StartNemu()

The virtual network is now launched and you can start to work

Android specificity

Some versions of Android unfortunately do not fix the DNS server address during the DHCP process. Thus, you may have to fix it manually form the Android Terminal Emulator application:

user$ su root
root$ setprop net.dns1 {@IP DNS}

In our configuration, and because our box contains a DNS server, the related operation will be:

user$ su root
root$ setprop net.dns1 192.168.0.1

Stop, clean and restore

At the end of your work, you can stop the session and delete it in a very simple way:

[nemu]~> StopNemu()
[nemu]~> DelNemu()
[nemu]~> quit()

Nevertheless, if you want to save your session and restore it after, you can perform the following command:

[nemu]~> StopNemu()
[nemu]~> SaveNemu('myhomenet.tgz')
[nemu]~> DelNemu()
[nemu]~> quit()

When you will want to restore the session, you will just have to launch:

$ nemu
[nemu]~> RestoreNemu('myhomenet.tgz')
[nemu]~> ImportNemu('script.py')
[nemu]~> StartNemu()

A configuration script is also cloned in the save archive. Thus you can import it instead of loading the original one:

$ nemu
[nemu]~> RestoreNemu('myhomenet.tgz')
[nemu]~> ImportNemu('/tmp/myhomenet/nemu.conf')
[nemu]~> StartNemu()

Your session, will be restored and you will be able to continue your work.