Skip to content

Commit

Permalink
Interface and Ethernet Counter support (#139)
Browse files Browse the repository at this point in the history
* Adding transformer support for OC yang intf.

Co-authored-by: Satoru-Shinohara <satoru.shinohara@dell.com>
Co-authored-by: Nikita Agarwal <nikita_agarwal1@dell.com>

* Adding fix for sanity check errors.

Co-authored-by: Satoru-Shinohara <satoru.shinohara@dell.com>
Co-authored-by: Nikita Agarwal <nikita_agarwal1@dell.com>

* Adding dbinit.py to azure-pipelines.yml

* Addressing review comments.

* Addressing review comments for subinterfaces.

* Adding go.mod file.

* interface and ethernet counters REST GET support (#30)

* add support for counters - top level and ethernet

* Code Clean-up

* Add subscription support for interface and ethernet counters

* Update test-cases to support interface and ethernet state counters

* Remove state related tests as azure-pipelines do not support them.  (#32)

* add support for counters - top level and ethernet

* Code Clean-up

* Add subscription support for interface and ethernet counters

* Update test-cases to support interface and ethernet state counters

* address azure-pipelines error

---------

Co-authored-by: Nikita Agarwal <55811498+nagarwal03@users.noreply.github.com>
Co-authored-by: Nikita Agarwal <nikita_agarwal1@dell.com>
  • Loading branch information
3 people committed May 20, 2024
1 parent 328d806 commit 1e12744
Show file tree
Hide file tree
Showing 4 changed files with 526 additions and 23 deletions.
16 changes: 16 additions & 0 deletions models/yang/annotations/openconfig-interfaces-annot.yang
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ module openconfig-interfaces-annot {
sonic-ext:field-name "admin_status";
}
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters {
deviate add {
sonic-ext:subtree-transformer "intf_get_counters_xfmr";
sonic-ext:db-name "COUNTERS_DB";
sonic-ext:subscribe-on-change "disable";
}
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters {
deviate add {
sonic-ext:db-name "COUNTERS_DB";
sonic-ext:subtree-transformer "intf_get_ether_counters_xfmr";
sonic-ext:subscribe-on-change "disable";
}
}

deviation /oc-intf:interfaces {
deviate add {
Expand Down
58 changes: 49 additions & 9 deletions models/yang/extensions/openconfig-interfaces-deviation.yang
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ module openconfig-interfaces-deviation {

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:last-change {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters {
deviate not-supported;
}
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:type {
deviate not-supported;
Expand All @@ -77,6 +73,22 @@ module openconfig-interfaces-deviation {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters/oc-intf:in-unknown-protos {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters/oc-intf:in-fcs-errors {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters/oc-intf:carrier-transitions {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:state/oc-intf:counters/oc-intf:last-clear {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-intf:hold-time {
deviate not-supported;
}
Expand Down Expand Up @@ -227,10 +239,6 @@ module openconfig-interfaces-deviation {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-lag:aggregate-id {
deviate not-supported;
}
Expand All @@ -247,6 +255,38 @@ module openconfig-interfaces-deviation {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:in-mac-control-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:in-mac-pause-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:in-8021q-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:in-crc-errors {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:in-block-errors {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:out-mac-control-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:out-mac-pause-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-eth:state/oc-eth:counters/oc-eth:out-8021q-frames {
deviate not-supported;
}

deviation /oc-intf:interfaces/oc-intf:interface/oc-eth:ethernet/oc-vlan:switched-vlan {
deviate not-supported;
}
Expand Down
16 changes: 8 additions & 8 deletions translib/transformer/interfaces_openconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Test_openconfig_interfaces(t *testing.T) {

t.Log("\n\n--- Verify PATCH interface leaf nodes ---")
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/state"
expected_get_json = "{\"openconfig-interfaces:state\": { \"admin-status\": \"UP\", \"enabled\": true, \"mtu\": 9000, \"name\": \"Ethernet0\"}}"
expected_get_json = "{\"openconfig-interfaces:state\": { \"admin-status\": \"UP\", \"counters\": {\"in-broadcast-pkts\": \"0\", \"in-discards\": \"0\", \"in-errors\": \"0\", \"in-multicast-pkts\": \"0\", \"in-octets\": \"0\", \"in-pkts\": \"0\", \"in-unicast-pkts\": \"0\", \"out-broadcast-pkts\": \"0\", \"out-discards\": \"0\", \"out-errors\": \"0\", \"out-multicast-pkts\": \"0\", \"out-octets\": \"0\", \"out-pkts\": \"0\", \"out-unicast-pkts\": \"0\"}, \"enabled\": true, \"mtu\": 9000, \"name\": \"Ethernet0\"}}"
t.Run("Test GET on interface state", processGetRequest(url, nil, expected_get_json, false))
time.Sleep(1 * time.Second)

Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_openconfig_interfaces(t *testing.T) {

t.Log("\n\n--- Verify PATCH interface ---")
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/state"
expected_get_json = "{\"openconfig-interfaces:state\": { \"admin-status\": \"UP\", \"enabled\": true, \"mtu\": 9100, \"name\": \"Ethernet0\"}}"
expected_get_json = "{\"openconfig-interfaces:state\": { \"admin-status\": \"UP\", \"counters\": {\"in-broadcast-pkts\": \"0\", \"in-discards\": \"0\", \"in-errors\": \"0\", \"in-multicast-pkts\": \"0\", \"in-octets\": \"0\", \"in-pkts\": \"0\", \"in-unicast-pkts\": \"0\", \"out-broadcast-pkts\": \"0\", \"out-discards\": \"0\", \"out-errors\": \"0\", \"out-multicast-pkts\": \"0\", \"out-octets\": \"0\", \"out-pkts\": \"0\", \"out-unicast-pkts\": \"0\"}, \"enabled\": true, \"mtu\": 9100, \"name\": \"Ethernet0\"}}"
t.Run("Test GET on interface state", processGetRequest(url, nil, expected_get_json, false))
time.Sleep(1 * time.Second)

Expand All @@ -149,12 +149,12 @@ func Test_openconfig_ethernet(t *testing.T) {

cleanuptbl := map[string]interface{}{"PORT_TABLE": map[string]interface{}{"Ethernet0": ""}}
unloadDB(db.ApplDB, cleanuptbl)
pre_req_map := map[string]interface{}{"PORT_TABLE": map[string]interface{}{"Ethernet0": map[string]interface{}{"admin_status": "up", "autoneg": "on", "mtu": "9100", "speed": "40000"}}}
pre_req_map := map[string]interface{}{"PORT_TABLE": map[string]interface{}{"Ethernet0": map[string]interface{}{"admin_status": "up", "autoneg": "on", "mtu": "9100", "speed": "40000", "counters": map[string]interface{}{"in-broadcast-pkts": "0", "in-discards": "0", "in-errors": "0", "in-multicast-pkts": "0", "in-octets": "0", "in-pkts": "0", "in-unicast-pkts": "0", "out-broadcast-pkts": "0", "out-discards": "0", "out-errors": "0", "out-multicast-pkts": "0", "out-octets": "0", "out-pkts": "0", "out-unicast-pkts": "0"}}}}
loadDB(db.ApplDB, pre_req_map)

t.Log("\n\n--- Verify PATCH ethernet ---")
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/openconfig-if-ethernet:ethernet"
expected_get_json := "{\"openconfig-if-ethernet:ethernet\": {\"config\": {\"auto-negotiate\": true,\"port-speed\": \"openconfig-if-ethernet:SPEED_40GB\"},\"state\": {\"auto-negotiate\": true,\"port-speed\": \"openconfig-if-ethernet:SPEED_40GB\"}}}"
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/openconfig-if-ethernet:ethernet/config"
expected_get_json := "{\"openconfig-if-ethernet:config\": {\"auto-negotiate\": true,\"port-speed\": \"openconfig-if-ethernet:SPEED_40GB\"}}"
t.Run("Test GET on ethernet", processGetRequest(url, nil, expected_get_json, false))
time.Sleep(1 * time.Second)

Expand All @@ -171,9 +171,9 @@ func Test_openconfig_ethernet(t *testing.T) {
time.Sleep(1 * time.Second)

t.Log("\n\n--- Verify DELETE at ethernet container ---")
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/openconfig-if-ethernet:ethernet/state"
expected_get_json = "{\"openconfig-if-ethernet:state\": {\"auto-negotiate\": true, \"port-speed\": \"openconfig-if-ethernet:SPEED_40GB\"}}"
t.Run("Test GET on ethernet state", processGetRequest(url, nil, expected_get_json, false))
url = "/openconfig-interfaces:interfaces/interface[name=Ethernet0]/openconfig-if-ethernet:ethernet/config"
expected_get_json = "{\"openconfig-if-ethernet:config\": {\"auto-negotiate\": true,\"port-speed\": \"openconfig-if-ethernet:SPEED_40GB\"}}"
t.Run("Test GET on ethernet", processGetRequest(url, nil, expected_get_json, false))
time.Sleep(1 * time.Second)

t.Log("\n\n--- DELETE at ethernet auto-negotiate ---")
Expand Down
Loading

0 comments on commit 1e12744

Please sign in to comment.