blob: 6e942150f6ff446813930fa1d05200d43da56ab1 [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 Baker51290152019-10-24 14:23:20 -070028 fu "github.com/opencord/voltha-lib-go/v2/pkg/flows"
29 "github.com/opencord/voltha-lib-go/v2/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},
Chaitrashree G S3b4c0352019-09-09 20:59:29 -0400472 {"DisableDevice-2", dh1, args{device: dh2.device}, true},
kdarapu891693b2019-09-16 12:33:49 +0530473 }
474 for _, tt := range tests {
475 t.Run(tt.name, func(t *testing.T) {
476
477 if err := tt.devicehandler.DisableDevice(tt.args.device); (err != nil) != tt.wantErr {
478 t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
479 }
480 })
481 }
482}
483
484func TestDeviceHandler_ReenableDevice(t *testing.T) {
485 dh1 := newMockDeviceHandler()
486 dh2 := negativeDeviceHandler()
487 type args struct {
488 device *voltha.Device
489 }
490 tests := []struct {
491 name string
492 devicehandler *DeviceHandler
493 args args
494 wantErr bool
495 }{
496 {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
497 {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
498 {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
499 }
500 for _, tt := range tests {
501 t.Run(tt.name, func(t *testing.T) {
502 dh := tt.devicehandler
503 if err := dh.ReenableDevice(tt.args.device); (err != nil) != tt.wantErr {
504 t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
505 }
506 })
507 }
508}
509
510func TestDeviceHandler_RebootDevice(t *testing.T) {
511 dh1 := newMockDeviceHandler()
512 dh2 := newMockDeviceHandler()
513 type args struct {
514 device *voltha.Device
515 }
516 tests := []struct {
517 name string
518 devicehandler *DeviceHandler
519 args args
520 wantErr bool
521 }{
522 // TODO: Add test cases.
523 {"RebootDevice-1", dh1, args{device: dh1.device}, false},
524 {"RebootDevice-2", dh1, args{device: dh2.device}, true},
525 {"RebootDevice-3", dh2, args{device: dh2.device}, false},
526 }
527 for _, tt := range tests {
528 t.Run(tt.name, func(t *testing.T) {
529
530 if err := tt.devicehandler.RebootDevice(tt.args.device); (err != nil) != tt.wantErr {
531 t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
532 }
533 })
534 }
535}
536
537func TestDeviceHandler_handleIndication(t *testing.T) {
538 dh1 := newMockDeviceHandler()
539 dh2 := negativeDeviceHandler()
540 dh3 := newMockDeviceHandler()
541 dh3.onus = map[string]*OnuDevice{"onu1": NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1"),
542 "onu2": NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2")}
543 type args struct {
544 indication *oop.Indication
545 }
546 tests := []struct {
547 name string
548 deviceHandler *DeviceHandler
549 args args
550 }{
551 // TODO: Add test cases.
552 {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
553 {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
554 {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
555 {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
556 {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
557 {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
558 {"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")}}}}}},
559 {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
560 {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
561 {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
562 {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
563 {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
564 {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
565 {"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}}}}},
566 {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
567 {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
568 {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
569 {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
570
571 // Negative testcases
572 {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
573 {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
574 {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
575 {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
576 {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
577 {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
578 {"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")}}}}}},
579 {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
580 {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
581 {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
582 {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
583 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
584 {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
585 {"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}}}}},
586 {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
587 {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
588 //
589 {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
590 {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
591 {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
592 {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
593 {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
594 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
595 }
596 for _, tt := range tests {
597 t.Run(tt.name, func(t *testing.T) {
598 dh := tt.deviceHandler
599 dh.handleIndication(tt.args.indication)
600 })
601 }
602}
603
604func TestDeviceHandler_addPort(t *testing.T) {
605 dh1 := newMockDeviceHandler()
606 dh2 := negativeDeviceHandler()
607 type args struct {
608 intfID uint32
609 portType voltha.Port_PortType
610 state string
611 }
612 tests := []struct {
613 name string
614 devicehandler *DeviceHandler
615 args args
616 }{
617 // State up
618 {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
619 {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
620 {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
621 {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
622 {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
623 {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
624 {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
625 {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
626 // state discovery
627 {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
628 {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
629 {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
630 {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
631 {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
632 {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
633 {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
634 {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
635
636 {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
637 {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
638 {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
639 {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
640 }
641 for _, tt := range tests {
642 t.Run(tt.name, func(t *testing.T) {
643 tt.devicehandler.addPort(tt.args.intfID, tt.args.portType, tt.args.state)
644 })
645 }
646}
647
648func Test_macAddressToUint32Array(t *testing.T) {
649 type args struct {
650 mac string
651 }
652 tests := []struct {
653 name string
654 args args
655 want []uint32
656 }{
657 // TODO: Add test cases.
658 {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
659 {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
660 {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
661 }
662 for _, tt := range tests {
663 t.Run(tt.name, func(t *testing.T) {
664 if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
665 t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
666 }
667 })
668 }
669}
670
671func TestDeviceHandler_handleOltIndication(t *testing.T) {
672
673 type args struct {
674 oltIndication *oop.OltIndication
675 }
676 tests := []struct {
677 name string
678 args args
679 }{
680 {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
681 {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
682 }
683 for _, tt := range tests {
684 t.Run(tt.name, func(t *testing.T) {
685 dh := newMockDeviceHandler()
686 dh.handleOltIndication(tt.args.oltIndication)
687 })
688 }
689}
690
691func TestDeviceHandler_AdoptDevice(t *testing.T) {
692 dh1 := newMockDeviceHandler()
693 dh2 := negativeDeviceHandler()
694 type args struct {
695 device *voltha.Device
696 }
697 tests := []struct {
698 name string
699 devicehandler *DeviceHandler
700 args args
701 }{
702 // TODO: Add test cases.
703 {"AdoptDevice-1", dh1, args{device: dh1.device}},
704 {"AdoptDevice-1", dh2, args{device: dh2.device}},
705 }
706 for _, tt := range tests {
707 t.Run(tt.name, func(t *testing.T) {
708 //dh.doStateInit()
709 // context.
710 //dh.AdoptDevice(tt.args.device)
711 tt.devicehandler.postInit()
712 })
713 }
714}
715
716func TestDeviceHandler_activateONU(t *testing.T) {
717 dh := newMockDeviceHandler()
718 dh1 := negativeDeviceHandler()
719 type args struct {
720 intfID uint32
721 onuID int64
722 serialNum *oop.SerialNumber
723 serialNumber string
724 }
725 tests := []struct {
726 name string
727 devicehandler *DeviceHandler
728 args args
729 }{
730 {"activateONU-1", dh, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
731 {"activateONU-2", dh, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
732 {"activateONU-3", dh1, args{intfID: 1, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
733 {"activateONU-4", dh1, args{intfID: 2, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
734 }
735 for _, tt := range tests {
736 t.Run(tt.name, func(t *testing.T) {
737
738 tt.devicehandler.activateONU(tt.args.intfID, tt.args.onuID,
739 tt.args.serialNum, tt.args.serialNumber)
740 })
741 }
742}
743
744func TestDeviceHandler_start(t *testing.T) {
745 dh := newMockDeviceHandler()
746 dh1 := negativeDeviceHandler()
747 dh.start(context.Background())
748 dh.stop(context.Background())
749
750 dh1.start(context.Background())
751 dh1.stop(context.Background())
752
753}
754
755func TestDeviceHandler_PacketOut(t *testing.T) {
756 dh1 := newMockDeviceHandler()
757 dh2 := negativeDeviceHandler()
758 acts := []*ofp.OfpAction{
759 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
760 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
761 fu.Output(1),
762 }
763 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
764 type args struct {
765 egressPortNo int
766 packet *of.OfpPacketOut
767 }
768 tests := []struct {
769 name string
770 devicehandler *DeviceHandler
771 args args
772 wantErr bool
773 }{
774 // TODO: Add test cases.
775 //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
776 {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
777 {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
778 {"PacketOut-2", dh2, args{egressPortNo: 115000, packet: pktout}, false},
779 {"PacketOut-3", dh1, args{egressPortNo: 65536, packet: pktout}, false},
780 {"PacketOut-4", dh2, args{egressPortNo: 65535, packet: pktout}, false},
781 }
782 for _, tt := range tests {
783 t.Run(tt.name, func(t *testing.T) {
784 dh := tt.devicehandler
785 if err := dh.PacketOut(tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
786 t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
787 }
788 })
789 }
790}
791
792//
793func TestDeviceHandler_doStateUp(t *testing.T) {
794 dh1 := newMockDeviceHandler()
795 dh2 := newMockDeviceHandler()
796
797 dh2.deviceID = ""
798 dh3 := negativeDeviceHandler()
799
800 tests := []struct {
801 name string
802 devicehandler *DeviceHandler
803 wantErr bool
804 }{
805 {"dostateup-1", dh1, false},
806 {"dostateup-2", dh2, false},
807 {"dostateup-3", dh3, true},
808 }
809 for _, tt := range tests {
810 t.Run(tt.name, func(t *testing.T) {
811 if err := tt.devicehandler.doStateUp(); (err != nil) != tt.wantErr {
812 t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
813 }
814 })
815 }
816}
817func TestDeviceHandler_doStateDown(t *testing.T) {
818 dh1 := newMockDeviceHandler()
819 dh2 := negativeDeviceHandler()
820 dh3 := newMockDeviceHandler()
821 dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
822 tests := []struct {
823 name string
824 devicehandler *DeviceHandler
825 wantErr bool
826 }{
827 {"dostatedown-1", dh1, false},
828 {"dostatedown-2", dh2, true},
829 {"dostatedown-2", dh3, true},
830 }
831 for _, tt := range tests {
832 t.Run(tt.name, func(t *testing.T) {
833 if err := tt.devicehandler.doStateDown(); (err != nil) != tt.wantErr {
834 t.Logf("DeviceHandler.doStateDown() error = %v", err)
835 }
836 })
837 }
838}
839
840func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
841 dh1 := newMockDeviceHandler()
842 dh2 := negativeDeviceHandler()
843 type args struct {
844 device *voltha.Device
845 }
846 tests := []struct {
847 name string
848 devicehandler *DeviceHandler
849 args args
850 wantErr bool
851 }{
852 // TODO: Add test cases.
853 {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
854 {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
855 {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
856 }
857 for _, tt := range tests {
858 t.Run(tt.name, func(t *testing.T) {
859 dh := tt.devicehandler
860 _, err := dh.GetOfpDeviceInfo(tt.args.device)
861 if (err != nil) != tt.wantErr {
862 t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
863 return
864 }
865 })
866 }
867}
868
869func TestDeviceHandler_GetOfpPortInfo(t *testing.T) {
870 dh1 := newMockDeviceHandler()
871 dh2 := negativeDeviceHandler()
872 type args struct {
873 device *voltha.Device
874 portNo int64
875 }
876 tests := []struct {
877 name string
878 devicehandler *DeviceHandler
879 args args
880 wantErr bool
881 }{
882 {"GetOfpPortInfo-1", dh1, args{device: dh1.device, portNo: 1}, false},
883 {"GetOfpPortInfo-2", dh2, args{device: dh2.device, portNo: 1}, false},
884 {"GetOfpPortInfo-3", dh1, args{device: dh1.device, portNo: 0}, false},
885 {"GetOfpPortInfo-4", dh2, args{device: dh2.device, portNo: 0}, false},
886 {"GetOfpPortInfo-5", dh1, args{device: &voltha.Device{}, portNo: 1}, false},
887 {"GetOfpPortInfo-6", dh2, args{device: &voltha.Device{}, portNo: 0}, false},
888 // TODO: Add test cases.
889 }
890 for _, tt := range tests {
891 t.Run(tt.name, func(t *testing.T) {
892 dh := tt.devicehandler
893 _, err := dh.GetOfpPortInfo(tt.args.device, tt.args.portNo)
894 if (err != nil) != tt.wantErr {
895 t.Errorf("DeviceHandler.GetOfpPortInfo() error = %v, wantErr %v", err, tt.wantErr)
896 return
897 }
898 })
899 }
900}
901
902func TestDeviceHandler_onuDiscIndication(t *testing.T) {
903
904 dh1 := newMockDeviceHandler()
905 dh1.discOnus = map[string]bool{"onu1": true, "onu2": false}
906 dh2 := negativeDeviceHandler()
907 type args struct {
908 onuDiscInd *oop.OnuDiscIndication
909 sn string
910 }
911 tests := []struct {
912 name string
913 devicehandler *DeviceHandler
914 args args
915 }{
916 // TODO: Add test cases.
917 {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
918 {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
919 {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
920 {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
921 {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
922 {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}},
923 {"onuDiscIndication-7", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
924 }
925 for _, tt := range tests {
926 t.Run(tt.name, func(t *testing.T) {
927 tt.devicehandler.onuDiscIndication(tt.args.onuDiscInd, tt.args.sn)
928 })
929 }
930}
931
932func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
933 dh1 := newMockDeviceHandler()
934 dh2 := negativeDeviceHandler()
935 tests := []struct {
936 name string
937 devicehandler *DeviceHandler
938
939 wantErr bool
940 }{
941 // TODO: Add test cases.
942 {"populateDeviceInfo-1", dh1, false},
943 {"populateDeviceInfo-2", dh1, true},
944 {"populateDeviceInfo-3", dh1, true},
945 {"populateDeviceInfo-4", dh1, true},
946 {"populateDeviceInfo-5", dh2, true},
947 }
948 for _, tt := range tests {
949 t.Run(tt.name, func(t *testing.T) {
950
951 _, err := tt.devicehandler.populateDeviceInfo()
952 if (err != nil) != tt.wantErr {
953 t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
954 return
955 }
956
957 })
958 }
959}
960
961func TestDeviceHandler_readIndications(t *testing.T) {
962 dh1 := newMockDeviceHandler()
963 dh2 := newMockDeviceHandler()
964 dh2.adminState = "down"
965 dh3 := newMockDeviceHandler()
966 dh3.device.AdminState = voltha.AdminState_DISABLED
967 dh4 := negativeDeviceHandler()
968 tests := []struct {
969 name string
970 devicehandler *DeviceHandler
971 }{
972 // TODO: Add test cases.
973 {"readIndications-1", dh1},
974 {"readIndications-2", dh2},
975 {"readIndications-3", dh2},
976 {"readIndications-4", dh2},
977 {"readIndications-5", dh2},
978 {"readIndications-6", dh3},
979 {"readIndications-7", dh3},
980 {"readIndications-8", dh4},
981 }
982 for _, tt := range tests {
983 t.Run(tt.name, func(t *testing.T) {
984 tt.devicehandler.readIndications()
985 })
986 }
987}