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

SONiC(2):手动运行sonic-vs

丌官利
2023-12-01

SONiC的testbed都是用ansible自动部署的,下面尝试手动来创建。另外最新的sonic-vs可以从这里下载。

准备工作

  • ansible生成的vlab-01这个虚机的vir配置xml文件如下
testbed@u1804-vm:~$ ll /etc/libvirt/qemu/vlab-01.xml 
-rw------- 1 root root 10993 7月  23 08:01 /etc/libvirt/qemu/vlab-01.xml
testbed@u1804-vm:~$
testbed@u1804-vm:~$ sudo cat /etc/libvirt/qemu/vlab-01.xml 
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit vlab-01
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>vlab-01</name>
  <uuid>9fc6aa50-1bb1-4e95-a0a7-596b1825544c</uuid>
  <memory unit='KiB'>3072000</memory>
  <currentMemory unit='KiB'>3072000</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-q35-2.11'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='writeback'/>
      <source file='/home/testbed/sonic-vm/disks/sonic_vlab-01.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x03' function='0x0'/>
    </controller>
    <controller type='sata' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pcie-root'/>
    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
      <model name='i82801b11-bridge'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
    </controller>
    <controller type='pci' index='2' model='pci-bridge'>
      <model name='pci-bridge'/>
      <target chassisNr='2'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </controller>
    <controller type='pci' index='3' model='pci-bridge'>
      <model name='pci-bridge'/>
      <target chassisNr='3'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
    </controller>
    <controller type='pci' index='4' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='4' port='0x8'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
    </controller>
    <controller type='pci' index='5' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='5' port='0x9'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='ethernet'>
      <mac address='52:54:00:46:f1:06'/>
      <target dev='vlab-01-0'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:71:01:5b'/>
      <target dev='vlab-01-1'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:3e:7d:af'/>
      <target dev='vlab-01-2'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x03' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:f4:5a:4b'/>
      <target dev='vlab-01-3'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x04' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:71:21:ab'/>
      <target dev='vlab-01-4'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x05' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:b4:ba:f3'/>
      <target dev='vlab-01-5'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x06' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:cd:0d:d8'/>
      <target dev='vlab-01-6'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x07' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:dc:a9:a0'/>
      <target dev='vlab-01-7'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x08' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:5c:36:e9'/>
      <target dev='vlab-01-8'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x09' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:e4:41:3e'/>
      <target dev='vlab-01-9'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0a' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:80:55:7f'/>
      <target dev='vlab-01-10'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0b' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:d7:e4:4b'/>
      <target dev='vlab-01-11'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0c' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:6c:e5:6c'/>
      <target dev='vlab-01-12'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0d' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:b3:a5:62'/>
      <target dev='vlab-01-13'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0e' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:d1:d4:64'/>
      <target dev='vlab-01-14'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x0f' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:f1:10:b6'/>
      <target dev='vlab-01-15'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x10' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:7e:4d:4c'/>
      <target dev='vlab-01-16'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x11' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:bb:42:6c'/>
      <target dev='vlab-01-17'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x12' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:83:12:ee'/>
      <target dev='vlab-01-18'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x13' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:67:24:38'/>
      <target dev='vlab-01-19'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x14' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:de:88:05'/>
      <target dev='vlab-01-20'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x15' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:4b:3c:43'/>
      <target dev='vlab-01-21'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x16' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:b4:b5:10'/>
      <target dev='vlab-01-22'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x17' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:4e:cb:7b'/>
      <target dev='vlab-01-23'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x18' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:6f:c9:15'/>
      <target dev='vlab-01-24'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x19' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:86:a7:52'/>
      <target dev='vlab-01-25'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1a' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:07:c1:b4'/>
      <target dev='vlab-01-26'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1b' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:81:8e:66'/>
      <target dev='vlab-01-27'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1c' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:43:ec:8d'/>
      <target dev='vlab-01-28'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1d' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:e9:1f:08'/>
      <target dev='vlab-01-29'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1e' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:ec:2e:6c'/>
      <target dev='vlab-01-30'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x1f' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:ed:42:c1'/>
      <target dev='vlab-01-31'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x01' function='0x0'/>
    </interface>
    <interface type='ethernet'>
      <mac address='52:54:00:98:7d:c8'/>
      <target dev='vlab-01-32'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x02' function='0x0'/>
    </interface>
    <serial type='tcp'>
      <source mode='bind' host='127.0.0.1' service='9000'/>
      <protocol type='telnet'/>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='tcp'>
      <source mode='bind' host='127.0.0.1' service='9000'/>
      <protocol type='telnet'/>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='apparmor' relabel='yes'/>
