Vnx-tutorial-openvswitch

From VNX
Jump to: navigation, search

VNX tutorial scenario using Open vSwitch and VLANs

Description  

This tutorial scenario is intended to show how to configure and use Open vSwitch (OVS) VLAN support in a VNX scenario. It shows also how to create direct connections between OVS switches.

The scenario is made of three OVS switches connected in a line topology with six Ubuntu LXC virtual machines (VM) connected to them (two VMs to each switch). Besides the host has an interface connected to Net2.

Three VLANs (1,2 and 3) are defined in the scenario, as show in the figure.

Figure 1: tutorial OpenvSwitch scenario topology

Starting the scenario and testing  

Start the scenario with:

cd /usr/share/vnx/examples
vnx -f tutorial_vlan_ovs.xml -v --create

Once the scenario has started, you can test the connectivity among VMs to check that the VLAN configuration works as expected according to the configuration. For example:

  • Ping between h1 and h3 works, as they are in the same VLAN and Net0-Net1 link transports VLAN 1:
  • root@h1:~# ping -c 2 10.1.1.3
    PING 10.1.1.3 (10.1.1.3) 56(84) bytes of data.
    64 bytes from 10.1.1.3: icmp_seq=1 ttl=64 time=0.034 ms
    64 bytes from 10.1.1.3: icmp_seq=2 ttl=64 time=0.036 ms
    
    --- 10.1.1.3 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 999ms
    rtt min/avg/max/mdev = 0.034/0.035/0.036/0.001 ms
    
  • Ping between h1 and h6 does not work, because although they are in the same VLAN, Net1-Net2 link does not transport VLAN 1:
  • root@h1:~# ping -c 1 10.1.1.6
    PING 10.1.1.6 (10.1.1.6) 56(84) bytes of data.
    From 10.1.1.1 icmp_seq=1 Destination Host Unreachable
    
    --- 10.1.1.6 ping statistics ---
    1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
    

Configuration  

Configuring VM interfaces  

To configure a VLAN in a VM interface you just have to add a <vlan> tag inside the <if> definition. For example, for h1:

<if id="1" net="Net0" >
    <vlan>
        <tag id='1'/>
    </vlan>
    <ipv4>10.1.1.1/24</ipv4>
</if>

Configuring interswitch links  

To configure a link between two OVS you have to add a <connection> tag to one of the switches (links are bidirectional, they only have to be defined once). For example, to create the connection between Net0 and Net1 switches:

<net name="Net0" mode="openvswitch" />
<net name="Net1" mode="openvswitch" >
  <connection name='firstlink' net='Net0'>
      <vlan>
         <tag id='1'/>
         <tag id='2'/>
      </vlan>
  </connection>
</net>

The type of interface used to create the link between the switches can be controlled with the type attribute of <connection> tag:

  • type="ovs-patch" to use an OVS Patch port.
  • type="veth" to use a veth virtual Ethernet interface.

Patch port are more efficient, but veth interfaces allow capturing traffic easily.

The VLANs suppported by the connection can be defined using a <vlan> tag similar to the one used in VM interfaces. Several <tag> tags can be added to declare that the link is a trunk supporting two or more VLANs.

In case only one VLAN is defined but we want to force the link to be declared in OVS as a trunk, we can use the trunk attribute of <vlan> tag:

<vlan trunk='yes'>
    <tag id='2'/>
</vlan>

OVS commands issued by VNX when creating the scenario  

The commands issued by VNX to create the OVS switches and configure the VLANs can be observed in the traces shown when issuing the "vnx -f tutorial_vlan_ovs.xml -v --create" command:

