Creating OpenVSwitch for GNS3

I’ve had some notes that I made about how to create an OpenVSwitch device for use within GNS3 on Windows.  Other platforms should be similar for these instructions.  So I thought I’d pass it along.

Prerequisites:

==================

Once you have the TAP driver installed, create a tap interface.

  •   Run the following as adminitrator
Start->All Programs->OpenVPN->Utilities
->Add a new TAP virtual ethernet adapter
  • In the Control Panel\Network and Internet\Network Connections, rename the new interface to ‘tap0’.

Tiny core howto
==================
Now that the software is ready, let’s create the OpenVSwitch device for GNS3.  To do this, we are going to create a very small Qemu VM that will be the OpenVSwitch device.  Open a command prompt window and ‘cd’ to the directory where we are going to create the VM.  Copy the TinyCore ISO file to that directory as well.  Then run the following commands to create the disk and start the VM installation.

"c:\Program Files\GNS3\qemu-img.exe" create -f qcow2 ./ovs171.img 200M
"c:\Program Files\GNS3\qemu.exe" -boot d -hda ovs171.img -cdrom .\CorePlus-current.iso -net nic -net tap,ifname=tap0

Install TinyCore into the VM

  • click on TC_Install
    • Start screen
      • Frugal
      • Whole Disk
      • choose sda
      • Install boot loader
      • Click Next arrow button
    • Formatting Options
      • choose default ext4
      • Next
    • Boot Options
      • nothing to choose
      • Next
    • Install Type
      • Core Only
      • Next
    • Review
      • Proceed
    • Done
      • Click the X to close the window
  • Shutdown the VM

Your initial TinyCore VM is now created, so let’s start it up.

"c:\Program Files\GNS3\qemu.exe" -boot c -hda ovs171.img -net nic -net tap,ifname=tap0

OpenVSwitch howto
==================

For the next part, I got several great tips from Brezular’s Technical Blog.

First, using the console window that is open lets’ install OpenSSH and OpenVSwitch packages.

tce-load -w -i openssh.tcz openvswitch.tcz

Start up the SSHd so we can use a remote login session to continue instead of trying to use the console.

sudo -s
cd /usr/local/etc/ssh

mv ssh_config.example ssh_config
mv sshd_config.example sshd_config
/usr/local/etc/init.d/openssh start

Remember to set a password for the ‘tc’ account.

passwd tc

Using the console is painful. Let’s login using SSH.

  • Run ‘ifconfig’ to see what IP you have.
  • SSH into your VM

Now that we are in, let’s initialize the ovsdb.

sudo ovsdb-tool create \
/usr/local/etc/openvswitch/conf.db \
/usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema

The only parts remaining of the installation is the configuration of the tinycore startup and config.

Edit the bootlocal.sh for the service you want to start.

sudo vi /opt/bootlocal.sh

#!/bin/sh
# put other system startup commands here

/usr/local/etc/init.d/openssh start

modprobe openvswitch
modprobe 8021q
modprobe ipv6

ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,manager_options --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach

ovs-vsctl --no-wait init

ovs-vswitchd --pidfile --detach

sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv6.conf.all.forwarding=1

 

Edit the .filetool.lst to let tinycore know what directories to preserve changes after a reboot.

sudo vi /opt/.filetool.lst

opt
home
etc/passwd
etc/shadow
usr/local/etc/ssh
usr/local/etc/openvswitch

Commit any file system changes to CORE.

/usr/bin/filetool.sh -b
sudo reboot

You now have a base OVS install where the drive is only about 27MB is sise. From here you can add you VM to the QEMU Guest list.
GNS3->Edit->Preferences->Qemu->Qemu Guest

Adding the Qemu Guest into a topology will start it with 6 ethernet interfaces. In GNS3, I connected eth0 to my local network and kept eth1-eth5 for OVS. When first creating the Qemu Guest in the preferences, this is when you specify how many interface it will have. Going forward, my host PC IP is 192.168.10.235.

Once you add the VM into the GNS3 canvas, start it up and login to it. Configure the OVS with the 5 interfaces.

sudo ovs-vsctl add-br br0
sudo ovs-vsctl add-port br0 eth1
sudo ovs-vsctl add-port br0 eth2
sudo ovs-vsctl add-port br0 eth3
sudo ovs-vsctl add-port br0 eth4
sudo ovs-vsctl add-port br0 eth5
/usr/bin/filetool.sh -b

If you want to use an SDN controller, you can use the following to configure the switch’s controller location.

sudo ovs-vsctl set-controller br0 \
    tcp:192.168.10.235:6633
/usr/bin/filetool.sh -b

Now, the OVS should look something like this.

tc@box:~$ sudo ovs-vsctl show
370eda01-cfdc-4d3e-a160-ef5381409bd1
    Bridge "br0"
        Controller "tcp:192.168.10.235:6633"
        Port "eth1"
            Interface "eth1"
        Port "eth2"
            Interface "eth2"
        Port "eth3"
            Interface "eth3"
        Port "eth5"
            Interface "eth5"
        Port "eth4"
            Interface "eth4"
        Port "br0"
            Interface "br0"
                type: internal

There you go. You have an OpenVSwitch running in your GNS3 that you can mix in with your topology.

As an added bonus. If you want OpenVSwitch to talk to an sFlow client on your PC, just run something like this.

sudo ovs-vsctl -- --id=@s create sFlow \
    agent=eth0 target=\"192.168.10.235:6343\" header=128 \
    sampling=64 polling=10 -- set Bridge br0 sflow=@s
/usr/bin/filetool.sh -b

And for a NetFlow client on your PC.

sudo ovs-vsctl -- set Bridge br0 \
    netflow=@nf -- --id=@nf create NetFlow \
    targets=\"192.168.10.235:2055\" active-timeout=60
/usr/bin/filetool.sh -b
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: