Skip to content

[MSTP] Swss Support #3606

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

Merged
merged 44 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
002a8ef
MSTP SWSS Support
wajahatrazi Apr 15, 2025
f7341b4
MSTP SWSS Support
wajahatrazi Apr 18, 2025
fe02870
Merge branch 'master' into mstp_swss
wajahatrazi Apr 18, 2025
98628f2
Fixing Conflicts 29Apr25
wajahatrazi Apr 29, 2025
6e4e157
Fixing Conflicts - 29Apr25
wajahatrazi Apr 29, 2025
12e70f2
Fixing Conflicts - 29Apr25
wajahatrazi Apr 29, 2025
cc5b795
Fixing Conflicts - 29Apr25
wajahatrazi Apr 29, 2025
9d18cb9
Merge branch 'master' into mstp_swss
muhammadalihussnain Apr 30, 2025
5d50a92
resolve conflicts
muhammadalihussnain Apr 30, 2025
4461afd
typo fix
muhammadalihussnain Apr 30, 2025
100285b
Merge branch 'master' into mstp_swss
muhammadalihussnain May 2, 2025
cacdf7e
Merge branch 'master' into mstp_swss
muhammadalihussnain May 5, 2025
01b9d36
Merge branch 'master' into mstp_swss
muhammadalihussnain May 6, 2025
2cd4965
Merge branch 'master' into mstp_swss
muhammadalihussnain May 7, 2025
b859a78
Merge branch 'master' into mstp_swss
muhammadalihussnain May 10, 2025
340a61e
Merge branch 'master' of github.com:wajahatrazi/sonic-swss into mstp_…
wajahatrazi May 12, 2025
ce45e96
Merge branch 'mstp_swss' of github.com:wajahatrazi/sonic-swss into ms…
wajahatrazi May 12, 2025
282586e
Triggering Pipelines
wajahatrazi May 15, 2025
87f0358
Merge branch 'master' into mstp_swss
muhammadalihussnain Jun 2, 2025
89d2a4a
Merge branch 'master' into mstp_swss
muhammadalihussnain Jun 4, 2025
2edd5c7
Merge branch 'master' into mstp_swss
muhammadalihussnain Jun 10, 2025
cd8a8a1
Merge branch 'master' into mstp_swss
muhammadalihussnain Jun 11, 2025
565176c
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jun 13, 2025
caf721a
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jul 4, 2025
6c583ce
removed the parameters for the default values for del operation
muhammadalihussnain Jul 4, 2025
5606685
removed the parameters for the default values for del operation
muhammadalihussnain Jul 4, 2025
ac4e936
removed the def setting in delete operation
muhammadalihussnain Jul 4, 2025
38e704e
changed time out for the PollingConfig
muhammadalihussnain Jul 9, 2025
34e2968
reverted timeout 40 to 20
muhammadalihussnain Jul 9, 2025
e3c914c
Merge branch 'master' into mstp_swss
muhammadalihussnain Jul 14, 2025
3a877d2
Remove .vscode from Git tracking
muhammadalihussnain Jul 14, 2025
1b1609b
removed syntax error after conflict resolve
muhammadalihussnain Jul 14, 2025
f6eda89
removed .gitignore
muhammadalihussnain Jul 14, 2025
50a5700
removed syntax error after conflict resolve
muhammadalihussnain Jul 14, 2025
3fc65ff
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jul 15, 2025
eacf5a2
Clean up: ignore and untrack .vscode and test binary
muhammadalihussnain Jul 15, 2025
c5ed8ec
Remove unwanted tracked files
muhammadalihussnain Jul 15, 2025
19cba27
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jul 16, 2025
e728421
to revert .gitignore
muhammadalihussnain Jul 16, 2025
b118326
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jul 18, 2025
fa41a1c
Merge branch 'sonic-net:master' into mstp_swss
muhammadalihussnain Jul 21, 2025
f2cbe3e
removed from orchdaemon un related changes
muhammadalihussnain Jul 21, 2025
1a3d92a
removing .vscode
muhammadalihussnain Jul 21, 2025
2e4a06b
removed unwanted changes
muhammadalihussnain Jul 21, 2025
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
463 changes: 425 additions & 38 deletions cfgmgr/stpmgr.cpp

Large diffs are not rendered by default.

115 changes: 84 additions & 31 deletions cfgmgr/stpmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <sys/un.h>
#include <unistd.h>
#include <bitset>
#include <vector>
#include <string>
#include <unordered_set>

#include "dbconnector.h"
#include "netmsg.h"
Expand All @@ -31,9 +34,9 @@
#define MAX_VLANS 4096

