From 30916937dfaeff52f9432230229d06c3c7bb5788 Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 5 Jan 2022 16:08:25 +0800 Subject: [PATCH 1/5] [YANG] Add route flow counter support --- .../yang_model_tests/tests/flex_counter.json | 11 +++ .../tests_config/flex_counter.json | 75 +++++++++++++++++++ .../yang-models/sonic-flex_counter.yang | 43 +++++++++++ 3 files changed, 129 insertions(+) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/flex_counter.json b/src/sonic-yang-models/tests/yang_model_tests/tests/flex_counter.json index 7a328ca693c1..92d96b54f3a1 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/flex_counter.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/flex_counter.json @@ -6,5 +6,16 @@ "desc": "Out of range poll interval.", "eStrKey": "Range", "eStr": "100..4294967295" + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_VRF": { + "desc": "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_VRF no failure." + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_DEFAULT_VRF": { + "desc": "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_DEFAULT_VRF no failure." + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_INVALID_MAX_MATCH_COUNT": { + "desc": "Out of range max_match_count.", + "eStrKey": "Range", + "eStr": "1..50" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json index 9043132791fd..6665659392d9 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json @@ -46,6 +46,10 @@ "FLOW_CNT_TRAP": { "FLEX_COUNTER_STATUS": "enable", "POLL_INTERVAL": 10000 + }, + "FLOW_CNT_ROUTE": { + "FLEX_COUNTER_STATUS": "enable", + "POLL_INTERVAL": 10000 } } } @@ -97,8 +101,79 @@ "FLOW_CNT_TRAP": { "FLEX_COUNTER_STATUS": "enable", "POLL_INTERVAL": 99 + }, + "FLOW_CNT_ROUTE": { + "FLEX_COUNTER_STATUS": "enable", + "POLL_INTERVAL": 99 } } } + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_VRF": { + "sonic-vrf:sonic-vrf":{ + "sonic-vrf:VRF": { + "VRF_LIST": [ + { + "name":"Vrf1" + } + ] + } + }, + "sonic-flex_counter:sonic-flex_counter": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "PATTERN_LIST": [ + { + "vrf_name": "Vrf1", + "ip_prefix": "1.1.1.0/24", + "max_match_count": 30 + }, + { + "vrf_name": "Vrf1", + "ip_prefix": "2000::/64", + "max_match_count": 30 + } + ] + } + } + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_DEFAULT_VRF": { + "sonic-flex_counter:sonic-flex_counter": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "PATTERN_LIST": [ + { + "vrf_name": "", + "ip_prefix": "1.1.1.0/24", + "max_match_count": 30 + }, + { + "vrf_name": "", + "ip_prefix": "2000::/64", + "max_match_count": 30 + } + ] + } + } + }, + "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_INVALID_MAX_MATCH_COUNT": { + "sonic-vrf:sonic-vrf":{ + "sonic-vrf:VRF": { + "VRF_LIST": [ + { + "name":"Vrf1" + } + ] + } + }, + "sonic-flex_counter:sonic-flex_counter": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "PATTERN_LIST": [ + { + "vrf_name": "Vrf1", + "ip_prefix": "1.1.1.0/24", + "max_match_count": 0 + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index 8e958af2f427..03a5c9a6bc14 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -211,8 +211,51 @@ module sonic-flex_counter { } } + container FLOW_CNT_ROUTE { + /* ROUTE_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + leaf FLEX_COUNTER_DELAY_STATUS { + type flex_delay_status; + } + leaf POLL_INTERVAL { + type poll_interval; + } + } + } /* end of container FLEX_COUNTER_TABLE */ + + container FLOW_COUNTER_ROUTE_PATTERN_TABLE { + description "Flow counter route pattern of config_db.json"; + + list PATTERN_LIST { + + key "vrf_name ip_prefix"; + + leaf vrf_name { + type string { + length 0..16; + } + } + + leaf ip_prefix { + type union { + type stypes:sonic-ip4-prefix; + type stypes:sonic-ip6-prefix; + } + } + + leaf max_match_count { + type uint32 { + range 1..50; + } + } + + } + } + /* end of container FLOW_COUNTER_ROUTE_PATTERN_TABLE */ } /* end of top level container */ } From 530967fe5397bed737a1d7dc7c66f67a5482b01d Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 24 Jan 2022 10:10:55 +0800 Subject: [PATCH 2/5] Fix review comment --- src/sonic-yang-models/yang-models/sonic-flex_counter.yang | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index 03a5c9a6bc14..17db1da48ade 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -241,10 +241,7 @@ module sonic-flex_counter { } leaf ip_prefix { - type union { - type stypes:sonic-ip4-prefix; - type stypes:sonic-ip6-prefix; - } + type stypes:sonic-ip-prefix; } leaf max_match_count { From d230e180a8eec337eca7975ecbd6d17be570e574 Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 25 Jan 2022 11:20:26 +0800 Subject: [PATCH 3/5] Add comment to explain why we do not use VRF reference in pattern table --- src/sonic-yang-models/yang-models/sonic-flex_counter.yang | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index 17db1da48ade..17af7676df14 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -235,6 +235,11 @@ module sonic-flex_counter { key "vrf_name ip_prefix"; leaf vrf_name { + /* + We don't use vrf_name reference here because: + 1. User is allowed to configure a VRF that does not exist yet here, orchagent is designed to resolve the VRF name once the VRF is created. + 2. The field vrf_name accept both VRF name and VNET name. + */ type string { length 0..16; } From 62457b8df3adcb5f6132c2df14cdfcb1cdf61db5 Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 26 Jan 2022 15:33:35 +0800 Subject: [PATCH 4/5] Rename FLOW_COUNTER_ROUTE_PATTERN_TABLE to FLOW_COUNTER_ROUTE_PATTERN --- .../tests/yang_model_tests/tests_config/flex_counter.json | 6 +++--- src/sonic-yang-models/yang-models/sonic-flex_counter.yang | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json index 6665659392d9..25a0c73b5ff6 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json @@ -120,7 +120,7 @@ } }, "sonic-flex_counter:sonic-flex_counter": { - "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { "PATTERN_LIST": [ { "vrf_name": "Vrf1", @@ -138,7 +138,7 @@ }, "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_DEFAULT_VRF": { "sonic-flex_counter:sonic-flex_counter": { - "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { "PATTERN_LIST": [ { "vrf_name": "", @@ -165,7 +165,7 @@ } }, "sonic-flex_counter:sonic-flex_counter": { - "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN_TABLE": { + "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { "PATTERN_LIST": [ { "vrf_name": "Vrf1", diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index 17af7676df14..bb26ddcc2b5f 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -227,7 +227,7 @@ module sonic-flex_counter { } /* end of container FLEX_COUNTER_TABLE */ - container FLOW_COUNTER_ROUTE_PATTERN_TABLE { + container FLOW_COUNTER_ROUTE_PATTERN { description "Flow counter route pattern of config_db.json"; list PATTERN_LIST { From b8b6ddd0fb038466d12f5bfa573fa320d3fa7a3f Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 8 Feb 2022 18:18:09 +0800 Subject: [PATCH 5/5] Fix review comment --- .../tests/files/sample_config_db.json | 15 +++++++++++ .../tests_config/flex_counter.json | 14 +++++----- .../yang-models/sonic-flex_counter.yang | 26 ++++++++++++++++--- 3 files changed, 44 insertions(+), 11 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 455eed24b01d..90e67a975aa0 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -957,6 +957,21 @@ }, "DEBUG_COUNTER": { "FLEX_COUNTER_STATUS": "enable" + }, + "FLOW_CNT_ROUTE": { + "FLEX_COUNTER_STATUS": "enable", + "POLL_INTERVAL": "10000" + } + }, + "FLOW_COUNTER_ROUTE_PATTERN": { + "1.1.1.0/24": { + "max_match_count": "30" + }, + "2000::/64": { + "max_match_count": "30" + }, + "Vnet1|2.2.2.0/24": { + "max_match_count": "30" } }, "CRM": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json index 25a0c73b5ff6..169a38ff6d7c 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/flex_counter.json @@ -121,7 +121,7 @@ }, "sonic-flex_counter:sonic-flex_counter": { "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { - "PATTERN_LIST": [ + "FLOW_COUNTER_ROUTE_PATTERN_VRF_LIST": [ { "vrf_name": "Vrf1", "ip_prefix": "1.1.1.0/24", @@ -139,14 +139,12 @@ "FLOW_COUNTER_ROUTE_PATTERN_TABLE_WITH_DEFAULT_VRF": { "sonic-flex_counter:sonic-flex_counter": { "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { - "PATTERN_LIST": [ + "FLOW_COUNTER_ROUTE_PATTERN_LIST": [ { - "vrf_name": "", "ip_prefix": "1.1.1.0/24", "max_match_count": 30 }, { - "vrf_name": "", "ip_prefix": "2000::/64", "max_match_count": 30 } @@ -158,15 +156,15 @@ "sonic-vrf:sonic-vrf":{ "sonic-vrf:VRF": { "VRF_LIST": [ - { - "name":"Vrf1" - } + { + "name":"Vrf1" + } ] } }, "sonic-flex_counter:sonic-flex_counter": { "sonic-flex_counter:FLOW_COUNTER_ROUTE_PATTERN": { - "PATTERN_LIST": [ + "FLOW_COUNTER_ROUTE_PATTERN_VRF_LIST": [ { "vrf_name": "Vrf1", "ip_prefix": "1.1.1.0/24", diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index bb26ddcc2b5f..9ced223e94bc 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -5,6 +5,10 @@ module sonic-flex_counter { namespace "http://github.com/Azure/sonic-flex_counter"; prefix flex_counter; + import ietf-inet-types { + prefix inet; + } + import sonic-types { prefix stypes; } @@ -230,7 +234,23 @@ module sonic-flex_counter { container FLOW_COUNTER_ROUTE_PATTERN { description "Flow counter route pattern of config_db.json"; - list PATTERN_LIST { + list FLOW_COUNTER_ROUTE_PATTERN_LIST { + + key "ip_prefix"; + + leaf ip_prefix { + type inet:ip-prefix; + } + + leaf max_match_count { + type uint32 { + range 1..50; + } + } + + } + + list FLOW_COUNTER_ROUTE_PATTERN_VRF_LIST { key "vrf_name ip_prefix"; @@ -246,7 +266,7 @@ module sonic-flex_counter { } leaf ip_prefix { - type stypes:sonic-ip-prefix; + type inet:ip-prefix; } leaf max_match_count { @@ -257,7 +277,7 @@ module sonic-flex_counter { } } - /* end of container FLOW_COUNTER_ROUTE_PATTERN_TABLE */ + /* end of container FLOW_COUNTER_ROUTE_PATTERN */ } /* end of top level container */ }