blob: 68309ad412eb32e1fad779c4cd8ea6ea7bff55bb [file] [log] [blame]
kdarapu381c6902019-07-31 18:23:16 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu381c6902019-07-31 18:23:16 +053019
20import (
kdarapu891693b2019-09-16 12:33:49 +053021 "context"
kdarapu381c6902019-07-31 18:23:16 +053022 "net"
kdarapu891693b2019-09-16 12:33:49 +053023 "reflect"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053024 "sync"
kdarapu381c6902019-07-31 18:23:16 +053025 "testing"
Naga Manjunath7615e552019-10-11 22:35:47 +053026 "time"
27
kdarapu891693b2019-09-16 12:33:49 +053028 "github.com/golang/protobuf/ptypes"
29 "github.com/golang/protobuf/ptypes/any"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070030 "github.com/opencord/voltha-lib-go/v4/pkg/db"
31 fu "github.com/opencord/voltha-lib-go/v4/pkg/flows"
32 "github.com/opencord/voltha-lib-go/v4/pkg/log"
33 "github.com/opencord/voltha-lib-go/v4/pkg/pmmetrics"
34 ponrmgr "github.com/opencord/voltha-lib-go/v4/pkg/ponresourcemanager"
kesavand494c2082020-08-31 11:16:12 +053035 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053036 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Scott Bakerdbd960e2020-02-28 08:57:51 -080037 "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
38 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070039 ic "github.com/opencord/voltha-protos/v4/go/inter_container"
40 of "github.com/opencord/voltha-protos/v4/go/openflow_13"
41 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
42 oop "github.com/opencord/voltha-protos/v4/go/openolt"
43 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapu381c6902019-07-31 18:23:16 +053044)
45
Girish Gowdra9602eb42020-09-09 15:50:39 -070046const (
Girish Gowdrafb3d6102020-10-16 16:32:36 -070047 NumPonPorts = 16
Girish Gowdra9602eb42020-09-09 15:50:39 -070048 OnuIDStart = 1
49 OnuIDEnd = 32
50 AllocIDStart = 1
51 AllocIDEnd = 10
52 GemIDStart = 1
53 GemIDEnd = 10
54 FlowIDStart = 1
55 FlowIDEnd = 10
56)
57
kdarapu891693b2019-09-16 12:33:49 +053058func newMockCoreProxy() *mocks.MockCoreProxy {
Kent Hagermanf1db18b2020-07-08 13:38:15 -040059 mcp := mocks.MockCoreProxy{
60 Devices: make(map[string]*voltha.Device),
61 DevicePorts: make(map[string][]*voltha.Port),
62 }
Naga Manjunath7615e552019-10-11 22:35:47 +053063 var pm []*voltha.PmConfig
kdarapu891693b2019-09-16 12:33:49 +053064 mcp.Devices["olt"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053065 Id: "olt",
66 Root: true,
67 ParentId: "logical_device",
68 ParentPortNo: 1,
kdarapu891693b2019-09-16 12:33:49 +053069 ProxyAddress: &voltha.Device_ProxyAddress{
70 DeviceId: "olt",
71 DeviceType: "onu",
72 ChannelId: 1,
73 ChannelGroupId: 1,
74 },
75 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +053076 PmConfigs: &voltha.PmConfigs{
77 DefaultFreq: 10,
78 Id: "olt",
79 FreqOverride: false,
80 Grouped: false,
81 Metrics: pm,
82 },
kdarapu891693b2019-09-16 12:33:49 +053083 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -040084 mcp.DevicePorts["olt"] = []*voltha.Port{
85 {PortNo: 1, Label: "pon"},
86 {PortNo: 2, Label: "nni"},
87 }
kdarapu891693b2019-09-16 12:33:49 +053088
Kent Hagermanf1db18b2020-07-08 13:38:15 -040089 mcp.Devices["onu1"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053090 Id: "1",
91 Root: false,
92 ParentId: "olt",
93 ParentPortNo: 1,
94
kdarapu891693b2019-09-16 12:33:49 +053095 OperStatus: 4,
96 ProxyAddress: &voltha.Device_ProxyAddress{
97 OnuId: 1,
98 ChannelId: 1,
99 ChannelGroupId: 1,
100 },
101 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530102 PmConfigs: &voltha.PmConfigs{
103 DefaultFreq: 10,
104 Id: "olt",
105 FreqOverride: false,
106 Grouped: false,
107 Metrics: pm,
108 },
kdarapu891693b2019-09-16 12:33:49 +0530109 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400110 mcp.DevicePorts["onu1"] = []*voltha.Port{
111 {PortNo: 1, Label: "pon"},
112 {PortNo: 2, Label: "uni"},
113 }
114
kdarapu891693b2019-09-16 12:33:49 +0530115 mcp.Devices["onu2"] = &voltha.Device{
116 Id: "2",
117 Root: false,
118 ParentId: "olt",
119 OperStatus: 2,
kdarapu891693b2019-09-16 12:33:49 +0530120
121 ParentPortNo: 1,
122
123 ProxyAddress: &voltha.Device_ProxyAddress{
124 OnuId: 2,
125 ChannelId: 1,
126 ChannelGroupId: 1,
127 },
128 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530129 PmConfigs: &voltha.PmConfigs{
130 DefaultFreq: 10,
131 Id: "olt",
132 FreqOverride: false,
133 Grouped: false,
134 Metrics: pm,
135 },
kdarapu891693b2019-09-16 12:33:49 +0530136 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400137 mcp.DevicePorts["onu2"] = []*voltha.Port{
138 {PortNo: 1, Label: "pon"},
139 {PortNo: 2, Label: "uni"},
140 }
kdarapu891693b2019-09-16 12:33:49 +0530141 return &mcp
142}
143func newMockDeviceHandler() *DeviceHandler {
kdarapu381c6902019-07-31 18:23:16 +0530144 device := &voltha.Device{
145 Id: "olt",
146 Root: true,
147 ParentId: "logical_device",
kdarapu891693b2019-09-16 12:33:49 +0530148 ProxyAddress: &voltha.Device_ProxyAddress{
149 DeviceId: "olt",
150 DeviceType: "onu",
151 ChannelId: 1,
152 ChannelGroupId: 1,
153 },
154 ConnectStatus: 1,
kdarapu381c6902019-07-31 18:23:16 +0530155 }
kdarapu891693b2019-09-16 12:33:49 +0530156 cp := newMockCoreProxy()
157 ap := &mocks.MockAdapterProxy{}
158 ep := &mocks.MockEventProxy{}
kesavand494c2082020-08-31 11:16:12 +0530159 cfg := &config.AdapterFlags{OmccEncryption: true}
160 openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep, config: cfg}
kdarapu891693b2019-09-16 12:33:49 +0530161 dh := NewDeviceHandler(cp, ap, ep, device, openOLT)
Girish Gowdra38d533d2020-03-30 20:38:51 -0700162 oopRanges := []*oop.DeviceInfo_DeviceResourceRanges{{
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700163 IntfIds: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
Girish Gowdra38d533d2020-03-30 20:38:51 -0700164 Technology: "xgs-pon",
165 Pools: []*oop.DeviceInfo_DeviceResourceRanges_Pool{{}},
166 }}
167
Girish Gowdra9602eb42020-09-09 15:50:39 -0700168 deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: oopRanges, Model: "openolt", DeviceId: dh.device.Id, PonPorts: NumPonPorts}
Thomas Lee S985938d2020-05-04 11:40:41 +0530169 rsrMgr := resourcemanager.OpenOltResourceMgr{DeviceID: dh.device.Id, DeviceType: dh.device.Type, DevInfo: deviceInf,
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530170 KVStore: &db.Backend{
171 Client: &mocks.MockKVClient{},
172 }}
Girish Gowdra38d533d2020-03-30 20:38:51 -0700173 rsrMgr.AllocIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
174 rsrMgr.GemPortIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
175 rsrMgr.OnuIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
176
177 dh.resourceMgr = &rsrMgr
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530178 dh.resourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
179 ranges := make(map[string]interface{})
180 sharedIdxByType := make(map[string]string)
181 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
182 sharedIdxByType["ONU_ID"] = "ONU_ID"
183 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
184 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
185 ranges["ONU_ID"] = uint32(0)
186 ranges["GEMPORT_ID"] = uint32(0)
187 ranges["ALLOC_ID"] = uint32(0)
188 ranges["FLOW_ID"] = uint32(0)
189 ranges["onu_id_shared"] = uint32(0)
190 ranges["alloc_id_shared"] = uint32(0)
191 ranges["gemport_id_shared"] = uint32(0)
192 ranges["flow_id_shared"] = uint32(0)
193
194 ponmgr := &ponrmgr.PONResourceManager{
195 DeviceID: "onu-1",
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700196 IntfIDs: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530197 KVStore: &db.Backend{
198 Client: &mocks.MockKVClient{},
199 },
200 PonResourceRanges: ranges,
201 SharedIdxByType: sharedIdxByType,
202 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700203 for i := 0; i < NumPonPorts; i++ {
204 dh.resourceMgr.ResourceMgrs[uint32(i)] = ponmgr
205 }
npujarec5762e2020-01-01 14:08:48 +0530206 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
207 defer cancel()
Girish Gowdra9602eb42020-09-09 15:50:39 -0700208 dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr)
209 dh.totalPonPorts = NumPonPorts
210 dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts)
211 for i := 0; i < int(dh.totalPonPorts); i++ {
212 // Instantiate flow manager
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700213 if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr, dh.groupMgr, uint32(i)); dh.flowMgr[i] == nil {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700214 return nil
215 }
216 }
kdarapu891693b2019-09-16 12:33:49 +0530217 dh.Client = &mocks.MockOpenoltClient{}
kesavand39e0aa32020-01-28 20:58:50 -0500218 dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}, handler: dh}
kdarapu891693b2019-09-16 12:33:49 +0530219 dh.transitionMap = &TransitionMap{}
Naga Manjunath7615e552019-10-11 22:35:47 +0530220 dh.portStats = &OpenOltStatisticsMgr{}
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000221
222 var pmNames = []string{
223 "rx_bytes",
224 "rx_packets",
225 "rx_mcast_packets",
226 "rx_bcast_packets",
227 "tx_bytes",
228 "tx_packets",
229 "tx_mcast_packets",
230 "tx_bcast_packets",
231 }
232
233 dh.metrics = pmmetrics.NewPmMetrics(device.Id, pmmetrics.Frequency(2), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
kdarapu891693b2019-09-16 12:33:49 +0530234 return dh
kdarapu381c6902019-07-31 18:23:16 +0530235}
236
kdarapu891693b2019-09-16 12:33:49 +0530237func negativeDeviceHandler() *DeviceHandler {
238 dh := newMockDeviceHandler()
239 device := dh.device
240 device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530241 return dh
242}
kdarapu381c6902019-07-31 18:23:16 +0530243func Test_generateMacFromHost(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000244 ctx := context.Background()
kdarapu381c6902019-07-31 18:23:16 +0530245 type args struct {
246 host string
247 }
248 tests := []struct {
249 name string
250 args args
251 want string
252 wantErr bool
253 }{
kdarapu891693b2019-09-16 12:33:49 +0530254 {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
255 {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
256 //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false},
257 {"generateMacFromHost-4", args{host: "testing3"}, "", true},
kdarapu381c6902019-07-31 18:23:16 +0530258 }
259 for _, tt := range tests {
260 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000261 got, err := generateMacFromHost(ctx, tt.args.host)
kdarapu381c6902019-07-31 18:23:16 +0530262 if (err != nil) != tt.wantErr {
263 t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr)
264 return
265 }
266 if got != tt.want {
267 t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want)
268 }
269 })
270 }
271}
272func Test_macifyIP(t *testing.T) {
273 type args struct {
274 ip net.IP
275 }
276 tests := []struct {
277 name string
278 args args
279 want string
280 }{{
kdarapu891693b2019-09-16 12:33:49 +0530281 "macifyIP-1",
kdarapu381c6902019-07-31 18:23:16 +0530282 args{ip: net.ParseIP("10.10.10.10")},
283 "00:00:0a:0a:0a:0a",
284 },
285 {
kdarapu891693b2019-09-16 12:33:49 +0530286 "macifyIP-2",
kdarapu381c6902019-07-31 18:23:16 +0530287 args{ip: net.ParseIP("127.0.0.1")},
288 "00:00:7f:00:00:01",
kdarapu891693b2019-09-16 12:33:49 +0530289 },
290 {
291 "macifyIP-3",
292 args{ip: net.ParseIP("127.0.0.1/24")},
293 "",
294 },
295 }
kdarapu381c6902019-07-31 18:23:16 +0530296 for _, tt := range tests {
297 t.Run(tt.name, func(t *testing.T) {
298 if got := macifyIP(tt.args.ip); got != tt.want {
299 t.Errorf("macifyIP() = %v, want %v", got, tt.want)
300 }
301 })
302 }
303}
304
David K. Bainbridge794735f2020-02-11 21:01:37 -0800305func sparseCompare(keys []string, spec, target interface{}) bool {
306 if spec == target {
307 return true
308 }
309 if spec == nil || target == nil {
310 return false
311 }
312 typeSpec := reflect.TypeOf(spec)
313 typeTarget := reflect.TypeOf(target)
314 if typeSpec != typeTarget {
315 return false
316 }
317
318 vSpec := reflect.ValueOf(spec)
319 vTarget := reflect.ValueOf(target)
320 if vSpec.Kind() == reflect.Ptr {
321 vSpec = vSpec.Elem()
322 vTarget = vTarget.Elem()
323 }
324
325 for _, key := range keys {
326 fSpec := vSpec.FieldByName(key)
327 fTarget := vTarget.FieldByName(key)
328 if !reflect.DeepEqual(fSpec.Interface(), fTarget.Interface()) {
329 return false
330 }
331 }
332 return true
333}
334
kdarapu381c6902019-07-31 18:23:16 +0530335func TestDeviceHandler_GetChildDevice(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000336 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530337 dh1 := newMockDeviceHandler()
338 dh2 := negativeDeviceHandler()
kdarapu381c6902019-07-31 18:23:16 +0530339 type args struct {
340 parentPort uint32
341 onuID uint32
342 }
343 tests := []struct {
kdarapu891693b2019-09-16 12:33:49 +0530344 name string
345 devicehandler *DeviceHandler
346 args args
347 want *voltha.Device
David K. Bainbridge794735f2020-02-11 21:01:37 -0800348 errType reflect.Type
kdarapu381c6902019-07-31 18:23:16 +0530349 }{
kdarapu891693b2019-09-16 12:33:49 +0530350 {"GetChildDevice-1", dh1,
351 args{parentPort: 1,
352 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800353 &voltha.Device{
354 Id: "1",
355 ParentId: "olt",
356 ParentPortNo: 1,
357 },
358 nil,
kdarapu891693b2019-09-16 12:33:49 +0530359 },
360 {"GetChildDevice-2", dh2,
kdarapu381c6902019-07-31 18:23:16 +0530361 args{parentPort: 1,
362 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800363 nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530364 reflect.TypeOf(&olterrors.ErrNotFound{}),
kdarapu381c6902019-07-31 18:23:16 +0530365 },
366 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800367
368 /*
369 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-1 (0.00s)
370 device_handler_test.go:309: GetportLabel() => want=(, <nil>) got=(id:"1" parent_id:"olt" parent_port_no:1 proxy_address:<channel_id:1 channel_group_id:1 onu_id:1 > oper_status:ACTIVE connect_status:UNREACHABLE ports:<port_no:1 label:"pon" > ports:<port_no:2 label:"uni" > pm_configs:<id:"olt" default_freq:10 > , <nil>)
371 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-2 (0.00s)
372 */
kdarapu381c6902019-07-31 18:23:16 +0530373 for _, tt := range tests {
374 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000375 got, err := tt.devicehandler.GetChildDevice(ctx, tt.args.parentPort, tt.args.onuID)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800376 if reflect.TypeOf(err) != tt.errType || !sparseCompare([]string{"Id", "ParentId", "ParentPortNo"}, tt.want, got) {
377 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
378 tt.want, tt.errType, got, reflect.TypeOf(err))
379 return
380 }
kdarapu381c6902019-07-31 18:23:16 +0530381 t.Log("onu device id", got)
382 })
383 }
384}
kdarapu891693b2019-09-16 12:33:49 +0530385
386func TestGetportLabel(t *testing.T) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530387 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530388 type args struct {
389 portNum uint32
390 portType voltha.Port_PortType
391 }
392 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800393 name string
394 args args
395 want string
396 errType reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530397 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800398 {"GetportLabel-1", args{portNum: 0, portType: 0}, "", invalid},
399 {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1", nil},
400 {"GetportLabel-3", args{portNum: 2, portType: 2}, "", invalid},
401 {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3", nil},
402 {"GetportLabel-5", args{portNum: 4, portType: 4}, "", invalid},
403 {"GetportLabel-6", args{portNum: 5, portType: 5}, "", invalid},
404 {"GetportLabel-7", args{portNum: 6, portType: 6}, "", invalid},
kdarapu891693b2019-09-16 12:33:49 +0530405 }
406 for _, tt := range tests {
407 t.Run(tt.name, func(t *testing.T) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800408 got, err := GetportLabel(tt.args.portNum, tt.args.portType)
409 if reflect.TypeOf(err) != tt.errType || got != tt.want {
410 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
411 tt.want, tt.errType, got, reflect.TypeOf(err))
kdarapu891693b2019-09-16 12:33:49 +0530412 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800413
kdarapu891693b2019-09-16 12:33:49 +0530414 })
415 }
416}
417
418func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000419 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530420 dh := newMockDeviceHandler()
421 proxyAddr := dh.device.ProxyAddress
422 body := &ic.InterAdapterOmciMessage{
423 Message: []byte("asdfasdfasdfasdfas"),
424 ProxyAddress: proxyAddr,
425 }
426 body2 := &ic.InterAdapterOmciMessage{
427 Message: []byte("asdfasdfasdfasdfas"),
428 //ProxyAddress: &voltha.Device_ProxyAddress{},
429 }
430 body3 := &ic.InterAdapterTechProfileDownloadMessage{}
431 var marshalledData *any.Any
432 var err error
433
434 if marshalledData, err = ptypes.MarshalAny(body); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000435 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530436 }
437
438 var marshalledData1 *any.Any
439
440 if marshalledData1, err = ptypes.MarshalAny(body2); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000441 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530442 }
443 var marshalledData2 *any.Any
444
445 if marshalledData2, err = ptypes.MarshalAny(body3); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000446 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530447 }
448 type args struct {
449 msg *ic.InterAdapterMessage
450 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530451 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530452 tests := []struct {
453 name string
454 args args
David K. Bainbridge794735f2020-02-11 21:01:37 -0800455 wantErr reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530456 }{
457 {"ProcessInterAdapterMessage-1", args{msg: &ic.InterAdapterMessage{
458 Header: &ic.InterAdapterHeader{
459 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800460 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530461 },
462 Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800463 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530464 {"ProcessInterAdapterMessage-2", args{msg: &ic.InterAdapterMessage{
465 Header: &ic.InterAdapterHeader{
466 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800467 Type: ic.InterAdapterMessageType_FLOW_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530468 },
469 Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800470 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530471 {"ProcessInterAdapterMessage-3", args{msg: &ic.InterAdapterMessage{
472 Header: &ic.InterAdapterHeader{
473 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800474 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530475 },
476 Body: marshalledData,
Thomas Lee S94109f12020-03-03 16:39:29 +0530477 }}, reflect.TypeOf(&olterrors.ErrCommunication{})},
kdarapu891693b2019-09-16 12:33:49 +0530478 {"ProcessInterAdapterMessage-4", args{msg: &ic.InterAdapterMessage{
479 Header: &ic.InterAdapterHeader{
480 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800481 Type: ic.InterAdapterMessageType_OMCI_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530482 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800483 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530484 {"ProcessInterAdapterMessage-5", args{msg: &ic.InterAdapterMessage{
485 Header: &ic.InterAdapterHeader{
486 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800487 Type: ic.InterAdapterMessageType_METRICS_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530488 }, Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800489 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530490 {"ProcessInterAdapterMessage-6", args{msg: &ic.InterAdapterMessage{
491 Header: &ic.InterAdapterHeader{
492 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800493 Type: ic.InterAdapterMessageType_METRICS_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530494 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800495 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530496 {"ProcessInterAdapterMessage-7", args{msg: &ic.InterAdapterMessage{
497 Header: &ic.InterAdapterHeader{
498 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800499 Type: ic.InterAdapterMessageType_ONU_IND_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530500 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800501 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530502 {"ProcessInterAdapterMessage-8", args{msg: &ic.InterAdapterMessage{
503 Header: &ic.InterAdapterHeader{
504 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800505 Type: ic.InterAdapterMessageType_ONU_IND_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530506 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800507 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530508 {"ProcessInterAdapterMessage-9", args{msg: &ic.InterAdapterMessage{
509 Header: &ic.InterAdapterHeader{
510 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800511 Type: ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530512 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800513 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530514 {"ProcessInterAdapterMessage-10", args{msg: &ic.InterAdapterMessage{
515 Header: &ic.InterAdapterHeader{
516 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800517 Type: ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530518 }, Body: marshalledData2,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800519 }}, invalid},
520 {"ProcessInterAdapterMessage-11", args{msg: &ic.InterAdapterMessage{
521 Header: &ic.InterAdapterHeader{
522 Id: "012345",
523 Type: ic.InterAdapterMessageType_DELETE_TCONT_REQUEST,
524 }, Body: marshalledData2,
525 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530526 }
527 for _, tt := range tests {
528 t.Run(tt.name, func(t *testing.T) {
529
Neha Sharma96b7bf22020-06-15 10:37:32 +0000530 if err := dh.ProcessInterAdapterMessage(ctx, tt.args.msg); reflect.TypeOf(err) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530531 t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr)
532 }
533 })
534 }
535}
536
537func TestDeviceHandler_sendProxiedMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000538 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530539 dh1 := newMockDeviceHandler()
540 dh2 := negativeDeviceHandler()
541 device1 := &voltha.Device{
542 Id: "onu1",
543 Root: false,
544 ParentId: "logical_device",
545 ProxyAddress: &voltha.Device_ProxyAddress{
546 DeviceId: "onu1",
547 DeviceType: "onu",
548 ChannelId: 1,
549 ChannelGroupId: 1,
550 },
551 ConnectStatus: 1,
552 }
553 device2 := device1
554 device2.ConnectStatus = 2
555 iaomciMsg1 := &ic.InterAdapterOmciMessage{
556 ProxyAddress: &voltha.Device_ProxyAddress{
557 DeviceId: "onu2",
558 DeviceType: "onu",
559 ChannelId: 1,
560 ChannelGroupId: 1,
561 //OnuId: 2,
562 },
563 ConnectStatus: 1,
564 }
565 iaomciMsg2 := &ic.InterAdapterOmciMessage{
566 ProxyAddress: &voltha.Device_ProxyAddress{
567 DeviceId: "onu3",
568 DeviceType: "onu",
569 ChannelId: 1,
570 ChannelGroupId: 1,
571 },
572 ConnectStatus: 1,
573 }
574 type args struct {
575 onuDevice *voltha.Device
576 omciMsg *ic.InterAdapterOmciMessage
577 }
578 tests := []struct {
579 name string
580 devicehandler *DeviceHandler
581 args args
582 }{
583 {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
584 {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ic.InterAdapterOmciMessage{}}},
585 {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}},
586 {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}},
587 {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}},
588 {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
589 }
590 for _, tt := range tests {
591 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400592 _ = tt.devicehandler.sendProxiedMessage(ctx, tt.args.onuDevice, tt.args.omciMsg)
593 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530594 })
595 }
596}
597
598func TestDeviceHandler_SendPacketInToCore(t *testing.T) {
599 dh1 := newMockDeviceHandler()
600 dh2 := negativeDeviceHandler()
601
602 type args struct {
603 logicalPort uint32
604 packetPayload []byte
605 }
606 tests := []struct {
607 name string
608 devicehandler *DeviceHandler
609 args args
610 }{
611 {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}},
612 {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}},
613 {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}},
614 }
615 for _, tt := range tests {
616 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400617 _ = tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload)
618 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530619 })
620 }
621}
622
623func TestDeviceHandler_DisableDevice(t *testing.T) {
624 dh1 := newMockDeviceHandler()
625 dh2 := negativeDeviceHandler()
626 type args struct {
627 device *voltha.Device
628 }
629 tests := []struct {
630 name string
631 devicehandler *DeviceHandler
632 args args
633 wantErr bool
634 }{
635 {"DisableDevice-1", dh1, args{device: dh1.device}, false},
Chaitrashree G S3b4c0352019-09-09 20:59:29 -0400636 {"DisableDevice-2", dh1, args{device: dh2.device}, true},
kdarapu891693b2019-09-16 12:33:49 +0530637 }
638 for _, tt := range tests {
639 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000640 if err := tt.devicehandler.DisableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530641 t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
642 }
643 })
644 }
645}
646
647func TestDeviceHandler_ReenableDevice(t *testing.T) {
648 dh1 := newMockDeviceHandler()
649 dh2 := negativeDeviceHandler()
650 type args struct {
651 device *voltha.Device
652 }
653 tests := []struct {
654 name string
655 devicehandler *DeviceHandler
656 args args
657 wantErr bool
658 }{
659 {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
660 {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
661 {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
662 }
663 for _, tt := range tests {
664 t.Run(tt.name, func(t *testing.T) {
665 dh := tt.devicehandler
Neha Sharma96b7bf22020-06-15 10:37:32 +0000666 if err := dh.ReenableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530667 t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
668 }
669 })
670 }
671}
672
673func TestDeviceHandler_RebootDevice(t *testing.T) {
674 dh1 := newMockDeviceHandler()
675 dh2 := newMockDeviceHandler()
676 type args struct {
677 device *voltha.Device
678 }
679 tests := []struct {
680 name string
681 devicehandler *DeviceHandler
682 args args
683 wantErr bool
684 }{
685 // TODO: Add test cases.
686 {"RebootDevice-1", dh1, args{device: dh1.device}, false},
687 {"RebootDevice-2", dh1, args{device: dh2.device}, true},
688 {"RebootDevice-3", dh2, args{device: dh2.device}, false},
689 }
690 for _, tt := range tests {
691 t.Run(tt.name, func(t *testing.T) {
692
Neha Sharma96b7bf22020-06-15 10:37:32 +0000693 if err := tt.devicehandler.RebootDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530694 t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
695 }
696 })
697 }
698}
699
700func TestDeviceHandler_handleIndication(t *testing.T) {
701 dh1 := newMockDeviceHandler()
702 dh2 := negativeDeviceHandler()
703 dh3 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530704 dh3.onus = sync.Map{}
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530705 dh3.onus.Store("onu1", NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1", false))
706 dh3.onus.Store("onu2", NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2", false))
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530707
kdarapu891693b2019-09-16 12:33:49 +0530708 type args struct {
709 indication *oop.Indication
710 }
711 tests := []struct {
712 name string
713 deviceHandler *DeviceHandler
714 args args
715 }{
716 // TODO: Add test cases.
717 {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
718 {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
719 {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
720 {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
721 {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
722 {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
723 {"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")}}}}}},
724 {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
725 {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
726 {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
727 {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
728 {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
729 {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
730 {"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}}}}},
731 {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
732 {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
733 {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
734 {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
735
736 // Negative testcases
737 {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
738 {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
739 {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
740 {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
741 {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
742 {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
743 {"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")}}}}}},
744 {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
745 {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
746 {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
747 {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
748 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
749 {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
750 {"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}}}}},
751 {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
752 {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
753 //
754 {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
755 {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
756 {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
757 {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
758 {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
759 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
760 }
761 for _, tt := range tests {
762 t.Run(tt.name, func(t *testing.T) {
763 dh := tt.deviceHandler
npujarec5762e2020-01-01 14:08:48 +0530764 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
765 defer cancel()
766 dh.handleIndication(ctx, tt.args.indication)
kdarapu891693b2019-09-16 12:33:49 +0530767 })
768 }
769}
770
771func TestDeviceHandler_addPort(t *testing.T) {
772 dh1 := newMockDeviceHandler()
773 dh2 := negativeDeviceHandler()
774 type args struct {
775 intfID uint32
776 portType voltha.Port_PortType
777 state string
778 }
779 tests := []struct {
780 name string
781 devicehandler *DeviceHandler
782 args args
783 }{
784 // State up
785 {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
786 {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
787 {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
788 {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
789 {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
790 {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
791 {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
792 {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
793 // state discovery
794 {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
795 {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
796 {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
797 {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
798 {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
799 {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
800 {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
801 {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
802
803 {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
804 {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
805 {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
806 {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
807 }
808 for _, tt := range tests {
809 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400810 _ = tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state)
811 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530812 })
813 }
814}
815
816func Test_macAddressToUint32Array(t *testing.T) {
817 type args struct {
818 mac string
819 }
820 tests := []struct {
821 name string
822 args args
823 want []uint32
824 }{
825 // TODO: Add test cases.
826 {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
827 {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
828 {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
829 }
830 for _, tt := range tests {
831 t.Run(tt.name, func(t *testing.T) {
832 if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
833 t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
834 }
835 })
836 }
837}
838
839func TestDeviceHandler_handleOltIndication(t *testing.T) {
840
841 type args struct {
842 oltIndication *oop.OltIndication
843 }
844 tests := []struct {
845 name string
846 args args
847 }{
848 {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
849 {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
850 }
851 for _, tt := range tests {
852 t.Run(tt.name, func(t *testing.T) {
853 dh := newMockDeviceHandler()
npujarec5762e2020-01-01 14:08:48 +0530854 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
855 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400856 if err := dh.handleOltIndication(ctx, tt.args.oltIndication); err != nil {
857 t.Error(err)
858 }
kdarapu891693b2019-09-16 12:33:49 +0530859 })
860 }
861}
862
863func TestDeviceHandler_AdoptDevice(t *testing.T) {
864 dh1 := newMockDeviceHandler()
865 dh2 := negativeDeviceHandler()
866 type args struct {
867 device *voltha.Device
868 }
869 tests := []struct {
870 name string
871 devicehandler *DeviceHandler
872 args args
873 }{
874 // TODO: Add test cases.
875 {"AdoptDevice-1", dh1, args{device: dh1.device}},
Naga Manjunath7615e552019-10-11 22:35:47 +0530876 {"AdoptDevice-2", dh2, args{device: dh2.device}},
kdarapu891693b2019-09-16 12:33:49 +0530877 }
878 for _, tt := range tests {
879 t.Run(tt.name, func(t *testing.T) {
880 //dh.doStateInit()
881 // context.
882 //dh.AdoptDevice(tt.args.device)
npujarec5762e2020-01-01 14:08:48 +0530883 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
884 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400885 if err := tt.devicehandler.postInit(ctx); err != nil {
886 t.Error(err)
887 }
kdarapu891693b2019-09-16 12:33:49 +0530888 })
889 }
890}
891
892func TestDeviceHandler_activateONU(t *testing.T) {
893 dh := newMockDeviceHandler()
894 dh1 := negativeDeviceHandler()
895 type args struct {
896 intfID uint32
897 onuID int64
898 serialNum *oop.SerialNumber
899 serialNumber string
900 }
901 tests := []struct {
902 name string
903 devicehandler *DeviceHandler
904 args args
905 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700906 {"activateONU-1", dh, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
907 {"activateONU-2", dh, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
908 {"activateONU-3", dh1, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
909 {"activateONU-4", dh1, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
kdarapu891693b2019-09-16 12:33:49 +0530910 }
911 for _, tt := range tests {
912 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530913 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
914 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400915 _ = tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum, tt.args.serialNumber)
916 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530917 })
918 }
919}
920
921func TestDeviceHandler_start(t *testing.T) {
922 dh := newMockDeviceHandler()
923 dh1 := negativeDeviceHandler()
924 dh.start(context.Background())
925 dh.stop(context.Background())
926
927 dh1.start(context.Background())
928 dh1.stop(context.Background())
929
930}
931
932func TestDeviceHandler_PacketOut(t *testing.T) {
933 dh1 := newMockDeviceHandler()
934 dh2 := negativeDeviceHandler()
935 acts := []*ofp.OfpAction{
936 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
937 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
938 fu.Output(1),
939 }
940 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
941 type args struct {
942 egressPortNo int
943 packet *of.OfpPacketOut
944 }
945 tests := []struct {
946 name string
947 devicehandler *DeviceHandler
948 args args
949 wantErr bool
950 }{
951 // TODO: Add test cases.
952 //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
953 {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
954 {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
Matteo Scandolo2c0d2742020-06-10 11:28:42 -0700955 {"PacketOut-3", dh2, args{egressPortNo: 4112, packet: pktout}, false},
956 {"PacketOut-4", dh1, args{egressPortNo: 1048577, packet: pktout}, false},
957 {"PacketOut-5", dh2, args{egressPortNo: 1048576, packet: pktout}, false},
kdarapu891693b2019-09-16 12:33:49 +0530958 }
959 for _, tt := range tests {
960 t.Run(tt.name, func(t *testing.T) {
961 dh := tt.devicehandler
npujarec5762e2020-01-01 14:08:48 +0530962 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
963 defer cancel()
964 if err := dh.PacketOut(ctx, tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530965 t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
966 }
967 })
968 }
969}
970
971//
972func TestDeviceHandler_doStateUp(t *testing.T) {
973 dh1 := newMockDeviceHandler()
974 dh2 := newMockDeviceHandler()
975
Thomas Lee S985938d2020-05-04 11:40:41 +0530976 dh2.device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530977 dh3 := negativeDeviceHandler()
978
979 tests := []struct {
980 name string
981 devicehandler *DeviceHandler
982 wantErr bool
983 }{
984 {"dostateup-1", dh1, false},
985 {"dostateup-2", dh2, false},
986 {"dostateup-3", dh3, true},
987 }
988 for _, tt := range tests {
989 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530990 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
991 defer cancel()
992 if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530993 t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
994 }
Thomas Lee S85f37312020-04-03 17:06:12 +0530995 tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp
kdarapu891693b2019-09-16 12:33:49 +0530996 })
997 }
998}
999func TestDeviceHandler_doStateDown(t *testing.T) {
1000 dh1 := newMockDeviceHandler()
1001 dh2 := negativeDeviceHandler()
1002 dh3 := newMockDeviceHandler()
1003 dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
1004 tests := []struct {
1005 name string
1006 devicehandler *DeviceHandler
1007 wantErr bool
1008 }{
1009 {"dostatedown-1", dh1, false},
1010 {"dostatedown-2", dh2, true},
1011 {"dostatedown-2", dh3, true},
1012 }
1013 for _, tt := range tests {
1014 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301015 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1016 defer cancel()
1017 if err := tt.devicehandler.doStateDown(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +05301018 t.Logf("DeviceHandler.doStateDown() error = %v", err)
Kent Hagermane6ff1012020-07-14 15:07:53 -04001019 //TODO: should fail this test case (Errorf) if result is not as expected
kdarapu891693b2019-09-16 12:33:49 +05301020 }
1021 })
1022 }
1023}
1024
1025func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
1026 dh1 := newMockDeviceHandler()
1027 dh2 := negativeDeviceHandler()
1028 type args struct {
1029 device *voltha.Device
1030 }
1031 tests := []struct {
1032 name string
1033 devicehandler *DeviceHandler
1034 args args
1035 wantErr bool
1036 }{
1037 // TODO: Add test cases.
1038 {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
1039 {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
1040 {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
1041 }
1042 for _, tt := range tests {
1043 t.Run(tt.name, func(t *testing.T) {
1044 dh := tt.devicehandler
1045 _, err := dh.GetOfpDeviceInfo(tt.args.device)
1046 if (err != nil) != tt.wantErr {
1047 t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1048 return
1049 }
1050 })
1051 }
1052}
1053
kdarapu891693b2019-09-16 12:33:49 +05301054func TestDeviceHandler_onuDiscIndication(t *testing.T) {
1055
1056 dh1 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +05301057 dh1.discOnus = sync.Map{}
1058 dh1.discOnus.Store("onu1", true)
1059 dh1.discOnus.Store("onu2", false)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +05301060 dh1.discOnus.Store("onu3", true)
1061 dh1.discOnus.Store("onu4", true)
1062 dh1.onus = sync.Map{}
1063 dh1.onus.Store("onu3", NewOnuDevice("onu3", "onu3", "onu3", 3, 3, "onu3", true))
1064 dh1.onus.Store("onu4", NewOnuDevice("onu4", "onu4", "onu4", 4, 4, "onu4", true))
kdarapu891693b2019-09-16 12:33:49 +05301065 dh2 := negativeDeviceHandler()
1066 type args struct {
1067 onuDiscInd *oop.OnuDiscIndication
1068 sn string
1069 }
1070 tests := []struct {
1071 name string
1072 devicehandler *DeviceHandler
1073 args args
1074 }{
1075 // TODO: Add test cases.
1076 {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
1077 {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
1078 {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
1079 {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
1080 {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
1081 {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}},
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +05301082 {"onuDiscIndication-7", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu3"}},
1083 {"onuDiscIndication-8", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu4"}},
1084 {"onuDiscIndication-9", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
kdarapu891693b2019-09-16 12:33:49 +05301085 }
1086 for _, tt := range tests {
1087 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301088 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1089 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -04001090 _ = tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd, tt.args.sn)
1091 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301092 })
1093 }
1094}
1095
1096func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
1097 dh1 := newMockDeviceHandler()
1098 dh2 := negativeDeviceHandler()
1099 tests := []struct {
1100 name string
1101 devicehandler *DeviceHandler
1102
1103 wantErr bool
1104 }{
1105 // TODO: Add test cases.
1106 {"populateDeviceInfo-1", dh1, false},
1107 {"populateDeviceInfo-2", dh1, true},
1108 {"populateDeviceInfo-3", dh1, true},
1109 {"populateDeviceInfo-4", dh1, true},
1110 {"populateDeviceInfo-5", dh2, true},
1111 }
1112 for _, tt := range tests {
1113 t.Run(tt.name, func(t *testing.T) {
1114
Neha Sharma96b7bf22020-06-15 10:37:32 +00001115 _, err := tt.devicehandler.populateDeviceInfo(context.Background())
kdarapu891693b2019-09-16 12:33:49 +05301116 if (err != nil) != tt.wantErr {
1117 t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1118 return
1119 }
1120
1121 })
1122 }
1123}
1124
1125func TestDeviceHandler_readIndications(t *testing.T) {
1126 dh1 := newMockDeviceHandler()
1127 dh2 := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +05301128 dh3 := newMockDeviceHandler()
1129 dh3.device.AdminState = voltha.AdminState_DISABLED
1130 dh4 := negativeDeviceHandler()
1131 tests := []struct {
1132 name string
1133 devicehandler *DeviceHandler
1134 }{
1135 // TODO: Add test cases.
1136 {"readIndications-1", dh1},
1137 {"readIndications-2", dh2},
1138 {"readIndications-3", dh2},
1139 {"readIndications-4", dh2},
1140 {"readIndications-5", dh2},
1141 {"readIndications-6", dh3},
1142 {"readIndications-7", dh3},
1143 {"readIndications-8", dh4},
1144 }
1145 for _, tt := range tests {
1146 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301147 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1148 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -04001149 _ = tt.devicehandler.readIndications(ctx)
1150 // TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301151 })
1152 }
1153}
Naga Manjunath7615e552019-10-11 22:35:47 +05301154
1155func Test_startCollector(t *testing.T) {
1156 type args struct {
1157 dh *DeviceHandler
1158 }
1159 dh := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001160 dh.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301161 {PortNo: 1, Label: "pon", Type: voltha.Port_PON_OLT},
1162 {PortNo: 1048577, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1163 {PortNo: 1048578, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1164 }
Naga Manjunath7615e552019-10-11 22:35:47 +05301165 dh.portStats.NorthBoundPort = make(map[uint32]*NniPort)
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301166 dh.portStats.NorthBoundPort[1] = &NniPort{Name: "OLT-1"}
1167 dh.portStats.NorthBoundPort[2] = &NniPort{Name: "OLT-1"}
Naga Manjunath7615e552019-10-11 22:35:47 +05301168 dh.portStats.SouthBoundPort = make(map[uint32]*PonPort)
1169 dh.portStats.Device = dh
1170 for i := 0; i < 16; i++ {
1171 dh.portStats.SouthBoundPort[uint32(i)] = &PonPort{DeviceID: "OLT-1"}
1172 }
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301173 dh1 := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001174 dh1.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{}
Naga Manjunath7615e552019-10-11 22:35:47 +05301175 tests := []struct {
1176 name string
1177 args args
1178 }{
1179 // TODO: Add test cases.
1180 {"StartCollector-1", args{dh}},
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301181 {"StartCollector-2", args{dh1}},
Naga Manjunath7615e552019-10-11 22:35:47 +05301182 }
1183 for _, tt := range tests {
1184 t.Run(tt.name, func(t *testing.T) {
1185 go func() {
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301186 time.Sleep(1 * time.Second) // simulated wait time to stop startCollector
Naga Manjunath7615e552019-10-11 22:35:47 +05301187 tt.args.dh.stopCollector <- true
1188 }()
Neha Sharma96b7bf22020-06-15 10:37:32 +00001189 startCollector(context.Background(), tt.args.dh)
Naga Manjunath7615e552019-10-11 22:35:47 +05301190 })
1191 }
1192}