diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json b/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json index 14c387d5effa..95e9b7ba9f80 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json @@ -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"] } } + diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json index 3f6d5e6c16c4..d1e82873bdda 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json @@ -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": "" + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-snmp.yang b/src/sonic-yang-models/yang-models/sonic-snmp.yang index f49c28f98050..1579dc1f04d8 100644 --- a/src/sonic-yang-models/yang-models/sonic-snmp.yang +++ b/src/sonic-yang-models/yang-models/sonic-snmp.yang @@ -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"; @@ -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"; + } + } + } } }