From e3f4253417e16503c4600fa98be11125a31840c8 Mon Sep 17 00:00:00 2001 From: Vasundhara Volam Date: Sat, 11 Jan 2025 14:05:35 +0000 Subject: [PATCH 1/5] Add yang model for DPU_PORT information --- src/sonic-yang-models/doc/Configuration.md | 36 +++++++++ .../tests/files/sample_config_db.json | 22 +++++- .../yang-models/sonic-smart-switch.yang | 77 +++++++++++++++++-- 3 files changed, 129 insertions(+), 6 deletions(-) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 0a721774e3c4..51f6f480d466 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -2973,6 +2973,42 @@ The ASIC_SENSORS table introduces the asic sensors polling configuration when th } ``` +### DPU PORT Configuration^M + +The **DPU_PORT** table introduces the configuration for the DPUs(Data Processing Unit) PORT information available on the platform. + +```json +{ + "DPU_PORT": { + "dpu0": { + "state": "up", + "vip_ipv4": "192.168.1.1/24", + "vip_ipv6": "2001:db8::1/64", + "pa_ipv4": "192.168.1.10", + "pa_ipv6": "2001:db8::10", + "vdpu_id": "vdpu0", + "gnmi": 50052 + }, + "dpu1": { + "state": "down", + "vip_ipv4": "192.168.1.2/24", + "vip_ipv6": "2001:db8::2/64", + "pa_ipv4": "192.168.1.20", + "pa_ipv6": "2001:db8::20", + "vdpu_id": "vdpu1", + "gnmi": 50052 + } + } +} +``` + +**state**: Administrative status of the DPU (`up` or `down`). +**vip_ipv4**: VIP IPv4 address from minigraph. +**vip_ipv6**: VIP IPv6 address from minigraph. +**pa_ipv4**: PA IPv4 address from minigraph. +**pa_ipv6**: PA IPv6 address from minigraph. +**vdpu_id**: ID of VDPUs from minigraph. +**gnmi**: Port gNMI runs on. # For Developers 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 ac347440893a..fbd18f370f13 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2767,6 +2767,26 @@ "midplane_interface": "dpu1" } }, + "DPU_PORT": { + "dpu0": { + "state": "up", + "vip_ipv4": "192.168.1.1/24", + "vip_ipv6": "2001:db8::1/64", + "pa_ipv4": "192.168.1.10", + "pa_ipv6": "2001:db8::10", + "vdpu_id": "vdpu0", + "gnmi": 50052 + }, + "dpu1": { + "state": "down", + "vip_ipv4": "192.168.1.2/24", + "vip_ipv6": "2001:db8::2/64", + "pa_ipv4": "192.168.1.20", + "pa_ipv6": "2001:db8::20", + "vdpu_id": "vdpu1", + "gnmi": 50052 + } + }, "XCVRD_LOG": { "Y_CABLE": { "log_verbosity": "notice" @@ -2783,7 +2803,7 @@ "client_key": "grpcclient.key", "ca_crt": "root.pem", "grpc_ssl_credential": "azureclient.ms" - } + } }, "BANNER_MESSAGE": { "global": { diff --git a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang index 77880f0362c3..a0e10a12682f 100644 --- a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang +++ b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang @@ -9,13 +9,19 @@ module sonic-smart-switch { prefix inet; } - import sonic-types { - prefix stypes; - } + import sonic-types { + prefix stypes; + } import sonic-port { - prefix port; - } + prefix port; + } + + organization + "SONiC"; + + contact + "SONiC"; description "Smart Switch yang Module for SONiC OS"; @@ -23,6 +29,10 @@ module sonic-smart-switch { description "First Revision"; } + revision 2025-01-11 { + description "Add new container DPU_PORT"; + } + container sonic-smart-switch { container MID_PLANE_BRIDGE { @@ -74,6 +84,63 @@ module sonic-smart-switch { /* end of container DPUS_LIST */ } /* end of container DPUS */ + + container DPU_PORT { + description "DPU_PORTs part of config_db.json"; + + list DPU_PORT_LIST { + description "Name of the DPU port"; + key "PORT_NAME"; + + leaf PORT_NAME { + description "Name of the DPU port"; + type string; + } + + leaf state { + description "Admin state of DPU device"; + type enumeration { + enum up { + description "Admin state is up"; + } + enum down { + description "Admin state is down"; + } + } + } + + leaf vip_ipv4 { + description "VIP IPv4 address from minigraph"; + type inet:ipv4-prefix; + } + + leaf vip_ipv6 { + description "VIP IPv6 address from minigraph"; + type inet:ipv6-prefix; + } + + leaf pa_ipv4 { + description "PA IPv4 address from minigraph"; + type inet:ipv4-address; + } + + leaf pa_ipv6 { + description "PA IPv6 address from minigraph"; + type inet:ipv6-address; + } + + leaf vdpu_id { + description "ID of VDPUs from minigraph"; + type string; + } + + leaf gnmi { + description "Port gNMI runs on."; + type inet:port-number; + } + } + } + /* end of container DPU_PORT */ } /* end of container sonic-smart-switch */ } From 30acd06780a2d52deabc4ed65fc793ed8b5f4927 Mon Sep 17 00:00:00 2001 From: Vasundhara Volam Date: Wed, 15 Jan 2025 19:43:28 +0000 Subject: [PATCH 2/5] Fix sample configuration --- src/sonic-yang-models/doc/Configuration.md | 12 ++++++------ .../tests/files/sample_config_db.json | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 51f6f480d466..03cf8e70704b 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -2982,21 +2982,21 @@ The **DPU_PORT** table introduces the configuration for the DPUs(Data Processing "DPU_PORT": { "dpu0": { "state": "up", - "vip_ipv4": "192.168.1.1/24", - "vip_ipv6": "2001:db8::1/64", + "vip_ipv4": "192.168.1.0/24", + "vip_ipv6": "2001:db8::/64", "pa_ipv4": "192.168.1.10", "pa_ipv6": "2001:db8::10", "vdpu_id": "vdpu0", - "gnmi": 50052 + "gnmi": "50052" }, "dpu1": { "state": "down", - "vip_ipv4": "192.168.1.2/24", - "vip_ipv6": "2001:db8::2/64", + "vip_ipv4": "192.168.1.0/24", + "vip_ipv6": "2001:db8::/64", "pa_ipv4": "192.168.1.20", "pa_ipv6": "2001:db8::20", "vdpu_id": "vdpu1", - "gnmi": 50052 + "gnmi": "50052" } } } 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 fbd18f370f13..ebeb701588d8 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2770,21 +2770,21 @@ "DPU_PORT": { "dpu0": { "state": "up", - "vip_ipv4": "192.168.1.1/24", - "vip_ipv6": "2001:db8::1/64", + "vip_ipv4": "192.168.1.0/24", + "vip_ipv6": "2001:db8::/64", "pa_ipv4": "192.168.1.10", "pa_ipv6": "2001:db8::10", "vdpu_id": "vdpu0", - "gnmi": 50052 + "gnmi": "50052" }, "dpu1": { "state": "down", - "vip_ipv4": "192.168.1.2/24", - "vip_ipv6": "2001:db8::2/64", + "vip_ipv4": "192.168.1.0/24", + "vip_ipv6": "2001:db8::/64", "pa_ipv4": "192.168.1.20", "pa_ipv6": "2001:db8::20", "vdpu_id": "vdpu1", - "gnmi": 50052 + "gnmi": "50052" } }, "XCVRD_LOG": { From 6b164d038d64a4c6bb7e85a49bdda86e26a7fddd Mon Sep 17 00:00:00 2001 From: Vasundhara Volam Date: Thu, 16 Jan 2025 19:35:56 +0000 Subject: [PATCH 3/5] Use sonic types Also, write test cases for DPU_PORT --- src/sonic-yang-models/doc/Configuration.md | 14 +- .../tests/files/sample_config_db.json | 12 +- .../yang_model_pytests/test_smart_switch.py | 162 ++++++++++++++++++ .../yang-models/sonic-smart-switch.yang | 19 +- 4 files changed, 182 insertions(+), 25 deletions(-) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 03cf8e70704b..b3ff0589dc19 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -2982,21 +2982,21 @@ The **DPU_PORT** table introduces the configuration for the DPUs(Data Processing "DPU_PORT": { "dpu0": { "state": "up", - "vip_ipv4": "192.168.1.0/24", - "vip_ipv6": "2001:db8::/64", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::10", "pa_ipv4": "192.168.1.10", "pa_ipv6": "2001:db8::10", "vdpu_id": "vdpu0", - "gnmi": "50052" + "gnmi_port": "50052" }, "dpu1": { "state": "down", - "vip_ipv4": "192.168.1.0/24", - "vip_ipv6": "2001:db8::/64", + "vip_ipv4": "192.168.1.2", + "vip_ipv6": "2001:db8::20", "pa_ipv4": "192.168.1.20", "pa_ipv6": "2001:db8::20", "vdpu_id": "vdpu1", - "gnmi": "50052" + "gnmi_port": "50052" } } } @@ -3008,7 +3008,7 @@ The **DPU_PORT** table introduces the configuration for the DPUs(Data Processing **pa_ipv4**: PA IPv4 address from minigraph. **pa_ipv6**: PA IPv6 address from minigraph. **vdpu_id**: ID of VDPUs from minigraph. -**gnmi**: Port gNMI runs on. +**gnmi_port**: Port gNMI runs on. # For Developers 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 ebeb701588d8..b924bd5d938e 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2770,21 +2770,21 @@ "DPU_PORT": { "dpu0": { "state": "up", - "vip_ipv4": "192.168.1.0/24", - "vip_ipv6": "2001:db8::/64", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::10", "pa_ipv4": "192.168.1.10", "pa_ipv6": "2001:db8::10", "vdpu_id": "vdpu0", - "gnmi": "50052" + "gnmi_port": "50052" }, "dpu1": { "state": "down", - "vip_ipv4": "192.168.1.0/24", - "vip_ipv6": "2001:db8::/64", + "vip_ipv4": "192.168.1.2", + "vip_ipv6": "2001:db8::20", "pa_ipv4": "192.168.1.20", "pa_ipv6": "2001:db8::20", "vdpu_id": "vdpu1", - "gnmi": "50052" + "gnmi_port": "50052" } }, "XCVRD_LOG": { diff --git a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py index f1242719c028..fa82acf22ab6 100644 --- a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py +++ b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py @@ -108,3 +108,165 @@ def test_dpu_midplane_interface(self, yang_model, midplane_interface, error_mess } yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "port_name, error_message", [ + ("port0", None), + ("Port0", 'Value "Port0" does not satisfy the constraint "[a-z]+[0-9]+"')] + ) + def test_dpu_port_name(self, yang_model, port_name, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": port_name, + "state": "up", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::1", + "pa_ipv4": "192.168.1.2", + "pa_ipv6": "2001:db8::2", + "vdpu_id": "vdpu0", + "gnmi_port": 8080 + } + ] + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "vip_ipv4, error_message", [ + ("192.168.1.1", None), + ("192.168.1.xyz", 'Value "192.168.1.xyz" does not satisfy the constraint')] + ) + def test_dpu_port_vip_ipv4(self, yang_model, vip_ipv4, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": "port0", + "state": "up", + "vip_ipv4": vip_ipv4, + "vip_ipv6": "2001:db8::1", + "pa_ipv4": "192.168.1.2", + "pa_ipv6": "2001:db8::2", + "vdpu_id": "vdpu0", + "gnmi_port": 8080 + } + ] + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "vip_ipv6, error_message", [ + ("2001:db8::1", None), + ("2001:db8::xyz", 'Value "2001:db8::xyz" does not satisfy the constraint')] + ) + def test_dpu_port_vip_ipv6(self, yang_model, vip_ipv6, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": "port0", + "state": "up", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": vip_ipv6, + "pa_ipv4": "192.168.1.2", + "pa_ipv6": "2001:db8::2", + "vdpu_id": "vdpu0", + "gnmi_port": 8080 + } + ] + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "pa_ipv4, error_message", [ + ("192.168.1.2", None), + ("192.168.1.xyz", 'Value "192.168.1.xyz" does not satisfy the constraint')] + ) + def test_dpu_port_pa_ipv4(self, yang_model, pa_ipv4, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": "port0", + "state": "up", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::1", + "pa_ipv4": pa_ipv4, + "pa_ipv6": "2001:db8::2", + "vdpu_id": "vdpu0", + "gnmi_port": 8080 + } + ] + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "pa_ipv6, error_message", [ + ("2001:db8::2", None), + ("2001:db8::xyz", 'Value "2001:db8::xyz" does not satisfy the constraint')] + ) + def test_dpu_port_pa_ipv6(self, yang_model, pa_ipv6, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": "port0", + "state": "up", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::1", + "pa_ipv4": "192.168.1.2", + "pa_ipv6": pa_ipv6, + "vdpu_id": "vdpu0", + "gnmi_port": 8080 + } + ] + } + } + } + + yang_model.load_data(data, error_message) + + @pytest.mark.parametrize( + "gnmi_port, error_message", [ + (8080, None), + (99999, 'Invalid value "99999" in "gnmi_port" element.')] + ) + def test_dpu_port_gnmi(self, yang_model, gnmi_port, error_message): + data = { + "sonic-smart-switch:sonic-smart-switch": { + "sonic-smart-switch:DPU_PORT": { + "DPU_PORT_LIST": [ + { + "PORT_NAME": "port0", + "state": "up", + "vip_ipv4": "192.168.1.1", + "vip_ipv6": "2001:db8::1", + "pa_ipv4": "192.168.1.2", + "pa_ipv6": "2001:db8::2", + "vdpu_id": "vdpu0", + "gnmi_port": gnmi_port + } + ] + } + } + } + + yang_model.load_data(data, error_message) diff --git a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang index a0e10a12682f..fd26bf7695c8 100644 --- a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang +++ b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang @@ -94,29 +94,24 @@ module sonic-smart-switch { leaf PORT_NAME { description "Name of the DPU port"; - type string; + type string { + pattern "[a-z]+[0-9]+"; + } } leaf state { description "Admin state of DPU device"; - type enumeration { - enum up { - description "Admin state is up"; - } - enum down { - description "Admin state is down"; - } - } + type stypes:admin_status; } leaf vip_ipv4 { description "VIP IPv4 address from minigraph"; - type inet:ipv4-prefix; + type inet:ipv4-address; } leaf vip_ipv6 { description "VIP IPv6 address from minigraph"; - type inet:ipv6-prefix; + type inet:ipv6-address; } leaf pa_ipv4 { @@ -134,7 +129,7 @@ module sonic-smart-switch { type string; } - leaf gnmi { + leaf gnmi_port { description "Port gNMI runs on."; type inet:port-number; } From a332c10c7544fdd1db3dd86b1943a166a053faf7 Mon Sep 17 00:00:00 2001 From: Vasundhara Volam Date: Wed, 22 Jan 2025 02:25:04 +0000 Subject: [PATCH 4/5] Allow capital alphabets in the PORT_NAME --- .../tests/yang_model_pytests/test_smart_switch.py | 2 +- src/sonic-yang-models/yang-models/sonic-smart-switch.yang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py index fa82acf22ab6..0e661e89c31e 100644 --- a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py +++ b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py @@ -112,7 +112,7 @@ def test_dpu_midplane_interface(self, yang_model, midplane_interface, error_mess @pytest.mark.parametrize( "port_name, error_message", [ ("port0", None), - ("Port0", 'Value "Port0" does not satisfy the constraint "[a-z]+[0-9]+"')] + ("Po0rt0", 'Value "Po0rt0" does not satisfy the constraint "[a-zA-Z]+[0-9]+"')] ) def test_dpu_port_name(self, yang_model, port_name, error_message): data = { diff --git a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang index fd26bf7695c8..1b91e5b61ced 100644 --- a/src/sonic-yang-models/yang-models/sonic-smart-switch.yang +++ b/src/sonic-yang-models/yang-models/sonic-smart-switch.yang @@ -95,7 +95,7 @@ module sonic-smart-switch { leaf PORT_NAME { description "Name of the DPU port"; type string { - pattern "[a-z]+[0-9]+"; + pattern "[a-zA-Z]+[0-9]+"; } } From a7de87854938fbdbc169cb351d0b2389dc6d8fbf Mon Sep 17 00:00:00 2001 From: Vasundhara Volam Date: Tue, 4 Feb 2025 03:16:29 +0000 Subject: [PATCH 5/5] Use dpu0 name uniformly --- .../tests/yang_model_pytests/test_smart_switch.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py index 0e661e89c31e..4258e5e80641 100644 --- a/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py +++ b/src/sonic-yang-models/tests/yang_model_pytests/test_smart_switch.py @@ -111,8 +111,8 @@ def test_dpu_midplane_interface(self, yang_model, midplane_interface, error_mess @pytest.mark.parametrize( "port_name, error_message", [ - ("port0", None), - ("Po0rt0", 'Value "Po0rt0" does not satisfy the constraint "[a-zA-Z]+[0-9]+"')] + ("dpu0", None), + ("dp0rt0", 'Value "dp0rt0" does not satisfy the constraint "[a-zA-Z]+[0-9]+"')] ) def test_dpu_port_name(self, yang_model, port_name, error_message): data = { @@ -147,7 +147,7 @@ def test_dpu_port_vip_ipv4(self, yang_model, vip_ipv4, error_message): "sonic-smart-switch:DPU_PORT": { "DPU_PORT_LIST": [ { - "PORT_NAME": "port0", + "PORT_NAME": "dpu0", "state": "up", "vip_ipv4": vip_ipv4, "vip_ipv6": "2001:db8::1", @@ -174,7 +174,7 @@ def test_dpu_port_vip_ipv6(self, yang_model, vip_ipv6, error_message): "sonic-smart-switch:DPU_PORT": { "DPU_PORT_LIST": [ { - "PORT_NAME": "port0", + "PORT_NAME": "dpu0", "state": "up", "vip_ipv4": "192.168.1.1", "vip_ipv6": vip_ipv6, @@ -201,7 +201,7 @@ def test_dpu_port_pa_ipv4(self, yang_model, pa_ipv4, error_message): "sonic-smart-switch:DPU_PORT": { "DPU_PORT_LIST": [ { - "PORT_NAME": "port0", + "PORT_NAME": "dpu0", "state": "up", "vip_ipv4": "192.168.1.1", "vip_ipv6": "2001:db8::1", @@ -228,7 +228,7 @@ def test_dpu_port_pa_ipv6(self, yang_model, pa_ipv6, error_message): "sonic-smart-switch:DPU_PORT": { "DPU_PORT_LIST": [ { - "PORT_NAME": "port0", + "PORT_NAME": "dpu0", "state": "up", "vip_ipv4": "192.168.1.1", "vip_ipv6": "2001:db8::1", @@ -255,7 +255,7 @@ def test_dpu_port_gnmi(self, yang_model, gnmi_port, error_message): "sonic-smart-switch:DPU_PORT": { "DPU_PORT_LIST": [ { - "PORT_NAME": "port0", + "PORT_NAME": "dpu0", "state": "up", "vip_ipv4": "192.168.1.1", "vip_ipv6": "2001:db8::1",