forked from sonic-net/sonic-sairedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncd.cpp
More file actions
3231 lines (2524 loc) · 92.8 KB
/
Copy pathsyncd.cpp
File metadata and controls
3231 lines (2524 loc) · 92.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "syncd.h"
#include "syncd_saiswitch.h"
#include "sairedis.h"
#include "syncd_pfc_watchdog.h"
#include "swss/tokenize.h"
#include <limits.h>
#include <iostream>
#include <map>
/**
* @brief Global mutex for thread synchronization
*
* Purpose of this mutex is to synchronize multiple threads like main thread,
* counters and notifications as well as all operations which require multiple
* Redis DB access.
*
* For example: query DB for next VID id number, and then put map RID and VID
* to Redis. From syncd point of view this entire operation should be atomic
* and no other thread should access DB or make assumption on previous
* information until entire operation will finish.
*/
std::mutex g_mutex;
std::shared_ptr<swss::RedisClient> g_redisClient;
std::shared_ptr<swss::ProducerTable> getResponse;
std::shared_ptr<swss::NotificationProducer> notifications;
/*
* TODO: Those are hard coded values for mlnx integration for v1.0.1 they need
* to be updated.
*
* Also DEVICE_MAC_ADDRESS is not present in saiswitch.h
*/
std::map<std::string, std::string> gProfileMap;
/**
* @brief Contais map of all created switches.
*
* This syncd implementation supports only one switch but it's writeen in
* a way that could be excented to use multple switches in t he future, some
* refactoring needs to be made in marked places.
*
* To support multiple switches VIDTORID and RIDTOVID db entries needs to be
* made per switch like HIDDEN and LANES. Best way is to wrap vid/rid map to
* functions that will return right key.
*
* Key is switch VID.
*/
std::map<sai_object_id_t, std::shared_ptr<SaiSwitch>> switches;
/**
* @brief set of objects removed by user when we are in init view mode. Those
* could be vlan members, bridge ports etc.
*
* We need this list to later on not put them back to temp view mode when doing
* populate existing objects in apply view mode.
*
* Object ids here a VIDs.
*/
std::set<sai_object_id_t> initViewRemovedVidSet;
/*
* By default we are in APPLY mode.
*/
volatile bool g_asicInitViewMode = false;
struct cmdOptions
{
int countersThreadIntervalInSeconds;
bool diagShell;
bool useTempView;
int startType;
bool disableCountersThread;
bool disableExitSleep;
std::string profileMapFile;
#ifdef SAITHRIFT
bool run_rpc_server;
std::string portMapFile;
#endif // SAITHRIFT
~cmdOptions() {}
};
cmdOptions options;
bool isInitViewMode()
{
SWSS_LOG_ENTER();
return g_asicInitViewMode && options.useTempView;
}
bool g_veryFirstRun = false;
void exit_and_notify(int status) __attribute__ ((__noreturn__));
void exit_and_notify(
_In_ int status)
{
SWSS_LOG_ENTER();
try
{
if (notifications != NULL)
{
std::vector<swss::FieldValueTuple> entry;
SWSS_LOG_NOTICE("sending switch_shutdown_request notification to OA");
notifications->send("switch_shutdown_request", "", entry);
SWSS_LOG_NOTICE("notification send successfull");
}
}
catch(const std::exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
catch(...)
{
SWSS_LOG_ERROR("Unknown runtime error");
}
if (options.disableExitSleep)
{
exit(status);
}
SWSS_LOG_WARN("sleep forever to keep data plane active");
while (true)
{
sleep(UINT_MAX);
SWSS_LOG_NOTICE("sleep ended, sleeping again");
}
}
void sai_diag_shell(
_In_ sai_object_id_t switch_id)
{
SWSS_LOG_ENTER();
sai_status_t status;
/*
* This is currently blocking API on broadcom, it will block untill we exit
* shell.
*/
while (true)
{
sai_attribute_t attr;
attr.id = SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE;
attr.value.booldata = true;
status = sai_metadata_sai_switch_api->set_switch_attribute(switch_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to enable switch shell: %s",
sai_serialize_status(status).c_str());
return;
}
sleep(1);
}
}
/*
* Defined bit position on sairedis VID where object type and switch id is
* located.
*/
#define OT_POSITION 48
#define SWID_POSITION 56
/*
* NOTE: those redis functions could go to librediscommon etc so syncd could
* link against it, so we don't have to duplicate code.
*/
sai_object_id_t redis_construct_object_id(
_In_ sai_object_type_t object_type,
_In_ int switch_index,
_In_ uint64_t real_id)
{
SWSS_LOG_ENTER();
return (sai_object_id_t)(((uint64_t)switch_index << SWID_POSITION) | ((uint64_t)object_type << OT_POSITION) | real_id);
}
sai_object_type_t redis_sai_object_type_query(
_In_ sai_object_id_t object_id)
{
SWSS_LOG_ENTER();
if (object_id == SAI_NULL_OBJECT_ID)
{
return SAI_OBJECT_TYPE_NULL;
}
sai_object_type_t ot = (sai_object_type_t)((object_id >> OT_POSITION) & 0xFF);
if (!sai_metadata_is_object_type_valid(ot))
{
SWSS_LOG_THROW("invalid object id 0x%lx", object_id);
}
return ot;
}
int redis_get_switch_id_index(
_In_ sai_object_id_t switch_id)
{
SWSS_LOG_ENTER();
sai_object_type_t switch_object_type = redis_sai_object_type_query(switch_id);
if (switch_object_type == SAI_OBJECT_TYPE_SWITCH)
{
return (int)((switch_id >> SWID_POSITION) & 0xFF);
}
SWSS_LOG_THROW("object type of switch %s is %s, should be SWITCH",
sai_serialize_object_id(switch_id).c_str(),
sai_serialize_object_type(switch_object_type).c_str());
}
sai_object_id_t redis_sai_switch_id_query(
_In_ sai_object_id_t oid)
{
SWSS_LOG_ENTER();
if (oid == SAI_NULL_OBJECT_ID)
{
return oid;
}
sai_object_type_t object_type = redis_sai_object_type_query(oid);
if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("invalid object type of oid 0x%lx", oid);
}
if (object_type == SAI_OBJECT_TYPE_SWITCH)
{
return oid;
}
/*
* Each VID contains switch index at constant position.
*
* We extract this index from VID and we create switch ID (VID) for
* specific object. We can do this for each object.
*/
int sw_index = (int)((oid >> SWID_POSITION) & 0xFF);
sai_object_id_t switch_id = redis_construct_object_id(SAI_OBJECT_TYPE_SWITCH, sw_index, sw_index);
return switch_id;
}
sai_object_id_t redis_create_virtual_object_id(
_In_ sai_object_id_t switch_id,
_In_ sai_object_type_t object_type)
{
SWSS_LOG_ENTER();
/*
* NOTE: switch ID is VID switch ID from sairedis.
*/
/*
* Check if object type is in valid range.
*/
if (!sai_metadata_is_object_type_valid(object_type))
{
SWSS_LOG_THROW("invalid object type: %s", sai_serialize_object_type(object_type).c_str());
}
/*
* Switch id is deterministic and it comes from sairedis so make check here
* that we will not use this for createing switch VIDs.
*/
if (object_type == SAI_OBJECT_TYPE_SWITCH)
{
SWSS_LOG_THROW("this function should not be used to create VID for switch id");
}
uint64_t virtual_id = g_redisClient->incr(VIDCOUNTER);
int switch_index = redis_get_switch_id_index(switch_id);
sai_object_id_t vid = redis_construct_object_id(object_type, switch_index, virtual_id);
auto info = sai_metadata_get_object_type_info(object_type);
SWSS_LOG_DEBUG("created virtual object id 0x%lx for object type %s",
vid,
info->objecttypename);
return vid;
}
std::unordered_map<sai_object_id_t, sai_object_id_t> local_rid_to_vid;
std::unordered_map<sai_object_id_t, sai_object_id_t> local_vid_to_rid;
void save_rid_and_vid_to_local(
_In_ sai_object_id_t rid,
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
local_rid_to_vid[rid] = vid;
local_vid_to_rid[vid] = rid;
}
void remove_rid_and_vid_from_local(
_In_ sai_object_id_t rid,
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
local_rid_to_vid.erase(rid);
local_vid_to_rid.erase(vid);
}
/*
* This method will create VID for actual RID retrived from device when doing
* GET api and snooping while in init view mode.
*
* This function should not be used to create VID for SWITCH object type.
*/
sai_object_id_t translate_rid_to_vid(
_In_ sai_object_id_t rid,
_In_ sai_object_id_t switch_vid)
{
SWSS_LOG_ENTER();
/*
* NOTE: switch_vid here is Virtual ID of switch for which we need
* create VID for given RID.
*/
if (rid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_DEBUG("translated RID null to VID null");
return SAI_NULL_OBJECT_ID;
}
auto it = local_rid_to_vid.find(rid);
if (it != local_rid_to_vid.end())
{
return it->second;
}
sai_object_id_t vid;
std::string str_rid = sai_serialize_object_id(rid);
auto pvid = g_redisClient->hget(RIDTOVID, str_rid);
if (pvid != NULL)
{
/*
* Object exists.
*/
std::string str_vid = *pvid;
sai_deserialize_object_id(str_vid, vid);
SWSS_LOG_DEBUG("translated RID 0x%lx to VID 0x%lx", rid, vid);
return vid;
}
SWSS_LOG_DEBUG("spotted new RID 0x%lx", rid);
sai_object_type_t object_type = sai_object_type_query(rid);
if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("sai_object_type_query returned NULL type for RID 0x%lx", rid);
}
if (object_type == SAI_OBJECT_TYPE_SWITCH)
{
/*
* Switch ID should be already inside local db or redis db when we
* created switch, so we should never get here.
*/
SWSS_LOG_THROW("RID 0x%lx is switch object, but not in local or redis db, bug!", rid);
}
vid = redis_create_virtual_object_id(switch_vid, object_type);
SWSS_LOG_DEBUG("translated RID 0x%lx to VID 0x%lx", rid, vid);
std::string str_vid = sai_serialize_object_id(vid);
/*
* TODO: This must be ATOMIC.
*
* TODO: To support multiple swiches we need this map per switch;
*/
g_redisClient->hset(RIDTOVID, str_rid, str_vid);
g_redisClient->hset(VIDTORID, str_vid, str_rid);
save_rid_and_vid_to_local(rid, vid);
return vid;
}
void translate_list_rid_to_vid(
_In_ sai_object_list_t &element,
_In_ sai_object_id_t switch_id)
{
SWSS_LOG_ENTER();
for (uint32_t i = 0; i < element.count; i++)
{
element.list[i] = translate_rid_to_vid(element.list[i], switch_id);
}
}
/*
* This method is required to translate RID to VIDs when we are doing snoop for
* new ID's in init view mode, on in apply view mode when we are executing GET
* api, and new object RIDs were spotted the we will create new VIDs for those
* objects and we will put them to redis db.
*/
void translate_rid_to_vid_list(
_In_ sai_object_type_t object_type,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
/*
* We receive real id's here, if they are new then create new VIDs for them
* and put in db, if entry exists in db, use it.
*
* NOTE: switch_id is VID of switch on which those RIDs are probided.
*/
for (uint32_t i = 0; i < attr_count; i++)
{
sai_attribute_t &attr = attr_list[i];
auto meta = sai_metadata_get_attr_metadata(object_type, attr.id);
if (meta == NULL)
{
SWSS_LOG_THROW("unable to get metadata for object type %x, attribute %d", object_type, attr.id);
}
/*
* TODO: Many times we do switch for list of attributes to perform some
* operation on each oid from that attribute, we should provide clever
* way via sai metadata utils to get that.
*/
switch (meta->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
attr.value.oid = translate_rid_to_vid(attr.value.oid, switch_id);
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:
translate_list_rid_to_vid(attr.value.objlist, switch_id);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_ID:
if (attr.value.aclfield.enable)
attr.value.aclfield.data.oid = translate_rid_to_vid(attr.value.aclfield.data.oid, switch_id);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
if (attr.value.aclfield.enable)
translate_list_rid_to_vid(attr.value.aclfield.data.objlist, switch_id);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID:
if (attr.value.aclaction.enable)
attr.value.aclaction.parameter.oid = translate_rid_to_vid(attr.value.aclaction.parameter.oid, switch_id);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
if (attr.value.aclaction.enable)
translate_list_rid_to_vid(attr.value.aclaction.parameter.objlist, switch_id);
break;
default:
/*
* If in futre new attribute with object id will be added this
* will make sure that we will need to add handler here.
*/
if (meta->isoidattribute)
{
SWSS_LOG_THROW("attribute %s is object id, but not processed, FIXME", meta->attridname);
}
break;
}
}
}
/*
* NOTE: We could have in metadata utils option to execute function on each
* object on oid like this. Problem is that we can't then add extra
* parameters.
*/
sai_object_id_t translate_vid_to_rid(
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
if (vid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_DEBUG("translated VID null to RID null");
return SAI_NULL_OBJECT_ID;
}
auto it = local_vid_to_rid.find(vid);
if (it != local_vid_to_rid.end())
{
return it->second;
}
std::string str_vid = sai_serialize_object_id(vid);
std::string str_rid;
auto prid = g_redisClient->hget(VIDTORID, str_vid);
if (prid == NULL)
{
if (isInitViewMode())
{
/*
* If user created object that is object id, then it should not
* query attributes of this object in init view mode, because he
* knows all attributes passed to that object.
*
* NOTE: This may be a problem for some objects in init view mode.
* We will need to revisit this after checking with real SAI
* implementation. Problem here may be that user will create some
* object and actually will need to to query some of it's values,
* like buffer limitations etc, mostly probably this will happen on
* SWITCH object.
*/
SWSS_LOG_THROW("can't get RID in init view mode - don't query created objects");
}
SWSS_LOG_THROW("unable to get RID for VID: 0x%lx", vid);
}
str_rid = *prid;
sai_object_id_t rid;
sai_deserialize_object_id(str_rid, rid);
/*
* We got this RID from redis db, so put it also to local db so it will be
* faster to retrive it late on.
*/
local_vid_to_rid[vid] = rid;
SWSS_LOG_DEBUG("translated VID 0x%lx to RID 0x%lx", vid, rid);
return rid;
}
void translate_list_vid_to_rid(
_In_ sai_object_list_t &element)
{
for (uint32_t i = 0; i < element.count; i++)
{
element.list[i] = translate_vid_to_rid(element.list[i]);
}
}
void translate_vid_to_rid_list(
_In_ sai_object_type_t object_type,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
/*
* All id's received from sairedis should be virtual, so lets translate
* them to real id's before we execute actual api.
*/
for (uint32_t i = 0; i < attr_count; i++)
{
sai_attribute_t &attr = attr_list[i];
auto meta = sai_metadata_get_attr_metadata(object_type, attr.id);
if (meta == NULL)
{
SWSS_LOG_THROW("unable to get metadata for object type %x, attribute %d", object_type, attr.id);
}
switch (meta->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
attr.value.oid = translate_vid_to_rid(attr.value.oid);
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:
translate_list_vid_to_rid(attr.value.objlist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_ID:
if (attr.value.aclfield.enable)
attr.value.aclfield.data.oid = translate_vid_to_rid(attr.value.aclfield.data.oid);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
if (attr.value.aclfield.enable)
translate_list_vid_to_rid(attr.value.aclfield.data.objlist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID:
if (attr.value.aclaction.enable)
attr.value.aclaction.parameter.oid = translate_vid_to_rid(attr.value.aclaction.parameter.oid);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
if (attr.value.aclaction.enable)
translate_list_vid_to_rid(attr.value.aclaction.parameter.objlist);
break;
default:
/*
* If in futre new attribute with object id will be added this
* will make sure that we will need to add handler here.
*/
if (meta->isoidattribute)
{
SWSS_LOG_THROW("attribute %s is object id, but not processed, FIXME", meta->attridname);
}
break;
}
}
}
void snoop_get_attr(
_In_ sai_object_type_t object_type,
_In_ const std::string &str_object_id,
_In_ const std::string &attr_id,
_In_ const std::string &attr_value)
{
SWSS_LOG_ENTER();
/*
* Note: str_object_type + ":" + str_object_id is meta_key we can us that
* here later on.
*/
std::string str_object_type = sai_serialize_object_type(object_type);
std::string key = TEMP_PREFIX + (ASIC_STATE_TABLE + (":" + str_object_type + ":" + str_object_id));
SWSS_LOG_DEBUG("%s", key.c_str());
g_redisClient->hset(key, attr_id, attr_value);
}
void snoop_get_oid(
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
if (vid == SAI_NULL_OBJECT_ID)
{
/*
* If snooped ois is NULL then we don't need take any action.
*/
return;
}
/*
* We need use redis version of object type query here since we are
* operating on VID value, and syncd is compiled agains real SAI
* implementation which has diffrent function sai_object_type_query.
*/
sai_object_type_t object_type = redis_sai_object_type_query(vid);
std::string str_vid = sai_serialize_object_id(vid);
snoop_get_attr(object_type, str_vid, "NULL", "NULL");
}
void snoop_get_oid_list(
_In_ const sai_object_list_t &list)
{
SWSS_LOG_ENTER();
for (uint32_t i = 0; i < list.count; i++)
{
snoop_get_oid(list.list[i]);
}
}
void snoop_get_attr_value(
_In_ const std::string &str_object_id,
_In_ const sai_attr_metadata_t *meta,
_In_ const sai_attribute_t &attr)
{
SWSS_LOG_ENTER();
std::string value = sai_serialize_attr_value(*meta, attr);
SWSS_LOG_DEBUG("%s:%s", meta->attridname, value.c_str());
snoop_get_attr(meta->objecttype, str_object_id, meta->attridname, value);
}
void snoop_get_response(
_In_ sai_object_type_t object_type,
_In_ const std::string &str_object_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
/*
* NOTE: this method is operating on VIDs, all RIDs were translated outside
* this method.
*/
/*
* Vlan (including vlan 1) will need to be put into TEMP view this should
* also be valid for all objects that were queried.
*/
for (uint32_t idx = 0; idx < attr_count; ++idx)
{
const sai_attribute_t &attr = attr_list[idx];
auto meta = sai_metadata_get_attr_metadata(object_type, attr.id);
if (meta == NULL)
{
SWSS_LOG_THROW("unable to get metadata for object type %d, attribute %d", object_type, attr.id);
}
/*
* We should snoop oid values even if they are readonly we just note in
* temp view that those objects exist on switch.
*/
switch (meta->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
snoop_get_oid(attr.value.oid);
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:
snoop_get_oid_list(attr.value.objlist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_ID:
if (attr.value.aclfield.enable)
snoop_get_oid(attr.value.aclfield.data.oid);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
if (attr.value.aclfield.enable)
snoop_get_oid_list(attr.value.aclfield.data.objlist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID:
if (attr.value.aclaction.enable)
snoop_get_oid(attr.value.aclaction.parameter.oid);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
if (attr.value.aclaction.enable)
snoop_get_oid_list(attr.value.aclaction.parameter.objlist);
break;
default:
/*
* If in futre new attribute with object id will be added this
* will make sure that we will need to add handler here.
*/
if (meta->isoidattribute)
{
SWSS_LOG_THROW("attribute %s is object id, but not processed, FIXME", meta->attridname);
}
break;
}
if (HAS_FLAG_READ_ONLY(meta->flags))
{
/*
* If value is read only, we skip it, since after syncd restart we
* won't be able to set/create it anyway.
*/
continue;
}
if (meta->objecttype == SAI_OBJECT_TYPE_PORT &&
meta->attrid == SAI_PORT_ATTR_HW_LANE_LIST)
{
/*
* Skip port lanes for now since we don't create ports.
*/
SWSS_LOG_INFO("skipping %s for %s", meta->attridname, str_object_id.c_str());
continue;
}
/*
* Put non readonly, and non oid attribute value to temp view.
*
* NOTE: This will also put create-only attributes to view, and after
* syncd hard reinit we will not be able to do "SET" on that attribute.
*
* Similar action can happen when we will do this on asicSet during
* apply view.
*/
snoop_get_attr_value(str_object_id, meta, attr);
}
}
void internal_syncd_get_send(
_In_ sai_object_type_t object_type,
_In_ const std::string &str_object_id,
_In_ sai_object_id_t switch_id,
_In_ sai_status_t status,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
std::vector<swss::FieldValueTuple> entry;
if (status == SAI_STATUS_SUCCESS)
{
translate_rid_to_vid_list(object_type, switch_id, attr_count, attr_list);
/*
* Normal serialization + translate RID to VID.
*/
entry = SaiAttributeList::serialize_attr_list(
object_type,
attr_count,
attr_list,
false);
if (isInitViewMode())
{
/*
* All oid values here are VIDs.
*/
snoop_get_response(object_type, str_object_id, attr_count, attr_list);
}
/*
* TODO: When we are doing GET in non init view mode, maybe we could
* snoop data also, since we will put this data anyway when we will do
* view compare. We would need to fix snoop_get_response since
* currently this method is writing only to TEMP view.
*/
}
else if (status == SAI_STATUS_BUFFER_OVERFLOW)
{
/*
* In this case we got correct values for list, but list was too small
* so serialize only count without list itself, sairedis will need to
* take this into account when deserialize.
*
* If there was a list somewhere, count will be changed to actual value
* different attributes can have different lists, many of them may
* serialize only count, and will need to support that on the receiver.
*/
entry = SaiAttributeList::serialize_attr_list(
object_type,
attr_count,
attr_list,
true);
}
else
{
/*
* Some other error, don't send attributes at all.
*/
}
for (const auto &e: entry)
{
SWSS_LOG_DEBUG("attr: %s: %s", fvField(e).c_str(), fvValue(e).c_str());
}
std::string str_status = sai_serialize_status(status);
SWSS_LOG_INFO("sending response for GET api with status: %s", str_status.c_str());
/*
* Since we have only one get at a time, we don't have to serialize object
* type and object id, only get status is required to be returned. Get
* response will not put any data to table, only queue is used.
*/
getResponse->set(str_status, entry, "getresponse");
SWSS_LOG_INFO("response for GET api was send");
}
const char* profile_get_value(
_In_ sai_switch_profile_id_t profile_id,
_In_ const char* variable)
{
SWSS_LOG_ENTER();
if (variable == NULL)
{
SWSS_LOG_WARN("variable is null");
return NULL;
}
auto it = gProfileMap.find(variable);
if (it == gProfileMap.end())
{
SWSS_LOG_NOTICE("%s: NULL", variable);
return NULL;
}
SWSS_LOG_NOTICE("%s: %s", variable, it->second.c_str());
return it->second.c_str();
}
std::map<std::string, std::string>::iterator gProfileIter = gProfileMap.begin();
int profile_get_next_value(
_In_ sai_switch_profile_id_t profile_id,
_Out_ const char** variable,
_Out_ const char** value)
{
SWSS_LOG_ENTER();
if (value == NULL)
{
SWSS_LOG_INFO("resetting profile map iterator");
gProfileIter = gProfileMap.begin();
return 0;
}
if (variable == NULL)
{
SWSS_LOG_WARN("variable is null");
return -1;
}
if (gProfileIter == gProfileMap.end())
{
SWSS_LOG_INFO("iterator reached end");
return -1;