Skip to contentSkip to conversation

net: Adding netmap network backend

PATCH Applied Vincenzo Maffione 4 participants 5 messages Nov 6, 2013 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 net: Adding netmap network backend

This patch adds support for a network backend based on netmap. netmap is a framework for high speed packet I/O. You can use it to build extremely fast traffic generators, monitors, software switches or network middleboxes. Its companion software switch VALE lets you interconnect virtual machines.
netmap and VALE are implemented as a non-intrusive kernel module, support NICs from multiple vendors, are part of standard FreeBSD distributions and available in source format for Linux too.

To compile QEMU with netmap support, use the following configure options:

    ./configure [...] --enable-netmap --extra-cflags=-I/path/to/netmap/sys
where "/path/to/netmap" contains the netmap source code, available at
    http://info.iet.unipi.it/~luigi/netmap/

The same webpage contains more information about the netmap project (together with papers and presentations).

---
Changes:
- Misspelling error (err --> errno) fixed.
- Early return also in netmap_receive().
- Help/qapi-schema modified, since with netmap backend you can also directly connect to a netmap-supported host network interface, as well as to a VALE switch port.

 configure         |  32 ++++
 hmp-commands.hx   |   4 +-
 net/Makefile.objs |   1 +
 net/clients.h     |   5 +
 net/net.c         |   6 +
 net/netmap.c      | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json  |  24 ++-
 qemu-options.hx   |   9 ++
 8 files changed, 513 insertions(+), 3 deletions(-)
 create mode 100644 net/netmap.c
configure +32 -0
index 91372f9..cfeef21 100755
@@ -156,6 +156,7 @@ curl=""
 curses=""
 docs=""
 fdt=""
+netmap="no"
 pixman=""
 sdl=""
 virtfs=""
@@ -473,6 +474,7 @@ FreeBSD)
   audio_possible_drivers="oss sdl esd pa"
   # needed for kinfo_getvmmap(3) in libutil.h
   LIBS="-lutil $LIBS"
+  netmap=""  # enable netmap autodetect
 ;;
 DragonFly)
   bsd="yes"
@@ -780,6 +782,10 @@ for opt do
   ;;
   --enable-vde) vde="yes"
   ;;
+  --disable-netmap) netmap="no"
+  ;;
+  --enable-netmap) netmap="yes"
+  ;;
   --disable-xen) xen="no"
   ;;
   --enable-xen) xen="yes"
@@ -1161,6 +1167,8 @@ echo "  --disable-uuid           disable uuid support"
 echo "  --enable-uuid            enable uuid support"
 echo "  --disable-vde            disable support for vde network"
 echo "  --enable-vde             enable support for vde network"
+echo "  --disable-netmap         disable support for netmap network"
+echo "  --enable-netmap          enable support for netmap network"
 echo "  --disable-linux-aio      disable Linux AIO support"
 echo "  --enable-linux-aio       enable Linux AIO support"
 echo "  --disable-cap-ng         disable libcap-ng support"
@@ -2065,6 +2073,26 @@ EOF
 fi
 
 ##########################################
+# netmap headers probe
+if test "$netmap" != "no" ; then
+  cat > $TMPC << EOF
+#include <inttypes.h>
+#include <net/if.h>
+#include <net/netmap.h>
+#include <net/netmap_user.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "" ; then
+    netmap=yes
+  else
+    if test "$netmap" = "yes" ; then
+      feature_not_found "netmap"
+    fi
+    netmap=no
+  fi
+fi
+
+##########################################
 # libcap-ng library probe
 if test "$cap_ng" != "no" ; then
   cap_libs="-lcap-ng"
@@ -3720,6 +3748,7 @@ echo "uname -r          $uname_release"
 echo "GUEST_BASE        $guest_base"
 echo "PIE               $pie"
 echo "vde support       $vde"
+echo "netmap support    $netmap"
 echo "Linux AIO support $linux_aio"
 echo "ATTR/XATTR support $attr"
 echo "Install blobs     $blobs"
@@ -3858,6 +3887,9 @@ fi
 if test "$vde" = "yes" ; then
   echo "CONFIG_VDE=y" >> $config_host_mak
 fi
+if test "$netmap" = "yes" ; then
+  echo "CONFIG_NETMAP=y" >> $config_host_mak
+fi
 if test "$cap_ng" = "yes" ; then
   echo "CONFIG_LIBCAP=y" >> $config_host_mak
 fi
hmp-commands.hx +2 -2
index caae5ad..ebe8e78 100644
@@ -1190,7 +1190,7 @@ ETEXI
     {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
-        .params     = "tap|user|socket|vde|dump [options]",
+        .params     = "tap|user|socket|vde|netmap|dump [options]",
         .help       = "add host VLAN client",
         .mhandler.cmd = net_host_device_add,
     },
@@ -1218,7 +1218,7 @@ ETEXI
     {
         .name       = "netdev_add",
         .args_type  = "netdev:O",
-        .params     = "[user|tap|socket|hubport],id=str[,prop=value][,...]",
+        .params     = "[user|tap|socket|hubport|netmap],id=str[,prop=value][,...]",
         .help       = "add host network device",
         .mhandler.cmd = hmp_netdev_add,
     },
