Skip to content

Commit c140614

Browse files
theasianpianistvidyac86
authored andcommitted
[YANG] Add YANG models for DEBUG_COUNTER and DEBUG_COUNTER_DROP_REASON tables (sonic-net#21969)
Why I did it Fixes sonic-net#21505 Work item tracking Microsoft ADO 31237447: How I did it Add a new file containing models for both DEBUG_COUNTER and DEBUG_COUNTER_DROP_REASON tables Add test cases to cover the new model How to verify it Run the yang model tests
1 parent 0659b4c commit c140614

File tree

9 files changed

+393
-1
lines changed

9 files changed

+393
-1
lines changed

src/sonic-yang-models/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var/
2222
*.egg-info/
2323
.installed.cfg
2424
*.egg
25+
*.whl
2526

2627
# PyInstaller
2728
# Usually these files are written by a python script from a template
@@ -57,3 +58,11 @@ docs/_build/
5758
target/
5859

5960
yang-models/sonic_yang_tree
61+
tests/yang-models/sonic_yang_tree
62+
63+
# Auto-generated YANG models
64+
yang-models/sonic-acl.yang
65+
yang-models/sonic-extension.yang
66+
yang-models/sonic-policer.yang
67+
yang-models/sonic-types.yang
68+
cvlyang-models/

src/sonic-yang-models/doc/Configuration.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [Console](#console)
2626
* [CRM](#crm)
2727
* [CRM DASH](#crm-dash)
28+
* [DEBUG_COUNTER and DEBUG_COUNTER_DROP_REASON](#debug_counter-and-debug_counter_drop_reason)
2829
* [DEFAULT_LOSSLESS_BUFFER_PARAMETER](#DEFAULT_LOSSLESS_BUFFER_PARAMETER)
2930
* [Device Metadata](#device-metadata)
3031
* [Device neighbor metada](#device-neighbor-metada)
@@ -928,6 +929,42 @@ It currently allows user to administratively bring down a line-card or fabric-ca
928929
}
929930
```
930931

932+
### DEBUG_COUNTER and DEBUG_COUNTER_DROP_REASON
933+
934+
These tables contain information on drop counters which have been added
935+
936+
DEBUG_COUNTER:
937+
```
938+
; DEBUG_COUNTER table
939+
940+
key = DEBUG_COUNTER_TABLE:name
941+
name = string
942+
type = (SWITCH_INGRESS_DROPS|PORT_INGRESS_DROPS|SWITCH_EGRESS_DROPS|PORT_EGRESS_DROPS)
943+
alias = string (optional)
944+
description = string (optional)
945+
group = string (optional)
946+
947+
"DEBUG_COUNTER": {
948+
"DEBUG_4": {
949+
"alias": "BAD_DROPS",
950+
"desc": "More port ingress drops",
951+
"group": "BAD",
952+
"type": "SWITCH_INGRESS_DROPS"
953+
}
954+
}
955+
```
956+
```
957+
; DEBUG_COUNTER_DROP_REASON table
958+
959+
key = DEBUG_COUNTER_DROP_REASON_TABLE:name:reason
960+
name = name of a counter in the DEBUG_COUNTER_TABLE
961+
reason = a valid drop reason without the 'SAI_IN/OUT_DROP_REASON_' prefix (https://github.com/sonic-net/sonic-swss/blob/7a965caf4c7211afca5303191cf731858c791bcd/orchagent/debug_counter/drop_counter.cpp#L20)
962+
963+
"DEBUG_COUNTER_DROP_REASON": {
964+
"DEBUG_4|DIP_LINK_LOCAL": {},
965+
"DEBUG_4|SIP_LINK_LOCAL": {}
966+
}
967+
```
931968

932969
### DEFAULT_LOSSLESS_BUFFER_PARAMETER
933970

src/sonic-yang-models/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def run(self):
110110
'./yang-models/sonic-console.yang',
111111
'./yang-models/sonic-crm.yang',
112112
'./yang-models/sonic-dash.yang',
113+
'./yang-models/sonic-debug-counter.yang',
113114
'./yang-models/sonic-default-lossless-buffer-parameter.yang',
114115
'./yang-models/sonic-device_metadata.yang',
115116
'./yang-models/sonic-device_neighbor.yang',
@@ -293,7 +294,8 @@ def run(self):
293294
'./cvlyang-models/sonic-macsec.yang',
294295
'./cvlyang-models/sonic-bmp.yang',
295296
'./cvlyang-models/sonic-serial-console.yang',
296-
'./cvlyang-models/sonic-bgp-sentinel.yang']),
297+
'./cvlyang-models/sonic-bgp-sentinel.yang',
298+
'./cvlyang-models/sonic-debug-counter.yang']),
297299
],
298300
zip_safe=False,
299301
)

src/sonic-yang-models/tests/files/sample_config_db.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,18 @@
29062906
"PREFIX_LIST": {
29072907
"ANCHOR_PREFIX|10.0.0.0/8" : {},
29082908
"ANCHOR_PREFIX|FC00::/48" : {}
2909+
},
2910+
"DEBUG_COUNTER": {
2911+
"DEBUG_4": {
2912+
"alias": "BAD_DROPS",
2913+
"desc": "More port ingress drops",
2914+
"group": "BAD",
2915+
"type": "SWITCH_INGRESS_DROPS"
2916+
}
2917+
},
2918+
"DEBUG_COUNTER_DROP_REASON": {
2919+
"DEBUG_4|DIP_LINK_LOCAL": {},
2920+
"DEBUG_4|SIP_LINK_LOCAL": {}
29092921
}
29102922
},
29112923
"SAMPLE_CONFIG_DB_UNKNOWN": {

src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def initTest(self):
4949
'MinElements': ['Too few'],
5050
'MaxElements': ['Too many'],
5151
'UnknownElement': ['Unknown element'],
52+
'Missing': ['Missing required element'],
5253
'None': []
5354
}
5455

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"VALID_DEBUG_COUNTERS": {
3+
"desc": "One debug counter of each valid type"
4+
},
5+
"VALID_COUNTERS_WITH_DROP_REASONS": {
6+
"desc": "Multiple counters with drop reasons added"
7+
},
8+
"INVALID_DEBUG_COUNTER_TYPE": {
9+
"desc": "One debug counter with invalid type",
10+
"eStrKey": "InvalidValue"
11+
},
12+
"DEBUG_COUNTER_MISSING_COUNTER_TYPE": {
13+
"desc": "One debug counter with missing type",
14+
"eStrKey": "Missing"
15+
},
16+
"NONEXIST_DEBUG_COUNTER_FOR_DROP_REASON": {
17+
"desc": "Add a drop reason for a non-existent counter",
18+
"eStr": "The counter does not exist in the DEBUG_COUNTER table"
19+
},
20+
"INVALID_DROP_REASON": {
21+
"desc": "Add an invalid drop reason to a counter",
22+
"eStrKey": "InvalidValue"
23+
}
24+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"VALID_DEBUG_COUNTERS": {
3+
"sonic-debug-counter:sonic-debug-counter": {
4+
"sonic-debug-counter:DEBUG_COUNTER": {
5+
"DEBUG_COUNTER_LIST": [
6+
{
7+
"name": "Counter 1",
8+
"alias": "Counter 1 alias",
9+
"desc": "Counter 1 description",
10+
"group": "Counter 1 group",
11+
"type": "SWITCH_INGRESS_DROPS"
12+
},
13+
{
14+
"name": "Counter 2",
15+
"alias": "Counter 2 alias",
16+
"desc": "Counter 2 description",
17+
"group": "Counter 2 group",
18+
"type": "PORT_INGRESS_DROPS"
19+
},
20+
{
21+
"name": "Counter 3",
22+
"type": "SWITCH_EGRESS_DROPS"
23+
},
24+
{
25+
"name": "Counter 4",
26+
"type": "PORT_EGRESS_DROPS"
27+
}
28+
]
29+
}
30+
}
31+
},
32+
"VALID_COUNTERS_WITH_DROP_REASONS": {
33+
"sonic-debug-counter:sonic-debug-counter": {
34+
"sonic-debug-counter:DEBUG_COUNTER": {
35+
"DEBUG_COUNTER_LIST": [
36+
{
37+
"name": "Counter 1",
38+
"alias": "Counter 1 alias",
39+
"desc": "Counter 1 description",
40+
"group": "ingress",
41+
"type": "SWITCH_INGRESS_DROPS"
42+
},
43+
{
44+
"name": "Counter 2",
45+
"alias": "Counter 2 alias",
46+
"desc": "Counter 3 description",
47+
"group": "ingress",
48+
"type": "PORT_INGRESS_DROPS"
49+
},
50+
{
51+
"name": "Counter 3",
52+
"alias": "Counter 3 alias",
53+
"desc": "Counter 3 description",
54+
"group": "egress",
55+
"type": "PORT_EGRESS_DROPS"
56+
}
57+
]
58+
},
59+
"sonic-debug-counter:DEBUG_COUNTER_DROP_REASON": {
60+
"DEBUG_COUNTER_DROP_REASON_LIST": [
61+
{
62+
"name": "Counter 1",
63+
"reason": "VLAN_TAG_NOT_ALLOWED"
64+
},
65+
{
66+
"name": "Counter 1",
67+
"reason": "IP_HEADER_ERROR"
68+
},
69+
{
70+
"name": "Counter 1",
71+
"reason": "SMAC_EQUALS_DMAC"
72+
},
73+
{
74+
"name": "Counter 2",
75+
"reason": "VLAN_TAG_NOT_ALLOWED"
76+
},
77+
{
78+
"name": "Counter 2",
79+
"reason": "NO_L3_HEADER"
80+
},
81+
{
82+
"name": "Counter 2",
83+
"reason": "SIP_LINK_LOCAL"
84+
},
85+
{
86+
"name": "Counter 3",
87+
"reason": "L3_ANY"
88+
},
89+
{
90+
"name": "Counter 3",
91+
"reason": "L2_ANY"
92+
},
93+
{
94+
"name": "Counter 3",
95+
"reason": "EGRESS_VLAN_FILTER"
96+
}
97+
]
98+
}
99+
}
100+
},
101+
"INVALID_DEBUG_COUNTER_TYPE": {
102+
"sonic-debug-counter:sonic-debug-counter": {
103+
"sonic-debug-counter:DEBUG_COUNTER": {
104+
"DEBUG_COUNTER_LIST": [
105+
{
106+
"name": "Counter 1",
107+
"type": "INVALID_TYPE"
108+
}
109+
]
110+
}
111+
}
112+
},
113+
"DEBUG_COUNTER_MISSING_COUNTER_TYPE": {
114+
"sonic-debug-counter:sonic-debug-counter": {
115+
"sonic-debug-counter:DEBUG_COUNTER": {
116+
"DEBUG_COUNTER_LIST": [
117+
{
118+
"name": "Counter 1"
119+
}
120+
]
121+
}
122+
}
123+
},
124+
"NONEXIST_DEBUG_COUNTER_FOR_DROP_REASON": {
125+
"sonic-debug-counter:sonic-debug-counter": {
126+
"sonic-debug-counter:DEBUG_COUNTER": {
127+
"DEBUG_COUNTER_LIST": [
128+
{
129+
"name": "Counter 1",
130+
"type": "PORT_INGRESS_DROPS"
131+
132+
}
133+
]
134+
},
135+
"sonic-debug-counter:DEBUG_COUNTER_DROP_REASON": {
136+
"DEBUG_COUNTER_DROP_REASON_LIST": [
137+
{
138+
"name": "Counter 2",
139+
"reason": "L2_ANY"
140+
}
141+
]
142+
}
143+
}
144+
},
145+
"INVALID_DROP_REASON": {
146+
"sonic-debug-counter:sonic-debug-counter": {
147+
"sonic-debug-counter:DEBUG_COUNTER": {
148+
"DEBUG_COUNTER_LIST": [
149+
{
150+
"name": "Counter 1",
151+
"type": "SWITCH_INGRESS_DROPS"
152+
}
153+
]
154+
},
155+
"sonic-debug-counter:DEBUG_COUNTER_DROP_REASON": {
156+
"DEBUG_COUNTER_DROP_REASON_LIST": [
157+
{
158+
"name": "Counter 1",
159+
"reason": "INVALID_REASON"
160+
}
161+
]
162+
}
163+
}
164+
}
165+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module sonic-debug-counter {
2+
namespace "http://github.com/sonic-net/sonic-debug-counter";
3+
prefix dbgcnt;
4+
yang-version 1.1;
5+
6+
import sonic-types {
7+
prefix stypes;
8+
}
9+
10+
organization
11+
"SONiC";
12+
13+
contact
14+
"SONiC";
15+
16+
description
17+
"SONiC Debug Counter Yang Model";
18+
19+
revision 2024-03-07 {
20+
description
21+
"Initial revision";
22+
}
23+
24+
container sonic-debug-counter{
25+
container DEBUG_COUNTER {
26+
list DEBUG_COUNTER_LIST {
27+
key "name";
28+
29+
leaf name {
30+
type string;
31+
}
32+
33+
leaf alias {
34+
type string;
35+
description "Alias of the counter";
36+
}
37+
38+
leaf desc {
39+
type string;
40+
description "Description of counter (can include counter type, intended use, etc.)";
41+
}
42+
43+
leaf group {
44+
type string;
45+
description "Group name to organize counters";
46+
}
47+
48+
leaf type {
49+
type stypes:debug_counter_type;
50+
mandatory true;
51+
description "Counter type indicating scope (switch or port) and direction (ingress or egress)";
52+
}
53+
}
54+
}
55+
56+
container DEBUG_COUNTER_DROP_REASON {
57+
list DEBUG_COUNTER_DROP_REASON_LIST {
58+
key "name reason";
59+
60+
leaf name {
61+
/* Counter must first be created in DEBUG_COUNTER_TABLE before we can add reasons to it */
62+
must "(current() = ../../../DEBUG_COUNTER/DEBUG_COUNTER_LIST[name=current()]/name)" {
63+
error-message "The counter does not exist in the DEBUG_COUNTER table";
64+
}
65+
type string;
66+
}
67+
68+
leaf reason {
69+
type stypes:counter_drop_reason;
70+
description "Drop reason which will cause the counter to increment";
71+
}
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)