[vs]: dynamically create front panel ports in vs docker (#4499)

currently, vs docker always create 32 front panel ports.

when vs docker starts, it first detects the peer links
in the namespace and then setup equal number of front panel
interfaces as the peer links.

Signed-off-by: Guohan Lu <lguohan@gmail.com>
This commit is contained in:
lguohan 2020-04-30 12:50:59 -07:00 committed by GitHub
parent 2153caef59
commit 86bc8aec5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 41 deletions

View File

@ -7,7 +7,7 @@ def
{%- endmacro -%} {%- endmacro -%}
{# Determine device topology and filename postfix #} {# Determine device topology and filename postfix #}
{%- if DEVICE_METADATA is defined %} {%- if DEVICE_METADATA is defined and DEVICE_METADATA['localhost']['type'] is defined %}
{%- set switch_role = DEVICE_METADATA['localhost']['type'] %} {%- set switch_role = DEVICE_METADATA['localhost']['type'] %}
{%- if switch_role.lower() == 'torrouter' %} {%- if switch_role.lower() == 'torrouter' %}
{%- set filename_postfix = 't0' %} {%- set filename_postfix = 't0' %}

View File

@ -1,42 +1,12 @@
HOWTO Use Virtual Switch (Docker) HOWTO Use Virtual Switch (Docker)
1. Create a docker with 32 front panel port 1. Create a docker with two front panel ports
``` ```
$ docker run -id --name sw debian bash $ docker run -id --name sw debian bash
$ sudo ./create_vnet.sh sw $ sudo ./create_vnet.sh -n 2 sw
$ ip netns list $ ip netns list
sw-srv31 (id: 37)
sw-srv30 (id: 35)
sw-srv29 (id: 34)
sw-srv28 (id: 33)
sw-srv27 (id: 32)
sw-srv26 (id: 31)
sw-srv25 (id: 30)
sw-srv24 (id: 29)
sw-srv23 (id: 28)
sw-srv22 (id: 27)
sw-srv21 (id: 26)
sw-srv20 (id: 25)
sw-srv19 (id: 24)
sw-srv18 (id: 23)
sw-srv17 (id: 22)
sw-srv16 (id: 21)
sw-srv15 (id: 20)
sw-srv14 (id: 19)
sw-srv13 (id: 18)
sw-srv12 (id: 17)
sw-srv11 (id: 16)
sw-srv10 (id: 15)
sw-srv9 (id: 14)
sw-srv8 (id: 13)
sw-srv7 (id: 12)
sw-srv6 (id: 11)
sw-srv5 (id: 10)
sw-srv4 (id: 9)
sw-srv3 (id: 8)
sw-srv2 (id: 7)
sw-srv1 (id: 6) sw-srv1 (id: 6)
sw-srv0 (id: 5) sw-srv0 (id: 5)
``` ```
@ -51,8 +21,10 @@ $ docker run --privileged --network container:sw --name vs -d docker-sonic-vs
``` ```
$ docker exec -it vs bash $ docker exec -it vs bash
root@2e9b5c2dc2a2:/# ifconfig Ethernet0 10.0.0.0/31 up root@2e9b5c2dc2a2:/# config interface ip add Ethernet0 10.0.0.0/31
root@2e9b5c2dc2a2:/# ifconfig Ethernet4 10.0.0.2/31 up root@2e9b5c2dc2a2:/# config interface ip add Ethernet4 10.0.0.2/31
root@2e9b5c2dc2a2:/# config interface startup Ethernet0
root@2e9b5c2dc2a2:/# config interface startup Ethernet4
``` ```
4. Setup IP in the server network namespace 4. Setup IP in the server network namespace

View File

@ -1,4 +1,24 @@
#!/bin/bash #!/bin/bash -e
usage() {
echo "Usage: $0 [-n <int>] swname" 1>&2
exit 1
}
SERVERS=2
while getopts ":n:" opt; do
case $opt in
n)
SERVERS=$((OPTARG))
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
SWNAME=$1 SWNAME=$1
@ -6,9 +26,8 @@ pid=$(docker inspect --format '{{.State.Pid}}' $SWNAME)
echo Seting up servers echo Seting up servers
SERVERS=31
for srv in `seq 0 $SERVERS`; do for srv in `seq 0 $((SERVERS-1))`; do
SRV="$SWNAME-srv$srv" SRV="$SWNAME-srv$srv"
@ -24,9 +43,10 @@ for srv in `seq 0 $SERVERS`; do
IF="eth$((srv+1))" IF="eth$((srv+1))"
ip link add ${SRV}eth0 type veth peer name $IF ip link add ${SRV}eth0 type veth peer name $SWNAME-$IF
ip link set ${SRV}eth0 netns $SRV ip link set ${SRV}eth0 netns $SRV
ip link set $IF netns ${pid} ip link set $SWNAME-$IF netns ${pid}
nsenter -t $pid -n ip link set dev $SWNAME-$IF name $IF
echo "Bring ${SRV}eth0 up" echo "Bring ${SRV}eth0 up"
$NSS ip link set dev ${SRV}eth0 name eth0 $NSS ip link set dev ${SRV}eth0 name eth0

View File

@ -7,6 +7,23 @@ HWSKU=Force10-S6000
ln -sf /usr/share/sonic/device/$PLATFORM/$HWSKU /usr/share/sonic/hwsku ln -sf /usr/share/sonic/device/$PLATFORM/$HWSKU /usr/share/sonic/hwsku
pushd /usr/share/sonic/hwsku
# filter available front panel ports in lanemap.ini
[ -f lanemap.ini.orig ] || cp lanemap.ini lanemap.ini.orig
for p in $(ip link show | grep -oE "eth[0-9]+" | grep -v eth0); do
grep ^$p: lanemap.ini.orig
done > lanemap.ini
# filter available sonic front panel ports in port_config.ini
[ -f port_config.ini.orig ] || cp port_config.ini port_config.ini.orig
grep ^# port_config.ini.orig > port_config.ini
for lanes in $(awk -F ':' '{print $2}' lanemap.ini); do
grep -E "\s$lanes\s" port_config.ini.orig
done >> port_config.ini
popd
[ -d /etc/sonic ] || mkdir -p /etc/sonic [ -d /etc/sonic ] || mkdir -p /etc/sonic
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
@ -17,7 +34,7 @@ if [ -f /etc/sonic/config_db.json ]; then
mv /tmp/config_db.json /etc/sonic/config_db.json mv /tmp/config_db.json /etc/sonic/config_db.json
else else
# generate and merge buffers configuration into config file # generate and merge buffers configuration into config file
sonic-cfggen -t /usr/share/sonic/hwsku/buffers.json.j2 > /tmp/buffers.json sonic-cfggen -k $HWSKU -p /usr/share/sonic/hwsku/port_config.ini -t /usr/share/sonic/hwsku/buffers.json.j2 > /tmp/buffers.json
sonic-cfggen -j /etc/sonic/init_cfg.json -t /usr/share/sonic/hwsku/qos.json.j2 > /tmp/qos.json sonic-cfggen -j /etc/sonic/init_cfg.json -t /usr/share/sonic/hwsku/qos.json.j2 > /tmp/qos.json
sonic-cfggen -p /usr/share/sonic/hwsku/port_config.ini -k $HWSKU --print-data > /tmp/ports.json sonic-cfggen -p /usr/share/sonic/hwsku/port_config.ini -k $HWSKU --print-data > /tmp/ports.json
sonic-cfggen -j /etc/sonic/init_cfg.json -j /tmp/buffers.json -j /tmp/qos.json -j /tmp/ports.json --print-data > /etc/sonic/config_db.json sonic-cfggen -j /etc/sonic/init_cfg.json -j /tmp/buffers.json -j /tmp/qos.json -j /tmp/ports.json --print-data > /etc/sonic/config_db.json