VOL-1381 and VOL-1091 Add feature to collect PMmetrics of OLT, this will collect Tx and Rx and posts to kafka. This commit is also related to changes of commit 72b25abd4e804596413558ef10f098c2262dd65d voltha-go
Updated review comments
Updated with code optimization
Updated with dep files
Updated fix for sanity test
Updated with gomod changes
Change-Id: I899e855812a6eda812c64664a9154321cdb16876
diff --git a/adaptercore/device_handler_test.go b/adaptercore/device_handler_test.go
index 6e94215..924430d 100644
--- a/adaptercore/device_handler_test.go
+++ b/adaptercore/device_handler_test.go
@@ -22,6 +22,9 @@
"net"
"reflect"
"testing"
+ "time"
+
+ "github.com/opencord/voltha-lib-go/v2/pkg/pmmetrics"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
@@ -43,6 +46,7 @@
func newMockCoreProxy() *mocks.MockCoreProxy {
mcp := mocks.MockCoreProxy{}
mcp.Devices = make(map[string]*voltha.Device)
+ var pm []*voltha.PmConfig
mcp.Devices["olt"] = &voltha.Device{
Id: "olt",
@@ -61,6 +65,13 @@
ChannelGroupId: 1,
},
ConnectStatus: 1,
+ PmConfigs: &voltha.PmConfigs{
+ DefaultFreq: 10,
+ Id: "olt",
+ FreqOverride: false,
+ Grouped: false,
+ Metrics: pm,
+ },
}
mcp.Devices["onu1"] = &voltha.Device{
@@ -80,6 +91,13 @@
ChannelGroupId: 1,
},
ConnectStatus: 1,
+ PmConfigs: &voltha.PmConfigs{
+ DefaultFreq: 10,
+ Id: "olt",
+ FreqOverride: false,
+ Grouped: false,
+ Metrics: pm,
+ },
}
mcp.Devices["onu2"] = &voltha.Device{
Id: "2",
@@ -99,6 +117,13 @@
ChannelGroupId: 1,
},
ConnectStatus: 1,
+ PmConfigs: &voltha.PmConfigs{
+ DefaultFreq: 10,
+ Id: "olt",
+ FreqOverride: false,
+ Grouped: false,
+ Metrics: pm,
+ },
}
return &mcp
}
@@ -131,6 +156,8 @@
dh.Client = &mocks.MockOpenoltClient{}
dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}}
dh.transitionMap = &TransitionMap{}
+ dh.portStats = &OpenOltStatisticsMgr{}
+ dh.metrics = &pmmetrics.PmMetrics{}
return dh
}
@@ -701,7 +728,7 @@
}{
// TODO: Add test cases.
{"AdoptDevice-1", dh1, args{device: dh1.device}},
- {"AdoptDevice-1", dh2, args{device: dh2.device}},
+ {"AdoptDevice-2", dh2, args{device: dh2.device}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -985,3 +1012,33 @@
})
}
}
+
+func Test_startCollector(t *testing.T) {
+ type args struct {
+ dh *DeviceHandler
+ }
+ dh := newMockDeviceHandler()
+ dh.portStats.NorthBoundPort = make(map[uint32]*NniPort)
+ dh.portStats.NorthBoundPort[0] = &NniPort{Name: "OLT-1"}
+ dh.portStats.SouthBoundPort = make(map[uint32]*PonPort)
+ dh.portStats.Device = dh
+ for i := 0; i < 16; i++ {
+ dh.portStats.SouthBoundPort[uint32(i)] = &PonPort{DeviceID: "OLT-1"}
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ // TODO: Add test cases.
+ {"StartCollector-1", args{dh}},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ go func() {
+ time.Sleep(2 * time.Minute)
+ tt.args.dh.stopCollector <- true
+ }()
+ startCollector(tt.args.dh)
+ })
+ }
+}