// Maximum number of instances supported
#define L2_INSTANCE_MAX MAX_VLANS
#define STP_DEFAULT_MAX_INSTANCES 255
#define INVALID_INSTANCE -1
#define L2_INSTANCE_MAX MAX_VLANS
#define STP_DEFAULT_MAX_INSTANCES 255
#define INVALID_INSTANCE -1

#define GET_FIRST_FREE_INST_ID(_idx) \
while (_idx < (int)l2InstPool.size() && l2InstPool.test(_idx)) ++_idx; \
Expand All @@ -49,7 +52,15 @@
typedef enum L2_PROTO_MODE {
L2_NONE,
L2_PVSTP,
} L2_PROTO_MODE;
L2_MSTP
}L2_PROTO_MODE;


typedef enum LinkType {
AUTO = 0, // Auto
POINT_TO_POINT = 1, // Point-to-point
SHARED = 2 // Shared
} LinkType;

typedef enum STP_MSG_TYPE {
STP_INVALID_MSG,
Expand All @@ -60,6 +71,9 @@ typedef enum STP_MSG_TYPE {
STP_PORT_CONFIG,
STP_VLAN_MEM_CONFIG,
STP_STPCTL_MSG,
STP_MST_GLOBAL_CONFIG,
STP_MST_INST_CONFIG,
STP_MST_INST_PORT_CONFIG,
STP_MAX_MSG
} STP_MSG_TYPE;

Expand Down Expand Up @@ -151,22 +165,26 @@ typedef struct VLAN_ATTR {
uint8_t padding[3];
} ALIGNED(4) VLAN_ATTR;

typedef struct VLAN_LIST{
uint16_t vlan_id;
}VLAN_LIST;

typedef struct STP_PORT_CONFIG_MSG {
uint8_t opcode; // enable/disable
char intf_name[IFNAMSIZ];
uint8_t enabled;
uint8_t root_guard;
uint8_t bpdu_guard;
uint8_t bpdu_guard_do_disable;
uint8_t portfast;
uint8_t uplink_fast;
// Add 2 bytes padding for alignment
uint16_t padding;
int path_cost;
int priority;
int count;
VLAN_ATTR vlan_list[0];
} ALIGNED(4) STP_PORT_CONFIG_MSG;
uint8_t opcode; // enable/disable
char intf_name[IFNAMSIZ];
uint8_t enabled;
uint8_t root_guard;
uint8_t bpdu_guard;
uint8_t bpdu_guard_do_disable;
uint8_t portfast; // PVST only
uint8_t uplink_fast; // PVST only
uint8_t edge_port; // MSTP only
LinkType link_type; // MSTP only
int path_cost;
int priority;
int count;
VLAN_ATTR vlan_list[0];
} STP_PORT_CONFIG_MSG;;

