sexta-feira, 2 de maio de 2014

Kernel-based Openflow OpenVSwitch on TP-Link WR-1043nd with OpenWRT

I spent a couple days compiling the OpenVswitch 2.0 (and 2.1.2) for my TP-Link WR-1043ND V1.8. I tried at first the Open WRT "trunk" version, but due some errors regarding the "PKG_USE_MIPS16:=0" parameters, I gave up and I decided to use the stable 12.10 Attitude Adjustment, r40431. Later, I found the solution for this MIPS16 issue in the menuconfig "Target Options", but I still with the 12.10 stable version.

The result was amazing, much better than the results with Pantou or CPQD's user-mode switches. I obtained 92 Mbps of throughput instead of the 29 Mbps in user-mode switches. Probably I can get more, but my computer interfaces negociated only at 100 Mbps for the Iperf test.
There is also a user-mode option on OpenVSwitch, but is very slow, with 4 Mbps of throughput.
I'll try to figure out the differences in features between the two modes later.

The steps to compile the OVS are the following, using a Linux machine (either virtual or real) with Ubuntu 12.19, 7 GB free space, 1,5 Gb RAM.

apt-get install git quilt build-essential binutils flex bison autoconf gettext texinfo sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk

git clone git://git.openwrt.org/12.09/openwrt.git cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
The next step is choosing the feed location. For the 2.0 OVS version:
echo 'src-git openvswitch git://github.com/alexanderplatz1999/openvswitch.git' >> feeds.conf
or 2.1.2 OVS version:
echo 'src-git openvswitch git://github.com/pichuang/openvwrt.git' >> feeds.conf

./scripts/feeds update openvswitch
./scripts/feeds install -a -p openvswitch
make menuconfig
Select Target Profile (TP-LINK TL-WR1043N/ND)
<*> iperf
-*- openvswitch-common
<*> openvswitch-controller
<*> openvswitch-ipsec
<*> openvswitch-switch
<*> tcpdump
Kernel modules ---> Network Support ---> <*> kmod-tun
Save and Exit
make kernel_menuconfig
> Networking support > Networking options > <*> Open vSwitch
> Networking support > Networking options > <*> Hierarchical Token Bucket (HTB)
Save and Exit
echo '# CONFIG_KERNEL_BRIDGE is not set' >> .config

     You can do the "make" command right now, but the image will be generated without the configuration files. The image will be in the openwrt/bin/ar71xx/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin file.The IP address for telnet access using a LAN port is 192.168.1.1, no login and password.
Transfer the image to the router using the Web GUI if you are using the original TP-Link firmware or WINSCP
BusyBox v1.19.4 (2014-04-08 13:48:14 PDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 ATTITUDE ADJUSTMENT (Attitude Adjustment, r40431)
 -----------------------------------------------------
  * 1/4 oz Vodka      Pour all ingredients into mixing
  * 1/4 oz Gin        tin with ice, strain into glass.
  * 1/4 oz Amaretto
  * 1/4 oz Triple sec
  * 1/4 oz Peach schnapps
  * 1/4 oz Sour mix
  * 1 splash Cranberry juice
 -----------------------------------------------------
root@OpenWrt:~#

    If you want to include the configuration files before the "make", follow this steps in the Linux machine (not the router):
mkdir files
mkdir files/etc
mkdir files/etc/config
mkdir files/etc/rc.d
   Copy the files from this Gist location. The S99ovsboot (adapted from a  script used  in NZNOG SDN workshop) must be saved in the files/etc/rc.d, and the "network", "firewall" and "wireless" in the files/etc/config directory.
With these configuration files, the IP address to access the router is 192.168.1.112 on the WAN port and the openflow controller address is 192.168.1.130.
   You can try the compiled image (tested on a TP-Link WR-1043 V1.8). The IP address of WAN interface is 192.168.1.112 and the controller is 192.168.1.130, but you can change them editing the files /etc/config/network and /etc/rc.d/S99bootovs.

Update:
During the tests I obtained more than 500 Mbps. Is much more than the user space switch (29 Mbps). The results of IPERF test for upload and WGET download of a 400 MB file are the following. Without the DUT (the TP-Link), the performance was about 1 Gbps.

IPERF:
------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54581 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   611 MBytes   513 Mbits/sec

------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54584 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   594 MBytes   498 Mbits/sec

------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54587 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   590 MBytes   495 Mbits/sec

WGET (HTTP)
...
410250K .......... .......... .......... .......... ....      100% 89,1M=6,7s
2014-05-19 13:22:36 (60,2 MB/s) - /dev/null

60,2 MB/s = 481,6 Mbps