Skip to content

Commit

Permalink
[FEC]Auto FEC initial changes (sonic-net#2893)
Browse files Browse the repository at this point in the history
* [FEC]Auto FEC initial changes
Initial Changes to support Auto FEC feature. Added support for mode "auto" in FEC

Why I did it
To implement auto FEC feature HLD: sonic-net/SONiC#1416
  • Loading branch information
dgsudharsan authored Oct 5, 2023
1 parent 91e7a27 commit 3599635
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 39 deletions.
11 changes: 8 additions & 3 deletions orchagent/p4orch/tests/fake_portorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,12 @@ bool PortsOrch::getPortPvid(Port &port, sai_uint32_t &pvid)
return true;
}

bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode)
bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode, bool override_fec)
{
return true;
}

bool PortsOrch::isFecModeSupported(const Port &port, sai_port_fec_mode_t fec_mode)
{
return true;
}
Expand Down Expand Up @@ -581,12 +586,12 @@ bool PortsOrch::getPortSpeed(sai_object_id_t port_id, sai_uint32_t &speed)
return true;
}

bool PortsOrch::setGearboxPortsAttr(const Port &port, sai_port_attr_t id, void *value)
bool PortsOrch::setGearboxPortsAttr(const Port &port, sai_port_attr_t id, void *value, bool override_fec)
{
return true;
}

bool PortsOrch::setGearboxPortAttr(const Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value)
bool PortsOrch::setGearboxPortAttr(const Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value, bool override_fec)
{
return true;
}
Expand Down
1 change: 1 addition & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Port
bool m_intf_cfg = false; // Interface type
bool m_adv_intf_cfg = false; // Advertised interface type
bool m_fec_cfg = false; // Forward Error Correction (FEC)
bool m_override_fec = false; // Enable Override FEC
bool m_pfc_asym_cfg = false; // Asymmetric Priority Flow Control (PFC)
bool m_lm_cfg = false; // Forwarding Database (FDB) Learning Mode (LM)
bool m_lt_cfg = false; // Link Training (LT)
Expand Down
1 change: 1 addition & 0 deletions orchagent/port/portcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PortConfig final
struct {
sai_port_fec_mode_t value;
bool is_set = false;
bool override_fec = false;
} fec; // Port FEC

struct {
Expand Down
43 changes: 42 additions & 1 deletion orchagent/port/porthlpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static const std::unordered_map<std::string, sai_port_fec_mode_t> portFecMap =
{
{ PORT_FEC_NONE, SAI_PORT_FEC_MODE_NONE },
{ PORT_FEC_RS, SAI_PORT_FEC_MODE_RS },
{ PORT_FEC_FC, SAI_PORT_FEC_MODE_FC }
{ PORT_FEC_FC, SAI_PORT_FEC_MODE_FC },
{ PORT_FEC_AUTO, SAI_PORT_FEC_MODE_NONE }
};

static const std::unordered_map<sai_port_fec_mode_t, std::string> portFecRevMap =
Expand All @@ -84,6 +85,14 @@ static const std::unordered_map<sai_port_fec_mode_t, std::string> portFecRevMap
{ SAI_PORT_FEC_MODE_FC, PORT_FEC_FC }
};

static const std::unordered_map<std::string, bool> portFecOverrideMap =
{
{ PORT_FEC_NONE, true },
{ PORT_FEC_RS, true },
{ PORT_FEC_FC, true },
{ PORT_FEC_AUTO, false }
};

static const std::unordered_map<std::string, sai_port_priority_flow_control_mode_t> portPfcAsymMap =
{
{ PORT_MODE_ON, SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE },
Expand Down Expand Up @@ -146,6 +155,30 @@ bool PortHelper::fecToStr(std::string &str, sai_port_fec_mode_t value) const
return true;
}

bool PortHelper::fecToSaiFecMode(const std::string &str, sai_port_fec_mode_t &value) const
{
const auto &cit = portFecMap.find(str);
if (cit == portFecMap.cend())
{
return false;
}

value = cit->second;

return true;
}

bool PortHelper::fecIsOverrideRequired(const std::string &str) const
{
const auto &cit = portFecMap.find(str);
if (cit == portFecMap.cend())
{
return false;
}

return cit->second;

}
std::string PortHelper::getFieldValueStr(const PortConfig &port, const std::string &field) const
{
static std::string str;
Expand Down Expand Up @@ -468,8 +501,16 @@ bool PortHelper::parsePortFec(PortConfig &port, const std::string &field, const
return false;
}

const auto &override_cit = portFecOverrideMap.find(value);
if (override_cit == portFecOverrideMap.cend())
{
SWSS_LOG_ERROR("Failed to parse field(%s): invalid value(%s) in override map", field.c_str(), value.c_str());
return false;
}

port.fec.value = cit->second;
port.fec.is_set = true;
port.fec.override_fec =override_cit->second;

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions orchagent/port/porthlpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class PortHelper final

public:
bool fecToStr(std::string &str, sai_port_fec_mode_t value) const;
bool fecToSaiFecMode(const std::string &str, sai_port_fec_mode_t &value) const;
bool fecIsOverrideRequired(const std::string &str) const;

std::string getAutonegStr(const PortConfig &port) const;
std::string getPortInterfaceTypeStr(const PortConfig &port) const;
Expand Down
1 change: 1 addition & 0 deletions orchagent/port/portschema.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define PORT_FEC_NONE "none"
#define PORT_FEC_RS "rs"
#define PORT_FEC_FC "fc"
#define PORT_FEC_AUTO "auto"

#define PORT_LEARN_MODE_DROP "drop"
#define PORT_LEARN_MODE_DISABLE "disable"
Expand Down
Loading

0 comments on commit 3599635

Please sign in to comment.