虚拟环境部署SONiC P4 Software Switch系统测试BGP

Events News

【背景】

数据中心交换机白盒化之势不可挡,开源网络潮流不可逆。SONiC作为新一代开源网络操作系统的代表,越发展现出他的优势和领先地位。

SONiC 是微软公司基于 Debian Linux 打造的一款网络交换机操作系统。是安装在Linux上的软件合集,运行在硬件交换机上,在数据中心网络中提供路由功能。该系统包含代码工具包和内核补丁能够根据你的意愿来调整网络交换机,降低了对来自网络设备提供商的固件依赖,能够让你全面接管网络交换机的工作。

为了储备相关知识,搭建模拟测试环境,以供自己和同仁们快速练手,整理此文。

 

【环境】

Mac笔记本上通过VMware运行Ubuntu操作系统,跑SONiC P4 Software Switch软件交换机,都是通过多个docker容器实现模拟测试。

 

【步骤】

一、准备基础系统

准备好一个Ubuntu系统环境,版本随意,本人准备的是20.04。目的还是跑后面的基于docker的软件交换机

lsb_release -a
No LSB modules are available.
Distributor ID:        Ubuntu
Description:        Ubuntu 20.04.1 LTS
Release:        20.04
Codename:        focal

 

二、下载模拟程序

模拟程序在github上有开源,下载地址如下

https://github.com/Azure/SONiC/wiki/files/SONiC-P4/SONiC-P4.Test.tar.gz

下载后解压,有如下文件:

 

 

三、测试使用程序

 

0、虚拟测试环境拓扑:

switch1 和 switch2 在不同的2个BGP AS中。 Switch1 宣告了 192.168.1.0/24网段, switch2 宣告了 192.168.2.0/24网段。

1、运行安装脚本

./install_docker_ovs.sh

 

2、运行获取docker镜像文件的脚本

./load_image.sh

 

3、运行启动脚本

./start.sh

 

4、查看docker运行情况

docker ps

 

5、测试内部系统互联情况

./test.sh

 

6、在switch1上检查BGP

docker exec -it switch1 bash
root@switch1:/# vtysh -c “show ip bgp sum”

 

7、清楚环境

./stop.sh

 

 


 

 

start.sh脚本解读

We set up the topology in start.sh. First, we start four docker containers in the topology. Take the command for switch1 as an example.

sudo docker run --net=none --privileged --entrypoint /bin/bash --name switch1 -it -d -v $PWD/switch1:/sonic docker-sonic-p4:latest

We specify --net=none to prevent Docker engine from adding its docker0 interface, which may interfere with the topology being tested. --privileged is to enable each container to configure their own interfaces. -v $PWD/switch1:/sonic mounts the configuration folder into the switch containers.

Then we create three links. Take the link between switch1 and switch2 as an example. The following commands connect switch1’s interface eth1 with switch2’s interface eth1.

sudo ovs-vsctl add-br switch1_switch2
sudo ovs-docker add-port switch1_switch2 eth1 switch1
sudo ovs-docker add-port switch1_switch2 eth1 switch2

We also configure the interface IP and default routes on the host1 and host2. Take host1 as an example.

sudo docker exec -d host1 ifconfig eth1 192.168.1.2/24 mtu 1400
sudo docker exec -d host1 ip route replace default via 192.168.1.1

Finally, we invoke the startup script for switch1 and switch2.

sudo docker exec -d switch1 sh /sonic/scripts/startup.sh
sudo docker exec -d switch2 sh /sonic/scripts/startup.sh

SONiC-P4 配置细节

In start.sh, we have mounted the configuration folder into the switch container, at /sonic. The most important configurations are at /sonic/scripts/startup.sh/sonic/etc/config_db/vlan_config.json, and /sonic/etc/quagga/bgpd.conf.

In /sonic/scripts/startup.sh, we start all SONiC services and a P4 software switch. The P4 software switch is started by this line (see supervisord.conf)

simple_switch --log-console -i 1@eth1 -i 2@eth2 ...

It binds interface eth1 to P4 software switch’s port 1, eth2 to port 2, and so on. These ethX interfaces are usually referred as front-panel interfaces, and directly used by the P4 switches for carrying data plane packets. However, SONiC operates on another type of interfaces, called host interfacesHost interfaces are for SONiC control plane, and are NOT carrying data plane packets. The host interfaces are named as EthernetX. We configure peer-to-peer IP and MTU on host interfaces. SONiC reads the configurations, like IP and MTU, from host interfaces, then configures these values on the P4 software switch using SAI. The mapping between host interfaces and switch ports is specified in /port_config.ini:

# alias         lanes
Ethernet0       1
Ethernet1       2
...

Together with the simple_switch command in /sonic/scripts/startup.sh, we have configured this mapping Ethernet0 –> lane 1 –> eth1. It is essentially a mapping between host interfaces and front-panel interfaces.

/sonic/etc/config_db/vlan_config.json configures the switch vlan interfaces used in this test, using ConfigDB interface, look here for details:

{
    "VLAN": {
        "Vlan15": {
            "members": [
                "Ethernet0"
            ], 
            "vlanid": "15"
        }, 
        "Vlan10": {
            "members": [
                "Ethernet1"
            ], 
            "vlanid": "10"
        }
    },
    "VLAN_MEMBER": {
        "Vlan15|Ethernet0": {
            "tagging_mode": "untagged"
        },
        "Vlan10|Ethernet1": {
            "tagging_mode": "untagged"
        }
    },
    "VLAN_INTERFACE": {
        "Vlan15|10.0.0.0/31": {},
        "Vlan10|192.168.1.1/24": {}
    }
}

/sonic/etc/quagga/bgpd.conf configures the BGP session on the switch. Here is the BGP configuration for switch1, which peers with switch2 using peer-to-peer IP 10.0.0.0/31, and announces 192.168.1.0/24.

router bgp 10001                        
  bgp router-id 192.168.1.1             
  network 192.168.1.0 mask 255.255.255.0
  neighbor 10.0.0.1 remote-as 10002     
  neighbor 10.0.0.1 timers 1 3          
  neighbor 10.0.0.1 send-community      
  neighbor 10.0.0.1 allowas-in          
  maximum-paths 64                      
!                                       
access-list all permit any