From 0a1b5653825bf67d3893a9177e188a131daba157 Mon Sep 17 00:00:00 2001 From: Jim Fehlig Date: Fri, 16 Nov 2018 13:08:23 -0700 Subject: [PATCH] xenconfig: add support for openvswitch configuration Add support for converting openvswitch interface configuration to/from libvirt domXML and xl.cfg(5). The xl config syntax for virtual interfaces is described in detail in the xl-network-configuration(5) man page. The Xen Networking wiki also contains information and examples for using openvswitch in xl.cfg config format https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch Tests are added to check conversions of openvswitch tagged and trunked VLAN configuration. Signed-off-by: Jim Fehlig ACKed-by: Michal Privoznik --- src/xenconfig/xen_common.c | 109 +++++++++++++++++- .../test-fullvirt-ovswitch-tagged.cfg | 25 ++++ .../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++ .../test-fullvirt-ovswitch-trunked.cfg | 25 ++++ .../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++ tests/xlconfigtest.c | 2 + 6 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-trunked.cfg create mode 100644 tests/xlconfigdata/test-fullvirt-ovswitch-trunked.xml diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 13646dffb4..60c8d7edc8 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -856,6 +856,80 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat) } +static int +xenParseVifBridge(virDomainNetDefPtr net, char *bridge) +{ + char *vlanstr; + unsigned int tag; + + if ((vlanstr = strchr(bridge, '.'))) { + /* 'bridge' string contains a bridge name and single vlan tag */ + if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0) + return -1; + + vlanstr++; + if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0) + return -1; + + if (VIR_ALLOC_N(net->vlan.tag, 1) < 0) + return -1; + + net->vlan.tag[0] = tag; + net->vlan.nTags = 1; + + if (VIR_ALLOC(net->virtPortProfile) < 0) + return -1; + + net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH; + return 0; + } else if ((vlanstr = strchr(bridge, ':'))) { + /* 'bridge' string contains a bridge name and one or more vlan trunks */ + size_t i; + size_t nvlans = 0; + char **vlanstr_list = virStringSplit(bridge, ":", 0); + + if (!vlanstr_list) + return -1; + + if (VIR_STRDUP(net->data.bridge.brname, vlanstr_list[0]) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + + for (i = 1; vlanstr_list[i]; i++) + nvlans++; + + if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + + for (i = 1; i <= nvlans; i++) { + if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + net->vlan.tag[i - 1] = tag; + } + net->vlan.nTags = nvlans; + net->vlan.trunk = true; + virStringListFree(vlanstr_list); + + if (VIR_ALLOC(net->virtPortProfile) < 0) + return -1; + + net->virtPortProfile->virtPortType = VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH; + return 0; + } else { + /* 'bridge' string only contains the bridge name */ + if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + return -1; + } + + return 0; +} + + static virDomainNetDefPtr xenParseVif(char *entry, const char *vif_typename) { @@ -974,8 +1048,8 @@ xenParseVif(char *entry, const char *vif_typename) net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; } - if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE && bridge[0]) { + if (xenParseVifBridge(net, bridge) < 0) goto cleanup; } if (ip[0]) { @@ -1264,14 +1338,41 @@ xenFormatNet(virConnectPtr conn, switch (net->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: + { + virNetDevVPortProfilePtr port_profile = virDomainNetGetActualVirtPortProfile(net); + virNetDevVlanPtr virt_vlan = virDomainNetGetActualVlan(net); + const char *script = net->script; + size_t i; + virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname); + if (port_profile && + port_profile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { + if (!script) + script = "vif-openvswitch"; + /* + * libxl_device_nic->bridge supports an extended format for + * specifying VLAN tags and trunks + * + * BRIDGE_NAME[.VLAN][:TRUNK:TRUNK] + */ + if (virt_vlan && virt_vlan->nTags > 0) { + if (virt_vlan->trunk) { + for (i = 0; i < virt_vlan->nTags; i++) + virBufferAsprintf(&buf, ":%d", virt_vlan->tag[i]); + } else { + virBufferAsprintf(&buf, ".%d", virt_vlan->tag[0]); + } + } + } + if (net->guestIP.nips > 0) { char *ipStr = xenMakeIPList(&net->guestIP); virBufferAsprintf(&buf, ",ip=%s", ipStr); VIR_FREE(ipStr); } - virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT); - break; + virBufferAsprintf(&buf, ",script=%s", script ? script : DEFAULT_VIF_SCRIPT); + } + break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (net->script) diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg new file mode 100644 index 0000000000..6a3dc3cfeb --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg @@ -0,0 +1,25 @@ +name = "XenGuest2" +uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" +maxmem = 8192 +memory = 8192 +vcpus = 8 +pae = 1 +acpi = 1 +apic = 1 +viridian = 0 +rtc_timeoffset = 0 +localtime = 0 +on_poweroff = "destroy" +on_reboot = "restart" +on_crash = "restart" +device_model = "/usr/lib/xen/bin/qemu-system-i386" +sdl = 0 +vnc = 1 +vncunused = 1 +vnclisten = "127.0.0.1" +vif = [ "mac=00:16:3e:66:92:9c,bridge=ovsbr0.42,script=vif-openvswitch,model=e1000" ] +parallel = "none" +serial = "none" +builder = "hvm" +boot = "c" +disk = [ "format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ] diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml new file mode 100644 index 0000000000..63f3258b84 --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml @@ -0,0 +1,50 @@ + + XenGuest2 + c7a5fdb2-cdaf-9455-926a-d65c16db1809 + 8388608 + 8388608 + 8 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + restart + restart + + /usr/lib/xen/bin/qemu-system-i386 + + + + +
+ + + + + + + + + +