Merge "devstack: network simulator support for sonic"

This commit is contained in:
Zuul 2025-04-08 20:49:15 +00:00 committed by Gerrit Code Review
commit c9090751b0
2 changed files with 115 additions and 19 deletions

View File

@ -2648,6 +2648,12 @@ function configure_ngs_for_simulator {
switch_pass="system_s3cret!" switch_pass="system_s3cret!"
enable_pass="" enable_pass=""
;; ;;
sonic)
switch_type="netmiko_sonic"
trunk_port="Ethernet0"
switch_pass="YourPaSsWoRd"
enable_pass=""
;;
esac esac
# NOTE(TheJulia) This is for a dell force10 switch, and it may need # NOTE(TheJulia) This is for a dell force10 switch, and it may need
# to be broken up to be more in-line with per-type options. # to be broken up to be more in-line with per-type options.
@ -2691,6 +2697,9 @@ function create_network_simulator_vm {
cisco_nexus9k) cisco_nexus9k)
create_network_simulator_vm_cisco_nexus $2 $3 create_network_simulator_vm_cisco_nexus $2 $3
;; ;;
sonic)
create_network_simulator_vm_sonic $2 $3
;;
esac esac
} }
@ -2951,6 +2960,65 @@ function create_network_simulator_vm_cisco_nexus {
send_switch_config_line localhost 55001 "copy run start" send_switch_config_line localhost 55001 "copy run start"
} # End of Cisco Nexus 9k simulator setup } # End of Cisco Nexus 9k simulator setup
function create_network_simulator_vm_sonic {
local sonic_image=/opt/stack/sonic-vs.img
if [ ! -f $sonic_image ]; then
sonic_url=$(curl -s https://sonic.software/builds.json | jq -r '.["master"]["sonic-vs.img.gz"]["url"]')
wget -O $sonic_image.gz $sonic_url
gzip -d $sonic_image.gz
fi
cp $sonic_image $sonic_image.qcow2
# For extra context:
# * 4GB of RAM
# * e1000 interfaces
# * virtio disk interface
# * boot_priority set to d
# First port is mapped to eth0.
# The VM will crash if the first interface is not present.
local emu_cmd="$IRONIC_VM_EMULATOR -enable-kvm -drive file=$sonic_image.qcow2,id=disk0,format=qcow2,if=none --device virtio-blk-pci,drive=disk0 -m 4096M -smp cpus=2 -display none -serial telnet:localhost:55001,server,nowait "
# Base interfaces, attaches the trunk and the management interfaces.
emu_cmd+=" -device e1000,netdev=net0 -netdev tap,id=net0,ifname=$1,script=no,downscript=no -device e1000,netdev=net1 -netdev tap,id=net1,ifname=$2,script=no,downscript=no,sndbuf=1048576"
# Get a list of links, cut everything *after* "@" since taps duplicate
# entries, limit to "sim-node" to match our nodes, and extract only
# the actual interface name.
local net_interface=2
for i in $(ip link show up |cut -f1 -d "@" |grep "sim-node"|cut -f2 -d" "|cut -d":" -f1|sed s/sim/sw/g); do
emu_cmd+=" -device e1000,netdev=net$net_interface -netdev tap,id=net$net_interface,ifname=$i,sndbuf=1048576"
net_interface=$(( net_interface + 1))
done
run_process ir-sw-sim "$emu_cmd" "root" "root"
# wait for the enable prompt
wait_for_switch_prompt localhost 55001 80 10 "sonic login:" False
sleep 4
send_switch_config_line localhost 55001 admin
sleep 2
send_switch_config_line localhost 55001 "YourPaSsWoRd"
sleep 10
# SONiC doesn't provide a means for this configuration through the CLI
# https://github.com/sonic-net/SONiC/blob/master/doc/SONiC-User-Manual.md#31-configuring-management-interface-and-loopback-interface
send_switch_config_line localhost 55001 "sudo /sbin/ifconfig eth0 172.24.5.20/24"
send_switch_config_line localhost 55001 "sonic-cli"
send_switch_config_line localhost 55001 "configure terminal"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet0 10.0.0.0/31"
send_switch_config_line localhost 55001 "sudo config switchport mode trunk Ethernet0"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet4 10.0.0.2/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet4"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet8 10.0.0.4/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet8"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet12 10.0.0.6/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet12"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet16 10.0.0.8/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet16"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet20 10.0.0.10/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet20"
send_switch_config_line localhost 55001 "sudo config interface ip remove Ethernet24 10.0.0.12/31"
send_switch_config_line localhost 55001 "sudo config switchport mode access Ethernet24"
} # End of SONiC configuration
function wait_for_switch_prompt { function wait_for_switch_prompt {
local host=$1 local host=$1
local port=$2 local port=$2
@ -3006,6 +3074,8 @@ function send_switch_config_line {
# NOTE(TheJulia): *Always* strings the output, in case 0xFF can # NOTE(TheJulia): *Always* strings the output, in case 0xFF can
# break devstack's executor. # break devstack's executor.
echo "$cmd" | nc -w1 $host $port | strings echo "$cmd" | nc -w1 $host $port | strings
# Sleep briefy to allow the execution to occur and finish.
sleep 1
} }
function wait_for_nova_resources { function wait_for_nova_resources {
@ -3497,27 +3567,30 @@ function identify_port_for_switch {
cisco_nexus9k) cisco_nexus9k)
identify_cisco_nexus_port $vm_port identify_cisco_nexus_port $vm_port
;; ;;
sonic)
identify_sonic_port $vm_port
;;
esac esac
} }
function identify_force10_port { function identify_force10_port {
case $1 in case $1 in
ovs-node-0i1) tap-node-0i1)
echo -n "forty0/4" echo -n "forty0/4"
;; ;;
ovs-node-0i2) tap-node-0i2)
echo -n "forty0/8" echo -n "forty0/8"
;; ;;
ovs-node-1i1) tap-node-1i1)
echo -n "forty0/12" echo -n "forty0/12"
;; ;;
ovs-node-1i2) tap-node-1i2)
echo -n "forty0/16" echo -n "forty0/16"
;; ;;
ovs-node-2i1) tap-node-2i1)
echo -n "forty0/20" echo -n "forty0/20"
;; ;;
ovs-node-2i2) tap-node-2i2)
echo -n "forty0/24" echo -n "forty0/24"
;; ;;
esac esac
@ -3525,22 +3598,22 @@ function identify_force10_port {
function identify_force10_10_port { function identify_force10_10_port {
case $1 in case $1 in
ovs-node-0i1) tap-node-0i1)
echo -n "ethernet1/1/2" echo -n "ethernet1/1/2"
;; ;;
ovs-node-0i2) tap-node-0i2)
echo -n "ethernet1/1/3" echo -n "ethernet1/1/3"
;; ;;
ovs-node-1i1) tap-node-1i1)
echo -n "ethernet1/1/4" echo -n "ethernet1/1/4"
;; ;;
ovs-node-1i2) tap-node-1i2)
echo -n "ethernet1/1/5" echo -n "ethernet1/1/5"
;; ;;
ovs-node-2i1) tap-node-2i1)
echo -n "ethernet1/1/6" echo -n "ethernet1/1/6"
;; ;;
ovs-node-2i2) tap-node-2i2)
echo -n "ethernet1/1/7" echo -n "ethernet1/1/7"
;; ;;
esac esac
@ -3548,27 +3621,50 @@ function identify_force10_10_port {
function identify_cisco_nexus_port { function identify_cisco_nexus_port {
case $1 in case $1 in
ovs-node-0i1) tap-node-0i1)
echo -n "ethernet1/2" echo -n "ethernet1/2"
;; ;;
ovs-node-0i2) tap-node-0i2)
echo -n "ethernet1/3" echo -n "ethernet1/3"
;; ;;
ovs-node-1i1) tap-node-1i1)
echo -n "ethernet1/4" echo -n "ethernet1/4"
;; ;;
ovs-node-1i2) tap-node-1i2)
echo -n "ethernet1/5" echo -n "ethernet1/5"
;; ;;
ovs-node-2i1) tap-node-2i1)
echo -n "ethernet1/6" echo -n "ethernet1/6"
;; ;;
ovs-node-2i2) tap-node-2i2)
echo -n "ethernet1/7" echo -n "ethernet1/7"
;; ;;
esac esac
} }
function identify_sonic_port {
case $1 in
tap-node-0i1)
echo -n "Ethernet4"
;;
tap-node-0i2)
echo -n "Ethernet8"
;;
tap-node-1i1)
echo -n "Ethernet12"
;;
tap-node-1i2)
echo -n "Ethernet16"
;;
tap-node-2i1)
echo -n "Ethernet20"
;;
tap-node-2i2)
echo -n "Ethernet24"
;;
esac
}
function configure_iptables { function configure_iptables {
# enable tftp natting for allowing connections to HOST_IP's tftp server # enable tftp natting for allowing connections to HOST_IP's tftp server

View File

@ -155,6 +155,6 @@ fi
if [[ "${NET_SIMULATOR:-ovs}" == "ovs" ]]; then if [[ "${NET_SIMULATOR:-ovs}" == "ovs" ]]; then
VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/ovs-/{print $5","$1}')|tr ' ' ';') VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/ovs-/{print $5","$1}')|tr ' ' ';')
else else
VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/tap-/{print $5","$1}')|tr ' ' ';') VM_MAC=$(echo -n $(virsh domiflist $NAME |awk '/tap-/{print $5","$3}')|tr ' ' ';')
fi fi
echo -n "$VM_MAC $VBMC_PORT $PDU_OUTLET" echo -n "$VM_MAC $VBMC_PORT $PDU_OUTLET"