From 92cfbb270a401f0361b2843c61dcdae75329a04b Mon Sep 17 00:00:00 2001 From: ganglv <88995770+ganglyu@users.noreply.github.com> Date: Tue, 21 Dec 2021 03:15:39 +0800 Subject: [PATCH] [yang]: Add constraint for pfcwd (#9513) #### Why I did it POLL_INTERVAL cannot be set if any of the detection/restoration times in this table is less than the POLL_INTERVAL. #### How I did it Add "must" constraint to make sure detection/restoration times are greater than POLL_INTERVAL. #### How to verify it Use apply-patch command to update POLL_INTERVAL. Build sonic-yang-model. --- .../tests/yang_model_tests/tests/pfc.json | 8 + .../yang_model_tests/tests_config/pfc.json | 138 +++++++++++++++++- .../yang-models/sonic-pfcwd.yang | 6 + 3 files changed, 150 insertions(+), 2 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/pfc.json b/src/sonic-yang-models/tests/yang_model_tests/tests/pfc.json index 4405075aee..0f8b4d0289 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/pfc.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/pfc.json @@ -31,6 +31,10 @@ "desc": "PFC_WDOG_WITH_WRONG_DETECTION_TIME_HIGH_VALUE", "eStr": "range" }, + "PFC_WDOG_WITH_INVALID_DETECTION_TIME": { + "desc": "PFC_WDOG_WITH_INVALID_DETECTION_TIME", + "eStr": ["detection_time must be greater than or equal to POLL_INTERVAL"] + }, "PFC_WDOG_WITH_WRONG_RESTORATION_TIME_LOW_VALUE": { "desc": "PFC_WDOG_WITH_WRONG_RESTORATION_TIME_LOW_VALUE", "eStr": "range" @@ -38,5 +42,9 @@ "PFC_WDOG_WITH_WRONG_RESTORATION_TIME_HIGH_VALUE": { "desc": "PFC_WDOG_WITH_WRONG_RESTORATION_TIME_HIGH_VALUE", "eStr": "range" + }, + "PFC_WDOG_WITH_INVALID_RESTORATION_TIME": { + "desc": "PFC_WDOG_WITH_INVALID_RESTORATION_TIME", + "eStr": ["restoration_time must be greater than or equal to POLL_INTERVAL"] } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/pfc.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/pfc.json index 8c31d6dd98..f493701384 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/pfc.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/pfc.json @@ -105,36 +105,102 @@ } }, "PFC_WDOG_WITH_CORRECT_POLL_INTERVAL_VALUE": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet4", + "lanes": "65", + "mtu": "9000", + "name": "Ethernet4", + "tpid": "0x8100", + "speed": "25000" + } + ] + } + }, "sonic-pfcwd:sonic-pfcwd": { "sonic-pfcwd:PFC_WD": { "PFC_WD_LIST": [ { "ifname": "GLOBAL", "POLL_INTERVAL": 101 + }, + { + "ifname": "Ethernet4", + "action": "drop", + "detection_time": 101, + "restoration_time": 3000 } ] } } }, "PFC_WDOG_WITH_WRONG_POLL_INTERVAL_LOW_VALUE": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet4", + "lanes": "65", + "mtu": "9000", + "name": "Ethernet4", + "tpid": "0x8100", + "speed": "25000" + } + ] + } + }, "sonic-pfcwd:sonic-pfcwd": { "sonic-pfcwd:PFC_WD": { "PFC_WD_LIST": [ { "ifname": "GLOBAL", "POLL_INTERVAL":99 + }, + { + "ifname": "Ethernet4", + "action": "drop", + "detection_time": 100, + "restoration_time": 3000 } ] } } }, "PFC_WDOG_WITH_WRONG_POLL_INTERVAL_HIGH_VALUE": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet4", + "lanes": "65", + "mtu": "9000", + "name": "Ethernet4", + "tpid": "0x8100", + "speed": "25000" + } + ] + } + }, "sonic-pfcwd:sonic-pfcwd": { "sonic-pfcwd:PFC_WD": { "PFC_WD_LIST": [ { "ifname": "GLOBAL", "POLL_INTERVAL": 3001 + }, + { + "ifname": "Ethernet4", + "action": "drop", + "detection_time": 3001, + "restoration_time": 3001 } ] } @@ -160,7 +226,7 @@ "PFC_WD_LIST": [ { "ifname": "Ethernet4", - "action": "wrong", + "action": "drop", "detection_time": 5001, "restoration_time": 3000 } @@ -168,6 +234,40 @@ } } }, + "PFC_WDOG_WITH_INVALID_DETECTION_TIME": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet4", + "lanes": "65", + "mtu": "9000", + "name": "Ethernet4", + "tpid": "0x8100", + "speed": "25000" + } + ] + } + }, + "sonic-pfcwd:sonic-pfcwd": { + "sonic-pfcwd:PFC_WD": { + "PFC_WD_LIST": [ + { + "ifname": "GLOBAL", + "POLL_INTERVAL": 1000 + }, + { + "ifname": "Ethernet4", + "action": "drop", + "detection_time": 999, + "restoration_time": 1000 + } + ] + } + } + }, "PFC_WDOG_WITH_WRONG_RESTORATION_TIME_LOW_VALUE": { "sonic-pfcwd:sonic-pfcwd": { "sonic-pfcwd:PFC_WD": { @@ -188,12 +288,46 @@ "PFC_WD_LIST": [ { "ifname": "Ethernet4", - "action": "wrong", + "action": "drop", "detection_time": 60001, "restoration_time": 3000 } ] } } + }, + "PFC_WDOG_WITH_INVALID_RESTORATION_TIME": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet4", + "lanes": "65", + "mtu": "9000", + "name": "Ethernet4", + "tpid": "0x8100", + "speed": "25000" + } + ] + } + }, + "sonic-pfcwd:sonic-pfcwd": { + "sonic-pfcwd:PFC_WD": { + "PFC_WD_LIST": [ + { + "ifname": "GLOBAL", + "POLL_INTERVAL": 1000 + }, + { + "ifname": "Ethernet4", + "action": "drop", + "detection_time": 1000, + "restoration_time": 999 + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-pfcwd.yang b/src/sonic-yang-models/yang-models/sonic-pfcwd.yang index beebf51965..4ea0ffb853 100644 --- a/src/sonic-yang-models/yang-models/sonic-pfcwd.yang +++ b/src/sonic-yang-models/yang-models/sonic-pfcwd.yang @@ -51,6 +51,9 @@ module sonic-pfcwd { } leaf detection_time { must "../ifname != 'GLOBAL'"; + must "(not(boolean(current()/../../PFC_WD_LIST[ifname='GLOBAL'])) or (current() >= current()/../../PFC_WD_LIST[ifname='GLOBAL']/POLL_INTERVAL))" { + error-message "detection_time must be greater than or equal to POLL_INTERVAL"; + } type uint32 { range 100..5000; } @@ -59,6 +62,9 @@ module sonic-pfcwd { } leaf restoration_time { must "../ifname != 'GLOBAL'"; + must "(not(boolean(current()/../../PFC_WD_LIST[ifname='GLOBAL'])) or (current() >= current()/../../PFC_WD_LIST[ifname='GLOBAL']/POLL_INTERVAL))" { + error-message "restoration_time must be greater than or equal to POLL_INTERVAL"; + } type uint32 { range 100..60000; }