From 86a5a7f1ea34893aa010ee6f850a82ad6dd5f22d Mon Sep 17 00:00:00 2001 From: Nikola Dancejic <26731235+Ndancejic@users.noreply.github.com> Date: Thu, 29 Dec 2022 17:12:25 -0800 Subject: [PATCH] add Tunnel yang model (#12232) #### Why I did it Add yang model for TUNNEL config #### How I did it created sonic-tunnel.yang file and tests #### How to verify it `make target/python-wheels/bullseye/sonic_yang_models-1.0-py3-none-any.whl` #### Link to config_db schema for YANG module changes https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#tunnel --- src/sonic-yang-models/doc/Configuration.md | 56 +++++++ src/sonic-yang-models/setup.py | 1 + .../tests/files/sample_config_db.json | 47 +++++- .../tests/yang_model_tests/tests/tunnel.json | 18 +++ .../yang_model_tests/tests_config/tunnel.json | 143 ++++++++++++++++++ .../yang-models/sonic-tunnel.yang | 122 +++++++++++++++ 6 files changed, 379 insertions(+), 8 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/tunnel.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/tunnel.json create mode 100644 src/sonic-yang-models/yang-models/sonic-tunnel.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index d05eca0d70ef..b56b9a2fbcd0 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -54,6 +54,7 @@ Table of Contents * [TC to Priority group map](#tc-to-priority-group-map) * [TC to Queue map](#tc-to-queue-map) * [Telemetry](#telemetry) + * [Tunnel](#tunnel) * [Versions](#versions) * [VLAN](#vlan) * [VLAN_MEMBER](#vlan_member) @@ -1594,6 +1595,61 @@ Container side configuration: } ``` +### Tunnel + +This table configures the MUX tunnel for Dual-ToR setup +``` +{ + "TUNNEL": { + "MuxTunnel0": { + "dscp_mode": "uniform", + "dst_ip": "10.1.0.32", + "ecn_mode": "copy_from_outer", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP" + } + } +} +``` + +different example for configuring MUX tunnel +``` +{ + "TUNNEL": { + "MuxTunnel0": { + "dscp_mode": "pipe", + "dst_ip": "10.1.0.32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "uniform", + "tunnel_type": "IPINIP" + } + } +} +``` + +example mux tunnel configuration for when tunnel_qos_remap is enabled +``` +{ + "TUNNEL": { + "MuxTunnel0": { + "tunnel_type": "IPINIP", + "src_ip": "10.1.0.33", + "dst_ip": "10.1.0.32", + "dscp_mode": "pipe", + "encap_ecn_mode": "standard", + "ecn_mode": "copy_from_outer", + "ttl_mode": "uniform", + "decap_dscp_to_tc_map": "DecapDscpToTcMap", + "decap_tc_to_pg_map": "DecapTcToPgMap", + "encap_tc_to_dscp_map": "EncapTcToQueueMap", + "encap_tc_to_queue_map": "EncapTcToDscpMap" + } + } +} +``` + ### Versions This table is where the curret version of the software is recorded. diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 8c318e583fa0..de33a04da64f 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -145,6 +145,7 @@ def run(self): './yang-models/sonic-system-aaa.yang', './yang-models/sonic-system-tacacs.yang', './yang-models/sonic-telemetry.yang', + './yang-models/sonic-tunnel.yang', './yang-models/sonic-types.yang', './yang-models/sonic-versions.yang', './yang-models/sonic-vlan.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 99c94e96cfae..ce006b497f63 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1144,14 +1144,45 @@ "TELEMETRY": { "certs": { "ca_crt": "/etc/sonic/telemetry/dsmsroot.cer", - "server_crt": "/etc/sonic/telemetry/streamingtelemetryserver.cer", - "server_key": "/etc/sonic/telemetry/streamingtelemetryserver.key" - }, - "gnmi": { - "client_auth": "true", - "log_level": "2", - "port": "50051" - } + "server_crt": "/etc/sonic/telemetry/streamingtelemetryserver.cer", + "server_key": "/etc/sonic/telemetry/streamingtelemetryserver.key" + }, + "gnmi": { + "client_auth": "true", + "log_level": "2", + "port": "50051" + } + }, + "TUNNEL": { + "MuxTunnel0": { + "dscp_mode": "uniform", + "dst_ip": "10.1.0.32", + "ecn_mode": "copy_from_outer", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP" + }, + "MuxTunnel1": { + "dscp_mode": "pipe", + "dst_ip": "10.1.0.32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "uniform", + "tunnel_type": "IPINIP" + }, + "MuxTunnel2": { + "tunnel_type": "IPINIP", + "src_ip": "10.1.0.33", + "dst_ip": "10.1.0.32", + "dscp_mode": "pipe", + "encap_ecn_mode": "standard", + "ecn_mode": "copy_from_outer", + "ttl_mode": "uniform", + "decap_dscp_to_tc_map": "Dscp_to_tc_map1", + "decap_tc_to_pg_map": "tc_to_pg_map1", + "encap_tc_to_dscp_map": "EncapTcToQueueMap", + "encap_tc_to_queue_map": "tc_to_q_map1" + } }, "RESTAPI": { "certs": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/tunnel.json b/src/sonic-yang-models/tests/yang_model_tests/tests/tunnel.json new file mode 100644 index 000000000000..b414b639aa35 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/tunnel.json @@ -0,0 +1,18 @@ +{ + "TUNNEL_LOAD_NORMAL": { + "desc": "Load TUNNEL for dualtor device." + }, + "TUNNEL_INVALID_ADDR": { + "desc": "Load TUNNEL with invalid IPv4 Address.", + "eStr": ["does not satisfy the constraint"] + }, + "TUNNEL_SRC_IP_NOT_PEER_SWITCH": { + "desc": "Load TUNNEL with wrong IPv4 Address.", + "eStr": ["points to a non-existing leaf."] + }, + "TUNNEL_MISSING_MUX_TUNNEL": { + "desc": "Load MUX_TUNNEL missing name.", + "eStr": ["Missing required element"] + } +} + diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/tunnel.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/tunnel.json new file mode 100644 index 000000000000..0f511e6dde24 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/tunnel.json @@ -0,0 +1,143 @@ +{ + "TUNNEL_LOAD_NORMAL": { + "sonic-peer-switch:sonic-peer-switch": { + "sonic-peer-switch:PEER_SWITCH": { + "PEER_SWITCH_LIST": [ + { + "peer_switch": "vlab-05", + "address_ipv4": "10.1.0.33" + } + ] + } + }, + "sonic-dscp-tc-map:sonic-dscp-tc-map": { + "sonic-dscp-tc-map:DSCP_TO_TC_MAP": { + "DSCP_TO_TC_MAP_LIST": [ + { + "name": "DecapDscpToTcMap", + "DSCP_TO_TC_MAP": [ + { + "dscp": "1", + "tc": "1" + } + ] + } + ] + } + }, + "sonic-tc-priority-group-map:sonic-tc-priority-group-map": { + "sonic-tc-priority-group-map:TC_TO_PRIORITY_GROUP_MAP": { + "TC_TO_PRIORITY_GROUP_MAP_LIST": [ + { + "name": "DecapTcToPgMap", + "TC_TO_PRIORITY_GROUP_MAP": [ + { + "tc": "1", + "pg": "1" + } + ] + } + ] + } + }, + "sonic-tc-queue-map:sonic-tc-queue-map": { + "sonic-tc-queue-map:TC_TO_QUEUE_MAP": { + "TC_TO_QUEUE_MAP_LIST": [ + { + "name": "EncapTcToQueueMap", + "TC_TO_QUEUE_MAP": [ + { + "tc": "1", + "qindex": "1" + } + ] + } + ] + } + }, + "sonic-tunnel:sonic-tunnel": { + "sonic-tunnel:TUNNEL": { + "TUNNEL_LIST": [ + { + "mux_tunnel": "MuxTunnel0", + "dscp_mode": "pipe", + "src_ip": "10.1.0.33", + "dst_ip": "10.1.0.32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP", + "decap_dscp_to_tc_map": "DecapDscpToTcMap", + "decap_tc_to_pg_map": "DecapTcToPgMap", + "encap_tc_to_dscp_map": "EncapTcToDscpMap", + "encap_tc_to_queue_map": "EncapTcToQueueMap" + } + ] + } + } + }, + + "TUNNEL_INVALID_ADDR": { + "sonic-tunnel:sonic-tunnel": { + "sonic-tunnel:TUNNEL": { + "TUNNEL_LIST": [ + { + "mux_tunnel": "MuxTunnel0", + "dscp_mode": "pipe", + "dst_ip": "10.1.0.33/32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP" + } + ] + } + } + }, + + "TUNNEL_SRC_IP_NOT_PEER_SWITCH": { + "sonic-peer-switch:sonic-peer-switch": { + "sonic-peer-switch:PEER_SWITCH": { + "PEER_SWITCH_LIST": [ + { + "peer_switch": "vlab-05", + "address_ipv4": "10.1.0.33" + } + ] + } + }, + "sonic-tunnel:sonic-tunnel": { + "sonic-tunnel:TUNNEL": { + "TUNNEL_LIST": [ + { + "mux_tunnel": "MuxTunnel0", + "dscp_mode": "pipe", + "dst_ip": "10.1.0.32", + "src_ip": "10.1.0.32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP" + } + ] + } + } + }, + + "TUNNEL_MISSING_MUX_TUNNEL": { + "sonic-tunnel:sonic-tunnel": { + "sonic-tunnel:TUNNEL": { + "TUNNEL_LIST": [ + { + "dscp_mode": "pipe", + "dst_ip": "10.1.0.32", + "ecn_mode": "standard", + "encap_ecn_mode": "standard", + "ttl_mode": "pipe", + "tunnel_type": "IPINIP" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-tunnel.yang b/src/sonic-yang-models/yang-models/sonic-tunnel.yang new file mode 100644 index 000000000000..e0e20ec8df2a --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-tunnel.yang @@ -0,0 +1,122 @@ +module sonic-tunnel { + yang-version 1.1; + namespace "http://github.com/sonic-net/sonic-tunnel"; + prefix tunnel; + + import ietf-inet-types { + prefix inet; + } + + import sonic-peer-switch { + prefix ps; + } + + import sonic-dscp-tc-map { + prefix dtm; + } + + import sonic-tc-priority-group-map { + prefix tpgm; + } + + import sonic-tc-queue-map { + prefix tqm; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONiC DualToR tunnel data"; + + revision 2022-08-23 { + description + "Initial revision"; + } + + container sonic-tunnel { + container TUNNEL { + description "TUNNEL configuration for SONiC Dual-ToR"; + list TUNNEL_LIST { + key "mux_tunnel"; + + leaf mux_tunnel { + description "Name of MuxTunnel"; + type string { + pattern "MuxTunnel[0-9]+"; + } + } + + leaf dscp_mode { + description "DSCP mode"; + type string { + pattern "uniform|pipe"; + } + } + + leaf src_ip { + description "source IPv4 address off the tunnel. Must be SONiC DualToR peer IPv4 address."; + type leafref { + path "/ps:sonic-peer-switch/ps:PEER_SWITCH/ps:PEER_SWITCH_LIST/ps:address_ipv4"; + } + } + + leaf dst_ip { + description "IPv4 address of this switch."; + type inet:ipv4-address; + } + + leaf ecn_mode { + description "ECN mode"; + type string { + pattern "copy_from_outer|standard"; + } + } + + leaf encap_ecn_mode { + description "Encap ECN mode"; + type string { + pattern "standard"; + } + } + + leaf ttl_mode { + description "TTL mode"; + type string { + pattern "uniform|pipe"; + } + } + + leaf tunnel_type { + description "Tunnel type"; + type string { + pattern "IPINIP"; + } + } + + leaf decap_dscp_to_tc_map { + description "Decap DSCP to TC map"; + type string; + } + + leaf decap_tc_to_pg_map { + description "Decap TC to PG map"; + type string; + } + + leaf encap_tc_to_dscp_map { + description "Encap TC to DSCP map"; + type string; + } + + leaf encap_tc_to_queue_map { + description "Encap TC to Queue map"; + type string; + } + } + } + } +}