diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 41787b6f3a08..6fb5113a3b13 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -47,6 +47,7 @@ './yang-models/sonic-bgp-neighbor.yang', './yang-models/sonic-bgp-peergroup.yang', './yang-models/sonic-breakout_cfg.yang', + './yang-models/sonic-copp.yang', './yang-models/sonic-crm.yang', './yang-models/sonic-device_metadata.yang', './yang-models/sonic-device_neighbor.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 5d1312564e76..7380f37bbbc2 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -825,7 +825,6 @@ "local_ip": "12.12.0.2" } }, - "BGP_GLOBALS": { "default": { "router_id": "5.5.5.5", @@ -891,6 +890,24 @@ "PREFIX": { "prefix1|1|10.0.0.0/8|8..16": { } + }, + "COPP_GROUP": { + "queue1_group1": { + "queue": "1", + "trap_priority":"1", + "trap_action":"trap", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"6000", + "cbs":"6000", + "red_action":"drop" + } + }, + "COPP_TRAP": { + "ip2me": { + "trap_ids": "ip2me", + "trap_group": "queue1_group1" + } } }, diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/copp.json b/src/sonic-yang-models/tests/yang_model_tests/tests/copp.json new file mode 100644 index 000000000000..09de1d12b367 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/copp.json @@ -0,0 +1,29 @@ +{ + "COPP_TRAP_WITH_EXIST_GROUP": { + "desc": "Configure COPP_TRAP with group in COPP_GROUP table." + }, + "COPP_TRAP_WITH_NON_EXIST_GROUP": { + "desc": "Configure COPP_TRAP with group which does not exist in COPP_GROUP table.", + "eStrKey" : "LeafRef" + }, + "COPP_GROUP_MANDATORY_TRAP_ACTION": { + "desc": "Configure COPP_GROUP with no trap_action.", + "eStrKey" : "Mandatory" + }, + "COPP_GROUP_MANDATORY_METER_TYPE": { + "desc": "Configure COPP_GROUP with no meter_type.", + "eStrKey" : "Mandatory" + }, + "COPP_GROUP_PIR_LESS_THAN_CIR": { + "desc": "Configure COPP_GROUP with PIR less than CIR.", + "eStr": ["pir must be greater than or equal to cir"] + }, + "COPP_TRAP_MANDATORY_TRAP_IDS": { + "desc": "Configure COPP_TRAP with no trap_ids.", + "eStrKey" : "Mandatory" + }, + "COPP_GROUP_WHEN_SRTCM_WITH_PIR": { + "desc": "Configure COPP_GROUP with srtcm and pir.", + "eStrKey" : "When" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/copp.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/copp.json new file mode 100644 index 000000000000..0d95fe7915c6 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/copp.json @@ -0,0 +1,147 @@ +{ + "COPP_TRAP_WITH_EXIST_GROUP": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue1_group1", + "trap_action":"trap", + "trap_priority":"1", + "queue": "1", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"6000", + "cbs":"6000", + "red_action":"drop" + }] + }, + "sonic-copp:COPP_TRAP": { + "COPP_TRAP_LIST": [{ + "name": "ip2me", + "trap_ids": "ip2me", + "trap_group": "queue1_group1" + }] + } + } + }, + + "COPP_TRAP_WITH_NON_EXIST_GROUP": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue2_group2", + "trap_action":"trap", + "trap_priority":"2", + "queue": "2", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + }, + "sonic-copp:COPP_TRAP": { + "COPP_TRAP_LIST": [{ + "name": "udld", + "trap_ids": "udld", + "trap_group": "queue3_group3" + }] + } + } + }, + + "COPP_GROUP_MANDATORY_TRAP_ACTION": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue3_group4", + "trap_priority":"3", + "queue": "3", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "COPP_GROUP_MANDATORY_METER_TYPE": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue4_group5", + "trap_action":"trap", + "trap_priority":"4", + "queue": "4", + "mode":"sr_tcm", + "cir":"5000", + "cbs":"5000", + "red_action":"drop" + }] + } + } + }, + + "COPP_GROUP_PIR_LESS_THAN_CIR": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue5_group6", + "trap_action":"trap", + "trap_priority":"5", + "queue": "5", + "mode":"tr_tcm", + "cir":"5000", + "cbs":"5000", + "pir":"4000", + "pbs":"4000", + "red_action":"drop" + }] + } + } + }, + + "COPP_TRAP_MANDATORY_TRAP_IDS": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue6_group7", + "trap_action":"trap", + "trap_priority":"6", + "queue": "6", + "meter_type":"packets", + "mode":"sr_tcm", + "cir":"6000", + "cbs":"6000", + "red_action":"drop" + }] + }, + "sonic-copp:COPP_TRAP": { + "COPP_TRAP_LIST": [{ + "name": "bgp", + "trap_group": "queue6_group7" + }] + } + } + }, + + "COPP_GROUP_WHEN_SRTCM_WITH_PIR": { + "sonic-copp:sonic-copp": { + "sonic-copp:COPP_GROUP": { + "COPP_GROUP_LIST": [{ + "name": "queue6_group7", + "trap_action":"trap", + "trap_priority":"6", + "queue": "6", + "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 new file mode 100644 index 000000000000..9805b5fd0cce --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-copp.yang @@ -0,0 +1,191 @@ +module sonic-copp { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-copp"; + prefix copp; + + import sonic-types { + prefix stypes; + } + + description "CoPP YANG Module for SONiC OS"; + + revision 2021-03-31 { + description + "First Revision"; + } + + container sonic-copp { + container COPP_GROUP { + list COPP_GROUP_LIST { + key name; + + leaf name { + type string; + description "Control plane policing group name"; + } + + leaf queue { + type uint32; + default 0; + description "CPU Rx queue id"; + } + + leaf trap_priority { + type uint32; + default 0; + description "Trap priority"; + } + + leaf trap_action { + mandatory true; + type stypes:copp_packet_action; + description "Trap action"; + } + + leaf meter_type { + mandatory true; + type stypes:meter_type; + description "Policer meter type"; + } + + leaf mode { + mandatory true; + type enumeration { + enum sr_tcm; + enum tr_tcm; + enum storm; + } + description "Policer mode"; + } + + leaf color { + type enumeration { + enum blind; + enum color; + } + default "color"; + 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:copp_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; + default "forward"; + description "Yellow action"; + } + + leaf red_action { + type stypes:copp_packet_action; + default "forward"; + description "Red action"; + } + } + /* end of list COPP_GROUP_LIST */ + } + /* end of container COPP_GROUP */ + + container COPP_TRAP { + list COPP_TRAP_LIST { + key name; + + leaf name { + type string; + description "Control plane policing trap name"; + } + + leaf trap_ids { + mandatory true; + type string; + description "list of trap_ids"; + } + + leaf trap_group { + type leafref { + path "/sonic-copp/COPP_GROUP/COPP_GROUP_LIST/name"; + } + description "reference to CoPP group"; + } + } + /* end of list COPP_TRAP_LIST */ + } + /* end of container COPP_TRAP */ + } + /* end of top level container */ + + rpc get-match-protocols { + description + "RPC to get allowed match protocols"; + + output { + list Match_protocols { + key "Protocol"; + + leaf Protocol { + type string; + description + "Protocol name"; + } + } + } + } + /* end of rpc get-match-protocols */ +} +/* end of module sonic-copp */ diff --git a/src/sonic-yang-models/yang-models/sonic-types.yang b/src/sonic-yang-models/yang-models/sonic-types.yang index db0f9a0ac16f..1e5d6dc29db3 100644 --- a/src/sonic-yang-models/yang-models/sonic-types.yang +++ b/src/sonic-yang-models/yang-models/sonic-types.yang @@ -159,4 +159,24 @@ module sonic-types { pattern "0x8100|0x9100|0x9200|0x88a8|0x88A8"; } } + + typedef meter_type { + type enumeration { + enum packets; + enum bytes; + } + } + + typedef copp_packet_action { + type enumeration { + enum drop; + enum forward; + enum copy; + enum copy_cancel; + enum trap; + enum log; + enum deny; + enum transit; + } + } }