typedef struct STP_VLAN_MEM_CONFIG_MSG {
uint8_t opcode; // enable/disable
Expand All @@ -181,6 +199,32 @@ typedef struct STP_VLAN_MEM_CONFIG_MSG {
int priority;
} ALIGNED(4) STP_VLAN_MEM_CONFIG_MSG;

typedef struct STP_MST_GLOBAL_CONFIG_MSG {
uint8_t opcode; // enable/disable
uint32_t revision_number;
char name[32];
uint8_t forward_delay;
uint8_t hello_time;
uint8_t max_age;
uint8_t max_hops;
}__attribute__ ((packed))STP_MST_GLOBAL_CONFIG_MSG;

typedef struct STP_MST_INST_CONFIG_MSG {
uint8_t opcode; // enable/disable
uint16_t mst_id; // MST instance ID
int priority; // Bridge priority
uint16_t vlan_count; // Number of VLANs in this instance
VLAN_LIST vlan_list[0]; // Flexible array for VLAN IDs
}__attribute__((packed)) STP_MST_INST_CONFIG_MSG;

typedef struct STP_MST_INST_PORT_CONFIG_MSG {
uint8_t opcode; // enable/disable
char intf_name[IFNAMSIZ]; // Interface name
uint16_t mst_id; // MST instance ID
int path_cost; // Path cost
int priority; // Port priority
} __attribute__((packed)) STP_MST_INST_PORT_CONFIG_MSG;

namespace swss {

class StpMgr : public Orch
Expand All @@ -194,7 +238,7 @@ class StpMgr : public Orch
int sendMsgStpd(STP_MSG_TYPE msgType, uint32_t msgLen, void *data);
MacAddress macAddress;
bool isPortInitDone(DBConnector *app_db);
uint16_t getStpMaxInstances(void);
uint16_t getStpMaxInstances(void);

private:
Table m_cfgStpGlobalTable;
Expand All @@ -207,6 +251,9 @@ class StpMgr : public Orch
Table m_stateVlanMemberTable;
Table m_stateLagTable;
Table m_stateStpTable;
Table m_cfgMstGlobalTable;
Table m_cfgMstInstTable;
Table m_cfgMstInstPortTable;

std::bitset<L2_INSTANCE_MAX> l2InstPool;
int stpd_fd;
Expand All @@ -220,6 +267,7 @@ class StpMgr : public Orch
bool stpVlanTask;
bool stpVlanPortTask;
bool stpPortTask;
bool stpMstInstTask;

void doTask(Consumer &consumer);
void doStpGlobalTask(Consumer &consumer);
Expand All @@ -228,6 +276,9 @@ class StpMgr : public Orch
void doStpPortTask(Consumer &consumer);
void doVlanMemUpdateTask(Consumer &consumer);
void doLagMemUpdateTask(Consumer &consumer);
void doStpMstGlobalTask(Consumer &consumer);
void doStpMstInstTask(Consumer &consumer);
void doStpMstInstPortTask(Consumer &consumer);

bool isVlanStateOk(const std::string &alias);
bool isLagStateOk(const std::string &alias);
Expand All @@ -239,17 +290,19 @@ class StpMgr : public Orch
int allocL2Instance(uint32_t vlan_id);
void deallocL2Instance(uint32_t vlan_id);
bool isLagEmpty(const std::string &key);

// The rest of the methods remain unchanged except we replaced the old approach with alignment-based approach
void processStpPortAttr(const std::string op,
std::vector<FieldValueTuple> &tupEntry,
const std::string intfName);
void processStpVlanPortAttr(const std::string op,
uint32_t vlan_id,
const std::string intfName,
std::vector<FieldValueTuple> &tupEntry);
void processStpPortAttr(const std::string op, std::vector<FieldValueTuple>&tupEntry, const std::string intfName);
void processStpVlanPortAttr(const std::string op, uint32_t vlan_id, const std::string intfName,
std::vector<FieldValueTuple>&tupEntry);
void processStpMstInstPortAttr(const std::string op, uint16_t mst_id, const std::string intfName,
std::vector<FieldValueTuple>&tupEntry);
std::vector<uint16_t> parseVlanList(const std::string &vlanStr);
void updateVlanInstanceMap(int instance, const std::vector<uint16_t>&newVlanList, bool operation);
bool isInstanceMapped(uint16_t instance);
std::vector<std::string> getVlanAliasesForInstance(uint16_t instance);


};

} // namespace swss

}
#endif

14 changes: 9 additions & 5 deletions cfgmgr/stpmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ int main(int argc, char **argv)
TableConnector conf_stp_vlan_table(&conf_db, CFG_STP_VLAN_TABLE_NAME);
TableConnector conf_stp_vlan_port_table(&conf_db, CFG_STP_VLAN_PORT_TABLE_NAME);
TableConnector conf_stp_port_table(&conf_db, CFG_STP_PORT_TABLE_NAME);

TableConnector conf_mst_global_table(&conf_db, "STP_MST");
TableConnector conf_mst_inst_table(&conf_db, "STP_MST_INST");
TableConnector conf_mst_inst_port_table(&conf_db, "STP_MST_PORT");
// VLAN DB Tables
TableConnector state_vlan_member_table(&state_db, STATE_VLAN_MEMBER_TABLE_NAME);

// LAG Tables
TableConnector conf_lag_member_table(&conf_db, CFG_LAG_MEMBER_TABLE_NAME);

vector<TableConnector> tables = {
conf_stp_global_table,
conf_stp_vlan_table,
conf_stp_vlan_port_table,
conf_stp_port_table,
conf_lag_member_table,
state_vlan_member_table
state_vlan_member_table,
conf_mst_global_table,
conf_mst_inst_table,
conf_mst_inst_port_table
};


Expand All @@ -64,7 +68,7 @@ int main(int argc, char **argv)
// Open a Unix Domain Socket with STPd for communication
stpmgr.ipcInitStpd();
stpmgr.isPortInitDone(&app_db);

// Get max STP instances from state DB and send to stpd
STP_INIT_READY_MSG msg;
memset(&msg, 0, sizeof(STP_INIT_READY_MSG));
Expand Down Expand Up @@ -116,4 +120,4 @@ int main(int argc, char **argv)
}

return -1;
}
}
5 changes: 3 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ bool OrchDaemon::init()
vector<string> stp_tables = {
APP_STP_VLAN_INSTANCE_TABLE_NAME,
APP_STP_PORT_STATE_TABLE_NAME,
APP_STP_FASTAGEING_FLUSH_TABLE_NAME
APP_STP_FASTAGEING_FLUSH_TABLE_NAME,
APP_STP_INST_PORT_FLUSH_TABLE_NAME
};
gStpOrch = new StpOrch(m_applDb, m_stateDb, stp_tables);
gDirectory.set(gStpOrch);
Expand Down Expand Up @@ -1316,4 +1317,4 @@ bool DpuOrchDaemon::init()
addOrchList(dash_port_map_orch);

