Skip to content

Commit 4d9aa18

Browse files
kcudniklguohan
authored andcommitted
Add missing object types to virtual switch (sonic-net#364)
Refactor common code
1 parent 1fdaf47 commit 4d9aa18

22 files changed

+1613
-324
lines changed

meta/sai_meta.cpp

+1,130-10
Large diffs are not rendered by default.

meta/sai_meta.h

+40-68
Original file line numberDiff line numberDiff line change
@@ -84,74 +84,46 @@ extern sai_status_t meta_sai_get_stats_oid(
8484
_Inout_ uint64_t *counter_list,
8585
_In_ sai_get_generic_stats_fn<T> get);
8686

87-
// META FDB
88-
89-
extern sai_status_t meta_sai_create_fdb_entry(
90-
_In_ const sai_fdb_entry_t* fdb_entry,
91-
_In_ uint32_t attr_count,
92-
_In_ const sai_attribute_t *attr_list,
93-
_In_ sai_create_fdb_entry_fn create);
94-
95-
extern sai_status_t meta_sai_remove_fdb_entry(
96-
_In_ const sai_fdb_entry_t* fdb_entry,
97-
_In_ sai_remove_fdb_entry_fn remove);
98-
99-
extern sai_status_t meta_sai_set_fdb_entry(
100-
_In_ const sai_fdb_entry_t* fdb_entry,
101-
_In_ const sai_attribute_t *attr,
102-
_In_ sai_set_fdb_entry_attribute_fn set);
103-
104-
extern sai_status_t meta_sai_get_fdb_entry(
105-
_In_ const sai_fdb_entry_t* fdb_entry,
106-
_In_ uint32_t attr_count,
107-
_Inout_ sai_attribute_t *attr_list,
108-
_In_ sai_get_fdb_entry_attribute_fn get);
109-
110-
// META NEIGHBOR
111-
112-
extern sai_status_t meta_sai_create_neighbor_entry(
113-
_In_ const sai_neighbor_entry_t* neighbor_entry,
114-
_In_ uint32_t attr_count,
115-
_In_ const sai_attribute_t *attr_list,
116-
_In_ sai_create_neighbor_entry_fn create);
117-
118-
extern sai_status_t meta_sai_remove_neighbor_entry(
119-
_In_ const sai_neighbor_entry_t* neighbor_entry,
120-
_In_ sai_remove_neighbor_entry_fn remove);
121-
122-
extern sai_status_t meta_sai_set_neighbor_entry(
123-
_In_ const sai_neighbor_entry_t* neighbor_entry,
124-
_In_ const sai_attribute_t *attr,
125-
_In_ sai_set_neighbor_entry_attribute_fn set);
126-
127-
extern sai_status_t meta_sai_get_neighbor_entry(
128-
_In_ const sai_neighbor_entry_t* neighbor_entry,
129-
_In_ uint32_t attr_count,
130-
_Inout_ sai_attribute_t *attr_list,
131-
_In_ sai_get_neighbor_entry_attribute_fn get);
132-
133-
// META ROUTE
134-
135-
extern sai_status_t meta_sai_create_route_entry(
136-
_In_ const sai_route_entry_t* route_entry,
137-
_In_ uint32_t attr_count,
138-
_In_ const sai_attribute_t *attr_list,
139-
_In_ sai_create_route_entry_fn create);
140-
141-
extern sai_status_t meta_sai_remove_route_entry(
142-
_In_ const sai_route_entry_t* route_entry,
143-
_In_ sai_remove_route_entry_fn remove);
144-
145-
extern sai_status_t meta_sai_set_route_entry(
146-
_In_ const sai_route_entry_t* route_entry,
147-
_In_ const sai_attribute_t *attr,
148-
_In_ sai_set_route_entry_attribute_fn set);
149-
150-
extern sai_status_t meta_sai_get_route_entry(
151-
_In_ const sai_route_entry_t* route_entry,
152-
_In_ uint32_t attr_count,
153-
_Inout_ sai_attribute_t *attr_list,
154-
_In_ sai_get_route_entry_attribute_fn get);
87+
// META ENTRY QUAD
88+
89+
#define META_CREATE_ENTRY(ot) \
90+
extern sai_status_t meta_sai_create_ ## ot( \
91+
_In_ const sai_ ## ot ## _t* ot, \
92+
_In_ uint32_t attr_count, \
93+
_In_ const sai_attribute_t *attr_list, \
94+
_In_ sai_create_ ## ot ## _fn create);
95+
96+
#define META_REMOVE_ENTRY(ot) \
97+
extern sai_status_t meta_sai_remove_ ## ot( \
98+
_In_ const sai_ ## ot ## _t* ot, \
99+
_In_ sai_remove_ ## ot ##_fn remove);
100+
101+
#define META_SET_ENTRY(ot) \
102+
extern sai_status_t meta_sai_set_ ## ot( \
103+
_In_ const sai_ ## ot ## _t* ot, \
104+
_In_ const sai_attribute_t *attr, \
105+
_In_ sai_set_ ## ot ## _attribute_fn set);
106+
107+
#define META_GET_ENTRY(ot) \
108+
extern sai_status_t meta_sai_get_ ## ot( \
109+
_In_ const sai_ ## ot ## _t* ot, \
110+
_In_ uint32_t attr_count, \
111+
_Inout_ sai_attribute_t *attr_list, \
112+
_In_ sai_get_ ## ot ## _attribute_fn get);
113+
114+
#define META_QUAD_ENTRY(ot) \
115+
META_CREATE_ENTRY(ot); \
116+
META_REMOVE_ENTRY(ot); \
117+
META_SET_ENTRY(ot); \
118+
META_GET_ENTRY(ot)
119+
120+
META_QUAD_ENTRY(fdb_entry);
121+
META_QUAD_ENTRY(inseg_entry);
122+
META_QUAD_ENTRY(ipmc_entry);
123+
META_QUAD_ENTRY(l2mc_entry);
124+
META_QUAD_ENTRY(mcast_fdb_entry);
125+
META_QUAD_ENTRY(neighbor_entry);
126+
META_QUAD_ENTRY(route_entry);
155127

156128
// NOTIFICATIONS
157129

meta/sai_serialize.h

+34
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ std::string sai_serialize_neighbor_entry(
4343
std::string sai_serialize_route_entry(
4444
_In_ const sai_route_entry_t &route_entry);
4545

46+
std::string sai_serialize_inseg_entry(
47+
_In_ const sai_inseg_entry_t &inseg_entry);
48+
49+
std::string sai_serialize_l2mc_entry(
50+
_In_ const sai_l2mc_entry_t &l2mc_entry);
51+
52+
std::string sai_serialize_ipmc_entry(
53+
_In_ const sai_ipmc_entry_t &ipmc_entry);
54+
55+
std::string sai_serialize_mcast_fdb_entry(
56+
_In_ const sai_mcast_fdb_entry_t &mcast_fdb_entry);
57+
4658
std::string sai_serialize_fdb_entry(
4759
_In_ const sai_fdb_entry_t &fdb_entry);
4860

@@ -117,6 +129,12 @@ std::string sai_serialize_mac(
117129
std::string sai_serialize_port_oper_status(
118130
_In_ sai_port_oper_status_t status);
119131

132+
std::string sai_serialize_l2mc_entry_type(
133+
_In_ const sai_l2mc_entry_type_t type);
134+
135+
std::string sai_serialize_ipmc_entry_type(
136+
_In_ const sai_ipmc_entry_type_t type);
137+
120138
// serialize ntf
121139

122140
std::string sai_serialize_fdb_event_ntf(
@@ -171,6 +189,22 @@ void sai_deserialize_route_entry(
171189
_In_ const std::string& s,
172190
_In_ sai_route_entry_t &route_entry);
173191

192+
void sai_deserialize_inseg_entry(
193+
_In_ const std::string& s,
194+
_In_ sai_inseg_entry_t &inseg_entry);
195+
196+
void sai_deserialize_l2mc_entry(
197+
_In_ const std::string& s,
198+
_In_ sai_l2mc_entry_t &l2mc_entry);
199+
200+
void sai_deserialize_ipmc_entry(
201+
_In_ const std::string& s,
202+
_In_ sai_ipmc_entry_t &ipmc_entry);
203+
204+
void sai_deserialize_mcast_fdb_entry(
205+
_In_ const std::string& s,
206+
_In_ sai_mcast_fdb_entry_t &mcast_fdb_entry);
207+
174208
void sai_deserialize_vlan_id(
175209
_In_ const std::string& s,
176210
_In_ sai_vlan_id_t& vlan_id);

meta/saiserialize.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,65 @@ std::string sai_serialize_route_entry(
709709
return j.dump();
710710
}
711711

712+
std::string sai_serialize_ipmc_entry(
713+
_In_ const sai_ipmc_entry_t& ipmc_entry)
714+
{
715+
SWSS_LOG_ENTER();
716+
717+
json j;
718+
719+
j["switch_id"] = sai_serialize_object_id(ipmc_entry.switch_id);
720+
j["vr_id"] = sai_serialize_object_id(ipmc_entry.vr_id);
721+
j["type"] = sai_serialize_ipmc_entry_type(ipmc_entry.type);
722+
j["destination"] = sai_serialize_ip_address(ipmc_entry.destination);
723+
j["sourte"] = sai_serialize_ip_address(ipmc_entry.source);
724+
725+
return j.dump();
726+
}
727+
728+
std::string sai_serialize_l2mc_entry(
729+
_In_ const sai_l2mc_entry_t& l2mc_entry)
730+
{
731+
SWSS_LOG_ENTER();
732+
733+
json j;
734+
735+
j["switch_id"] = sai_serialize_object_id(l2mc_entry.switch_id);
736+
j["bv_id"] = sai_serialize_object_id(l2mc_entry.bv_id);
737+
j["type"] = sai_serialize_l2mc_entry_type(l2mc_entry.type);
738+
j["destination"] = sai_serialize_ip_address(l2mc_entry.destination);
739+
j["sourte"] = sai_serialize_ip_address(l2mc_entry.source);
740+
741+
return j.dump();
742+
}
743+
744+
std::string sai_serialize_mcast_fdb_entry(
745+
_In_ const sai_mcast_fdb_entry_t& mcast_fdb_entry)
746+
{
747+
SWSS_LOG_ENTER();
748+
749+
json j;
750+
751+
j["switch_id"] = sai_serialize_object_id(mcast_fdb_entry.switch_id);
752+
j["bv_id"] = sai_serialize_object_id(mcast_fdb_entry.bv_id);
753+
j["mac_address"] = sai_serialize_mac(mcast_fdb_entry.mac_address);
754+
755+
return j.dump();
756+
}
757+
758+
std::string sai_serialize_inseg_entry(
759+
_In_ const sai_inseg_entry_t& inseg_entry)
760+
{
761+
SWSS_LOG_ENTER();
762+
763+
json j;
764+
765+
j["switch_id"] = sai_serialize_object_id(inseg_entry.switch_id);
766+
j["label"] = sai_serialize_number(inseg_entry.label);
767+
768+
return j.dump();
769+
}
770+
712771
std::string sai_serialize_fdb_entry(
713772
_In_ const sai_fdb_entry_t& fdb_entry)
714773
{
@@ -723,6 +782,22 @@ std::string sai_serialize_fdb_entry(
723782
return j.dump();
724783
}
725784

785+
std::string sai_serialize_l2mc_entry_type(
786+
_In_ const sai_l2mc_entry_type_t type)
787+
{
788+
SWSS_LOG_ENTER();
789+
790+
return sai_serialize_enum(type, &sai_metadata_enum_sai_l2mc_entry_type_t);
791+
}
792+
793+
std::string sai_serialize_ipmc_entry_type(
794+
_In_ const sai_ipmc_entry_type_t type)
795+
{
796+
SWSS_LOG_ENTER();
797+
798+
return sai_serialize_enum(type, &sai_metadata_enum_sai_ipmc_entry_type_t);
799+
}
800+
726801
std::string sai_serialize_port_stat(
727802
_In_ const sai_port_stat_t counter)
728803
{

0 commit comments

Comments
 (0)