</domain>
testbed@u1804-vm:~$ 
  • 复制一份并修改
testbed@u1804-vm:~$ sudo cp /etc/libvirt/qemu/vlab-01.xml /etc/libvirt/qemu/vlab-02.xml

修改一:删除一行
修改二:修改串口9000->9001
修改三:修改mac前缀,例如52:54->52:58
修改四:将所有的vlab-01改为vlab-02

  • 复制一份img
testbed@u1804-vm:~$ cp /home/testbed/sonic-vm/images/sonic-vs.img /home/testbed/sonic-vm/disks/sonic_vlab-02.img

创建和启动

  • 创建vlab-02虚机
testbed@u1804-vm:~$ sudo virsh define /etc/libvirt/qemu/vlab-02.xml
Domain vlab-02 defined from /etc/libvirt/qemu/vlab-02.xml

testbed@u1804-vm:~$ 
testbed@u1804-vm:~$ sudo virsh list --all
Id    Name                           State
----------------------------------------------------
19    vlab-01                        running
-     vlab-02                        shut off
  • 启动虚机
testbed@u1804-vm:~$ sudo virsh start vlab-02
Domain vlab-02 started
  • 查看端口
testbed@u1804-vm:~$ ip add | grep vlab-02
854: vlab-02-0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br1 state UNKNOWN group default qlen 1000
855: vlab-02-1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
856: vlab-02-2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
857: vlab-02-3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
858: vlab-02-4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
859: vlab-02-5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
860: vlab-02-6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
861: vlab-02-7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
862: vlab-02-8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
863: vlab-02-9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
864: vlab-02-10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
865: vlab-02-11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
866: vlab-02-12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
867: vlab-02-13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
868: vlab-02-14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
869: vlab-02-15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
870: vlab-02-16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
871: vlab-02-17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
872: vlab-02-18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
873: vlab-02-19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
874: vlab-02-20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
875: vlab-02-21: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
876: vlab-02-22: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
877: vlab-02-23: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
878: vlab-02-24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
879: vlab-02-25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
880: vlab-02-26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
881: vlab-02-27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
882: vlab-02-28: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
883: vlab-02-29: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
884: vlab-02-30: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
885: vlab-02-31: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
886: vlab-02-32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
testbed@u1804-vm:~$ 

登录和配置

  • 通过串口登录,可以看到启动log
testbed@u1804-vm:~$ telnet localhost 9001
  • 登录的用户名密码:admin/YourPaSsWoRd
  • 配置管理IP
admin@sonic:~$ sudo config interface ip add eth0 10.250.0.201/24
  • 回到服务器上,将vlab-02-0加到管理bridge上
testbed@u1804-vm:~$ sudo brctl addif br1 vlab-02-0
  • 这样就可以ssh登录了(br1自己的IP是10.250.0.1/24)
testbed@u1804-vm:~$ ssh admin@10.250.0.201
The authenticity of host '10.250.0.201 (10.250.0.201)' can't be established.
RSA key fingerprint is SHA256:hv4SyAf5wtjvtR385h7mGry5wO9OXUItjVzEfDfQLOM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.250.0.201' (RSA) to the list of known hosts.
admin@10.250.0.201's password: 
Permission denied, please try again.
admin@10.250.0.201's password: 
Linux sonic 4.19.0-9-2-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-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: Thu Aug 13 01:49:36 2020
admin@sonic:~$ 
  • 后面想让vlab-02的端口和谁通信,只需要将对应端口加到相应的OVS bridge上即可,例如
testbed@u1804-vm:~$ sudo ovs-vsctl add-port br-VM0100-1 vlab-02-1

testbed@u1804-vm:~$ sudo ovs-vsctl show
   Bridge "br-VM0100-1"
        Port "vlab-01-1"
           Interface "vlab-01-1"
       Port "vlab-02-1"
           Interface "vlab-02-1"
       Port "VM0100-t1"
           Interface "VM0100-t1"
       Port "br-VM0100-1"
           Interface "br-VM0100-1"
               type: internal

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 类似资料: