Skip to content

Commit 80dfc97

Browse files
gechiangraphaelt-nvidia
authored andcommitted
[sonic-swss:TPID CONFIG]Added Orchagent TPID config support for Port/LAG (sonic-net#1747)
* [sonic-swss:TPID CONFIG]Added Orchagent TPID config support for Port/LAG Signed-off-by: Gen-Hwa Chiang <gechiang@microsoft.com> * Changed per review comment to move TPID capability query under switchorch class
1 parent b4440a1 commit 80dfc97

11 files changed

Lines changed: 304 additions & 1 deletion

File tree

cfgmgr/portmgr.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ bool PortMgr::setPortMtu(const string &alias, const string &mtu)
3838
return true;
3939
}
4040

41+
bool PortMgr::setPortTpid(const string &alias, const string &tpid)
42+
{
43+
stringstream cmd;
44+
string res;
45+
46+
// Set the port TPID in application database to update port TPID
47+
vector<FieldValueTuple> fvs;
48+
FieldValueTuple fv("tpid", tpid);
49+
fvs.push_back(fv);
50+
m_appPortTable.set(alias, fvs);
51+
52+
return true;
53+
}
54+
55+
4156
bool PortMgr::setPortAdminStatus(const string &alias, const bool up)
4257
{
4358
stringstream cmd;
@@ -102,7 +117,7 @@ void PortMgr::doTask(Consumer &consumer)
102117
continue;
103118
}
104119

105-
string admin_status, mtu, learn_mode;
120+
string admin_status, mtu, learn_mode, tpid;
106121

107122
bool configured = (m_portList.find(alias) != m_portList.end());
108123

@@ -131,6 +146,10 @@ void PortMgr::doTask(Consumer &consumer)
131146
{
132147
learn_mode = fvValue(i);
133148
}
149+
else if (fvField(i) == "tpid")
150+
{
151+
tpid = fvValue(i);
152+
}
134153
}
135154

136155
if (!mtu.empty())
@@ -150,6 +169,12 @@ void PortMgr::doTask(Consumer &consumer)
150169
setPortLearnMode(alias, learn_mode);
151170
SWSS_LOG_NOTICE("Configure %s MAC learn mode to %s", alias.c_str(), learn_mode.c_str());
152171
}
172+
173+
if (!tpid.empty())
174+
{
175+
setPortTpid(alias, tpid);
176+
SWSS_LOG_NOTICE("Configure %s TPID to %s", alias.c_str(), tpid.c_str());
177+
}
153178
}
154179
else if (op == DEL_COMMAND)
155180
{

cfgmgr/portmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class PortMgr : public Orch
3030

3131
void doTask(Consumer &consumer);
3232
bool setPortMtu(const std::string &alias, const std::string &mtu);
33+
bool setPortTpid(const std::string &alias, const std::string &tpid);
3334
bool setPortAdminStatus(const std::string &alias, const bool up);
3435
bool setPortLearnMode(const std::string &alias, const std::string &learn_mode);
3536
bool isPortStateOk(const std::string &alias);

cfgmgr/teammgr.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ void TeamMgr::doLagTask(Consumer &consumer)
145145
string admin_status = DEFAULT_ADMIN_STATUS_STR;
146146
string mtu = DEFAULT_MTU_STR;
147147
string learn_mode;
148+
string tpid;
148149

149150
for (auto i : kfvFieldsValues(t))
150151
{
@@ -178,6 +179,11 @@ void TeamMgr::doLagTask(Consumer &consumer)
178179
SWSS_LOG_INFO("Get learn_mode %s",
179180
learn_mode.c_str());
180181
}
182+
else if (fvField(i) == "tpid")
183+
{
184+
tpid = fvValue(i);
185+
SWSS_LOG_INFO("Get TPID %s", tpid.c_str());
186+
}
181187
}
182188

183189
if (m_lagList.find(alias) == m_lagList.end())
@@ -198,6 +204,11 @@ void TeamMgr::doLagTask(Consumer &consumer)
198204
setLagLearnMode(alias, learn_mode);
199205
SWSS_LOG_NOTICE("Configure %s MAC learn mode to %s", alias.c_str(), learn_mode.c_str());
200206
}
207+
if (!tpid.empty())
208+
{
209+
setLagTpid(alias, tpid);
210+
SWSS_LOG_NOTICE("Configure %s TPID to %s", alias.c_str(), tpid.c_str());
211+
}
201212
}
202213
else if (op == DEL_COMMAND)
203214
{
@@ -395,6 +406,21 @@ bool TeamMgr::setLagMtu(const string &alias, const string &mtu)
395406
return true;
396407
}
397408

