VLAN Trunking to Guest Domains with Open vSwitch
来源:互联网 发布:everspace 优化 编辑:程序博客网 时间:2024/04/30 02:35
In other articles, I’ve talked about how to use Open vSwitch (OVS) with VLANsto place guest domains (VMs) into a particular VLAN. In this article, I want to show you how to pass VLAN tags all the way into the guest domain—in other words, how to do VLAN trunking to guest domains using OVS. To do this, we’re going to leverage the OVS-libvirt integration I referenced in this post on using VLANs with OVS and libvirt.
For this to work, you must have an operating system in the guest domain that is capable of recognizing and using the VLAN tags that are being passed to it by OVS. In this article, I’ll use Ubuntu 12.04 as the OS in the guest domain. For other operating systems, the commands and/or procedures to configure VLAN support appropriately will probably differ, so keep that in mind.
There are two parts to making this work:
- Configuring OVS (manually or via libvirt) topass VLAN tags to the guest OS.
- Configuring the guest domain’s installed OS to take advantage of the VLAN tags being passed up by OVS.
Let’s look at each of these parts separately. We’ll start with configuring OVS, either manually or via libvirt, to pass the VLAN tags up to the guest domain.
Configuring OVS to Pass VLAN Tags to the Guest Domain
There are two ways to accomplish this: you can do it manually, or you can do it via OVS integration with recent builds of libvirt.
MANUALLY CONFIGURING OVS
To configure OVS manually, you would need to:
- Identify which vnet port you want to configure for VLAN trunking
- Configure the vnet port to trunk the VLANs.
To identify which vnet port needs to be modified, you’ll want tofigure out the guest domain interface(s) that is/are connected to the vnet port. You can do this by using this command (substitute the desired vnet port name in place ofvnet0
in the following command):
In the output of the command, look for the external_ids
line; it will contain an entry called “attached-mac”, and that represents the MAC address of the interface in the guest domain OS attached to this particular vnet port. You can compare this to the output of ip addr list
or ifconfig -a
in Ubuntu to find a matching MAC address in the guest domain. Correlating the two values allows you to determine which guest domain is attached to which vnet port, and then you can modify the correct vnet port appropriately.
You’d modify the vnet port using this command:
You’d want to substitute the appropriate values for vnet0
and the VLAN IDs that you want passed up to the guest domain. Once you’ve made the change, you can verify the changes using this command (replacing vnet0
with the correct port):
Note that if you want the guest domain to receive both untagged (native VLAN) traffic as well as tagged (trunked) traffic, there is an additional setting you must set:
With this setting in place, the OS installed into the guest domain will be able to communicate over the untagged (native) VLAN as well as using VLAN tags.
USING LIBVIRT INTEGRATION
If the manual method of configuring OVS seems a bit cumbersome, using the libvirt integration makes it much easier.
Basically, you’ll follow the configuration outlined in this blog post to create a libvirt network that corresponds to an OVS bridge. Here’s an example of the XML code to accomplish this task:
Of particular interest for what we’re trying to accomplish here is the very last section, the portgroup named “vlan-all.” Note that for this specific portgroup, the vlan
element has a property that specifies it is a trunk, and then there are multiple tag
elements that list each VLAN ID that will be trunked across this network into the guest domain.
Using this configuration, when we create the guest domain and specify that it isattached to the network named “vlan-all” (matching the portgroup in the libvirt network definition), libvirt will automatically configure OVS appropriately (it will set the trunks
value for that domain’s OVS port).
However, it will not configure the OVS port to allow untagged traffic as well (only tagged traffic will be passed). If you want the guest domain to receive untagged traffic also, you must set the vlan_mode
value manually as outlined above.
Configuring the Guest Domain to Use VLAN Tags
Once you’ve followed the steps outlined above and have OVS configured correctly, then you’re ready to configure the OS in the guest domain. Keep in mind that I’m using Ubuntu 12.04 in this post, but you’re welcome to use any operating system that supports VLAN tags.
Assuming that eth0 is the interface in the guest domain that is receiving tagged traffic from OVS, this snippet in /etc/network/interfaces
will create and configure a VLAN interface:
Technically, the “raw-vlan-device” line isn’t needed because the parent device name is in the name of the VLAN device, but I like to include it for completeness and ease of debugging. (Your mileage may vary, of course.)The number on the end of the eth0 (for example, eth0.20) corresponds to the VLAN ID (VLAN 20, in this case) being passed up by OVS.
You can repeat this configuration for multiple VLAN interfaces.
Use Case
I’ll have to admit that I can’t immediately think of some useful use cases for this sort of configuration. At first glance, you might think that it would be useful in situations where you need logical separation, but I think there are better ways than VLANs to accomplish this task (and those ways are probably simpler). I primarily set out to document this in order to better solidify my knowledge of how OVS works and is configured. However, I’d be happy to hear from others on what they think might be interesting or useful use cases for this sort of configuration. Feel free to add your thoughts in the comments below. Courteous comments are always welcome!
- VLAN Trunking to Guest Domains with Open vSwitch
- Layer 3 Routing with Open vSwitch for inter-VLAN
- 用Open vSwitch实现VLAN
- Fedora 17 with Open vSwitch
- VTP (VLAN Trunking Protocol)
- Neutron 理解 (2): 使用 Open vSwitch + VLAN 组网 [Netruon Open vSwitch + VLAN Virutal Network]
- Bridging VLAN Trunk to the Guest
- VTP:Cisco VLAN Trunking Protocol
- VTP(VLAN Trunking Protocol) - Pruning
- Using Open vswitch with Fedora 17
- Getting through OpenStack Quantum with Open vSwitch
- Link Aggregation and LACP with Open vSwitch
- Link Aggregation and LACP with Open vSwitch
- VLANs with Open vSwitch Fake Bridges
- Link Aggregation and LACP with Open vSwitch
- Using GRE Tunnels with Open vSwitch
- Using GRE Tunnels with Open vSwitch
- Using GRE Tunnels with Open vSwitch
- 理解C++ dynamic_cast
- LINUX系统调用
- 多边形间并踵点对
- 网络编程常见问题总结 2
- wpa_supplicant软件架构分析
- VLAN Trunking to Guest Domains with Open vSwitch
- Ognl表达式
- 自定义dialog+swich合用
- 如何让new操作符不分配内存,只调用构造函数
- Usb设备驱动0:从usb设备被发现开始
- Jackson
- XXX.exe 中的 0x5404723c (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0xfeeefee8 时发生访问冲突
- makefile
- vc创建对话框