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

[portsorch] fix errors when moving port from one lag to another. #1797

Merged
merged 11 commits into from
Jul 8, 2021
51 changes: 35 additions & 16 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ static char* hostif_vlan_tag[] = {
[SAI_HOSTIF_VLAN_TAG_KEEP] = "SAI_HOSTIF_VLAN_TAG_KEEP",
[SAI_HOSTIF_VLAN_TAG_ORIGINAL] = "SAI_HOSTIF_VLAN_TAG_ORIGINAL"
};

static bool isValidPortTypeForLagMember(const Port& port)
{
return (port.m_type == Port::Type::PHY || port.m_type == Port::Type::SYSTEM);
}

/*
* Initialize PortsOrch
* 0) If Gearbox is enabled, then initialize the external PHYs as defined in
Expand Down Expand Up @@ -1722,7 +1728,7 @@ void PortsOrch::getPortSupportedSpeeds(const std::string& alias, sai_object_id_t
}

// if our guess was wrong, retry with the correct value
speeds.resize(attr.value.u32list.count);
speeds.resize(attr.value.u32list.count);
}

if (status == SAI_STATUS_SUCCESS)
Expand Down Expand Up @@ -2193,7 +2199,7 @@ sai_status_t PortsOrch::removePort(sai_object_id_t port_id)

Port port;

/*
/*
* Make sure to bring down admin state.
* SET would have replaced with DEL
*/
Expand Down Expand Up @@ -2765,7 +2771,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
it = consumer.m_toSync.erase(it);
continue;
}

an = autoneg_mode_map[an_str];
if (an != p.m_autoneg)
{
Expand Down Expand Up @@ -2831,7 +2837,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
it++;
continue;
}

SWSS_LOG_NOTICE("Set port %s speed from %u to %u", alias.c_str(), p.m_speed, speed);
p.m_speed = speed;
m_portList[alias] = p;
Expand Down Expand Up @@ -2872,7 +2878,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
auto ori_adv_speeds = swss::join(',', p.m_adv_speeds.begin(), p.m_adv_speeds.end());
if (!setPortAdvSpeeds(p.m_port_id, adv_speeds))
{

SWSS_LOG_ERROR("Failed to set port %s advertised speed from %s to %s", alias.c_str(),
ori_adv_speeds.c_str(),
adv_speeds_str.c_str());
Expand Down Expand Up @@ -3666,6 +3672,15 @@ void PortsOrch::doLagMemberTask(Consumer &consumer)
continue;
}

/* Fail if a port type is not a valid type for being a LAG member port.
* Erase invalid entry, no need to retry in this case. */
if (!isValidPortTypeForLagMember(port))
judyjoseph marked this conversation as resolved.
Show resolved Hide resolved
{
SWSS_LOG_ERROR("LAG member port has to be of type PHY or SYSTEM");
it = consumer.m_toSync.erase(it);
continue;
}

if (table_name == CHASSIS_APP_LAG_MEMBER_TABLE_NAME)
{
int32_t lag_switch_id = lag.m_system_lag_info.switch_id;
Expand Down Expand Up @@ -3699,8 +3714,12 @@ void PortsOrch::doLagMemberTask(Consumer &consumer)

if (lag.m_members.find(port_alias) == lag.m_members.end())
{
/* Assert the port doesn't belong to any LAG already */
assert(!port.m_lag_id && !port.m_lag_member_id);
if (port.m_lag_member_id != SAI_NULL_OBJECT_ID)
{
SWSS_LOG_INFO("Port %s is already a LAG member", port.m_alias.c_str());
it++;
continue;
}

if (!addLagMember(lag, port, (status == "enabled")))
{
Expand Down Expand Up @@ -5500,7 +5519,7 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str,
}
}

bool PortsOrch::getPortAdvSpeedsVal(const std::string &val_str,
bool PortsOrch::getPortAdvSpeedsVal(const std::string &val_str,
std::vector<uint32_t> &speed_values)
{
SWSS_LOG_ENTER();
Expand All @@ -5514,7 +5533,7 @@ bool PortsOrch::getPortAdvSpeedsVal(const std::string &val_str,
std::string speed_str;
std::istringstream iss(val_str);

try
try
{
while (std::getline(iss, speed_str, ','))
{
Expand All @@ -5531,31 +5550,31 @@ bool PortsOrch::getPortAdvSpeedsVal(const std::string &val_str,
return true;
}

bool PortsOrch::getPortInterfaceTypeVal(const std::string &s,
bool PortsOrch::getPortInterfaceTypeVal(const std::string &s,
sai_port_interface_type_t &interface_type)
{
SWSS_LOG_ENTER();

auto iter = interface_type_map_for_an.find(s);
if (iter != interface_type_map_for_an.end())
if (iter != interface_type_map_for_an.end())
{
interface_type = interface_type_map_for_an[s];
return true;
}
else
else
{
const std::string &validInterfaceTypes = getValidInterfaceTypes();
SWSS_LOG_ERROR("Failed to parse interface_type value %s, valid interface type includes: %s",
SWSS_LOG_ERROR("Failed to parse interface_type value %s, valid interface type includes: %s",
s.c_str(), validInterfaceTypes.c_str());
return false;
}
}

bool PortsOrch::getPortAdvInterfaceTypesVal(const std::string &val_str,
bool PortsOrch::getPortAdvInterfaceTypesVal(const std::string &val_str,
std::vector<uint32_t> &type_values)
{
SWSS_LOG_ENTER();
if (val_str == "all")
if (val_str == "all")
{
return true;
}
Expand All @@ -5570,7 +5589,7 @@ bool PortsOrch::getPortAdvInterfaceTypesVal(const std::string &val_str,
valid = getPortInterfaceTypeVal(type_str, interface_type);
if (!valid) {
const std::string &validInterfaceTypes = getValidInterfaceTypes();
SWSS_LOG_ERROR("Failed to parse adv_interface_types value %s, valid interface type includes: %s",
SWSS_LOG_ERROR("Failed to parse adv_interface_types value %s, valid interface type includes: %s",
val_str.c_str(), validInterfaceTypes.c_str());
return false;
}
Expand Down
Loading