Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
39 changes: 22 additions & 17 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -404,28 +404,33 @@ start() {

DOCKERCHECK=`docker inspect --type container ${DOCKERNAME} 2>/dev/null`
if [ "$?" -eq "0" ]; then
{%- if docker_container_name == "database" %}
DOCKERMOUNT=""
{%- if docker_container_name == "database" and sonic_asic_platform == "vs" %}
echo "Removing existing ${DOCKERNAME} container"
docker rm -f ${DOCKERNAME}
{%- else %}
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
{%- endif %}
if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then
CONTAINER_EXISTS="yes"
preStartAction
{%- if docker_container_name == "database" %}
echo "Starting existing ${DOCKERNAME} container"
docker start ${DOCKERNAME}
DOCKERMOUNT=""
{%- else %}
echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU"
/usr/local/bin/container start ${DOCKERNAME}
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
{%- endif %}
postStartAction
exit $?
fi
if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then
CONTAINER_EXISTS="yes"
preStartAction
{%- if docker_container_name == "database" %}
echo "Starting existing ${DOCKERNAME} container"
docker start ${DOCKERNAME}
{%- else %}
echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU"
/usr/local/bin/container start ${DOCKERNAME}
{%- endif %}
postStartAction
exit $?
fi

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

{%- if docker_container_name == "database" %}
Expand Down
3 changes: 1 addition & 2 deletions files/image_config/topology/topology.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ ExecStart=/usr/bin/topology.sh start
ExecStop=/usr/bin/topology.sh stop

[Install]
WantedBy=multi-user.target

WantedBy=sonic.target
93 changes: 91 additions & 2 deletions files/image_config/topology/topology.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,99 @@ get_hwsku() {
echo "${HWSKU}"
}

bind_ports_to_ns() {
PLATFORM="$1"
HWSKU="$2"
BIND="$3"

# Check if the directory exists
if [[ ! -d "/usr/share/sonic/device/$PLATFORM/$HWSKU" ]]; then
echo "Directory /usr/share/sonic/device/$PLATFORM/$HWSKU does not exist"
exit 1
fi

# Read NUM_ASIC from asic.conf file
asic_conf="/usr/share/sonic/device/$PLATFORM/asic.conf"
if [[ ! -f "$asic_conf" ]]; then
echo "Error: $asic_conf file not found"
exit 1
fi

# Read NUM_ASIC from asic.conf file
num_asic=$(awk -F "=" '/^NUM_ASIC=/ {print $2}' "$asic_conf")
if [[ -z $num_asic ]]; then
echo "NUM_ASIC not found in $asic_conf"
exit 1
fi

for ((asic_num = 0; asic_num < num_asic; asic_num++)); do
echo "Processing $PLATFORM/$HWSKU/$asic_num"
asic_dir="/usr/share/sonic/device/$PLATFORM/$HWSKU/$asic_num"

# Check if the directory exists for the ASIC number
if [[ ! -d "$asic_dir" ]]; then
echo "Directory $asic_dir does not exist"
exit 1
fi

lanemap_ini="$asic_dir/lanemap.ini"

if [[ ! -f "$lanemap_ini" ]]; then
echo "lanemap.ini not found in $asic_dir"
exit 1
fi

# Loop through each line of lanemap.ini
while IFS= read -r line; do
# Extract interface before ":"
intf=$(echo "$line" | cut -d ":" -f 1)
if [[ $BIND == true ]]; then
echo "Moving interface $intf to asic$asic_num"
if [[ $intf == "Cpu0" ]]; then
# Extract the numeric part of the interface name
num="${prev#eth}"
# Increment the numeric part
((num++))
# Construct the new interface name
cur="eth$num"
echo "Renaming $cur to $intf"
ip link sev dev $cur down
ip link set dev $cur name $intf
fi
ip link set dev $intf netns asic$asic_num
sudo ip netns exec asic$asic_num ip link set dev $intf mtu 9100
sudo ip netns exec asic$asic_num ip link set $intf up
else
echo "Moving interface $intf back to default ns"
sudo ip netns exec asic$asic_num ip link set dev $intf netns 1
if [[ $intf == "Cpu0" ]]; then
# Extract the numeric part of the interface name
num="${prev#eth}"
# Increment the numeric part
((num++))
# Construct the new interface name
cur="eth$num"
echo "Renaming $intf to $cur"
ip link set dev $intf down
ip link set dev $intf name $cur
ip link set dev $cur up
fi
fi
prev=$intf
done < "$lanemap_ini"
done
exit 0 # Exit script with success
}


start() {
TOPOLOGY_SCRIPT="topology.sh"
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
HWSKU=`get_hwsku`
if [[ $HWSKU != "" ]]; then
if [[ $HWSKU == "msft_"* ]]; then
/usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start
elif [[ $HWSKU != "" ]]; then
bind_ports_to_ns "$PLATFORM" "$HWSKU" true
else
echo "Failed to get HWSKU"
exit 1
Expand All @@ -38,8 +125,10 @@ stop() {
TOPOLOGY_SCRIPT="topology.sh"
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
HWSKU=`get_hwsku`
if [[ $HWSKU != "" ]]; then
if [[ $HWSKU == "msft_"* ]]; then
/usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop
elif [[ $HWSKU != "" ]]; then
bind_ports_to_ns "$PLATFORM" "$HWSKU" false
else
echo "Failed to get HWSKU"
exit 1
Expand Down
1 change: 1 addition & 0 deletions platform/vs/kvm-image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SONIC_KVM_IMAGE = sonic-vs.img.gz
$(SONIC_KVM_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
$(SONIC_KVM_IMAGE)_LAZY_INSTALLS += $(VS_PLATFORM_MODULE)
$(SONIC_KVM_IMAGE)_MACHINE = vs
$(SONIC_KVM_IMAGE)_IMAGE_TYPE = kvm
ifeq ($(INSTALL_DEBUG_TOOLS),y)
Expand Down
1 change: 1 addition & 0 deletions platform/vs/one-image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SONIC_ONE_IMAGE = sonic-vs.bin
$(SONIC_ONE_IMAGE)_MACHINE = vs
$(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie
$(SONIC_ONE_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
$(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(VS_PLATFORM_MODULE)
ifeq ($(INSTALL_DEBUG_TOOLS),y)
$(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES)
$(SONIC_ONE_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES))
Expand Down
11 changes: 11 additions & 0 deletions platform/vs/platform-modules-vs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# VS Platform modules

VS_PLATFORM_MODULE_VERSION = 1.0

export VS_PLATFORM_MODULE_VERSION

VS_PLATFORM_MODULE = sonic-platform-vs_$(VS_PLATFORM_MODULE_VERSION)_amd64.deb
$(VS_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-vs
$(VS_PLATFORM_MODULE)_DEPENDS =
$(VS_PLATFORM_MODULE)_PLATFORM = x86_64-kvm_x86_64-r0
SONIC_DPKG_DEBS += $(VS_PLATFORM_MODULE)
1 change: 1 addition & 0 deletions platform/vs/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include $(PLATFORM_PATH)/docker-gbsyncd-vs.mk
include $(PLATFORM_PATH)/docker-ptf.mk
include $(PLATFORM_PATH)/docker-ptf-sai.mk
include $(PLATFORM_PATH)/libsaithrift-dev.mk
include $(PLATFORM_PATH)/platform-modules-vs.mk
include $(PLATFORM_PATH)/one-image.mk
include $(PLATFORM_PATH)/onie.mk
include $(PLATFORM_PATH)/kvm-image.mk
Expand Down
10 changes: 10 additions & 0 deletions platform/vs/sonic-platform-modules-vs/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sonic-platform-vs (1.0) UNRELEASED; urgency=low

* Initial release of the sonic-platform-vs package.
* This package provides platform-specific modules for SONiC on virtualized VS platforms.
* Included modules:
- Chassis module
* This package is part of the initial release of SONiC for VS platforms.

-- Deepak Singhal <deepsinghal@microsoft.com> Fri, 26 Feb 2024 12:00:00 +0000

1 change: 1 addition & 0 deletions platform/vs/sonic-platform-modules-vs/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
10 changes: 10 additions & 0 deletions platform/vs/sonic-platform-modules-vs/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source: sonic-platform-vs
Section: main
Priority: extra
Maintainer: Deepak Singhal <deepsinghal@microsoft.com>
Build-Depends: debhelper (>= 9), bzip2
Standards-Version: 3.9.3

Package: sonic-platform-vs
Architecture: amd64
Description: Sonic VS platform Module
58 changes: 58 additions & 0 deletions platform/vs/sonic-platform-modules-vs/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.

include /usr/share/dpkg/pkg-info.mk

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

PYTHON ?= python3
PACKAGE_PRE_NAME := sonic-platform-vs
SRC_DIR:= $(shell pwd)

%:
dh $@ --with python3 --buildsystem=pybuild

clean:
dh_testdir
dh_testroot
dh_clean

build:
# Nothing to do


binary: binary-arch binary-indep
# Nothing to do

binary-arch:
# Nothing to do

binary-indep:
# temporary commented out
# dh_testdir
dh_installdirs

# Custom package commands
$(PYTHON) setup.py install --root=$(SRC_DIR)/debian/$(PACKAGE_PRE_NAME) --install-layout=deb;

# Resuming debhelper scripts
dh_testroot
dh_install
dh_installchangelogs
dh_installdocs
dh_systemd_enable
dh_installinit
dh_systemd_start
dh_link
dh_fixperms
dh_compress
dh_strip
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
.PHONY: build binary binary-arch binary-indep clean
15 changes: 15 additions & 0 deletions platform/vs/sonic-platform-modules-vs/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import os
import sys
from setuptools import setup
os.listdir

setup(
name='sonic_platform',
version='1.0',
description='Module to initialize VS platforms',

packages=['sonic_platform'],
package_dir={'sonic_platform': 'sonic_platform'}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ["platform"]
from sonic_platform import *
61 changes: 61 additions & 0 deletions platform/vs/sonic-platform-modules-vs/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Description: Module contains the definitions of SONiC platform APIs
# which provide the chassis specific details
#
# Copyright (c) 2019, Nokia
# All rights reserved.
#

try:
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform_base.module_base import ModuleBase
import os
import json
import threading

except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Chassis(ChassisBase):
"""
VS Platform-specific Chassis class
"""
def __init__(self):
ChassisBase.__init__(self)
self.metadata_file = '/etc/sonic/vs_chassis_metadata.json'
self.metadata = self._read_metadata()

def _read_metadata(self):
metadata = {}
if os.path.exists(self.metadata_file):
with open(self.metadata_file, 'r') as f:
metadata = json.load(f)
else:
raise FileNotFoundError("Metadata file {} not found".format(self.metadata_file))
return metadata

def get_supervisor_slot(self):
if 'sup_slot_num' not in self.metadata:
raise KeyError("sup_slot_num not found in Metadata file {}".format(self.metadata_file))
return self.metadata['sup_slot_num']

def get_linecard_slot(self):
if 'lc_slot_num' not in self.metadata:
raise KeyError("lc_slot_num not found in Metadata file {}".format(self.metadata_file))
return self.metadata['lc_slot_num']

def get_my_slot(self):
if 'is_supervisor' not in self.metadata or 'is_linecard' not in self.metadata:
raise KeyError("is_supervisor or is_linecard not found in metadata file {}".format(self.metadata_file))

if self.metadata['is_supervisor']:
return self.get_supervisor_slot()
elif self.metadata['is_linecard']:
return self.get_linecard_slot()
else:
raise ValueError("Invalid configuration: Neither supervisor nor line card")

def get_chassis_mac(self):
slotid = self.get_my_slot()
mac = "52:54:56:58:{:02x}:00".format(slotid)
return mac
Loading