0%

Ubuntu16.04 VPP环境搭建

环境

环境准备

  1. VmWare虚拟环境
  2. Host需求:2cpu,4G内存,3块网卡
  3. Ubuntu16.04

拓扑

搭建典型的c2s拓扑

  • 通过vsphere创建两个虚拟交换机
  • host1的第二个接口与vpp的第二个接口连在同一个交换机上
  • host2的第二个接口与vpp的第三个接口连在同一个交换机上

VPP安装先决条件

  1. Ubuntu安装git(git默认安装)
  2. Ubuntu安装dpdk,并绑定PCI的另外两个接口到dpdk

安装

官方文档提供了多种安装方式,并且推荐使用vagrant包,由于这里使用的是虚拟环境,则使用直接安装的方式

获取源码

1
$ git clone https://gerrit.fd.io/r/vpp

安装vpp

1
$ cd vpp
  • Step1

可以先执行一下make查看可以执行哪些操作

  • Step2 - make
1
2
3
4
5
6
7
8
$ make build-release

...

by executing "make install-dep"

Makefile:262: recipe for target '/root/vpp/build-root/.deps.ok' failed
make: *** [/root/vpp/build-root/.deps.ok] Error 1

如果遇到以上错误,则意味着缺少依赖包

1
$ make install-dep

依赖包安装完成后,再次执行make build-release

  • Step3 - Build deb包
1
$ make pkg-deb
  • Step4 - 安装VPP packages
1
$ dpkg -i /vpp/build-root/*.deb

中间可能会遇到vpp-api-python的错误,使用apt安装后重新安装packages

1
$ apt install vpp-api-python

配置

1
2
3
mkdir -p /etc/vpp
cp ./build-root/deb/debian/vpp/etc/vpp/startup.conf /etc/vpp/
cp ./build-root/deb/debian/vpp/etc/sysctl.d/80-vpp.conf /etc/sysctl.d/

修改/etc/vpp/startup.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
unix {
nodaemon
log /var/log/vpp/vpp.log
full-coredump
#cli-listen /run/vpp/cli.sock
cli-listen 0.0.0.0:5002
gid vpp
}

api-trace {
on
}

api-segment {
gid vpp
}

socksvr {
default
}

cpu {
main-core 0
workers 2
}

dpdk {
dev 0000:0b:00.0 {num-rx-queues 2}
dev 0000:13:00.0 {num-rx-queues 2}
num-mbufs 128000
socket-mem 1024,1024
}

plugins {
path /root/vpp/build-root/install-vpp-native/vpp/lib/vpp_plugins
}

启动VPP

1
$ service vpp start

查看状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ systemctl status vpp.service
● vpp.service - vector packet processing engine
Loaded: loaded (/lib/systemd/system/vpp.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-11-15 16:00:09 CST; 4min 52s ago
Process: 19959 ExecStopPost=/bin/rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api (code=exited, status=0/SUCCESS)
Process: 19985 ExecStartPre=/sbin/modprobe uio_pci_generic (code=exited, status=0/SUCCESS)
Process: 19981 ExecStartPre=/bin/rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api (code=exited, status=0/SUCCESS)
Main PID: 19989 (vpp_main)
Tasks: 6
Memory: 55.9M
CPU: 9min 46.890s
CGroup: /system.slice/vpp.service
└─19989 /usr/bin/vpp -c /etc/vpp/startup.conf

Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: nat_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: lb_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: gtpu_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: avf_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: acl_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: memif_test_plugin.so
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: load_one_vat_plugin:67: Loaded plugin: stn_test_plugin.so
Nov 15 16:00:09 fdio vpp[19989]: /usr/bin/vpp[19989]: dpdk: EAL init args: -c 7 -n 4 --huge-dir /run/vpp/hugepages --file-prefix vpp -w 0000:0b:00.0 -w 0000:13:00.0 --master-lcor
Nov 15 16:00:09 fdio /usr/bin/vpp[19989]: dpdk: EAL init args: -c 7 -n 4 --huge-dir /run/vpp/hugepages --file-prefix vpp -w 0000:0b:00.0 -w 0000:13:00.0 --master-lcore 0 --socket
Nov 15 16:00:10 fdio vnet[19989]: dpdk_ipsec_process:1015: not enough DPDK crypto resources, default to OpenSSL

虽然有警告信息,但似乎不影响使用

测试

根据startup.conf中的配置不同,选择不同的连接vpp方式

登陆VPP CLI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ telnet 127.0.0.1 5002
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
_______ _ _ _____ ___
__/ __/ _ \ (_)__ | | / / _ \/ _ \
_/ _// // / / / _ \ | |/ / ___/ ___/
/_/ /____(_)_/\___/ |___/_/ /_/

vpp# show interface
Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
GigabitEthernet13/0/0 2 down 9000/0/0/0
GigabitEthernetb/0/0 1 down 9000/0/0/0
local0 0 down 0/0/0/0
vpp#

开启端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vpp# set interface state GigabitEthernet13/0/0 up
vpp# set interface state GigabitEthernetb/0/0 up
vpp# show interface
Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
GigabitEthernet13/0/0 2 up 9000/0/0/0 rx packets 1
rx bytes 60
drops 1
ip4 1
GigabitEthernetb/0/0 1 up 9000/0/0/0 rx packets 4
rx bytes 240
drops 4
ip4 1
local0 0 down 0/0/0/0
vpp#

配置为switch模式

1
2
3
4
5
vpp# set interface l2 bridge GigabitEthernet13/0/0 1
vpp# set interface l2 bridge GigabitEthernetb/0/0 1
vpp# show bridge-domain
BD-ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1 1 0 off on on flood on off N/A

测试连通性

  • c2s
  1. Host1: 192.168.0.2/24
  2. Host2: 192.168.0.3/24

通过host1 ping host2

  • 配置loopback口测试连通性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vpp# create loopback interface
loop0
vpp# set interface ip address loop0 192.168.0.1/24
vpp# set interface state loop0 up
vpp# set interface l2 bridge loop0 1 bvi
vpp# show bridge-domain
BD-ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1 1 0 off on on flood on off loop0
vpp# ping 192.168.0.2
116 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=.8704 ms
116 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=.2564 ms
116 bytes from 192.168.0.2: icmp_seq=4 ttl=64 time=.2653 ms
116 bytes from 192.168.0.2: icmp_seq=5 ttl=64 time=.3413 ms

Statistics: 5 sent, 4 received, 20% packet loss

set interface l2 bridge loop0 1 bvi中的bvi意味着这个接口将用来接收、发送以及转发该bridge domain的报文