From 8472c03259379f421c5769a4b19e4a4b6e0e659e Mon Sep 17 00:00:00 2001 From: Rida Hanif Date: Sun, 5 May 2024 18:45:28 +0000 Subject: [PATCH 1/3] YANG MODEL for DHCP RATE LIMIT --- .../tests/files/sample_config_db.json | 123 ++++++++++++------ .../tests/yang_model_tests/tests/port.json | 8 ++ .../yang_model_tests/tests_config/port.json | 65 +++++++++ .../yang-models/sonic-port.yang | 8 ++ 4 files changed, 163 insertions(+), 41 deletions(-) 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 4cf42f535c60..d6c51302ee6d 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -582,7 +582,8 @@ "link_training": "off", "laser_freq": "191600", "tx_power": "-26.6", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet1": { "alias": "Eth1/2", @@ -600,7 +601,8 @@ "link_training": "on", "laser_freq": "191300", "tx_power": "-27.3", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet2": { "alias": "Eth1/3", @@ -618,7 +620,8 @@ "adv_interface_types": "all", "subport" : "0", "mode":"trunk", - "dom_polling":"enabled" + "dom_polling":"enabled", + "dhcp_rate_limit": "300" }, "Ethernet3": { "alias": "Eth1/4", @@ -628,7 +631,8 @@ "tpid": "0x88A8", "admin_status": "up", "subport": "1", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet4": { "alias": "Eth2/1", @@ -639,7 +643,8 @@ "admin_status": "up", "subport": "2", "mode":"trunk", - "dom_polling":"enabled" + "dom_polling":"enabled", + "dhcp_rate_limit": "300" }, "Ethernet5": { "alias": "Eth2/2", @@ -649,7 +654,8 @@ "tpid": "0x9200", "admin_status": "up", "subport": "3", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet6": { "alias": "Eth2/3", @@ -659,7 +665,8 @@ "tpid": "0x8100", "admin_status": "up", "subport": "4", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet7": { "alias": "Eth2/4", @@ -669,7 +676,8 @@ "tpid": "0x8100", "admin_status": "up", "subport": "5", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet8": { "alias": "Eth3/1", @@ -679,7 +687,8 @@ "tpid": "0x8100", "admin_status": "up", "subport": "6", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet9": { "alias": "Eth3/2", @@ -689,7 +698,8 @@ "tpid": "0x8100", "admin_status": "up", "subport": "7", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet10": { "alias": "Eth3/3", @@ -699,7 +709,8 @@ "tpid": "0x8100", "admin_status": "up", "subport": "8", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet11": { "alias": "Eth3/4", @@ -708,7 +719,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet12": { "alias": "Eth4/1", @@ -717,7 +729,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet13": { "alias": "Eth4/2", @@ -726,7 +739,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet14": { "alias": "Eth4/3", @@ -735,7 +749,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet15": { "alias": "Eth4/4", @@ -744,7 +759,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet16": { "alias": "Eth5/1", @@ -753,7 +769,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet17": { "alias": "Eth5/2", @@ -762,7 +779,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet18": { "alias": "Eth5/3", @@ -771,7 +789,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet19": { "alias": "Eth5/4", @@ -780,7 +799,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet20": { "alias": "Eth6/1", @@ -789,7 +809,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet21": { "alias": "Eth6/2", @@ -798,7 +819,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet22": { "alias": "Eth6/3", @@ -807,7 +829,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet23": { "alias": "Eth6/4", @@ -816,7 +839,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet24": { "alias": "Eth7/1", @@ -825,7 +849,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet25": { "alias": "Eth7/2", @@ -834,7 +859,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet26": { "alias": "Eth7/3", @@ -843,7 +869,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet27": { "alias": "Eth7/4", @@ -852,7 +879,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet28": { "alias": "Eth8/1", @@ -861,7 +889,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet29": { "alias": "Eth8/2", @@ -870,7 +899,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet30": { "alias": "Eth8/3", @@ -879,7 +909,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet31": { "alias": "Eth8/4", @@ -888,7 +919,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet32": { "alias": "Eth9/1", @@ -897,7 +929,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet33": { "alias": "Eth9/2", @@ -906,7 +939,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet34": { "alias": "Eth9/3", @@ -915,7 +949,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet35": { "alias": "Eth9/4", @@ -924,7 +959,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet36": { "alias": "Eth10/1", @@ -933,7 +969,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"trunk" + "mode":"trunk", + "dhcp_rate_limit": "300" }, "Ethernet112": { "alias": "Eth29/1", @@ -943,7 +980,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet120": { "alias": "Eth31/1", @@ -953,7 +991,8 @@ "speed": "11100", "tpid": "0x8100", "admin_status": "up", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet-BP0": { "admin_status": "up", @@ -967,7 +1006,8 @@ "role": "Int", "speed": "40000", "tpid": "0x8100", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" }, "Ethernet-BP4": { "admin_status": "up", @@ -981,7 +1021,8 @@ "role": "Int", "speed": "40000", "tpid": "0x8100", - "mode":"routed" + "mode":"routed", + "dhcp_rate_limit": "300" } }, "LOGGER": { 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 b35f9fd2231f..13521ff552be 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 @@ -13,6 +13,14 @@ "eStrKey" : "Pattern", "eStr": ["rc"] }, + "PORT_VALID_DHCP_RATE_LIMIT": { + "desc": "PORT_VALID_DHCP_RATE_LIMIT no failure." + }, + "PORT_INVALID_DHCP_RATE_LIMIT": { + "desc": "Out of range for dhcp rate", + "eStrKey": "Range", + "eStr": "0..800000" + }, "PORT_VALID_MTU_TEST_1": { "desc": "PORT_VALID_MTU_TEST_1 no failure." }, 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 37c5606c1c33..3829b17733d4 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 @@ -88,6 +88,71 @@ } } }, + + "PORT_VALID_DHCP_RATE_LIMIT": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet0", + "alias": "etp1a", + "lanes": "60, 61", + "speed": 100000, + "subport": 1, + "mode":"trunk", + "dhcp_rate_limit": "301" + }, + { + "name": "Ethernet2", + "alias": "etp1b", + "lanes": "62, 63", + "speed": 100000, + "subport": 2, + "mode":"trunk", + "dhcp_rate_limit": "500" + }, + { + "name": "Ethernet4", + "alias": "etp1c", + "lanes": "64, 65", + "speed": 100000, + "subport": 3, + "mode":"trunk", + "dhcp_rate_limit": "100000" + }, + { + "name": "Ethernet6", + "alias": "etp1d", + "lanes": "66, 67", + "speed": 100000, + "subport": 4, + "mode":"trunk", + "dhcp_rate_limit": "400000" + } + ] + } + } + }, + + "PORT_INVALID_DHCP_RATE_LIMIT": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet0", + "alias": "etp1a", + "lanes": "60, 61", + "speed": 100000, + "mode":"trunk", + "dhcp_rate_limit": "900000" + + + + } + ] + } + } + }, "PORT_VALID_AUTONEG_TEST_1": { "sonic-port:sonic-port": { "sonic-port:PORT": { diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 163e19fc841b..26e2f9a79f53 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -91,6 +91,14 @@ module sonic-port{ } } + leaf dhcp_rate_limit { + description "DHCP DOS Mitigation Rate with default value 300"; + type uint32 { + range 0..800000; + } + default 300; + } + leaf link_training { description "Port link training mode"; From 157b1e7c4ec58f09443eed4820328dab38b10d08 Mon Sep 17 00:00:00 2001 From: Rida Hanif Date: Fri, 14 Jun 2024 10:20:49 +0500 Subject: [PATCH 2/3] Removed Range value --- src/sonic-yang-models/yang-models/sonic-port.yang | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 26e2f9a79f53..1a133a244801 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -93,9 +93,7 @@ module sonic-port{ leaf dhcp_rate_limit { description "DHCP DOS Mitigation Rate with default value 300"; - type uint32 { - range 0..800000; - } + type uint32 default 300; } From da859d85d6192d95d10967959062fdd47cdc6a72 Mon Sep 17 00:00:00 2001 From: Rida Hanif Date: Fri, 14 Jun 2024 06:23:20 +0000 Subject: [PATCH 3/3] Updated Code as per suggestion --- .../tests/yang_model_tests/tests/port.json | 6 +----- .../yang_model_tests/tests_config/port.json | 19 ------------------- .../yang-models/sonic-port.yang | 2 +- 3 files changed, 2 insertions(+), 25 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 13521ff552be..98b809530453 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 @@ -16,11 +16,7 @@ "PORT_VALID_DHCP_RATE_LIMIT": { "desc": "PORT_VALID_DHCP_RATE_LIMIT no failure." }, - "PORT_INVALID_DHCP_RATE_LIMIT": { - "desc": "Out of range for dhcp rate", - "eStrKey": "Range", - "eStr": "0..800000" - }, + "PORT_VALID_MTU_TEST_1": { "desc": "PORT_VALID_MTU_TEST_1 no failure." }, 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 3829b17733d4..58b7a586c829 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 @@ -134,25 +134,6 @@ } }, - "PORT_INVALID_DHCP_RATE_LIMIT": { - "sonic-port:sonic-port": { - "sonic-port:PORT": { - "PORT_LIST": [ - { - "name": "Ethernet0", - "alias": "etp1a", - "lanes": "60, 61", - "speed": 100000, - "mode":"trunk", - "dhcp_rate_limit": "900000" - - - - } - ] - } - } - }, "PORT_VALID_AUTONEG_TEST_1": { "sonic-port:sonic-port": { "sonic-port:PORT": { diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 1a133a244801..ecb19d04a4da 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -93,7 +93,7 @@ module sonic-port{ leaf dhcp_rate_limit { description "DHCP DOS Mitigation Rate with default value 300"; - type uint32 + type uint32; default 300; }