LINUXOR.SK ... open source notes ...

5. Connecting two network namespaces (ns1, ns2) - with two ports on a distributed OVS switch (openvswitch)

category: howtoz · date: 2016-11-01 · updated: 2018-01-09

The Slovak original of this document: 5. Prepojenie dvoch sieťových menných priestorov (ns1, ns2) - pomocou 2 portov na distribuovanom prepínači OVS (openvswitch) (slovensky).

2016 - Linux NET Namespace - Connecting two network namespaces (ns1, ns2) - with two ports on a distributed OVS switch (openvswitch)

asciiart
======================================================================================================================
 [1] NET namespace - Connecting two network namespaces (ns1, ns2) - with two ports on a distributed
                     prepinaci OVS (openvswitch)
======================================================================================================================

     +------------------+                  +-------------------------------+                  +------------------+
     | ns1        veth1 |=====ovs-port=====|              ovs0             |=====ovs-port=====| veth2        ns2 |
     +------------------+                  +-------------------------------+                  +------------------+
       namespace "ns1"                      hostitelsky system (openvswitch)                    namespace "ns2"

    The first OVS port - an internal OVS port "veth1" is created on the OVS switch and given to namespace "ns1".
    The second OVS port - an internal OVS port "veth2" is created on the OVS switch and given to namespace "ns2".

    These test scenarios use RedHat Linux 7.3, which does carry the kernel module for Openvswitch, but
    no longer carries the user tools that administer openvswitch (ovs-vsctl). Those user tools are
    carried in other Redhat products such as Red Hat Openstack Platform. At this point what we
    there is nothing for it but to install Openvswitch from source, see [1.0.X].

    [1.0.1] Installing the distributed switch Openvswitch successfully needs the tools to compile it and
            kniznice, ktore Openvswitch vyuziva.
    ----------------------------------------------------------------------------------------------------------------
    # yum install gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake \
      rpm-build redhat-rpm-config libtool checkpolicy selinux-policy-devel python-six
    ----------------------------------------------------------------------------------------------------------------

    [1.0.2] - Create a directory to build the RPM package from source in, and download the current source package
              pre Openvswitch.
    ----------------------------------------------------------------------------------------------------------------
    # mkdir -p /root/rpmbuild/SOURCES
    # cd /root/rpmbuild/SOURCES
    # wget http://openvswitch.org/releases/openvswitch-2.6.1.tar.gz
    ----------------------------------------------------------------------------------------------------------------

    [1.0.3] - Unpack the source package, compile it and build the RPM package
              The RPM packages for Openvswitch appear in "/root/rpmbuild/RPMS/x86_64/"
    ----------------------------------------------------------------------------------------------------------------
    # cd /root/rpmbuild/SOURCES/
    # tar -xvf ./openvswitch-2.6.1.tar.gz
    # sed 's/openvswitch-kmod, //g' openvswitch-2.6.1/rhel/openvswitch.spec > openvswitch-2.6.1/rhel/openvswitch_no_kmod.spec
    # rpmbuild -bb --nocheck openvswitch-2.6.1/rhel/openvswitch_no_kmod.spec
    ----------------------------------------------------------------------------------------------------------------

    [1.0.4] - Nainstalujeme RPM balicek s Openvswitch
    ----------------------------------------------------------------------------------------------------------------
    # cd /root/rpmbuild/RPMS/x86_64/
    # yum localinstall ./openvswitch-2.6.1-1.x86_64.rpm
    ----------------------------------------------------------------------------------------------------------------

    [1.1] - Odstranime (ak existuju) sietove menne priestory "ns1" a "ns2".
    [1.2] - Create two network (NET) namespaces, "ns1" and "ns2".
    ----------------------------------------------------------------------------------------------------------------
    [1.1]# ip netns del ns1 &>/dev/null
    [1.1]# ip netns del ns2 &>/dev/null
    [1.2]# ip netns add ns1
    [1.2]# ip netns add ns2
    ----------------------------------------------------------------------------------------------------------------

    [1.3] - V hostitelskom systeme spustime Openvswitch a
    [1.3] - vytvorime distribuovany (openvswitch) ethernet prepinac/bridge s menom "ovs0".
    ----------------------------------------------------------------------------------------------------------------
    [1.3]# /etc/init.d/openvswitch start
    [1.3]# ovs-vsctl add-br ovs0
    ----------------------------------------------------------------------------------------------------------------

    [1.4]TERM1 - In network namespace "ns1", exec the command "bash".
    [1.5]TERM2 - In network namespace "ns2", exec the command "bash".
    ----------------------------------------------------------------------------------------------------------------
    [1.4]TERM1# ip netns exec ns1 bash
    [1.5]TERM2# ip netns exec ns2 bash
    ----------------------------------------------------------------------------------------------------------------

    [1.6] - Na distribuovanom prepinace "ovs0" vytvorime interny port "veth1-ovs".
    [1.7] - Virtualny ethernet adapter "veth1-ovs" umiestnime do sietoveho menneho priestoru "ns1".

    [1.8] - Na distribuovanom prepinace "ovs0" vytvorime interny port "veth2-ovs".
    [1.9] - Virtualny ethernet adapter "veth2-ovs" umiestnime do sietoveho menneho priestoru "ns2".
    ----------------------------------------------------------------------------------------------------------------
    [1.6]# ovs-vsctl add-port ovs0 veth1-ovs -- set Interface veth1-ovs type=internal
    [1.7]# ip link set veth1-ovs netns ns1

    [1.8]# ovs-vsctl add-port ovs0 veth2-ovs -- set Interface veth2-ovs type=internal
    [1.9]# ip link set veth2-ovs netns ns2
    ----------------------------------------------------------------------------------------------------------------

    [1.10] - Bring the network adapter "veth1-ovs" up in namespace "ns1" and give it the address "10.0.0.1".
    [1.11] - Bring the network adapter "veth2-ovs" up in namespace "ns2" and give it the address "10.0.0.2".

    [1.12] - From network namespace "ns1", test that namespace "ns2" answers.
    [1.13] - From network namespace "ns2", test that namespace "ns1" answers.
    -------------------------------------------------------------------------
    [1.10]# ip netns exec ns1 ifconfig veth1-ovs 10.0.0.1/24 up
    [1.11]# ip netns exec ns2 ifconfig veth2-ovs 10.0.0.2/24 up

    [1.12]# ip netns exec ns1 ping 10.0.0.2
    [1.13]# ip netns exec ns2 ping 10.0.0.1
    ----------------------------------------------------------------------------------------------------------------

    [1.14] - Na distribuovanom prepinaci "ovs0" zobrazime informacie o konfiguracii portov.
    ----------------------------------------------------------------------------------------------------------------
    [1.14]# ovs-vsctl show
    ----------------------------------------------------------------------------------------------------------------
    31dff9cb-870d-4093-915d-28dc71f8ac6e
        Bridge "ovs0"
            Port "ovs0"
                Interface "ovs0"
                    type: internal
            Port "veth1-ovs"
                Interface "veth1-ovs"
                    type: internal
            Port "veth2-ovs"
                Interface "veth2-ovs"
                    type: internal
        ovs_version: "2.6.1"
    ----------------------------------------------------------------------------------------------------------------
← howtoz(EN | SK)