title: LXC with Open vSwitch
body: <p>I want to try OVS (software Linux switch) <a href="http://openvswitch.org/" rel="nofollow">http://openvswitch.org/</a> with my LXC container with Ubuntu as host and guest. So I have installed it:</p>
  
  <pre><code># apt-get install openvswitch-switch
  </code></pre>
  
  <p>Configured according this doc <a href="https://infologs.wordpress.com/2015/06/19/how-to-attach-lxc-container-to-ovs-openvswitch/" rel="nofollow">https://infologs.wordpress.com/2015/06/19/how-to-attach-lxc-container-to-ovs-openvswitch/</a></p>
  
  <ol>
  <li><p>Created test container:</p>
  
  <pre><code># lxc-create -t ubuntu -n veth03-ovs -- -r trusty
  </code></pre></li>
  <li><p>Created ovs bridge and assigned IP to it:</p>
  
  <pre><code># ovs-vsctl add-br switch0
  # ip add add 192.168.100.1/24 dev switch0
  </code></pre></li>
  </ol>
  
  <p>Let it be new network 192.168.100.0/24 and switch0 (according to my understanding) will be first address (gateway) there.</p>
  
  <p>Looks fine:</p>
  
  <pre><code># ip a
  ...
  4: ovs-system: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN group default 
      link/ether 52:9d:e1:60:1d:56 brd ff:ff:ff:ff:ff:ff
  5: switch0: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN group default 
      link/ether 16:63:eb:47:13:41 brd ff:ff:ff:ff:ff:ff
      inet 192.168.100.1/24 scope global switch0
         valid_lft forever preferred_lft forever
  </code></pre>
  
  <p>Bridge interface status:</p>
  
  <pre><code># ovs-vsctl show
  1b236728-4637-42a5-8b81-53d4c93a6803
      Bridge "switch0"
          Port "switch0"
              Interface "switch0"
                  type: internal
      ovs_version: "2.3.2"
  </code></pre>
  
  <ol start="3">
  <li><p>Edited LXC config for veth03-ovs container for using this bridge:</p>
  
  <pre><code># vim /var/lib/lxc/veth03-ovs/config
  ...
  lxc.network.type = veth
  lxc.network.flags = up
  
  lxc.network.script.up = /etc/lxc/ifup
  lxc.network.script.down = /etc/lxc/ifdown
  # lxc.network.veth.pair = lxc0
  lxc.network.hwaddr = 00:16:3e:15:b3:62
  lxc.network.ipv4 = 192.168.100.10
  </code></pre></li>
  </ol>
  
  <p>So I want to point 192.168.100.10 for internal interface of container.</p>
  
  <p><strong>/etc/lxc/ifup</strong> and <strong>/etc/lxc/ifdown</strong> add/remove ports for this bridge after start/stop of container.</p>
  
  <pre><code># cat /etc/lxc/ifup
  #!/bin/bash
  
  BRIDGE=”switch0″
  ovs-vsctl –may-exist add-br $BRIDGE
  ovs-vsctl –if-exists del-port $BRIDGE $5
  ovs-vsctl –may-exist add-port $BRIDGE $5
  
  # cat /etc/lxc/ifdown 
  #!/bin/bash
  ovsBr=’switch0′
  ovs-vsctl –if-exists del-port ${ovsBr} $5
  </code></pre>
  
  <p>So now I want to start container but getting:</p>
  
  <pre><code># lxc-start -n veth03-ovs --logfile /tmp/log
  lxc-start: lxc_start.c: main: 344 The container failed to start.
  lxc-start: lxc_start.c: main: 346 To get more details, run the container in foreground mode.
  lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --logfile and --logpriority options.
  
  # cat /tmp/log
    lxc-start 1448974395.199 ERROR    lxc_conf - conf.c:run_buffer:342 - Script exited with status 1
    lxc-start 1448974395.225 ERROR    lxc_conf - conf.c:lxc_create_network:3079 - failed to create netdev
    lxc-start 1448974395.225 ERROR    lxc_start - start.c:lxc_spawn:950 - failed to create the network
    lxc-start 1448974395.225 ERROR    lxc_start - start.c:__lxc_start:1213 - failed to spawn 'veth03-ovs'
    lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:344 - The container failed to start.
    lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:346 - To get more details, run the container in foreground mode.
    lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:348 - Additional information can be obtained by setting the --logfile and --logpriority options.
  </code></pre>
  
  <p>I suppose that error in <strong>lxc.network.script.up</strong> / <strong>lxc.network.script.down</strong> scripts and its are not getting <code>$5</code> parameter, which should be intermediate interface passed by LXC to OVS. But I am not sure.</p>
  
  <p>Is LXC supports Open vSwitch? <a href="https://github.com/lxc/lxc/issues/256" rel="nofollow">https://github.com/lxc/lxc/issues/256</a></p>