Skip to content

Commit

Permalink
[files]: add topology service
Browse files Browse the repository at this point in the history
* add script to configure virtual switch internal topology
* create service to manage topology
* install topology service in sonic_debian_extension

Signed-off-by: Lawrence Lee <t-lale@microsoft.com>
  • Loading branch information
Lawrence Lee committed Aug 2, 2019
1 parent ba7b7e0 commit bf7b16d
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
7 changes: 7 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.service $FILESYSTEM_ROOT/etc/sy
echo "hostname-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $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 %}

# 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
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
Requires=namespace@0.service namespace@1.service namespace@2.service namespace@3.service namespace@4.service namespace@5.service
After=namespace@0.service namespace@1.service namespace@2.service namespace@3.service namespace@4.service namespace@5.service
Before=database@0.service database@1.service database@2.service database@3.service database@4.service database@5.service
PartOf=namespace@0.service namespace@1.service namespace@2.service namespace@3.service namespace@4.service namespace@5.service

[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 () {
# Move external links into assigned frontend namespaces
# eth0 - eth15: namespace2
# eth16 - eth31: namespace3
# eth32 - eth47: namespace4
# eth48 - eth63: namespace5
for NS in `seq 2 5`; do
for NUM in `seq 1 16`; do
ORIG="eth$((16 * $(($NS - 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 namespace$NS
sudo ip netns exec namespace$NS ip link set $TEMP name $NEW # rename to final interface name
sudo ip netns exec namespace$NS 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 namespace$BACKEND
ip link set dev $TEMP_FRONT netns namespace$FRONTEND

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

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

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

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

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

0 comments on commit bf7b16d

Please # to comment.