How to do libvirt network configure?

At the moment, by default, when creating instance for controllers and databases, xml is used to define a network of the following form:

<network>
  <name>ovs-network</name>
  <forward mode='bridge'/>
  <bridge name='br-ex'/>
  <virtualport type='openvswitch'/>
  <portgroup name='all-vlan' default='yes'>
  </portgroup>
</network>

Where br-ex is the bridge to which the instance interfaces will connect, ovs-network is network name.

With this network setup, all tagged and untagged networks will be forwarded to the instance as they are for br-ex.

In order to make one vlan from br-ex untagged for instance, you need to list the tagged vlans you need to forward and specify one untagged vlan:

<network>
  <name>ovs-network</name>
  <forward mode='bridge'/>
  <bridge name='br-ex'/>
  <virtualport type='openvswitch'/>
  <portgroup name='all-vlan' default='yes'>
    <vlan>
      <tag id='4001' nativeMode='untagged'/>
      <tag id='4020' />
    </vlan>
  </portgroup>
</network>

With this network setup, vlan 4001 will be forwarded to the instance as an untagged vlan, and 4020 as a tagged one. You can specify many tagged vlans for forwarding.

You can also specify several portgroups on the same network and specify the desired value in the instance settings.

Example with multiple portgroups:

<network>
  <name>ovs-network</name>
  <forward mode='bridge'/>
  <bridge name='br-ex'/>
  <virtualport type='openvswitch'/>
  <portgroup name='all-vlan' >
    <vlan>
      <tag id='4001' nativeMode='untagged'/>
      <tag id='4020' />
    </vlan>
  </portgroup>
  <portgroup name='other1' >
    <vlan>
      <tag id='4002' nativeMode='untagged'/>
      <tag id='4022' />
    </vlan>
  </portgroup>
</network>

Example of the xml part for instance related to the network interface:

<interface type='network'>
  <mac address='52:54:00:2f:00:02'/>
  <source network='ovs-network' portgroup='all-vlan'/>
  <virtualport type='openvswitch'>
  </virtualport>
  <model type='virtio'/>
  <mtu size='1500'/>
</interface>

Where portgroup='all-vlan' is the parameter that was specified earlier in the network settings.

Network creation command:

virsh net-define /tmp/ovs-network.xml

Where /tmp/ovs-network.xml is the file that describes the network.

Network activation command:

virsh net-start ovs-network

Where ovs-network is the name of the created network.

Command to set network activation after system restart:

virsh net-autostart ovs-network