@@ -18,6 +18,10 @@ using swss::DBConnector;
1818using swss::FieldValueTuple;
1919using swss::ProducerTable;
2020
21+ extern sai_switch_api_t *sai_switch_api;
22+
23+ extern sai_object_id_t gSwitchId ;
24+
2125const string FLEX_COUNTER_ENABLE (" enable" );
2226const string FLEX_COUNTER_DISABLE (" disable" );
2327
@@ -89,13 +93,13 @@ FlexCounterManager::FlexCounterManager(
8993 const uint polling_interval,
9094 const bool enabled,
9195 FieldValueTuple fv_plugin) :
92- FlexCounterManager(" FLEX_COUNTER_DB " , group_name, stats_mode,
96+ FlexCounterManager(false , group_name, stats_mode,
9397 polling_interval, enabled, fv_plugin)
9498{
9599}
96100
97101FlexCounterManager::FlexCounterManager (
98- const string& db_name ,
102+ const bool is_gearbox ,
99103 const string& group_name,
100104 const StatsMode stats_mode,
101105 const uint polling_interval,
@@ -106,11 +110,7 @@ FlexCounterManager::FlexCounterManager(
106110 polling_interval(polling_interval),
107111 enabled(enabled),
108112 fv_plugin(fv_plugin),
109- flex_counter_db(new DBConnector(db_name, 0 )),
110- flex_counter_group_table(new ProducerTable(flex_counter_db.get(),
111- FLEX_COUNTER_GROUP_TABLE)),
112- flex_counter_table(new ProducerTable(flex_counter_db.get(),
113- FLEX_COUNTER_TABLE))
113+ is_gearbox(is_gearbox)
114114{
115115 SWSS_LOG_ENTER ();
116116
@@ -125,13 +125,10 @@ FlexCounterManager::~FlexCounterManager()
125125
126126 for (const auto & counter: installed_counters)
127127 {
128- flex_counter_table-> del ( getFlexCounterTableKey (group_name, counter));
128+ stopFlexCounterPolling (counter. second , getFlexCounterTableKey (group_name, counter. first ));
129129 }
130130
131- if (flex_counter_group_table != nullptr )
132- {
133- flex_counter_group_table->del (group_name);
134- }
131+ delFlexCounterGroup (group_name, is_gearbox);
135132
136133 SWSS_LOG_DEBUG (" Deleted flex counter group '%s'." , group_name.c_str ());
137134}
@@ -140,31 +137,21 @@ void FlexCounterManager::applyGroupConfiguration()
140137{
141138 SWSS_LOG_ENTER ();
142139
143- vector<FieldValueTuple> field_values =
144- {
145- FieldValueTuple (STATS_MODE_FIELD, stats_mode_lookup.at (stats_mode)),
146- FieldValueTuple (POLL_INTERVAL_FIELD, std::to_string (polling_interval)),
147- FieldValueTuple (FLEX_COUNTER_STATUS_FIELD, status_lookup.at (enabled))
148- };
149-
150- if (!fvField (fv_plugin).empty ())
151- {
152- field_values.emplace_back (fv_plugin);
153- }
154-
155- flex_counter_group_table->set (group_name, field_values);
140+ setFlexCounterGroupParameter (group_name,
141+ std::to_string (polling_interval),
142+ stats_mode_lookup.at (stats_mode),
143+ fvField (fv_plugin),
144+ fvValue (fv_plugin),
145+ status_lookup.at (enabled),
146+ is_gearbox);
156147}
157148
158149void FlexCounterManager::updateGroupPollingInterval (
159150 const uint polling_interval)
160151{
161152 SWSS_LOG_ENTER ();
162153
163- vector<FieldValueTuple> field_values =
164- {
165- FieldValueTuple (POLL_INTERVAL_FIELD, std::to_string (polling_interval))
166- };
167- flex_counter_group_table->set (group_name, field_values);
154+ setFlexCounterGroupPollInterval (group_name, std::to_string (polling_interval), is_gearbox);
168155
169156 SWSS_LOG_DEBUG (" Set polling interval for flex counter group '%s' to %d ms." ,
170157 group_name.c_str (), polling_interval);
@@ -181,11 +168,7 @@ void FlexCounterManager::enableFlexCounterGroup()
181168 return ;
182169 }
183170
184- vector<FieldValueTuple> field_values =
185- {
186- FieldValueTuple (FLEX_COUNTER_STATUS_FIELD, FLEX_COUNTER_ENABLE)
187- };
188- flex_counter_group_table->set (group_name, field_values);
171+ setFlexCounterGroupOperation (group_name, FLEX_COUNTER_ENABLE, is_gearbox);
189172 enabled = true ;
190173
191174 SWSS_LOG_DEBUG (" Enabling flex counters for group '%s'." ,
@@ -203,11 +186,7 @@ void FlexCounterManager::disableFlexCounterGroup()
203186 return ;
204187 }
205188
206- vector<FieldValueTuple> field_values =
207- {
208- FieldValueTuple (FLEX_COUNTER_STATUS_FIELD, FLEX_COUNTER_DISABLE)
209- };
210- flex_counter_group_table->set (group_name, field_values);
189+ setFlexCounterGroupOperation (group_name, FLEX_COUNTER_DISABLE, is_gearbox);
211190 enabled = false ;
212191
213192 SWSS_LOG_DEBUG (" Disabling flex counters for group '%s'." ,
@@ -219,7 +198,8 @@ void FlexCounterManager::disableFlexCounterGroup()
219198void FlexCounterManager::setCounterIdList (
220199 const sai_object_id_t object_id,
221200 const CounterType counter_type,
222- const unordered_set<string>& counter_stats)
201+ const unordered_set<string>& counter_stats,
202+ const sai_object_id_t switch_id)
223203{
224204 SWSS_LOG_ENTER ();
225205
@@ -231,12 +211,12 @@ void FlexCounterManager::setCounterIdList(
231211 return ;
232212 }
233213
234- std::vector<swss::FieldValueTuple> field_values =
235- {
236- FieldValueTuple (counter_type_it-> second , serializeCounterStats (counter_stats))
237- };
238- flex_counter_table-> set ( getFlexCounterTableKey (group_name, object_id), field_values );
239- installed_counters. insert ( object_id) ;
214+ auto key = getFlexCounterTableKey (group_name, object_id);
215+ auto counter_ids = serializeCounterStats (counter_stats);
216+ auto effective_switch_id = switch_id == SAI_NULL_OBJECT_ID ? gSwitchId : switch_id;
217+
218+ startFlexCounterPolling (effective_switch_id, key, counter_ids, counter_type_it-> second );
219+ installed_counters[ object_id] = effective_switch_id ;
240220
241221 SWSS_LOG_DEBUG (" Updated flex counter id list for object '%" PRIu64 " ' in group '%s'." ,
242222 object_id,
@@ -258,7 +238,8 @@ void FlexCounterManager::clearCounterIdList(const sai_object_id_t object_id)
258238 return ;
259239 }
260240
261- flex_counter_table->del (getFlexCounterTableKey (group_name, object_id));
241+ auto key = getFlexCounterTableKey (group_name, object_id);
242+ stopFlexCounterPolling (installed_counters[object_id], key);
262243 installed_counters.erase (counter_it);
263244
264245 SWSS_LOG_DEBUG (" Cleared flex counter id list for object '%" PRIu64 " ' in group '%s'." ,
@@ -272,7 +253,7 @@ string FlexCounterManager::getFlexCounterTableKey(
272253{
273254 SWSS_LOG_ENTER ();
274255
275- return group_name + flex_counter_table-> getTableNameSeparator () + sai_serialize_object_id (object_id);
256+ return group_name + " : " + sai_serialize_object_id (object_id);
276257}
277258
278259// serializeCounterStats turns a set of stats into a format suitable for FLEX_COUNTER_DB.
0 commit comments