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