Skip to content

Commit

Permalink
Add SAI_PORT_ATTR_OPER_SPEED support
Browse files Browse the repository at this point in the history
Signed-off-by: Ze Gan <[email protected]>
  • Loading branch information
Pterosaur committed Aug 20, 2022
1 parent 9652ea4 commit 4420bed
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions unittest/vslib/TestSwitchBCM81724.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ TEST(SwitchBCM81724, refresh_read_only)

EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_PORT, strPortId, 1, &attr), SAI_STATUS_SUCCESS);

attr.id = SAI_PORT_ATTR_OPER_SPEED;

EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_PORT, strPortId, 1, &attr), SAI_STATUS_SUCCESS);

//std::cout << sw.dump_switch_database_for_warm_restart();
}

Expand Down
33 changes: 33 additions & 0 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,36 @@ sai_status_t SwitchStateBase::refresh_port_serdes_id(
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::refresh_port_oper_speed(
_In_ sai_object_id_t port_id)
{
SWSS_LOG_ENTER();

sai_attribute_t attr;

attr.id = SAI_PORT_ATTR_OPER_STATUS;

CHECK_STATUS(get(SAI_OBJECT_TYPE_PORT, port_id, 1, &attr));

if (attr.value.s32 == SAI_PORT_OPER_STATUS_DOWN)
{
attr.value.u32 = 0;
}
else
{
if (!vs_get_oper_speed(port_id, attr.value.u32))
{
return SAI_STATUS_FAILURE;
}
}

attr.id = SAI_PORT_ATTR_OPER_SPEED;

CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, port_id, &attr));

return SAI_STATUS_SUCCESS;
}

// XXX extra work may be needed on GET api if N on list will be > then actual

/*
Expand Down Expand Up @@ -2312,6 +2342,9 @@ sai_status_t SwitchStateBase::refresh_read_only(

case SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE:
return SAI_STATUS_SUCCESS;

case SAI_PORT_ATTR_OPER_SPEED:
return refresh_port_oper_speed(object_id);
}
}

Expand Down
7 changes: 7 additions & 0 deletions vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ namespace saivs
virtual sai_status_t refresh_port_serdes_id(
_In_ sai_object_id_t bridge_id);

virtual sai_status_t refresh_port_oper_speed(
_In_ sai_object_id_t port_id);

public:

virtual sai_status_t warm_boot_initialize_objects();
Expand Down Expand Up @@ -486,6 +489,10 @@ namespace saivs
bool hasIfIndex(
_In_ int ifIndex) const;

bool vs_get_oper_speed(
_In_ sai_object_id_t port_id,
_Out_ uint32_t& speed);

public: // TODO move inside warm boot load state

sai_status_t vs_recreate_hostif_tap_interfaces();
Expand Down
40 changes: 40 additions & 0 deletions vslib/SwitchStateBaseHostif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/if.h>

#include <algorithm>
#include <fstream>

using namespace saivs;

Expand Down Expand Up @@ -871,6 +872,45 @@ bool SwitchStateBase::hasIfIndex(
return false;
}

bool SwitchStateBase::vs_get_oper_speed(
_In_ sai_object_id_t port_id,
_Out_ uint32_t& speed)

{
SWSS_LOG_ENTER();

auto info = findHostInterfaceInfoByPort(port_id);

if (!info)
{
SWSS_LOG_ERROR("Port %s don't exists",
sai_serialize_object_id(port_id).c_str());

return false;
}

auto veth_name = vs_get_veth_name(info->m_name, port_id);

std::string veth_speed_filename = "/sys/class/net/";

veth_speed_filename += veth_name;
veth_speed_filename += "/speed";

std::ifstream ifs(veth_speed_filename);

if (!ifs.is_open())
{
SWSS_LOG_ERROR("Failed to open %s", veth_speed_filename.c_str());

return false;
}

ifs >> speed;
ifs.close();

return true;
}

void SwitchStateBase::syncOnLinkMsg(
_In_ std::shared_ptr<EventPayloadNetLinkMsg> payload)
{
Expand Down

0 comments on commit 4420bed

Please sign in to comment.