BESS【6】Hooking up BESS Ports

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::QueueInc(port=myport, qid=0) #This module will read from myport on queue 0
input1::QueueInc(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 to BESS with Vhost Ports

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')

You can now use my_vhost and other Vhost ports you create in combination with any number of bess modules, to connect VMs and process the packets flowing between them.

If you're using Qemu as your VMM, you can connect my_vport to a VM with a command line like this.

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

Connecting VMs and Containers with BESS VPorts

BESS also has support for interfaces called VPorts which are exposed to the kernel. If you want to connect containers to BESS, a VPort is the way to go. VPorts require the BESS kernel module. See here for how to build and load the BESS kernel module.

With the BESS kernel module built and loaded we can now create VPorts and use them to provide networking between containers.

Before doing anything, boot a container.

docker pull ubuntu
docker run -i -d --net=none --name=vport_test ubuntu /usr/bin/tail -f /dev/null

Currently vport_test has no network interfaces. You need to write a bessctl script to create and plumb together the interfaces that will allow the host (or other containers) to talk to vport_test. Let's do that step-by-step (skip to the bottom of this section for the complete script).

First, create a VPort and attach it to vport_test by adding the following to your bessctl script.

container_if = VPort(ifname='eth_vport_test', docker='vport_test', ip_addrs=['10.255.99.2/24'])

If you would rather attach the VPort to your container with its CID you can pass container_pid=<CID> instead of docker=... to the constructor. Further, you can also attach the VPort directly to the container's network namespace by passing netns=<NAMESPACE> instead.

Now, if you run ifconfig inside the container you should see a new interface eth_vport_test.

Next, to allow the host to talk to the container, create another VPort by adding the following to your bessctl script. Note the absence of a docker, container_pid or netns field. This means the interface will be created on the host.

host_if = VPort(ifname='eth_host', ip_addrs=['10.255.99.1/24'])

If you run ifconfig on the host you should now see a new interface eth_host; however, the interfaces are not yet plumbed together, so any attempt to send packets on either will fail. To fix this, connect your interfaces with PortInc and PortOut modules by adding the following to your script.

PortInc(port=host_if) -> PortOut(port=container_if)
PortInc(port=container_if) -> PortOut(port=host_if)

Now, on the host you should be able to ping into the container, and vice versa. For the sake of completeness, your final bessctl script should look like the following.

container_if = VPort(ifname='eth_vport_test', docker='vport_test', ip_addrs=['10.255.99.2/24'])
host_if = VPort(ifname='eth_host', ip_addrs=['10.255.99.1/24'])

PortInc(port=host_if) -> PortOut(port=container_if)
PortInc(port=container_if) -> PortOut(port=host_if)

This example only provides basic connectivity, but you can place an arbitrarily complex pipeline of other BESS modules between the PortInc/PortOut pairs to realize more complex policies/behavior.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,033评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,725评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,473评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,846评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,848评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,691评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,053评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,700评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,856评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,676评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,787评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,430评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,034评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,990评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,218评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,174评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,526评论 2 343