2013年7月19日星期五

openvswitch on my router

To set up a lab at home, I need a openflow compatible swtich, was thinking about buy a netfpga, seems its not cost effective.  Then turn to find a router which can be flashed with openwrt, this approach make more sense for me. Searched from taobao, I got a buffalo's wzr-hp-300np, which has a decent specs.
4 x 1GHz lan  port
32M flash and 64M RAM.
Its supported since openwrt's 10.03 release, so latest release can be flashed too, even the trunk release, if you want to try with 3.10.1 version of kernel. 
It comes with buffalo's stock rom, the one I got is actually a Japanese release, which means you can't flash openwrt directly, because of the bootloaded has been locked to refuse flash non-japanese firmware, tricky here is you can flash dd-wrt by using buffalo's web flash tool, then you can flash openwrt from within dd-wrt. Not too bad.
To use openwrt, you may choose a release from their website or you may build it from trunk, no matter which one you choose, you need set up a openwrt build environment. Because there is no such a openvswitch binary package, so I'd build by myself.

Checkout from my branch, which was upgraded to build openvswitch-1.10.0 version.
https://github.com/zhengpenghou/openvswitch

And then follow instructions on openwrt to flash the image and install openvswitch's package onto your router, your openflow compatible switch is ready.  After boot up the switch, ssh into it, edit the network config accordingly.

Here is mine for your reference, each switch's configuration differs from others.





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdcc:c956:e56e::/48'

config interface 'lan'
	option ifname 'eth0.1'
	option type 'bridge'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.168.1.251'
	option gateway '192.168.1.1'
	option broadcast '192.168.1.255'
	option dns '192.168.1.1'

config interface 'wan'
	option ifname 'eth1'
	option _orig_ifname 'eth1'
	option _orig_bridge 'false'
	option proto 'static'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'
	option enable_vlan4k '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 5t'

config interface
	option ifname 'eth0.2'
	option proto 'static'

config interface
	option ifname 'eth0.3'
	option proto 'static'

config interface
	option ifname 'eth0.4'
	option proto 'static'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '1 5t'

config switch_vlan
	option device 'switch0'
	option vlan '3'
	option ports '2 5t'

config switch_vlan
	option device 'switch0'
	option vlan '4'
	option ports '3 5t'

and then add a bridge,  add port into the bridge


1
2
3
4
5
ovs-vsctl add-br ovsbr0
ovs-vsctl add-port ovsbr0 eth0.1 -- set Interface eth0.1 ofport_request=1
ovs-vsctl add-port ovsbr0 eth0.2 -- set Interface eth0.2 ofport_request=2
ovs-vsctl add-port ovsbr0 eth0.3 -- set Interface eth0.3 ofport_request=3
ovs-vsctl add-port ovsbr0 eth0.4 -- set Interface eth0.4 ofport_request=4
ovs is up to be used now. if you mess it up, reset the router.