From 92d4bfef10788e42676a205d24d86f8bf7d929a6 Mon Sep 17 00:00:00 2001 From: Praveen Madhusudhana <54973959+ph408077@users.noreply.github.com> Date: Thu, 26 Aug 2021 23:00:59 +0530 Subject: [PATCH] [yang]: SONiC Yang model support for LLDP (#8120) --- src/sonic-yang-models/setup.py | 1 + .../tests/files/sample_config_db.json | 18 ++ .../tests/yang_model_tests/tests/lldp.json | 28 +++ .../yang_model_tests/tests_config/lldp.json | 166 ++++++++++++++++++ .../yang-models/sonic-lldp.yang | 155 ++++++++++++++++ 5 files changed, 368 insertions(+) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/lldp.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/lldp.json create mode 100644 src/sonic-yang-models/yang-models/sonic-lldp.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 51bc30c89b..13ce554d02 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -72,6 +72,7 @@ setup( './yang-models/sonic-versions.yang', './yang-models/sonic-vlan.yang', './yang-models/sonic-vrf.yang', + './yang-models/sonic-lldp.yang', './yang-models/sonic_yang_tree']), ], zip_safe=False, 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 a26902ad71..5d8009afbc 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1050,6 +1050,24 @@ "trap_ids": "ip2me", "trap_group": "queue1_group1" } + }, + "LLDP": { + "GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "12", + "multiplier": "5", + "supp_mgmt_address_tlv": "true", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + }, + "LLDP_PORT": { + "Ethernet0": { + "mode": "TRANSMIT", + "enabled": "true" + } } }, diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/lldp.json b/src/sonic-yang-models/tests/yang_model_tests/tests/lldp.json new file mode 100644 index 0000000000..fbd621b84f --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/lldp.json @@ -0,0 +1,28 @@ +{ + "LLDP_GLOBAL_TEST": { + "desc": "LLDP test global LLDP table" + }, + "LLDP_GLOBAL_TEST_INVALID_HELLO": { + "desc": "LLDP test global table with invalid hello value", + "eStrKey" : "InvalidValue", + "eStr": ["hello_time"] + }, + "LLDP_GLOBAL_TEST_INVALID_MULTIPLIER": { + "desc": "LLDP test global table with invalid multiplier value", + "eStrKey" : "InvalidValue", + "eStr": ["multiplier"] + }, + "LLDP_PORT_TEST": { + "desc": "LLDP test LLDP port table" + }, + "LLDP_PORT_TEST_INVALID_IFNAME": { + "desc": "LLDP test port table with invalid ifname", + "eStrKey" : "LeafRef", + "eStr": ["Eth"] + }, + "LLDP_PORT_TEST_INVALID_MODE": { + "desc": "LLDP test port table with invalid mode", + "eStrKey" : "InvalidValue", + "eStr": ["mode"] + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/lldp.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/lldp.json new file mode 100644 index 0000000000..4543fc8a1b --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/lldp.json @@ -0,0 +1,166 @@ +{ + "LLDP_GLOBAL_TEST": { + "sonic-lldp:sonic-lldp": { + "sonic-lldp:LLDP": { + "sonic-lldp:GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "20", + "multiplier": "5", + "supp_mgmt_address_tlv": "true", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + } + } + }, + "LLDP_GLOBAL_TEST_INVALID_ID": { + "sonic-lldp:sonic-lldp": { + "sonic-lldp:LLDP": { + "sonic-lldp:GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "10", + "multiplier": "5", + "supp_mgmt_address_tlv": "true", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + } + } + }, + "LLDP_GLOBAL_TEST_INVALID_HELLO": { + "sonic-lldp:sonic-lldp": { + "sonic-lldp:LLDP": { + "sonic-lldp:GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "test", + "multiplier": "5", + "supp_mgmt_address_tlv": "true", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + } + } + }, + "LLDP_GLOBAL_TEST_INVALID_MULTIPLIER": { + "sonic-lldp:sonic-lldp": { + "sonic-lldp:LLDP": { + "sonic-lldp:GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "10", + "multiplier": "xyz", + "supp_mgmt_address_tlv": "true", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + } + } + }, + "LLDP_GLOBAL_TEST_DEFAULT_SUPP_MGMT_ADDR_TLV": { + "sonic-lldp:sonic-lldp": { + "sonic-lldp:LLDP": { + "sonic-lldp:GLOBAL": { + "mode": "TRANSMIT", + "enabled": "true", + "hello_time": "10", + "multiplier": "5", + "supp_mgmt_address_tlv": "false", + "supp_system_capabilities_tlv": "false", + "system_name": "sonic", + "system_description": "sonic-system" + } + } + } + }, + "LLDP_PORT_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-lldp:sonic-lldp": { + "sonic-lldp:LLDP_PORT": { + "LLDP_PORT_LIST": [ + { + "ifname": "Ethernet0", + "mode": "TRANSMIT", + "enabled": "true" + } + ] + } + } + }, + "LLDP_PORT_TEST_INVALID_IFNAME": { + "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-lldp:sonic-lldp": { + "sonic-lldp:LLDP_PORT": { + "LLDP_PORT_LIST": [ + { + "ifname": "Eth", + "mode": "TRANSMIT", + "enabled": "true" + } + ] + } + } + }, + "LLDP_PORT_TEST_INVALID_MODE": { + "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-lldp:sonic-lldp": { + "sonic-lldp:LLDP_PORT": { + "LLDP_PORT_LIST": [ + { + "ifname": "Ethernet0", + "mode": "TRANSMITTING", + "enabled": "true" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-lldp.yang b/src/sonic-yang-models/yang-models/sonic-lldp.yang new file mode 100644 index 0000000000..d1b04f28e9 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-lldp.yang @@ -0,0 +1,155 @@ +module sonic-lldp { + namespace "http://github.com/Azure/sonic-lldp"; + prefix slldp; + yang-version 1.1; + + import sonic-port { + prefix prt; + } + + import sonic-extension { + prefix sonic-ext; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONiC LLDP yang model"; + + revision 2021-07-08 { + description + "Initial revision."; + } + + grouping lldp_mode_config { + leaf enabled { + type boolean; + description + "Enable/Disable LLDP"; + } + + leaf mode { + type enumeration { + enum RECEIVE; + enum TRANSMIT; + } + + description + "RX/TX mode for LLDP frames"; + } + } + + container sonic-lldp { + container LLDP { + container GLOBAL { + + leaf hello_time { + type uint8 { + range "5..254" { + error-message "Invalid hello timer value."; + } + } + default 30; + units seconds; + description + "It is the time interval at which periodic hellos are + exchanged. Default is 30 seconds"; + } + + leaf multiplier { + type uint8 { + range "1..10" { + error-message "Invalid LLDP multiplier value."; + } + } + default 4; + description + "This multiplier value is used to determine the timeout + interval (i.e. hello-time x multiplier value) after + which LLDP neighbor entry is deleted."; + } + + leaf system_name { + type string; + description + "System administratively assigned name"; + } + + leaf system_description { + type string; + description + "System description"; + } + + leaf supp_mgmt_address_tlv { + type boolean; + default false; + description + "Suppress sending of Management Address TLV in LLDP frames"; + } + + leaf supp_system_capabilities_tlv { + type boolean; + default false; + description + "Suppress sending of System Capabilities TLV in LLDP frames"; + } + + leaf enabled { + type boolean; + default true; + description + "Enable/Disable LLDP"; + } + + leaf mode { + type enumeration { + enum RECEIVE; + enum TRANSMIT; + } + + description + "RX/TX mode for LLDP frames"; + } + + //uses lldp_mode_config; + } + } + + container LLDP_PORT { + list LLDP_PORT_LIST { + key "ifname"; + + leaf ifname { + type leafref { + path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:name"; + } + description + "Reference of port on which LLDP to be configured."; + } + + leaf enabled { + type boolean; + default true; + description + "Enable/Disable LLDP"; + } + + leaf mode { + type enumeration { + enum RECEIVE; + enum TRANSMIT; + } + + description + "RX/TX mode for LLDP frames"; + } + //uses lldp_mode_config; + } + } + } +}