Learning VPP: Two instances in different namespaces

2023-03-07 17:31:54 浏览数 (1)

本文描述如何在一台机器上但在不同的命名空间中运行两个vpp的实例。命名空间之间的通信通过linux-cp插件及memif接口来完成。

首先我们需要创建2个网络命名空间vpp1-ns 和vpp2-ns。

代码语言:javascript复制
ip netns add vpp1-ns
ip netns add vpp2-ns
代码语言:javascript复制
    分别设置命名空间对应vpp的启动配置文件及vpp启动默认创建memif接口。
代码语言:javascript复制
vpp1startup.conf配置文件及启动配置:
代码语言:javascript复制
##vpp1 vpp1_startup.conf 配置如下:
unix {
log ./vpp1.log
full-coredump
cli-listen /run/vpp/cli-vpp1.sock
gid vpp
startup-config /root/memif/vpp1.conf
}

api-segment {
prefix vpp1
}

socksvr {
socket-name /run/vpp/api_1.sock
}

dpdk {
blacklist 8086:100f
}

plugins {
plugin linux_cp_plugin.so { enable }
plugin linux_nl_plugin.so { enable }
}

logging {
default-log-level debug
default-syslog-log-level info
}

###vpp1.conf文件是vpp cli配置,用来设置lcp 命名空间及创建memif接口,
#并通过linux-cp插件将memif接口映射到内核中。

lcp default netns vpp1-ns
create interface memif id 0 master
set interface state memif0/0 up
lcp create 1 host-if memif0
vpp2 startup.conf配置文件及启动配置文件:
代码语言:javascript复制
##vpp2 vpp2_startup.conf 配置如下:
unix {
log ./vpp2.log
full-coredump
cli-listen /run/vpp/cli-vpp2.sock
gid vpp
startup-config /root/memif/vpp2.conf
}

api-segment {
prefix vpp2
}

socksvr {
socket-name /run/vpp/api_2.sock
}

dpdk {
blacklist 8086:100f
}

plugins {
plugin linux_cp_plugin.so { enable }
plugin linux_nl_plugin.so { enable }
}

logging {
default-log-level debug
default-syslog-log-level info
}

###vpp2.conf文件是vpp cli配置,用来设置lcp 命名空间及创建memif接口,
#并通过linux-cp插件将memif接口映射到内核中。

lcp default netns vpp2-ns
create interface memif id 0 slave
set interface state memif0/0 up
lcp create 1 host-if memif0

在不同的网络命名空间中运行vpp程序,运行之后可以在/run/vpp目录下看到生成vppctl登陆使用unix域socket文件。

代码语言:javascript复制
#分别启动vpp1和vpp2
ip netns exec vpp1-ns /usr/bin/vpp -c `pwd`/vpp1_startup.conf
ip netns exec vpp1-ns /usr/bin/vpp -c `pwd`/vpp2_startup.conf
#分别在命名空间中设置linux接口memif0状态up及配置ip地址.
ip netns exec vpp1-ns ip link set dev memif0 up
ip netns exec vpp1-ns ip add add 10.0.0.1/24 dev memif0
ip netns exec vpp2-ns ip link set dev memif0 up
ip netns exec vpp2-ns ip add add 10.0.0.2/24 dev memif0

#查询生成了vpp1 和vpp2 对应cli sock文件。
root@jinsh:~/memif# ls /run/vpp/  -l | grep cli-vpp
srwxr-xr-x 1 root vpp 0 Mar  5 03:24 cli-vpp1.sock
srwxr-xr-x 1 root vpp 0 Mar  5 03:29 cli-vpp2.sock

分别命名空间中配置内核memif接口状态up及接口ip 地址,默认会同步到vpp中去。使用vppctl登录到vpp命令行视图,查询接口配置及互ping操作。

代码语言:javascript复制
#分别启动vpp1和vpp2
root@jinsh:~/memif# vppctl -s /run/vpp/cli-vpp1.sock
    _______    _        _   _____  ___
 __/ __/ _   (_)__    | | / / _ / _ 
 _/ _// // / / / _    | |/ / ___/ ___/
 /_/ /____(_)_/___/   |___/_/  /_/

vpp# show interface addr
local0 (dn):
memif0/0 (up):
  L3 10.0.0.1/24
tap1 (up):
vpp# ping 10.0.0.2
116 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=11.7408 ms
116 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=11.7551 ms
Aborted due to a keypress.

Statistics: 2 sent, 2 received, 0% packet loss
root@jinsh:~/memif# vppctl -s /run/vpp/cli-vpp2.sock
    _______    _        _   _____  ___
 __/ __/ _   (_)__    | | / / _ / _ 
 _/ _// // / / / _    | |/ / ___/ ___/
 /_/ /____(_)_/___/   |___/_/  /_/

vpp# show interface addr
local0 (dn):
memif0/0 (up):
  L3 10.0.0.2/24
tap1 (up):
vpp# ping 10.0.0.1
116 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=15.7554 ms
116 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=15.7501 ms
Aborted due to a keypress.

Statistics: 2 sent, 2 received, 0% packet loss
#分别在网络命名空间内核ping
oot@jinsh:~/memif# ip netns exec vpp1-ns ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=35.6 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=13.2 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=15.4 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=9.24 ms
^C
--- 10.0.0.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 9.239/18.368/35.599/10.191 ms
root@jinsh:~/memif# ip netns exec vpp2-ns ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=28.4 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=17.2 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=24.2 ms
^C
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 17.180/23.257/28.411/4.631 ms

在实验过程中,遇到一个问题:先在vpp创建好memif接口并配置ip地址,然后使用linux-cp插件将memif接口映射到内核。这时内核对应的memif接口不会自动配置ip地址的。这应该是linux-cp插件还存在小缺陷。

本文实验相关配置文件已放置于github:https://github.com/jin13417/dpdk-vpp-learning/tree/main/test/memif

0 人点赞