Skip to content

Commit

Permalink
[sonic-sairedis] Add support for PoE
Browse files Browse the repository at this point in the history
Add SwitchPoe to vslib
Add a python script to spawn the PoE syncd process

Signed-off-by: Serhiy Boiko <[email protected]>
  • Loading branch information
SerhiyBoikoPLV committed Jul 19, 2024
1 parent a988dd1 commit 76f90a0
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 2 deletions.
24 changes: 24 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,10 @@ void Meta::meta_generic_validation_post_remove(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
// no special action required
break;

default:
META_LOG_THROW(md, "serialization type is not supported yet FIXME");
}
Expand Down Expand Up @@ -3573,6 +3577,9 @@ sai_status_t Meta::meta_generic_validation_create(
VALIDATION_LIST(md, value.ipprefixlist);
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -4248,6 +4255,9 @@ sai_status_t Meta::meta_generic_validation_set(
VALIDATION_LIST(md, value.ipprefixlist);
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -4635,6 +4645,9 @@ sai_status_t Meta::meta_generic_validation_get(
VALIDATION_LIST(md, value.ipprefixlist);
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
break;

default:

// acl capability will is more complex since is in/out we need to check stage
Expand Down Expand Up @@ -4908,6 +4921,9 @@ void Meta::meta_generic_validation_post_get(
VALIDATION_LIST_GET(md, value.ipprefixlist);
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -5802,6 +5818,10 @@ void Meta::meta_generic_validation_post_create(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
// no special action required
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -6041,6 +6061,10 @@ void Meta::meta_generic_validation_post_set(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_POE_PORT_POWER_CONSUMPTION:
// no special action required
break;

default:
META_LOG_THROW(md, "serialization type is not supported yet FIXME");
}
Expand Down
7 changes: 6 additions & 1 deletion syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ sai_switch_type_t SaiSwitch::getSwitchType() const
attr.value.s32 = SAI_SWITCH_TYPE_NPU;
}

SWSS_LOG_INFO("switch type: '%s'", (attr.value.s32 == SAI_SWITCH_TYPE_NPU ? "SAI_SWITCH_TYPE_NPU" : "SAI_SWITCH_TYPE_PHY"));
if (attr.value.s32 == SAI_SWITCH_TYPE_NPU)
SWSS_LOG_INFO("switch type: 'SAI_SWITCH_TYPE_NPU'");
else if (attr.value.s32 == SAI_SWITCH_TYPE_PHY)
SWSS_LOG_INFO("switch type: 'SAI_SWITCH_TYPE_PHY'");
else if (attr.value.s32 == SAI_SWITCH_TYPE_POE)
SWSS_LOG_INFO("switch type: 'SAI_SWITCH_TYPE_POE'");

return (sai_switch_type_t) attr.value.s32;
}
Expand Down
76 changes: 76 additions & 0 deletions syncd/scripts/poesyncdmgrd
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3

import os
import signal
import subprocess
import sys
import syslog
import time


SYSLOG_IDENTIFIER = os.path.basename(__file__)

EXIT_SUCCESS = 0
EXIT_INSUFFICIENT_PERMISSIONS = 1
EXIT_UNKNOWN = 2

running = True
exit_code = EXIT_UNKNOWN


def fatal_signal_handler(sig, frame):
global running

signal_name = signal.Signals(sig).name

syslog.syslog(syslog.LOG_NOTICE, 'Caught signal {} - exiting...'.format(signal_name))
exit_code = sig + 128
running = False


def main():
# Only privileged users can run this daemon
if os.geteuid() != 0:
print('Root privileges required for this operation')
return EXIT_INSUFFICIENT_PERMISSIONS

syslog.openlog(SYSLOG_IDENTIFIER)

# Register our signal handlers
signal.signal(signal.SIGTERM, fatal_signal_handler)

# Check if a poe config exists
if not os.path.isfile('/usr/share/sonic/hwsku/poe_config.json'):
syslog.syslog(syslog.LOG_NOTICE, 'PoE is not supported on this platform. Exiting ...')
syslog.closelog()
time.sleep(2)
return EXIT_SUCCESS

# Spawn poe syncd process
cmd = '/usr/bin/syncd -s -p /etc/sai.d/poe.profile -x /usr/share/sonic/hwsku/context_config.json -g 1'
proc = subprocess.Popen(cmd.split(), close_fds=True)

global running

# Check all of our subprocesses. If any exit, we should too.
while running:
proc.poll()
if proc.returncode is not None:
syslog.syslog(syslog.LOG_NOTICE, 'Subprocess PID {} exited. Shutting down ...'.format(proc.pid))
running = False
break
time.sleep(1)

# If we get here, either the subprocess exited or we recieved a signal to exit
# so we send SIGTERM to the subprocesses (if it is still running) before exiting
if proc.returncode is None:
syslog.syslog(syslog.LOG_INFO, 'Terminating PID {} ...'.format(proc.pid))
proc.terminate()

syslog.closelog()

return exit_code


if __name__ == '__main__':
sys.exit(main())
1 change: 1 addition & 0 deletions vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ libSaiVS_a_SOURCES = \
SwitchContainer.cpp \
Switch.cpp \
SwitchMLNX2700.cpp \
SwitchPoE.cpp \
SwitchNvdaMBF2H536C.cpp \
SwitchStateBase.cpp \
SwitchStateBaseFdb.cpp \
Expand Down
12 changes: 11 additions & 1 deletion vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ bool SwitchConfig::parseSaiSwitchType(
{
saiSwitchType = SAI_SWITCH_TYPE_PHY;
}
else if (st == SAI_VALUE_SAI_SWITCH_TYPE_POE)
{
saiSwitchType = SAI_SWITCH_TYPE_POE;
}
else
{
SWSS_LOG_ERROR("unknown SAI switch type: '%s', expected (%s|%s)",
SWSS_LOG_ERROR("unknown SAI switch type: '%s', expected (%s|%s|%s)",
saiSwitchTypeStr,
SAI_VALUE_SAI_SWITCH_TYPE_NPU,
SAI_VALUE_SAI_SWITCH_TYPE_POE,
SAI_VALUE_SAI_SWITCH_TYPE_PHY);

return false;
Expand Down Expand Up @@ -73,6 +78,10 @@ bool SwitchConfig::parseSwitchType(
{
switchType = SAI_VS_SWITCH_TYPE_BCM81724;
}
else if (st == SAI_VALUE_VS_SWITCH_TYPE_POE_VS)
{
switchType = SAI_VS_SWITCH_TYPE_POE_VS;
}
else if (st == SAI_VALUE_VS_SWITCH_TYPE_MLNX2700)
{
switchType = SAI_VS_SWITCH_TYPE_MLNX2700;
Expand All @@ -96,6 +105,7 @@ bool SwitchConfig::parseSwitchType(
SAI_VALUE_VS_SWITCH_TYPE_BCM81724,
SAI_VALUE_VS_SWITCH_TYPE_BCM56850,
SAI_VALUE_VS_SWITCH_TYPE_BCM56971B0,
SAI_VALUE_VS_SWITCH_TYPE_POE_VS,
SAI_VALUE_VS_SWITCH_TYPE_MLNX2700,
SAI_VALUE_VS_SWITCH_TYPE_NVDA_MBF2H536C,
SAI_VALUE_VS_SWITCH_TYPE_DPU_SIMU_2P
Expand Down
2 changes: 2 additions & 0 deletions vslib/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace saivs

SAI_VS_SWITCH_TYPE_NVDA_MBF2H536C,

SAI_VS_SWITCH_TYPE_POE_VS,

} sai_vs_switch_type_t;

typedef enum _sai_vs_boot_type_t
Expand Down
Loading

0 comments on commit 76f90a0

Please sign in to comment.