blob: ecfca4be86ecbdd019fa27e10d2bbfe37108c090 [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
17//Package adaptercore provides the utility for olt devices, flows and statistics
18package adaptercore
19
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"
kdarapu381c6902019-07-31 18:23:16 +053024 "testing"
25
kdarapu891693b2019-09-16 12:33:49 +053026 "github.com/golang/protobuf/ptypes"
27 "github.com/golang/protobuf/ptypes/any"
Scott Baker355d1742019-10-24 10:57:52 -070028 fu "github.com/opencord/voltha-lib-go/pkg/flows"
Scott Bakerf8424cc2019-10-18 11:26:50 -070029 "github.com/opencord/voltha-lib-go/pkg/log"
kdarapu891693b2019-09-16 12:33:49 +053030 "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
kdarapu381c6902019-07-31 18:23:16 +053031 "github.com/opencord/voltha-openolt-adapter/mocks"
kdarapu891693b2019-09-16 12:33:49 +053032 ic "github.com/opencord/voltha-protos/go/inter_container"
33 of "github.com/opencord/voltha-protos/go/openflow_13"
34 ofp "github.com/opencord/voltha-protos/go/openflow_13"
35 oop "github.com/opencord/voltha-protos/go/openolt"
kdarapu381c6902019-07-31 18:23:16 +053036 "github.com/opencord/voltha-protos/go/voltha"
37)
38
kdarapu891693b2019-09-16 12:33:49 +053039func init() {
40 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
41}
42
43func newMockCoreProxy() *mocks.MockCoreProxy {
44 mcp := mocks.MockCoreProxy{}
45 mcp.Devices = make(map[string]*voltha.Device)
46 mcp.Devices["olt"] = &voltha.Device{
47
48 Id: "olt",
49 Root: true,
50 ParentId: "logical_device",
51 ParentPortNo: 1,
52
53 Ports: []*voltha.Port{
54 {PortNo: 1, Label: "pon"},
55 {PortNo: 2, Label: "nni"},
56 },
57 ProxyAddress: &voltha.Device_ProxyAddress{
58 DeviceId: "olt",
59 DeviceType: "onu",
60 ChannelId: 1,
61 ChannelGroupId: 1,
62 },
63 ConnectStatus: 1,
64 }
65 mcp.Devices["onu1"] = &voltha.Device{
66
67 Id: "1",
68 Root: false,
69 ParentId: "olt",
70 ParentPortNo: 1,
71
72 Ports: []*voltha.Port{
73 {PortNo: 1, Label: "pon"},
74 {PortNo: 2, Label: "uni"},
75 },
76 OperStatus: 4,
77 ProxyAddress: &voltha.Device_ProxyAddress{
78 OnuId: 1,
79 ChannelId: 1,
80 ChannelGroupId: 1,
81 },
82 ConnectStatus: 1,
83 }
84 mcp.Devices["onu2"] = &voltha.Device{
85 Id: "2",
86 Root: false,
87 ParentId: "olt",
88 OperStatus: 2,
89 Ports: []*voltha.Port{
90 {PortNo: 1, Label: "pon"},
91 {PortNo: 2, Label: "uni"},
92 },
93
94 ParentPortNo: 1,
95
96 ProxyAddress: &voltha.Device_ProxyAddress{
97 OnuId: 2,
98 ChannelId: 1,
99 ChannelGroupId: 1,
100 },
101 ConnectStatus: 1,
102 }
103 return &mcp
104}
105func newMockDeviceHandler() *DeviceHandler {
kdarapu381c6902019-07-31 18:23:16 +0530106 device := &voltha.Device{
107 Id: "olt",
108 Root: true,
109 ParentId: "logical_device",
110 Ports: []*voltha.Port{
111 {PortNo: 1, Label: "pon"},
112 {PortNo: 2, Label: "nni"},
113 },
kdarapu891693b2019-09-16 12:33:49 +0530114 ProxyAddress: &voltha.Device_ProxyAddress{
115 DeviceId: "olt",
116 DeviceType: "onu",
117 ChannelId: 1,
118 ChannelGroupId: 1,
119 },
120 ConnectStatus: 1,
kdarapu381c6902019-07-31 18:23:16 +0530121 }
kdarapu891693b2019-09-16 12:33:49 +0530122 cp := newMockCoreProxy()
123 ap := &mocks.MockAdapterProxy{}
124 ep := &mocks.MockEventProxy{}
125 openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep}
126 dh := NewDeviceHandler(cp, ap, ep, device, openOLT)
kdarapub26b4502019-10-05 03:02:33 +0530127 dh.nniIntfID = 1
kdarapu891693b2019-09-16 12:33:49 +0530128 deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: nil, Model: "openolt", DeviceId: dh.deviceID}
129 dh.resourceMgr = &resourcemanager.OpenOltResourceMgr{DeviceID: dh.deviceID, DeviceType: dh.deviceType, DevInfo: deviceInf}
130 dh.flowMgr = NewFlowManager(dh, dh.resourceMgr)
131 dh.Client = &mocks.MockOpenoltClient{}
132 dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}}
133 dh.transitionMap = &TransitionMap{}
134 return dh
kdarapu381c6902019-07-31 18:23:16 +0530135}
136
kdarapu891693b2019-09-16 12:33:49 +0530137func negativeDeviceHandler() *DeviceHandler {
138 dh := newMockDeviceHandler()
139 device := dh.device
140 device.Id = ""
141 dh.adminState = "down"
142 return dh
143}
kdarapu381c6902019-07-31 18:23:16 +0530144func Test_generateMacFromHost(t *testing.T) {
145 type args struct {
146 host string
147 }
148 tests := []struct {
149 name string
150 args args
151 want string
152 wantErr bool
153 }{
kdarapu891693b2019-09-16 12:33:49 +0530154 {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
155 {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
156 //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false},
157 {"generateMacFromHost-4", args{host: "testing3"}, "", true},
kdarapu381c6902019-07-31 18:23:16 +0530158 }
159 for _, tt := range tests {
160 t.Run(tt.name, func(t *testing.T) {
161 got, err := generateMacFromHost(tt.args.host)
162 if (err != nil) != tt.wantErr {
163 t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr)
164 return
165 }
166 if got != tt.want {
167 t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want)
168 }
169 })
170 }
171}
172func Test_macifyIP(t *testing.T) {
173 type args struct {
174 ip net.IP
175 }
176 tests := []struct {
177 name string
178 args args
179 want string
180 }{{
kdarapu891693b2019-09-16 12:33:49 +0530181 "macifyIP-1",
kdarapu381c6902019-07-31 18:23:16 +0530182 args{ip: net.ParseIP("10.10.10.10")},
183 "00:00:0a:0a:0a:0a",
184 },
185 {
kdarapu891693b2019-09-16 12:33:49 +0530186 "macifyIP-2",
kdarapu381c6902019-07-31 18:23:16 +0530187 args{ip: net.ParseIP("127.0.0.1")},
188 "00:00:7f:00:00:01",
kdarapu891693b2019-09-16 12:33:49 +0530189 },
190 {
191 "macifyIP-3",
192 args{ip: net.ParseIP("127.0.0.1/24")},
193 "",
194 },
195 }
kdarapu381c6902019-07-31 18:23:16 +0530196 for _, tt := range tests {
197 t.Run(tt.name, func(t *testing.T) {
198 if got := macifyIP(tt.args.ip); got != tt.want {
199 t.Errorf("macifyIP() = %v, want %v", got, tt.want)
200 }
201 })
202 }
203}
204
kdarapu381c6902019-07-31 18:23:16 +0530205func TestDeviceHandler_GetChildDevice(t *testing.T) {
kdarapu891693b2019-09-16 12:33:49 +0530206 dh1 := newMockDeviceHandler()
207 dh2 := negativeDeviceHandler()
kdarapu381c6902019-07-31 18:23:16 +0530208 type args struct {
209 parentPort uint32
210 onuID uint32
211 }
212 tests := []struct {
kdarapu891693b2019-09-16 12:33:49 +0530213 name string
214 devicehandler *DeviceHandler
215 args args
216 want *voltha.Device
kdarapu381c6902019-07-31 18:23:16 +0530217 }{
kdarapu891693b2019-09-16 12:33:49 +0530218 {"GetChildDevice-1", dh1,
219 args{parentPort: 1,
220 onuID: 1},
221 &voltha.Device{},
222 },
223 {"GetChildDevice-2", dh2,
kdarapu381c6902019-07-31 18:23:16 +0530224 args{parentPort: 1,
225 onuID: 1},
226 &voltha.Device{},
227 },
228 }
229 for _, tt := range tests {
230 t.Run(tt.name, func(t *testing.T) {
kdarapu891693b2019-09-16 12:33:49 +0530231 got := tt.devicehandler.GetChildDevice(tt.args.parentPort, tt.args.onuID)
kdarapu381c6902019-07-31 18:23:16 +0530232 t.Log("onu device id", got)
233 })
234 }
235}
kdarapu891693b2019-09-16 12:33:49 +0530236
237func TestGetportLabel(t *testing.T) {
238 type args struct {
239 portNum uint32
240 portType voltha.Port_PortType
241 }
242 tests := []struct {
243 name string
244 args args
245 want string
246 }{
247 {"GetportLabel-1", args{portNum: 0, portType: 0}, ""},
248 {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1"},
249 {"GetportLabel-3", args{portNum: 2, portType: 2}, ""},
250 {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3"},
251 {"GetportLabel-5", args{portNum: 4, portType: 4}, ""},
252 {"GetportLabel-6", args{portNum: 5, portType: 5}, ""},
253 {"GetportLabel-7", args{portNum: 6, portType: 6}, ""},
254 }
255 for _, tt := range tests {
256 t.Run(tt.name, func(t *testing.T) {
257 if got := GetportLabel(tt.args.portNum, tt.args.portType); got != tt.want {
258 t.Errorf("GetportLabel() = %v, want %v", got, tt.want)
259 }
260 })
261 }
262}
263
264func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) {
265 dh := newMockDeviceHandler()
266 proxyAddr := dh.device.ProxyAddress
267 body := &ic.InterAdapterOmciMessage{
268 Message: []byte("asdfasdfasdfasdfas"),
269 ProxyAddress: proxyAddr,
270 }
271 body2 := &ic.InterAdapterOmciMessage{
272 Message: []byte("asdfasdfasdfasdfas"),
273 //ProxyAddress: &voltha.Device_ProxyAddress{},
274 }
275 body3 := &ic.InterAdapterTechProfileDownloadMessage{}
276 var marshalledData *any.Any
277 var err error
278
279 if marshalledData, err = ptypes.MarshalAny(body); err != nil {
280 log.Errorw("cannot-marshal-request", log.Fields{"error": err})
281 }
282
283 var marshalledData1 *any.Any
284
285 if marshalledData1, err = ptypes.MarshalAny(body2); err != nil {
286 log.Errorw("cannot-marshal-request", log.Fields{"error": err})
287 }
288 var marshalledData2 *any.Any
289
290 if marshalledData2, err = ptypes.MarshalAny(body3); err != nil {
291 log.Errorw("cannot-marshal-request", log.Fields{"error": err})
292 }
293 type args struct {
294 msg *ic.InterAdapterMessage
295 }
296 tests := []struct {
297 name string
298 args args
299 wantErr bool
300 }{
301 {"ProcessInterAdapterMessage-1", args{msg: &ic.InterAdapterMessage{
302 Header: &ic.InterAdapterHeader{
303 Id: "012345",
304 Type: 0,
305 },
306 Body: marshalledData,
307 }}, false},
308 {"ProcessInterAdapterMessage-2", args{msg: &ic.InterAdapterMessage{
309 Header: &ic.InterAdapterHeader{
310 Id: "012345",
311 Type: 1,
312 },
313 Body: marshalledData1,
314 }}, false},
315 {"ProcessInterAdapterMessage-3", args{msg: &ic.InterAdapterMessage{
316 Header: &ic.InterAdapterHeader{
317 Id: "012345",
318 Type: 2,
319 },
320 Body: marshalledData,
321 }}, false},
322 {"ProcessInterAdapterMessage-4", args{msg: &ic.InterAdapterMessage{
323 Header: &ic.InterAdapterHeader{
324 Id: "012345",
325 Type: 3,
326 }, Body: marshalledData,
327 }}, false},
328 {"ProcessInterAdapterMessage-5", args{msg: &ic.InterAdapterMessage{
329 Header: &ic.InterAdapterHeader{
330 Id: "012345",
331 Type: 4,
332 }, Body: marshalledData1,
333 }}, false},
334 {"ProcessInterAdapterMessage-6", args{msg: &ic.InterAdapterMessage{
335 Header: &ic.InterAdapterHeader{
336 Id: "012345",
337 Type: 4,
338 }, Body: marshalledData,
339 }}, false},
340 {"ProcessInterAdapterMessage-7", args{msg: &ic.InterAdapterMessage{
341 Header: &ic.InterAdapterHeader{
342 Id: "012345",
343 Type: 5,
344 }, Body: marshalledData,
345 }}, false},
346 {"ProcessInterAdapterMessage-8", args{msg: &ic.InterAdapterMessage{
347 Header: &ic.InterAdapterHeader{
348 Id: "012345",
349 Type: 6,
350 }, Body: marshalledData,
351 }}, false},
352 {"ProcessInterAdapterMessage-9", args{msg: &ic.InterAdapterMessage{
353 Header: &ic.InterAdapterHeader{
354 Id: "012345",
355 Type: 7,
356 }, Body: marshalledData,
357 }}, false},
358 {"ProcessInterAdapterMessage-10", args{msg: &ic.InterAdapterMessage{
359 Header: &ic.InterAdapterHeader{
360 Id: "012345",
361 Type: 7,
362 }, Body: marshalledData2,
363 }}, false},
364 //marshalledData2
365 }
366 for _, tt := range tests {
367 t.Run(tt.name, func(t *testing.T) {
368
369 if err := dh.ProcessInterAdapterMessage(tt.args.msg); (err != nil) != tt.wantErr {
370 t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr)
371 }
372 })
373 }
374}
375
376func TestDeviceHandler_sendProxiedMessage(t *testing.T) {
377 dh1 := newMockDeviceHandler()
378 dh2 := negativeDeviceHandler()
379 device1 := &voltha.Device{
380 Id: "onu1",
381 Root: false,
382 ParentId: "logical_device",
383 ProxyAddress: &voltha.Device_ProxyAddress{
384 DeviceId: "onu1",
385 DeviceType: "onu",
386 ChannelId: 1,
387 ChannelGroupId: 1,
388 },
389 ConnectStatus: 1,
390 }
391 device2 := device1
392 device2.ConnectStatus = 2
393 iaomciMsg1 := &ic.InterAdapterOmciMessage{
394 ProxyAddress: &voltha.Device_ProxyAddress{
395 DeviceId: "onu2",
396 DeviceType: "onu",
397 ChannelId: 1,
398 ChannelGroupId: 1,
399 //OnuId: 2,
400 },
401 ConnectStatus: 1,
402 }
403 iaomciMsg2 := &ic.InterAdapterOmciMessage{
404 ProxyAddress: &voltha.Device_ProxyAddress{
405 DeviceId: "onu3",
406 DeviceType: "onu",
407 ChannelId: 1,
408 ChannelGroupId: 1,
409 },
410 ConnectStatus: 1,
411 }
412 type args struct {
413 onuDevice *voltha.Device
414 omciMsg *ic.InterAdapterOmciMessage
415 }
416 tests := []struct {
417 name string
418 devicehandler *DeviceHandler
419 args args
420 }{
421 {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
422 {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ic.InterAdapterOmciMessage{}}},
423 {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}},
424 {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}},
425 {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}},
426 {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
427 }
428 for _, tt := range tests {
429 t.Run(tt.name, func(t *testing.T) {
430 tt.devicehandler.sendProxiedMessage(tt.args.onuDevice, tt.args.omciMsg)
431 })
432 }
433}
434
435func TestDeviceHandler_SendPacketInToCore(t *testing.T) {
436 dh1 := newMockDeviceHandler()
437 dh2 := negativeDeviceHandler()
438
439 type args struct {
440 logicalPort uint32
441 packetPayload []byte
442 }
443 tests := []struct {
444 name string
445 devicehandler *DeviceHandler
446 args args
447 }{
448 {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}},
449 {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}},
450 {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}},
451 }
452 for _, tt := range tests {
453 t.Run(tt.name, func(t *testing.T) {
454 tt.devicehandler.SendPacketInToCore(tt.args.logicalPort, tt.args.packetPayload)
455 })
456 }
457}
458
459func TestDeviceHandler_DisableDevice(t *testing.T) {
460 dh1 := newMockDeviceHandler()
461 dh2 := negativeDeviceHandler()
462 type args struct {
463 device *voltha.Device
464 }
465 tests := []struct {
466 name string
467 devicehandler *DeviceHandler
468 args args
469 wantErr bool
470 }{
471 {"DisableDevice-1", dh1, args{device: dh1.device}, false},
472 {"DisableDevice-2", dh1, args{device: dh1.device}, true},
473 {"DisableDevice-3", dh2, args{device: dh2.device}, true},
474 }
475 for _, tt := range tests {
476 t.Run(tt.name, func(t *testing.T) {
477
478 if err := tt.devicehandler.DisableDevice(tt.args.device); (err != nil) != tt.wantErr {
479 t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
480 }
481 })
482 }
483}
484
485func TestDeviceHandler_ReenableDevice(t *testing.T) {
486 dh1 := newMockDeviceHandler()
487 dh2 := negativeDeviceHandler()
488 type args struct {
489 device *voltha.Device
490 }
491 tests := []struct {
492 name string
493 devicehandler *DeviceHandler
494 args args
495 wantErr bool
496 }{
497 {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
498 {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
499 {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
500 }
501 for _, tt := range tests {
502 t.Run(tt.name, func(t *testing.T) {
503 dh := tt.devicehandler
504 if err := dh.ReenableDevice(tt.args.device); (err != nil) != tt.wantErr {
505 t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
506 }
507 })
508 }
509}
510
511func TestDeviceHandler_RebootDevice(t *testing.T) {
512 dh1 := newMockDeviceHandler()
513 dh2 := newMockDeviceHandler()
514 type args struct {
515 device *voltha.Device
516 }
517 tests := []struct {
518 name string
519 devicehandler *DeviceHandler
520 args args
521 wantErr bool
522 }{
523 // TODO: Add test cases.
524 {"RebootDevice-1", dh1, args{device: dh1.device}, false},
525 {"RebootDevice-2", dh1, args{device: dh2.device}, true},
526 {"RebootDevice-3", dh2, args{device: dh2.device}, false},
527 }
528 for _, tt := range tests {
529 t.Run(tt.name, func(t *testing.T) {
530
531 if err := tt.devicehandler.RebootDevice(tt.args.device); (err != nil) != tt.wantErr {
532 t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
533 }
534 })
535 }
536}
537
538func TestDeviceHandler_handleIndication(t *testing.T) {
539 dh1 := newMockDeviceHandler()
540 dh2 := negativeDeviceHandler()
541 dh3 := newMockDeviceHandler()
542 dh3.onus = map[string]*OnuDevice{"onu1": NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1"),
543 "onu2": NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2")}
544 type args struct {
545 indication *oop.Indication
546 }
547 tests := []struct {
548 name string
549 deviceHandler *DeviceHandler
550 args args
551 }{
552 // TODO: Add test cases.
553 {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
554 {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
555 {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
556 {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
557 {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
558 {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
559 {"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")}}}}}},
560 {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
561 {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
562 {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
563 {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
564 {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
565 {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
566 {"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}}}}},
567 {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
568 {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
569 {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
570 {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
571
572 // Negative testcases
573 {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
574 {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
575 {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
576 {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
577 {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
578 {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
579 {"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")}}}}}},
580 {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
581 {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
582 {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
583 {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
584 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
585 {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
586 {"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}}}}},
587 {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
588 {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
589 //
590 {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
591 {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
592 {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
593 {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
594 {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
595 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
596 }
597 for _, tt := range tests {
598 t.Run(tt.name, func(t *testing.T) {
599 dh := tt.deviceHandler
600 dh.handleIndication(tt.args.indication)
601 })
602 }
603}
604
605func TestDeviceHandler_addPort(t *testing.T) {
606 dh1 := newMockDeviceHandler()
607 dh2 := negativeDeviceHandler()
608 type args struct {
609 intfID uint32
610 portType voltha.Port_PortType
611 state string
612 }
613 tests := []struct {
614 name string
615 devicehandler *DeviceHandler
616 args args
617 }{
618 // State up
619 {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
620 {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
621 {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
622 {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
623 {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
624 {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
625 {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
626 {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
627 // state discovery
628 {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
629 {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
630 {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
631 {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
632 {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
633 {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
634 {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
635 {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
636
637 {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
638 {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
639 {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
640 {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
641 }
642 for _, tt := range tests {
643 t.Run(tt.name, func(t *testing.T) {
644 tt.devicehandler.addPort(tt.args.intfID, tt.args.portType, tt.args.state)
645 })
646 }
647}
648
649func Test_macAddressToUint32Array(t *testing.T) {
650 type args struct {
651 mac string
652 }
653 tests := []struct {
654 name string
655 args args
656 want []uint32
657 }{
658 // TODO: Add test cases.
659 {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
660 {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
661 {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
662 }
663 for _, tt := range tests {
664 t.Run(tt.name, func(t *testing.T) {
665 if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
666 t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
667 }
668 })
669 }
670}
671
672func TestDeviceHandler_handleOltIndication(t *testing.T) {
673
674 type args struct {
675 oltIndication *oop.OltIndication
676 }
677 tests := []struct {
678 name string
679 args args
680 }{
681 {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
682 {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
683 }
684 for _, tt := range tests {
685 t.Run(tt.name, func(t *testing.T) {
686 dh := newMockDeviceHandler()
687 dh.handleOltIndication(tt.args.oltIndication)
688 })
689 }
690}
691
692func TestDeviceHandler_AdoptDevice(t *testing.T) {
693 dh1 := newMockDeviceHandler()
694 dh2 := negativeDeviceHandler()
695 type args struct {
696 device *voltha.Device
697 }
698 tests := []struct {
699 name string
700 devicehandler *DeviceHandler
701 args args
702 }{
703 // TODO: Add test cases.
704 {"AdoptDevice-1", dh1, args{device: dh1.device}},
705 {"AdoptDevice-1", dh2, args{device: dh2.device}},
706 }
707 for _, tt := range tests {
708 t.Run(tt.name, func(t *testing.T) {
709 //dh.doStateInit()
710 // context.
711 //dh.AdoptDevice(tt.args.device)
712 tt.devicehandler.postInit()
713 })
714 }
715}
716
717func TestDeviceHandler_activateONU(t *testing.T) {
718 dh := newMockDeviceHandler()
719 dh1 := negativeDeviceHandler()
720 type args struct {
721 intfID uint32
722 onuID int64
723 serialNum *oop.SerialNumber
724 serialNumber string
725 }
726 tests := []struct {
727 name string
728 devicehandler *DeviceHandler
729 args args
730 }{
731 {"activateONU-1", dh, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
732 {"activateONU-2", dh, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
733 {"activateONU-3", dh1, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
734 {"activateONU-4", dh1, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
735 }
736 for _, tt := range tests {
737 t.Run(tt.name, func(t *testing.T) {
738
739 tt.devicehandler.activateONU(tt.args.intfID, tt.args.onuID,
740 tt.args.serialNum, tt.args.serialNumber)
741 })
742 }
743}
744
745func TestDeviceHandler_start(t *testing.T) {
746 dh := newMockDeviceHandler()
747 dh1 := negativeDeviceHandler()
748 dh.start(context.Background())
749 dh.stop(context.Background())
750
751 dh1.start(context.Background())
752 dh1.stop(context.Background())
753
754}
755
756func TestDeviceHandler_PacketOut(t *testing.T) {
757 dh1 := newMockDeviceHandler()
758 dh2 := negativeDeviceHandler()
759 acts := []*ofp.OfpAction{
760 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
761 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
762 fu.Output(1),
763 }
764 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
765 type args struct {
766 egressPortNo int
767 packet *of.OfpPacketOut
768 }
769 tests := []struct {
770 name string
771 devicehandler *DeviceHandler
772 args args
773 wantErr bool
774 }{
775 // TODO: Add test cases.
776 //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
777 {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
778 {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
779 {"PacketOut-2", dh2, args{egressPortNo: 115000, packet: pktout}, false},
780 {"PacketOut-3", dh1, args{egressPortNo: 65536, packet: pktout}, false},
781 {"PacketOut-4", dh2, args{egressPortNo: 65535, packet: pktout}, false},
782 }
783 for _, tt := range tests {
784 t.Run(tt.name, func(t *testing.T) {
785 dh := tt.devicehandler
786 if err := dh.PacketOut(tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
787 t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
788 }
789 })
790 }
791}
792
793//
794func TestDeviceHandler_doStateUp(t *testing.T) {
795 dh1 := newMockDeviceHandler()
796 dh2 := newMockDeviceHandler()
797
798 dh2.deviceID = ""
799 dh3 := negativeDeviceHandler()
800
801 tests := []struct {
802 name string
803 devicehandler *DeviceHandler
804 wantErr bool
805 }{
806 {"dostateup-1", dh1, false},
807 {"dostateup-2", dh2, false},
808 {"dostateup-3", dh3, true},
809 }
810 for _, tt := range tests {
811 t.Run(tt.name, func(t *testing.T) {
812 if err := tt.devicehandler.doStateUp(); (err != nil) != tt.wantErr {
813 t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
814 }
815 })
816 }
817}
818func TestDeviceHandler_doStateDown(t *testing.T) {
819 dh1 := newMockDeviceHandler()
820 dh2 := negativeDeviceHandler()
821 dh3 := newMockDeviceHandler()
822 dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
823 tests := []struct {
824 name string
825 devicehandler *DeviceHandler
826 wantErr bool
827 }{
828 {"dostatedown-1", dh1, false},
829 {"dostatedown-2", dh2, true},
830 {"dostatedown-2", dh3, true},
831 }
832 for _, tt := range tests {
833 t.Run(tt.name, func(t *testing.T) {
834 if err := tt.devicehandler.doStateDown(); (err != nil) != tt.wantErr {
835 t.Logf("DeviceHandler.doStateDown() error = %v", err)
836 }
837 })
838 }
839}
840
841func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
842 dh1 := newMockDeviceHandler()
843 dh2 := negativeDeviceHandler()
844 type args struct {
845 device *voltha.Device
846 }
847 tests := []struct {
848 name string
849 devicehandler *DeviceHandler
850 args args
851 wantErr bool
852 }{
853 // TODO: Add test cases.
854 {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
855 {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
856 {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
857 }
858 for _, tt := range tests {
859 t.Run(tt.name, func(t *testing.T) {
860 dh := tt.devicehandler
861 _, err := dh.GetOfpDeviceInfo(tt.args.device)
862 if (err != nil) != tt.wantErr {
863 t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
864 return
865 }
866 })
867 }
868}
869
870func TestDeviceHandler_GetOfpPortInfo(t *testing.T) {
871 dh1 := newMockDeviceHandler()
872 dh2 := negativeDeviceHandler()
873 type args struct {
874 device *voltha.Device
875 portNo int64
876 }
877 tests := []struct {
878 name string
879 devicehandler *DeviceHandler
880 args args
881 wantErr bool
882 }{
883 {"GetOfpPortInfo-1", dh1, args{device: dh1.device, portNo: 1}, false},
884 {"GetOfpPortInfo-2", dh2, args{device: dh2.device, portNo: 1}, false},
885 {"GetOfpPortInfo-3", dh1, args{device: dh1.device, portNo: 0}, false},
886 {"GetOfpPortInfo-4", dh2, args{device: dh2.device, portNo: 0}, false},
887 {"GetOfpPortInfo-5", dh1, args{device: &voltha.Device{}, portNo: 1}, false},
888 {"GetOfpPortInfo-6", dh2, args{device: &voltha.Device{}, portNo: 0}, false},
889 // TODO: Add test cases.
890 }
891 for _, tt := range tests {
892 t.Run(tt.name, func(t *testing.T) {
893 dh := tt.devicehandler
894 _, err := dh.GetOfpPortInfo(tt.args.device, tt.args.portNo)
895 if (err != nil) != tt.wantErr {
896 t.Errorf("DeviceHandler.GetOfpPortInfo() error = %v, wantErr %v", err, tt.wantErr)
897 return
898 }
899 })
900 }
901}
902
903func TestDeviceHandler_onuDiscIndication(t *testing.T) {
904
905 dh1 := newMockDeviceHandler()
906 dh1.discOnus = map[string]bool{"onu1": true, "onu2": false}
907 dh2 := negativeDeviceHandler()
908 type args struct {
909 onuDiscInd *oop.OnuDiscIndication
910 sn string
911 }
912 tests := []struct {
913 name string
914 devicehandler *DeviceHandler
915 args args
916 }{
917 // TODO: Add test cases.
918 {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
919 {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
920 {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
921 {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
922 {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
923 {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}},
924 {"onuDiscIndication-7", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
925 }
926 for _, tt := range tests {
927 t.Run(tt.name, func(t *testing.T) {
928 tt.devicehandler.onuDiscIndication(tt.args.onuDiscInd, tt.args.sn)
929 })
930 }
931}
932
933func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
934 dh1 := newMockDeviceHandler()
935 dh2 := negativeDeviceHandler()
936 tests := []struct {
937 name string
938 devicehandler *DeviceHandler
939
940 wantErr bool
941 }{
942 // TODO: Add test cases.
943 {"populateDeviceInfo-1", dh1, false},
944 {"populateDeviceInfo-2", dh1, true},
945 {"populateDeviceInfo-3", dh1, true},
946 {"populateDeviceInfo-4", dh1, true},
947 {"populateDeviceInfo-5", dh2, true},
948 }
949 for _, tt := range tests {
950 t.Run(tt.name, func(t *testing.T) {
951
952 _, err := tt.devicehandler.populateDeviceInfo()
953 if (err != nil) != tt.wantErr {
954 t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
955 return
956 }
957
958 })
959 }
960}
961
962func TestDeviceHandler_readIndications(t *testing.T) {
963 dh1 := newMockDeviceHandler()
964 dh2 := newMockDeviceHandler()
965 dh2.adminState = "down"
966 dh3 := newMockDeviceHandler()
967 dh3.device.AdminState = voltha.AdminState_DISABLED
968 dh4 := negativeDeviceHandler()
969 tests := []struct {
970 name string
971 devicehandler *DeviceHandler
972 }{
973 // TODO: Add test cases.
974 {"readIndications-1", dh1},
975 {"readIndications-2", dh2},
976 {"readIndications-3", dh2},
977 {"readIndications-4", dh2},
978 {"readIndications-5", dh2},
979 {"readIndications-6", dh3},
980 {"readIndications-7", dh3},
981 {"readIndications-8", dh4},
982 }
983 for _, tt := range tests {
984 t.Run(tt.name, func(t *testing.T) {
985 tt.devicehandler.readIndications()
986 })
987 }
988}