Author Archive

ZhengPeng Hou

lxc and openvswtich

Intended to use ovs with lxc before, but lxc only support linux bridge:

int lxc_bridge_attach(const char *bridge, const char *ifname)
{
int fd, index, err;
struct ifreq ifr;

if (strlen(ifname) >= IFNAMSIZ)
return -EINVAL;

index = if_nametoindex(ifname);
if (!index)
return -EINVAL;

process_lock();
fd = socket(AF_INET, SOCK_STREAM, 0);
process_unlock();
if (fd < 0)
return -errno;

strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
ifr.ifr_ifindex = index;
err = ioctl(fd, SIOCBRADDIF, &ifr);
process_lock();
close(fd);
process_unlock();
if (err)
err = -errno;

return err;
}

here we can see only linux bridg supported, if you try to attach to ovs, it fails.
with help from a friend, had some changes here:


--- lxc-1.0.0~alpha1.orig/src/lxc/network.c 2013-09-11 06:22:00.000000000 +0800
+++ lxc-1.0.0~alpha1/src/lxc/network.c 2013-10-12 22:01:28.926679880 +0800
@@ -986,6 +986,9 @@
{
int fd, index, err;
struct ifreq ifr;
+ struct stat sb;
+ char brdirname[22 + IFNAMSIZ + 1] = {0};
+ char ovscmd[20 + IFNAMSIZ * 2 + 1] = {0};

if (strlen(ifname) >= IFNAMSIZ)
return -EINVAL;
@@ -993,6 +996,15 @@
index = if_nametoindex(ifname);
if (!index)
return -EINVAL;
+ snprintf(brdirname, 22 +IFNAMSIZ + 1, "/sys/class/net/%s/bridge", bridge);
+ if (stat(brdirname, &sb) == -1) {
+ if (errno == ENOENT) {
+ snprintf(ovscmd, 20 + IFNAMSIZ * 2 + 1, "ovs-vsctl add-port %s %s", bridge, ifname);
+ err = system(ovscmd);
+ } else {
+ err = -EINVAL;
+ }
+ } else if (S_ISDIR(sb.st_mode)) {

fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
@@ -1004,7 +1016,9 @@
close(fd);
if (err)
err = -errno;
-
+ } else {
+ err = -EINVAL;
+ }
return err;
}

This patch was made for lxc in ubuntu 13.10, I have it build in my ppa. binary package can be found from my ppa
ppa:zhengpeng-hou/dev.
So now, I have all my containers bridged to my home network directly.
https://docs.google.com/file/d/0BwNEP6aM800AMUhHcDdQb3B1NEU/edit?usp=sharing

ZhengPeng Hou

juju-core with local provider

Last night, spent some time with latest jujuc-core in saucy, was interested with local provider support which was added recently. Couple of things worth to be known:
1 juju-core now use mongodb to replace zookeeper, so to play with local provider, you need install lxc, mongodb. I have whishlist against juju-core packaging for providing a meta package to install those dependencies.
2 After install mongodb, do remember to stop the server manually, because juju bootstrap will create its own upstart scripts to handle start/stop the service.
3 The configuration of local provider is quite simple now, you may copy and paste the one by running juju init, not need modify anything, I did comment out root-dir, which made me run into .
4 Two commands need to be run with sudo, one is bootstrap, the other is destroy-environment.

ZhengPeng Hou

openvswitch on openwrt 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.

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

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.