@@ -31,6 +31,8 @@ SflowMgr::SflowMgr(DBConnector *cfgDb, DBConnector *appDb, const vector<string>
31
31
{
32
32
m_intfAllConf = true ;
33
33
m_gEnable = false ;
34
+ m_gDirection = " rx" ;
35
+ m_intfAllDir = " rx" ;
34
36
}
35
37
36
38
void SflowMgr::sflowHandleService (bool enable)
@@ -85,9 +87,11 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
85
87
new_port = true ;
86
88
port_info.local_rate_cfg = false ;
87
89
port_info.local_admin_cfg = false ;
90
+ port_info.local_dir_cfg = false ;
88
91
port_info.speed = SFLOW_ERROR_SPEED_STR;
89
92
port_info.rate = " " ;
90
93
port_info.admin = " " ;
94
+ port_info.dir = " " ;
91
95
m_sflowPortConfMap[key] = port_info;
92
96
}
93
97
@@ -106,13 +110,19 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
106
110
speed_change = true ;
107
111
}
108
112
113
+ string def_dir = " rx" ;
114
+ if (m_sflowPortConfMap[key].dir != def_dir && !m_sflowPortConfMap[key].local_dir_cfg )
115
+ {
116
+ m_sflowPortConfMap[key].dir = def_dir;
117
+ }
118
+
109
119
if (m_gEnable && m_intfAllConf)
110
120
{
111
121
// If the Local rate Conf is already present, dont't override it even though the speed is changed
112
122
if (new_port || (speed_change && !m_sflowPortConfMap[key].local_rate_cfg ))
113
123
{
114
124
vector<FieldValueTuple> fvs;
115
- sflowGetGlobalInfo (fvs, m_sflowPortConfMap[key].speed );
125
+ sflowGetGlobalInfo (fvs, m_sflowPortConfMap[key].speed , m_sflowPortConfMap[key]. dir );
116
126
m_appSflowSessionTable.set (key, fvs);
117
127
}
118
128
}
@@ -123,7 +133,8 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
123
133
if (sflowPortConf != m_sflowPortConfMap.end ())
124
134
{
125
135
bool local_cfg = m_sflowPortConfMap[key].local_rate_cfg ||
126
- m_sflowPortConfMap[key].local_admin_cfg ;
136
+ m_sflowPortConfMap[key].local_admin_cfg ||
137
+ m_sflowPortConfMap[key].local_dir_cfg ;
127
138
128
139
m_sflowPortConfMap.erase (key);
129
140
if ((m_intfAllConf && m_gEnable) || local_cfg)
@@ -136,25 +147,31 @@ void SflowMgr::sflowUpdatePortInfo(Consumer &consumer)
136
147
}
137
148
}
138
149
139
- void SflowMgr::sflowHandleSessionAll (bool enable)
150
+ void SflowMgr::sflowHandleSessionAll (bool enable, string direction )
140
151
{
141
152
for (auto it: m_sflowPortConfMap)
142
153
{
143
154
if (enable)
144
155
{
145
156
vector<FieldValueTuple> fvs;
146
- if (it.second .local_rate_cfg || it.second .local_admin_cfg )
157
+ if (it.second .local_rate_cfg || it.second .local_admin_cfg || it. second . local_dir_cfg )
147
158
{
148
159
sflowGetPortInfo (fvs, it.second );
149
160
/* Use global admin state if there is not a local one */
150
161
if (!it.second .local_admin_cfg ) {
151
162
FieldValueTuple fv1 (" admin_state" , " up" );
152
163
fvs.push_back (fv1);
153
164
}
165
+
166
+ /* Use global sample direction state if there is not a local one */
167
+ if (!it.second .local_dir_cfg ) {
168
+ FieldValueTuple fv2 (" sample_direction" , direction);
169
+ fvs.push_back (fv2);
170
+ }
154
171
}
155
172
else
156
173
{
157
- sflowGetGlobalInfo (fvs, it.second .speed );
174
+ sflowGetGlobalInfo (fvs, it.second .speed , direction );
158
175
}
159
176
m_appSflowSessionTable.set (it.first , fvs);
160
177
}
@@ -169,7 +186,7 @@ void SflowMgr::sflowHandleSessionLocal(bool enable)
169
186
{
170
187
for (auto it: m_sflowPortConfMap)
171
188
{
172
- if (it.second .local_admin_cfg || it.second .local_rate_cfg )
189
+ if (it.second .local_admin_cfg || it.second .local_rate_cfg || it. second . local_dir_cfg )
173
190
{
174
191
vector<FieldValueTuple> fvs;
175
192
sflowGetPortInfo (fvs, it.second );
@@ -185,7 +202,7 @@ void SflowMgr::sflowHandleSessionLocal(bool enable)
185
202
}
186
203
}
187
204
188
- void SflowMgr::sflowGetGlobalInfo (vector<FieldValueTuple> &fvs, string speed)
205
+ void SflowMgr::sflowGetGlobalInfo (vector<FieldValueTuple> &fvs, string speed, string dir )
189
206
{
190
207
string rate;
191
208
FieldValueTuple fv1 (" admin_state" , " up" );
@@ -201,6 +218,9 @@ void SflowMgr::sflowGetGlobalInfo(vector<FieldValueTuple> &fvs, string speed)
201
218
}
202
219
FieldValueTuple fv2 (" sample_rate" ,rate);
203
220
fvs.push_back (fv2);
221
+
222
+ FieldValueTuple fv3 (" sample_direction" ,dir);
223
+ fvs.push_back (fv3);
204
224
}
205
225
206
226
void SflowMgr::sflowGetPortInfo (vector<FieldValueTuple> &fvs, SflowPortInfo &local_info)
@@ -213,6 +233,12 @@ void SflowMgr::sflowGetPortInfo(vector<FieldValueTuple> &fvs, SflowPortInfo &loc
213
233
214
234
FieldValueTuple fv2 (" sample_rate" , local_info.rate );
215
235
fvs.push_back (fv2);
236
+
237
+ if (local_info.local_dir_cfg )
238
+ {
239
+ FieldValueTuple fv3 (" sample_direction" , local_info.dir );
240
+ fvs.push_back (fv3);
241
+ }
216
242
}
217
243
218
244
void SflowMgr::sflowCheckAndFillValues (string alias, vector<FieldValueTuple> &values,
@@ -221,6 +247,7 @@ void SflowMgr::sflowCheckAndFillValues(string alias, vector<FieldValueTuple> &va
221
247
string rate;
222
248
bool admin_present = false ;
223
249
bool rate_present = false ;
250
+ bool dir_present = false ;
224
251
225
252
for (auto i : values)
226
253
{
@@ -240,6 +267,14 @@ void SflowMgr::sflowCheckAndFillValues(string alias, vector<FieldValueTuple> &va
240
267
FieldValueTuple fv (fvField (i), fvValue (i));
241
268
fvs.push_back (fv);
242
269
}
270
+ if (fvField (i) == " sample_direction" )
271
+ {
272
+ dir_present = true ;
273
+ m_sflowPortConfMap[alias].dir = fvValue (i);
274
+ m_sflowPortConfMap[alias].local_dir_cfg = true ;
275
+ FieldValueTuple fv (fvField (i), fvValue (i));
276
+ fvs.push_back (fv);
277
+ }
243
278
if (fvField (i) == " NULL" )
244
279
{
245
280
continue ;
@@ -282,6 +317,18 @@ void SflowMgr::sflowCheckAndFillValues(string alias, vector<FieldValueTuple> &va
282
317
FieldValueTuple fv (" admin_state" , m_sflowPortConfMap[alias].admin );
283
318
fvs.push_back (fv);
284
319
}
320
+
321
+ if (!dir_present)
322
+ {
323
+ if (m_sflowPortConfMap[alias].dir == " " )
324
+ {
325
+ /* By default direction is set to global, if not set explicitly */
326
+ m_sflowPortConfMap[alias].dir = m_gDirection;
327
+ }
328
+ m_sflowPortConfMap[alias].local_dir_cfg = false ;
329
+ FieldValueTuple fv (" sample_direction" , m_sflowPortConfMap[alias].dir );
330
+ fvs.push_back (fv);
331
+ }
285
332
}
286
333
287
334
void SflowMgr::doTask (Consumer &consumer)
@@ -309,51 +356,92 @@ void SflowMgr::doTask(Consumer &consumer)
309
356
{
310
357
if (table == CFG_SFLOW_TABLE_NAME)
311
358
{
359
+ SWSS_LOG_DEBUG (" Current Cfg admin %d dir %s " , (unsigned int )m_gEnable, m_gDirection.c_str ());
360
+ bool enable = false ;
361
+ string direction = " rx" ;
312
362
for (auto i : values)
313
363
{
314
364
if (fvField (i) == " admin_state" )
315
365
{
316
- bool enable = false ;
317
366
if (fvValue (i) == " up" )
318
367
{
319
368
enable = true ;
320
369
}
321
- if (enable == m_gEnable)
322
- {
323
- break ;
324
- }
325
- m_gEnable = enable;
326
- sflowHandleService (enable);
327
- if (m_intfAllConf)
328
- {
329
- sflowHandleSessionAll (enable);
330
- }
331
- sflowHandleSessionLocal (enable);
370
+ }
371
+ else if (fvField (i) == " sample_direction" )
372
+ {
373
+ direction = fvValue (i);
332
374
}
333
375
}
376
+
377
+ if (direction != m_gDirection)
378
+ {
379
+ m_gDirection = direction;
380
+ }
381
+
382
+ if (m_gEnable != enable)
383
+ {
384
+ m_gEnable = enable;
385
+ sflowHandleService (enable);
386
+ }
387
+
388
+ if (m_intfAllConf)
389
+ {
390
+ sflowHandleSessionAll (m_gEnable, m_gDirection);
391
+ }
392
+
393
+ sflowHandleSessionLocal (m_gEnable);
334
394
m_appSflowTable.set (key, values);
395
+
396
+ SWSS_LOG_DEBUG (" New config admin %d dir %s " , (unsigned int )m_gEnable, m_gDirection.c_str ());
335
397
}
336
398
else if (table == CFG_SFLOW_SESSION_TABLE_NAME)
337
399
{
338
400
if (key == " all" )
339
401
{
402
+ SWSS_LOG_DEBUG (" current config gAdmin %d dir %s intfAllEna %d intfAllDir %s" ,
403
+ (unsigned int )m_gEnable, m_gDirection.c_str (),
404
+ (unsigned int )m_intfAllConf, m_intfAllDir.c_str ());
405
+
406
+ string direction = m_intfAllDir;
407
+ bool enable = m_intfAllConf;
340
408
for (auto i : values)
341
409
{
342
410
if (fvField (i) == " admin_state" )
343
411
{
344
- bool enable = false ;
345
-
346
412
if (fvValue (i) == " up" )
347
413
{
348
414
enable = true ;
349
415
}
350
- if ((enable != m_intfAllConf) && (m_gEnable) )
416
+ else if (fvValue (i) == " down " )
351
417
{
352
- sflowHandleSessionAll ( enable) ;
418
+ enable = false ;
353
419
}
354
- m_intfAllConf = enable;
355
420
}
421
+ else if (fvField (i) == " sample_direction" )
422
+ {
423
+ direction = fvValue (i);
424
+ }
425
+ }
426
+
427
+ if (m_intfAllDir != direction)
428
+ {
429
+ m_intfAllDir = direction;
430
+ }
431
+
432
+ if (enable != m_intfAllConf)
433
+ {
434
+ m_intfAllConf = enable;
435
+ }
436
+
437
+ if (m_gEnable)
438
+ {
439
+ sflowHandleSessionAll (m_intfAllConf, m_intfAllDir);
356
440
}
441
+
442
+ SWSS_LOG_DEBUG (" New config gAdmin %d dir %s intfAllEna %d intfAllDir %s" ,
443
+ (unsigned int )m_gEnable, m_gDirection.c_str (),
444
+ (unsigned int )m_intfAllConf, m_intfAllDir.c_str ());
357
445
}
358
446
else
359
447
{
@@ -380,10 +468,11 @@ void SflowMgr::doTask(Consumer &consumer)
380
468
if (m_gEnable)
381
469
{
382
470
sflowHandleService (false );
383
- sflowHandleSessionAll (false );
471
+ sflowHandleSessionAll (false , " " );
384
472
sflowHandleSessionLocal (false );
385
473
}
386
474
m_gEnable = false ;
475
+ m_gDirection = " rx" ;
387
476
m_appSflowTable.del (key);
388
477
}
389
478
else if (table == CFG_SFLOW_SESSION_TABLE_NAME)
@@ -394,7 +483,7 @@ void SflowMgr::doTask(Consumer &consumer)
394
483
{
395
484
if (m_gEnable)
396
485
{
397
- sflowHandleSessionAll (true );
486
+ sflowHandleSessionAll (true , m_gDirection );
398
487
}
399
488
}
400
489
m_intfAllConf = true ;
@@ -404,14 +493,16 @@ void SflowMgr::doTask(Consumer &consumer)
404
493
m_appSflowSessionTable.del (key);
405
494
m_sflowPortConfMap[key].local_rate_cfg = false ;
406
495
m_sflowPortConfMap[key].local_admin_cfg = false ;
496
+ m_sflowPortConfMap[key].local_dir_cfg = false ;
407
497
m_sflowPortConfMap[key].rate = " " ;
408
498
m_sflowPortConfMap[key].admin = " " ;
499
+ m_sflowPortConfMap[key].dir = " " ;
409
500
410
501
/* If Global configured, set global session on port after local config is deleted */
411
502
if (m_intfAllConf)
412
503
{
413
504
vector<FieldValueTuple> fvs;
414
- sflowGetGlobalInfo (fvs, m_sflowPortConfMap[key].speed );
505
+ sflowGetGlobalInfo (fvs, m_sflowPortConfMap[key].speed , m_intfAllDir );
415
506
m_appSflowSessionTable.set (key,fvs);
416
507
}
417
508
}
0 commit comments