Skip to content

Commit

Permalink
gNMI-1.11 add check for monitoring traffic counters per 30 seconds (#…
Browse files Browse the repository at this point in the history
…2150)

* add check for traffic counters per second

* Update import to github.com/openconfig

* updating import

* Update telemetry_interface_packet_counters_test.go

* importing gnmi proto instead

* Greenlight gofmt

* gofmt fix

* update polling time to 30seconds

* fix typo in README

* Adding condition to check with past counter values

* Adding condition to check with past counter values
  • Loading branch information
cfernanz authored Sep 22, 2023
1 parent cfb0998 commit 8b4aeda
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ following features:

* For the parent interface counters in-pkts and out-pkts:

Check the presence of packet counter paths:
Check the presence of packet counter paths and monitor counters every 30 seconds:

* /interfaces/interface[name=<port>]/state/counters/in-pkts
* /interfaces/interface[name=<port>]/state/counters/out-pkts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
otgtelemetry "github.com/openconfig/ondatra/gnmi/otg"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"

gpb "github.com/openconfig/gnmi/proto/gnmi"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -173,6 +175,51 @@ func TestInterfaceCounters(t *testing.T) {
}
}

func validateInAndOutPktsPerSecond(t *testing.T, dut *ondatra.DUTDevice, i1, i2 *interfaces.InterfacePath) bool {
if deviations.InterfaceCountersFromContainer(dut) {
time.Sleep(10 * time.Second)
return true
}
inSamples := gnmi.Collect(t, dut.GNMIOpts().WithYGNMIOpts(ygnmi.WithSubscriptionMode(gpb.SubscriptionMode_SAMPLE), ygnmi.WithSampleInterval(30*time.Second)), i1.Counters().InUnicastPkts().State(), 90*time.Second)
outSamples := gnmi.Collect(t, dut.GNMIOpts().WithYGNMIOpts(ygnmi.WithSubscriptionMode(gpb.SubscriptionMode_SAMPLE), ygnmi.WithSampleInterval(30*time.Second)), i2.Counters().OutUnicastPkts().State(), 90*time.Second)

inPkts := inSamples.Await(t)
outPkts := outSamples.Await(t)

if len(inPkts) < 2 || len(outPkts) < 2 {
t.Fatalf("did not get enough samples: in counters: %s out counters %s",
inPkts, outPkts)
}
t.Logf("Sample Size Incoming Packets: %d, Sample Size Outgoing Packets: %d", len(inPkts), len(outPkts))
var pktCounterOK = true
// check counters for first and last sample interval, they shouldn't be equal
inValFirst, _ := inPkts[0].Val()
outValFirst, _ := outPkts[0].Val()
inValFinal, _ := inPkts[len(inPkts)-1].Val()
outValFinal, _ := outPkts[len(inPkts)-1].Val()

if inValFinal == inValFirst || outValFinal == outValFirst {
t.Logf("Counters not incremented: Initial Incoming Packets: %d, Final Incoming Packets: %d", inValFirst, inValFinal)
t.Logf("Counters not incremented: Initial Outgoing Packets: %d, Final Outgoing Packets: %d", outValFirst, outValFinal)
pktCounterOK = false
return pktCounterOK
}

for i := 1; i < len(inPkts); i++ {
inValOld, _ := inPkts[i-1].Val()
outValOld, _ := outPkts[i-1].Val()
inValLatest, _ := inPkts[i].Val()
outValLatest, _ := outPkts[i].Val()
t.Logf("Incoming Packets: %d, Outgoing Packets: %d", inValLatest, outValLatest)
if inValLatest == inValOld || outValLatest == outValOld || (inValLatest-inValOld != outValLatest-outValOld) {
t.Logf("Comparison with previous iteration: Incoming Packets Delta : %d, Outgoing Packets Delta: %d", inValLatest-inValOld, outValLatest-outValOld)
pktCounterOK = false
break
}
}
return pktCounterOK
}

func fetchInAndOutPkts(t *testing.T, dut *ondatra.DUTDevice, i1, i2 *interfaces.InterfacePath) (map[string]uint64, map[string]uint64) {
// TODO: Replace InUnicastPkts with InPkts and OutUnicastPkts with OutPkts.
if deviations.InterfaceCountersFromContainer(dut) {
Expand Down Expand Up @@ -268,7 +315,9 @@ func TestIntfCounterUpdate(t *testing.T) {
waitOTGARPEntry(t)

otg.StartTraffic(t)
time.Sleep(10 * time.Second)
time.Sleep(2 * time.Second)
// Check incoming and outgoing interface counters updated per second
inAndOutPktsPerSecoundCounterOK := validateInAndOutPktsPerSecond(t, dut, i1, i2)
otg.StopTraffic(t)

// Check interface status is up.
Expand Down Expand Up @@ -337,6 +386,10 @@ func TestIntfCounterUpdate(t *testing.T) {
t.Errorf("Get less outPkts from telemetry: got %v, want >= %v", got, want)
}
}
// Validate per second interface counters are updated
if !inAndOutPktsPerSecoundCounterOK {
t.Error("Interface Packet Counters are not updated per second")
}
}

func ConfigureDUTIntf(t *testing.T, dut *ondatra.DUTDevice) {
Expand Down

0 comments on commit 8b4aeda

Please sign in to comment.