return true;
}
}
51 changes: 28 additions & 23 deletions orchagent/p4orch/tests/mock_sai_stp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ extern "C"
{
#include "sai.h"
}

// Mock class for SAI STP APIs
class MockSaiStp {
public:
// Mock method for creating an STP instance
MOCK_METHOD4(create_stp,
sai_status_t(_Out_ sai_object_id_t *stp_instance_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
sai_status_t(_Out_ sai_object_id_t *stp_instance_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list));

// Mock method for removing an STP instance
MOCK_METHOD1(remove_stp, sai_status_t(_In_ sai_object_id_t stp_instance_id));

// Mock method for setting STP instance attributes
MOCK_METHOD2(set_stp_attribute,
sai_status_t(_In_ sai_object_id_t stp_instance_id,
sai_status_t(_In_ sai_object_id_t stp_instance_id,
_In_ const sai_attribute_t *attr));

// Mock method for getting STP instance attributes
MOCK_METHOD3(get_stp_attribute,
sai_status_t(_Out_ sai_object_id_t stp_instance_id,
_In_ uint32_t attr_count,
sai_status_t(_Out_ sai_object_id_t stp_instance_id,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list));

// Mock method for creating an STP port
MOCK_METHOD4(create_stp_port,
sai_status_t(_Out_ sai_object_id_t *stp_port_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
sai_status_t(_Out_ sai_object_id_t *stp_port_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list));

// Mock method for removing an STP port
Expand All @@ -44,22 +44,28 @@ class MockSaiStp {

// Mock method for setting STP port attributes
MOCK_METHOD2(set_stp_port_attribute,
sai_status_t(_Out_ sai_object_id_t stp_port_id,
sai_status_t(_Out_ sai_object_id_t stp_port_id,
_In_ const sai_attribute_t *attr));

// Mock method for getting STP port attributes
MOCK_METHOD3(get_stp_port_attribute,
sai_status_t(_Out_ sai_object_id_t stp_port_id,
sai_status_t(_Out_ sai_object_id_t stp_port_id,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list));

// Mock method for flushing FDB entries
MOCK_METHOD3(flush_fdb_entries,
sai_status_t(_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list));
};

// Global mock object for SAI STP APIs
MockSaiStp *mock_sai_stp;

sai_status_t mock_create_stp(_Out_ sai_object_id_t *stp_instance_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
sai_status_t mock_create_stp(_Out_ sai_object_id_t *stp_instance_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
return mock_sai_stp->create_stp(stp_instance_id, switch_id, attr_count, attr_list);
Expand All @@ -75,14 +81,14 @@ sai_status_t mock_set_stp_attribute(_In_ sai_object_id_t stp_instance_id, _In_ c
return mock_sai_stp->set_stp_attribute(stp_instance_id, attr);
}

sai_status_t mock_get_stp_attribute(_Out_ sai_object_id_t stp_instance_id,
sai_status_t mock_get_stp_attribute(_Out_ sai_object_id_t stp_instance_id,
_In_ uint32_t attr_count, _Inout_ sai_attribute_t *attr_list)
{
return mock_sai_stp->get_stp_attribute(stp_instance_id, attr_count, attr_list);
}
sai_status_t mock_create_stp_port(_Out_ sai_object_id_t *stp_port_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
sai_status_t mock_create_stp_port(_Out_ sai_object_id_t *stp_port_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
return mock_sai_stp->create_stp_port(stp_port_id, switch_id,attr_count, attr_list);
Expand All @@ -93,18 +99,17 @@ sai_status_t mock_remove_stp_port(_In_ sai_object_id_t stp_port_id)
return mock_sai_stp->remove_stp_port(stp_port_id);
}

sai_status_t mock_set_stp_port_attribute(_In_ sai_object_id_t stp_port_id,
sai_status_t mock_set_stp_port_attribute(_In_ sai_object_id_t stp_port_id,
_In_ const sai_attribute_t *attr)
{
return mock_sai_stp->set_stp_port_attribute(stp_port_id, attr);
}

sai_status_t mock_get_stp_port_attribute(_Out_ sai_object_id_t stp_port_id,
sai_status_t mock_get_stp_port_attribute(_Out_ sai_object_id_t stp_port_id,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list)
_Inout_ sai_attribute_t *attr_list)
{
return mock_sai_stp->get_stp_port_attribute(stp_port_id, attr_count, attr_list);
}

#endif // MOCK_SAI_STP_H

Loading
Loading