From 8542063d64f728358bccf2c90539e5f791397c47 Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 8 Feb 2021 16:18:57 +0800 Subject: [PATCH 1/8] Add yang model for port auto-neg feature --- .../yang-models/sonic-port.yang | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 61338234126c..3dc2f373049e 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -67,6 +67,30 @@ module sonic-port{ } } + leaf autoneg { + type string { + pattern "0|1"; + } + } + + leaf adv_speeds { + type string { + length 1..128; + } + } + + leaf interface_type { + type string { + length 1..128; + } + } + + leaf adv_interface_types { + type string { + length 1..128; + } + } + leaf mtu { type uint16 { range 1..9216; From a643311d65b78e88c69835b9333aea0371923661 Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 10 Feb 2021 10:08:02 +0800 Subject: [PATCH 2/8] Add unit test --- .../tests/yang_model_tests/test_yang_model.py | 4 +++ .../tests/yang_model_tests/yangTest.json | 28 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py index adf643ad793e..feb5ac023cf5 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py +++ b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py @@ -181,6 +181,10 @@ def initTest(self): 'desc': 'LOAD PORT TABLE FEC PATTERN FAILURE', 'eStr': self.defaultYANGFailure['Pattern'] + ['rc'] }, + 'PORT_INVALID_AUTONEG_TEST': { + 'desc': 'LOAD PORT TABLE AUTONEG PATTERN FAILURE.', + 'eStr': self.defaultYANGFailure['Pattern'] + ['2'], + }, 'CRM_WITH_WRONG_PERCENTAGE': { 'desc': 'CRM_WITH_WRONG_PERCENTAGE must condition failure.', 'eStr': self.defaultYANGFailure['Must'] diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index 92c841830d63..a2792c37b47e 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -632,7 +632,11 @@ "fec": "rs", "mtu": 9000, "admin_status": "up", - "pfc_asym": "on" + "pfc_asym": "on", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }] } } @@ -656,6 +660,28 @@ } }, + "PORT_INVALID_AUTONEG_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [{ + "port_name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "description": "Ethernet8", + "speed": 25000, + "fec": "rs", + "mtu": 9000, + "admin_status": "up", + "pfc_asym": "on", + "autoneg": "2", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" + }] + } + } + }, + "ACL_RULE_ARP_TYPE_ICMPV6_CODE_MISMATCH": { "sonic-acl:sonic-acl": { "sonic-acl:ACL_RULE": { From a590759c2e1b3934c069ec6ddc516b3052792e78 Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 10 Feb 2021 16:11:07 +0800 Subject: [PATCH 3/8] Add new field to sample config db --- .../tests/yang_model_tests/yangTest.json | 228 +++++++++++++++--- 1 file changed, 190 insertions(+), 38 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index a2792c37b47e..31e8061ef102 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -1326,259 +1326,407 @@ "lanes": "65", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet1": { "alias": "Eth1/2", "lanes": "66", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet2": { "alias": "Eth1/3", "lanes": "67", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet3": { "alias": "Eth1/4", "lanes": "68", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet4": { "alias": "Eth2/1", "lanes": "69", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet5": { "alias": "Eth2/2", "lanes": "70", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet6": { "alias": "Eth2/3", "lanes": "71", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet7": { "alias": "Eth2/4", "lanes": "72", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet8": { "alias": "Eth3/1", "lanes": "73", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet9": { "alias": "Eth3/2", "lanes": "74", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet10": { "alias": "Eth3/3", "lanes": "75", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet11": { "alias": "Eth3/4", "lanes": "76", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet12": { "alias": "Eth4/1", "lanes": "77", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet13": { "alias": "Eth4/2", "lanes": "78", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet14": { "alias": "Eth4/3", "lanes": "79", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet15": { "alias": "Eth4/4", "lanes": "80", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet16": { "alias": "Eth5/1", "lanes": "33", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet17": { "alias": "Eth5/2", "lanes": "34", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet18": { "alias": "Eth5/3", "lanes": "35", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet19": { "alias": "Eth5/4", "lanes": "36", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet20": { "alias": "Eth6/1", "lanes": "37", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet21": { "alias": "Eth6/2", "lanes": "38", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet22": { "alias": "Eth6/3", "lanes": "39", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet23": { "alias": "Eth6/4", "lanes": "40", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet24": { "alias": "Eth7/1", "lanes": "41", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet25": { "alias": "Eth7/2", "lanes": "42", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet26": { "alias": "Eth7/3", "lanes": "43", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet27": { "alias": "Eth7/4", "lanes": "44", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet28": { "alias": "Eth8/1", "lanes": "45", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet29": { "alias": "Eth8/2", "lanes": "46", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet30": { "alias": "Eth8/3", "lanes": "47", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet31": { "alias": "Eth8/4", "lanes": "48", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet32": { "alias": "Eth9/1", "lanes": "49", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet33": { "alias": "Eth9/2", "lanes": "50", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet34": { "alias": "Eth9/3", "lanes": "51", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet35": { "alias": "Eth9/4", "lanes": "52", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet36": { "alias": "Eth10/1", "lanes": "53", "description": "", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" }, "Ethernet112": { "alias": "Eth29/1", @@ -1586,7 +1734,11 @@ "description": "50G|dccsw01.nw|Eth18", "fec": "fc", "speed": "11100", - "admin_status": "up" + "admin_status": "up", + "autoneg": "1", + "adv_speeds": "10000,25000", + "adv_interface_types": "CR,CR2", + "interface_type": "CR" } }, "ACL_TABLE": { From d7b212965d39030c4fb5970e0c716425b1cc9198 Mon Sep 17 00:00:00 2001 From: junchao Date: Thu, 4 Mar 2021 16:13:57 +0800 Subject: [PATCH 4/8] Optimize yang model definition for port auto negotiation attributes --- .../tests/yang_model_tests/yangTest.json | 232 +++--------------- .../yang-models/sonic-port.yang | 26 +- .../yang-models/sonic-types.yang | 24 ++ 3 files changed, 80 insertions(+), 202 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index 31e8061ef102..f889a3a6dcc6 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -634,8 +634,8 @@ "admin_status": "up", "pfc_asym": "on", "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", + "adv_speeds": ["10000","25000"], + "adv_interface_types": ["all"], "interface_type": "CR" }] } @@ -1326,407 +1326,259 @@ "lanes": "65", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet1": { "alias": "Eth1/2", "lanes": "66", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet2": { "alias": "Eth1/3", "lanes": "67", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet3": { "alias": "Eth1/4", "lanes": "68", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet4": { "alias": "Eth2/1", "lanes": "69", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet5": { "alias": "Eth2/2", "lanes": "70", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet6": { "alias": "Eth2/3", "lanes": "71", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet7": { "alias": "Eth2/4", "lanes": "72", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet8": { "alias": "Eth3/1", "lanes": "73", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet9": { "alias": "Eth3/2", "lanes": "74", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet10": { "alias": "Eth3/3", "lanes": "75", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet11": { "alias": "Eth3/4", "lanes": "76", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet12": { "alias": "Eth4/1", "lanes": "77", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet13": { "alias": "Eth4/2", "lanes": "78", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet14": { "alias": "Eth4/3", "lanes": "79", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet15": { "alias": "Eth4/4", "lanes": "80", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet16": { "alias": "Eth5/1", "lanes": "33", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet17": { "alias": "Eth5/2", "lanes": "34", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet18": { "alias": "Eth5/3", "lanes": "35", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet19": { "alias": "Eth5/4", "lanes": "36", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet20": { "alias": "Eth6/1", "lanes": "37", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet21": { "alias": "Eth6/2", "lanes": "38", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet22": { "alias": "Eth6/3", "lanes": "39", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet23": { "alias": "Eth6/4", "lanes": "40", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet24": { "alias": "Eth7/1", "lanes": "41", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet25": { "alias": "Eth7/2", "lanes": "42", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet26": { "alias": "Eth7/3", "lanes": "43", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet27": { "alias": "Eth7/4", "lanes": "44", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet28": { "alias": "Eth8/1", "lanes": "45", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet29": { "alias": "Eth8/2", "lanes": "46", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet30": { "alias": "Eth8/3", "lanes": "47", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet31": { "alias": "Eth8/4", "lanes": "48", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet32": { "alias": "Eth9/1", "lanes": "49", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet33": { "alias": "Eth9/2", "lanes": "50", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet34": { "alias": "Eth9/3", "lanes": "51", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet35": { "alias": "Eth9/4", "lanes": "52", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet36": { "alias": "Eth10/1", "lanes": "53", "description": "", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" }, "Ethernet112": { "alias": "Eth29/1", @@ -1734,11 +1586,7 @@ "description": "50G|dccsw01.nw|Eth18", "fec": "fc", "speed": "11100", - "admin_status": "up", - "autoneg": "1", - "adv_speeds": "10000,25000", - "adv_interface_types": "CR,CR2", - "interface_type": "CR" + "admin_status": "up" } }, "ACL_TABLE": { diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 3dc2f373049e..6677fe9ec577 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -72,22 +72,28 @@ module sonic-port{ pattern "0|1"; } } - - leaf adv_speeds { - type string { - length 1..128; + + leaf-list adv_speeds { + type union { + type uint32 { + range 1..400000; + } + type string { + pattern "all"; + } } } leaf interface_type { - type string { - length 1..128; - } + type stypes:interface_type; } - leaf adv_interface_types { - type string { - length 1..128; + leaf-list adv_interface_types { + type union { + type stypes:interface_type; + type string { + pattern "all"; + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-types.yang b/src/sonic-yang-models/yang-models/sonic-types.yang index 0bfcddc56103..e102badb0fb7 100644 --- a/src/sonic-yang-models/yang-models/sonic-types.yang +++ b/src/sonic-yang-models/yang-models/sonic-types.yang @@ -107,4 +107,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; + } + } } From 3396cc7e4624ccc80e06bb859675fac89026f57d Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 5 Mar 2021 09:13:03 +0800 Subject: [PATCH 5/8] Change autoneg value pattern to on|off --- .../tests/yang_model_tests/test_yang_model.py | 2 +- src/sonic-yang-models/tests/yang_model_tests/yangTest.json | 4 ++-- src/sonic-yang-models/yang-models/sonic-port.yang | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py index feb5ac023cf5..5d550ccbb7d9 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py +++ b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py @@ -183,7 +183,7 @@ def initTest(self): }, 'PORT_INVALID_AUTONEG_TEST': { 'desc': 'LOAD PORT TABLE AUTONEG PATTERN FAILURE.', - 'eStr': self.defaultYANGFailure['Pattern'] + ['2'], + 'eStr': self.defaultYANGFailure['Pattern'] + ['invalid'], }, 'CRM_WITH_WRONG_PERCENTAGE': { 'desc': 'CRM_WITH_WRONG_PERCENTAGE must condition failure.', diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index f889a3a6dcc6..6ffbd512d86e 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -633,7 +633,7 @@ "mtu": 9000, "admin_status": "up", "pfc_asym": "on", - "autoneg": "1", + "autoneg": "on", "adv_speeds": ["10000","25000"], "adv_interface_types": ["all"], "interface_type": "CR" @@ -673,7 +673,7 @@ "mtu": 9000, "admin_status": "up", "pfc_asym": "on", - "autoneg": "2", + "autoneg": "invalid", "adv_speeds": "10000,25000", "adv_interface_types": "CR,CR2", "interface_type": "CR" diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 6677fe9ec577..2fdcda43a9c0 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -69,7 +69,7 @@ module sonic-port{ leaf autoneg { type string { - pattern "0|1"; + pattern "on|off"; } } From efae6d9edb73c185b01c39c0a2a45f4f699b21b0 Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 17 Mar 2021 10:23:26 +0800 Subject: [PATCH 6/8] Add description for each new field --- src/sonic-yang-models/yang-models/sonic-port.yang | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 2fdcda43a9c0..7b1e633b5a60 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -68,12 +68,16 @@ module sonic-port{ } leaf autoneg { + /* Port auto negotiation mode */ type string { pattern "on|off"; } } leaf-list adv_speeds { + /* A list of advertised port speeds, + "all" means to advertise all supported speeds + */ type union { type uint32 { range 1..400000; @@ -85,10 +89,14 @@ module sonic-port{ } leaf interface_type { + /* Port interface type */ type stypes:interface_type; } leaf-list adv_interface_types { + /* A list of advertised interface types, + "all" means to advertise all supported interface types + */ type union { type stypes:interface_type; type string { From 2489804d4c674552fc37afb41d428e9ec9804a5e Mon Sep 17 00:00:00 2001 From: junchao Date: Fri, 2 Apr 2021 11:45:35 +0800 Subject: [PATCH 7/8] Add description for new fields and adjust unit test --- .../tests/yang_model_tests/tests/port.json | 30 ++++ .../yang_model_tests/tests_config/port.json | 136 ++++++++++++++++++ .../yang-models/sonic-port.yang | 14 +- 3 files changed, 174 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..456a53685104 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,35 @@ "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": { + "desc": "PORT_INVALID_ADVSPEEDS_TEST must condition failure.", + "eStrKey" : "InvalidValue", + "eStr": ["adv_speeds"] + }, + "PORT_VALID_TYPE_TEST": { + "desc": "PORT_VALID_TYPE_TEST no failure." + }, + "PORT_INVALID_TYPE_TEST": { + "desc": "PORT_INVALID_TYPE_TEST no 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": { + "desc": "PORT_INVALID_ADVTYPES_TEST no failure.", + "eStrKey" : "InvalidValue", + "eStr": ["adv_interface_types"] } } 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..a52a29f72287 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,141 @@ ] } } + }, + + "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": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_speeds": ["invalid"] + } + ] + } + } + }, + + "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": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 25000, + "autoneg": "on", + "adv_interface_types": ["Invalid"] + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 4ddb2eba075c..4f1b31e50f6f 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -64,12 +64,16 @@ 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; @@ -81,10 +85,14 @@ module sonic-port{ } 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 { @@ -120,12 +128,6 @@ module sonic-port{ pattern "on|off"; } } - - leaf autoneg { - type string { - pattern "on|off"; - } - } } /* end of list PORT_LIST */ } /* end of container PORT */ From f4399a5f95c3a22ec03319bf2b7261e4bab18741 Mon Sep 17 00:00:00 2001 From: junchao Date: Thu, 15 Apr 2021 18:09:34 +0800 Subject: [PATCH 8/8] Fix review comment --- .../tests/yang_model_tests/tests/port.json | 18 ++++++--- .../yang_model_tests/tests_config/port.json | 38 ++++++++++++++++++- .../yang-models/sonic-port.yang | 8 +++- 3 files changed, 55 insertions(+), 9 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 456a53685104..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 @@ -30,16 +30,20 @@ "PORT_VALID_ADVSPEEDS_TEST_2": { "desc": "PORT_VALID_ADVSPEEDS_TEST_2 no failure." }, - "PORT_INVALID_ADVSPEEDS_TEST": { - "desc": "PORT_INVALID_ADVSPEEDS_TEST must condition 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 no failure.", + "desc": "PORT_INVALID_TYPE_TEST InvalidValue condition failure.", "eStrKey" : "InvalidValue", "eStr": ["interface_type"] }, @@ -49,9 +53,13 @@ "PORT_VALID_ADVTYPES_TEST_2": { "desc": "PORT_VALID_ADVTYPES_TEST_2 no failure." }, - "PORT_INVALID_ADVTYPES_TEST": { - "desc": "PORT_INVALID_ADVTYPES_TEST 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 a52a29f72287..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 @@ -119,7 +119,7 @@ } }, - "PORT_INVALID_ADVSPEEDS_TEST": { + "PORT_INVALID_ADVSPEEDS_TEST_1": { "sonic-port:sonic-port": { "sonic-port:PORT": { "PORT_LIST": [ @@ -136,6 +136,23 @@ } }, + "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": { @@ -204,7 +221,7 @@ } }, - "PORT_INVALID_ADVTYPES_TEST": { + "PORT_INVALID_ADVTYPES_TEST_1": { "sonic-port:sonic-port": { "sonic-port:PORT": { "PORT_LIST": [ @@ -219,5 +236,22 @@ ] } } + }, + + "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 4f1b31e50f6f..ff235ee3ef64 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -70,10 +70,10 @@ module sonic-port{ 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; @@ -84,6 +84,8 @@ module sonic-port{ } } + must "(count(adv_speeds[text()='all']) = 0) or (count(adv_speeds) = 1)"; + leaf interface_type { description "Port interface type"; @@ -101,6 +103,8 @@ module sonic-port{ } } + must "(count(adv_interface_types[text()='all']) = 0) or (count(adv_interface_types) = 1)"; + leaf mtu { type uint16 { range 1..9216;