From 2692a4732e148b15d12a7cfb0961ba92c8ebe17c Mon Sep 17 00:00:00 2001
From: svshah-intel <102195908+svshah-intel@users.noreply.github.com>
Date: Tue, 6 Jun 2023 14:30:31 -0700
Subject: [PATCH] Resource Monitoring support for Generic SAI Extensions
(#1243)
*[CRM] Resource Monitoring support for Generic SAI Extensions
---
doc/crm/Generic_SAI_Extensions_CRM.md | 70 +++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 doc/crm/Generic_SAI_Extensions_CRM.md
diff --git a/doc/crm/Generic_SAI_Extensions_CRM.md b/doc/crm/Generic_SAI_Extensions_CRM.md
new file mode 100644
index 0000000000..96448a3440
--- /dev/null
+++ b/doc/crm/Generic_SAI_Extensions_CRM.md
@@ -0,0 +1,70 @@
+# Generic SAI Extension Critical Resource Monitoring (CRM)
+
+## Table of Content
+- [Introduction](#Itroduction)
+- [Scope](#Scope)
+- [Requirements](#Requirements)
+- [Highlevel Design](#Highlevel-Design)
+- [Unit Test Automation](#Unit-Test-Automation)
+
+## Revision
+| Rev | Date | Author | Change Description |
+| :--: | :-------: | :--------------------------------------------------: | :--------------------------------: |
+| 0.1 | 1/17/2023 | Intel | Initial Revision |
+
+## Introduction
+High Level Design for critical resource monitoring (crm) in SONiC for Generic SAI Extension tables.
+
+## Scope
+The scope of the design is to publish CRM counts, for Generic SAI Extension tables, into the COUNTERS-DB. Support for existing generic crm configurations that is applicable to all resources, like polling interval, is in the scope of this document. No additional configuration specific to extension tables resource is in the scope.
+
+## Requirements
+- Support reporting of used counts
+- Support reporting of available counts
+- Support default watermark checks
+
+## Highlevel Design
+New crm resource type enum - CrmResourceType::CRM_EXT_TABLE
+ - Each extension table specific stats are stored in,
+ m_resourcesMap.at(CrmResourceType::CRM_EXT_TABLE).countersMap[EXT_TABLE_STATS:"table-name"]
+
+All existing generic crm configuration, like polling-interval, is applicable to this new crm type.
+
+Currently supported default watermark check for other existing crm resource types is also applicable to every extension table under this new crm type.
+
+
+### API to retrieve available counts
+sai_object_type_get_availability() is an existing SAI API used to query any resource specific availability count. The same API is to be used to query generic SAI extension table resource availability as well. API call is to have following object-type and attributes as parameters,
+
+ - object-type : SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE
+ - attribute-id : SAI_GENERIC_PROGRAMMABLE_ATTR_OBJECT_NAME
+
+respective data-plane implementing this API should return resource count available for the corresponding extension table matching the generic programmable object name
+
+### APIs for used counter book-keeping
+- CrmOrch::incCrmExtTableUsedCounter()
+- CrmOrch::decCrmExtTableUsedCounter()
+
+P4Orch extension table manager is responsible to call APIs when a specific entry for extension table is successfully created or removed.
+
+### Example of CRM counts of extension table o/p in redis
+Example o/p for VIPV4_TABLE with max capacity of 1024
+
+```text
+127.0.0.1:6379[2]> KEYS *EXT_TABLE_STATS*
+ 1) "CRM:EXT_TABLE_STATS:EXT_VIPV4_TABLE"
+
+127.0.0.1:6379[2]> HGETALL "CRM:EXT_TABLE_STATS:EXT_VIPV4_TABLE"
+1) "crm_stats_extension_table_used"
+2) "1"
+3) "crm_stats_extension_table_available"
+4) "1023"
+```
+
+## Unit Test Automation
+P4Orch pytest automation
+- Enhance current viplb generic sai extension test automation to insert validation for crm
+ - after viplb table entry is programmed, get crm used counters
+ - validate used counter has value 1 since 1 viplb entry is programmed
+ - after viplb table entry is removed, get crm used counters
+ - validate used counter has value 0 since there are no more any entries in viplb table