diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 16f3b3e36f35..bb83598e7f84 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -64,6 +64,7 @@ './yang-models/sonic-route-common.yang', './yang-models/sonic-route-map.yang', './yang-models/sonic-routing-policy-sets.yang', + './yang-models/sonic-sflow.yang', './yang-models/sonic-system-aaa.yang', './yang-models/sonic-system-tacacs.yang', './yang-models/sonic-types.yang', diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 2693c5c22164..da880a2549b9 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -792,6 +792,36 @@ "polling_interval": "0" } }, + + "SFLOW_COLLECTOR": { + "collector1": { + "collector_ip": "10.100.12.13", + "collector_port": "6343" + }, + "collector2": { + "collector_ip": "10.144.1.2" + } + }, + + "SFLOW_SESSION": { + "Ethernet0": { + "admin_state": "down", + "sample_rate": "40000" + }, + "Ethernet16": { + "admin_state": "up", + "sample_rate": "32768" + } + }, + + "SFLOW" : { + "global": { + "admin_state": "up", + "polling_interval": "20", + "agent_id": "Ethernet0" + } + }, + "AAA": { "authentication": { "login": "local" @@ -908,6 +938,7 @@ "prefix1|1|10.0.0.0/8|8..16": { } } + }, "SAMPLE_CONFIG_DB_UNKNOWN": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/sflow.json b/src/sonic-yang-models/tests/yang_model_tests/tests/sflow.json new file mode 100644 index 000000000000..42d09a773c0d --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/sflow.json @@ -0,0 +1,47 @@ +{ + "SFLOW_COLLECTOR_TEST": { + "desc": "Configure a collector in SFLOW_COLLECTOR table." + }, + "SFLOW_COLLECTOR_WRONG_NAME_TEST": { + "desc": "Configure a collector with incorrect name in SFLOW_COLLECTOR table.", + "eStr" : ["not", "satisfy", "the", "constraint", "1..64"] + }, + "SFLOW_TEST_WITHOUT_COLLECTOR_IP": { + "desc": "Configure a collector without collector IP attribute in SFLOW_COLLECTOR table.", + "eStrKey" : "Mandatory" + }, + "SFLOW_TEST_EXCEEDING_MAX_ELEMENTS": { + "desc": "Configure collectors above the specified limit in SFLOW_COLLECTOR table.", + "eStr": ["Too many \"SFLOW_COLLECTOR_LIST\" elements"] + }, + "SFLOW_SESSION_TEST": { + "desc": "Configure a sflow session in SFLOW_SESSION table." + }, + "SFLOW_SESSION_TEST_WITH_NON_EXIST_PORT": { + "desc": "Configure Port in SFLOW_SESSION table which does not exist in PORT table.", + "eStrKey": "InvalidValue" + }, + "SFLOW_SESSION_TEST_WITH_INCORRECT_PORT_NAME_PATTERN": { + "desc": "Configure SFLOW_SESSION table with incorrect pattern in port name attribute.", + "eStrKey": "InvalidValue" + }, + "SFLOW_SESSION_TEST_WITH_INCORRECT_SAMPLE_RATE": { + "desc": "Configure sflow session in SFLOW_SESSION table with an out of range sample rate.", + "eStr": ["sFlow sample rate must be [256-8388608]"] + }, + "SFLOW_SESSION_TEST_WITH_INCORRECT_PORT_TYPE_IN_SAMPLE_RATE": { + "desc": "Configure sflow session in SFLOW_SESSION table with an incorrect port type in sample rate.", + "eStrKey": "Must" + }, + "SFLOW_TEST": { + "desc": "Configure sflow global entry in SFLOW table." + }, + "SFLOW_TEST_WITH_NON_EXIST_PORT": { + "desc": "Configure Port in SFLOW table which does not exist in PORT table.", + "eStrKey": "InvalidValue" + }, + "SFLOW_TEST_WITH_INCORRECT_POLLING_INTERVAL": { + "desc": "Configure SFLOW table with an out of range polling interval.", + "eStr": ["sFlow polling interval must be [0, 5-300]"] + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/sflow.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/sflow.json new file mode 100644 index 000000000000..5d1a561a9f66 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/sflow.json @@ -0,0 +1,225 @@ +{ + "SFLOW_COLLECTOR_TEST": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_COLLECTOR": { + "SFLOW_COLLECTOR_LIST": [ + { + "name": "collector1", + "collector_ip": "10.100.12.13", + "collector_port": "6343" + } + ] + } + } + }, + + "SFLOW_COLLECTOR_WRONG_NAME_TEST": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_COLLECTOR": { + "SFLOW_COLLECTOR_LIST": [ + { + "name": "collector1111111111111111111111111111111111111111111111111111111111111111", + "collector_ip": "10.100.12.13" + } + ] + } + } + }, + + "SFLOW_TEST_WITHOUT_COLLECTOR_IP": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_COLLECTOR": { + "SFLOW_COLLECTOR_LIST": [ + { + "name": "collector1" + } + ] + } + } + }, + + "SFLOW_TEST_EXCEEDING_MAX_ELEMENTS": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_COLLECTOR": { + "SFLOW_COLLECTOR_LIST": [ + { + "name": "collector1", + "collector_ip": "10.100.12.13" + }, + { + "name": "collector2", + "collector_ip": "10.144.1.2" + }, + { + "name": "collector3", + "collector_ip": "10.100.12.15" + } + ] + } + } + }, + + "SFLOW_SESSION_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + } + ] + } + }, + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_SESSION": { + "SFLOW_SESSION_LIST": [ + { + "port": "Ethernet0", + "admin_state": "up", + "sample_rate": "40000" + } + ] + } + } + }, + + "SFLOW_SESSION_TEST_WITH_NON_EXIST_PORT": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_SESSION": { + "SFLOW_SESSION_LIST": [ + { + "port": "Ethernet4", + "admin_state": "down", + "sample_rate": "32768" + } + ] + } + } + }, + + "SFLOW_SESSION_TEST_WITH_INCORRECT_PORT_NAME_PATTERN": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_SESSION": { + "SFLOW_SESSION_LIST": [ + { + "port": "allllll", + "admin_state": "down" + } + ] + } + } + }, + + "SFLOW_SESSION_TEST_WITH_INCORRECT_SAMPLE_RATE": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + } + ] + } + }, + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_SESSION": { + "SFLOW_SESSION_LIST": [ + { + "port": "Ethernet0", + "admin_state": "up", + "sample_rate": "40" + } + ] + } + } + }, + + "SFLOW_SESSION_TEST_WITH_INCORRECT_PORT_TYPE_IN_SAMPLE_RATE": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW_SESSION": { + "SFLOW_SESSION_LIST": [ + { + "port": "all", + "admin_state": "up", + "sample_rate": "40000" + } + ] + } + } + }, + + "SFLOW_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + } + ] + } + }, + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW": { + "global": { + "agent_id": "Ethernet0", + "admin_state": "up", + "polling_interval": "20" + } + } + } + }, + + "SFLOW_TEST_WITH_NON_EXIST_PORT": { + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW": { + "global": { + "agent_id": "Ethernet0", + "admin_state": "up", + "polling_interval": "20" + } + } + } + }, + + "SFLOW_TEST_WITH_INCORRECT_POLLING_INTERVAL": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "speed": 25000 + } + ] + } + }, + "sonic-sflow:sonic-sflow": { + "sonic-sflow:SFLOW": { + "global": { + "admin_state": "up", + "polling_interval": "305" + } + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-sflow.yang b/src/sonic-yang-models/yang-models/sonic-sflow.yang new file mode 100644 index 000000000000..62984f064c51 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-sflow.yang @@ -0,0 +1,141 @@ +module sonic-sflow{ + + namespace "http://github.com/Azure/sonic-sflow"; + prefix sflow; + yang-version 1.1; + + import ietf-inet-types { + prefix inet; + } + + import sonic-types { + prefix stypes; + } + import sonic-port { + prefix port; + } + /* + import sonic-vlan { + prefix vlan; + } + */ + import sonic-portchannel { + prefix lag; + } + import sonic-mgmt_port { + prefix mgmt-port; + } + + description "SFLOW yang Module for SONiC OS"; + + revision 2021-04-26 { + description "First Revision"; + } + + container sonic-sflow { + + container SFLOW_COLLECTOR { + list SFLOW_COLLECTOR_LIST { + max-elements 2; + key "name"; + + leaf name { + type string { + length 1..64; + } + } + + leaf collector_ip { + mandatory true; + type inet:ip-address; + } + + + leaf collector_port { + type inet:port-number; + default 6343; + } + + } /* end of list SFLOW_COLLECTOR_LIST */ + } /* end of container SFLOW_COLLECTOR */ + + container SFLOW_SESSION { + list SFLOW_SESSION_LIST { + key "port"; + + leaf port { + type union { + type leafref { + path "/port:sonic-port/port:PORT/port:PORT_LIST/port:name"; + } + type string { + pattern "all"; + } + } + description "Sets sflow session table attributes for either all interfaces or a specific Ethernet interface."; + } + + leaf admin_state { + type stypes:admin_status; + default up; + } + + leaf sample_rate { + must "../port != 'all'"; + type uint32 { + range "256..8388608" { + error-message "sFlow sample rate must be [256-8388608]"; + } + } + description "Sets the packet sampling rate. The rate is expressed as an integer N, where the intended sampling rate is 1/N packets."; + } + } /* end of list SFLOW_SESSION_LIST */ + } /* end of container SFLOW_SESSION */ + + container SFLOW { + + container global { + + leaf admin_state { + type stypes:admin_status; + default down; + } + + leaf polling_interval { + type uint16 { + range "0|5..300" { + error-message "sFlow polling interval must be [0, 5-300]"; + } + } + description "The interval within which sFlow data is collected and sent to the configured collectors"; + default 20; + } + + leaf agent_id { + type union { + type leafref { + path "/port:sonic-port/port:PORT/port:PORT_LIST/port:name"; + } + type leafref { + path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; + } + type leafref { + path "/mgmt-port:sonic-mgmt_port/mgmt-port:MGMT_PORT/mgmt-port:MGMT_PORT_LIST/mgmt-port:name"; + } + /* + type leafref { + path "/vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name"; + } + */ + type string { + pattern 'Vlan([0-9]{1,3}|[1-3][0-9]{3}|[4][0][0-8][0-9]|[4][0][9][0-4])'; + } + } + description "Interface name"; + } + } /* end of container global */ + } /* end of container SFLOW */ + + } /* end of container sonic-sflow */ + +} /* end of module sonic-sflow */