-
Notifications
You must be signed in to change notification settings - Fork 372
Populate CHASSIS_APP_DB when flex counters are read #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a810271
1e5e680
73368cc
aeb2bcd
62cc42c
56605d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,13 @@ static const std::string ATTR_TYPE_PG = "Priority Group Attribute"; | |
| static const std::string ATTR_TYPE_MACSEC_SA = "MACSEC SA Attribute"; | ||
| static const std::string ATTR_TYPE_ACL_COUNTER = "ACL Counter Attribute"; | ||
|
|
||
| // --> Needed for agg voq stats | ||
| static sai_queue_api_t *sai_queue_api = NULL; | ||
| static swss::DBConnector configDb("CONFIG_DB", 0); | ||
| static swss::Table cfgDeviceMetaDataTable(&configDb, CFG_DEVICE_METADATA_TABLE_NAME); | ||
| static swss::DBConnector counterDb("COUNTERS_DB", 0); | ||
| // <-- agg voq stats end | ||
|
|
||
|
||
| BaseCounterContext::BaseCounterContext(const std::string &name): | ||
| m_name(name) | ||
| { | ||
|
|
@@ -363,6 +370,7 @@ void deserializeAttr( | |
| sai_deserialize_acl_counter_attr(name, attr); | ||
| } | ||
|
|
||
|
|
||
| template <typename StatType> | ||
| class CounterContext : public BaseCounterContext | ||
|
Comment on lines
367
to
368
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in separate file 1 class per one file cpp
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is not added by me. |
||
| { | ||
|
|
@@ -511,8 +519,72 @@ class CounterContext : public BaseCounterContext | |
| } | ||
| } | ||
|
|
||
| void addVoqEntryToChassisAppDb(_In_ const sai_object_id_t rid, | ||
|
||
| _In_ const sai_object_id_t vid, | ||
| _In_ std::vector<swss::FieldValueTuple> &counterValues, | ||
| _Out_ swss::Table *appDbCountersTable ) { | ||
|
||
| // We need to update CHASSIS_APP_DB only if it is a VOQ counter. So first check | ||
kcudnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // if the counter is a QUEUE counter and if yes, query the queue attribute to check | ||
| // if it is a VOQ queue or not. | ||
| sai_status_t status; | ||
|
|
||
| if (m_objectType == SAI_OBJECT_TYPE_QUEUE) { | ||
| sai_attribute_t attr; | ||
| attr.id = SAI_QUEUE_ATTR_TYPE; | ||
| status = sai_queue_api->get_queue_attribute(rid, 1, &attr); | ||
| if (status != SAI_STATUS_SUCCESS ) { | ||
| SWSS_LOG_ERROR( "sai get_queue_attribute failed for SAI_QUEUE_ATTR_TYPE. " | ||
| "status %d rid 0x%" PRIx64 "vid 0x%" PRIx64, status, rid, vid); | ||
| return; | ||
| } | ||
| if (attr.value.s32 == SAI_QUEUE_TYPE_UNICAST_VOQ) { | ||
| attr.id = SAI_QUEUE_ATTR_INDEX; | ||
| status = sai_queue_api->get_queue_attribute(rid, 1, &attr); | ||
| if (status != SAI_STATUS_SUCCESS ) { | ||
| SWSS_LOG_ERROR( "sai get_queue_attribute failed for SAI_QUEUE_ATTR_INDEX." | ||
|
||
| " status %d rid 0x%" PRIx64 "vid 0x%" PRIx64, status, rid, vid) ; | ||
| return; | ||
| } | ||
| auto iface = counterDb.hget(COUNTERS_PORT_NAME_VOQ_MAP, sai_serialize_object_id(vid)); | ||
| if (!iface) | ||
| { | ||
| SWSS_LOG_ERROR("Cannot query port name for queue. rid 0x%" PRIx64 "vid 0x%" PRIx64, rid, vid); | ||
| return; | ||
| } | ||
|
Comment on lines
+548
to
+552
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add empty line before each if and after each }
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| string hostname; | ||
| if (!cfgDeviceMetaDataTable.hget("localhost", "hostname", hostname)) | ||
| { | ||
| // hostname is not configured. | ||
| SWSS_LOG_ERROR("Host name is not configured"); | ||
| return; | ||
| } | ||
| string asic; | ||
| if (!cfgDeviceMetaDataTable.hget("localhost", "asic_name", asic)) | ||
| { | ||
| // Asic name not configured | ||
| SWSS_LOG_ERROR("Asic name is not configured"); | ||
| return; | ||
| } | ||
| // Form the key to be inserted in "COUNTERS" table in CHASSIS_APP_DB. | ||
| // The key is of the form <INTF>@<VOQ>. | ||
| // Like this <table>|fsi_id|asic_id|intf@fsi_id|asic_id:VOQ_index | ||
| // Interface part: | ||
| // iface: "fsi_id|asic_id|intf" - desribes the chip and core where the intf | ||
| // is present | ||
| // | ||
| // VOQ part: | ||
| // fsi_id: FSI id of the chip where the voq is present | ||
| // asic_id: asic id of the core where the voq is present | ||
| // VOQ_index: index of the voq among all the voqs for this interface on this chip and asic | ||
| string key = *iface + "@" + hostname + "|" + asic + ":" + std::to_string( attr.value.u8 ); | ||
| appDbCountersTable->set(key, counterValues, ""); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| virtual void collectData( | ||
| _In_ swss::Table &countersTable) override | ||
| _In_ swss::Table &countersTable, | ||
| _In_ swss::Table *appDbCountersTable) override | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
| sai_stats_mode_t effective_stats_mode = m_groupStatsMode; | ||
|
|
@@ -541,6 +613,11 @@ class CounterContext : public BaseCounterContext | |
| values.emplace_back(serializeStat(statIds[i]), std::to_string(stats[i])); | ||
| } | ||
| countersTable.set(sai_serialize_object_id(vid), values, ""); | ||
| if (appDbCountersTable) | ||
| { | ||
| // Chassis based system | ||
| addVoqEntryToChassisAppDb(rid, vid, values, appDbCountersTable); | ||
| } | ||
| } | ||
|
|
||
| for (const auto &kv : m_bulkContexts) | ||
|
|
@@ -954,7 +1031,8 @@ class AttrContext : public CounterContext<AttrType> | |
| } | ||
|
|
||
| void collectData( | ||
| _In_ swss::Table &countersTable) override | ||
| _In_ swss::Table &countersTable, | ||
| _In_ swss::Table *appDbCountersTable) override | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
|
|
@@ -995,6 +1073,11 @@ class AttrContext : public CounterContext<AttrType> | |
| values.emplace_back(meta->attridname, sai_serialize_attr_value(*meta, attrs[i])); | ||
| } | ||
| countersTable.set(sai_serialize_object_id(vid), values, ""); | ||
| if (appDbCountersTable) | ||
| { | ||
| // Chassis based system | ||
| appDbCountersTable->set(sai_serialize_object_id(vid), values, ""); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
@@ -1014,6 +1097,14 @@ FlexCounter::FlexCounter( | |
| m_enable = false; | ||
| m_isDiscarded = false; | ||
|
|
||
| if (!sai_queue_api) { | ||
| sai_status_t status; | ||
| status = sai_api_query(SAI_API_QUEUE, (void **)&sai_queue_api); | ||
|
||
| if (status != SAI_STATUS_SUCCESS) { | ||
| SWSS_LOG_ERROR("SAI queue API query failed. Status %d", status); | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+1134
to
+1145
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all databases names are hardcoded, they should be obrained from defines or config header
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| startFlexCounterThread(); | ||
| } | ||
|
|
||
|
|
@@ -1358,16 +1449,18 @@ bool FlexCounter::hasCounterContext( | |
| } | ||
|
|
||
| void FlexCounter::collectCounters( | ||
| _In_ swss::Table &countersTable) | ||
| _In_ swss::Table &countersTable, | ||
| _In_ swss::Table *appDbCountersTable) | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
| for (const auto &it : m_counterContext) | ||
| { | ||
| it.second->collectData(countersTable); | ||
| it.second->collectData(countersTable, appDbCountersTable); | ||
| } | ||
|
|
||
| countersTable.flush(); | ||
| appDbCountersTable->flush(); | ||
| } | ||
|
|
||
| void FlexCounter::runPlugins( | ||
|
|
@@ -1388,6 +1481,30 @@ void FlexCounter::runPlugins( | |
| } | ||
| } | ||
|
|
||
| void getCfgSwitchType(string &switch_type) | ||
| { | ||
| try | ||
| { | ||
| if (!cfgDeviceMetaDataTable.hget("localhost", "switch_type", switch_type)) | ||
| { | ||
| //Switch type is not configured. Consider it default = "switch" (regular switch) | ||
| switch_type = "switch"; | ||
| } | ||
| } | ||
| catch(const std::system_error& e) | ||
| { | ||
| SWSS_LOG_ERROR("System error: %s", e.what()); | ||
| switch_type = "switch"; | ||
| } | ||
|
|
||
| if (switch_type != "voq" && switch_type != "fabric" && switch_type != "chassis-packet" && switch_type != "switch" && switch_type != "dpu") | ||
| { | ||
| SWSS_LOG_ERROR("Invalid switch type %s configured", switch_type.c_str()); | ||
| //If configured switch type is none of the supported, assume regular switch | ||
| switch_type = "switch"; | ||
| } | ||
| } | ||
|
|
||
| void FlexCounter::flexCounterThreadRunFunction() | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
@@ -1396,6 +1513,16 @@ void FlexCounter::flexCounterThreadRunFunction() | |
| swss::RedisPipeline pipeline(&db); | ||
| swss::Table countersTable(&pipeline, COUNTERS_TABLE, true); | ||
|
|
||
| string switchType; | ||
| swss::Table *appDbCountersTable = NULL; | ||
| getCfgSwitchType(switchType); | ||
| if (switchType == "voq") | ||
| { | ||
| swss::DBConnector appDb("CHASSIS_APP_DB", 0, true); | ||
| swss::RedisPipeline appDbPipeline(&appDb); | ||
| appDbCountersTable = new swss::Table(&appDbPipeline, "COUNTERS", true); | ||
|
||
| } | ||
|
|
||
| while (m_runFlexCounterThread) | ||
| { | ||
| MUTEX; | ||
|
|
@@ -1404,7 +1531,7 @@ void FlexCounter::flexCounterThreadRunFunction() | |
| { | ||
| auto start = std::chrono::steady_clock::now(); | ||
|
|
||
| collectCounters(countersTable); | ||
| collectCounters(countersTable, appDbCountersTable); | ||
|
|
||
| runPlugins(db); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no api should be uses, VendorCalss shoud be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I do not understand. I need a handle
sai_queue_apiso that I can query queue stats like thisstatus = sai_queue_api->get_queue_attribute(rid, 1, &attr);. I am not aware of an alternative to this. What is VendorClass? How to use it? Can you point me to an example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use VendorSai class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.