blob: 1a11b9213acff7e1eb59fda596e93ed0a68baf3d [file] [log] [blame]
kdarapu381c6902019-07-31 18:23:16 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu381c6902019-07-31 18:23:16 +053019
20import (
kdarapu891693b2019-09-16 12:33:49 +053021 "context"
kdarapu381c6902019-07-31 18:23:16 +053022 "net"
kdarapu891693b2019-09-16 12:33:49 +053023 "reflect"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053024 "sync"
kdarapu381c6902019-07-31 18:23:16 +053025 "testing"
Naga Manjunath7615e552019-10-11 22:35:47 +053026 "time"
27
kdarapu891693b2019-09-16 12:33:49 +053028 "github.com/golang/protobuf/ptypes"
29 "github.com/golang/protobuf/ptypes/any"
Esin Karamanccb714b2019-11-29 15:02:06 +000030 "github.com/opencord/voltha-lib-go/v3/pkg/db"
31 fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
32 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Kent Hagermane6ff1012020-07-14 15:07:53 -040033 "github.com/opencord/voltha-lib-go/v3/pkg/pmmetrics"
Esin Karamanccb714b2019-11-29 15:02:06 +000034 ponrmgr "github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager"
kesavand494c2082020-08-31 11:16:12 +053035 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053036 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Scott Bakerdbd960e2020-02-28 08:57:51 -080037 "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
38 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
Esin Karamanccb714b2019-11-29 15:02:06 +000039 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
40 of "github.com/opencord/voltha-protos/v3/go/openflow_13"
41 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
42 oop "github.com/opencord/voltha-protos/v3/go/openolt"
43 "github.com/opencord/voltha-protos/v3/go/voltha"
kdarapu381c6902019-07-31 18:23:16 +053044)
45
Girish Gowdra9602eb42020-09-09 15:50:39 -070046const (
47 NumPonPorts = 2
48 OnuIDStart = 1
49 OnuIDEnd = 32
50 AllocIDStart = 1
51 AllocIDEnd = 10
52 GemIDStart = 1
53 GemIDEnd = 10
54 FlowIDStart = 1
55 FlowIDEnd = 10
56)
57
kdarapu891693b2019-09-16 12:33:49 +053058func newMockCoreProxy() *mocks.MockCoreProxy {
Kent Hagermanf1db18b2020-07-08 13:38:15 -040059 mcp := mocks.MockCoreProxy{
60 Devices: make(map[string]*voltha.Device),
61 DevicePorts: make(map[string][]*voltha.Port),
62 }
Naga Manjunath7615e552019-10-11 22:35:47 +053063 var pm []*voltha.PmConfig
kdarapu891693b2019-09-16 12:33:49 +053064 mcp.Devices["olt"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053065 Id: "olt",
66 Root: true,
67 ParentId: "logical_device",
68 ParentPortNo: 1,
kdarapu891693b2019-09-16 12:33:49 +053069 ProxyAddress: &voltha.Device_ProxyAddress{
70 DeviceId: "olt",
71 DeviceType: "onu",
72 ChannelId: 1,
73 ChannelGroupId: 1,
74 },
75 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +053076 PmConfigs: &voltha.PmConfigs{
77 DefaultFreq: 10,
78 Id: "olt",
79 FreqOverride: false,
80 Grouped: false,
81 Metrics: pm,
82 },
kdarapu891693b2019-09-16 12:33:49 +053083 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -040084 mcp.DevicePorts["olt"] = []*voltha.Port{
85 {PortNo: 1, Label: "pon"},
86 {PortNo: 2, Label: "nni"},
87 }
kdarapu891693b2019-09-16 12:33:49 +053088
Kent Hagermanf1db18b2020-07-08 13:38:15 -040089 mcp.Devices["onu1"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053090 Id: "1",
91 Root: false,
92 ParentId: "olt",
93 ParentPortNo: 1,
94
kdarapu891693b2019-09-16 12:33:49 +053095 OperStatus: 4,
96 ProxyAddress: &voltha.Device_ProxyAddress{
97 OnuId: 1,
98 ChannelId: 1,
99 ChannelGroupId: 1,
100 },
101 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530102 PmConfigs: &voltha.PmConfigs{
103 DefaultFreq: 10,
104 Id: "olt",
105 FreqOverride: false,
106 Grouped: false,
107 Metrics: pm,
108 },
kdarapu891693b2019-09-16 12:33:49 +0530109 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400110 mcp.DevicePorts["onu1"] = []*voltha.Port{
111 {PortNo: 1, Label: "pon"},
112 {PortNo: 2, Label: "uni"},
113 }
114
kdarapu891693b2019-09-16 12:33:49 +0530115 mcp.Devices["onu2"] = &voltha.Device{
116 Id: "2",
117 Root: false,
118 ParentId: "olt",
119 OperStatus: 2,
kdarapu891693b2019-09-16 12:33:49 +0530120
121 ParentPortNo: 1,
122
123 ProxyAddress: &voltha.Device_ProxyAddress{
124 OnuId: 2,
125 ChannelId: 1,
126 ChannelGroupId: 1,
127 },
128 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530129 PmConfigs: &voltha.PmConfigs{
130 DefaultFreq: 10,
131 Id: "olt",
132 FreqOverride: false,
133 Grouped: false,
134 Metrics: pm,
135 },
kdarapu891693b2019-09-16 12:33:49 +0530136 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400137 mcp.DevicePorts["onu2"] = []*voltha.Port{
138 {PortNo: 1, Label: "pon"},
139 {PortNo: 2, Label: "uni"},
140 }
kdarapu891693b2019-09-16 12:33:49 +0530141 return &mcp
142}
143func newMockDeviceHandler() *DeviceHandler {
kdarapu381c6902019-07-31 18:23:16 +0530144 device := &voltha.Device{
145 Id: "olt",
146 Root: true,
147 ParentId: "logical_device",
kdarapu891693b2019-09-16 12:33:49 +0530148 ProxyAddress: &voltha.Device_ProxyAddress{
149 DeviceId: "olt",
150 DeviceType: "onu",
151 ChannelId: 1,
152 ChannelGroupId: 1,
153 },
154 ConnectStatus: 1,
kdarapu381c6902019-07-31 18:23:16 +0530155 }
kdarapu891693b2019-09-16 12:33:49 +0530156 cp := newMockCoreProxy()
157 ap := &mocks.MockAdapterProxy{}
158 ep := &mocks.MockEventProxy{}
kesavand494c2082020-08-31 11:16:12 +0530159 cfg := &config.AdapterFlags{OmccEncryption: true}
160 openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep, config: cfg}
kdarapu891693b2019-09-16 12:33:49 +0530161 dh := NewDeviceHandler(cp, ap, ep, device, openOLT)
Girish Gowdra38d533d2020-03-30 20:38:51 -0700162 oopRanges := []*oop.DeviceInfo_DeviceResourceRanges{{
163 IntfIds: []uint32{0, 1},
164 Technology: "xgs-pon",
165 Pools: []*oop.DeviceInfo_DeviceResourceRanges_Pool{{}},
166 }}
167
Girish Gowdra9602eb42020-09-09 15:50:39 -0700168 deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: oopRanges, Model: "openolt", DeviceId: dh.device.Id, PonPorts: NumPonPorts}
Thomas Lee S985938d2020-05-04 11:40:41 +0530169 rsrMgr := resourcemanager.OpenOltResourceMgr{DeviceID: dh.device.Id, DeviceType: dh.device.Type, DevInfo: deviceInf,
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530170 KVStore: &db.Backend{
171 Client: &mocks.MockKVClient{},
172 }}
Girish Gowdra38d533d2020-03-30 20:38:51 -0700173 rsrMgr.AllocIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
174 rsrMgr.GemPortIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
175 rsrMgr.OnuIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
176
177 dh.resourceMgr = &rsrMgr
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530178 dh.resourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
179 ranges := make(map[string]interface{})
180 sharedIdxByType := make(map[string]string)
181 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
182 sharedIdxByType["ONU_ID"] = "ONU_ID"
183 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
184 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
185 ranges["ONU_ID"] = uint32(0)
186 ranges["GEMPORT_ID"] = uint32(0)
187 ranges["ALLOC_ID"] = uint32(0)
188 ranges["FLOW_ID"] = uint32(0)
189 ranges["onu_id_shared"] = uint32(0)
190 ranges["alloc_id_shared"] = uint32(0)
191 ranges["gemport_id_shared"] = uint32(0)
192 ranges["flow_id_shared"] = uint32(0)
193
194 ponmgr := &ponrmgr.PONResourceManager{
195 DeviceID: "onu-1",
Girish Gowdra38d533d2020-03-30 20:38:51 -0700196 IntfIDs: []uint32{0, 1},
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530197 KVStore: &db.Backend{
198 Client: &mocks.MockKVClient{},
199 },
200 PonResourceRanges: ranges,
201 SharedIdxByType: sharedIdxByType,
202 }
Girish Gowdra38d533d2020-03-30 20:38:51 -0700203 dh.resourceMgr.ResourceMgrs[0] = ponmgr
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530204 dh.resourceMgr.ResourceMgrs[1] = ponmgr
npujarec5762e2020-01-01 14:08:48 +0530205 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
206 defer cancel()
Girish Gowdra9602eb42020-09-09 15:50:39 -0700207 dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr)
208 dh.totalPonPorts = NumPonPorts
209 dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts)
210 for i := 0; i < int(dh.totalPonPorts); i++ {
211 // Instantiate flow manager
212 if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr, dh.groupMgr); dh.flowMgr[i] == nil {
213 return nil
214 }
215 }
kdarapu891693b2019-09-16 12:33:49 +0530216 dh.Client = &mocks.MockOpenoltClient{}
kesavand39e0aa32020-01-28 20:58:50 -0500217 dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}, handler: dh}
kdarapu891693b2019-09-16 12:33:49 +0530218 dh.transitionMap = &TransitionMap{}
Naga Manjunath7615e552019-10-11 22:35:47 +0530219 dh.portStats = &OpenOltStatisticsMgr{}
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000220
221 var pmNames = []string{
222 "rx_bytes",
223 "rx_packets",
224 "rx_mcast_packets",
225 "rx_bcast_packets",
226 "tx_bytes",
227 "tx_packets",
228 "tx_mcast_packets",
229 "tx_bcast_packets",
230 }
231
232 dh.metrics = pmmetrics.NewPmMetrics(device.Id, pmmetrics.Frequency(2), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
kdarapu891693b2019-09-16 12:33:49 +0530233 return dh
kdarapu381c6902019-07-31 18:23:16 +0530234}
235
kdarapu891693b2019-09-16 12:33:49 +0530236func negativeDeviceHandler() *DeviceHandler {
237 dh := newMockDeviceHandler()
238 device := dh.device
239 device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530240 return dh
241}
kdarapu381c6902019-07-31 18:23:16 +0530242func Test_generateMacFromHost(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000243 ctx := context.Background()
kdarapu381c6902019-07-31 18:23:16 +0530244 type args struct {
245 host string
246 }
247 tests := []struct {
248 name string
249 args args
250 want string
251 wantErr bool
252 }{
kdarapu891693b2019-09-16 12:33:49 +0530253 {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
254 {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
255 //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false},
256 {"generateMacFromHost-4", args{host: "testing3"}, "", true},
kdarapu381c6902019-07-31 18:23:16 +0530257 }
258 for _, tt := range tests {
259 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000260 got, err := generateMacFromHost(ctx, tt.args.host)
kdarapu381c6902019-07-31 18:23:16 +0530261 if (err != nil) != tt.wantErr {
262 t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr)
263 return
264 }
265 if got != tt.want {
266 t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want)
267 }
268 })
269 }
270}
271func Test_macifyIP(t *testing.T) {
272 type args struct {
273 ip net.IP
274 }
275 tests := []struct {
276 name string
277 args args
278 want string
279 }{{
kdarapu891693b2019-09-16 12:33:49 +0530280 "macifyIP-1",
kdarapu381c6902019-07-31 18:23:16 +0530281 args{ip: net.ParseIP("10.10.10.10")},
282 "00:00:0a:0a:0a:0a",
283 },
284 {
kdarapu891693b2019-09-16 12:33:49 +0530285 "macifyIP-2",
kdarapu381c6902019-07-31 18:23:16 +0530286 args{ip: net.ParseIP("127.0.0.1")},
287 "00:00:7f:00:00:01",
kdarapu891693b2019-09-16 12:33:49 +0530288 },
289 {
290 "macifyIP-3",
291 args{ip: net.ParseIP("127.0.0.1/24")},
292 "",
293 },
294 }
kdarapu381c6902019-07-31 18:23:16 +0530295 for _, tt := range tests {
296 t.Run(tt.name, func(t *testing.T) {
297 if got := macifyIP(tt.args.ip); got != tt.want {
298 t.Errorf("macifyIP() = %v, want %v", got, tt.want)
299 }
300 })
301 }
302}
303
David K. Bainbridge794735f2020-02-11 21:01:37 -0800304func sparseCompare(keys []string, spec, target interface{}) bool {
305 if spec == target {
306 return true
307 }
308 if spec == nil || target == nil {
309 return false
310 }
311 typeSpec := reflect.TypeOf(spec)
312 typeTarget := reflect.TypeOf(target)
313 if typeSpec != typeTarget {
314 return false
315 }
316
317 vSpec := reflect.ValueOf(spec)
318 vTarget := reflect.ValueOf(target)
319 if vSpec.Kind() == reflect.Ptr {
320 vSpec = vSpec.Elem()
321 vTarget = vTarget.Elem()
322 }
323
324 for _, key := range keys {
325 fSpec := vSpec.FieldByName(key)
326 fTarget := vTarget.FieldByName(key)
327 if !reflect.DeepEqual(fSpec.Interface(), fTarget.Interface()) {
328 return false
329 }
330 }
331 return true
332}
333
kdarapu381c6902019-07-31 18:23:16 +0530334func TestDeviceHandler_GetChildDevice(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000335 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530336 dh1 := newMockDeviceHandler()
337 dh2 := negativeDeviceHandler()
kdarapu381c6902019-07-31 18:23:16 +0530338 type args struct {
339 parentPort uint32
340 onuID uint32
341 }
342 tests := []struct {
kdarapu891693b2019-09-16 12:33:49 +0530343 name string
344 devicehandler *DeviceHandler
345 args args
346 want *voltha.Device
David K. Bainbridge794735f2020-02-11 21:01:37 -0800347 errType reflect.Type
kdarapu381c6902019-07-31 18:23:16 +0530348 }{
kdarapu891693b2019-09-16 12:33:49 +0530349 {"GetChildDevice-1", dh1,
350 args{parentPort: 1,
351 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800352 &voltha.Device{
353 Id: "1",
354 ParentId: "olt",
355 ParentPortNo: 1,
356 },
357 nil,
kdarapu891693b2019-09-16 12:33:49 +0530358 },
359 {"GetChildDevice-2", dh2,
kdarapu381c6902019-07-31 18:23:16 +0530360 args{parentPort: 1,
361 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800362 nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530363 reflect.TypeOf(&olterrors.ErrNotFound{}),
kdarapu381c6902019-07-31 18:23:16 +0530364 },
365 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800366
367 /*
368 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-1 (0.00s)
369 device_handler_test.go:309: GetportLabel() => want=(, <nil>) got=(id:"1" parent_id:"olt" parent_port_no:1 proxy_address:<channel_id:1 channel_group_id:1 onu_id:1 > oper_status:ACTIVE connect_status:UNREACHABLE ports:<port_no:1 label:"pon" > ports:<port_no:2 label:"uni" > pm_configs:<id:"olt" default_freq:10 > , <nil>)
370 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-2 (0.00s)
371 */
kdarapu381c6902019-07-31 18:23:16 +0530372 for _, tt := range tests {
373 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000374 got, err := tt.devicehandler.GetChildDevice(ctx, tt.args.parentPort, tt.args.onuID)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800375 if reflect.TypeOf(err) != tt.errType || !sparseCompare([]string{"Id", "ParentId", "ParentPortNo"}, tt.want, got) {
376 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
377 tt.want, tt.errType, got, reflect.TypeOf(err))
378 return
379 }
kdarapu381c6902019-07-31 18:23:16 +0530380 t.Log("onu device id", got)
381 })
382 }
383}
kdarapu891693b2019-09-16 12:33:49 +0530384
385func TestGetportLabel(t *testing.T) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530386 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530387 type args struct {
388 portNum uint32
389 portType voltha.Port_PortType
390 }
391 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800392 name string
393 args args
394 want string
395 errType reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530396 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800397 {"GetportLabel-1", args{portNum: 0, portType: 0}, "", invalid},
398 {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1", nil},
399 {"GetportLabel-3", args{portNum: 2, portType: 2}, "", invalid},
400 {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3", nil},
401 {"GetportLabel-5", args{portNum: 4, portType: 4}, "", invalid},
402 {"GetportLabel-6", args{portNum: 5, portType: 5}, "", invalid},
403 {"GetportLabel-7", args{portNum: 6, portType: 6}, "", invalid},
kdarapu891693b2019-09-16 12:33:49 +0530404 }
405 for _, tt := range tests {
406 t.Run(tt.name, func(t *testing.T) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800407 got, err := GetportLabel(tt.args.portNum, tt.args.portType)
408 if reflect.TypeOf(err) != tt.errType || got != tt.want {
409 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
410 tt.want, tt.errType, got, reflect.TypeOf(err))
kdarapu891693b2019-09-16 12:33:49 +0530411 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800412
kdarapu891693b2019-09-16 12:33:49 +0530413 })
414 }
415}
416
417func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000418 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530419 dh := newMockDeviceHandler()
420 proxyAddr := dh.device.ProxyAddress
421 body := &ic.InterAdapterOmciMessage{
422 Message: []byte("asdfasdfasdfasdfas"),
423 ProxyAddress: proxyAddr,
424 }
425 body2 := &ic.InterAdapterOmciMessage{
426 Message: []byte("asdfasdfasdfasdfas"),
427 //ProxyAddress: &voltha.Device_ProxyAddress{},
428 }
429 body3 := &ic.InterAdapterTechProfileDownloadMessage{}
430 var marshalledData *any.Any
431 var err error
432
433 if marshalledData, err = ptypes.MarshalAny(body); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000434 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530435 }
436
437 var marshalledData1 *any.Any
438
439 if marshalledData1, err = ptypes.MarshalAny(body2); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000440 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530441 }
442 var marshalledData2 *any.Any
443
444 if marshalledData2, err = ptypes.MarshalAny(body3); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000445 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530446 }
447 type args struct {
448 msg *ic.InterAdapterMessage
449 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530450 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530451 tests := []struct {
452 name string
453 args args
David K. Bainbridge794735f2020-02-11 21:01:37 -0800454 wantErr reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530455 }{
456 {"ProcessInterAdapterMessage-1", args{msg: &ic.InterAdapterMessage{
457 Header: &ic.InterAdapterHeader{
458 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800459 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530460 },
461 Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800462 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530463 {"ProcessInterAdapterMessage-2", args{msg: &ic.InterAdapterMessage{
464 Header: &ic.InterAdapterHeader{
465 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800466 Type: ic.InterAdapterMessageType_FLOW_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530467 },
468 Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800469 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530470 {"ProcessInterAdapterMessage-3", args{msg: &ic.InterAdapterMessage{
471 Header: &ic.InterAdapterHeader{
472 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800473 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530474 },
475 Body: marshalledData,
Thomas Lee S94109f12020-03-03 16:39:29 +0530476 }}, reflect.TypeOf(&olterrors.ErrCommunication{})},
kdarapu891693b2019-09-16 12:33:49 +0530477 {"ProcessInterAdapterMessage-4", args{msg: &ic.InterAdapterMessage{
478 Header: &ic.InterAdapterHeader{
479 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800480 Type: ic.InterAdapterMessageType_OMCI_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530481 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800482 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530483 {"ProcessInterAdapterMessage-5", args{msg: &ic.InterAdapterMessage{
484 Header: &ic.InterAdapterHeader{
485 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800486 Type: ic.InterAdapterMessageType_METRICS_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530487 }, Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800488 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530489 {"ProcessInterAdapterMessage-6", args{msg: &ic.InterAdapterMessage{
490 Header: &ic.InterAdapterHeader{
491 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800492 Type: ic.InterAdapterMessageType_METRICS_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530493 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800494 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530495 {"ProcessInterAdapterMessage-7", args{msg: &ic.InterAdapterMessage{
496 Header: &ic.InterAdapterHeader{
497 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800498 Type: ic.InterAdapterMessageType_ONU_IND_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530499 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800500 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530501 {"ProcessInterAdapterMessage-8", args{msg: &ic.InterAdapterMessage{
502 Header: &ic.InterAdapterHeader{
503 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800504 Type: ic.InterAdapterMessageType_ONU_IND_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530505 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800506 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530507 {"ProcessInterAdapterMessage-9", args{msg: &ic.InterAdapterMessage{
508 Header: &ic.InterAdapterHeader{
509 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800510 Type: ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530511 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800512 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530513 {"ProcessInterAdapterMessage-10", args{msg: &ic.InterAdapterMessage{
514 Header: &ic.InterAdapterHeader{
515 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800516 Type: ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530517 }, Body: marshalledData2,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800518 }}, invalid},
519 {"ProcessInterAdapterMessage-11", args{msg: &ic.InterAdapterMessage{
520 Header: &ic.InterAdapterHeader{
521 Id: "012345",
522 Type: ic.InterAdapterMessageType_DELETE_TCONT_REQUEST,
523 }, Body: marshalledData2,
524 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530525 }
526 for _, tt := range tests {
527 t.Run(tt.name, func(t *testing.T) {
528
Neha Sharma96b7bf22020-06-15 10:37:32 +0000529 if err := dh.ProcessInterAdapterMessage(ctx, tt.args.msg); reflect.TypeOf(err) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530530 t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr)
531 }
532 })
533 }
534}
535
536func TestDeviceHandler_sendProxiedMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000537 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530538 dh1 := newMockDeviceHandler()
539 dh2 := negativeDeviceHandler()
540 device1 := &voltha.Device{
541 Id: "onu1",
542 Root: false,
543 ParentId: "logical_device",
544 ProxyAddress: &voltha.Device_ProxyAddress{
545 DeviceId: "onu1",
546 DeviceType: "onu",
547 ChannelId: 1,
548 ChannelGroupId: 1,
549 },
550 ConnectStatus: 1,
551 }
552 device2 := device1
553 device2.ConnectStatus = 2
554 iaomciMsg1 := &ic.InterAdapterOmciMessage{
555 ProxyAddress: &voltha.Device_ProxyAddress{
556 DeviceId: "onu2",
557 DeviceType: "onu",
558 ChannelId: 1,
559 ChannelGroupId: 1,
560 //OnuId: 2,
561 },
562 ConnectStatus: 1,
563 }
564 iaomciMsg2 := &ic.InterAdapterOmciMessage{
565 ProxyAddress: &voltha.Device_ProxyAddress{
566 DeviceId: "onu3",
567 DeviceType: "onu",
568 ChannelId: 1,
569 ChannelGroupId: 1,
570 },
571 ConnectStatus: 1,
572 }
573 type args struct {
574 onuDevice *voltha.Device
575 omciMsg *ic.InterAdapterOmciMessage
576 }
577 tests := []struct {
578 name string
579 devicehandler *DeviceHandler
580 args args
581 }{
582 {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
583 {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ic.InterAdapterOmciMessage{}}},
584 {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}},
585 {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}},
586 {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}},
587 {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
588 }
589 for _, tt := range tests {
590 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400591 _ = tt.devicehandler.sendProxiedMessage(ctx, tt.args.onuDevice, tt.args.omciMsg)
592 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530593 })
594 }
595}
596
597func TestDeviceHandler_SendPacketInToCore(t *testing.T) {
598 dh1 := newMockDeviceHandler()
599 dh2 := negativeDeviceHandler()
600
601 type args struct {
602 logicalPort uint32
603 packetPayload []byte
604 }
605 tests := []struct {
606 name string
607 devicehandler *DeviceHandler
608 args args
609 }{
610 {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}},
611 {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}},
612 {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}},
613 }
614 for _, tt := range tests {
615 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400616 _ = tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload)
617 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530618 })
619 }
620}
621
622func TestDeviceHandler_DisableDevice(t *testing.T) {
623 dh1 := newMockDeviceHandler()
624 dh2 := negativeDeviceHandler()
625 type args struct {
626 device *voltha.Device
627 }
628 tests := []struct {
629 name string
630 devicehandler *DeviceHandler
631 args args
632 wantErr bool
633 }{
634 {"DisableDevice-1", dh1, args{device: dh1.device}, false},
Chaitrashree G S3b4c0352019-09-09 20:59:29 -0400635 {"DisableDevice-2", dh1, args{device: dh2.device}, true},
kdarapu891693b2019-09-16 12:33:49 +0530636 }
637 for _, tt := range tests {
638 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000639 if err := tt.devicehandler.DisableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530640 t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
641 }
642 })
643 }
644}
645
646func TestDeviceHandler_ReenableDevice(t *testing.T) {
647 dh1 := newMockDeviceHandler()
648 dh2 := negativeDeviceHandler()
649 type args struct {
650 device *voltha.Device
651 }
652 tests := []struct {
653 name string
654 devicehandler *DeviceHandler
655 args args
656 wantErr bool
657 }{
658 {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
659 {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
660 {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
661 }
662 for _, tt := range tests {
663 t.Run(tt.name, func(t *testing.T) {
664 dh := tt.devicehandler
Neha Sharma96b7bf22020-06-15 10:37:32 +0000665 if err := dh.ReenableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530666 t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
667 }
668 })
669 }
670}
671
672func TestDeviceHandler_RebootDevice(t *testing.T) {
673 dh1 := newMockDeviceHandler()
674 dh2 := newMockDeviceHandler()
675 type args struct {
676 device *voltha.Device
677 }
678 tests := []struct {
679 name string
680 devicehandler *DeviceHandler
681 args args
682 wantErr bool
683 }{
684 // TODO: Add test cases.
685 {"RebootDevice-1", dh1, args{device: dh1.device}, false},
686 {"RebootDevice-2", dh1, args{device: dh2.device}, true},
687 {"RebootDevice-3", dh2, args{device: dh2.device}, false},
688 }
689 for _, tt := range tests {
690 t.Run(tt.name, func(t *testing.T) {
691
Neha Sharma96b7bf22020-06-15 10:37:32 +0000692 if err := tt.devicehandler.RebootDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530693 t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
694 }
695 })
696 }
697}
698
699func TestDeviceHandler_handleIndication(t *testing.T) {
700 dh1 := newMockDeviceHandler()
701 dh2 := negativeDeviceHandler()
702 dh3 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530703 dh3.onus = sync.Map{}
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530704 dh3.onus.Store("onu1", NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1", false))
705 dh3.onus.Store("onu2", NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2", false))
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530706
kdarapu891693b2019-09-16 12:33:49 +0530707 type args struct {
708 indication *oop.Indication
709 }
710 tests := []struct {
711 name string
712 deviceHandler *DeviceHandler
713 args args
714 }{
715 // TODO: Add test cases.
716 {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
717 {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
718 {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
719 {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
720 {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
721 {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
722 {"handleIndication-7", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuDiscInd{OnuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}}},
723 {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
724 {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
725 {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
726 {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
727 {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
728 {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
729 {"handleIndication-14", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PortStats{PortStats: &oop.PortStatistics{IntfId: 1, RxBytes: 100, RxPackets: 100, RxUcastPackets: 100, RxMcastPackets: 100, RxBcastPackets: 100, RxErrorPackets: 100, TxBytes: 100, TxPackets: 100, TxUcastPackets: 100, TxMcastPackets: 100, TxBcastPackets: 100, TxErrorPackets: 100, RxCrcErrors: 100, BipErrors: 100, Timestamp: 1000}}}}},
730 {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
731 {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
732 {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
733 {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
734
735 // Negative testcases
736 {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
737 {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
738 {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
739 {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
740 {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
741 {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
742 {"handleIndication-25", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuDiscInd{OnuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}}},
743 {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
744 {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
745 {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
746 {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
747 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
748 {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
749 {"handleIndication-32", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PortStats{PortStats: &oop.PortStatistics{IntfId: 1, RxBytes: 100, RxPackets: 100, RxUcastPackets: 100, RxMcastPackets: 100, RxBcastPackets: 100, RxErrorPackets: 100, TxBytes: 100, TxPackets: 100, TxUcastPackets: 100, TxMcastPackets: 100, TxBcastPackets: 100, TxErrorPackets: 100, RxCrcErrors: 100, BipErrors: 100, Timestamp: 1000}}}}},
750 {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
751 {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
752 //
753 {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
754 {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
755 {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
756 {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
757 {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
758 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
759 }
760 for _, tt := range tests {
761 t.Run(tt.name, func(t *testing.T) {
762 dh := tt.deviceHandler
npujarec5762e2020-01-01 14:08:48 +0530763 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
764 defer cancel()
765 dh.handleIndication(ctx, tt.args.indication)
kdarapu891693b2019-09-16 12:33:49 +0530766 })
767 }
768}
769
770func TestDeviceHandler_addPort(t *testing.T) {
771 dh1 := newMockDeviceHandler()
772 dh2 := negativeDeviceHandler()
773 type args struct {
774 intfID uint32
775 portType voltha.Port_PortType
776 state string
777 }
778 tests := []struct {
779 name string
780 devicehandler *DeviceHandler
781 args args
782 }{
783 // State up
784 {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
785 {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
786 {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
787 {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
788 {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
789 {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
790 {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
791 {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
792 // state discovery
793 {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
794 {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
795 {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
796 {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
797 {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
798 {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
799 {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
800 {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
801
802 {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
803 {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
804 {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
805 {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
806 }
807 for _, tt := range tests {
808 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400809 _ = tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state)
810 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530811 })
812 }
813}
814
815func Test_macAddressToUint32Array(t *testing.T) {
816 type args struct {
817 mac string
818 }
819 tests := []struct {
820 name string
821 args args
822 want []uint32
823 }{
824 // TODO: Add test cases.
825 {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
826 {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
827 {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
828 }
829 for _, tt := range tests {
830 t.Run(tt.name, func(t *testing.T) {
831 if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
832 t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
833 }
834 })
835 }
836}
837
838func TestDeviceHandler_handleOltIndication(t *testing.T) {
839
840 type args struct {
841 oltIndication *oop.OltIndication
842 }
843 tests := []struct {
844 name string
845 args args
846 }{
847 {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
848 {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
849 }
850 for _, tt := range tests {
851 t.Run(tt.name, func(t *testing.T) {
852 dh := newMockDeviceHandler()
npujarec5762e2020-01-01 14:08:48 +0530853 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
854 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400855 if err := dh.handleOltIndication(ctx, tt.args.oltIndication); err != nil {
856 t.Error(err)
857 }
kdarapu891693b2019-09-16 12:33:49 +0530858 })
859 }
860}
861
862func TestDeviceHandler_AdoptDevice(t *testing.T) {
863 dh1 := newMockDeviceHandler()
864 dh2 := negativeDeviceHandler()
865 type args struct {
866 device *voltha.Device
867 }
868 tests := []struct {
869 name string
870 devicehandler *DeviceHandler
871 args args
872 }{
873 // TODO: Add test cases.
874 {"AdoptDevice-1", dh1, args{device: dh1.device}},
Naga Manjunath7615e552019-10-11 22:35:47 +0530875 {"AdoptDevice-2", dh2, args{device: dh2.device}},
kdarapu891693b2019-09-16 12:33:49 +0530876 }
877 for _, tt := range tests {
878 t.Run(tt.name, func(t *testing.T) {
879 //dh.doStateInit()
880 // context.
881 //dh.AdoptDevice(tt.args.device)
npujarec5762e2020-01-01 14:08:48 +0530882 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
883 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400884 if err := tt.devicehandler.postInit(ctx); err != nil {
885 t.Error(err)
886 }
kdarapu891693b2019-09-16 12:33:49 +0530887 })
888 }
889}
890
891func TestDeviceHandler_activateONU(t *testing.T) {
892 dh := newMockDeviceHandler()
893 dh1 := negativeDeviceHandler()
894 type args struct {
895 intfID uint32
896 onuID int64
897 serialNum *oop.SerialNumber
898 serialNumber string
899 }
900 tests := []struct {
901 name string
902 devicehandler *DeviceHandler
903 args args
904 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700905 {"activateONU-1", dh, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
906 {"activateONU-2", dh, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
907 {"activateONU-3", dh1, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
908 {"activateONU-4", dh1, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
kdarapu891693b2019-09-16 12:33:49 +0530909 }
910 for _, tt := range tests {
911 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530912 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
913 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400914 _ = tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum, tt.args.serialNumber)
915 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530916 })
917 }
918}
919
920func TestDeviceHandler_start(t *testing.T) {
921 dh := newMockDeviceHandler()
922 dh1 := negativeDeviceHandler()
923 dh.start(context.Background())
924 dh.stop(context.Background())
925
926 dh1.start(context.Background())
927 dh1.stop(context.Background())
928
929}
930
931func TestDeviceHandler_PacketOut(t *testing.T) {
932 dh1 := newMockDeviceHandler()
933 dh2 := negativeDeviceHandler()
934 acts := []*ofp.OfpAction{
935 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
936 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
937 fu.Output(1),
938 }
939 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
940 type args struct {
941 egressPortNo int
942 packet *of.OfpPacketOut
943 }
944 tests := []struct {
945 name string
946 devicehandler *DeviceHandler
947 args args
948 wantErr bool
949 }{
950 // TODO: Add test cases.
951 //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
952 {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
953 {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
Matteo Scandolo2c0d2742020-06-10 11:28:42 -0700954 {"PacketOut-3", dh2, args{egressPortNo: 4112, packet: pktout}, false},
955 {"PacketOut-4", dh1, args{egressPortNo: 1048577, packet: pktout}, false},
956 {"PacketOut-5", dh2, args{egressPortNo: 1048576, packet: pktout}, false},
kdarapu891693b2019-09-16 12:33:49 +0530957 }
958 for _, tt := range tests {
959 t.Run(tt.name, func(t *testing.T) {
960 dh := tt.devicehandler
npujarec5762e2020-01-01 14:08:48 +0530961 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
962 defer cancel()
963 if err := dh.PacketOut(ctx, tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530964 t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
965 }
966 })
967 }
968}
969
970//
971func TestDeviceHandler_doStateUp(t *testing.T) {
972 dh1 := newMockDeviceHandler()
973 dh2 := newMockDeviceHandler()
974
Thomas Lee S985938d2020-05-04 11:40:41 +0530975 dh2.device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530976 dh3 := negativeDeviceHandler()
977
978 tests := []struct {
979 name string
980 devicehandler *DeviceHandler
981 wantErr bool
982 }{
983 {"dostateup-1", dh1, false},
984 {"dostateup-2", dh2, false},
985 {"dostateup-3", dh3, true},
986 }
987 for _, tt := range tests {
988 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530989 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
990 defer cancel()
991 if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530992 t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
993 }
Thomas Lee S85f37312020-04-03 17:06:12 +0530994 tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp
kdarapu891693b2019-09-16 12:33:49 +0530995 })
996 }
997}
998func TestDeviceHandler_doStateDown(t *testing.T) {
999 dh1 := newMockDeviceHandler()
1000 dh2 := negativeDeviceHandler()
1001 dh3 := newMockDeviceHandler()
1002 dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
1003 tests := []struct {
1004 name string
1005 devicehandler *DeviceHandler
1006 wantErr bool
1007 }{
1008 {"dostatedown-1", dh1, false},
1009 {"dostatedown-2", dh2, true},
1010 {"dostatedown-2", dh3, true},
1011 }
1012 for _, tt := range tests {
1013 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301014 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1015 defer cancel()
1016 if err := tt.devicehandler.doStateDown(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +05301017 t.Logf("DeviceHandler.doStateDown() error = %v", err)
Kent Hagermane6ff1012020-07-14 15:07:53 -04001018 //TODO: should fail this test case (Errorf) if result is not as expected
kdarapu891693b2019-09-16 12:33:49 +05301019 }
1020 })
1021 }
1022}
1023
1024func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
1025 dh1 := newMockDeviceHandler()
1026 dh2 := negativeDeviceHandler()
1027 type args struct {
1028 device *voltha.Device
1029 }
1030 tests := []struct {
1031 name string
1032 devicehandler *DeviceHandler
1033 args args
1034 wantErr bool
1035 }{
1036 // TODO: Add test cases.
1037 {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
1038 {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
1039 {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
1040 }
1041 for _, tt := range tests {
1042 t.Run(tt.name, func(t *testing.T) {
1043 dh := tt.devicehandler
1044 _, err := dh.GetOfpDeviceInfo(tt.args.device)
1045 if (err != nil) != tt.wantErr {
1046 t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1047 return
1048 }
1049 })
1050 }
1051}
1052
kdarapu891693b2019-09-16 12:33:49 +05301053func TestDeviceHandler_onuDiscIndication(t *testing.T) {
1054
1055 dh1 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +05301056 dh1.discOnus = sync.Map{}
1057 dh1.discOnus.Store("onu1", true)
1058 dh1.discOnus.Store("onu2", false)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +05301059 dh1.discOnus.Store("onu3", true)
1060 dh1.discOnus.Store("onu4", true)
1061 dh1.onus = sync.Map{}
1062 dh1.onus.Store("onu3", NewOnuDevice("onu3", "onu3", "onu3", 3, 3, "onu3", true))
1063 dh1.onus.Store("onu4", NewOnuDevice("onu4", "onu4", "onu4", 4, 4, "onu4", true))
kdarapu891693b2019-09-16 12:33:49 +05301064 dh2 := negativeDeviceHandler()
1065 type args struct {
1066 onuDiscInd *oop.OnuDiscIndication
1067 sn string
1068 }
1069 tests := []struct {
1070 name string
1071 devicehandler *DeviceHandler
1072 args args
1073 }{
1074 // TODO: Add test cases.
1075 {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
1076 {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
1077 {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
1078 {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
1079 {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
1080 {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}},
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +05301081 {"onuDiscIndication-7", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu3"}},
1082 {"onuDiscIndication-8", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu4"}},
1083 {"onuDiscIndication-9", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
kdarapu891693b2019-09-16 12:33:49 +05301084 }
1085 for _, tt := range tests {
1086 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301087 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1088 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -04001089 _ = tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd, tt.args.sn)
1090 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301091 })
1092 }
1093}
1094
1095func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
1096 dh1 := newMockDeviceHandler()
1097 dh2 := negativeDeviceHandler()
1098 tests := []struct {
1099 name string
1100 devicehandler *DeviceHandler
1101
1102 wantErr bool
1103 }{
1104 // TODO: Add test cases.
1105 {"populateDeviceInfo-1", dh1, false},
1106 {"populateDeviceInfo-2", dh1, true},
1107 {"populateDeviceInfo-3", dh1, true},
1108 {"populateDeviceInfo-4", dh1, true},
1109 {"populateDeviceInfo-5", dh2, true},
1110 }
1111 for _, tt := range tests {
1112 t.Run(tt.name, func(t *testing.T) {
1113
Neha Sharma96b7bf22020-06-15 10:37:32 +00001114 _, err := tt.devicehandler.populateDeviceInfo(context.Background())
kdarapu891693b2019-09-16 12:33:49 +05301115 if (err != nil) != tt.wantErr {
1116 t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1117 return
1118 }
1119
1120 })
1121 }
1122}
1123
1124func TestDeviceHandler_readIndications(t *testing.T) {
1125 dh1 := newMockDeviceHandler()
1126 dh2 := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +05301127 dh3 := newMockDeviceHandler()
1128 dh3.device.AdminState = voltha.AdminState_DISABLED
1129 dh4 := negativeDeviceHandler()
1130 tests := []struct {
1131 name string
1132 devicehandler *DeviceHandler
1133 }{
1134 // TODO: Add test cases.
1135 {"readIndications-1", dh1},
1136 {"readIndications-2", dh2},
1137 {"readIndications-3", dh2},
1138 {"readIndications-4", dh2},
1139 {"readIndications-5", dh2},
1140 {"readIndications-6", dh3},
1141 {"readIndications-7", dh3},
1142 {"readIndications-8", dh4},
1143 }
1144 for _, tt := range tests {
1145 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301146 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1147 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -04001148 _ = tt.devicehandler.readIndications(ctx)
1149 // TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301150 })
1151 }
1152}
Naga Manjunath7615e552019-10-11 22:35:47 +05301153
1154func Test_startCollector(t *testing.T) {
1155 type args struct {
1156 dh *DeviceHandler
1157 }
1158 dh := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001159 dh.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301160 {PortNo: 1, Label: "pon", Type: voltha.Port_PON_OLT},
1161 {PortNo: 1048577, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1162 {PortNo: 1048578, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1163 }
Naga Manjunath7615e552019-10-11 22:35:47 +05301164 dh.portStats.NorthBoundPort = make(map[uint32]*NniPort)
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301165 dh.portStats.NorthBoundPort[1] = &NniPort{Name: "OLT-1"}
1166 dh.portStats.NorthBoundPort[2] = &NniPort{Name: "OLT-1"}
Naga Manjunath7615e552019-10-11 22:35:47 +05301167 dh.portStats.SouthBoundPort = make(map[uint32]*PonPort)
1168 dh.portStats.Device = dh
1169 for i := 0; i < 16; i++ {
1170 dh.portStats.SouthBoundPort[uint32(i)] = &PonPort{DeviceID: "OLT-1"}
1171 }
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301172 dh1 := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001173 dh1.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{}
Naga Manjunath7615e552019-10-11 22:35:47 +05301174 tests := []struct {
1175 name string
1176 args args
1177 }{
1178 // TODO: Add test cases.
1179 {"StartCollector-1", args{dh}},
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301180 {"StartCollector-2", args{dh1}},
Naga Manjunath7615e552019-10-11 22:35:47 +05301181 }
1182 for _, tt := range tests {
1183 t.Run(tt.name, func(t *testing.T) {
1184 go func() {
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301185 time.Sleep(1 * time.Second) // simulated wait time to stop startCollector
Naga Manjunath7615e552019-10-11 22:35:47 +05301186 tt.args.dh.stopCollector <- true
1187 }()
Neha Sharma96b7bf22020-06-15 10:37:32 +00001188 startCollector(context.Background(), tt.args.dh)
Naga Manjunath7615e552019-10-11 22:35:47 +05301189 })
1190 }
1191}