Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building multi-asic component #3856

Merged
merged 27 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b2d1f3
[platform/vs]: Update README
May 23, 2019
342c1f0
[build systemd]: support multi-ASIC build
Jul 11, 2019
70a7d75
[build][rules][build_templates][platform/vs]: add network namespace/m…
Jun 5, 2019
262f37e
[files]: add topology service
Jun 14, 2019
dbf7ec0
[multi-asic build]: address review comments
Aug 2, 2019
d007d29
[systemd-generator]: Get number of asics in the platform from
SuvarnaMeenakshi Dec 5, 2019
90a76bf
[docker_image_ctl]: Make changes to remove namespace docker
SuvarnaMeenakshi Dec 6, 2019
5566d9b
[docker_image_ctl]: minor fixes
SuvarnaMeenakshi Dec 6, 2019
b482c2e
[namespace]: Remove namespace docker
SuvarnaMeenakshi Dec 6, 2019
9c058b4
[systemd-generator]: Minor Fix
SuvarnaMeenakshi Dec 6, 2019
9602cdc
[sonic.xml]: Add a new xml file for multiasic vs platform.
SuvarnaMeenakshi Dec 11, 2019
0d03c90
[systemd_generator]: Added check to include aboot_platform string.
SuvarnaMeenakshi Dec 12, 2019
1bd3de4
[sonic_multiasic.xml]:Increased cpu and memory usage.
SuvarnaMeenakshi Dec 12, 2019
f827f0a
[docker_img_ctl]: Minor fix as per review comment
SuvarnaMeenakshi Dec 12, 2019
f22ed0f
[systemd-sonic-generator]: Added check to start topology service
SuvarnaMeenakshi Dec 12, 2019
d054739
[device/virtual]: Review comments fix and added new demo multi-asic V…
SuvarnaMeenakshi Jan 2, 2020
1082c49
[topology.service]: Fix dependency and minor fix in the script file.
SuvarnaMeenakshi Jan 2, 2020
a1bf9c9
[systemd-generator]: Add code to dynamically change dependency
SuvarnaMeenakshi Jan 3, 2020
8cb203d
[sonic.xml]: Minor fix in image path
SuvarnaMeenakshi Jan 3, 2020
4387c15
[systemd-generator]: Corrected dynamic systemd service dependency update
SuvarnaMeenakshi Jan 9, 2020
3554e97
[topology.sh]: Fix review comment
SuvarnaMeenakshi Jan 9, 2020
828c7dc
[systemd-geenrator]: minor correction to dynamic systemd dependency u…
SuvarnaMeenakshi Jan 9, 2020
2228821
[rules/docker-sflow.mk]: remove --net option as it is added in
SuvarnaMeenakshi Jan 14, 2020
e08a838
[gitginore]: deleted namespace docker related file from .gitignore.
SuvarnaMeenakshi Jan 14, 2020
e2020a5
[sonic.xml]: Minor correction in vs name
SuvarnaMeenakshi Jan 15, 2020
a3e42bb
[slave.mk]: review comment fix to remove retrying to build based.
SuvarnaMeenakshi Jan 23, 2020
7379938
[docker_image_ctl]: Fix spacing
SuvarnaMeenakshi Jan 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dockers/docker-fpm-frr/Dockerfile
dockers/docker-fpm-gobgp/Dockerfile
dockers/docker-fpm-quagga/Dockerfile
dockers/docker-lldp-sv2/Dockerfile
dockers/docker-namespace/Dockerfile
lguohan marked this conversation as resolved.
Show resolved Hide resolved
dockers/docker-orchagent/Dockerfile
dockers/docker-platform-monitor/Dockerfile
dockers/docker-router-advertiser/Dockerfile
Expand Down
95 changes: 73 additions & 22 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#!/bin/bash

# single instance containers are still supported (even though it might not look like it)
# if no instance number is passed to this script, $DEV will simply be unset, resulting in docker
# commands being sent to the base container name. E.g. `docker start database$DEV` simply starts
# the container `database` if no instance number is passed since `$DEV` is not defined


