qemu/kvm 桥接_QEMU / KVM网络机制

qemu/kvm 桥接

Introduction

介绍

As we know, network subsystems are important in computer systems since they are I/O systems and need to be optimized with many algorithms and skills. This article will introduce how QEMU/KVM [2] network part works. In order to put everything simple and easy to understand, we will begin with several examples and then understand how it works internally.

众所周知, 网络子系统在计算机系统中很重要,因为它们是I / O系统,需要使用许多算法和技能进行优化。 本文将介绍QEMU / KVM [2]网络部分的工作方式。 为了使所有内容简单易懂,我们将以几个示例开始,然后再了解其内部工作方式。

Examples

例子

In this example, we will use TAP device [1] as QEMU/KVM host network device driver and VirtIO driver will be used to send/receive network packets/data between Host OS and Guest OS. See following “Start QEMU/KVM virtual machine” commands in details.

在此示例中,我们将使用TAP设备[1]作为QEMU / KVM主机网络设备驱动程序,而VirtIO驱动程序将用于在主机OS和来宾OS之间发送/接收网络数据包/数据。 详细信息,请参见以下“启动QEMU / KVM虚拟机”命令。


sudo x86_64-softmmu/qemu-system-x86_64 /home/hkucs/colo_ubuntu_single.img -machine pc-i440fx-2.3,accel=kvm,usb=off -netdev tap,id=hn0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -device virtio-net-pci,id=net-pci0,netdev=hn0 -vnc :7 -m 2048 -smp 2 -device piix3-usb-uhci -device usb-tablet -monitor stdio


sudo x86_64-softmmu/qemu-system-x86_64 /home/hkucs/colo_ubuntu_single.img -machine pc-i440fx-2.3,accel=kvm,usb=off -netdev tap,id=hn0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -device virtio-net-pci,id=net-pci0,netdev=hn0 -vnc :7 -m 2048 -smp 2 -device piix3-usb-uhci -device usb-tablet -monitor stdio

Actually, according to my understanding, TAP device and driver are used in Host OS to send/receive packets/data to/from Gust OS since TAP driver can connect Gust OS with Internet. TAP driver will send the packets to Virtio in Host OS part and Virtio puts these packets into buffers, and at last, it notifies Virtio driver in Guest OS part to receive these packets. It has the same theory for how TAP devices receive packets from Guest OS. See following function stack for this part.

实际上,根据我的理解,由于TAP驱动程序可以将Gust OS与Internet连接,因此在主机OS中使用TAP设备和驱动程序向Gust OS发送/从Gust OS接收数据包/数据。 TAP驱动程序会将数据包发送到主机OS部分的Virtio,Virtio将这些数据包放入缓冲区,最后,它通知Guest OS部分的Virtio驱动程序接收这些数据包。 对于TAP设备如何从Guest OS接收数据包,它具有相同的理论。 请参见以下函数堆栈。


tap_send -----------> HOST TAP device driver
-> qemu_send_packet_async
-> qemu_send_packet_async_with_flags
->qemu_net_queue_send
->qemu_net_queue_deliver
->qemu_deliver_packet
->nc->info->receive
->virtio_net_receive -------------> since we use virtio-net-pci driver
->virtqueue_fill, virtqueue_flush, virtio_notify
->virtio_notify_vector
->k->notify
->virtio_pci_notify
->msix_notify
-> msi_send_message
->address_space_stl_le
->address_space_stl_internal


tap_send -----------> HOST TAP device driver
-> qemu_send_packet_async
-> qemu_send_packet_async_with_flags
->qemu_net_queue_send
->qemu_net_queue_deliver
->qemu_deliver_packet
->nc->info->receive
->virtio_net_receive -------------> since we use virtio-net-pci driver
->virtqueue_fill, virtqueue_flush, virtio_notify
->virtio_notify_vector
->k->notify
->virtio_pci_notify
->msix_notify
-> msi_send_message
->address_space_stl_le
->address_space_stl_internal

Actually, I think there is another example in [1]’s “Connecting VLANs To TAP Devices” part, and the function call stack should be like following.

实际上,我认为[1]的“将VLAN连接到TAP设备”部分中还有另一个示例,并且函数调用堆栈应如下所示。


tap_send -----------> HOST TAP device driver
-> qemu_send_packet_async
-> qemu_send_packet_async_with_flags
->qemu_net_queue_send
->qemu_net_queue_deliver
->qemu_deliver_packet
->nc->info->receive
->net_hub_port_receive ---> Start VLAN
->net_hub_receive
->qemu_send_packet
-> qemu_send_packet_async
->qemu_sendv_packet_async
...
->e1000_receive ---->NIC


tap_send -----------> HOST TAP device driver
-> qemu_send_packet_async
-> qemu_send_packet_async_with_flags
->qemu_net_queue_send
->qemu_net_queue_deliver
->qemu_deliver_packet
->nc->info->receive
->net_hub_port_receive ---> Start VLAN
->net_hub_receive
->qemu_send_packet
-> qemu_send_packet_async
->qemu_sendv_packet_async
...
->e1000_receive ---->NIC

Mechanisms

机制

We need to look into mechanisms from above examples. So firstly, we will find that, in order to improve system performance, network part in QEMU/KVM will handle these packets in asynchronous way (it is also the way to be used in critical section). This is also due to these packets in memory cannot be operated by two threads simultaneously. On the other hand, these layers (TAP layer, Virtio layer, etc) are decoupled so they system design/implementation will be more flexibility and scalability. At last, Virtio is a para-virtualized technology to improve the performance for I/O systems in virtualization environments.

我们需要从以上示例中研究机制。 因此,首先,我们将发现,为了提高系统性能,QEMU / KVM中的网络部分将以异步方式处理这些数据包(这也是关键部分中使用的方式)。 这也是由于内存中的这些数据包无法同时由两个线程操作。 另一方面,这些层(TAP层,Virtio层等)是分离的,因此它们的系统设计/实现将具有更大的灵活性和可伸缩性。 最后,Virtio是一种半虚拟化技术,旨在提高虚拟化环境中I / O系统的性能。

References

参考资料

[1] https://people.gnome.org/~markmc/qemu-networking.html
[2] https://lxr.missinglinkelectronics.com/qemu+v2.4.0/

[1] https://people.gnome.org/~markmc/qemu-networking.html
[2] https://lxr.missinglinkelectronics.com/qemu+v2.4.0/

翻译自: https://www.systutorials.com/qemukvm-network-mechanisms/

qemu/kvm 桥接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值