From f3b7a5e47af2dbb6a49b53fef56bc73e41cbf431 Mon Sep 17 00:00:00 2001 From: Koren Lev Date: Thu, 6 Dec 2018 10:51:18 +0200 Subject: vpp_if_stats: Fixing a bug in getting vpp interfaces indexes Change-Id: I6290945a94b4f7878e9af94cc7daec455327482e Signed-off-by: Koren Lev --- extras/vpp_if_stats/vpp_if_stats.go | 10 +++++----- extras/vpp_if_stats/vpp_if_stats_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) mode change 100755 => 100644 extras/vpp_if_stats/vpp_if_stats.go mode change 100755 => 100644 extras/vpp_if_stats/vpp_if_stats_test.go (limited to 'extras/vpp_if_stats') diff --git a/extras/vpp_if_stats/vpp_if_stats.go b/extras/vpp_if_stats/vpp_if_stats.go old mode 100755 new mode 100644 index 48ce0853d1e..90c1700430c --- a/extras/vpp_if_stats/vpp_if_stats.go +++ b/extras/vpp_if_stats/vpp_if_stats.go @@ -117,9 +117,9 @@ func (v *vppConnector) reduceCombinedCounters(stat *adapter.StatEntry) *[]adapte counters := stat.Data.(adapter.CombinedCounterStat) stats := make([]adapter.CombinedCounter, len(v.Interfaces)) for _, workerStats := range counters { - for i, interfaceStats := range workerStats { - stats[i].Bytes += interfaceStats.Bytes - stats[i].Packets += interfaceStats.Packets + for i := 0; i < len(v.Interfaces); i++ { + stats[i].Bytes += workerStats[i].Bytes + stats[i].Packets += workerStats[i].Packets } } return &stats @@ -129,8 +129,8 @@ func (v *vppConnector) reduceSimpleCounters(stat *adapter.StatEntry) *[]adapter. counters := stat.Data.(adapter.SimpleCounterStat) stats := make([]adapter.Counter, len(v.Interfaces)) for _, workerStats := range counters { - for i, interfaceStats := range workerStats { - stats[i] += interfaceStats + for i := 0; i < len(v.Interfaces); i++ { + stats[i] += workerStats[i] } } return &stats diff --git a/extras/vpp_if_stats/vpp_if_stats_test.go b/extras/vpp_if_stats/vpp_if_stats_test.go old mode 100755 new mode 100644 index 07a598364af..3c22ce85d75 --- a/extras/vpp_if_stats/vpp_if_stats_test.go +++ b/extras/vpp_if_stats/vpp_if_stats_test.go @@ -25,9 +25,9 @@ var ( Stats: interfaceStats{}, // TODO } } - testInterfaces = func() *map[uint32]*vppInterface { - return &map[uint32]*vppInterface{ - testSwIfIndex: testInterface(), + testInterfaces = func() []*vppInterface { + return []*vppInterface{ + testInterface(), } } @@ -164,7 +164,7 @@ func TestVppIfStats_GetStatsForAllInterfacesNoStats(t *testing.T) { mockStatsAPI := NewMockStatsAPI(mockCtrl) mockStatsAPI.EXPECT().DumpStats("/if").Return([]*adapter.StatEntry{}, nil) - v := vppConnector{stats: mockStatsAPI, Interfaces: *testInterfaces()} + v := vppConnector{stats: mockStatsAPI, Interfaces: testInterfaces()} err := v.getStatsForAllInterfaces() assert.NoError(t, err, "GetStatsForAllInterfaces should not return an error") assert.Equal(t, interfaceStats{}, v.Interfaces[testSwIfIndex].Stats, "Stats should be empty") @@ -177,7 +177,7 @@ func testStats(t *testing.T, statsDump *[]*adapter.StatEntry, expectedStats *int mockStatsAPI := NewMockStatsAPI(mockCtrl) mockStatsAPI.EXPECT().DumpStats("/if").Return(*statsDump, nil) - v := vppConnector{stats: mockStatsAPI, Interfaces: *testInterfaces()} + v := vppConnector{stats: mockStatsAPI, Interfaces: testInterfaces()} err := v.getStatsForAllInterfaces() assert.NoError(t, err, "GetStatsForAllInterfaces should not return an error") assert.Equal(t, *expectedStats, v.Interfaces[testSwIfIndex].Stats, "Collected and saved stats should match") -- cgit 1.2.3-korg