|
| 1 | +.. _open_vswitch: |
| 2 | + |
| 3 | +How to enable OVS in ACRN |
| 4 | +######################### |
| 5 | +Hypervisors need the ability to bridge network traffic between VMs |
| 6 | +and with the outside world. This tutorial describes how to |
| 7 | +use `Open Virtual Switch (OVS) |
| 8 | +<https://www.openvswitch.org/>`_ bridge in ACRN for this purpose. |
| 9 | + |
| 10 | +.. note:: |
| 11 | + OVS is provided as part of the ``service-os`` |
| 12 | + bundle. Use ClearLinux OS version ``29660`` or higher. |
| 13 | + |
| 14 | +What is OVS |
| 15 | +*********** |
| 16 | +Open vSwitch (OVS) is an open-source implementation of |
| 17 | +a distributed virtual multilayer switch that provides a switching |
| 18 | +stack for hardware virtualization environments. OVS supports multiple |
| 19 | +protocols and standards used in computer networks. For more detailed |
| 20 | +OVS information, please refer to `what-is-ovs |
| 21 | +<http://docs.openvswitch.org/en/latest/intro/what-is-ovs/#what-is-open-vswitch>`_. |
| 22 | + |
| 23 | +Why OVS |
| 24 | +******* |
| 25 | +Open vSwitch is targeted at multi-server virtualization deployments, |
| 26 | +a landscape not well suited for ACRN's built-in L2 switch (the `Linux bridge |
| 27 | +<https://wiki.linuxfoundation.org/networking/bridge>`_). |
| 28 | +These environments are often characterized by highly dynamic end-points, |
| 29 | +the maintenance of logical abstractions, and (sometimes) integration with |
| 30 | +or offloading to special purpose switching hardware. |
| 31 | +For more reasons about why Open vSwitch is used, please refer to `why-ovs |
| 32 | +<http://docs.openvswitch.org/en/latest/intro/why-ovs/>`_. |
| 33 | + |
| 34 | +.. _enable_ovs_in_ACRN: |
| 35 | + |
| 36 | +How to enable OVS in ACRN |
| 37 | +************************* |
| 38 | +The OVS service is included with the Clear Linux ``service-os`` bundle. |
| 39 | + |
| 40 | +After booting the ACRN Service OS, disable the Clear Linux |
| 41 | +autoupdate feature before setting up the OVS bridge to |
| 42 | +prevent autoupdate from restoring the default bridge after |
| 43 | +a system update:: |
| 44 | + |
| 45 | + # swupd autoupdate --disable |
| 46 | + |
| 47 | +You can then start the OVS service with the command:: |
| 48 | + |
| 49 | + # systemctl start openvswitch |
| 50 | + |
| 51 | +To start OVS automatically after a reboot, you should also use this command:: |
| 52 | + |
| 53 | + # systemctl enable openvswitch |
| 54 | + |
| 55 | +The default ``acrn-br0`` bridge is created by the Service VM ``systemd`` and |
| 56 | +supports the User VM network. |
| 57 | + |
| 58 | +.. figure:: images/default-acrn-network.png |
| 59 | + :align: center |
| 60 | + |
| 61 | + Default ACRN Network |
| 62 | + |
| 63 | +How to use OVS bridge |
| 64 | +********************* |
| 65 | +#. Disable acrn network configuration:: |
| 66 | + |
| 67 | + # cd /usr/lib/systemd/network/ |
| 68 | + # mv 50-acrn.network 50-acrn.network_bak |
| 69 | + |
| 70 | +#. Modify ``50-eth.network`` to enable DHCP on OVS bridge |
| 71 | + |
| 72 | + .. code-block:: none |
| 73 | +
|
| 74 | + [Match] |
| 75 | + Name=ovs-br0 |
| 76 | +
|
| 77 | + [Network] |
| 78 | + DHCP=ipv4 |
| 79 | +
|
| 80 | +#. Create OVS bridge and ``tap1`` network interface:: |
| 81 | + |
| 82 | + # ovs-vsctl add-br ovs-br0 |
| 83 | + # ip tuntap add dev tap1 mode tap |
| 84 | + # ip link set dev tap1 down |
| 85 | + # ip link set dev tap1 up |
| 86 | + |
| 87 | +#. Add ``eno1``, ``tap1`` into OVS bridge:: |
| 88 | + |
| 89 | + # ovs-vsctl add-port ovs-br0 eno1 |
| 90 | + # ovs-vsctl add-port ovs-br0 tap1 |
| 91 | + |
| 92 | +#. Modify ``launch_uos.sh`` script to enable ``tap1`` device before launching the User VM: |
| 93 | + |
| 94 | + .. code-block:: none |
| 95 | +
|
| 96 | + # sed -i "s/virtio-net,tap0/virtio-net,tap1/" /usr/share/acrn/samples/nuc/launch_uos.sh |
| 97 | +
|
| 98 | + .. note:: |
| 99 | + If you set up the User VM via `acrn_quick_setup.sh |
| 100 | + <https://raw.githubusercontent.com/projectacrn/acrn-hypervisor/master/doc/getting-started/acrn_quick_setup.sh>`_, |
| 101 | + then replace ``/usr/share/acrn/samples/nuc/launch_uos.sh`` with ``/root/launch_uos_<version>.sh`` |
| 102 | + in ``sed`` command above. |
| 103 | + |
| 104 | +#. The User VM and Service VM network will work after rebooting the host via ``ovs-br0`` |
| 105 | + |
| 106 | +Example for VLAN network based on OVS in ACRN |
| 107 | +********************************************* |
| 108 | +We will use the OVS bridge VLAN feature to support network isolation |
| 109 | +between VMs. :numref:`ovs-example1` shows an example with four VMs in two hosts, |
| 110 | +with the hosts directly connected by a network cable. The VMs are interconnected |
| 111 | +through statically configured IP addresses, and use VLAN id to put VM1 of |
| 112 | +HOST1 and VM1 of HOST2 into a VLAN. Similarly, VM2 of HOST1 and VM2 of |
| 113 | +HOST2 are put into a VLAN. In this configuration, the VM1s can communicate with each other, |
| 114 | +and VM2s can directly communicate with each other, but VM1s and VM2s cannot connect. |
| 115 | + |
| 116 | +.. figure:: images/example-of-OVS-usage.png |
| 117 | + :align: center |
| 118 | + :name: ovs-example1 |
| 119 | + |
| 120 | + An example of OVS usage in ACRN |
| 121 | + |
| 122 | +Follow these steps to set up OVS networks on both HOSTs: |
| 123 | + |
| 124 | +#. Set up ``ovs-br0`` instead of ``acrn-br0``, (refer to the the previous section |
| 125 | + :ref:`enable_ovs_in_ACRN` for details). |
| 126 | + |
| 127 | +#. Add ``eno1``, ``tap<VM number>`` into OVS bridge: |
| 128 | + |
| 129 | + .. code-block:: none |
| 130 | +
|
| 131 | + # ovs-vsctl add-port ovs-br0 eno1 |
| 132 | + # ovs-vsctl add-port ovs-br0 tap1 tag=101 |
| 133 | + # ovs-vsctl add-port ovs-br0 tap2 tag=102 |
| 134 | + # sed -i "s/virtio-net,tap0/virtio-net,tap1/" <1st launch_uos script> |
| 135 | + # sed -i "s/virtio-net,tap0/virtio-net,tap2/" <2nd launch_uos script> |
| 136 | + # reboot |
| 137 | +
|
| 138 | +#. Configure the static IP address on both HOSTs and it's VMs:: |
| 139 | + |
| 140 | + # <HOST_1 Service VM>: |
| 141 | + # ifconfig ovs-br0 192.168.1.100 |
| 142 | + # <HOST_1 User VM1>: |
| 143 | + # ifconfig enp0s4 192.168.1.101 |
| 144 | + # <HOST_1 User VM2>: |
| 145 | + # ifconfig enp0s4 192.168.1.102 |
| 146 | + # |
| 147 | + # <HOST_2 Service VM>: |
| 148 | + # ifconfig ovs-br0 192.168.1.200 |
| 149 | + # <HOST_2 User VM1>: |
| 150 | + # ifconfig enp0s4 192.168.1.201 |
| 151 | + # <HOST_2 User VM2>: |
| 152 | + # ifconfig enp0s4 192.168.1.202 |
| 153 | + |
| 154 | +#. After that, it will succeed to ``ping`` from VM1 of HOST1 to VM1 of HOST2, |
| 155 | + but fail to ``ping`` from VM1 of HOST1 to VM2 of HOST2. |
0 commit comments