From: Antoni Segura Puimedon <toni@xxxxxxxxxxxx> Midonet is an opensource virtual networking that over lays the IP network between hypervisors. Currently, such networks can be made with the openvswitch virtualport type. With this patch, one will be able to setup such configurations by binding vNICs to Midonet overlay ports. Signed-off-by: Antoni Segura Puimedon <toni@xxxxxxxxxxxx> --- configure.ac | 4 ++ docs/schemas/networkcommon.rng | 12 +++++ src/Makefile.am | 1 + src/conf/domain_conf.h | 1 + src/conf/netdev_vport_profile_conf.c | 3 +- src/libvirt_private.syms | 5 ++ src/qemu/qemu_hotplug.c | 25 +++++++--- src/qemu/qemu_process.c | 13 +++-- src/util/virnetdevmidonet.c | 97 ++++++++++++++++++++++++++++++++++++ src/util/virnetdevmidonet.h | 37 ++++++++++++++ src/util/virnetdevtap.c | 11 ++-- src/util/virnetdevvportprofile.c | 1 + src/util/virnetdevvportprofile.h | 5 +- 13 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 src/util/virnetdevmidonet.c create mode 100644 src/util/virnetdevmidonet.h diff --git a/configure.ac b/configure.ac index b3e99e7..ddffbb2 100644 --- a/configure.ac +++ b/configure.ac @@ -425,6 +425,8 @@ AC_PATH_PROG([MODPROBE], [modprobe], [modprobe], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([RMMOD], [rmmod], [rmmod], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) +AC_PATH_PROG([MMCTL], [mm-ctl], [mm-ctl], + [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([SCRUB], [scrub], [scrub], @@ -440,6 +442,8 @@ AC_DEFINE_UNQUOTED([RADVD],["$RADVD"], [Location or name of the radvd program]) AC_DEFINE_UNQUOTED([TC],["$TC"], [Location or name of the tc program (see iproute2)]) +AC_DEFINE_UNQUOTED([MMCTL],["$MMCTL"], + [Location or name of the mm-ctl program]) AC_DEFINE_UNQUOTED([OVSVSCTL],["$OVSVSCTL"], [Location or name of the ovs-vsctl program]) diff --git a/docs/schemas/networkcommon.rng b/docs/schemas/networkcommon.rng index 162ea3d..cc8b1dc 100644 --- a/docs/schemas/networkcommon.rng +++ b/docs/schemas/networkcommon.rng @@ -79,6 +79,18 @@ </element> </group> <group> + <element name="virtualport"> + <attribute name="type"> + <value>midonet</value> + </attribute> + <element name="parameters"> + <attribute name="interfaceid"> + <ref name="UUID"/> + </attribute> + </element> + </element> + </group> + <group> <!-- use this when no type attribute is present --> <element name="virtualport"> <optional> diff --git a/src/Makefile.am b/src/Makefile.am index b41c6d4..23d3f93 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -129,6 +129,7 @@ UTIL_SOURCES = \ util/virnetdevbandwidth.h util/virnetdevbandwidth.c \ util/virnetdevbridge.h util/virnetdevbridge.c \ util/virnetdevmacvlan.c util/virnetdevmacvlan.h \ + util/virnetdevmidonet.h util/virnetdevmidonet.c \ util/virnetdevopenvswitch.h util/virnetdevopenvswitch.c \ util/virnetdevtap.h util/virnetdevtap.c \ util/virnetdevveth.h util/virnetdevveth.c \ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index da21bce..8049470 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -42,6 +42,7 @@ # include "virnetdevmacvlan.h" # include "virsysinfo.h" # include "virnetdevvportprofile.h" +# include "virnetdevmidonet.h" # include "virnetdevopenvswitch.h" # include "virnetdevbandwidth.h" # include "virnetdevvlan.h" diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index 8da0838..1641a3e 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -260,7 +260,8 @@ virNetDevVPortProfileFormat(virNetDevVPortProfilePtr virtPort, virBufferAsprintf(buf, " instanceid='%s'", uuidstr); } if (virtPort->interfaceID_specified && - (type == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH || + (type == VIR_NETDEV_VPORT_PROFILE_MIDONET || + type == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH || type == VIR_NETDEV_VPORT_PROFILE_NONE)) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 645aef1..df09ef8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1735,6 +1735,11 @@ virNetDevMacVLanRestartWithVPortProfile; virNetDevMacVLanVPortProfileRegisterCallback; +# util/virnetdevmidonet.h +virNetDevMidonetBindPort; +virNetDevMidonetUnbindPort; + + # util/virnetdevopenvswitch.h virNetDevOpenvswitchAddPort; virNetDevOpenvswitchGetMigrateData; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f1079fb..ac0c757 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1141,9 +1141,15 @@ int qemuDomainAttachNetDevice(virConnectPtr conn, } vport = virDomainNetGetActualVirtPortProfile(net); - if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) - ignore_value(virNetDevOpenvswitchRemovePort( - virDomainNetGetActualBridgeName(net), net->ifname)); + if (vport) { + if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) { + ignore_value(virNetDevMidonetUnbindPort(vport)); + } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { + ignore_value(virNetDevOpenvswitchRemovePort( + virDomainNetGetActualBridgeName(net), + net->ifname)); + } + } } virDomainNetRemoveHostdev(vm->def, net); @@ -2933,10 +2939,15 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, } vport = virDomainNetGetActualVirtPortProfile(net); - if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) - ignore_value(virNetDevOpenvswitchRemovePort( - virDomainNetGetActualBridgeName(net), - net->ifname)); + if (vport) { + if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) { + ignore_value(virNetDevMidonetUnbindPort(vport)); + } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { + ignore_value(virNetDevOpenvswitchRemovePort( + virDomainNetGetActualBridgeName(net), + net->ifname)); + } + } networkReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4773120..0cd0e3f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5278,10 +5278,15 @@ void qemuProcessStop(virQEMUDriverPtr driver, /* release the physical device (or any other resources used by * this interface in the network driver */ - if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) - ignore_value(virNetDevOpenvswitchRemovePort( - virDomainNetGetActualBridgeName(net), - net->ifname)); + if (vport) { + if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) { + ignore_value(virNetDevMidonetUnbindPort(vport)); + } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { + ignore_value(virNetDevOpenvswitchRemovePort( + virDomainNetGetActualBridgeName(net), + net->ifname)); + } + } /* kick the device out of the hostdev list too */ virDomainNetRemoveHostdev(def, net); diff --git a/src/util/virnetdevmidonet.c b/src/util/virnetdevmidonet.c new file mode 100644 index 0000000..57fb636 --- /dev/null +++ b/src/util/virnetdevmidonet.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2015 Midokura, Sarl. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: + * Antoni Segura Puimedon <toni@xxxxxxxxxxxx> + */ + +#include <config.h> + +#include "virnetdevmidonet.h" +#include "vircommand.h" +#include "viralloc.h" +#include "virerror.h" +#include "viruuid.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +/** + * virNetDevMidonetBindPort: + * @ifname: the network interface name + * @virtualport: the midonet specific fields + * + * Bind an interface to a Midonet virtual port + * + * Returns 0 in case of success or -1 in case of failure. + */ +int virNetDevMidonetBindPort(const char *ifname, + virNetDevVPortProfilePtr virtualport) +{ + int ret = -1; + virCommandPtr cmd = NULL; + char virtportuuid[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(virtualport->interfaceID, virtportuuid); + + cmd = virCommandNew(MMCTL); + + virCommandAddArgList(cmd, "--bind-port", virtportuuid, ifname, NULL); + + if (virCommandRun(cmd, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to bind port %s to the virtual port %s"), + ifname, virtportuuid); + goto cleanup; + } + + ret = 0; + cleanup: + virCommandFree(cmd); + return ret; +} + +/** + * virNetDevMidonetUnbindPort: + * @virtualport: the midonet specific fields + * + * Unbinds a virtual port from the host + * + * Returns 0 in case of success or -1 in case of failure. + */ +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport) +{ + int ret = -1; + virCommandPtr cmd = NULL; + char virtportuuid[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(virtualport->interfaceID, virtportuuid); + + cmd = virCommandNew(MMCTL); + virCommandAddArgList(cmd, "--unbind-port", virtportuuid, NULL); + + if (virCommandRun(cmd, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to unbind the virtual port %s from Midonet"), + virtportuuid); + goto cleanup; + } + + ret = 0; + cleanup: + virCommandFree(cmd); + return ret; +} diff --git a/src/util/virnetdevmidonet.h b/src/util/virnetdevmidonet.h new file mode 100644 index 0000000..b8dbeac --- /dev/null +++ b/src/util/virnetdevmidonet.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Midokura Sarl. + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: + * Antoni Segura Puimedon <toni@xxxxxxxxxxxx + */ + +#ifndef __VIR_NETDEV_MIDONET_H__ +# define __VIR_NETDEV_MIDONET_H__ + +# include "internal.h" +# include "virnetdevvportprofile.h" + + +int virNetDevMidonetBindPort(const char *ifname, + virNetDevVPortProfilePtr virtualport) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; + +#endif /* __VIR_NETDEV_MIDONET_H__ */ + diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 83b4131..f6152e9 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -26,6 +26,7 @@ #include "virnetdevtap.h" #include "virnetdev.h" #include "virnetdevbridge.h" +#include "virnetdevmidonet.h" #include "virnetdevopenvswitch.h" #include "virerror.h" #include "virfile.h" @@ -580,9 +581,13 @@ int virNetDevTapCreateInBridgePort(const char *brname, goto error; if (virtPortProfile) { - if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr, vmuuid, - virtPortProfile, virtVlan) < 0) { - goto error; + if (virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) { + if (virNetDevMidonetBindPort(*ifname, virtPortProfile) < 0) + goto error; + } else { + if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr, vmuuid, + virtPortProfile, virtVlan) < 0) + goto error; } } else { if (virNetDevBridgeAddPort(brname, *ifname) < 0) diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 6ee20d3..921c6aa 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -33,6 +33,7 @@ VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST, "none", "802.1Qbg", "802.1Qbh", + "midonet", "openvswitch") VIR_ENUM_IMPL(virNetDevVPortProfileOp, VIR_NETDEV_VPORT_PROFILE_OP_LAST, diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h index ad063c5..60121e9 100644 --- a/src/util/virnetdevvportprofile.h +++ b/src/util/virnetdevvportprofile.h @@ -34,6 +34,7 @@ enum virNetDevVPortProfile { VIR_NETDEV_VPORT_PROFILE_NONE, VIR_NETDEV_VPORT_PROFILE_8021QBG, VIR_NETDEV_VPORT_PROFILE_8021QBH, + VIR_NETDEV_VPORT_PROFILE_MIDONET, VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH, VIR_NETDEV_VPORT_PROFILE_LAST, @@ -53,8 +54,6 @@ typedef enum { VIR_NETDEV_VPORT_PROFILE_OP_LAST } virNetDevVPortProfileOp; VIR_ENUM_DECL(virNetDevVPortProfileOp) - -/* profile data for macvtap (VEPA) and openvswitch */ typedef struct _virNetDevVPortProfile virNetDevVPortProfile; typedef virNetDevVPortProfile *virNetDevVPortProfilePtr; struct _virNetDevVPortProfile { @@ -73,7 +72,7 @@ struct _virNetDevVPortProfile { /* this is a null-terminated character string */ char profileID[LIBVIRT_IFLA_VF_PORT_PROFILE_MAX]; - /* this member is used when virtPortType == openvswitch */ + /* this member is used when virtPortType == openvswitch|midonet */ unsigned char interfaceID[VIR_UUID_BUFLEN]; bool interfaceID_specified; /* NB - if virtPortType == NONE, any/all of the items could be used */ -- 2.3.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list