diff --git a/doc/policer_counter/PolicerCounter-HLD.md b/doc/policer_counter/PolicerCounter-HLD.md new file mode 100755 index 0000000000..fcf26feb61 --- /dev/null +++ b/doc/policer_counter/PolicerCounter-HLD.md @@ -0,0 +1,296 @@ +# POLICER Counters Support # + +## Table of Content +* [Revision](#revision) +* [Scope](#scope) +* [Defintions/Abbreviation](#definitionsabbreviation) +* [Overview](#overview) +* [Requirements](#requirements) +* [Architecture Design](#Architecture-Design) + - [High-Level Design](#High-Level-Design) + - [Orchagent](#orchagent) + - [Syncd](#syncd) + - [SAI APIs](#sai-apis) + - [Counters DB](#counters-db) + - [CLI](#cli) + - [Flows](#flows) + - [POLICER counter registration in FC](#policer-counter-registration-in-FC) + - [POLICER counter de-registration in FC](#policer-counter-de-registration-in-FC) +- [Configuration and management](#configuration-management) + - [CLI/YANG model Enhancements](#cli-yang) + - [Config DB Enhancements](#config-db) +- [Warmboot and Fastboot Design Impact](#warmboot-fastboot) +- [Restrictions/Limitations](#restrictions-limitations) +- [Testing Requirements/Design](#testing) + - [Unit Test cases](#unit-test) + - [System Test cases](#system-test) +- [Open/Action items](#open-item) + +### Revision + +| Rev | Date | Author | Change Description | +|:---:|:-----------:|:------------------:|-----------------------------------| +| 0.1 | | Shira Ezra | Initial version | + +### Scope + +This document provides general information about Policer counter feature in SONiC. + +### Definitions/Abbreviations + +| Definitions/Abbreviation | Description | +|--------------------------|--------------------------------------------| +| API | Application Programmable Interface | +| FC | Flex Counter | +| VID | SAIRedis Virtual object identifier | +| SAI | Switch Abstraction Interface | + +### Overview + +Policer Counters provides a simple and scalable approach for monitoring and analyzing traffic policing statistics. +This design leverages the existing FC infrastructure, to efficiently collect, process, and store policer statistics such as total packets/bytes and color-based (green/yellow/red) packet/byte counts. By offering real-time visibility into traffic patterns and policy enforcement, this feature enhances network management capabilities, facilitates troubleshooting, and enables fine-tuning of network policies. + +### Requirements + +- Support for configuring and managing policer counters through the Flex Counter infrastructure. +- Ability to retrieve policer counter values, including green, yellow, and red packet/byte counters. +- Integration with the existing SONiC Flex Counter configuration and management interfaces. +- Compatibility with the SAI for platform-independent implementation. +- Using the exsiting ```counterpoll``` CLI command we are adding support for enabling and disabling polling, and changing polling interval, based on user configuration. + +### Architecture Design + +No SONiC architecture changes are required as an existing flex counter infrastructure is being used. + +### High-Level Design + +
+ +
+ +### SAI + +The attributes that are being queried: + +| SAI Attribute | Description +|------------------------------|----------------------| +| SAI_POLICER_STAT_PACKETS | Get/set packet count | +| SAI_POLICER_STAT_ATTR_BYTES | Get/set byte count | +| SAI_POLICER_STAT_GREEN_PACKETS | Get/set green packet count | +| SAI_POLICER_STAT_GREEN_BYTES | Get/set green byte count | +| SAI_POLICER_STAT_YELLOW_PACKETS | Get/set yellow packet count | +| SAI_POLICER_STAT_YELLOW_BYTES | Get/set yellow byte count | +| SAI_POLICER_STAT_RED_PACKETS | Get/set red packet count | +| SAI_POLICER_STAT_RED_PACKETS | Get/set red byte count | + +### Orchagent + +A new type of FC has been added to flex_counter/flex_counter_manager.h for its corresponding SAI object, along with a new FC group named "POLICER": + +Counter Type: +```c++ +CounterType::POLICER +``` + +PolicerOrch holds a new object of type FlexCounterManager and is initialized with ```StatsMode::READ``` +and a default polling interval of 10 sec and disable by default: +```c++ +FlexCounterManager m_pc_manager; +``` + +#### Additionally, the following mapping should be added for the CLI: +- "COUNTERS_POLICER_NAME_MAP" - maps the POLICER oid to its name + +### Syncd + +Added POLICER FC group support in syncd/FlexCounter.cpp. + +### SAI API + +No new SAI API is used. + +### COUNTERS DB + +Counters table in COUNTERS DB: + +- "COUNTERS:oid:+ +
+ + +### POLICER counter de-registration in FC ++ +
+ +### CLI + +*policerstat* utility is added to reads counters from the COUNTERS DB using the POLICER table in CONFIG DB and the COUNTERS_POLICER_NAME_MAP. It maps each POLICER to its VID and fetches counter values. If a map entry or VID is missing, it shows N/A, indicating either the POLICER was created without a counter, the policer/map entry isn't created yet, polling is disabled, or syncd hasn't updated the COUNTERS DB. + +``` +admin@sonic:~$ policerstat + Name Green Packets Green Bytes Yellow Packets Yellow Bytes Red Packets Red Bytes +------- --------------- ------------- ---------------- --------------- ------------- ------------ +span_policer 600 61440 300 30720 100 10240 + +``` + +Added a new CLI command +``` +show policer counter