net/Makefile.objs +1 -0
index 4854a14..c25fe69 100644
@@ -11,3 +11,4 @@ common-obj-$(CONFIG_AIX) += tap-aix.o
 common-obj-$(CONFIG_HAIKU) += tap-haiku.o
 common-obj-$(CONFIG_SLIRP) += slirp.o
 common-obj-$(CONFIG_VDE) += vde.o
+common-obj-$(CONFIG_NETMAP) += netmap.o
net/clients.h +5 -0
index 7793294..7322ff5 100644
@@ -52,4 +52,9 @@ int net_init_vde(const NetClientOptions *opts, const char *name,
                  NetClientState *peer);
 #endif
 
+#ifdef CONFIG_NETMAP
+int net_init_netmap(const NetClientOptions *opts, const char *name,
+                    NetClientState *peer);
+#endif
+
 #endif /* QEMU_NET_CLIENTS_H */
net/net.c +6 -0
index c330c9a..2526e4a 100644
@@ -721,6 +721,9 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
 #ifdef CONFIG_VDE
         [NET_CLIENT_OPTIONS_KIND_VDE]       = net_init_vde,
 #endif
+#ifdef CONFIG_NETMAP
+        [NET_CLIENT_OPTIONS_KIND_NETMAP]    = net_init_netmap,
+#endif
         [NET_CLIENT_OPTIONS_KIND_DUMP]      = net_init_dump,
 #ifdef CONFIG_NET_BRIDGE
         [NET_CLIENT_OPTIONS_KIND_BRIDGE]    = net_init_bridge,
@@ -752,6 +755,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
 #ifdef CONFIG_VDE
         case NET_CLIENT_OPTIONS_KIND_VDE:
 #endif
+#ifdef CONFIG_NETMAP
+        case NET_CLIENT_OPTIONS_KIND_NETMAP:
+#endif
 #ifdef CONFIG_NET_BRIDGE
         case NET_CLIENT_OPTIONS_KIND_BRIDGE:
 #endif
net/netmap.c new file +435 -0

435 lines not on this page · raw message

qapi-schema.json +23 -1
index 81a375b..3d2f0d7 100644
@@ -3008,6 +3008,27 @@
     'hubid':     'int32' } }
 
 ##
+# @NetdevNetmapOptions
+#
+# Connect a client to a netmap-enabled NIC or to a VALE switch port
+#
+# @ifname: Either the name of an existing network interface supported by
+#          netmap, or the name of a VALE port (created on the fly).
+#          A VALE port name is in the form 'valeXXX:YYY', where XXX and
+#          YYY are non-negative integers. XXX identifies a switch and
+#          YYY identifies a port of the switch. VALE ports having the
+#          same XXX are therefore connected to the same switch.
+#
+# @devname: #optional path of the netmap device (default: '/dev/netmap').
+#
+# Since 1.8
+##
+{ 'type': 'NetdevNetmapOptions',
+  'data': {
+    'ifname':     'str',
+    '*devname':    'str' } }
+
+##
 # @NetClientOptions
 #
 # A discriminated record of network device traits.
@@ -3024,7 +3045,8 @@
     'vde':      'NetdevVdeOptions',
     'dump':     'NetdevDumpOptions',
     'bridge':   'NetdevBridgeOptions',
-    'hubport':  'NetdevHubPortOptions' } }
+    'hubport':  'NetdevHubPortOptions',
+    'netmap':   'NetdevNetmapOptions' } }
 
 ##
 # @NetLegacy
qemu-options.hx +9 -0
index 5dc8b75..3d158e7 100644
@@ -1409,6 +1409,12 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
     "                Use group 'groupname' and mode 'octalmode' to change default\n"
     "                ownership and permissions for communication port.\n"
 #endif
+#ifdef CONFIG_NETMAP
+    "-net netmap,ifname=name[,devname=nmname]\n"
+    "                attach to the existing netmap-enabled network interface 'name', or to a\n"
+    "                VALE port (created on the fly) called 'name' ('nmname' is name of the \n"
+    "                netmap device, defaults to '/dev/netmap')\n"
+#endif
     "-net dump[,vlan=n][,file=f][,len=n]\n"
     "                dump traffic on vlan 'n' to file 'f' (max n bytes per packet)\n"
     "-net none       use it alone to have zero network devices. If no -net option\n"
@@ -1423,6 +1429,9 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
 #ifdef CONFIG_VDE
     "vde|"
 #endif
+#ifdef CONFIG_NETMAP
+    "netmap|"
+#endif
     "socket|"
     "hubport],id=str[,option][,option][,...]\n", QEMU_ARCH_ALL)
 STEXI
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 27 lines · Vincenzo Maffione

This patch adds support for a network backend based on netmap. netmap is a framework for high speed packet I/O. You can use it to build extremely fast traffic generators, monitors, software switches or network middleboxes. Its companion software switch VALE lets you interconnect virtual machines.
netmap and VALE are implemented as a non-intrusive kernel module, support NICs from multiple vendors, are part of standard FreeBSD distributions and available in source format for Linux too.

