Skip to content

Commit

Permalink
[bluefield] Add platform-api implementation. (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Ivantsiv <oivantsiv@nvidia.com>
  • Loading branch information
oleksandrivantsiv authored Mar 30, 2022
1 parent 15553ab commit 71a9ee5
Show file tree
Hide file tree
Showing 23 changed files with 1,244 additions and 2 deletions.
34 changes: 34 additions & 0 deletions device/nvidia-bluefield/arm64-nvda_bf-mbf2h536c/platform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"chassis": {
"name": "Nvidia-MBF2H536C",
"components": [],
"fans": [],
"fan_drawers": [],
"psus": [],
"thermals": [],
"sfps": [
{
"name": "p0"
},
{
"name": "p1"
}
]
},
"interfaces": {
"Ethernet0": {
"index": "1,1,1,1",
"lanes": "0,1,2,3",
"breakout_modes": {
"1x100G": ["etp1"]
}
},
"Ethernet4": {
"index": "2,2,2,2",
"lanes": "4,5,6,7",
"breakout_modes": {
"1x100G": ["etp2"]
}
}
}
}
34 changes: 34 additions & 0 deletions device/nvidia-bluefield/arm64-nvda_bf-mbf2m516a/platform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"chassis": {
"name": "Nvidia-MBF2H516A",
"components": [],
"fans": [],
"fan_drawers": [],
"psus": [],
"thermals": [],
"sfps": [
{
"name": "p0"
},
{
"name": "p1"
}
]
},
"interfaces": {
"Ethernet0": {
"index": "1,1,1,1",
"lanes": "0,1,2,3",
"breakout_modes": {
"1x100G": ["etp1"]
}
},
"Ethernet4": {
"index": "2,2,2,2",
"lanes": "4,5,6,7",
"breakout_modes": {
"1x100G": ["etp2"]
}
}
}
}
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 @@ -846,6 +846,13 @@ sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $MLNX_
sudo rm -rf $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME
{% endif %}

{% if sonic_asic_platform == "nvidia-bluefield" %}
SONIC_PLATFORM_PY3_WHEEL_NAME=$(basename {{platform_api_py3_wheel_path}})
sudo cp {{platform_api_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PLATFORM_PY3_WHEEL_NAME
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PLATFORM_PY3_WHEEL_NAME
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PLATFORM_PY3_WHEEL_NAME
{% endif %}

{%- if SONIC_ROUTING_STACK == "frr" %}
sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr
sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/frr.conf
Expand Down
6 changes: 6 additions & 0 deletions platform/nvidia-bluefield/platform-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
.cache/
*/test-results.xml
*/htmlcov/
*/coverage.xml
*/.coverage
20 changes: 20 additions & 0 deletions platform/nvidia-bluefield/platform-api/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
##
## Copyright (c) 2020-2022 NVIDIA CORPORATION & AFFILIATES.
## Apache-2.0
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
[pytest]
addopts = --cov=sonic_platform --cov-report html --cov-report term --cov-report xml --junitxml=test-results.xml -vv
filterwarnings =
ignore::DeprecationWarning
2 changes: 2 additions & 0 deletions platform/nvidia-bluefield/platform-api/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test=pytest
54 changes: 54 additions & 0 deletions platform/nvidia-bluefield/platform-api/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright (c) 2019-2022 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from setuptools import setup

setup(
name='platform-api',
version='1.0',
description='SONiC platform API implementation on NVIDIA BlueField platform',
license='Apache 2.0',
author='NVIDIA SONiC Team',
author_email='oivantsiv@nvidia.com',
url='https://github.com/Azure/sonic-buildimage',
maintainer='Oleksandr Ivantsiv',
maintainer_email='oivantsiv@nvidia.com',
packages=[
'sonic_platform',
'tests'
],
setup_requires= [
'pytest-runner'
],
tests_require = [
'pytest',
'mock>=2.0.0'
],
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.7',
'Topic :: Utilities',
],
keywords='sonic SONiC platform PLATFORM',
test_suite='setup.get_test_suite'
)
18 changes: 18 additions & 0 deletions platform/nvidia-bluefield/platform-api/sonic_platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__all__ = ["platform", "chassis"]
from sonic_platform import *
155 changes: 155 additions & 0 deletions platform/nvidia-bluefield/platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#
# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

try:
from sonic_platform_base.chassis_base import ChassisBase
from sonic_py_common.logger import Logger
import os
from functools import reduce

from . import utils
from .device_data import DeviceDataManager
from .sfp import Sfp
from .eeprom import Eeprom
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

MAX_SELECT_DELAY = 3600


# Global logger class instance
logger = Logger()


class Chassis(ChassisBase):
"""Platform-specific Chassis class"""

def __init__(self):
super(Chassis, self).__init__()

# Initialize DMI data
self.dmi_data = None

self.device_data = DeviceDataManager()
self._initialize_sfp()
self.sfp_event = None
self._eeprom = Eeprom()
logger.log_info("Chassis loaded successfully")

def _initialize_sfp(self):
self._sfp_list = []

sfp_count = self.get_num_sfps()
for index in range(sfp_count):
sfp_module = Sfp(index, self.device_data.get_sfp_data(index))
self._sfp_list.append(sfp_module)

def get_sfp(self, index):
return super(Chassis, self).get_sfp(index - 1)

def get_num_sfps(self):
"""
Retrieves the number of sfps available on this chassis
Returns:
An integer, the number of sfps available on this chassis
"""
return self.device_data.get_sfp_count()

def get_eeprom(self):
"""
Retreives eeprom device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
eeprom device
"""
return self._eeprom

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return self._eeprom.get_product_name()

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return self._eeprom.get_part_number()

def get_base_mac(self):
"""
Retrieves the base MAC address for the chassis
Returns:
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
return self._eeprom.get_base_mac()

def get_serial(self):
"""
Retrieves the hardware serial number for the chassis
Returns:
A string containing the hardware serial number for this chassis.
"""
return self._eeprom.get_serial_number()

def get_system_eeprom_info(self):
"""
Retrieves the full content of system EEPROM information for the chassis
Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their corresponding
values.
"""
return self._eeprom.get_system_eeprom_info()

def get_revision(self):
"""
Retrieves the hardware revision of the device
Returns:
string: Revision value of device
"""
return self._eeprom.get_revision()

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
"""
return -1

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False
Loading

0 comments on commit 71a9ee5

Please sign in to comment.