forked from sonic-net/sonic-sairedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeta.cpp
More file actions
7486 lines (5722 loc) · 240 KB
/
Copy pathMeta.cpp
File metadata and controls
7486 lines (5722 loc) · 240 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 "Meta.h"
#include "swss/logger.h"
#include "sai_serialize.h"
#include "Globals.h"
#include "SaiAttributeList.h"
#include <inttypes.h>
#include <boost/algorithm/string/join.hpp>
#include <set>
// TODO add validation for all oids belong to the same switch
#define MAX_LIST_COUNT (0x1<<24) // 16M
#define CHECK_STATUS_SUCCESS(s) { if ((s) != SAI_STATUS_SUCCESS) return (s); }
#define CHECK_STATUS_SUCCESS_MODE(s,m) \
{ \
if ((s) != SAI_STATUS_SUCCESS && m != SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR) return (s); \
} \
#define VALIDATION_LIST(md,vlist) \
{ \
auto _status = meta_genetic_validation_list(md,vlist.count,vlist.list); \
if (_status != SAI_STATUS_SUCCESS) \
{ \
return _status; \
} \
}
#define VALIDATION_STATS_LIST(cnt,lst) \
{ \
if ((cnt > MAX_LIST_COUNT) || ((cnt == 0) && (lst != NULL)) || ((cnt > 0) && (lst == NULL)))\
{ \
SWSS_LOG_ERROR("Invalid list and list-count"); \
return SAI_STATUS_INVALID_PARAMETER; \
} \
}
#define VALIDATION_LIST_GET(md, list) \
{ \
if (list.count > MAX_LIST_COUNT) \
{ \
META_LOG_ERROR(md, "list count %u > max list count %u", list.count, MAX_LIST_COUNT);\
} \
}
#define META_LOG_STATUS(status,msg) \
if ((status) == SAI_STATUS_SUCCESS) \
{ SWSS_LOG_DEBUG(msg " status: %s", sai_serialize_status(status).c_str()); } \
else { SWSS_LOG_ERROR(msg " status: %s", sai_serialize_status(status).c_str()); }
#define DECLARE_CREATE_ENTRY(OT,ot) \
sai_status_t Meta::create( \
_In_ const sai_ ## ot ## _t* ot, \
_In_ uint32_t attr_count, \
_In_ const sai_attribute_t *attr_list) \
{ \
SWSS_LOG_ENTER(); \
sai_status_t status = meta_sai_validate_ ## ot (ot, true); \
CHECK_STATUS_SUCCESS(status); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = *ot } } }; \
status = meta_generic_validation_create(meta_key, ot->switch_id, \
attr_count, attr_list); \
CHECK_STATUS_SUCCESS(status); \
status = m_implementation->create(ot, attr_count, attr_list); \
META_LOG_STATUS(status, "create"); \
if (status == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_create(meta_key, ot->switch_id, \
attr_count, attr_list); \
} \
return status; \
}
#define DECLARE_REMOVE_ENTRY(OT,ot) \
sai_status_t Meta::remove( \
_In_ const sai_ ## ot ## _t* ot) \
{ \
SWSS_LOG_ENTER(); \
sai_status_t status = meta_sai_validate_ ## ot (ot, false); \
CHECK_STATUS_SUCCESS(status); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = *ot } } \
}; \
status = meta_generic_validation_remove(meta_key); \
CHECK_STATUS_SUCCESS(status); \
status = m_implementation->remove(ot); \
META_LOG_STATUS(status, "remove"); \
if (status == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_remove(meta_key); \
} \
return status; \
}
#define DECLARE_SET_ENTRY(OT,ot) \
sai_status_t Meta::set( \
_In_ const sai_ ## ot ## _t* ot, \
_In_ const sai_attribute_t *attr) \
{ \
SWSS_LOG_ENTER(); \
sai_status_t status = meta_sai_validate_ ## ot (ot, false); \
CHECK_STATUS_SUCCESS(status); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = *ot } } }; \
status = meta_generic_validation_set(meta_key, attr); \
CHECK_STATUS_SUCCESS(status); \
status = m_implementation->set(ot, attr); \
META_LOG_STATUS(status, "set"); \
if (status == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_set(meta_key, attr); \
} \
return status; \
}
#define DECLARE_GET_ENTRY(OT,ot) \
sai_status_t Meta::get( \
_In_ const sai_ ## ot ## _t* ot, \
_In_ uint32_t attr_count, \
_Inout_ sai_attribute_t *attr_list) \
{ \
SWSS_LOG_ENTER(); \
sai_status_t status = meta_sai_validate_ ## ot (ot, false, true); \
CHECK_STATUS_SUCCESS(status); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = *ot } } }; \
status = meta_generic_validation_get(meta_key, attr_count, attr_list); \
CHECK_STATUS_SUCCESS(status); \
status = m_implementation->get(ot, attr_count, attr_list); \
if (status == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_get(meta_key, ot->switch_id, \
attr_count, attr_list); \
} \
return status; \
}
using namespace saimeta;
Meta::Meta(
_In_ std::shared_ptr<sairedis::SaiInterface> impl):
m_implementation(impl)
{
SWSS_LOG_ENTER();
m_unittestsEnabled = false;
// TODO if metadata supports multiple switches
// then warm boot must be per each switch
m_warmBoot = false;
}
sai_status_t Meta::apiInitialize(
_In_ uint64_t flags,
_In_ const sai_service_method_table_t *service_method_table)
{
SWSS_LOG_ENTER();
return m_implementation->apiInitialize(flags, service_method_table);
}
sai_status_t Meta::apiUninitialize(void)
{
SWSS_LOG_ENTER();
return m_implementation->apiUninitialize();
}
void Meta::meta_warm_boot_notify()
{
SWSS_LOG_ENTER();
m_warmBoot = true;
SWSS_LOG_NOTICE("warmBoot = true");
}
void Meta::meta_init_db()
{
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("begin");
/*
* This DB will contain objects from all switches.
*
* TODO: later on we will have separate bases for each switch. This way
* should be easier to manage, on remove switch we will just clear that db,
* instead of checking all objects.
*/
m_oids.clear();
m_saiObjectCollection.clear();
m_attrKeys.clear();
m_portRelatedSet.clear();
// m_meta_unittests_set_readonly_set.clear();
// m_unittestsEnabled = false
m_warmBoot = false;
SWSS_LOG_NOTICE("end");
}
bool Meta::isEmpty() const
{
SWSS_LOG_ENTER();
return m_portRelatedSet.getAllPorts().empty()
&& m_oids.getAllOids().empty()
&& m_attrKeys.getAllKeys().empty()
&& m_saiObjectCollection.getAllKeys().empty();
}
void Meta::dump() const
{
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("portRelatedSet: %zu", m_portRelatedSet.getAllPorts().size());
SWSS_LOG_NOTICE("oids: %zu", m_oids.getAllOids().size());
SWSS_LOG_NOTICE("attrKeys: %zu", m_attrKeys.getAllKeys().size());
SWSS_LOG_NOTICE("saiObjectCollection: %zu", m_saiObjectCollection.getAllKeys().size());
for (auto &oid: m_oids.getAllReferences())
{
SWSS_LOG_NOTICE("oid: %s: count: %u",
sai_serialize_object_id(oid.first).c_str(),
oid.second);
}
for (auto &mk: m_saiObjectCollection.getAllKeys())
{
SWSS_LOG_NOTICE("objcollection: %s", sai_serialize_object_meta_key(mk).c_str());
}
}
sai_status_t Meta::remove(
_In_ sai_object_type_t object_type,
_In_ sai_object_id_t object_id)
{
SWSS_LOG_ENTER();
sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false);
CHECK_STATUS_SUCCESS(status)
sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } };
status = meta_generic_validation_remove(meta_key);
CHECK_STATUS_SUCCESS(status)
status = m_implementation->remove(object_type, object_id);
META_LOG_STATUS(status, "remove");
if (status == SAI_STATUS_SUCCESS)
{
meta_generic_validation_post_remove(meta_key);
}
return status;
}
sai_status_t Meta::create(
_In_ sai_object_type_t object_type,
_Out_ sai_object_id_t* object_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
sai_status_t status = meta_sai_validate_oid(object_type, object_id, switch_id, true);
CHECK_STATUS_SUCCESS(status)
sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = SAI_NULL_OBJECT_ID } } };
status = meta_generic_validation_create(meta_key, switch_id, attr_count, attr_list);
CHECK_STATUS_SUCCESS(status)
status = m_implementation->create(object_type, object_id, switch_id, attr_count, attr_list);
META_LOG_STATUS(status, "create");
if (status == SAI_STATUS_SUCCESS)
{
meta_key.objectkey.key.object_id = *object_id;
if (meta_key.objecttype == SAI_OBJECT_TYPE_SWITCH)
{
/*
* We are creating switch object, so switch id must be the same as
* just created object. We could use SAI_NULL_OBJECT_ID in that
* case and do special switch inside post_create method.
*/
switch_id = *object_id;
}
meta_generic_validation_post_create(meta_key, switch_id, attr_count, attr_list);
}
return status;
}
sai_status_t Meta::set(
_In_ sai_object_type_t object_type,
_In_ sai_object_id_t object_id,
_In_ const sai_attribute_t *attr)
{
SWSS_LOG_ENTER();
sai_object_id_t switch_id = switchIdQuery(object_id);
if (!m_oids.objectReferenceExists(switch_id))
{
SWSS_LOG_ERROR("switch id %s doesn't exist",
sai_serialize_object_id(switch_id).c_str());
return SAI_STATUS_INVALID_PARAMETER;
}
sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false);
CHECK_STATUS_SUCCESS(status)
sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } };
status = meta_generic_validation_set(meta_key, attr);
CHECK_STATUS_SUCCESS(status)
status = m_implementation->set(object_type, object_id, attr);
META_LOG_STATUS(status, "set");
if (status == SAI_STATUS_SUCCESS)
{
meta_generic_validation_post_set(meta_key, attr);
}
return status;
}
sai_status_t Meta::get(
_In_ sai_object_type_t object_type,
_In_ sai_object_id_t object_id,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
sai_object_id_t switch_id = switchIdQuery(object_id);
sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false);
CHECK_STATUS_SUCCESS(status)
sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } };
status = meta_generic_validation_get(meta_key, attr_count, attr_list);
CHECK_STATUS_SUCCESS(status)
status = m_implementation->get(object_type, object_id, attr_count, attr_list);
if (status == SAI_STATUS_SUCCESS)
{
meta_generic_validation_post_get(meta_key, switch_id, attr_count, attr_list);
}
return status;
}
SAIREDIS_DECLARE_EVERY_ENTRY(DECLARE_REMOVE_ENTRY);
SAIREDIS_DECLARE_EVERY_ENTRY(DECLARE_CREATE_ENTRY);
SAIREDIS_DECLARE_EVERY_ENTRY(DECLARE_SET_ENTRY);
SAIREDIS_DECLARE_EVERY_ENTRY(DECLARE_GET_ENTRY);
sai_status_t Meta::flushFdbEntries(
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
SWSS_LOG_ENTER();
if (attr_count > MAX_LIST_COUNT)
{
SWSS_LOG_ERROR("create attribute count %u > max list count %u", attr_count, MAX_LIST_COUNT);
return SAI_STATUS_INVALID_PARAMETER;
}
if (attr_count != 0 && attr_list == NULL)
{
SWSS_LOG_ERROR("attribute list is NULL");
return SAI_STATUS_INVALID_PARAMETER;
}
sai_object_type_t swot = objectTypeQuery(switch_id);
if (swot != SAI_OBJECT_TYPE_SWITCH)
{
SWSS_LOG_ERROR("object type for switch_id %s is %s",
sai_serialize_object_id(switch_id).c_str(),
sai_serialize_object_type(swot).c_str());
return SAI_STATUS_INVALID_PARAMETER;
}
if (!m_oids.objectReferenceExists(switch_id))
{
SWSS_LOG_ERROR("switch id %s doesn't exist",
sai_serialize_object_id(switch_id).c_str());
return SAI_STATUS_INVALID_PARAMETER;
}
// validate attributes
// - attribute list can be empty
// - validation is similar to "create" action but there is no
// post create step and no references are updated
// - fdb entries are updated in fdb notification
std::unordered_map<sai_attr_id_t, const sai_attribute_t*> attrs;
SWSS_LOG_DEBUG("attr count = %u", attr_count);
for (uint32_t idx = 0; idx < attr_count; ++idx)
{
const sai_attribute_t* attr = &attr_list[idx];
auto mdp = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_FDB_FLUSH, attr->id);
if (mdp == NULL)
{
SWSS_LOG_ERROR("unable to find attribute metadata SAI_OBJECT_TYPE_FDB_FLUSH:%d", attr->id);
return SAI_STATUS_INVALID_PARAMETER;
}
const sai_attribute_value_t& value = attr->value;
const sai_attr_metadata_t& md = *mdp;
META_LOG_DEBUG(md, "(fdbflush)");
if (attrs.find(attr->id) != attrs.end())
{
META_LOG_ERROR(md, "attribute id (%u) is defined on attr list multiple times", attr->id);
return SAI_STATUS_INVALID_PARAMETER;
}
attrs[attr->id] = attr;
// SAI metadata checks if
// - attribute is create only
// - is not conditional
// - is not valid only
switch (md.attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_INT32:
if (md.isenum && !sai_metadata_is_allowed_enum_value(&md, value.s32))
{
META_LOG_ERROR(md, "is enum, but value %d not found on allowed values list", value.s32);
return SAI_STATUS_INVALID_PARAMETER;
}
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
{
sai_status_t status = meta_generic_validation_objlist(md, switch_id, 1, &value.oid);
CHECK_STATUS_SUCCESS(status)
break;
}
default:
META_LOG_THROW(md, "value type %s is not supported yet, FIXME",
sai_serialize_attr_value_type(md.attrvaluetype).c_str());
}
}
// there are no mandatory attributes
// there are no conditional attributes
auto status = m_implementation->flushFdbEntries(switch_id, attr_count, attr_list);
if (status == SAI_STATUS_SUCCESS)
{
// use same logic as notification, so create notification event
std::vector<int32_t> types;
auto *et = sai_metadata_get_attr_by_id(SAI_FDB_FLUSH_ATTR_ENTRY_TYPE, attr_count, attr_list);
if (et)
{
switch (et->value.s32)
{
case SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC:
types.push_back(SAI_FDB_ENTRY_TYPE_DYNAMIC);
break;
case SAI_FDB_FLUSH_ENTRY_TYPE_STATIC:
types.push_back(SAI_FDB_ENTRY_TYPE_STATIC);
break;
default:
types.push_back(SAI_FDB_ENTRY_TYPE_DYNAMIC);
types.push_back(SAI_FDB_ENTRY_TYPE_STATIC);
break;
}
}
else
{
// no type specified so we need to flush dynamic only
types.push_back(SAI_FDB_ENTRY_TYPE_DYNAMIC);
}
for (auto type: types)
{
sai_fdb_event_notification_data_t data = {};
auto *bv_id = sai_metadata_get_attr_by_id(SAI_FDB_FLUSH_ATTR_BV_ID, attr_count, attr_list);
auto *bp_id = sai_metadata_get_attr_by_id(SAI_FDB_FLUSH_ATTR_BRIDGE_PORT_ID, attr_count, attr_list);
sai_attribute_t list[2];
list[0].id = SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID;
list[0].value.oid = bp_id ? bp_id->value.oid : SAI_NULL_OBJECT_ID;
list[1].id = SAI_FDB_ENTRY_ATTR_TYPE;
list[1].value.s32 = type;
data.event_type = SAI_FDB_EVENT_FLUSHED;
data.fdb_entry.switch_id = switch_id;
data.fdb_entry.bv_id = (bv_id) ? bv_id->value.oid : SAI_NULL_OBJECT_ID;
data.attr_count = 2;
data.attr = list;
meta_sai_on_fdb_flush_event_consolidated(data);
}
}
return status;
}
#define PARAMETER_CHECK_IF_NOT_NULL(param) { \
if ((param) == nullptr) { \
SWSS_LOG_ERROR("parameter " # param " is NULL"); \
return SAI_STATUS_INVALID_PARAMETER; } }
#define PARAMETER_CHECK_OID_OBJECT_TYPE(param, OT) { \
sai_object_type_t _ot = objectTypeQuery(param); \
if (_ot != (OT)) { \
SWSS_LOG_ERROR("parameter " # param " %s object type is %s, but expected %s", \
sai_serialize_object_id(param).c_str(), \
sai_serialize_object_type(_ot).c_str(), \
sai_serialize_object_type(OT).c_str()); \
return SAI_STATUS_INVALID_PARAMETER; } }
#define PARAMETER_CHECK_OBJECT_TYPE_VALID(ot) { \
if (!sai_metadata_is_object_type_valid(ot)) { \
SWSS_LOG_ERROR("parameter " # ot " object type %d is invalid", (ot)); \
return SAI_STATUS_INVALID_PARAMETER; } }
#define PARAMETER_CHECK_POSITIVE(param) { \
if ((param) <= 0) { \
SWSS_LOG_ERROR("parameter " #param " must be positive"); \
return SAI_STATUS_INVALID_PARAMETER; } }
#define PARAMETER_CHECK_OID_EXISTS(oid, OT) { \
sai_object_meta_key_t _key = { \
.objecttype = (OT), .objectkey = { .key = { .object_id = (oid) } } }; \
if (!m_saiObjectCollection.objectExists(_key)) { \
SWSS_LOG_ERROR("object %s don't exists", sai_serialize_object_id(oid).c_str()); } }
#define DECLARE_BULK_CREATE_ENTRY(OT,ot) \
sai_status_t Meta::bulkCreate( \
_In_ uint32_t object_count, \
_In_ const sai_ ## ot ## _t *ot, \
_In_ const uint32_t *attr_count, \
_In_ const sai_attribute_t **attr_list, \
_In_ sai_bulk_op_error_mode_t mode, \
_Out_ sai_status_t *object_statuses) \
{ \
SWSS_LOG_ENTER(); \
PARAMETER_CHECK_IF_NOT_NULL(object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; \
} \
PARAMETER_CHECK_POSITIVE(object_count); \
PARAMETER_CHECK_IF_NOT_NULL(ot); \
PARAMETER_CHECK_IF_NOT_NULL(attr_count); \
PARAMETER_CHECK_IF_NOT_NULL(attr_list); \
if (sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_bulk_op_error_mode_t, mode) == nullptr) \
{ \
SWSS_LOG_ERROR("mode value %d is not in range on %s", mode, sai_metadata_enum_sai_bulk_op_error_mode_t.name); \
return SAI_STATUS_INVALID_PARAMETER; \
} \
std::vector<sai_object_meta_key_t> vmk; \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
sai_status_t status = meta_sai_validate_ ##ot (&ot[idx], true); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = ot[idx] } } \
}; \
vmk.push_back(meta_key); \
status = meta_generic_validation_create(meta_key, ot[idx].switch_id, attr_count[idx], attr_list[idx]); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
} \
auto status = m_implementation->bulkCreate(object_count, ot, attr_count, attr_list, mode, object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
if (object_statuses[idx] == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_create(vmk[idx], ot[idx].switch_id, attr_count[idx], attr_list[idx]); \
} \
} \
return status; \
}
#define DECLARE_BULK_REMOVE_ENTRY(OT,ot) \
sai_status_t Meta::bulkRemove( \
_In_ uint32_t object_count, \
_In_ const sai_ ## ot ## _t *ot, \
_In_ sai_bulk_op_error_mode_t mode, \
_Out_ sai_status_t *object_statuses) \
{ \
SWSS_LOG_ENTER(); \
PARAMETER_CHECK_IF_NOT_NULL(object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; \
} \
PARAMETER_CHECK_POSITIVE(object_count); \
PARAMETER_CHECK_IF_NOT_NULL(ot); \
if (sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_bulk_op_error_mode_t, mode) == nullptr) \
{ \
SWSS_LOG_ERROR("mode value %d is not in range on %s", mode, sai_metadata_enum_sai_bulk_op_error_mode_t.name); \
return SAI_STATUS_INVALID_PARAMETER; \
} \
std::vector<sai_object_meta_key_t> vmk; \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
sai_status_t status = meta_sai_validate_ ##ot (&ot[idx], false); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = ot[idx] } } \
}; \
vmk.push_back(meta_key); \
status = meta_generic_validation_remove(meta_key); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
} \
auto status = m_implementation->bulkRemove(object_count, ot, mode, object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
if (object_statuses[idx] == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_remove(vmk[idx]); \
} \
} \
return status; \
}
#define DECLARE_BULK_SET_ENTRY(OT,ot) \
sai_status_t Meta::bulkSet( \
_In_ uint32_t object_count, \
_In_ const sai_ ## ot ## _t *ot, \
_In_ const sai_attribute_t *attr_list, \
_In_ sai_bulk_op_error_mode_t mode, \
_Out_ sai_status_t *object_statuses) \
{ \
SWSS_LOG_ENTER(); \
PARAMETER_CHECK_IF_NOT_NULL(object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; \
} \
PARAMETER_CHECK_POSITIVE(object_count); \
PARAMETER_CHECK_IF_NOT_NULL(ot); \
PARAMETER_CHECK_IF_NOT_NULL(attr_list); \
if (sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_bulk_op_error_mode_t, mode) == nullptr) \
{ \
SWSS_LOG_ERROR("mode value %d is not in range on %s", mode, sai_metadata_enum_sai_bulk_op_error_mode_t.name); \
return SAI_STATUS_INVALID_PARAMETER; \
} \
std::vector<sai_object_meta_key_t> vmk; \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
sai_status_t status = meta_sai_validate_ ##ot (&ot[idx], false); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
sai_object_meta_key_t meta_key = { \
.objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_ ## OT, \
.objectkey = { .key = { .ot = ot[idx] } } \
}; \
vmk.push_back(meta_key); \
status = meta_generic_validation_set(meta_key, &attr_list[idx]); \
CHECK_STATUS_SUCCESS_MODE(status, mode); \
} \
auto status = m_implementation->bulkSet(object_count, ot, attr_list, mode, object_statuses); \
for (uint32_t idx = 0; idx < object_count; idx++) \
{ \
if (object_statuses[idx] == SAI_STATUS_SUCCESS) \
{ \
meta_generic_validation_post_set(vmk[idx], &attr_list[idx]); \
} \
} \
return status; \
}
// BULK GET
#define DECLARE_BULK_GET_ENTRY(OT,ot) \
sai_status_t Meta::bulkGet( \
_In_ uint32_t object_count, \
_In_ const sai_ ## ot ## _t *ot, \
_In_ const uint32_t *attr_count, \
_Inout_ sai_attribute_t **attr_list, \
_In_ sai_bulk_op_error_mode_t mode, \
_Out_ sai_status_t *object_statuses) \
{ \
SWSS_LOG_ENTER(); \
SWSS_LOG_ERROR("FIXME not implemented"); \
return SAI_STATUS_NOT_IMPLEMENTED; \
}
SAIREDIS_DECLARE_EVERY_BULK_ENTRY(DECLARE_BULK_CREATE_ENTRY);
SAIREDIS_DECLARE_EVERY_BULK_ENTRY(DECLARE_BULK_REMOVE_ENTRY);
SAIREDIS_DECLARE_EVERY_BULK_ENTRY(DECLARE_BULK_SET_ENTRY);
SAIREDIS_DECLARE_EVERY_BULK_ENTRY(DECLARE_BULK_GET_ENTRY);
sai_status_t Meta::objectTypeGetAvailability(
_In_ sai_object_id_t switchId,
_In_ sai_object_type_t objectType,
_In_ uint32_t attrCount,
_In_ const sai_attribute_t *attrList,
_Out_ uint64_t *count)
{
SWSS_LOG_ENTER();
PARAMETER_CHECK_OID_OBJECT_TYPE(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OID_EXISTS(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OBJECT_TYPE_VALID(objectType);
// When checking availability of a resource solely based on OBJECT_TYPE, attrCount is 0
if (attrCount)
{
PARAMETER_CHECK_IF_NOT_NULL(attrList);
}
PARAMETER_CHECK_IF_NOT_NULL(count);
auto info = sai_metadata_get_object_type_info(objectType);
PARAMETER_CHECK_IF_NOT_NULL(info);
std::set<sai_attr_id_t> attrs;
for (uint32_t idx = 0; idx < attrCount; idx++)
{
auto id = attrList[idx].id;
auto mdp = sai_metadata_get_attr_metadata(objectType, id);
if (mdp == nullptr)
{
SWSS_LOG_ERROR("can't find attribute %s:%d",
info->objecttypename,
attrList[idx].id);
return SAI_STATUS_INVALID_PARAMETER;
}
if (attrs.find(id) != attrs.end())
{
SWSS_LOG_ERROR("attr %s already defined on list", mdp->attridname);
return SAI_STATUS_INVALID_PARAMETER;
}
attrs.insert(id);
if (!mdp->isresourcetype)
{
SWSS_LOG_ERROR("attr %s is not resource type", mdp->attridname);
return SAI_STATUS_INVALID_PARAMETER;
}
switch (mdp->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_INT32:
if (mdp->isenum && !sai_metadata_is_allowed_enum_value(mdp, attrList[idx].value.s32))
{
SWSS_LOG_ERROR("%s is enum, but value %d not found on allowed values list",
mdp->attridname,
attrList[idx].value.s32);
return SAI_STATUS_INVALID_PARAMETER;
}
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
{
sai_object_type_t ot = objectTypeQuery(attrList[idx].value.oid);
PARAMETER_CHECK_OBJECT_TYPE_VALID(ot);
PARAMETER_CHECK_OID_EXISTS(attrList[idx].value.oid, ot);
break;
}
default:
META_LOG_THROW(*mdp, "value type %s not supported yet, FIXME!",
sai_serialize_attr_value_type(mdp->attrvaluetype).c_str());
}
}
auto status = m_implementation->objectTypeGetAvailability(switchId, objectType, attrCount, attrList, count);
// no post validation required
return status;
}
sai_status_t Meta::queryAttributeCapability(
_In_ sai_object_id_t switchId,
_In_ sai_object_type_t objectType,
_In_ sai_attr_id_t attrId,
_Out_ sai_attr_capability_t *capability)
{
SWSS_LOG_ENTER();
PARAMETER_CHECK_OID_OBJECT_TYPE(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OID_EXISTS(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OBJECT_TYPE_VALID(objectType);
auto mdp = sai_metadata_get_attr_metadata(objectType, attrId);
if (!mdp)
{
SWSS_LOG_ERROR("unable to find attribute: %s:%d",
sai_serialize_object_type(objectType).c_str(),
attrId);
return SAI_STATUS_INVALID_PARAMETER;
}
PARAMETER_CHECK_IF_NOT_NULL(capability);
auto status = m_implementation->queryAttributeCapability(switchId, objectType, attrId, capability);
// no post validation required
return status;
}
sai_status_t Meta::queryAttributeEnumValuesCapability(
_In_ sai_object_id_t switchId,
_In_ sai_object_type_t objectType,
_In_ sai_attr_id_t attrId,
_Inout_ sai_s32_list_t *enumValuesCapability)
{
SWSS_LOG_ENTER();
PARAMETER_CHECK_OID_OBJECT_TYPE(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OID_EXISTS(switchId, SAI_OBJECT_TYPE_SWITCH);
PARAMETER_CHECK_OBJECT_TYPE_VALID(objectType);
auto mdp = sai_metadata_get_attr_metadata(objectType, attrId);
if (!mdp)
{
SWSS_LOG_ERROR("unable to find attribute: %s:%d",
sai_serialize_object_type(objectType).c_str(),
attrId);
return SAI_STATUS_INVALID_PARAMETER;
}
if (!mdp->isenum && !mdp->isenumlist)
{
SWSS_LOG_ERROR("%s is not enum/enum list", mdp->attridname);
return SAI_STATUS_INVALID_PARAMETER;
}
PARAMETER_CHECK_IF_NOT_NULL(enumValuesCapability);
if (meta_genetic_validation_list(*mdp, enumValuesCapability->count, enumValuesCapability->list)
!= SAI_STATUS_SUCCESS)
{
return SAI_STATUS_INVALID_PARAMETER;
}
auto status = m_implementation->queryAttributeEnumValuesCapability(switchId, objectType, attrId, enumValuesCapability);
if (status == SAI_STATUS_SUCCESS)
{
if (enumValuesCapability->list)
{
// check if all returned values are members of defined enum
for (uint32_t idx = 0; idx < enumValuesCapability->count; idx++)
{
int val = enumValuesCapability->list[idx];
if (!sai_metadata_is_allowed_enum_value(mdp, val))
{
SWSS_LOG_ERROR("returned value %d is not allowed on %s", val, mdp->attridname);
}
}
}
}
return status;
}
#define META_COUNTERS_COUNT_MSB (0x80000000)
sai_status_t Meta::meta_validate_stats(
_In_ sai_object_type_t object_type,
_In_ sai_object_id_t object_id,
_In_ uint32_t number_of_counters,
_In_ const sai_stat_id_t *counter_ids,
_Out_ uint64_t *counters,
_In_ sai_stats_mode_t mode)
{
SWSS_LOG_ENTER();
/*
* If last bit of counters count is set to high, and unittests are enabled,
* then this api can be used to SET counter values by user for debugging purposes.
*/
if (m_unittestsEnabled)
{
number_of_counters &= ~(META_COUNTERS_COUNT_MSB);
}
PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type);
PARAMETER_CHECK_OID_OBJECT_TYPE(object_id, object_type);
PARAMETER_CHECK_OID_EXISTS(object_id, object_type);
PARAMETER_CHECK_POSITIVE(number_of_counters);
PARAMETER_CHECK_IF_NOT_NULL(counter_ids);
PARAMETER_CHECK_IF_NOT_NULL(counters);
sai_object_id_t switch_id = switchIdQuery(object_id);
// checks also if object type is OID
sai_status_t status = meta_sai_validate_oid(object_type, &object_id, switch_id, false);
CHECK_STATUS_SUCCESS(status);
auto info = sai_metadata_get_object_type_info(object_type);
PARAMETER_CHECK_IF_NOT_NULL(info);
if (info->statenum == nullptr)
{
SWSS_LOG_ERROR("%s does not support stats", info->objecttypename);
return SAI_STATUS_INVALID_PARAMETER;
}
// check if all counter ids are in enum range
for (uint32_t idx = 0; idx < number_of_counters; idx++)
{