To compile QEMU with netmap support, use the following configure options:

    ./configure [...] --enable-netmap --extra-cflags=-I/path/to/netmap/sys
where "/path/to/netmap" contains the netmap source code, available at
    http://info.iet.unipi.it/~luigi/netmap/

The same webpage contains more information about the netmap project (together with papers and presentations).

---
Changes:
- Misspelling error (err --> errno) fixed.
- Early return also in netmap_receive().
- Help/qapi-schema modified, since with netmap backend you can also directly connect to a netmap-supported host network interface, as well as to a VALE switch port.

Quoted 10 lines
 configure         |  32 ++++
 hmp-commands.hx   |   4 +-
 net/Makefile.objs |   1 +
 net/clients.h     |   5 +
 net/net.c         |   6 +
 net/netmap.c      | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json  |  24 ++-
 qemu-options.hx   |   9 ++
 8 files changed, 513 insertions(+), 3 deletions(-)
 create mode 100644 net/netmap.c

Thanks, applied to my net-next tree for QEMU 1.8:
https://github.com/stefanha/qemu/commits/net-next

Will you be around to maintain and test this in the future? Please add yourself to the ./MAINTAINERS file for net/netmap.c and submit a patch.

It's important we have someone who can keep this code working over time. Otherwise the feature may get dropped again due to bitrot.

Stefan

#2 lore raw

Sure,
I see that all the "net/" is in the "Network device layer" section.

Our section would be something like
"
Netmap network backend
M: Luigi Rizzo <mail>
M: Giuseppe Lettieri <mail>
M: Vincenzo Maffione <mail>
S: Maintained
F: net/netmap.c
"
right?
Do we have to exclude (X) "net/netmap.c" into the "Network device layer" section?
Where do we have to put the netmap section?

Thanks,
Vincenzo

2013/11/6 Stefan Hajnoczi <[email protected]>

Quoted 52 lines · Vincenzo Maffione
Quoted 9 lines

This patch adds support for a network backend based on netmap. netmap is a framework for high speed packet I/O. You can use it to build extremely fast traffic generators, monitors, software switches or network middleboxes. Its companion software switch VALE lets you interconnect virtual machines.
netmap and VALE are implemented as a non-intrusive kernel module, support NICs from multiple vendors, are part of standard FreeBSD distributions and available in source format for Linux too.

Quoted 3 lines

To compile QEMU with netmap support, use the following configure options:

    ./configure [...] --enable-netmap

--extra-cflags=-I/path/to/netmap/sys

Quoted 15 lines

where "/path/to/netmap" contains the netmap source code, available at

    http://info.iet.unipi.it/~luigi/netmap/

The same webpage contains more information about the netmap project (together with papers and presentations).

---
Changes:
- Misspelling error (err --> errno) fixed.
- Early return also in netmap_receive().
- Help/qapi-schema modified, since with netmap backend you can also directly connect to a netmap-supported host network interface, as well as to a VALE switch port.

Quoted 6 lines
 configure         |  32 ++++
 hmp-commands.hx   |   4 +-
 net/Makefile.objs |   1 +
 net/clients.h     |   5 +
 net/net.c         |   6 +
 net/netmap.c      | 435

++++++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 4 lines
 qapi-schema.json  |  24 ++-
 qemu-options.hx   |   9 ++
 8 files changed, 513 insertions(+), 3 deletions(-)
 create mode 100644 net/netmap.c

Thanks, applied to my net-next tree for QEMU 1.8:
https://github.com/stefanha/qemu/commits/net-next

Will you be around to maintain and test this in the future? Please add yourself to the ./MAINTAINERS file for net/netmap.c and submit a patch.

It's important we have someone who can keep this code working over time. Otherwise the feature may get dropped again due to bitrot.

Stefan

Signature · 1 line
Vincenzo Maffione
#3 lore raw
Quoted 5 lines · Vincenzo Maffione

Our section would be something like
"
Netmap network backend
M: Luigi Rizzo <mail>
M: Giuseppe Lettieri <mail>

Quoted 8 lines

M: Vincenzo Maffione <mail>
S: Maintained
F: net/netmap.c
"
right?
Do we have to exclude (X) "net/netmap.c" into the "Network device layer" section?
Where do we have to put the netmap section?

That looks good, you can just put it at the bottom of the file or below the "Network device layer" section. Don't worry about excluding anything, I don't think we do that much elsewhere.

Stefan

#4 lore raw
Quoted 15 lines · Stefan Hajnoczi
Quoted 5 lines · Vincenzo Maffione

Our section would be something like
"
Netmap network backend
M: Luigi Rizzo <mail>
M: Giuseppe Lettieri <mail>

Quoted 8 lines

M: Vincenzo Maffione <mail>
S: Maintained
F: net/netmap.c
"
right?
Do we have to exclude (X) "net/netmap.c" into the "Network device layer" section?
Where do we have to put the netmap section?

Quoted 3 lines

That looks good, you can just put it at the bottom of the file or below the "Network device layer" section. Don't worry about excluding anything, I don't think we do that much elsewhere.

You can always test that you've done the right thing by checking ./scripts/get_maintainer.pl -f output.

r~