当前位置: 首页 > 工具软件 > Sonic > 使用案例 >

SONiC vs testbed搭建

阎璞瑜
2023-12-01

准备工作

  • 一台安装Ubuntu18.04的系统,内存建议不少于16G,需要支持kvm虚拟化
  • 安装ssh server
sudo apt update -y
sudo apt openssh-server -y
  • 设置sudo免密
sudo visudo
#最后一行加上自己的用户名
ljyfree ALL=(ALL:ALL) NOPASSWD: ALL
#退出
  • 安装必要的软件
sudo apt install python python-pip -y
sudo pip install j2cli==0.3.10
sudo apt install git vim -y
  • 安装虚拟化需要的软件
sudo apt-get install qemu-kvm qemu virt-manager virt-viewer -y

ljyfree@testbed:~$ kvm-ok 
INFO: /dev/kvm exists
KVM acceleration can be used
ljyfree@testbed:~$ 
  • GitHub上面拉代码慢,可以先用gitee克隆,然后直接从gitee上拉取
ljyfree@sonic-testbed:~$ git clone https://gitee.com/ljyfree/sonic-mgmt.git
Cloning into 'sonic-mgmt'...
Username for 'https://gitee.com': ljyfree
Password for 'https://ljyfree@gitee.com': 
remote: Enumerating objects: 41008, done.
remote: Counting objects: 100% (41008/41008), done.
remote: Compressing objects: 100% (10794/10794), done.
remote: Total 41008 (delta 29463), reused 41008 (delta 29463), pack-reused 0
Receiving objects: 100% (41008/41008), 32.28 MiB | 5.56 MiB/s, done.
Resolving deltas: 100% (29463/29463), done.
ljyfree@sonic-testbed:~$ 
  • 安装docker
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release -y

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


sudo apt-get update -y
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
  • 将当前用户加到docker这个group中,然后退出后重新登录
ljyfree@testbed:~$ sudo groupadd docker
groupadd: group 'docker' already exists
ljyfree@testbed:~$ sudo usermod -aG docker $USER
ljyfree@testbed:~$ 
ljyfree@testbed:~$ 
ljyfree@testbed:~$ 
ljyfree@testbed:~$ exit
logout
#退出再重新登录
ljyfree@testbed:~/packages$ sha256sum cEOS64-lab-4.25.8M.tar.xz 
71161e2973579fd1fa4045cefd530176d047dc8c068279965fb5e404d604f43d  cEOS64-lab-4.25.8M.tar.xz
ljyfree@testbed:~/packages$ 
  • 加载镜像并设置tag
ljyfree@testbed:~/packages$ docker import cEOS64-lab-4.25.8M.tar.xz ceosimage:4.25.8M ceosimage:4.25.8M
  • 下载最新的sonic-vs镜像,这个镜像会不时更新
ljyfree@testbed:~/packages$ wget "https://sonic-build.azurewebsites.net/api/sonic/artifacts?branchName=master&platform=vs&target=target/sonic-vs.img.gz" -O sonic-vs.img.gz
ljyfree@testbed:~/packages$ sha256sum sonic-vs.img.gz 
6f01483503b08c19ff199d74f06b682647cc0110dbbf8f21653a3eecdc118a6d  sonic-vs.img.gz
ljyfree@testbed:~/packages$ 
  • 拷贝到目标目录
ljyfree@sonic-testbed:~/packages$ mkdir -p ~/sonic-vm/images/
ljyfree@sonic-testbed:~/packages$ cp sonic-vs.img ~/sonic-vm/images/
  • 设置网桥
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ sudo ./setup-management-network.sh
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ sudo ./setup-management-network.sh
Refreshing apt package lists...
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                                                                           
Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]        
Get:5 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [55.3 kB]
Get:6 http://cn.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [61.0 kB]
Get:8 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,596 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:10 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,482 kB]
Get:11 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [297 kB]
Get:12 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,817 kB]
Get:13 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,613 kB]
Get:14 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [302 kB]
Get:15 http://cn.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:16 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [9,272 B]
Fetched 8,488 kB in 5s (1,738 kB/s)                                  
Reading package lists... Done

STEP 1: Checking for j2cli package...
/usr/local/bin/j2

STEP 2: Checking for bridge-utils package...
/sbin/brctl

STEP 3: Checking for net-tools package...
/sbin/ifconfig

STEP 4: Checking for ethtool package...
/sbin/ethtool