{%- if docker_container_name == "database" %}
link_namespace() {
# Makes namespace of a docker container available in
# /var/run/netns so it can be managed with iproute2

mkdir -p /var/run/netns
PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$1")"

if `ip netns | grep --quiet "{{docker_container_name}}$1"`; then # namespace exists
lguohan marked this conversation as resolved.
Show resolved Hide resolved
if [ $(readlink -f /var/run/netns/ns$1) = $(readlink -f /proc/$PID/ns/net) ]; then # namespace is correctly linked
return 0
else # if it's incorrectly linked remove it
ip netns delete "{{docker_container_name}}$1"
fi
fi

ln -s /proc/$PID/ns/net /var/run/netns/asic$1
SuvarnaMeenakshi marked this conversation as resolved.
Show resolved Hide resolved
}
{%- endif %}

function getMountPoint()
{
echo $1 | python -c "import sys, json, os; mnts = [x for x in json.load(sys.stdin)[0]['Mounts'] if x['Destination'] == '/usr/share/sonic/hwsku']; print '' if len(mnts) == 0 else os.path.basename(mnts[0]['Source'])" 2>/dev/null
Expand All @@ -10,7 +36,7 @@ function updateHostName()
HOSTS=/etc/hosts
HOSTS_TMP=/etc/hosts.tmp

EXEC="docker exec -i {{docker_container_name}} bash -c"
EXEC="docker exec -i {{docker_container_name}}$DEV bash -c"

NEW_HOSTNAME="$1"
HOSTNAME=`$EXEC "hostname"`
Expand All @@ -25,7 +51,7 @@ function updateHostName()
# add entry with new hostname
$EXEC "echo -e \"127.0.0.1\t$NEW_HOSTNAME\" >> $HOSTS_TMP"

echo "Set hostname in {{docker_container_name}} container"
echo "Set hostname in {{docker_container_name}}$DEV container"
$EXEC "hostname '$NEW_HOSTNAME'"
$EXEC "cat $HOSTS_TMP > $HOSTS"
$EXEC "rm -f $HOSTS_TMP"
Expand Down Expand Up @@ -139,6 +165,9 @@ function preStartAction()
function postStartAction()
{
{%- if docker_container_name == "database" %}
if [ "$DEV" ]; then
link_namespace $DEV
fi
# Wait until redis starts
/usr/bin/docker exec database ping_pong_db_insts
if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then
Expand Down Expand Up @@ -200,7 +229,7 @@ start() {
HOSTNAME=`hostname`
fi

DOCKERCHECK=`docker inspect --type container {{docker_container_name}} 2>/dev/null`
DOCKERCHECK=`docker inspect --type container {{docker_container_name}}$DEV 2>/dev/null`
if [ "$?" -eq "0" ]; then
{%- if docker_container_name == "database" %}
DOCKERMOUNT=""
Expand All @@ -209,39 +238,52 @@ start() {
{%- endif %}
if [ x"$DOCKERMOUNT" == x"$HWSKU" ]; then
{%- if docker_container_name == "database" %}
echo "Starting existing {{docker_container_name}} container"
echo "Starting existing {{docker_container_name}}$DEV container"
{%- else %}
echo "Starting existing {{docker_container_name}} container with HWSKU $HWSKU"
echo "Starting existing {{docker_container_name}}$DEV container with HWSKU $HWSKU"
{%- endif %}
preStartAction
docker start {{docker_container_name}}
CURRENT_HOSTNAME="$(docker exec {{docker_container_name}} hostname)"
docker start {{docker_container_name}}$DEV
postStartAction
CURRENT_HOSTNAME="$(docker exec {{docker_container_name}}$DEV hostname)"
if [ x"$HOSTNAME" != x"$CURRENT_HOSTNAME" ]; then
updateHostName "$HOSTNAME"
fi
postStartAction
updateHostName "$HOSTNAME"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late comment.
Why it is needed to call updateHostName even though it is called in the condition right above?

exit $?
fi

# docker created with a different HWSKU, remove and recreate
echo "Removing obsolete {{docker_container_name}} container with HWSKU $DOCKERMOUNT"
docker rm -f {{docker_container_name}}
echo "Removing obsolete {{docker_container_name}}$DEV container with HWSKU $DOCKERMOUNT"
docker rm -f {{docker_container_name}}$DEV
fi

{%- if docker_container_name == "database" %}
echo "Creating new {{docker_container_name}} container"
{%- if docker_container_name == "database" %}
echo "Creating new {{docker_container_name}}$DEV container"
# if database_config exists in old_config, use it; otherwise use the default one in new image
if [ -f /etc/sonic/old_config/database_config.json ]; then
echo "Use database_config.json from old system..."
mv /etc/sonic/old_config/database_config.json /etc/sonic/
fi
{%- else %}
echo "Creating new {{docker_container_name}} container with HWSKU $HWSKU"
{%- endif %}
{%- else %}
echo "Creating new {{docker_container_name}}$DEV container with HWSKU $HWSKU"
{%- endif %}

if [ -z "$DEV" ]; then
NET="host"
else
{%- if docker_container_name == "database" %}
NET="bridge"
lguohan marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are using tab, but other places you are using space in the same file. can you change to space and make the spacing consistent acrosss the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spacing

{%- else %}
NET="container:database$DEV"
{%- endif %}
fi

{%- if sonic_asic_platform == "mellanox" %}
# TODO: Mellanox will remove the --tmpfs exception after SDK socket path changed in new SDK version
{%- endif %}
docker create {{docker_image_run_opt}} \
--net=$NET \
{%- if install_debug_image == "y" %}
-v /src:/src:ro -v /debug:/debug:rw \
{%- endif %}
Expand Down Expand Up @@ -270,33 +312,42 @@ start() {
--tmpfs /tmp \
{%- endif %}
--tmpfs /var/tmp \
--hostname "$HOSTNAME" \
--name={{docker_container_name}} {{docker_image_name}}:latest || {
--name={{docker_container_name}}$DEV {{docker_image_name}}:latest || {
echo "Failed to docker run" >&1
exit 4
}

preStartAction
docker start {{docker_container_name}}
postStartAction
updateHostName "$HOSTNAME"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

}

wait() {
docker wait {{docker_container_name}}
docker wait {{docker_container_name}}$DEV
}

stop() {
docker stop {{docker_container_name}}
docker stop {{docker_container_name}}$DEV
{%- if docker_container_name == "database" %}
ip netns delete "asic$DEV"
{%- endif %}
}

OP=$1
DEV=$2 # namespace/device number to operate on

case "$1" in
start|wait|stop|updateHostName)
start|wait|stop)
$1
;;
updateHostName)
cmd=$1
shift
shift 2
$cmd $@
;;
*)
echo "Usage: $0 {start|wait|stop|updateHostName new_hostname}"
echo "Usage: $0 {start namespace(optional)|wait namespace(optional)|stop namespace(optional)|updateHostName namespace(optional) new_hostname}"
exit 1
;;
esac
14 changes: 14 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/
# Copy miscellaneous scripts
sudo cp $IMAGE_CONFIGS/misc/docker-wait-any $FILESYSTEM_ROOT/usr/bin/

# Copy internal topology configuration scripts
{%- if sonic_asic_platform == "vs" %}
sudo cp $IMAGE_CONFIGS/topology/topology.service $FILESYSTEM_ROOT/etc/systemd/system/
echo "topology.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/topology/topology.sh $FILESYSTEM_ROOT/usr/bin
{%- endif %}
lguohan marked this conversation as resolved.
Show resolved Hide resolved

# Copy updategraph script and service file
j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service
sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/
Expand Down Expand Up @@ -354,6 +361,13 @@ sudo cp {{script}} $FILESYSTEM_ROOT/usr/bin/
{% for service in installer_services.split(' ') -%}
if [ -f {{service}} ]; then
sudo cp {{service}} $FILESYSTEM_ROOT/etc/systemd/system/

{% if "@" in service %}
MULTI_INSTANCE="{{service}}"
SINGLE_INSTANCE=${MULTI_INSTANCE/"@"}
sudo cp $SINGLE_INSTANCE $FILESYSTEM_ROOT/etc/systemd/system/
{% endif %}

echo "{{service}}" | sudo tee -a $GENERATED_SERVICE_FILE
fi
{% endfor %}
Expand Down
17 changes: 17 additions & 0 deletions files/image_config/topology/topology.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Internal topology service
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hard code numbers here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to dynamically update dependency based on number of asics

[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

[Service]
Type=oneshot
User=root
RemainAfterExit=yes
ExecStart=/usr/bin/topology.sh start
ExecStop=/usr/bin/topology.sh stop

[Install]
WantedBy=multi-user.target

75 changes: 75 additions & 0 deletions files/image_config/topology/topology.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

start () {
lguohan marked this conversation as resolved.
Show resolved Hide resolved
# Move external links into assigned frontend namespaces
# eth0 - eth15: asic2
# eth16 - eth31: asic3
# eth32 - eth47: asic4
# eth48 - eth63: asic5
for ASIC in `seq 2 5`; do
lguohan marked this conversation as resolved.
Show resolved Hide resolved
for NUM in `seq 1 16`; do
ORIG="eth$((16 * $(($ASIC - 2)) + $NUM - 1))"
TEMP="ethTemp999"
NEW="eth$(($NUM + 16))"
ip link set dev $ORIG down
ip link set dev $ORIG name $TEMP # rename to prevent conflicts before renaming in new namespace
ip link set dev $TEMP netns asic$ASIC
sudo ip netns exec asic$ASIC ip link set $TEMP name $NEW # rename to final interface name
sudo ip netns exec asic$ASIC ip link set $NEW up
done
done

# Connect all backend namespaces to frontend namespaces
for BACKEND in `seq 0 1`; do
for FRONTEND in `seq 2 5`; do
for LINK in `seq 1 8`; do
BACK_NAME="eth$((8 * $(($FRONTEND - 2)) + $LINK))"
FRONT_NAME="eth$((8 * $BACKEND + $LINK))"
TEMP_BACK="ethBack999"
TEMP_FRONT="ethFront999"

ip link add $TEMP_BACK type veth peer name $TEMP_FRONT # temporary name to prevent conflicts between interfaces
ip link set dev $TEMP_BACK netns asic$BACKEND
ip link set dev $TEMP_FRONT netns asic$FRONTEND

sudo ip netns exec asic$BACKEND ip link set $TEMP_BACK name $BACK_NAME
sudo ip netns exec asic$FRONTEND ip link set $TEMP_FRONT name $FRONT_NAME

sudo ip netns exec asic$BACKEND ip link set $BACK_NAME up
sudo ip netns exec asic$FRONTEND ip link set $FRONT_NAME up
done
done
done
}

stop() {
for ASIC in `seq 2 5`; do
for NUM in `seq 1 16`; do
TEMP="eth999"
OLD="eth$(($NUM + 16))"
NAME="eth$((16 * $(($ASIC - 2)) + $NUM - 1))"
sudo ip netns exec asic$ASIC ip link set dev $OLD down
sudo ip netns exec asic$ASIC ip link set dev $OLD name $TEMP
sudo ip netns exec asic$ASIC ip link set dev $TEMP netns 1
ip link set dev $TEMP name $NAME
ip link set dev $NAME up
done
done

for ASIC in `seq 0 1`; do
for NUM in `seq 1 32`; do
sudo ip netns exec asic$ASIC ip link set dev eth$NUM down
sudo ip netns exec asic$ASIC ip link delete dev eth$NUM
done
done
}

case "$1" in
start|stop)
$1
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac

2 changes: 1 addition & 1 deletion platform/template/docker-syncd-base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif


$(DOCKER_SYNCD_BASE)_CONTAINER_NAME = syncd
$(DOCKER_SYNCD_BASE)_RUN_OPT += --net=host --privileged -t
$(DOCKER_SYNCD_BASE)_RUN_OPT += --privileged -t
$(DOCKER_SYNCD_BASE)_RUN_OPT += -v /host/machine.conf:/etc/machine.conf
$(DOCKER_SYNCD_BASE)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro

35 changes: 23 additions & 12 deletions platform/vs/README.vsvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo apt-get install libvirt-clients qemu-kvm libvirt-bin
2. Create SONiC VM

```
$ virsh
$ sudo virsh
Welcome to virsh, the virtualization interactive terminal.

Type: 'help' for help with commands
Expand All @@ -22,14 +22,25 @@ Domain sonic created from sonic.xml
virsh #
```

2. Connect SONiC VM via console

```
$ telnet 127.0.0.1 7000
```

3. Connect SONiC VM via SSH

```
$ ssh -p 3040 [email protected]
```
3. Access virtual switch:

1. Connect SONiC VM via console
```
$ telnet 127.0.0.1 7000
```

OR

2. Connect SONiC VM via SSH

1. Connect via console (see 3.1 above)

2. Request a new DHCP address
```
sudo dhclient -v
```

3. Connect via SSH
```
$ ssh -p 3040 [email protected]
```
Loading