Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vslib] Add support for PoE feature #1404

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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 @@ -3611,6 +3615,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 @@ -4286,6 +4293,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 @@ -4673,6 +4683,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 @@ -4946,6 +4959,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 @@ -5840,6 +5856,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 @@ -6079,6 +6099,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
8 changes: 8 additions & 0 deletions meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,14 @@ std::string sai_serialize_object_type(
return sai_serialize_enum(object_type, &sai_metadata_enum_sai_object_type_t);
}

std::string sai_serialize_switch_type(
_In_ const sai_switch_type_t switch_type)
{
SWSS_LOG_ENTER();

return sai_serialize_enum(switch_type, &sai_metadata_enum_sai_switch_type_t);
}

std::string sai_serialize_log_level(
_In_ sai_log_level_t log_level)
{
Expand Down
3 changes: 3 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ std::string sai_serialize_vlan_id(
std::string sai_serialize_object_type(
_In_ const sai_object_type_t object_type);

std::string sai_serialize_switch_type(
_In_ const sai_switch_type_t switch_type);

std::string sai_serialize_object_id(
_In_ const sai_object_id_t object_id);

Expand Down
12 changes: 8 additions & 4 deletions syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,28 @@ void SaiSwitch::getDefaultMacAddress(
sai_switch_type_t SaiSwitch::getSwitchType() const
{
SWSS_LOG_ENTER();
sai_switch_type_t switch_type;
sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_TYPE;

sai_status_t status = m_vendorSai->get(SAI_OBJECT_TYPE_SWITCH, m_switch_rid, 1, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("failed to get switch type with status: %s, assume default SAI_SWITCH_TYPE_NPU",
sai_serialize_status(status).c_str());

// Set to SAI_SWITCH_TYPE_NPU and move on
attr.value.s32 = SAI_SWITCH_TYPE_NPU;
switch_type = SAI_SWITCH_TYPE_NPU;
}
else
{
switch_type = (sai_switch_type_t) attr.value.s32;
}

SWSS_LOG_INFO("switch type: '%s'", (attr.value.s32 == SAI_SWITCH_TYPE_NPU ? "SAI_SWITCH_TYPE_NPU" : "SAI_SWITCH_TYPE_PHY"));
SWSS_LOG_INFO("switch type: '%s'", sai_serialize_switch_type(switch_type).c_str());

return (sai_switch_type_t) attr.value.s32;
return switch_type;
}

#define MAX_HARDWARE_INFO_LENGTH 0x1000
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
kcudnik marked this conversation as resolved.
Show resolved Hide resolved
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())
2 changes: 2 additions & 0 deletions tests/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ pn
PN
policer
PORTs
POE
PSE
pre
printf
ptr
Expand Down
1 change: 1 addition & 0 deletions unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tests_SOURCES = main.cpp \
TestSwitchNvdaMBF2H536C.cpp \
TestSwitchBCM56850.cpp \
TestSwitchBCM81724.cpp \
TestSwitchPoe.cpp \
TestSwitchStateBaseMACsec.cpp \
TestMACsecManager.cpp \
TestSwitchStateBase.cpp \
Expand Down
6 changes: 6 additions & 0 deletions unittest/vslib/TestSwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ TEST(SwitchConfig, parseSaiSwitchType)

EXPECT_TRUE(SwitchConfig::parseSaiSwitchType(SAI_VALUE_SAI_SWITCH_TYPE_PHY, type));
EXPECT_EQ(type, SAI_SWITCH_TYPE_PHY);

EXPECT_TRUE(SwitchConfig::parseSaiSwitchType(SAI_VALUE_SAI_SWITCH_TYPE_POE, type));
EXPECT_EQ(type, SAI_SWITCH_TYPE_POE);
}

TEST(SwitchConfig, parseSwitchType)
Expand All @@ -36,6 +39,9 @@ TEST(SwitchConfig, parseSwitchType)

EXPECT_TRUE(SwitchConfig::parseSwitchType(SAI_VALUE_VS_SWITCH_TYPE_MLNX2700, type));
EXPECT_EQ(type, SAI_VS_SWITCH_TYPE_MLNX2700);

EXPECT_TRUE(SwitchConfig::parseSwitchType(SAI_VALUE_VS_SWITCH_TYPE_POE, type));
EXPECT_EQ(type, SAI_VS_SWITCH_TYPE_POE);
}


Expand Down
Loading
Loading