From e17e9f4b6079d7e94c84af2841c1a3f499f8747c Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Fri, 21 May 2021 01:12:22 +0800 Subject: [PATCH] [YANG] Enhance the port yang model with new port fields: adv_speeds, interface_type and adv_interface_types (#6948) Enhance the port yang model with new port fields: adv_speeds, interface_types and adv_interface_types Refer to HLD Azure/SONiC#732 --- .../tests/yang_model_tests/tests/port.json | 38 ++++ .../yang_model_tests/tests_config/port.json | 170 ++++++++++++++++++ .../yang-models/sonic-port.yang | 48 ++++- .../yang-models/sonic-types.yang | 24 +++ 4 files changed, 274 insertions(+), 6 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/port.json b/src/sonic-yang-models/tests/yang_model_tests/tests/port.json index e79507bd8de0..1e217820a276 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/port.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/port.json @@ -23,5 +23,43 @@ "desc": "PORT_INVALID_AUTONEG_TEST must condition failure.", "eStrKey" : "Pattern", "eStr": ["on|off"] + }, + "PORT_VALID_ADVSPEEDS_TEST_1": { + "desc": "PORT_VALID_ADVSPEEDS_TEST_1 no failure." + }, + "PORT_VALID_ADVSPEEDS_TEST_2": { + "desc": "PORT_VALID_ADVSPEEDS_TEST_2 no failure." + }, + "PORT_INVALID_ADVSPEEDS_TEST_1": { + "desc": "PORT_INVALID_ADVSPEEDS_TEST_1 InvalidValue condition failure.", + "eStrKey" : "InvalidValue", + "eStr": ["adv_speeds"] + }, + "PORT_INVALID_ADVSPEEDS_TEST_2": { + "desc": "PORT_INVALID_ADVSPEEDS_TEST_2 must condition failure.", + "eStrKey" : "Must" + }, + "PORT_VALID_TYPE_TEST": { + "desc": "PORT_VALID_TYPE_TEST no failure." + }, + "PORT_INVALID_TYPE_TEST": { + "desc": "PORT_INVALID_TYPE_TEST InvalidValue condition failure.", + "eStrKey" : "InvalidValue", + "eStr": ["interface_type"] + }, + "PORT_VALID_ADVTYPES_TEST_1": { + "desc": "PORT_VALID_ADVTYPES_TEST_1 no failure." + }, + "PORT_VALID_ADVTYPES_TEST_2": { + "desc": "PORT_VALID_ADVTYPES_TEST_2 no failure." + }, + "PORT_INVALID_ADVTYPES_TEST_1": { + "desc": "PORT_INVALID_ADVTYPES_TEST_1 InvalidValue condition failure.", + "eStrKey" : "InvalidValue", + "eStr": ["adv_interface_types"] + }, + "PORT_INVALID_ADVTYPES_TEST_2": { + "desc": "PORT_INVALID_ADVTYPES_TEST_2 must condition failure.", + "eStrKey" : "Must" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json index 661bf252bc61..50d04a007e8d 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json @@ -83,5 +83,175 @@ ] } } + }, + + "PORT_VALID_ADVSPEEDS_TEST_1": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_speeds": [25000,40000] + } + ] + } + } + }, + + "PORT_VALID_ADVSPEEDS_TEST_2": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_speeds": ["all"] + } + ] + } + } + }, + + "PORT_INVALID_ADVSPEEDS_TEST_1": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_speeds": ["invalid"] + } + ] + } + } + }, + + "PORT_INVALID_ADVSPEEDS_TEST_2": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_speeds": ["all", "25000"] + } + ] + } + } + }, + + "PORT_VALID_TYPE_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "interface_type": "CR4" + } + ] + } + } + }, + + "PORT_INVALID_TYPE_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "interface_type": "Invalid" + } + ] + } + } + }, + + "PORT_VALID_ADVTYPES_TEST_1": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_interface_types": ["CR4", "CR"] + } + ] + } + } + }, + + "PORT_VALID_ADVTYPES_TEST_2": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_interface_types": ["all"] + } + ] + } + } + }, + + "PORT_INVALID_ADVTYPES_TEST_1": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_interface_types": ["Invalid"] + } + ] + } + } + }, + + "PORT_INVALID_ADVTYPES_TEST_2": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_interface_types": ["all", "CR4"] + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index e585a2caa3c6..ff235ee3ef64 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -63,6 +63,48 @@ module sonic-port{ } } + leaf autoneg { + description "Port auto negotiation mode"; + + type string { + pattern "on|off"; + } + } + + leaf-list adv_speeds { + description "Port advertised speeds, valid value could be a list of interger or all"; + + type union { + type uint32 { + range 1..400000; + } + type string { + pattern "all"; + } + } + } + + must "(count(adv_speeds[text()='all']) = 0) or (count(adv_speeds) = 1)"; + + leaf interface_type { + description "Port interface type"; + + type stypes:interface_type; + } + + leaf-list adv_interface_types { + description "Port advertised interface type, valid value could be a list of stypes:interface_type or all"; + + type union { + type stypes:interface_type; + type string { + pattern "all"; + } + } + } + + must "(count(adv_interface_types[text()='all']) = 0) or (count(adv_interface_types) = 1)"; + leaf mtu { type uint16 { range 1..9216; @@ -90,12 +132,6 @@ module sonic-port{ pattern "on|off"; } } - - leaf autoneg { - type string { - pattern "on|off"; - } - } } /* end of list PORT_LIST */ } /* end of container PORT */ diff --git a/src/sonic-yang-models/yang-models/sonic-types.yang b/src/sonic-yang-models/yang-models/sonic-types.yang index 93842a11f51e..2b0fdafafa2c 100644 --- a/src/sonic-yang-models/yang-models/sonic-types.yang +++ b/src/sonic-yang-models/yang-models/sonic-types.yang @@ -114,4 +114,28 @@ module sonic-types { pattern "percentage|used|free|PERCENTAGE|USED|FREE"; } } + + typedef interface_type { + type enumeration { + enum CR; + enum CR2; + enum CR4; + enum SR; + enum SR2; + enum SR4; + enum LR; + enum LR4; + enum KR; + enum KR4; + enum CAUI; + enum GMII; + enum SFI; + enum XLAUI; + enum KR2; + enum CAUI4; + enum XAUI; + enum XFI; + enum XGMII; + } + } }