diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index cafc4fcaac16..6c70b5c707ad 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -573,6 +573,7 @@ When the system is running in traditional buffer model, the size of all of the b ``` When the system is running in dynamic buffer model, the size of some of the buffer pools can be omitted and will be dynamically calculated. +In this case, A percentage can be configured on a pool, representing how many the available buffer can be allloced to the pool. ``` { @@ -584,11 +585,12 @@ When the system is running in dynamic buffer model, the size of some of the buff }, "egress_lossy_pool": { "type": "egress", - "mode": "dynamic", + "mode": "dynamic" }, "ingress_lossless_pool": { "type": "ingress", "mode": "dynamic", + "percentage": "80" } } } 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 8ebb1d655675..534a0d986480 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -36,6 +36,11 @@ "size": "12766208", "type": "egress", "mode": "dynamic" + }, + "ingress_percentage_pool": { + "type": "ingress", + "mode": "dynamic", + "percentage": "90" } }, "BUFFER_PROFILE": { @@ -351,6 +356,7 @@ }, "DEVICE_METADATA": { "localhost": { + "buffer_model": "dynamic", "type": "ToRRouter", "asic_id": "06:00.0", "mac": "00:11:22:33:dd:5a", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/buffer_pool.json b/src/sonic-yang-models/tests/yang_model_tests/tests/buffer_pool.json index 974ece55dd79..ff35fc7357d1 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/buffer_pool.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/buffer_pool.json @@ -39,5 +39,23 @@ "BUFFER_POOL_WRONG_SIZE_VALUE": { "desc": "BUFFER_POOL_WRONG_SIZE_VALUE pattern failure.", "eStr": "wrong" + }, + "BUFFER_POOL_CORRECT_PERCENTAGE_VALUE": { + "desc": "BUFFER_POOL_CORRECT_PERCENTAGE_VALUE no failure." + }, + "BUFFER_POOL_CORRECT_LARGE_PERCENTAGE_VALUE": { + "desc": "BUFFER_POOL_CORRECT_PERCENTAGE_VALUE no failure." + }, + "BUFFER_POOL_WRONG_PERCENTAGE_NEGATIVE_VALUE": { + "desc": "BUFFER_POOL_WRONG_PERCENTAGE_NEGATIVE_VALUE pattern failure.", + "eStr": "Invalid value" + }, + "BUFFER_POOL_WRONG_PERCENTAGE_NOT_A_NUMBER_VALUE": { + "desc": "BUFFER_POOL_WRONG_PERCENTAGE_NOT_A_NUMBER_VALUE pattern failure.", + "eStr": "Invalid value" + }, + "BUFFER_POOL_WRONG_PERCENTAGE_VALUE_WITH_SIZE": { + "desc": "BUFFER_POOL_WRONG_PERCENTAGE_VALUE_WITH_SIZE pattern failure.", + "eStr": "Percentage should not be configured along with size" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/buffer_pool.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/buffer_pool.json index a2a4d6fc1f0e..47ce26357d4b 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/buffer_pool.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/buffer_pool.json @@ -167,5 +167,90 @@ ] } } + }, + "BUFFER_POOL_CORRECT_PERCENTAGE_VALUE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost":{ + "buffer_model": "dynamic" + } + } + }, + "sonic-buffer-pool:sonic-buffer-pool": { + "sonic-buffer-pool:BUFFER_POOL": { + "BUFFER_POOL_LIST": [ + { + "name": "ingress_lossless_pool", + "mode": "dynamic", + "percentage": "99", + "type": "ingress" + } + ] + } + } + }, + "BUFFER_POOL_CORRECT_LARGE_PERCENTAGE_VALUE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost":{ + "buffer_model": "dynamic" + } + } + }, + "sonic-buffer-pool:sonic-buffer-pool": { + "sonic-buffer-pool:BUFFER_POOL": { + "BUFFER_POOL_LIST": [ + { + "name": "ingress_lossless_pool", + "mode": "dynamic", + "percentage": "200", + "type": "ingress" + } + ] + } + } + }, + "BUFFER_POOL_WRONG_PERCENTAGE_NEGATIVE_VALUE": { + "sonic-buffer-pool:sonic-buffer-pool": { + "sonic-buffer-pool:BUFFER_POOL": { + "BUFFER_POOL_LIST": [ + { + "name": "ingress_lossless_pool", + "mode": "static", + "percentage": "-10", + "type": "ingress" + } + ] + } + } + }, + "BUFFER_POOL_WRONG_PERCENTAGE_NOT_A_NUMBER_VALUE": { + "sonic-buffer-pool:sonic-buffer-pool": { + "sonic-buffer-pool:BUFFER_POOL": { + "BUFFER_POOL_LIST": [ + { + "name": "ingress_lossless_pool", + "mode": "static", + "percentage": "NaN", + "type": "ingress" + } + ] + } + } + }, + "BUFFER_POOL_WRONG_PERCENTAGE_VALUE_WITH_SIZE": { + "sonic-buffer-pool:sonic-buffer-pool": { + "sonic-buffer-pool:BUFFER_POOL": { + "BUFFER_POOL_LIST": [ + { + "name": "ingress_lossless_pool", + "mode": "static", + "percentage": "90", + "size": "12766208", + "type": "ingress" + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-buffer-pool.yang b/src/sonic-yang-models/yang-models/sonic-buffer-pool.yang index dd8c74c13ab5..174e6b2a0b38 100644 --- a/src/sonic-yang-models/yang-models/sonic-buffer-pool.yang +++ b/src/sonic-yang-models/yang-models/sonic-buffer-pool.yang @@ -2,6 +2,10 @@ module sonic-buffer-pool { namespace "http://github.com/sonic-net/sonic-buffer-pool"; prefix bpl; + import sonic-device_metadata { + prefix device_metadata; + } + organization "SONiC"; @@ -57,6 +61,20 @@ module sonic-buffer-pool { type uint64; description "Buffer Pool Xoff Threshold (in Bytes)"; } + + leaf percentage { + type uint8; + description " + Buffer Pool percentage. + The buffer pool size will be available_buffer * percentage / 100 if percentage is provided. + It is valid in dynamic buffer model only."; + must "(not(current()/../size))" { + error-message "Percentage should not be configured along with size"; + } + must "/device_metadata:sonic-device_metadata/device_metadata:DEVICE_METADATA/device_metadata:localhost/device_metadata:buffer_model = 'dynamic'" { + error-message "Percentage must be configured in dynamic buffer model"; + } + } } } }