Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Mirror Rules with KVM and Open VSwitch  (Read 3231 times)

0 Members and 1 Guest are viewing this topic.

Jreg

    Topic Starter


    Greenhorn

    • Experience: Expert
    • OS: Windows 7
    Mirror Rules with KVM and Open VSwitch
    « on: November 21, 2016, 08:53:35 AM »
    Hello all,

    I have an ubuntu 14.04.5 LTS X32 server that is running KVM/virtmanager with 2 VMs.

    I need all traffic on the box to be mirrored to an interface on one of my VMs.

    I installed Openvswitch and created bridge ovsbr0 with it. I setup eth0 to use ovsbr0.

    I went into virt-manager and changed the nic to "specify shared device name" and the bridge was set to "ovsbr0". On VM start, I observe port vnet0, vnet1, and vnet2 created and attach to the bridge. (output below)

    admin@ubuntu:~$ sudo ovs-vsctl show
    xxx-xxx-xxx-xxx
        Bridge "ovsbr0"
            Port "vnet1"
                Interface "vnet1"
            Port "vnet2"
                Interface "vnet2"
            Port "eth0"
                Interface "eth0"
            Port "ovsbr0"
                Interface "ovsbr0"
                    type: internal
            Port "vnet0"
                Interface "vnet0"
        ovs_version: "2.0.2"


    I was then able to create a rule in openvswitch using the following command to bridge all traffic to one of those ports.

    sudo ovs-vsctl -- set Bridge ovsbr0 mirrors=@m -- --id=@eth0 get Port eth0 -- --id=@vnet0 get Port vnet0 -- --id=@vnet1 get Port vnet1 -- --id=@vnet2 get Port vnet2 -- --id=@m create Mirror name=pvsintfmirror select-dst-port=@vnet0,@vnet1,@eth0 select-src-port=@vnet0,@vnet1,@eth0 output-port=@vnet2

    The mirroring worked but my issue is that on reboot, the VM interfaces seem to get assigned to those vnet ports randomly. Thus, the mirroring rule breaks if the wrong VM interface gets assigned to the wrong port.

    If anyone knows how to ensure that the right interface connects to the vnet2 port so that mirrored traffic flows correctly, that would be a big help.

    Thanks

    camerongray



      Expert
    • Thanked: 306
      • Yes
      • Cameron Gray - The Random Rambings of a Computer Geek
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Mac OS
    Re: Mirror Rules with KVM and Open VSwitch
    « Reply #1 on: November 21, 2016, 10:20:35 AM »
    Random thought coming from my use of Xen (so may be completely useless in your situation) - Check what MAC address the interfaces are coming up with in your VMs and check that they are the same on every reboot - I found with Xen that it would randomly generate a MAC address for each interface every time the VM was started and since it was different the guest OS wouldn't necessarily assign them the same interface number as they had previously (the guest OS sees them as completely new adapters).  If this turns out to be the issue, you'd then want to look and see if there is a way to specify the MAC address you want each interface to have so that it is persistent.

    Jreg

      Topic Starter


      Greenhorn

      • Experience: Expert
      • OS: Windows 7
      Re: Mirror Rules with KVM and Open VSwitch
      « Reply #2 on: November 21, 2016, 03:25:14 PM »
      Thanks for the reply.

      the MAC addresses of the interfaces are coming up the same accross reboots. The interface MAC addresses are stated in VM xml files.