STEP 5: Checking if bridge br1 already exists...
br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.250.0.1  netmask 255.255.255.0  broadcast 10.250.0.255
        inet6 fe80::c08:81ff:fe96:9ac6  prefixlen 64  scopeid 0x20<link>
        inet6 fec0::1  prefixlen 64  scopeid 0x40<site>
        ether 5e:62:5e:d0:d4:42  txqueuelen 1000  (Ethernet)
        RX packets 23176  bytes 7602662 (7.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14454  bytes 25263480 (25.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


STEP 6: Configuring br1 interface...
Assigning 10.250.0.1/24 to br1
SIOCSIFADDR: File exists
Bringing up br1

COMPLETE. Bridge info:

bridge name     bridge id               STP enabled     interfaces
br1             8000.5e625ed0d442       no              VM0100-m
                                                        VM0101-m
                                                        VM0102-m
                                                        VM0103-m
                                                        ptf-vms6-1-m
                                                        vlab-01-0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.250.0.1  netmask 255.255.255.0  broadcast 10.250.0.255
        inet6 fe80::c08:81ff:fe96:9ac6  prefixlen 64  scopeid 0x20<link>
        inet6 fec0::1  prefixlen 64  scopeid 0x40<site>
        ether 5e:62:5e:d0:d4:42  txqueuelen 1000  (Ethernet)
        RX packets 23176  bytes 7602662 (7.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14455  bytes 25263610 (25.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ 
  • 编出需要的docker镜像
ljyfree@testbed:~/packages$ cd ~/sonic-mgmt/
ljyfree@testbed:~/sonic-mgmt$ ./setup-container.sh -n sonic-testbed -d /data
Using default tag: latest
latest: Pulling from docker-sonic-mgmt
40dd5be53814: Pull complete 
a00a8fe57a8a: Pull complete 
Digest: sha256:97d5825766e162bb15fc9d253f89378447c33e34c93d202f3fa3a0986f3bf101
Status: Downloaded newer image for sonicdev-microsoft.azurecr.io:443/docker-sonic-mgmt:latest
sonicdev-microsoft.azurecr.io:443/docker-sonic-mgmt:latest

******************************************************************************
EXEC: docker exec --user ljyfree -ti sonic-testbed bash
SSH:  ssh -i ~/.ssh/id_rsa_docker_sonic_mgmt ljyfree@172.17.0.2
******************************************************************************
ljyfree@testbed:~/sonic-mgmt$ 
ljyfree@sonic-testbed:~/sonic-mgmt$ docker images | grep ljyfree
docker-sonic-mgmt-ljyfree                             master    31f770d9e315   About a minute ago   4.07GB
ljyfree@sonic-testbed:~/sonic-mgmt$ 
  • 后续操作基本上都是在这个docker进行的
ljyfree@testbed:~/sonic-mgmt$ docker exec -it sonic-testbed bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ljyfree@1fcfe589370d:~$ cd /data/sonic-mgmt/
ljyfree@1fcfe589370d:/data/sonic-mgmt$

搭建t0拓扑

  • 修改veos_vtb里面的用户名
ljyfree@1fcfe589370d:/data/sonic-mgmt/ansible$ git diff veos_vtb
diff --git a/ansible/veos_vtb b/ansible/veos_vtb
index a6788b28..51fe7488 100644
--- a/ansible/veos_vtb
+++ b/ansible/veos_vtb
@@ -242,7 +242,7 @@ vm_host_1:
   hosts:
     STR-ACS-VSERV-01:
       ansible_host: 172.17.0.1
-      ansible_user: use_own_value
+      ansible_user: ljyfree
 
 vms_1:
   hosts:
ljyfree@1fcfe589370d:/data/sonic-mgmt/ansible$ 
  • 创建一个叫password.txt的文件,里面随便写点什么
ljyfree@1fcfe589370d:/data/sonic-mgmt/ansible$ cat password.txt
123
  • 拷贝ansible文件
ljyfree@7aa71bfca417:/data/sonic-mgmt/ansible$ sudo mkdir /etc/ansible/
ljyfree@7aa71bfca417:/data/sonic-mgmt/ansible$ sudo cp ansible.cfg /etc/ansible/
ljyfree@7aa71bfca417:/data/sonic-mgmt/ansible$ sudo cp -r plugins/ /etc/ansible/
  • 修改cEOS的信息
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ git diff ./group_vars/all/ceos.yml
diff --git a/ansible/group_vars/all/ceos.yml b/ansible/group_vars/all/ceos.yml
index 1bbc1c7d..73951d08 100644
--- a/ansible/group_vars/all/ceos.yml
+++ b/ansible/group_vars/all/ceos.yml
@@ -3,7 +3,7 @@
 #ceos_image_filename: cEOS64-lab-4.23.2F.tar.xz
 #ceos_image_orig: ceosimage:4.23.2F
 #ceos_image: ceosimage:4.23.2F-1
-ceos_image_filename: cEOS64-lab-4.25.5.1M.tar
-ceos_image_orig: ceosimage:4.25.5.1M
-ceos_image: ceosimage:4.25.5.1M-1
-skip_ceos_image_downloading: false
+ceos_image_filename: cEOS64-lab-4.25.8M.tar
+ceos_image_orig: ceosimage:4.25.8M
+ceos_image: ceosimage:4.25.8M
+skip_ceos_image_downloading: true
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ 
  • 运行,后面加-vvv是为了打印出更多的信息,方便定位
ljyfree@7aa71bfca417:/data/sonic-mgmt/ansible$ ./testbed-cli.sh -t vtestbed.yaml -m veos_vtb -k ceos add-topo vms-kvm-t0 password.txt -vvv
  • 此时的docker和镜像
ljyfree@sonic-testbed:~$ docker images
REPOSITORY                                            TAG       IMAGE ID       CREATED          SIZE
docker-sonic-mgmt-ljyfree                             master    7eeb2c593949   22 minutes ago   4.07GB
ceosimage                                             4.25.8M   68fa20982853   39 minutes ago   1.68GB
sonicdev-microsoft.azurecr.io:443/docker-sonic-mgmt   latest    c219e3beb76e   19 hours ago     3.46GB
sonicdev-microsoft.azurecr.io:443/docker-ptf          latest    b91d9bca6405   4 weeks ago      1.81GB
ljyfree@sonic-testbed:~$ 

ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ docker ps
CONTAINER ID   IMAGE                                                 COMMAND                  CREATED          STATUS          PORTS     NAMES
cb674ee5416b   ceosimage:4.25.8M                                     "/sbin/init systemd.…"   2 minutes ago    Up 2 minutes              ceos_vms6-1_VM0103
b8c400251d8d   ceosimage:4.25.8M                                     "/sbin/init systemd.…"   2 minutes ago    Up 2 minutes              ceos_vms6-1_VM0102
af685d0e0cf2   ceosimage:4.25.8M                                     "/sbin/init systemd.…"   2 minutes ago    Up 2 minutes              ceos_vms6-1_VM0101
829905291a70   ceosimage:4.25.8M                                     "/sbin/init systemd.…"   2 minutes ago    Up 2 minutes              ceos_vms6-1_VM0100
171f18426e09   debian:jessie                                         "bash"                   3 minutes ago    Up 3 minutes              net_vms6-1_VM0103
f23219cde94d   debian:jessie                                         "bash"                   3 minutes ago    Up 3 minutes              net_vms6-1_VM0102
8e557ef627e8   debian:jessie                                         "bash"                   3 minutes ago    Up 3 minutes              net_vms6-1_VM0100
9769708c84f4   debian:jessie                                         "bash"                   3 minutes ago    Up 3 minutes              net_vms6-1_VM0101
853b43fe5bbb   sonicdev-microsoft.azurecr.io:443/docker-ptf:latest   "/usr/local/bin/supe…"   21 minutes ago   Up 21 minutes             ptf_vms6-1
7aa71bfca417   docker-sonic-mgmt-ljyfree:master                      "/bin/bash"              44 minutes ago   Up 44 minutes   22/tcp    sonic-testbed
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ 
  • sonic vs已经启动
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 3     vlab-01                        running

ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ 
  • 可以通过ssh或是串口登录
#ssh
ssh admin@10.250.101,
登录密码是password

#串口登录
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

vlab-01 login: admin
Password: #填入password
  • 通过minigraph对vs下发配置
ljyfree@7aa71bfca417:/data/sonic-mgmt/ansible$ ./testbed-cli.sh -t vtestbed.yaml -m veos_vtb deploy-mg vms-kvm-t0 veos_vtb password.txt -vvv
  • 登录vs,发现BGP邻居已经建立,BGP路由已经学习到了
ljyfree@sonic-testbed:~/sonic-mgmt/ansible$ ssh admin@10.250.0.101
admin@10.250.0.101's password: 
Linux vlab-01 5.10.0-12-2-amd64 #1 SMP Debian 5.10.103-1 (2022-03-07) x86_64
You are on
  ____   ___  _   _ _  ____
 / ___| / _ \| \ | (_)/ ___|
 \___ \| | | |  \| | | |
  ___) | |_| | |\  | | |___
 |____/ \___/|_| \_|_|\____|

-- Software for Open Networking in the Cloud --

Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.

Help:    http://azure.github.io/SONiC/

Last login: Wed Jun  1 10:02:16 2022 from 10.250.0.1
admin@vlab-01:~$ 
admin@vlab-01:~$ vtysh

Hello, this is FRRouting (version 8.2.2).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

vlab-01# 
vlab-01# show ip bgp summary 

IPv4 Unicast Summary (VRF default):
BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 6405
RIB entries 12807, using 2301 KiB of memory
Peers 4, using 2894 KiB of memory
Peer groups 4, using 256 bytes of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.0.0.57       4      64600     52983     52981        0    0    0 1d17h28m         6400     6405 ARISTA01T1
10.0.0.59       4      64600     52986     52980        0    0    0 1d17h28m         6400     6405 ARISTA02T1
10.0.0.61       4      64600     52985     52981        0    0    0 1d17h28m         6400     6405 ARISTA03T1
10.0.0.63       4      64600     52986     52980        0    0    0 1d17h28m         6400     6405 ARISTA04T1

Total number of neighbors 4
vlab-01# 
 类似资料: