forked from sonic-net/sonic-sairedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncd_applyview.cpp
More file actions
5834 lines (4669 loc) · 190 KB
/
syncd_applyview.cpp
File metadata and controls
5834 lines (4669 loc) · 190 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 "sairedis.h"
#include "swss/table.h"
#include "swss/logger.h"
#include "swss/dbconnector.h"
#include <algorithm>
#include <list>
/*
* NOTE: All methods taking current and temporary view could be moved to
* transition class etc to just use class members instead of passing those
* parameters to every function.
*/
/**
* @brief Represents SAI object status during comparison
*/
typedef enum _sai_object_status_t
{
/**
* @brief Object was not processed at all
*
* This enum must be declared first.
*/
SAI_OBJECT_STATUS_NOT_PROCESSED = 0,
/**
* @brief Object was matched in previous view
*
* Previous VID was matched to temp VID since it's the same. Objects exists
* in both previous and next view and have the save VID/RID values.
*
* However attributes of that object could be different and may be not
* matched yet. This object still needs processing for attributes.
*
* Since only attributes can be updated then this object may not be removed
* at all, it must be possible to update only attribute values.
*/
SAI_OBJECT_STATUS_MATCHED,
/**
* @brief Object was removed during child processing
*
* Only current view objects can be set to this status.
*/
SAI_OBJECT_STATUS_REMOVED,
/**
* @brief Object is in final stage
*
* This means object was matched/set/created and proper actions were
* generated as diff data to be executed on ASIC.
*/
SAI_OBJECT_STATUS_FINAL,
} sai_object_status_t;
struct AsicOperation
{
AsicOperation(int id, sai_object_id_t vID, bool remove,
std::shared_ptr<swss::KeyOpFieldsValuesTuple>& operation):
opId(id), vid(vID), isRemove(remove), op(operation)
{
}
int opId;
sai_object_id_t vid;
bool isRemove;
std::shared_ptr<swss::KeyOpFieldsValuesTuple> op;
};
/**
* @brief Class represents single attribute
*
* Some attributes are lists, and have allocated memory, this class will help to
* handle memory management and also will keep metadata for attribute.
*/
class SaiAttr
{
public:
/**
* @brief Constructor
*
* @param[in] str_attr_id Attribute is as string
* @param[in] str_attr_value Attribute value as string
*/
SaiAttr(
_In_ const std::string &str_attr_id,
_In_ const std::string &str_attr_value):
m_str_attr_id(str_attr_id),
m_str_attr_value(str_attr_value),
m_meta(NULL)
{
SWSS_LOG_ENTER();
/*
* We perform deserialize here to have attribute value when we need
* it, this can include allocated lists, so on destructor we need
* to free this memory.
*/
sai_deserialize_attr_id(str_attr_id, &m_meta);
m_attr.id = m_meta->attrid;
sai_deserialize_attr_value(str_attr_value, *m_meta, m_attr, false);
}
/**
* @brief Destructor
*/
~SaiAttr()
{
SWSS_LOG_ENTER();
sai_deserialize_free_attribute_value(m_meta->attrvaluetype, m_attr);
}
sai_attribute_t* getRWSaiAttr()
{
SWSS_LOG_ENTER();
return &m_attr;
}
const sai_attribute_t* getSaiAttr() const
{
SWSS_LOG_ENTER();
return &m_attr;
}
/**
* @brief Tells whether attribute contains OIDs
*
* @return True if attribute contains OIDs, false otherwise
*/
bool isObjectIdAttr() const
{
SWSS_LOG_ENTER();
return m_meta->isoidattribute;
}
const std::string& getStrAttrId() const
{
SWSS_LOG_ENTER();
return m_str_attr_id;
}
const std::string& getStrAttrValue() const
{
SWSS_LOG_ENTER();
return m_str_attr_value;
}
const sai_attr_metadata_t* getAttrMetadata() const
{
SWSS_LOG_ENTER();
return m_meta;
}
void UpdateValue()
{
SWSS_LOG_ENTER();
m_str_attr_value = sai_serialize_attr_value(*m_meta, m_attr);
}
/**
* @brief Get OID list from attribute
*
* Based on serialization type attribute may be oid attribute, oid list
* attribute or non oid attribute. This method will extract all those oids from
* this attribute and return as vector. This is handy when we need processing
* oids per attribute.
*
* @return Object list used in attribute
*/
std::vector<sai_object_id_t> getOidListFromAttribute() const
{
SWSS_LOG_ENTER();
const sai_attribute_t &attr = m_attr;
uint32_t count = 0;
const sai_object_id_t *objectIdList = NULL;
/*
* For ACL fields and actions we need to use enable flag as
* indicator, since when attribute is disabled then parameter can
* be garbage.
*/
switch (m_meta->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
count = 1;
objectIdList = &attr.value.oid;
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:
count = attr.value.objlist.count;
objectIdList = attr.value.objlist.list;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_ID:
if (attr.value.aclfield.enable)
{
count = 1;
objectIdList = &attr.value.aclfield.data.oid;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
if (attr.value.aclfield.enable)
{
count = attr.value.aclfield.data.objlist.count;
objectIdList = attr.value.aclfield.data.objlist.list;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID:
if (attr.value.aclaction.enable)
{
count = 1;
objectIdList = &attr.value.aclaction.parameter.oid;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
if (attr.value.aclaction.enable)
{
count = attr.value.aclaction.parameter.objlist.count;
objectIdList = attr.value.aclaction.parameter.objlist.list;
}
break;
default:
if (m_meta->isoidattribute)
{
SWSS_LOG_THROW("attribute %s is oid attrubute but not handled", m_meta->attridname);
}
/*
* Attribute not contain any object ids.
*/
break;
}
std::vector<sai_object_id_t> result(objectIdList, objectIdList + count);
return result;
}
private:
/*
* Copy constructor and assignment operator are marked as private to
* prevent copy of this object, since attribute can contain pointers to
* list which can lead to double free when object copy.
*
* This can be solved by making proper implementations of those
* methods, currently this is not required.
*/
SaiAttr(const SaiAttr&);
SaiAttr& operator=(const SaiAttr&);
const std::string m_str_attr_id;
std::string m_str_attr_value;
const sai_attr_metadata_t* m_meta;
sai_attribute_t m_attr;
};
/**
* @brief Class represents SAI object
*/
class SaiObj
{
public:
/**
* @brief Constructor
*/
SaiObj():
createdObject(false),
m_object_status(SAI_OBJECT_STATUS_NOT_PROCESSED)
{
SWSS_LOG_ENTER();
/* empty intentionally */
}
// TODO move to methods or constructor ?
std::string str_object_type;
std::string str_object_id;
sai_object_meta_key_t meta_key;
const sai_object_type_info_t *info;
/**
* @brief This will indicate whether object was created and it will
* indicate that currently there is no RID for it.
*/
bool createdObject;
bool isOidObject() const
{
SWSS_LOG_ENTER();
// XXX return info->isobjectid;
return !info->isnonobjectid;
}
const std::unordered_map<sai_attr_id_t, std::shared_ptr<SaiAttr>>& getAllAttributes() const
{
SWSS_LOG_ENTER();
return m_attrs;
}
std::shared_ptr<const SaiAttr> getSaiAttr(
_In_ sai_attr_id_t id) const
{
SWSS_LOG_ENTER();
auto it = m_attrs.find(id);
if (it == m_attrs.end())
{
for (const auto &ita: m_attrs)
{
const auto &a = ita.second;
SWSS_LOG_ERROR("%s: %s", a->getStrAttrId().c_str(), a->getStrAttrValue().c_str());
}
SWSS_LOG_THROW("object %s has no attribute %d", str_object_id.c_str(), id);
}
return it->second;
}
/**
* @brief Sets object status
*
* @param[in] object_status New object status
*/
void setObjectStatus(
_In_ sai_object_status_t object_status)
{
SWSS_LOG_ENTER();
m_object_status = object_status;
}
/**
* @brief Gets current object status
*
* @return Current object status
*/
sai_object_status_t getObjectStatus() const
{
SWSS_LOG_ENTER();
return m_object_status;
}
/**
* @brief Gets object type
*
* @return Object type
*/
sai_object_type_t getObjectType() const
{
SWSS_LOG_ENTER();
return meta_key.objecttype;
}
// TODO should be private, and we should have some friends from AsicView class
void setAttr(
_In_ const std::shared_ptr<SaiAttr> &attr)
{
SWSS_LOG_ENTER();
m_attrs[attr->getSaiAttr()->id] = attr;
}
bool hasAttr(
_In_ sai_attr_id_t id) const
{
SWSS_LOG_ENTER();
return m_attrs.find(id) != m_attrs.end();
}
sai_object_id_t getVid() const
{
SWSS_LOG_ENTER();
if (isOidObject())
{
return meta_key.objectkey.key.object_id;
}
SWSS_LOG_THROW("object %s it not object id type", str_object_id.c_str());
}
/*
* NOTE: We need dependency tree if we want to remove objects which
* have reference count not zero. Currently we just iterate on removed
* objects as many times as their reference will get down to zero.
*/
private:
sai_object_status_t m_object_status;
std::unordered_map<sai_attr_id_t, std::shared_ptr<SaiAttr>> m_attrs;
SaiObj(const SaiObj&);
SaiObj& operator=(const SaiObj&);
};
typedef std::unordered_map<sai_object_id_t, sai_object_id_t> ObjectIdMap;
typedef std::unordered_map<std::string, std::shared_ptr<SaiObj>> StrObjectIdToSaiObjectHash;
typedef std::unordered_map<sai_object_id_t, std::shared_ptr<SaiObj>> ObjectIdToSaiObjectHash;
/**
* @brief Class represents ASIC view
*/
class AsicView
{
public:
/**
* @brief Constructor
*/
AsicView():
m_asicOperationId(0)
{
SWSS_LOG_ENTER();
/* empty intentionally */
}
/**
* @brief Populates ASIC view from REDIS table dump
*
* @param[in] dump Redis table dump
*
* NOTE: Could be static method that returns AsicView object.
*/
void fromDump(
_In_ const swss::TableDump &dump)
{
SWSS_LOG_ENTER();
/*
* Input should be also existing objects, so they could be created
* here right away but we would need VIDs as well.
*/
for (const auto &key: dump)
{
auto start = key.first.find_first_of(":");
if (start == std::string::npos)
{
SWSS_LOG_THROW("failed to find colon in %s", key.first.c_str());
}
std::shared_ptr<SaiObj> o = std::make_shared<SaiObj>();
// TODO we could use sai deserialize object meta key
o->str_object_type = key.first.substr(0, start);
o->str_object_id = key.first.substr(start + 1);
sai_deserialize_object_type(o->str_object_type, o->meta_key.objecttype);
o->info = sai_metadata_get_object_type_info(o->meta_key.objecttype);
/*
* Since neighbor/route/fdb structs objects contains OIDs, we
* need to increase vid reference. With new metadata for SAI
* 1.0 this can be done in generic way for all non object ids.
*/
switch (o->meta_key.objecttype)
{
case SAI_OBJECT_TYPE_FDB_ENTRY:
sai_deserialize_fdb_entry(o->str_object_id, o->meta_key.objectkey.key.fdb_entry);
soFdbs[o->str_object_id] = o;
break;
case SAI_OBJECT_TYPE_NEIGHBOR_ENTRY:
sai_deserialize_neighbor_entry(o->str_object_id, o->meta_key.objectkey.key.neighbor_entry);
soNeighbors[o->str_object_id] = o;
break;
case SAI_OBJECT_TYPE_ROUTE_ENTRY:
sai_deserialize_route_entry(o->str_object_id, o->meta_key.objectkey.key.route_entry);
soRoutes[o->str_object_id] = o;
break;
default:
if (o->info->isnonobjectid)
{
SWSS_LOG_THROW("object %s is non object id, not handled, FIXME", key.first.c_str());
}
sai_deserialize_object_id(o->str_object_id, o->meta_key.objectkey.key.object_id);
soOids[o->str_object_id] = o;
oOids[o->meta_key.objectkey.key.object_id] = o;
break;
}
soAll[o->str_object_id] = o;
sotAll[o->meta_key.objecttype][o->str_object_id] = o;
if (o->info->isnonobjectid)
{
updateNonObjectIdVidReferenceCountByValue(o, 1);
}
else
{
/*
* Here is only object VID declaration, since we don't
* know what objects were processed previously but on
* some of previous object attributes this VID could be
* used, so value can be already greater than zero, but
* here we need to just mark that vid exists in
* vidReference.
*/
m_vidReference[o->meta_key.objectkey.key.object_id] += 0;
}
populateAttributes(o, key.second);
}
}
private:
/**
* @brief Release existing VID links (references) based on given attribute.
*
* @param[in] attr Attribute which will be used to obtain oids.
*/
void releaseExisgingLinks(
_In_ const std::shared_ptr<const SaiAttr> &attr)
{
SWSS_LOG_ENTER();
/*
* For each VID on that attribute (it can be single oid or oid list,
* release link on current view.
*
* Second operation after could increase links of setting new attribute, or
* nothing if object was removed.
*
* Also if we want to keep track of object reverse dependency
* this action can be more complicated.
*/
for (auto const &vid: attr->getOidListFromAttribute())
{
releaseVidReference(vid);
}
}
/**
* @brief Release existing VID links (references) based on given obejct.
*
* All OID attributes will be scanned and released.
*
* @param[in] obj Object which will be used to obtain attributes and oids
*/
void releaseExisgingLinks(
_In_ const std::shared_ptr<const SaiObj> &obj)
{
SWSS_LOG_ENTER();
for (const auto &ita: obj->getAllAttributes())
{
releaseExisgingLinks(ita.second);
}
}
/**
* @brief Release VID reference.
*
* If SET operation was performed on attribute, and attribute was OID
* attribute, then we need to release previous reference to that VID,
* and bind new reference to next OID if present.
*
* @param[in] vid Virtual ID to be released.
*/
void releaseVidReference(
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
if (vid == SAI_NULL_OBJECT_ID)
{
return;
}
auto it = m_vidReference.find(vid);
if (it == m_vidReference.end())
{
SWSS_LOG_THROW("vid %s don't exist in reference map",
sai_serialize_object_id(vid).c_str());
}
int referenceCount = --(it->second);
if (referenceCount < 0)
{
SWSS_LOG_THROW("vid %s decreased reference count too many times: %d, BUG",
sai_serialize_object_id(vid).c_str(),
referenceCount);
}
SWSS_LOG_INFO("decreased vid %s refrence to %d",
sai_serialize_object_id(vid).c_str(),
referenceCount);
if (referenceCount == 0)
{
m_vidToAsicOperationId[vid] = m_asicOperationId;
}
}
/**
* @brief Bind new links (references) based on attribute
*
* @param[in] attr Attribute to obtain oids to bind references
*/
void bindNewLinks(
_In_ const std::shared_ptr<const SaiAttr> &attr)
{
SWSS_LOG_ENTER();
/*
* For each VID on that attribute (it can be single oid or oid list,
* bind new link on current view.
*
* Notice that this list can contain VIDs from temporary view or default
* view, so they may not exists in current view. But that should also be
* not the case since we either created new object on current view or
* either we matched current object to temporary object so RID can be the
* same.
*
* Also if we want to keep track of object reverse dependency
* this action can be more complicated.
*/
for (auto const &vid: attr->getOidListFromAttribute())
{
bindNewVidReference(vid);
}
}
/**
* @brief Bind existing VID links (references) based on given obejct.
*
* All OID attributes will be scanned and binded.
*
* @param[in] obj Object which will be used to obtain attributes and oids
*/
void bindNewLinks(
_In_ const std::shared_ptr<const SaiObj> &obj)
{
SWSS_LOG_ENTER();
for (const auto &ita: obj->getAllAttributes())
{
bindNewLinks(ita.second);
}
}
/**
* @brief Bind new VID reference
*
* If attribute is OID attribute then we need to increase reference
* count on that VID to mark it that it is in use.
*
* @param[in] vid Virtual ID reference to be bind
*/
void bindNewVidReference(
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
if (vid == SAI_NULL_OBJECT_ID)
{
return;
}
/*
* If we are doing bind on new VID reference, that VID needs to
* exist int current view, either object was matched or new object
* was created.
*
* TODO: Not sure if this will have impact on some other object
* processing since if object was matched or created then this VID
* can be found in other attributes comparing them, and it will get
* NULL instead RID.
*/
auto it = m_vidReference.find(vid);
if (it == m_vidReference.end())
{
SWSS_LOG_THROW("vid %s don't exist in reference map",
sai_serialize_object_id(vid).c_str());
}
int referenceCount = ++(it->second);
SWSS_LOG_INFO("increased vid %s refrence to %d",
sai_serialize_object_id(vid).c_str(),
referenceCount);
}
public:
/**
* @brief Gets VID reference count.
*
* @param vid Virtual ID to obtain reference count.
*
* @return Reference count or -1 if VID was not found.
*/
int getVidReferenceCount(
_In_ sai_object_id_t vid) const
{
SWSS_LOG_ENTER();
auto it = m_vidReference.find(vid);
if (it != m_vidReference.end())
{
return it->second;
}
return -1;
}
/**
* @brief Insert new VID reference.
*
* Inserts new reference to be tracked. This also make sure that
* reference don't exists yet, as a sanity check if same reference
* would be inserted twice.
*
* @param[in] vid Virtual ID reference to be inserted.
*/
void insertNewVidReference(
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
auto it = m_vidReference.find(vid);
if (it != m_vidReference.end())
{
SWSS_LOG_THROW("vid %s already exist in reference map, BUG",
sai_serialize_object_id(vid).c_str());
}
m_vidReference[vid] = 0;
SWSS_LOG_INFO("inserted vid %s as reference",
sai_serialize_object_id(vid).c_str());
}
// TODO convert to something like nonObjectIdMap
StrObjectIdToSaiObjectHash soFdbs;
StrObjectIdToSaiObjectHash soNeighbors;
StrObjectIdToSaiObjectHash soRoutes;
StrObjectIdToSaiObjectHash soOids;
StrObjectIdToSaiObjectHash soAll;
private:
std::map<sai_object_type_t, StrObjectIdToSaiObjectHash> sotAll;
public:
ObjectIdToSaiObjectHash oOids;
/*
* On temp view this needs to be used for actual NEW rids created and
* then reused with rid mapping to create new rid/vid map.
*/
ObjectIdMap ridToVid;
ObjectIdMap vidToRid;
ObjectIdMap removedVidToRid;
std::map<sai_object_type_t, std::unordered_map<std::string,std::string>> nonObjectIdMap;
sai_object_id_t defaultTrapGroupRid;
/**
* @brief Gets objects by object type.
*
* @param object_type Object type to be used as filter.
*
* @return List of objects with requested object type.
* Order on list is random.
*/
std::vector<std::shared_ptr<SaiObj>> getObjectsByObjectType(
_In_ sai_object_type_t object_type) const
{
SWSS_LOG_ENTER();
std::vector<std::shared_ptr<SaiObj>> list;
/*
* We need to use find, since object type may not exist.
*/
auto it = sotAll.find(object_type);
if (it == sotAll.end())
{
return list;
}
for (const auto &p: it->second)
{
list.push_back(p.second);
}
return list;
}
/**
* @brief Gets not processed objects by object type.
*
* Call to this method can be expensive, since every time we iterate
* entire list. This list can contain even 10k elements if view will be
* very large.
*
* @param object_type Object type to be used as filter.
*
* @return List of objects with requested object type and marked
* as not processed. Order on list is random.
*/
std::vector<std::shared_ptr<SaiObj>> getNotProcessedObjectsByObjectType(
_In_ sai_object_type_t object_type) const
{
SWSS_LOG_ENTER();
std::vector<std::shared_ptr<SaiObj>> list;
/*
* We need to use find, since object type may not exist.
*/
auto it = sotAll.find(object_type);
if (it == sotAll.end())
{
return list;
}
for (const auto &p: it->second)
{
if (p.second->getObjectStatus() == SAI_OBJECT_STATUS_NOT_PROCESSED)
{
list.push_back(p.second);
}
}
return list;
}
/**
* @brief Gets all not processed objects
*
* @return List of all not processed objects. Order on list is random.
*/
std::vector<std::shared_ptr<SaiObj>> getAllNotProcessedObjects() const
{
SWSS_LOG_ENTER();
std::vector<std::shared_ptr<SaiObj>> list;
for (const auto &p: soAll)
{
if (p.second->getObjectStatus() == SAI_OBJECT_STATUS_NOT_PROCESSED)
{
list.push_back(p.second);
}
}
return list;
}
/**
* @brief Create dummy existing object
*
* Function creates dummy object, which is used to indicate that
* this OID object exist in current view. This is used for existing
* objects, like CPU port, default trap group.
*
* @param[in] rid Real ID
* @param[in] vid Virtual ID
*/
void createDummyExistingObject(
_In_ sai_object_id_t rid,
_In_ sai_object_id_t vid)
{
SWSS_LOG_ENTER();
sai_object_type_t object_type = getObjectTypeFromVid(vid);
if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("got null object type from VID %s",
sai_serialize_object_id(vid).c_str());
}
std::shared_ptr<SaiObj> o = std::make_shared<SaiObj>();
o->str_object_type = sai_serialize_object_type(object_type);
o->str_object_id = sai_serialize_object_id(vid);
o->meta_key.objecttype = object_type;
o->meta_key.objectkey.key.object_id = vid;
o->info = sai_metadata_get_object_type_info(object_type);
soOids[o->str_object_id] = o;
oOids[vid] = o;
m_vidReference[vid] += 0;
soAll[o->str_object_id] = o;
sotAll[o->meta_key.objecttype][o->str_object_id] = o;
ridToVid[rid] = vid;
vidToRid[vid] = rid;
}
/**
* @brief Destructor
*/
~AsicView()
{
/* empty intentionally */
}
/**
* @brief Generate ASIC set operation on current existing object.
*
* NOTE: In long run, this is serialize, and then we call deserialize
* to execute them on actual ASIC, maybe this is not necessary
* and could be optimized later.
*
* TODO: Set on object id should do release of links (currently done
* outside) and modify dependency tree.
*
* @param currentObj Current object.
* @param attr Attribute to be set on current object.
*/
void asicSetAttribute(
_In_ const std::shared_ptr<SaiObj> ¤tObj,