From 88301b3fdc89ff3ae7aa924c4828910f7f94d772 Mon Sep 17 00:00:00 2001
From: kenneth-arista <93353051+kenneth-arista@users.noreply.github.com>
Date: Thu, 2 Feb 2023 10:19:30 -0800
Subject: [PATCH] [yang-models] Add YANG model for SYSTEM_PORT (#12689)
Add YANG model for SYSTEM_PORT.
Resolves https://github.com/sonic-net/sonic-buildimage/issues/12458
YANG model for SYSTEM_PORT in CONFIG_DB was missing.
Added new YANG model and associated unit tests.
Passing unit tests
---
.../tests/sample-voq-graph.xml | 16 ++--
src/sonic-config-engine/tests/test_cfggen.py | 16 ++--
src/sonic-yang-models/doc/Configuration.md | 44 +++++++++
src/sonic-yang-models/setup.py | 2 +
.../tests/files/sample_config_db.json | 74 +++++++++++++++
.../yang_model_tests/tests/system_port.json | 9 ++
.../tests_config/system_port.json | 91 ++++++++++++++++++
.../yang-models/sonic-system-port.yang | 95 +++++++++++++++++++
8 files changed, 331 insertions(+), 16 deletions(-)
create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/system_port.json
create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/system_port.json
create mode 100644 src/sonic-yang-models/yang-models/sonic-system-port.yang
diff --git a/src/sonic-config-engine/tests/sample-voq-graph.xml b/src/sonic-config-engine/tests/sample-voq-graph.xml
index b152d74df8a8..b6e8ff1521a0 100644
--- a/src/sonic-config-engine/tests/sample-voq-graph.xml
+++ b/src/sonic-config-engine/tests/sample-voq-graph.xml
@@ -619,7 +619,7 @@
8
- Ethernet1/1
+ Ethernet0
linecard-1
Asic0
40000
@@ -630,7 +630,7 @@
8
- Ethernet1/2
+ Ethernet4
linecard-1
Asic0
40000
@@ -641,7 +641,7 @@
8
- Ethernet1/3
+ Ethernet8
linecard-1
Asic0
40000
@@ -652,7 +652,7 @@
8
- Ethernet1/4
+ Ethernet12
linecard-1
Asic0
40000
@@ -675,7 +675,7 @@
8
- Ethernet1/5
+ Ethernet0
linecard-2
Asic0
40000
@@ -686,7 +686,7 @@
8
- Ethernet1/6
+ Ethernet4
linecard-2
Asic0
40000
@@ -709,7 +709,7 @@
8
- Ethernet1/7
+ Ethernet8
linecard-2
Asic1
40000
@@ -720,7 +720,7 @@
8
- Ethernet1/8
+ Ethernet12
linecard-2
Asic1
40000
diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py
index 15950cdf61a5..94985748baf2 100644
--- a/src/sonic-config-engine/tests/test_cfggen.py
+++ b/src/sonic-config-engine/tests/test_cfggen.py
@@ -914,16 +914,16 @@ def test_minigraph_voq_system_ports(self):
json.loads(self.run_script(argument)),
{
"linecard-1|Asic0|Cpu0": { "core_port_index": "0", "num_voq": "8", "switch_id": "0", "speed": "1000", "core_index": "0", "system_port_id": "1" },
- "linecard-1|Asic0|Ethernet1/1": { "core_port_index": "1", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "0", "system_port_id": "2" },
- "linecard-1|Asic0|Ethernet1/2": { "core_port_index": "2", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "0", "system_port_id": "3" },
- "linecard-1|Asic0|Ethernet1/3": { "core_port_index": "3", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "1", "system_port_id": "4" },
- "linecard-1|Asic0|Ethernet1/4": { "core_port_index": "4", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "1", "system_port_id": "5" },
+ "linecard-1|Asic0|Ethernet0": { "core_port_index": "1", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "0", "system_port_id": "2" },
+ "linecard-1|Asic0|Ethernet4": { "core_port_index": "2", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "0", "system_port_id": "3" },
+ "linecard-1|Asic0|Ethernet8": { "core_port_index": "3", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "1", "system_port_id": "4" },
+ "linecard-1|Asic0|Ethernet12": { "core_port_index": "4", "num_voq": "8", "switch_id": "0", "speed": "40000", "core_index": "1", "system_port_id": "5" },
"linecard-2|Asic0|Cpu0": { "core_port_index": "0", "num_voq": "8", "switch_id": "2", "speed": "1000", "core_index": "0", "system_port_id": "256" },
- "linecard-2|Asic0|Ethernet1/5": { "core_port_index": "1", "num_voq": "8", "switch_id": "2", "speed": "40000", "core_index": "0", "system_port_id": "257" },
- "linecard-2|Asic0|Ethernet1/6": { "core_port_index": "2", "num_voq": "8", "switch_id": "2", "speed": "40000", "core_index": "1", "system_port_id": "258" },
+ "linecard-2|Asic0|Ethernet0": { "core_port_index": "1", "num_voq": "8", "switch_id": "2", "speed": "40000", "core_index": "0", "system_port_id": "257" },
+ "linecard-2|Asic0|Ethernet4": { "core_port_index": "2", "num_voq": "8", "switch_id": "2", "speed": "40000", "core_index": "1", "system_port_id": "258" },
"linecard-2|Asic1|Cpu0": { "core_port_index": "0", "num_voq": "8", "switch_id": "4", "speed": "1000", "core_index": "0", "system_port_id": "259" },
- "linecard-2|Asic1|Ethernet1/7": { "core_port_index": "1", "num_voq": "8", "switch_id": "4", "speed": "40000", "core_index": "0", "system_port_id": "260" },
- "linecard-2|Asic1|Ethernet1/8": { "core_port_index": "2", "num_voq": "8", "switch_id": "4", "speed": "40000", "core_index": "1", "system_port_id": "261" }
+ "linecard-2|Asic1|Ethernet8": { "core_port_index": "1", "num_voq": "8", "switch_id": "4", "speed": "40000", "core_index": "0", "system_port_id": "260" },
+ "linecard-2|Asic1|Ethernet12": { "core_port_index": "2", "num_voq": "8", "switch_id": "4", "speed": "40000", "core_index": "1", "system_port_id": "261" }
}
)
diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md
index da6f1e2173ea..562ef837acac 100644
--- a/src/sonic-yang-models/doc/Configuration.md
+++ b/src/sonic-yang-models/doc/Configuration.md
@@ -54,6 +54,7 @@ Table of Contents
* [Queue](#queue)
* [Sflow](#sflow)
* [Restapi](#restapi)
+ * [System Port](#system-port)
* [Tacplus Server](#tacplus-server)
* [TC to Priority group map](#tc-to-priority-group-map)
* [TC to Queue map](#tc-to-queue-map)
@@ -1616,6 +1617,49 @@ Container side configuration:
}
```
+### System Port
+Every port on the system requires a global representation, known as a System Port,
+and is listed in this table.
+
+```
+{
+"SYSTEM_PORT": {
+ "host227-4|asic0|Ethernet0": {
+ "core_index": "1",
+ "core_port_index": "1",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "0",
+ "system_port_id": "1"
+ },
+ "host227-4|asic0|Ethernet4": {
+ "core_index": "1",
+ "core_port_index": "2",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "0",
+ "system_port_id": "2"
+ },
+ "host227-5|asic0|Ethernet0": {
+ "core_index": "1",
+ "core_port_index": "1",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "4",
+ "system_port_id": "80"
+ },
+ "host227-5|asic0|Ethernet4": {
+ "core_index": "1",
+ "core_port_index": "2",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "4",
+ "system_port_id": "81"
+ }
+ }
+}
+```
+
### Tacplus Server
```
diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py
index 986a5635c548..da8214387060 100644
--- a/src/sonic-yang-models/setup.py
+++ b/src/sonic-yang-models/setup.py
@@ -165,6 +165,7 @@ def run(self):
'./yang-models/sonic-pfc-priority-queue-map.yang',
'./yang-models/sonic-pfc-priority-priority-group-map.yang',
'./yang-models/sonic-port-qos-map.yang',
+ './yang-models/sonic-system-port.yang',
'./yang-models/sonic-macsec.yang']),
('cvlyang-models', ['./cvlyang-models/sonic-acl.yang',
'./cvlyang-models/sonic-bgp-common.yang',
@@ -224,6 +225,7 @@ def run(self):
'./cvlyang-models/sonic-pfc-priority-queue-map.yang',
'./cvlyang-models/sonic-pfc-priority-priority-group-map.yang',
'./cvlyang-models/sonic-port-qos-map.yang',
+ './cvlyang-models/sonic-system-port.yang',
'./cvlyang-models/sonic-macsec.yang']),
],
zip_safe=False,
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 c2d76a7ded5e..16b652fb23b0 100644
--- a/src/sonic-yang-models/tests/files/sample_config_db.json
+++ b/src/sonic-yang-models/tests/files/sample_config_db.json
@@ -1280,6 +1280,80 @@
"login": "local"
}
},
+ "SYSTEM_PORT": {
+ "host227-4|asic0|Cpu0": {
+ "core_index": "0",
+ "core_port_index": "0",
+ "num_voq": "8",
+ "speed": "10000",
+ "switch_id": "0",
+ "system_port_id": "1"
+ },
+ "host227-4|asic0|Ethernet0": {
+ "core_index": "1",
+ "core_port_index": "1",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "0",
+ "system_port_id": "2"
+ },
+ "host227-4|asic0|Ethernet4": {
+ "core_index": "1",
+ "core_port_index": "2",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "0",
+ "system_port_id": "3"
+ },
+ "host227-4|asic1|Cpu0": {
+ "core_index": "0",
+ "core_port_index": "0",
+ "num_voq": "8",
+ "speed": "10000",
+ "switch_id": "0",
+ "system_port_id": "41"
+ },
+ "host227-4|asic1|Ethernet8": {
+ "core_index": "0",
+ "core_port_index": "1",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "2",
+ "system_port_id": "42"
+ },
+ "host227-4|asic1|Ethernet12": {
+ "core_index": "0",
+ "core_port_index": "2",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "2",
+ "system_port_id": "43"
+ },
+ "host227-5|asic0|Cpu0": {
+ "core_index": "0",
+ "core_port_index": "0",
+ "num_voq": "8",
+ "speed": "10000",
+ "switch_id": "0",
+ "system_port_id": "81"
+ },
+ "host227-5|asic0|Ethernet0": {
+ "core_index": "1",
+ "core_port_index": "1",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "4",
+ "system_port_id": "82"
+ },
+ "host227-5|asic0|Ethernet4": {
+ "core_index": "1",
+ "core_port_index": "2",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "4",
+ "system_port_id": "83"
+ }
+ },
"TACPLUS": {
"global": {
"auth_type": "pap",
diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/system_port.json b/src/sonic-yang-models/tests/yang_model_tests/tests/system_port.json
new file mode 100644
index 000000000000..727373ade25a
--- /dev/null
+++ b/src/sonic-yang-models/tests/yang_model_tests/tests/system_port.json
@@ -0,0 +1,9 @@
+{
+ "SYSTEM_PORT_POSITIVE_CONFIG": {
+ "desc": "Configure SYSTEM_PORT positive config."
+ },
+ "SYSTEM_PORT_WRONG_SPEED_PATTERN": {
+ "desc": "Configure SYSTEM_PORT wrong speed.",
+ "eStr": ["pattern", "does not satisfy"]
+ }
+}
diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_port.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_port.json
new file mode 100644
index 000000000000..28edae5727a1
--- /dev/null
+++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_port.json
@@ -0,0 +1,91 @@
+{
+ "SYSTEM_PORT_POSITIVE_CONFIG": {
+ "sonic-port:sonic-port": {
+ "sonic-port:PORT": {
+ "PORT_LIST": [
+ {
+ "admin_status": "up",
+ "alias": "eth0",
+ "description": "Ethernet0",
+ "lanes": "65",
+ "mtu": 9000,
+ "name": "Ethernet0",
+ "speed": 100000
+ },
+ {
+ "admin_status": "up",
+ "alias": "eth4",
+ "description": "Ethernet4",
+ "lanes": "65",
+ "mtu": 9000,
+ "name": "Ethernet4",
+ "speed": 100000
+ }
+ ]
+ }
+ },
+ "sonic-system-port:sonic-system-port": {
+ "sonic-system-port:SYSTEM_PORT": {
+ "SYSTEM_PORT_LIST": [
+ {
+ "hostname": "host123",
+ "asic_name": "asic0",
+ "ifname": "Ethernet0",
+ "core_index": "0",
+ "core_port_index": "10",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "0",
+ "system_port_id": "100"
+ },
+ {
+ "hostname": "host123",
+ "asic_name": "asic1",
+ "ifname": "Ethernet4",
+ "core_index": "1",
+ "core_port_index": "20",
+ "num_voq": "8",
+ "speed": "100000",
+ "switch_id": "1",
+ "system_port_id": "200"
+ }
+ ]
+ }
+ }
+ },
+ "SYSTEM_PORT_WRONG_SPEED_PATTERN": {
+ "sonic-port:sonic-port": {
+ "sonic-port:PORT": {
+ "PORT_LIST": [
+ {
+ "admin_status": "up",
+ "alias": "eth0",
+ "description": "Ethernet0",
+ "lanes": "65",
+ "mtu": 9000,
+ "name": "Ethernet0",
+ "speed": 100000
+ }
+ ]
+ }
+ },
+ "sonic-system-port:sonic-system-port": {
+ "sonic-system-port:SYSTEM_PORT": {
+ "SYSTEM_PORT_LIST": [
+ {
+ "hostname": "host456",
+ "asic_name": "asic0",
+ "ifname": "Ethernet0",
+ "core_index": "1",
+ "core_port_index": "20",
+ "num_voq": "8",
+ "speed": "900000",
+ "switch_id": "1",
+ "system_port_id": "200"
+ }
+ ]
+ }
+ }
+ }
+
+}
diff --git a/src/sonic-yang-models/yang-models/sonic-system-port.yang b/src/sonic-yang-models/yang-models/sonic-system-port.yang
new file mode 100644
index 000000000000..804b3313fc18
--- /dev/null
+++ b/src/sonic-yang-models/yang-models/sonic-system-port.yang
@@ -0,0 +1,95 @@
+module sonic-system-port {
+
+ yang-version 1.1;
+
+ namespace "http://github.com/sonic-net/sonic-system-port";
+ prefix system-port;
+
+ import sonic-port {
+ prefix port;
+ }
+
+ import sonic-types {
+ prefix stypes;
+ }
+
+ description "SYSTEM_PORT YANG Module for SONiC OS";
+
+ revision 2022-11-10 {
+ description "First Revision";
+ }
+
+ container sonic-system-port {
+
+ container SYSTEM_PORT {
+
+ description "SYSTEM_PORT table of config_db.json";
+
+ list SYSTEM_PORT_LIST {
+
+ key "hostname asic_name ifname";
+
+ leaf hostname {
+ type stypes:hostname;
+ }
+
+ leaf asic_name {
+ type string {
+ pattern "[Aa]sic[0-4]";
+ }
+ }
+
+ leaf ifname {
+ type union {
+ type leafref {
+ path /port:sonic-port/port:PORT/port:PORT_LIST/port:name;
+ }
+ type string {
+ pattern "Cpu0";
+ }
+ }
+ }
+
+ leaf core_index {
+ type uint8 {
+ range 0..7;
+ }
+ description "Hardware core index a port is affiliated with.";
+ }
+
+ leaf core_port_index {
+ type uint16;
+ description "Local port index index to an ASIC core.";
+ }
+
+ leaf num_voq {
+ type uint8 {
+ range 1..8;
+ }
+ description "Number of VoQs associated with a port.";
+ }
+
+ leaf speed {
+ type uint32 {
+ range 1..800000;
+ }
+ description "Port speed in Mbps.";
+ }
+
+ leaf switch_id {
+ type uint16;
+ description "On a VoQ switch, the global ASIC identifier.";
+ }
+
+ leaf system_port_id {
+ type uint32;
+ description "On a VoQ switch, the global port identifier.";
+ }
+ }
+ /* end of list SYSTEM_PORT_LIST */
+ }
+ /* end of container SYSTEM_PORT */
+ }
+ /* end of container sonic-system-port */
+}
+/* end of module sonic-system-port */