From 6a3d3a4b9ec317993bffcb677062bbd88eaddcce Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 4 Feb 2022 21:32:48 +0000 Subject: [PATCH 1/2] [yang]YANG changes for policer table Signed-off-by: Sudharsan Dhamal Gopalarathnam --- .../tests/files/sample_config_db.json | 11 + .../tests/mirror_session.json | 47 ++-- .../tests/yang_model_tests/tests/policer.json | 61 +++++ .../tests_config/mirror_session.json | 51 ++++ .../tests_config/policer.json | 219 ++++++++++++++++++ .../yang-models/sonic-copp.yang | 16 +- .../yang-models/sonic-mirror-session.yang | 12 + .../yang-templates/sonic-policer.yang.j2 | 126 ++++++++++ .../yang-templates/sonic-types.yang.j2 | 18 +- 9 files changed, 530 insertions(+), 31 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/policer.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json create mode 100644 src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 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 e69255623144..32207eb1759e 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1546,6 +1546,7 @@ "queue": "0", "src_ip": "10.1.1.1", "ttl": "10", + "policer": "everflow_static_policer", "type": "ERSPAN" }, "span": { @@ -1564,5 +1565,15 @@ "UNKNOWN_TABLE": { "Error": "This Table is for testing, This Table does not have YANG models." } + }, + "POLICER": { + "everflow_static_policer": { + "meter_type": "bytes", + "mode": "sr_tcm", + "cir": "12500000", + "cbs": "12500000", + "color": "aware", + "red_packet_action": "drop" + } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/mirror_session.json b/src/sonic-yang-models/tests/yang_model_tests/tests/mirror_session.json index 9c94deb343cf..6d53b0e9cffb 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/mirror_session.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/mirror_session.json @@ -3,79 +3,86 @@ "desc": "Configuring ERSPAN entry with valid values." }, "MIRROR_ERSPAN_ENTRY_WRONG_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid type", + "desc": "Configuring ERSPAN entry with invalid type", "eStrKey": "InvalidValue" }, "MIRROR_ERSPAN_ENTRY_WRONG_DST_IP": { - "desc": "Configurinng ERSPAN entry with invalid dst_ip", + "desc": "Configuring ERSPAN entry with invalid dst_ip", "eStrKey" : "Pattern" }, "MIRROR_ERSPAN_ENTRY_WRONG_DST_IP_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid dst_ip", + "desc": "Configuring ERSPAN entry with invalid dst_ip", "eStrKey" : "When" }, "MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP": { - "desc": "Configurinng ERSPAN entry with invalid src_ip", + "desc": "Configuring ERSPAN entry with invalid src_ip", "eStrKey" : "Pattern" }, "MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid src_ip", + "desc": "Configuring ERSPAN entry with invalid src_ip", "eStrKey" : "When" }, "MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid GRE type", + "desc": "Configuring ERSPAN entry with invalid GRE type", "eStrKey" : "Pattern" }, "MIRROR_ERSPAN_ENTRY_GRE_WRONG_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid GRE type", + "desc": "Configuring ERSPAN entry with invalid GRE type", "eStrKey" : "When" }, "MIRROR_ERSPAN_ENTRY_WRONG_DSCP": { - "desc": "Configurinng ERSPAN entry with invalid dscp", + "desc": "Configuring ERSPAN entry with invalid dscp", "eStr" : "Invalid dscp value" }, "MIRROR_ERSPAN_ENTRY_WRONG_DSCP_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid dscp", + "desc": "Configuring ERSPAN entry with invalid dscp", "eStrKey" : "When" }, "MIRROR_ERSPAN_ENTRY_WRONG_TTL": { - "desc": "Configurinng ERSPAN entry with invalid ttl", + "desc": "Configuring ERSPAN entry with invalid ttl", "eStr": "Invalid TTL value" }, "MIRROR_ERSPAN_ENTRY_WRONG_TTL_TYPE": { - "desc": "Configurinng ERSPAN entry with invalid ttl", + "desc": "Configuring ERSPAN entry with invalid ttl", "eStrKey" : "When" }, "MIRROR_ERSPAN_ENTRY_VALID_SRC_PORT": { - "desc": "Configurinng ERSPAN entry with valid source port" + "desc": "Configuring ERSPAN entry with valid source port" }, "MIRROR_ERSPAN_ENTRY_VALID_SRC_PORTCHANNEL": { - "desc": "Configurinng ERSPAN entry with valid source portchannel" + "desc": "Configuring ERSPAN entry with valid source portchannel" }, "MIRROR_ERSPAN_ENTRY_INVALID_SRC_PORT": { - "desc": "Configurinng ERSPAN entry with invalid source port", + "desc": "Configuring ERSPAN entry with invalid source port", "eStrKey" : "InvalidValue" }, "MIRROR_SPAN_ENTRY_WITH_VALID_VALUES": { - "desc": "Configurinng SPAN entry with valid source and destination ports" + "desc": "Configuring SPAN entry with valid source and destination ports" }, "MIRROR_SPAN_ENTRY_INVALID_DST_PORT": { - "desc": "Configurinng SPAN entry with invalid destination ports", + "desc": "Configuring SPAN entry with invalid destination ports", "eStrKey" : "InvalidValue" }, "MIRROR_SPAN_ENTRY_INVALID_DST_PORT_TYPE": { - "desc": "Configurinng SPAN entry with invalid destination ports", + "desc": "Configuring SPAN entry with invalid destination ports", "eStrKey" : "When" }, "MIRROR_SPAN_ENTRY_VALID_DST_PORT_CPU": { - "desc": "Configurinng SPAN entry with valid destination port CPU" + "desc": "Configuring SPAN entry with valid destination port CPU" }, "MIRROR_SPAN_ENTRY_INVALID_SRC_PORT": { - "desc": "Configurinng SPAN entry with invalid destination ports", + "desc": "Configuring SPAN entry with invalid destination ports", "eStrKey" : "InvalidValue" }, "MIRROR_SPAN_ENTRY_INVALID_DIRECTION": { - "desc": "Configurinng SPAN entry with invalid direction", + "desc": "Configuring SPAN entry with invalid direction", "eStrKey": "InvalidValue" + }, + "MIRROR_ERSPAN_ENTRY_WITH_VALID_POLICER": { + "desc": "Configuring SPAN entry with valid policer" + }, + "MIRROR_ERSPAN_ENTRY_WITH_INVALID_POLICER": { + "desc": "Configuring SPAN entry with invalid policer", + "eStrKey": "LeafRef" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json b/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json new file mode 100644 index 000000000000..906d26820099 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json @@ -0,0 +1,61 @@ +{ + "POLICER_TABLE": { + "desc": "Configure policer with all fields." + }, + "POLICER_MANDATORY_MODE": { + "desc": "Configure policer with no mode.", + "eStrKey" : "Mandatory" + }, + "POLICER_MANDATORY_METER_TYPE": { + "desc": "Configure policer with no meter type.", + "eStrKey" : "Mandatory" + }, + "POLICER_UNKNOWN_METER_TYPE": { + "desc": "Configure policer with unknown meter type.", + "eStrKey" : "InvalidValue", + "eStr" : ["meter_type"] + }, + "POLICER_UNKNOWN_MODE": { + "desc": "Configure policer with unknown mode.", + "eStrKey" : "InvalidValue", + "eStr" : ["mode"] + }, + "POLICER_UNKNOWN_ACTION": { + "desc": "Configure policer with unknown action.", + "eStrKey" : "InvalidValue", + "eStr" : ["red_action"] + }, + "POLICER_UNKNOWN_COLOR": { + "desc": "Configure policer with unknown color awareness.", + "eStrKey" : "InvalidValue", + "eStr" : ["color"] + }, + "POLICER_CBS_WITHOUT_CIR": { + "desc": "Configure policer with cbs but without cir.", + "eStr": ["cbs can't be configured without cir."] + }, + "POLICER_CBS_LESS_THAN_CIR": { + "desc": "Configure policer with cbs less than cir.", + "eStr": ["cbs must be greater than or equal to cir"] + }, + "POLICER_PIR_LESS_THAN_CIR": { + "desc": "Configure policer with pir less than cir.", + "eStr": ["pir must be greater than or equal to cir"] + }, + "POLICER_PBS_WITH_STORM": { + "desc": "Configure policer with pbs configured in storm mode.", + "eStrKey" : "When" + }, + "POLICER_PBS_LESS_THAN_CBS": { + "desc": "Configure policer with pbs less than cbs.", + "eStr": ["pbs must be greater than or equal to cbs"] + }, + "POLICER_PIR_WITHOUT_CIR": { + "desc": "Configure policer with pir but without cir.", + "eStr": ["pir can't be configured without cir."] + }, + "POLICER_WHEN_SRTCM_WITH_PIR": { + "desc": "Configure policer with pir configured in sr_tcm mode.", + "eStrKey" : "When" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json index 8f0580bbafdd..6cea2998d4c7 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json @@ -442,5 +442,56 @@ ] } } + }, + "MIRROR_ERSPAN_ENTRY_WITH_VALID_POLICER": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [ + { + "name": "erspan_policer", + "meter_type":"packets", + "mode":"tr_tcm", + "color": "aware", + "cir":"5000", + "cbs":"5000", + "pir":"15000", + "pbs":"15000", + "red_action":"drop" + } + ] + } + }, + "sonic-mirror-session:sonic-mirror-session": { + "MIRROR_SESSION": { + "MIRROR_SESSION_LIST": [ + { + "name": "erspan", + "type": "ERSPAN", + "dst_ip": "11.1.1.1", + "src_ip": "10.1.1.1", + "gre_type": "0x1234", + "dscp": "10", + "policer": "erspan_policer" + } + ] + } + } + }, + "MIRROR_ERSPAN_ENTRY_WITH_INVALID_POLICER": { + "sonic-mirror-session:sonic-mirror-session": { + "MIRROR_SESSION": { + "MIRROR_SESSION_LIST": [ + { + "name": "erspan", + "type": "ERSPAN", + "dst_ip": "11.1.1.1", + "src_ip": "10.1.1.1", + "gre_type": "0x1234", + "dscp": "10", + "policer": "erspan_policer2" + } + ] + } + } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json new file mode 100644 index 000000000000..6766833b4191 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json @@ -0,0 +1,219 @@ +{ + "POLICER_TABLE": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session1_policer", + "meter_type":"packets", + "mode":"tr_tcm", + "color": "aware", + "cir":"5000", + "cbs":"5000", + "pir":"15000", + "pbs":"15000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_MANDATORY_MODE": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session1_policer", + "meter_type":"packets", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_MANDATORY_METER_TYPE": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session2_policer", + "mode":"sr_tcm", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_UNKNOWN_METER_TYPE": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session4_policer", + "mode":"sr_tcm", + "meter_type":"bits", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_UNKNOWN_MODE": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session5_policer", + "mode":"srtcm", + "meter_type":"bytes", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_UNKNOWN_ACTION": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session6_policer", + "mode":"storm", + "meter_type":"bytes", + "cir":"5000", + "cbs":"5000", + "color":"aware", + "red_action":"act" + }] + } + } + }, + + "POLICER_UNKNOWN_COLOR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "everflow_session7_policer", + "mode":"sr_tcm", + "meter_type":"bytes", + "cir":"5000", + "cbs":"5000", + "red_action":"drop", + "color":"yes" + }] + } + } + }, + + "POLICER_CBS_WITHOUT_CIR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "p5", + "meter_type":"bytes", + "mode":"tr_tcm", + "cbs":"5000", + "pir":"4000", + "pbs":"4000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_CBS_LESS_THAN_CIR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "policer5", + "meter_type":"bytes", + "mode":"sr_tcm", + "cbs":"5000", + "cir":"6000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_PIR_LESS_THAN_CIR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "e3_policer", + "meter_type":"bytes", + "mode":"tr_tcm", + "cir":"5000", + "cbs":"5000", + "pir":"4000", + "pbs":"4000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_PBS_WITH_STORM": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "e1policer", + "meter_type":"bytes", + "mode":"storm", + "cir":"5000", + "cbs":"5000", + "pbs":"6000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_PBS_LESS_THAN_CBS": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "e2policer", + "meter_type":"bytes", + "mode":"tr_tcm", + "cir":"5000", + "cbs":"5000", + "pbs":"2000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_PIR_WITHOUT_CIR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "e3policer", + "meter_type":"bytes", + "mode":"tr_tcm", + "pir":"2000", + "red_action":"drop" + }] + } + } + }, + + "POLICER_WHEN_SRTCM_WITH_PIR": { + "sonic-policer:sonic-policer": { + "sonic-policer:POLICER": { + "POLICER_LIST": [{ + "name": "policer1", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"6000", + "cbs":"6000", + "pir":"6000", + "red_action":"drop" + }] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-copp.yang b/src/sonic-yang-models/yang-models/sonic-copp.yang index c869b439faa9..d735150a5c40 100644 --- a/src/sonic-yang-models/yang-models/sonic-copp.yang +++ b/src/sonic-yang-models/yang-models/sonic-copp.yang @@ -40,7 +40,7 @@ module sonic-copp { leaf trap_action { mandatory true; - type stypes:copp_packet_action; + type stypes:policer_packet_action; description "Trap action"; } @@ -61,12 +61,8 @@ module sonic-copp { } leaf color { - type enumeration { - enum blind; - enum color; - } - default "color"; - description "Policer color source"; + type stypes:policer_color_source; + description "Policer color Source"; } leaf cir { @@ -120,20 +116,20 @@ module sonic-copp { } leaf green_action { - type stypes:copp_packet_action; + type stypes:policer_packet_action; default "forward"; description "Green action"; } leaf yellow_action { when "((current()/../mode = 'sr_tcm') or (current()/../mode = 'tr_tcm'))"; - type stypes:copp_packet_action; + type stypes:policer_packet_action; default "forward"; description "Yellow action"; } leaf red_action { - type stypes:copp_packet_action; + type stypes:policer_packet_action; default "forward"; description "Red action"; } diff --git a/src/sonic-yang-models/yang-models/sonic-mirror-session.yang b/src/sonic-yang-models/yang-models/sonic-mirror-session.yang index 7a9afcd1ae48..ba8a1e13c7d6 100644 --- a/src/sonic-yang-models/yang-models/sonic-mirror-session.yang +++ b/src/sonic-yang-models/yang-models/sonic-mirror-session.yang @@ -17,6 +17,10 @@ module sonic-mirror-session { prefix lag; } + import sonic-policer { + prefix policer; + } + description "SONiC Mirror session yang model"; @@ -174,6 +178,14 @@ module sonic-mirror-session { TX: Captures frames egressing on source port. BOTH: Captures frames ingressing or egressing on source port."; } + + leaf policer { + type leafref { + path "/policer:sonic-policer/policer:POLICER/policer:POLICER_LIST/policer:name"; + } + description + "Policer to be applied for the mirrored traffic."; + } } } } diff --git a/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 new file mode 100644 index 000000000000..6aeed7e7288b --- /dev/null +++ b/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 @@ -0,0 +1,126 @@ +{% if yang_model_type == "cvl" %} +/* this is sonic cvl yang model */ +{% else %} +/* this is sonic py yang model */ +{% endif %} +module sonic-policer { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-policer"; + prefix policer; + + import sonic-types { + prefix stypes; + } + + description "Policer YANG Module for SONiC OS"; + + revision 2022-02-03 { + description + "First Revision"; + } + + container sonic-policer { + container POLICER { + list POLICER_LIST { + key name; + + leaf name { + type string; + description "Policer name"; + } + + leaf meter_type { + mandatory true; + type stypes:meter_type; + description "Policer meter type"; + } + + leaf mode { + mandatory true; + type stypes:policer_mode; + description "Policer mode"; + } + + leaf color { + type stypes:policer_color_source; + description "Policer color Source"; + } + + leaf cir { + type uint64; + default 0; + description + "Committed information rate for the dual-rate token + bucket policer. This value represents the rate at which + tokens are added to the primary bucket."; + } + + leaf cbs { + must "((current()/../cir) and (current()/../cir > 0))" { + error-message "cbs can't be configured without cir."; + } + must "(current() >= current()/../cir)" { + error-message "cbs must be greater than or equal to cir"; + } + type uint64; + default 0; + description + "Committed burst size for the dual-rate token bucket + policer. This value represents the depth of the token + bucket."; + } + + leaf pir { + when "current()/../mode = 'tr_tcm'"; + must "((current()/../cir) and (current()/../cir > 0))" { + error-message "pir can't be configured without cir."; + } + must "(current() >= current()/../cir)" { + error-message "pir must be greater than or equal to cir"; + } + type uint64; + description + "Peak information rate for the dual-rate token bucket + policer. This value represents the rate at which tokens + are added to the secondary bucket."; + } + + leaf pbs { + when "((current()/../mode = 'sr_tcm') or (current()/../mode = 'tr_tcm'))"; + must "((not(current()/../cbs)) or (current() >= current()/../cbs))" { + error-message "pbs must be greater than or equal to cbs"; + } + type uint64; + description + "Excess burst size for the dual-rate token bucket policer. + This value represents the depth of the secondary bucket."; + } + + leaf green_action { + type stypes:policer_packet_action; + default "forward"; + description "Green action"; + } + + leaf yellow_action { + when "((current()/../mode = 'sr_tcm') or (current()/../mode = 'tr_tcm'))"; + type stypes:policer_packet_action; + default "forward"; + description "Yellow action"; + } + + leaf red_action { + type stypes:policer_packet_action; + default "forward"; + description "Red action"; + } + } + /* end of list POLICER_LIST */ + } + /* end of container POLICER */ + } + /* end of top level container */ +} +/* end of module sonic-policer */ diff --git a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 index 2388b487e0eb..da043fa8761d 100644 --- a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 @@ -205,7 +205,23 @@ module sonic-types { } } - typedef copp_packet_action { + typedef policer_mode { + type enumeration { + enum sr_tcm; + enum tr_tcm; + enum storm; + } + } + + typedef policer_color_source { + type enumeration { + enum aware; + enum blind; + } + } + + + typedef policer_packet_action { type enumeration { enum drop; enum forward; From f687b80a31b9b530d89bc3b4141abee6a681f11f Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Wed, 9 Feb 2022 04:20:02 +0000 Subject: [PATCH 2/2] Build fixes --- src/sonic-yang-models/setup.py | 2 ++ .../tests/files/sample_config_db.json | 20 ++++++------- .../tests/yang_model_tests/tests/policer.json | 2 +- .../tests_config/mirror_session.json | 2 +- .../tests_config/policer.json | 29 ++++++++++--------- .../yang-templates/sonic-policer.yang.j2 | 6 ++-- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index fb8734e571b4..1f9b51b0c566 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -110,6 +110,7 @@ def run(self): './yang-models/sonic-nat.yang', './yang-models/sonic-pbh.yang', './yang-models/sonic-port.yang', + './yang-models/sonic-policer.yang', './yang-models/sonic-portchannel.yang', './yang-models/sonic-pfcwd.yang', './yang-models/sonic-route-common.yang', @@ -165,6 +166,7 @@ def run(self): './cvlyang-models/sonic-ntp.yang', './cvlyang-models/sonic-nat.yang', './cvlyang-models/sonic-pbh.yang', + './cvlyang-models/sonic-policer.yang', './cvlyang-models/sonic-port.yang', './cvlyang-models/sonic-portchannel.yang', './cvlyang-models/sonic-pfcwd.yang', 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 32207eb1759e..38a5ae930cdd 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1559,21 +1559,21 @@ ] } + }, + "POLICER": { + "everflow_static_policer": { + "meter_type": "bytes", + "mode": "sr_tcm", + "cir": "12500000", + "cbs": "12500000", + "color": "aware", + "red_packet_action": "drop" + } } }, "SAMPLE_CONFIG_DB_UNKNOWN": { "UNKNOWN_TABLE": { "Error": "This Table is for testing, This Table does not have YANG models." } - }, - "POLICER": { - "everflow_static_policer": { - "meter_type": "bytes", - "mode": "sr_tcm", - "cir": "12500000", - "cbs": "12500000", - "color": "aware", - "red_packet_action": "drop" - } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json b/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json index 906d26820099..f4acdbce0d91 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/policer.json @@ -23,7 +23,7 @@ "POLICER_UNKNOWN_ACTION": { "desc": "Configure policer with unknown action.", "eStrKey" : "InvalidValue", - "eStr" : ["red_action"] + "eStr" : ["red_packet_action"] }, "POLICER_UNKNOWN_COLOR": { "desc": "Configure policer with unknown color awareness.", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json index 6cea2998d4c7..ddf956c79f83 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json @@ -456,7 +456,7 @@ "cbs":"5000", "pir":"15000", "pbs":"15000", - "red_action":"drop" + "red_packet_action":"drop" } ] } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json index 6766833b4191..b952e970592f 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/policer.json @@ -11,7 +11,8 @@ "cbs":"5000", "pir":"15000", "pbs":"15000", - "red_action":"drop" + "yellow_packet_action":"forward", + "green_packet_action":"forward" }] } } @@ -25,7 +26,7 @@ "meter_type":"packets", "cir":"5000", "cbs":"5000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -39,7 +40,7 @@ "mode":"sr_tcm", "cir":"5000", "cbs":"5000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -54,7 +55,7 @@ "meter_type":"bits", "cir":"5000", "cbs":"5000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -69,7 +70,7 @@ "meter_type":"bytes", "cir":"5000", "cbs":"5000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -85,7 +86,7 @@ "cir":"5000", "cbs":"5000", "color":"aware", - "red_action":"act" + "red_packet_action":"act" }] } } @@ -100,7 +101,7 @@ "meter_type":"bytes", "cir":"5000", "cbs":"5000", - "red_action":"drop", + "red_packet_action":"drop", "color":"yes" }] } @@ -117,7 +118,7 @@ "cbs":"5000", "pir":"4000", "pbs":"4000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -132,7 +133,7 @@ "mode":"sr_tcm", "cbs":"5000", "cir":"6000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -149,7 +150,7 @@ "cbs":"5000", "pir":"4000", "pbs":"4000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -165,7 +166,7 @@ "cir":"5000", "cbs":"5000", "pbs":"6000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -181,7 +182,7 @@ "cir":"5000", "cbs":"5000", "pbs":"2000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -195,7 +196,7 @@ "meter_type":"bytes", "mode":"tr_tcm", "pir":"2000", - "red_action":"drop" + "red_packet_action":"drop" }] } } @@ -211,7 +212,7 @@ "cir":"6000", "cbs":"6000", "pir":"6000", - "red_action":"drop" + "red_packet_action":"drop" }] } } diff --git a/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 index 6aeed7e7288b..71246a885dd1 100644 --- a/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-policer.yang.j2 @@ -98,20 +98,20 @@ module sonic-policer { This value represents the depth of the secondary bucket."; } - leaf green_action { + leaf green_packet_action { type stypes:policer_packet_action; default "forward"; description "Green action"; } - leaf yellow_action { + leaf yellow_packet_action { when "((current()/../mode = 'sr_tcm') or (current()/../mode = 'tr_tcm'))"; type stypes:policer_packet_action; default "forward"; description "Yellow action"; } - leaf red_action { + leaf red_packet_action { type stypes:policer_packet_action; default "forward"; description "Red action";