/usr/bin/ovs-vsctl --may-exist add-br Net0
/sbin/ip link set Net0 up
/usr/bin/ovs-vsctl --may-exist add-br Net1
/sbin/ip link set Net1 up
/usr/bin/ovs-vsctl --may-exist add-br Net2
/sbin/ip link set Net2 up
/sbin/ip link add firstlink-0 type veth peer name firstlink-1
/sbin/ip link set firstlink-0 up
/sbin/ip link set firstlink-1 up
/usr/bin/ovs-vsctl add-port Net1 firstlink-0
/usr/bin/ovs-vsctl add-port Net0 firstlink-1
/sbin/ip link add secondlink-0 type veth peer name secondlink-1
/sbin/ip link set secondlink-0 up
/sbin/ip link set secondlink-1 up
/usr/bin/ovs-vsctl add-port Net1 secondlink-0
/usr/bin/ovs-vsctl add-port Net2 secondlink-1
/usr/bin/ovs-vsctl add-port Net0 h1-e1
/usr/bin/ovs-vsctl add-port Net0 h2-e1
/usr/bin/ovs-vsctl add-port Net1 h3-e1
/usr/bin/ovs-vsctl add-port Net1 h4-e1
/usr/bin/ovs-vsctl add-port Net2 h5-e1
/usr/bin/ovs-vsctl add-port Net2 h6-e1
/usr/bin/ovs-vsctl set port h1-e1 tag=1
/usr/bin/ovs-vsctl set port h2-e1 tag=2
/usr/bin/ovs-vsctl set port h3-e1 tag=1
/usr/bin/ovs-vsctl set port h4-e1 tag=3
/usr/bin/ovs-vsctl set port h5-e1 tag=3
/usr/bin/ovs-vsctl set port h6-e1 tag=1
/usr/bin/ovs-vsctl set port firstlink-1 trunk=1,2
/usr/bin/ovs-vsctl set port firstlink-0 trunk=1,2
/usr/bin/ovs-vsctl set port secondlink-1 trunk=3
/usr/bin/ovs-vsctl set port secondlink-0 trunk=3
/usr/bin/ovs-vsctl set port Net2 tag=1

tutorial_vlan_ovs.xml scenario  

<?xml version="1.0" encoding="UTF-8"?>

<!--

~~~~~~~~~~~~~~~~~~~~
VNX Sample scenarios
~~~~~~~~~~~~~~~~~~~~

Name:        tutorial_vlan_ovs
Description:

This file is part of the Virtual Networks over LinuX (VNX) Project distribution.
(www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es)

Departamento de Ingenieria de Sistemas Telematicos (DIT)
Universidad Politecnica de Madrid
SPAIN

-->

<vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
  <global>
    <version>2.0</version>
    <scenario_name>tutorial_vlan_ovs</scenario_name>
    <automac offset="5"/>
    <vm_mgmt type="none" />
    <!--vm_mgmt type="private" network="10.250.0.0" mask="24" offset="16">
       <host_mapping />
    </vm_mgmt-->
    <vm_defaults>
	    <console id="0" display="no"/>
	    <console id="1" display="yes"/>
    </vm_defaults>
  </global>

  <net name="Net0" mode="openvswitch" />
  <net name="Net1" mode="openvswitch" >
	<connection name='firstlink' net='Net0'>
	    <vlan>
	       <tag id='1'/>
	       <tag id='2'/>
	    </vlan>
    </connection>
	<connection name='secondlink' net='Net2'>
	   <vlan>
         <tag id='3'/>
       </vlan>
    </connection>
  </net>
  <net name="Net2" mode="openvswitch" />

  <!-- NODES -->
  <vm name="h1" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <mem>512M</mem>
    <if id="1" net="Net0" >
	   <vlan>
	     <tag id='1'/>
      </vlan>
      <ipv4>10.1.1.1/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <vm name="h2" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <mem>512M</mem>
    <if id="1" net="Net0" >
      <vlan>
	     <tag id='2'/>
      </vlan>
      <ipv4>10.1.1.2/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <vm name="h3" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <if id="1" net="Net1" >
      <vlan>
	    <tag id='1'/>
      </vlan>
      <ipv4>10.1.1.3/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <vm name="h4" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <if id="1" net="Net1" >
      <vlan>
        <tag id='3'/>
      </vlan>
      <ipv4>10.1.1.4/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <vm name="h5" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <if id="1" net="Net2" >
      <vlan>
        <tag id='3'/>
      </vlan>
      <ipv4>10.1.1.5/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <vm name="h6" type="lxc" subtype="" os="">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_lxc</filesystem>
    <if id="1" net="Net2" >
      <vlan>
		<tag id='1'/>
      </vlan>
      <ipv4>10.1.1.6/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp/" perms="644">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

  </vm>

  <host>
    <hostif net="Net2">
      <vlan>
		<tag id='1'/>
      </vlan>
      <ipv4>10.1.1.7/24</ipv4>
    </hostif>
  </host>

</vnx>