Skip to content

Commit 86bc8ae

Browse files
authored
[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 <[email protected]>
1 parent 2153cae commit 86bc8ae

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

files/build_templates/buffers_config.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def
77
{%- endmacro -%}
88

99
{# Determine device topology and filename postfix #}
10-
{%- if DEVICE_METADATA is defined %}
10+
{%- if DEVICE_METADATA is defined and DEVICE_METADATA['localhost']['type'] is defined %}
1111
{%- set switch_role = DEVICE_METADATA['localhost']['type'] %}
1212
{%- if switch_role.lower() == 'torrouter' %}
1313
{%- set filename_postfix = 't0' %}

platform/vs/README.vsdocker.md

+6-34
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,12 @@
11
HOWTO Use Virtual Switch (Docker)
22

33

4-
1. Create a docker with 32 front panel port
4+
1. Create a docker with two front panel ports
55

66
```
77
$ docker run -id --name sw debian bash
8-
$ sudo ./create_vnet.sh sw
8+
$ sudo ./create_vnet.sh -n 2 sw
99
$ ip netns list
10-
sw-srv31 (id: 37)
11-
sw-srv30 (id: 35)
12-
sw-srv29 (id: 34)
13-
sw-srv28 (id: 33)
14-
sw-srv27 (id: 32)
15-
sw-srv26 (id: 31)
16-
sw-srv25 (id: 30)
17-
sw-srv24 (id: 29)
18-
sw-srv23 (id: 28)
19-
sw-srv22 (id: 27)
20-
sw-srv21 (id: 26)
21-
sw-srv20 (id: 25)
22-
sw-srv19 (id: 24)
23-
sw-srv18 (id: 23)
24-
sw-srv17 (id: 22)
25-
sw-srv16 (id: 21)
26-
sw-srv15 (id: 20)
27-
sw-srv14 (id: 19)
28-
sw-srv13 (id: 18)
29-
sw-srv12 (id: 17)
30-
sw-srv11 (id: 16)
31-
sw-srv10 (id: 15)
32-
sw-srv9 (id: 14)
33-
sw-srv8 (id: 13)
34-
sw-srv7 (id: 12)
35-
sw-srv6 (id: 11)
36-
sw-srv5 (id: 10)
37-
sw-srv4 (id: 9)
38-
sw-srv3 (id: 8)
39-
sw-srv2 (id: 7)
4010
sw-srv1 (id: 6)
4111
sw-srv0 (id: 5)
4212
```
@@ -51,8 +21,10 @@ $ docker run --privileged --network container:sw --name vs -d docker-sonic-vs
5121

5222
```
5323
$ docker exec -it vs bash
54-
root@2e9b5c2dc2a2:/# ifconfig Ethernet0 10.0.0.0/31 up
55-
root@2e9b5c2dc2a2:/# ifconfig Ethernet4 10.0.0.2/31 up
24+
root@2e9b5c2dc2a2:/# config interface ip add Ethernet0 10.0.0.0/31
25+
root@2e9b5c2dc2a2:/# config interface ip add Ethernet4 10.0.0.2/31
26+
root@2e9b5c2dc2a2:/# config interface startup Ethernet0
27+
root@2e9b5c2dc2a2:/# config interface startup Ethernet4
5628
```
5729

5830
4. Setup IP in the server network namespace

platform/vs/create_vnet.sh

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
#!/bin/bash
1+
#!/bin/bash -e
2+
3+
usage() {
4+
echo "Usage: $0 [-n <int>] swname" 1>&2
5+
exit 1
6+
}
7+
8+
SERVERS=2
9+
10+
while getopts ":n:" opt; do
11+
case $opt in
12+
n)
13+
SERVERS=$((OPTARG))
14+
;;
15+
*)
16+
usage
17+
;;
18+
esac
19+
done
20+
21+
shift $((OPTIND-1))
222

323
SWNAME=$1
424

525
pid=$(docker inspect --format '{{.State.Pid}}' $SWNAME)
626

727
echo Seting up servers
828

9-
SERVERS=31
1029

11-
for srv in `seq 0 $SERVERS`; do
30+
for srv in `seq 0 $((SERVERS-1))`; do
1231

1332
SRV="$SWNAME-srv$srv"
1433

@@ -24,9 +43,10 @@ for srv in `seq 0 $SERVERS`; do
2443

2544
IF="eth$((srv+1))"
2645

27-
ip link add ${SRV}eth0 type veth peer name $IF
46+
ip link add ${SRV}eth0 type veth peer name $SWNAME-$IF
2847
ip link set ${SRV}eth0 netns $SRV
29-
ip link set $IF netns ${pid}
48+
ip link set $SWNAME-$IF netns ${pid}
49+
nsenter -t $pid -n ip link set dev $SWNAME-$IF name $IF
3050

3151
echo "Bring ${SRV}eth0 up"
3252
$NSS ip link set dev ${SRV}eth0 name eth0

platform/vs/docker-sonic-vs/start.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ HWSKU=Force10-S6000
77

88
ln -sf /usr/share/sonic/device/$PLATFORM/$HWSKU /usr/share/sonic/hwsku
99

10+
pushd /usr/share/sonic/hwsku
11+
12+
# filter available front panel ports in lanemap.ini
13+
[ -f lanemap.ini.orig ] || cp lanemap.ini lanemap.ini.orig
14+
for p in $(ip link show | grep -oE "eth[0-9]+" | grep -v eth0); do
15+
grep ^$p: lanemap.ini.orig
16+
done > lanemap.ini
17+
18+
# filter available sonic front panel ports in port_config.ini
19+
[ -f port_config.ini.orig ] || cp port_config.ini port_config.ini.orig
20+
grep ^# port_config.ini.orig > port_config.ini
21+
for lanes in $(awk -F ':' '{print $2}' lanemap.ini); do
22+
grep -E "\s$lanes\s" port_config.ini.orig
23+
done >> port_config.ini
24+
25+
popd
26+
1027
[ -d /etc/sonic ] || mkdir -p /etc/sonic
1128

1229
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
@@ -17,7 +34,7 @@ if [ -f /etc/sonic/config_db.json ]; then
1734
mv /tmp/config_db.json /etc/sonic/config_db.json
1835
else
1936
# generate and merge buffers configuration into config file
20-
sonic-cfggen -t /usr/share/sonic/hwsku/buffers.json.j2 > /tmp/buffers.json
37+
sonic-cfggen -k $HWSKU -p /usr/share/sonic/hwsku/port_config.ini -t /usr/share/sonic/hwsku/buffers.json.j2 > /tmp/buffers.json
2138
sonic-cfggen -j /etc/sonic/init_cfg.json -t /usr/share/sonic/hwsku/qos.json.j2 > /tmp/qos.json
2239
sonic-cfggen -p /usr/share/sonic/hwsku/port_config.ini -k $HWSKU --print-data > /tmp/ports.json
2340
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

0 commit comments

Comments
 (0)