Skip to content

Hooking up BESS Ports

Melvin Walls edited this page Feb 22, 2017 · 9 revisions

If you are walking through the Intro to BESS, you have just written your first BESS configuration script using synthetic traffic generated by a FlowGen module and released out to a Sink module which deletes all of the packets. This document will explain how to set up BESS ports, which will let you read in or write out packets from a network interface card, a virtual machine, an application, etc.

Working with Ports operates in two stages. You create a port in your configuration script, and then you create a module to read or write to that port. The modules that connect to ports are PortInc, PortOut, QueueInc, and QueueOut. We will show you how to use them in the following examples.

Connecting BESS to a Network Interface using DPDK

BESS utilizes DPDK Poll-Mode Drivers (PMDs) to perform high-performance packet I/O with direct hardware NIC access. To use PMDs, first you need to unbind network interfaces from Linux kernel device drivers, then bind them to a special module (uio_pci_generic, vfio-pci, or igb_uio) to enable user-space I/O.

Creating a port for a Network Interface

DPDK provides a script to (un)bind network interfaces. The following command with --status can be used to list all network interfaces in the system.

$ bin/dpdk_devbind.py --status

Network devices using DPDK-compatible driver
============================================
<none>

Network devices using kernel driver
===================================
0000:01:00.0 'MT27500 Family [ConnectX-3]' if=rename6,p2p1 drv=mlx4_core unused=
0000:03:00.0 'Ethernet Connection X552 10 GbE SFP+' if=eth0 drv=ixgbe unused=
0000:03:00.1 'Ethernet Connection X552 10 GbE SFP+' if=eth1 drv=ixgbe unused=
0000:07:00.0 'I210 Gigabit Network Connection' if=p5p1 drv=igb unused= *Active*
0000:08:00.0 'I210 Gigabit Network Connection' if=p6p1 drv=igb unused=

Other network devices
=====================
<none>

Suppose we want the Intel X552 dual-port NIC (03:00.0 and 03:00.1) to be used by BESS. These ports are currently used by the kernel ixgbe driver as eth0 and eth1. The command below binds the ports to uio_pci_generic for user-space I/O.

$ sudo modprobe uio_pci_generic
$ sudo bin/dpdk_devbind.py -b uio_pci_generic 03:00.0 03:00.1

Then you can see the ports moved to under the "DPDK-compatible driver" section. The ports are ready to be used by BESS.

$ bin/dpdk_devbind.py --status

Network devices using DPDK-compatible driver
============================================
0000:03:00.0 'Ethernet Connection X552 10 GbE SFP+' drv=uio_pci_generic unused=
0000:03:00.1 'Ethernet Connection X552 10 GbE SFP+' drv=uio_pci_generic unused=

Network devices using kernel driver
===================================
0000:01:00.0 'MT27500 Family [ConnectX-3]' if=rename6,p2p1 drv=mlx4_core unused=uio_pci_generic
0000:07:00.0 'I210 Gigabit Network Connection' if=p5p1 drv=igb unused=uio_pci_generic *Active*
0000:08:00.0 'I210 Gigabit Network Connection' if=p6p1 drv=igb unused=uio_pci_generic

Other network devices
=====================
<none>

NOTE: If you connect to a server with ssh connection, do not unbind the interface on which the connection is running.

Using the Network Interface with your BESS Script

Now that you have configured your network interface to use the DPDK driver, BESS can automatically find it when it starts up. To create a port connecting to that driver, you can add the following to your script:

myport::PMDPort(port_id=0, num_inc_q=2, num_out_q=2)

This tells BESS to create a port connecting to the first of your network interfaces, and create two input and output queues on it. You can read in packets from this port, just like from Source or Flowgen, with

input0::QueueIn(port=myport, qid=0) #This module will read from myport on queue 0
input1::QueueIn(port=myport, qid=1) #This module will read from myport on queue 1

You can write out packets to this port just like Sink() with

output0::QueueOut(port=myport, qid=0) #This module will write to myport on queue 0
output1::QueueOut(port=myport, qid=1) #This module will write to myport on queue 1   

Connecting VMs with BESS

BESS also supports DPDK Vhost PMD ports, which can be used forward packets between virtual machines. Creating a Vhost PMD port is very much like creating a physical PMD port, but instead of passing the constructor a PCI address or a DPDK port ID, you pass in a DPDK vdev specifier. The command below will create a new Vhost-backed PMDPort with a single queue and a chardev at /tmp/my_vhost.sock. For a more detailed description of the fields you can set see the DPDK documentation.

my_vhost::PMDPort(name='my_vhost', vdev='eth_vhost0,iface=/tmp/my_vhost.sock,queues=1')

If you're using KVM, you can now connect my_vport to a VM with a command line like the one below.

qemu-system-x86_64 <other args...>
    -chardev socket,id=mychr,path=/tmp/my_vhost.sock \
    -netdev vhost-user,id=mydev,chardev=mychr,vhostforce,queues=1 \
    -device virtio-net-pci,netdev=mydev
Clone this wiki locally