Skip to content

Commit a878f97

Browse files
T2-VOQ: VS Support
1 parent 2e24b35 commit a878f97

File tree

20 files changed

+471
-32
lines changed

20 files changed

+471
-32
lines changed

files/build_templates/docker_image_ctl.j2

+21-16
Original file line numberDiff line numberDiff line change
@@ -376,27 +376,32 @@ start() {
376376

377377
DOCKERCHECK=`docker inspect --type container ${DOCKERNAME} 2>/dev/null`
378378
if [ "$?" -eq "0" ]; then
379-
{%- if docker_container_name == "database" %}
380-
DOCKERMOUNT=""
379+
{%- if docker_container_name == "database" and sonic_asic_platform == "vs" %}
380+
echo "Removing existing ${DOCKERNAME} container"
381+
docker rm -f ${DOCKERNAME}
381382
{%- else %}
382-
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
383-
{%- endif %}
384-
if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then
385-
preStartAction
386383
{%- if docker_container_name == "database" %}
387-
echo "Starting existing ${DOCKERNAME} container"
388-
docker start ${DOCKERNAME}
384+
DOCKERMOUNT=""
389385
{%- else %}
390-
echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU"
391-
/usr/local/bin/container start ${DOCKERNAME}
386+
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
392387
{%- endif %}
393-
postStartAction
394-
exit $?
395-
fi
388+
if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then
389+
preStartAction
390+
{%- if docker_container_name == "database" %}
391+
echo "Starting existing ${DOCKERNAME} container"
392+
docker start ${DOCKERNAME}
393+
{%- else %}
394+
echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU"
395+
/usr/local/bin/container start ${DOCKERNAME}
396+
{%- endif %}
397+
postStartAction
398+
exit $?
399+
fi
396400

397-
# docker created with a different HWSKU, remove and recreate
398-
echo "Removing obsolete ${DOCKERNAME} container with HWSKU $DOCKERMOUNT"
399-
docker rm -f ${DOCKERNAME}
401+
# docker created with a different HWSKU, remove and recreate
402+
echo "Removing obsolete ${DOCKERNAME} container with HWSKU $DOCKERMOUNT"
403+
docker rm -f ${DOCKERNAME}
404+
{%- endif %}
400405
fi
401406

402407
{%- if docker_container_name == "database" %}

files/image_config/topology/topology.service

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ ExecStart=/usr/bin/topology.sh start
1212
ExecStop=/usr/bin/topology.sh stop
1313

1414
[Install]
15-
WantedBy=multi-user.target
16-
15+
WantedBy=sonic.target

files/image_config/topology/topology.sh

+91-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,99 @@ get_hwsku() {
2222
echo "${HWSKU}"
2323
}
2424

25+
bind_ports_to_ns() {
26+
PLATFORM="$1"
27+
HWSKU="$2"
28+
BIND="$3"
29+
30+
# Check if the directory exists
31+
if [[ ! -d "/usr/share/sonic/device/$PLATFORM/$HWSKU" ]]; then
32+
echo "Directory /usr/share/sonic/device/$PLATFORM/$HWSKU does not exist"
33+
exit 1
34+
fi
35+
36+
# Read NUM_ASIC from asic.conf file
37+
asic_conf="/usr/share/sonic/device/$PLATFORM/asic.conf"
38+
if [[ ! -f "$asic_conf" ]]; then
39+
echo "Error: $asic_conf file not found"
40+
exit 1
41+
fi
42+
43+
# Read NUM_ASIC from asic.conf file
44+
num_asic=$(awk -F "=" '/^NUM_ASIC=/ {print $2}' "$asic_conf")
45+
if [[ -z $num_asic ]]; then
46+
echo "NUM_ASIC not found in $asic_conf"
47+
exit 1
48+
fi
49+
50+
for ((asic_num = 0; asic_num < num_asic; asic_num++)); do
51+
echo "Processing $PLATFORM/$HWSKU/$asic_num"
52+
asic_dir="/usr/share/sonic/device/$PLATFORM/$HWSKU/$asic_num"
53+
54+
# Check if the directory exists for the ASIC number
55+
if [[ ! -d "$asic_dir" ]]; then
56+
echo "Directory $asic_dir does not exist"
57+
exit 1
58+
fi
59+
60+
lanemap_ini="$asic_dir/lanemap.ini"
61+
62+
if [[ ! -f "$lanemap_ini" ]]; then
63+
echo "lanemap.ini not found in $asic_dir"
64+
exit 1
65+
fi
66+
67+
# Loop through each line of lanemap.ini
68+
while IFS= read -r line; do
69+
# Extract interface before ":"
70+
intf=$(echo "$line" | cut -d ":" -f 1)
71+
if [[ $BIND == true ]]; then
72+
echo "Moving interface $intf to asic$asic_num"
73+
if [[ $intf == "Cpu0" ]]; then
74+
# Extract the numeric part of the interface name
75+
num="${prev#eth}"
76+
# Increment the numeric part
77+
((num++))
78+
# Construct the new interface name
79+
cur="eth$num"
80+
echo "Renaming $cur to $intf"
81+
ip link sev dev $cur down
82+
ip link set dev $cur name $intf
83+
fi
84+
ip link set dev $intf netns asic$asic_num
85+
sudo ip netns exec asic$asic_num ip link set dev $intf mtu 9100
86+
sudo ip netns exec asic$asic_num ip link set $intf up
87+
else
88+
echo "Moving interface $intf back to default ns"
89+
sudo ip netns exec asic$asic_num ip link set dev $intf netns 1
90+
if [[ $intf == "Cpu0" ]]; then
91+
# Extract the numeric part of the interface name
92+
num="${prev#eth}"
93+
# Increment the numeric part
94+
((num++))
95+
# Construct the new interface name
96+
cur="eth$num"
97+
echo "Renaming $intf to $cur"
98+
ip link set dev $intf down
99+
ip link set dev $intf name $cur
100+
ip link set dev $cur up
101+
fi
102+
fi
103+
prev=$intf
104+
done < "$lanemap_ini"
105+
done
106+
exit 0 # Exit script with success
107+
}
108+
109+
25110
start() {
26111
TOPOLOGY_SCRIPT="topology.sh"
27112
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
28113
HWSKU=`get_hwsku`
29-
if [[ $HWSKU != "" ]]; then
114+
if [[ $HWSKU == "msft_"* ]]; then
30115
/usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start
116+
elif [[ $HWSKU != "" ]]; then
117+
bind_ports_to_ns "$PLATFORM" "$HWSKU" true
31118
else
32119
echo "Failed to get HWSKU"
33120
exit 1
@@ -38,8 +125,10 @@ stop() {
38125
TOPOLOGY_SCRIPT="topology.sh"
39126
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
40127
HWSKU=`get_hwsku`
41-
if [[ $HWSKU != "" ]]; then
128+
if [[ $HWSKU == "msft_"* ]]; then
42129
/usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop
130+
elif [[ $HWSKU != "" ]]; then
131+
bind_ports_to_ns "$PLATFORM" "$HWSKU" false
43132
else
44133
echo "Failed to get HWSKU"
45134
exit 1

platform/vs/kvm-image.mk

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
SONIC_KVM_IMAGE = sonic-vs.img.gz
44
$(SONIC_KVM_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
5+
$(SONIC_KVM_IMAGE)_LAZY_INSTALLS += $(VS_PLATFORM_MODULE)
56
$(SONIC_KVM_IMAGE)_MACHINE = vs
67
$(SONIC_KVM_IMAGE)_IMAGE_TYPE = kvm
78
ifeq ($(INSTALL_DEBUG_TOOLS),y)

platform/vs/one-image.mk

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SONIC_ONE_IMAGE = sonic-vs.bin
44
$(SONIC_ONE_IMAGE)_MACHINE = vs
55
$(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie
66
$(SONIC_ONE_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
7+
$(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(VS_PLATFORM_MODULE)
78
ifeq ($(INSTALL_DEBUG_TOOLS),y)
89
$(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES)
910
$(SONIC_ONE_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES))

platform/vs/platform-modules-vs.mk

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# VS Platform modules
2+
3+
VS_PLATFORM_MODULE_VERSION = 1.0
4+
5+
export VS_PLATFORM_MODULE_VERSION
6+
7+
VS_PLATFORM_MODULE = sonic-platform-vs_$(VS_PLATFORM_MODULE_VERSION)_amd64.deb
8+
$(VS_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-vs
9+
$(VS_PLATFORM_MODULE)_DEPENDS =
10+
$(VS_PLATFORM_MODULE)_PLATFORM = x86_64-kvm_x86_64-r0
11+
SONIC_DPKG_DEBS += $(VS_PLATFORM_MODULE)

platform/vs/rules.mk

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include $(PLATFORM_PATH)/docker-gbsyncd-vs.mk
66
include $(PLATFORM_PATH)/docker-ptf.mk
77
include $(PLATFORM_PATH)/docker-ptf-sai.mk
88
include $(PLATFORM_PATH)/libsaithrift-dev.mk
9+
include $(PLATFORM_PATH)/platform-modules-vs.mk
910
include $(PLATFORM_PATH)/one-image.mk
1011
include $(PLATFORM_PATH)/onie.mk
1112
include $(PLATFORM_PATH)/kvm-image.mk
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sonic-platform-vs (1.0) UNRELEASED; urgency=low
2+
3+
* Initial release of the sonic-platform-vs package.
4+
* This package provides platform-specific modules for SONiC on virtualized VS platforms.
5+
* Included modules:
6+
- Chassis module
7+
* This package is part of the initial release of SONiC for VS platforms.
8+
9+
-- Deepak Singhal <[email protected]> Fri, 26 Feb 2024 12:00:00 +0000
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Source: sonic-platform-vs
2+
Section: main
3+
Priority: extra
4+
Maintainer: Deepak Singhal <[email protected]>
5+
Build-Depends: debhelper (>= 9), bzip2
6+
Standards-Version: 3.9.3
7+
8+
Package: sonic-platform-vs
9+
Architecture: amd64
10+
Description: Sonic VS platform Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/make -f
2+
# -*- makefile -*-
3+
# Sample debian/rules that uses debhelper.
4+
# As a special exception, when this file is copied by dh-make into a
5+
# dh-make output file, you may use that output file without restriction.
6+
7+
include /usr/share/dpkg/pkg-info.mk
8+
9+
# Uncomment this to turn on verbose mode.
10+
export DH_VERBOSE=1
11+
12+
PYTHON ?= python3
13+
PACKAGE_PRE_NAME := sonic-platform-vs
14+
SRC_DIR:= $(shell pwd)
15+
16+
%:
17+
dh $@ --with python3 --buildsystem=pybuild
18+
19+
clean:
20+
dh_testdir
21+
dh_testroot
22+
dh_clean
23+
24+
build:
25+
# Nothing to do
26+
27+
28+
binary: binary-arch binary-indep
29+
# Nothing to do
30+
31+
binary-arch:
32+
# Nothing to do
33+
34+
binary-indep:
35+
# temporary commented out
36+
# dh_testdir
37+
dh_installdirs
38+
39+
# Custom package commands
40+
$(PYTHON) setup.py install --root=$(SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb;
41+
42+
# Resuming debhelper scripts
43+
dh_testroot
44+
dh_install
45+
dh_installchangelogs
46+
dh_installdocs
47+
dh_systemd_enable
48+
dh_installinit
49+
dh_systemd_start
50+
dh_link
51+
dh_fixperms
52+
dh_compress
53+
dh_strip
54+
dh_installdeb
55+
dh_gencontrol
56+
dh_md5sums
57+
dh_builddeb
58+
.PHONY: build binary binary-arch binary-indep clean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
from setuptools import setup
6+
os.listdir
7+
8+
setup(
9+
name='sonic_platform',
10+
version='1.0',
11+
description='Module to initialize VS platforms',
12+
13+
packages=['sonic_platform'],
14+
package_dir={'sonic_platform': 'sonic_platform'}
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__all__ = ["platform"]
2+
from sonic_platform import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Description: Module contains the definitions of SONiC platform APIs
2+
# which provide the chassis specific details
3+
#
4+
# Copyright (c) 2019, Nokia
5+
# All rights reserved.
6+
#
7+
8+
try:
9+
from sonic_platform_base.chassis_base import ChassisBase
10+
from sonic_platform_base.module_base import ModuleBase
11+
import os
12+
import json
13+
import threading
14+
15+
except ImportError as e:
16+
raise ImportError(str(e) + "- required module not found")
17+
18+
19+
class Chassis(ChassisBase):
20+
"""
21+
VS Platform-specific Chassis class
22+
"""
23+
def __init__(self):
24+
ChassisBase.__init__(self)
25+
self.metadata_file = '/etc/sonic/vs_chassis_metadata.json'
26+
self.metadata = self._read_metadata()
27+
28+
def _read_metadata(self):
29+
metadata = {}
30+
if os.path.exists(self.metadata_file):
31+
with open(self.metadata_file, 'r') as f:
32+
metadata = json.load(f)
33+
else:
34+
raise FileNotFoundError("Metadata file {} not found".format(self.metadata_file))
35+
return metadata
36+
37+
def get_supervisor_slot(self):
38+
if 'sup_slot_num' not in self.metadata:
39+
raise KeyError("sup_slot_num not found in Metadata file {}".format(self.metadata_file))
40+
return self.metadata['sup_slot_num']
41+
42+
def get_linecard_slot(self):
43+
if 'lc_slot_num' not in self.metadata:
44+
raise KeyError("lc_slot_num not found in Metadata file {}".format(self.metadata_file))
45+
return self.metadata['lc_slot_num']
46+
47+
def get_my_slot(self):
48+
if 'is_supervisor' not in self.metadata or 'is_linecard' not in self.metadata:
49+
raise KeyError("is_supervisor or is_linecard not found in metadata file {}".format(self.metadata_file))
50+
51+
if self.metadata['is_supervisor']:
52+
return self.get_supervisor_slot()
53+
elif self.metadata['is_linecard']:
54+
return self.get_linecard_slot()
55+
else:
56+
raise ValueError("Invalid configuration: Neither supervisor nor line card")

0 commit comments

Comments
 (0)