Skip to content

Commit

Permalink
[YANG][SNMP]: Add YANG model for SNMP_AGENT_ADDRESS_CONFIG table (son…
Browse files Browse the repository at this point in the history
…ic-net#15587)

#### Why I did it
sonic-net/sonic-utilities#472 Added SNMP_AGENT_ADDRESS_CONFIG table in config db.
This PR is to add corresponding YANG model for that table.
##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
Added YANG modesl for SNMP_AGENT_ADDRESS_CONFIG.

keys: agent_ip, port number, vrf.
CLI implementaion checks if agent_ip, port number already exists in CONFIG_DB table, if it does, then new entry is not added.
So added another condition to ensure combination of agent_ip and port is unique.
Below is an example of how data looks like in DB:
```
127.0.0.1:6379[4]> HGETALL  "SNMP_AGENT_ADDRESS_CONFIG|10.1.1.1|161|foo"
1) "NULL"
2) "NULL"
127.0.0.1:6379[4]> HGETALL "SNMP_AGENT_ADDRESS_CONFIG|10.1.0.32|161|"
1) "NULL"
2) "NULL"
```
#### How to verify it
Added unit-test for various combinations and ensures that it passes.
  • Loading branch information
SuvarnaMeenakshi authored and sonic-otn committed Sep 20, 2023
1 parent 9dc9899 commit c48b03a
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,40 @@
"SNMP_USER_PRIV_LONG_ENCRYPT_PASS_NEG_TEST": {
"desc": "Load SNMP user with user type Priv with long encryption password",
"eStrKey": "Range"
},
"SNMP_AGENT_ADDRESS_CONFIG": {
"desc": "Load SNMP agent address config"
},
"SNMP_AGENT_ADDRESS_CONFIG_IPV6": {
"desc": "Load SNMP agent address config"
},
"SNMP_AGENT_ADDRESS_CONFIG_EMPTY_PORT_NUMBER": {
"desc": "Load SNMP agent address config with empty port number"
},
"SNMP_AGENT_ADDRESS_CONFIG_MGMT_VRF": {
"desc": "Load SNMP agent address config with mgmt vrf"
},
"SNMP_AGENT_ADDRESS_CONFIG_NO_VRF": {
"desc": "Load SNMP agent address config with no vrf",
"eStr": ["Missing required element"]
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_PORT": {
"desc": "Load SNMP agent address config with invalid port",
"eStrKey": "InvalidValue"
},
"SNMP_AGENT_ADDRESS_CONFIG_DUPLICATE_IP_PORT": {
"desc": "Load two SNMP agent address config same ip and port",
"eStr": ["Unique data leaf(s)"]
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_IPV4_ADDRESS": {
"desc": "Load SNMP agent address config with invalid IPv4 address",
"eStrKey": "InvalidValue",
"eStr": ["ip"]
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_IPV6_ADDRESS": {
"desc": "Load SNMP agent address config with invalid IPV6 address",
"eStrKey": "InvalidValue",
"eStr": ["ip"]
}
}

121 changes: 121 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,126 @@
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "161",
"vrf_name": ""
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_IPV6": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "fd00::1",
"port": "161",
"vrf_name": ""
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_EMPTY_PORT_NUMBER": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "",
"vrf_name": "mgmt"
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_MGMT_VRF": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "161",
"vrf_name": "mgmt"
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_NO_VRF": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "161"
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_PORT": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "65536",
"vrf_name": "mgmt"
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_DUPLICATE_IP_PORT": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "10.0.0.1",
"port": "161",
"vrf_name": "mgmt"
},
{
"agent_ip": "10.0.0.1",
"port": "161",
"vrf_name": ""
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_IPV4_ADDRESS": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "340.1.1.10",
"port": "161",
"vrf_name": ""
}
]
}
}
},
"SNMP_AGENT_ADDRESS_CONFIG_INVALID_IPV6_ADDRESS": {
"sonic-snmp:sonic-snmp": {
"sonic-snmp:SNMP_AGENT_ADDRESS_CONFIG": {
"SNMP_AGENT_ADDRESS_LIST": [
{
"agent_ip": "2001:aa:aa:aa",
"port": "161",
"vrf_name": ""
}
]
}
}
}
}
43 changes: 43 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-snmp.yang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module sonic-snmp {
prefix ssnmp;
yang-version 1.1;

import ietf-inet-types {
prefix inet;
}
import sonic-vrf {
prefix vrf;
}

organization
"SONiC";
Expand Down Expand Up @@ -156,5 +162,42 @@ module sonic-snmp {
}
}
}
container SNMP_AGENT_ADDRESS_CONFIG {
list SNMP_AGENT_ADDRESS_LIST {
key "agent_ip port vrf_name";
unique "agent_ip port";
description "List of SNMP agent listening IP Addresses and ports.";

leaf agent_ip {
type inet:ip-address;
description "SNMP agent listening IP";
}
leaf port {
type union {
type string {
pattern '';
}
type inet:port-number;
}
default "";
description "SNMP agent listening port number";
}
leaf vrf_name {
type union {
type string {
pattern '';
}
type string {
pattern 'mgmt';
}
type string {
pattern "Vrf[a-zA-Z0-9_-]+";
}
}
default "";
description "VRF name";
}
}
}
}
}

0 comments on commit c48b03a

Please sign in to comment.