409+
bool TeamMgr::setLagTpid(const string &alias, const string &tpid)
410+
{
411+
SWSS_LOG_ENTER();
412+
413+
vector<FieldValueTuple> fvs;
414+
FieldValueTuple fv("tpid", tpid);
415+
fvs.push_back(fv);
416+
m_appLagTable.set(alias, fvs);
417+
418+
SWSS_LOG_NOTICE("Set port channel %s TPID to %s", alias.c_str(), tpid.c_str());
419+
420+
return true;
421+
}
422+
423+
398424
bool TeamMgr::setLagLearnMode(const string &alias, const string &learn_mode)
399425
{
400426
// Set the port MAC learn mode in application database

cfgmgr/teammgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class TeamMgr : public Orch
4949
bool setLagAdminStatus(const std::string &alias, const std::string &admin_status);
5050
bool setLagMtu(const std::string &alias, const std::string &mtu);
5151
bool setLagLearnMode(const std::string &alias, const std::string &learn_mode);
52+
bool setLagTpid(const std::string &alias, const std::string &tpid);
5253

5354

5455
bool isPortEnslaved(const std::string &);

orchagent/port.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ extern "C" {
2020
*/
2121
#define DEFAULT_MTU 1492
2222

23+
/*
24+
* Default TPID is 8100
25+
* User can configure other values such as 9100, 9200, or 88A8
26+
*/
27+
#define DEFAULT_TPID 0x8100
28+
2329
#define VNID_NONE 0xFFFFFFFF
2430

2531
namespace swss {
@@ -128,6 +134,7 @@ class Port
128134
std::vector<sai_object_id_t> m_priority_group_ids;
129135
sai_port_priority_flow_control_mode_t m_pfc_asym = SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED;
130136
uint8_t m_pfc_bitmask = 0;
137+
uint16_t m_tpid = DEFAULT_TPID;
131138
uint32_t m_nat_zone_id = 0;
132139
uint32_t m_vnid = VNID_NONE;
133140
uint32_t m_fdb_count = 0;

orchagent/portsorch.cpp

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,36 @@ bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu)
968968
return true;
969969
}
970970

971+
972+
bool PortsOrch::setPortTpid(sai_object_id_t id, sai_uint16_t tpid)
973+
{
974+
SWSS_LOG_ENTER();
975+
sai_status_t status = SAI_STATUS_SUCCESS;
976+
sai_attribute_t attr;
977+
978+
attr.id = SAI_PORT_ATTR_TPID;
979+
980+
attr.value.u16 = (uint16_t)tpid;
981+
982+
status = sai_port_api->set_port_attribute(id, &attr);
983+
if (status != SAI_STATUS_SUCCESS)
984+
{
985+
SWSS_LOG_ERROR("Failed to set TPID 0x%x to port pid:%" PRIx64 ", rv:%d",
986+
attr.value.u16, id, status);
987+
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
988+
if (handle_status != task_success)
989+
{
990+
return parseHandleSaiStatusFailure(handle_status);
991+
}
992+
}
993+
else
994+
{
995+
SWSS_LOG_NOTICE("Set TPID 0x%x to port pid:%" PRIx64, attr.value.u16, id);
996+
}
997+
return true;
998+
}
999+
1000+
9711001
bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t mode)
9721002
{
9731003
SWSS_LOG_ENTER();
@@ -2451,6 +2481,8 @@ void PortsOrch::doPortTask(Consumer &consumer)
24512481
vector<uint32_t> adv_speeds;
24522482
sai_port_interface_type_t interface_type;
24532483
vector<uint32_t> adv_interface_types;
2484+
string tpid_string;
2485+
uint16_t tpid = 0;
24542486

24552487
for (auto i : kfvFieldsValues(t))
24562488
{
@@ -2482,6 +2514,15 @@ void PortsOrch::doPortTask(Consumer &consumer)
24822514
{
24832515
mtu = (uint32_t)stoul(fvValue(i));
24842516
}
2517+
/* Set port TPID */
2518+
if (fvField(i) == "tpid")
2519+
{
2520+
tpid_string = fvValue(i);
2521+
// Need to get rid of the leading 0x
2522+
tpid_string.erase(0,2);
2523+
tpid = (uint16_t)stoi(tpid_string, 0, 16);
2524+
SWSS_LOG_DEBUG("Handling TPID to 0x%x, string value:%s", tpid, tpid_string.c_str());
2525+
}
24852526
/* Set port speed */
24862527
else if (fvField(i) == "speed")
24872528
{
@@ -2914,6 +2955,22 @@ void PortsOrch::doPortTask(Consumer &consumer)
29142955
}
29152956
}
29162957

2958+
if (tpid != 0 && tpid != p.m_tpid)
2959+
{
2960+
SWSS_LOG_DEBUG("Set port %s TPID to 0x%x", alias.c_str(), tpid);
2961+
if (setPortTpid(p.m_port_id, tpid))
2962+
{
2963+
p.m_tpid = tpid;
2964+
m_portList[alias] = p;
2965+
}
2966+
else
2967+
{
2968+
SWSS_LOG_ERROR("Failed to set port %s TPID to 0x%x", alias.c_str(), tpid);
2969+
it++;
2970+
continue;
2971+
}
2972+
}
2973+
29172974
if (!fec_mode.empty())
29182975
{
29192976
if (fec_mode_map.find(fec_mode) != fec_mode_map.end())
@@ -3366,6 +3423,8 @@ void PortsOrch::doLagTask(Consumer &consumer)
33663423
string operation_status;
33673424
uint32_t lag_id = 0;
33683425
int32_t switch_id = -1;
3426+
string tpid_string;
3427+
uint16_t tpid = 0;
33693428

33703429
for (auto i : kfvFieldsValues(t))
33713430
{
@@ -3395,6 +3454,14 @@ void PortsOrch::doLagTask(Consumer &consumer)
33953454
{
33963455
switch_id = stoi(fvValue(i));
33973456
}
3457+
else if (fvField(i) == "tpid")
3458+
{
3459+
tpid_string = fvValue(i);
3460+
// Need to get rid of the leading 0x
3461+
tpid_string.erase(0,2);
3462+
tpid = (uint16_t)stoi(tpid_string, 0, 16);
3463+
SWSS_LOG_DEBUG("reading TPID string:%s to uint16: 0x%x", tpid_string.c_str(), tpid);
3464+
}
33983465
}
33993466

34003467
if (table_name == CHASSIS_APP_LAG_TABLE_NAME)
@@ -3451,6 +3518,23 @@ void PortsOrch::doLagTask(Consumer &consumer)
34513518
updateChildPortsMtu(l, mtu);
34523519
}
34533520

3521+
if (tpid != 0)
3522+
{
3523+
if (tpid != l.m_tpid)
3524+
{
3525+
if(!setLagTpid(l.m_lag_id, tpid))
3526+
{
3527+
SWSS_LOG_ERROR("Failed to set LAG %s TPID 0x%x", alias.c_str(), tpid);
3528+
}
3529+
else
3530+
{
3531+
SWSS_LOG_DEBUG("Set LAG %s TPID to 0x%x", alias.c_str(), tpid);
3532+
l.m_tpid = tpid;
3533+
m_portList[alias] = l;
3534+
}
3535+
}
3536+
}
3537+
34543538
if (!learn_mode.empty() && (l.m_learn_mode != learn_mode))
34553539
{
34563540
if (l.m_bridge_port_id != SAI_NULL_OBJECT_ID)
@@ -4656,6 +4740,35 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
46564740
return true;
46574741
}
46584742

4743+
bool PortsOrch::setLagTpid(sai_object_id_t id, sai_uint16_t tpid)
4744+
{
4745+
SWSS_LOG_ENTER();
4746+
sai_status_t status = SAI_STATUS_SUCCESS;
4747+
sai_attribute_t attr;
4748+
4749+
attr.id = SAI_LAG_ATTR_TPID;
4750+
4751+
attr.value.u16 = (uint16_t)tpid;
4752+
4753+
status = sai_lag_api->set_lag_attribute(id, &attr);
4754+
if (status != SAI_STATUS_SUCCESS)
4755+
{
4756+
SWSS_LOG_ERROR("Failed to set TPID 0x%x to LAG pid:%" PRIx64 ", rv:%d",
4757+
attr.value.u16, id, status);
4758+
task_process_status handle_status = handleSaiSetStatus(SAI_API_LAG, status);
4759+
if (handle_status != task_success)
4760+
{
4761+
return parseHandleSaiStatusFailure(handle_status);
4762+
}
4763+
}
4764+
else
4765+
{
4766+
SWSS_LOG_NOTICE("Set TPID 0x%x to LAG pid:%" PRIx64 , attr.value.u16, id);
4767+
}
4768+
return true;
4769+
}
4770+
4771+
46594772
bool PortsOrch::setCollectionOnLagMember(Port &lagMember, bool enableCollection)
46604773
{
46614774
/* Port must be LAG member */

orchagent/portsorch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class PortsOrch : public Orch, public Subject
247247

248248
bool addLag(string lag, uint32_t spa_id, int32_t switch_id);
249249
bool removeLag(Port lag);
250+
bool setLagTpid(sai_object_id_t id, sai_uint16_t tpid);
250251
bool addLagMember(Port &lag, Port &port, bool enableForwarding);
251252
bool removeLagMember(Port &lag, Port &port);
252253
bool setCollectionOnLagMember(Port &lagMember, bool enableCollection);
@@ -260,6 +261,7 @@ class PortsOrch : public Orch, public Subject
260261
bool setPortAdminStatus(Port &port, bool up);
261262
bool getPortAdminStatus(sai_object_id_t id, bool& up);
262263
bool setPortMtu(sai_object_id_t id, sai_uint32_t mtu);
264+
bool setPortTpid(sai_object_id_t id, sai_uint16_t tpid);
263265
bool setPortPvid (Port &port, sai_uint32_t pvid);
264266
bool getPortPvid(Port &port, sai_uint32_t &pvid);
265267
bool setPortFec(Port &port, sai_port_fec_mode_t mode);

orchagent/switchorch.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector<TableConnector>& connectors, Tabl
4646
Orch::addExecutor(restartCheckNotifier);
4747

4848
initSensorsTable();
49+
querySwitchTpidCapability();
4950
auto executorT = new ExecutableTimer(m_sensorsPollerTimer, this, "ASIC_SENSORS_POLL_TIMER");
5051
Orch::addExecutor(executorT);
5152
}
@@ -486,3 +487,56 @@ void SwitchOrch::set_switch_capability(const std::vector<FieldValueTuple>& value
486487
{
487488
m_switchTable.set("switch", values);
488489
}
490+
491+
void SwitchOrch::querySwitchTpidCapability()
492+
{
493+
SWSS_LOG_ENTER();
494+
// Check if SAI is capable of handling TPID config and store result in StateDB switch capability table
495+
{
496+
vector<FieldValueTuple> fvVector;
497+
sai_status_t status = SAI_STATUS_SUCCESS;
498+
sai_attr_capability_t capability;
499+
500+
// Check if SAI is capable of handling TPID for Port
501+
status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_PORT, SAI_PORT_ATTR_TPID, &capability);
502+
if (status != SAI_STATUS_SUCCESS)
503+
{
504+
SWSS_LOG_WARN("Could not query port TPID capability %d", status);
505+
// Since pre-req of TPID support requires querry capability failed, it means TPID not supported
506+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "false");
507+
}
508+
else
509+
{
510+
if (capability.set_implemented)
511+
{
512+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "true");
513+
}
514+
else
515+
{
516+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "false");
517+
}
518+
SWSS_LOG_NOTICE("port TPID capability %d", capability.set_implemented);
519+
}
520+
// Check if SAI is capable of handling TPID for LAG
521+
status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_LAG, SAI_LAG_ATTR_TPID, &capability);
522+
if (status != SAI_STATUS_SUCCESS)
523+
{
524+
SWSS_LOG_WARN("Could not query LAG TPID capability %d", status);
525+
// Since pre-req of TPID support requires querry capability failed, it means TPID not supported
526+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "false");
527+
}
528+
else
529+
{
530+
if (capability.set_implemented)
531+
{
532+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "true");
533+
}
534+
else
535+
{
536+
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "false");
537+
}
538+
SWSS_LOG_NOTICE("LAG TPID capability %d", capability.set_implemented);
539+
}
540+
set_switch_capability(fvVector);
541+
}
542+
}

0 commit comments

Comments
 (0)