blob: 9770f15740002ac226c8b68676d1cade6d5ff8e2 [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"
Matteo Scandolodfa7a972020-11-06 13:03:40 -080022 conf "github.com/opencord/voltha-lib-go/v4/pkg/config"
kdarapu381c6902019-07-31 18:23:16 +053023 "net"
kdarapu891693b2019-09-16 12:33:49 +053024 "reflect"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053025 "sync"
kdarapu381c6902019-07-31 18:23:16 +053026 "testing"
Naga Manjunath7615e552019-10-11 22:35:47 +053027 "time"
28
kdarapu891693b2019-09-16 12:33:49 +053029 "github.com/golang/protobuf/ptypes"
30 "github.com/golang/protobuf/ptypes/any"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070031 "github.com/opencord/voltha-lib-go/v4/pkg/db"
32 fu "github.com/opencord/voltha-lib-go/v4/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v4/pkg/log"
34 "github.com/opencord/voltha-lib-go/v4/pkg/pmmetrics"
35 ponrmgr "github.com/opencord/voltha-lib-go/v4/pkg/ponresourcemanager"
kesavand494c2082020-08-31 11:16:12 +053036 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053037 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Scott Bakerdbd960e2020-02-28 08:57:51 -080038 "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
39 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070040 ic "github.com/opencord/voltha-protos/v4/go/inter_container"
41 of "github.com/opencord/voltha-protos/v4/go/openflow_13"
42 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
43 oop "github.com/opencord/voltha-protos/v4/go/openolt"
44 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapu381c6902019-07-31 18:23:16 +053045)
46
Girish Gowdra9602eb42020-09-09 15:50:39 -070047const (
Girish Gowdrafb3d6102020-10-16 16:32:36 -070048 NumPonPorts = 16
Girish Gowdra9602eb42020-09-09 15:50:39 -070049 OnuIDStart = 1
50 OnuIDEnd = 32
51 AllocIDStart = 1
52 AllocIDEnd = 10
53 GemIDStart = 1
54 GemIDEnd = 10
55 FlowIDStart = 1
56 FlowIDEnd = 10
57)
58
kdarapu891693b2019-09-16 12:33:49 +053059func newMockCoreProxy() *mocks.MockCoreProxy {
Kent Hagermanf1db18b2020-07-08 13:38:15 -040060 mcp := mocks.MockCoreProxy{
61 Devices: make(map[string]*voltha.Device),
62 DevicePorts: make(map[string][]*voltha.Port),
63 }
Naga Manjunath7615e552019-10-11 22:35:47 +053064 var pm []*voltha.PmConfig
kdarapu891693b2019-09-16 12:33:49 +053065 mcp.Devices["olt"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053066 Id: "olt",
67 Root: true,
68 ParentId: "logical_device",
69 ParentPortNo: 1,
kdarapu891693b2019-09-16 12:33:49 +053070 ProxyAddress: &voltha.Device_ProxyAddress{
71 DeviceId: "olt",
72 DeviceType: "onu",
73 ChannelId: 1,
74 ChannelGroupId: 1,
75 },
76 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +053077 PmConfigs: &voltha.PmConfigs{
78 DefaultFreq: 10,
79 Id: "olt",
80 FreqOverride: false,
81 Grouped: false,
82 Metrics: pm,
83 },
kdarapu891693b2019-09-16 12:33:49 +053084 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -040085 mcp.DevicePorts["olt"] = []*voltha.Port{
86 {PortNo: 1, Label: "pon"},
87 {PortNo: 2, Label: "nni"},
88 }
kdarapu891693b2019-09-16 12:33:49 +053089
Kent Hagermanf1db18b2020-07-08 13:38:15 -040090 mcp.Devices["onu1"] = &voltha.Device{
kdarapu891693b2019-09-16 12:33:49 +053091 Id: "1",
92 Root: false,
93 ParentId: "olt",
94 ParentPortNo: 1,
95
kdarapu891693b2019-09-16 12:33:49 +053096 OperStatus: 4,
97 ProxyAddress: &voltha.Device_ProxyAddress{
98 OnuId: 1,
99 ChannelId: 1,
100 ChannelGroupId: 1,
101 },
102 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530103 PmConfigs: &voltha.PmConfigs{
104 DefaultFreq: 10,
105 Id: "olt",
106 FreqOverride: false,
107 Grouped: false,
108 Metrics: pm,
109 },
kdarapu891693b2019-09-16 12:33:49 +0530110 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400111 mcp.DevicePorts["onu1"] = []*voltha.Port{
112 {PortNo: 1, Label: "pon"},
113 {PortNo: 2, Label: "uni"},
114 }
115
kdarapu891693b2019-09-16 12:33:49 +0530116 mcp.Devices["onu2"] = &voltha.Device{
117 Id: "2",
118 Root: false,
119 ParentId: "olt",
120 OperStatus: 2,
kdarapu891693b2019-09-16 12:33:49 +0530121
122 ParentPortNo: 1,
123
124 ProxyAddress: &voltha.Device_ProxyAddress{
125 OnuId: 2,
126 ChannelId: 1,
127 ChannelGroupId: 1,
128 },
129 ConnectStatus: 1,
Naga Manjunath7615e552019-10-11 22:35:47 +0530130 PmConfigs: &voltha.PmConfigs{
131 DefaultFreq: 10,
132 Id: "olt",
133 FreqOverride: false,
134 Grouped: false,
135 Metrics: pm,
136 },
kdarapu891693b2019-09-16 12:33:49 +0530137 }
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400138 mcp.DevicePorts["onu2"] = []*voltha.Port{
139 {PortNo: 1, Label: "pon"},
140 {PortNo: 2, Label: "uni"},
141 }
kdarapu891693b2019-09-16 12:33:49 +0530142 return &mcp
143}
144func newMockDeviceHandler() *DeviceHandler {
kdarapu381c6902019-07-31 18:23:16 +0530145 device := &voltha.Device{
146 Id: "olt",
147 Root: true,
148 ParentId: "logical_device",
kdarapu891693b2019-09-16 12:33:49 +0530149 ProxyAddress: &voltha.Device_ProxyAddress{
150 DeviceId: "olt",
151 DeviceType: "onu",
152 ChannelId: 1,
153 ChannelGroupId: 1,
154 },
155 ConnectStatus: 1,
kdarapu381c6902019-07-31 18:23:16 +0530156 }
kdarapu891693b2019-09-16 12:33:49 +0530157 cp := newMockCoreProxy()
158 ap := &mocks.MockAdapterProxy{}
159 ep := &mocks.MockEventProxy{}
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800160 cm := &conf.ConfigManager{}
kesavand494c2082020-08-31 11:16:12 +0530161 cfg := &config.AdapterFlags{OmccEncryption: true}
162 openOLT := &OpenOLT{coreProxy: cp, adapterProxy: ap, eventProxy: ep, config: cfg}
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800163 dh := NewDeviceHandler(cp, ap, ep, device, openOLT, cm)
Girish Gowdra38d533d2020-03-30 20:38:51 -0700164 oopRanges := []*oop.DeviceInfo_DeviceResourceRanges{{
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700165 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 -0700166 Technology: "xgs-pon",
167 Pools: []*oop.DeviceInfo_DeviceResourceRanges_Pool{{}},
168 }}
169
Girish Gowdra9602eb42020-09-09 15:50:39 -0700170 deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: oopRanges, Model: "openolt", DeviceId: dh.device.Id, PonPorts: NumPonPorts}
Thomas Lee S985938d2020-05-04 11:40:41 +0530171 rsrMgr := resourcemanager.OpenOltResourceMgr{DeviceID: dh.device.Id, DeviceType: dh.device.Type, DevInfo: deviceInf,
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530172 KVStore: &db.Backend{
173 Client: &mocks.MockKVClient{},
174 }}
Girish Gowdra38d533d2020-03-30 20:38:51 -0700175 rsrMgr.AllocIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
176 rsrMgr.GemPortIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
177 rsrMgr.OnuIDMgmtLock = make([]sync.RWMutex, deviceInf.PonPorts)
178
179 dh.resourceMgr = &rsrMgr
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530180 dh.resourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
181 ranges := make(map[string]interface{})
182 sharedIdxByType := make(map[string]string)
183 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
184 sharedIdxByType["ONU_ID"] = "ONU_ID"
185 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
186 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
187 ranges["ONU_ID"] = uint32(0)
188 ranges["GEMPORT_ID"] = uint32(0)
189 ranges["ALLOC_ID"] = uint32(0)
190 ranges["FLOW_ID"] = uint32(0)
191 ranges["onu_id_shared"] = uint32(0)
192 ranges["alloc_id_shared"] = uint32(0)
193 ranges["gemport_id_shared"] = uint32(0)
194 ranges["flow_id_shared"] = uint32(0)
195
196 ponmgr := &ponrmgr.PONResourceManager{
197 DeviceID: "onu-1",
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700198 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 +0530199 KVStore: &db.Backend{
200 Client: &mocks.MockKVClient{},
201 },
202 PonResourceRanges: ranges,
203 SharedIdxByType: sharedIdxByType,
204 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700205 for i := 0; i < NumPonPorts; i++ {
206 dh.resourceMgr.ResourceMgrs[uint32(i)] = ponmgr
207 }
npujarec5762e2020-01-01 14:08:48 +0530208 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
209 defer cancel()
Girish Gowdra9602eb42020-09-09 15:50:39 -0700210 dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr)
211 dh.totalPonPorts = NumPonPorts
212 dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts)
213 for i := 0; i < int(dh.totalPonPorts); i++ {
214 // Instantiate flow manager
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700215 if dh.flowMgr[i] = NewFlowManager(ctx, dh, dh.resourceMgr, dh.groupMgr, uint32(i)); dh.flowMgr[i] == nil {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700216 return nil
217 }
218 }
kdarapu891693b2019-09-16 12:33:49 +0530219 dh.Client = &mocks.MockOpenoltClient{}
kesavand39e0aa32020-01-28 20:58:50 -0500220 dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}, handler: dh}
kdarapu891693b2019-09-16 12:33:49 +0530221 dh.transitionMap = &TransitionMap{}
Naga Manjunath7615e552019-10-11 22:35:47 +0530222 dh.portStats = &OpenOltStatisticsMgr{}
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000223
224 var pmNames = []string{
225 "rx_bytes",
226 "rx_packets",
227 "rx_mcast_packets",
228 "rx_bcast_packets",
229 "tx_bytes",
230 "tx_packets",
231 "tx_mcast_packets",
232 "tx_bcast_packets",
233 }
234
235 dh.metrics = pmmetrics.NewPmMetrics(device.Id, pmmetrics.Frequency(2), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
kdarapu891693b2019-09-16 12:33:49 +0530236 return dh
kdarapu381c6902019-07-31 18:23:16 +0530237}
238
kdarapu891693b2019-09-16 12:33:49 +0530239func negativeDeviceHandler() *DeviceHandler {
240 dh := newMockDeviceHandler()
241 device := dh.device
242 device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530243 return dh
244}
kdarapu381c6902019-07-31 18:23:16 +0530245func Test_generateMacFromHost(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000246 ctx := context.Background()
kdarapu381c6902019-07-31 18:23:16 +0530247 type args struct {
248 host string
249 }
250 tests := []struct {
251 name string
252 args args
253 want string
254 wantErr bool
255 }{
kdarapu891693b2019-09-16 12:33:49 +0530256 {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false},
257 {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false},
258 //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false},
259 {"generateMacFromHost-4", args{host: "testing3"}, "", true},
kdarapu381c6902019-07-31 18:23:16 +0530260 }
261 for _, tt := range tests {
262 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000263 got, err := generateMacFromHost(ctx, tt.args.host)
kdarapu381c6902019-07-31 18:23:16 +0530264 if (err != nil) != tt.wantErr {
265 t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr)
266 return
267 }
268 if got != tt.want {
269 t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want)
270 }
271 })
272 }
273}
274func Test_macifyIP(t *testing.T) {
275 type args struct {
276 ip net.IP
277 }
278 tests := []struct {
279 name string
280 args args
281 want string
282 }{{
kdarapu891693b2019-09-16 12:33:49 +0530283 "macifyIP-1",
kdarapu381c6902019-07-31 18:23:16 +0530284 args{ip: net.ParseIP("10.10.10.10")},
285 "00:00:0a:0a:0a:0a",
286 },
287 {
kdarapu891693b2019-09-16 12:33:49 +0530288 "macifyIP-2",
kdarapu381c6902019-07-31 18:23:16 +0530289 args{ip: net.ParseIP("127.0.0.1")},
290 "00:00:7f:00:00:01",
kdarapu891693b2019-09-16 12:33:49 +0530291 },
292 {
293 "macifyIP-3",
294 args{ip: net.ParseIP("127.0.0.1/24")},
295 "",
296 },
297 }
kdarapu381c6902019-07-31 18:23:16 +0530298 for _, tt := range tests {
299 t.Run(tt.name, func(t *testing.T) {
300 if got := macifyIP(tt.args.ip); got != tt.want {
301 t.Errorf("macifyIP() = %v, want %v", got, tt.want)
302 }
303 })
304 }
305}
306
David K. Bainbridge794735f2020-02-11 21:01:37 -0800307func sparseCompare(keys []string, spec, target interface{}) bool {
308 if spec == target {
309 return true
310 }
311 if spec == nil || target == nil {
312 return false
313 }
314 typeSpec := reflect.TypeOf(spec)
315 typeTarget := reflect.TypeOf(target)
316 if typeSpec != typeTarget {
317 return false
318 }
319
320 vSpec := reflect.ValueOf(spec)
321 vTarget := reflect.ValueOf(target)
322 if vSpec.Kind() == reflect.Ptr {
323 vSpec = vSpec.Elem()
324 vTarget = vTarget.Elem()
325 }
326
327 for _, key := range keys {
328 fSpec := vSpec.FieldByName(key)
329 fTarget := vTarget.FieldByName(key)
330 if !reflect.DeepEqual(fSpec.Interface(), fTarget.Interface()) {
331 return false
332 }
333 }
334 return true
335}
336
kdarapu381c6902019-07-31 18:23:16 +0530337func TestDeviceHandler_GetChildDevice(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000338 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530339 dh1 := newMockDeviceHandler()
340 dh2 := negativeDeviceHandler()
kdarapu381c6902019-07-31 18:23:16 +0530341 type args struct {
342 parentPort uint32
343 onuID uint32
344 }
345 tests := []struct {
kdarapu891693b2019-09-16 12:33:49 +0530346 name string
347 devicehandler *DeviceHandler
348 args args
349 want *voltha.Device
David K. Bainbridge794735f2020-02-11 21:01:37 -0800350 errType reflect.Type
kdarapu381c6902019-07-31 18:23:16 +0530351 }{
kdarapu891693b2019-09-16 12:33:49 +0530352 {"GetChildDevice-1", dh1,
353 args{parentPort: 1,
354 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800355 &voltha.Device{
356 Id: "1",
357 ParentId: "olt",
358 ParentPortNo: 1,
359 },
360 nil,
kdarapu891693b2019-09-16 12:33:49 +0530361 },
362 {"GetChildDevice-2", dh2,
kdarapu381c6902019-07-31 18:23:16 +0530363 args{parentPort: 1,
364 onuID: 1},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800365 nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530366 reflect.TypeOf(&olterrors.ErrNotFound{}),
kdarapu381c6902019-07-31 18:23:16 +0530367 },
368 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800369
370 /*
371 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-1 (0.00s)
372 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>)
373 --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-2 (0.00s)
374 */
kdarapu381c6902019-07-31 18:23:16 +0530375 for _, tt := range tests {
376 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000377 got, err := tt.devicehandler.GetChildDevice(ctx, tt.args.parentPort, tt.args.onuID)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800378 if reflect.TypeOf(err) != tt.errType || !sparseCompare([]string{"Id", "ParentId", "ParentPortNo"}, tt.want, got) {
379 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
380 tt.want, tt.errType, got, reflect.TypeOf(err))
381 return
382 }
kdarapu381c6902019-07-31 18:23:16 +0530383 t.Log("onu device id", got)
384 })
385 }
386}
kdarapu891693b2019-09-16 12:33:49 +0530387
388func TestGetportLabel(t *testing.T) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530389 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530390 type args struct {
391 portNum uint32
392 portType voltha.Port_PortType
393 }
394 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800395 name string
396 args args
397 want string
398 errType reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530399 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800400 {"GetportLabel-1", args{portNum: 0, portType: 0}, "", invalid},
401 {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1", nil},
402 {"GetportLabel-3", args{portNum: 2, portType: 2}, "", invalid},
403 {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3", nil},
404 {"GetportLabel-5", args{portNum: 4, portType: 4}, "", invalid},
405 {"GetportLabel-6", args{portNum: 5, portType: 5}, "", invalid},
406 {"GetportLabel-7", args{portNum: 6, portType: 6}, "", invalid},
kdarapu891693b2019-09-16 12:33:49 +0530407 }
408 for _, tt := range tests {
409 t.Run(tt.name, func(t *testing.T) {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800410 got, err := GetportLabel(tt.args.portNum, tt.args.portType)
411 if reflect.TypeOf(err) != tt.errType || got != tt.want {
412 t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)",
413 tt.want, tt.errType, got, reflect.TypeOf(err))
kdarapu891693b2019-09-16 12:33:49 +0530414 }
David K. Bainbridge794735f2020-02-11 21:01:37 -0800415
kdarapu891693b2019-09-16 12:33:49 +0530416 })
417 }
418}
419
420func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000421 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530422 dh := newMockDeviceHandler()
423 proxyAddr := dh.device.ProxyAddress
424 body := &ic.InterAdapterOmciMessage{
425 Message: []byte("asdfasdfasdfasdfas"),
426 ProxyAddress: proxyAddr,
427 }
428 body2 := &ic.InterAdapterOmciMessage{
429 Message: []byte("asdfasdfasdfasdfas"),
430 //ProxyAddress: &voltha.Device_ProxyAddress{},
431 }
432 body3 := &ic.InterAdapterTechProfileDownloadMessage{}
433 var marshalledData *any.Any
434 var err error
435
436 if marshalledData, err = ptypes.MarshalAny(body); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000437 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530438 }
439
440 var marshalledData1 *any.Any
441
442 if marshalledData1, err = ptypes.MarshalAny(body2); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000443 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530444 }
445 var marshalledData2 *any.Any
446
447 if marshalledData2, err = ptypes.MarshalAny(body3); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000448 logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"error": err})
kdarapu891693b2019-09-16 12:33:49 +0530449 }
450 type args struct {
451 msg *ic.InterAdapterMessage
452 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530453 invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{})
kdarapu891693b2019-09-16 12:33:49 +0530454 tests := []struct {
455 name string
456 args args
David K. Bainbridge794735f2020-02-11 21:01:37 -0800457 wantErr reflect.Type
kdarapu891693b2019-09-16 12:33:49 +0530458 }{
459 {"ProcessInterAdapterMessage-1", args{msg: &ic.InterAdapterMessage{
460 Header: &ic.InterAdapterHeader{
461 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800462 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530463 },
464 Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800465 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530466 {"ProcessInterAdapterMessage-2", args{msg: &ic.InterAdapterMessage{
467 Header: &ic.InterAdapterHeader{
468 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800469 Type: ic.InterAdapterMessageType_FLOW_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530470 },
471 Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800472 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530473 {"ProcessInterAdapterMessage-3", args{msg: &ic.InterAdapterMessage{
474 Header: &ic.InterAdapterHeader{
475 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800476 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530477 },
478 Body: marshalledData,
Thomas Lee S94109f12020-03-03 16:39:29 +0530479 }}, reflect.TypeOf(&olterrors.ErrCommunication{})},
kdarapu891693b2019-09-16 12:33:49 +0530480 {"ProcessInterAdapterMessage-4", args{msg: &ic.InterAdapterMessage{
481 Header: &ic.InterAdapterHeader{
482 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800483 Type: ic.InterAdapterMessageType_OMCI_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530484 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800485 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530486 {"ProcessInterAdapterMessage-5", args{msg: &ic.InterAdapterMessage{
487 Header: &ic.InterAdapterHeader{
488 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800489 Type: ic.InterAdapterMessageType_METRICS_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530490 }, Body: marshalledData1,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800491 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530492 {"ProcessInterAdapterMessage-6", args{msg: &ic.InterAdapterMessage{
493 Header: &ic.InterAdapterHeader{
494 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800495 Type: ic.InterAdapterMessageType_METRICS_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530496 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800497 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530498 {"ProcessInterAdapterMessage-7", args{msg: &ic.InterAdapterMessage{
499 Header: &ic.InterAdapterHeader{
500 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800501 Type: ic.InterAdapterMessageType_ONU_IND_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530502 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800503 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530504 {"ProcessInterAdapterMessage-8", args{msg: &ic.InterAdapterMessage{
505 Header: &ic.InterAdapterHeader{
506 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800507 Type: ic.InterAdapterMessageType_ONU_IND_RESPONSE,
kdarapu891693b2019-09-16 12:33:49 +0530508 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800509 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530510 {"ProcessInterAdapterMessage-9", args{msg: &ic.InterAdapterMessage{
511 Header: &ic.InterAdapterHeader{
512 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800513 Type: ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530514 }, Body: marshalledData,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800515 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530516 {"ProcessInterAdapterMessage-10", args{msg: &ic.InterAdapterMessage{
517 Header: &ic.InterAdapterHeader{
518 Id: "012345",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800519 Type: ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST,
kdarapu891693b2019-09-16 12:33:49 +0530520 }, Body: marshalledData2,
David K. Bainbridge794735f2020-02-11 21:01:37 -0800521 }}, invalid},
522 {"ProcessInterAdapterMessage-11", args{msg: &ic.InterAdapterMessage{
523 Header: &ic.InterAdapterHeader{
524 Id: "012345",
525 Type: ic.InterAdapterMessageType_DELETE_TCONT_REQUEST,
526 }, Body: marshalledData2,
527 }}, invalid},
kdarapu891693b2019-09-16 12:33:49 +0530528 }
529 for _, tt := range tests {
530 t.Run(tt.name, func(t *testing.T) {
531
Neha Sharma96b7bf22020-06-15 10:37:32 +0000532 if err := dh.ProcessInterAdapterMessage(ctx, tt.args.msg); reflect.TypeOf(err) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530533 t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr)
534 }
535 })
536 }
537}
538
539func TestDeviceHandler_sendProxiedMessage(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000540 ctx := context.Background()
kdarapu891693b2019-09-16 12:33:49 +0530541 dh1 := newMockDeviceHandler()
542 dh2 := negativeDeviceHandler()
543 device1 := &voltha.Device{
544 Id: "onu1",
545 Root: false,
546 ParentId: "logical_device",
547 ProxyAddress: &voltha.Device_ProxyAddress{
548 DeviceId: "onu1",
549 DeviceType: "onu",
550 ChannelId: 1,
551 ChannelGroupId: 1,
552 },
553 ConnectStatus: 1,
554 }
555 device2 := device1
556 device2.ConnectStatus = 2
557 iaomciMsg1 := &ic.InterAdapterOmciMessage{
558 ProxyAddress: &voltha.Device_ProxyAddress{
559 DeviceId: "onu2",
560 DeviceType: "onu",
561 ChannelId: 1,
562 ChannelGroupId: 1,
563 //OnuId: 2,
564 },
565 ConnectStatus: 1,
566 }
567 iaomciMsg2 := &ic.InterAdapterOmciMessage{
568 ProxyAddress: &voltha.Device_ProxyAddress{
569 DeviceId: "onu3",
570 DeviceType: "onu",
571 ChannelId: 1,
572 ChannelGroupId: 1,
573 },
574 ConnectStatus: 1,
575 }
576 type args struct {
577 onuDevice *voltha.Device
578 omciMsg *ic.InterAdapterOmciMessage
579 }
580 tests := []struct {
581 name string
582 devicehandler *DeviceHandler
583 args args
584 }{
585 {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
586 {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ic.InterAdapterOmciMessage{}}},
587 {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}},
588 {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}},
589 {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}},
590 {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ic.InterAdapterOmciMessage{}}},
591 }
592 for _, tt := range tests {
593 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400594 _ = tt.devicehandler.sendProxiedMessage(ctx, tt.args.onuDevice, tt.args.omciMsg)
595 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530596 })
597 }
598}
599
600func TestDeviceHandler_SendPacketInToCore(t *testing.T) {
601 dh1 := newMockDeviceHandler()
602 dh2 := negativeDeviceHandler()
603
604 type args struct {
605 logicalPort uint32
606 packetPayload []byte
607 }
608 tests := []struct {
609 name string
610 devicehandler *DeviceHandler
611 args args
612 }{
613 {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}},
614 {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}},
615 {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}},
616 }
617 for _, tt := range tests {
618 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400619 _ = tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload)
620 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530621 })
622 }
623}
624
625func TestDeviceHandler_DisableDevice(t *testing.T) {
626 dh1 := newMockDeviceHandler()
627 dh2 := negativeDeviceHandler()
628 type args struct {
629 device *voltha.Device
630 }
631 tests := []struct {
632 name string
633 devicehandler *DeviceHandler
634 args args
635 wantErr bool
636 }{
637 {"DisableDevice-1", dh1, args{device: dh1.device}, false},
Chaitrashree G S3b4c0352019-09-09 20:59:29 -0400638 {"DisableDevice-2", dh1, args{device: dh2.device}, true},
kdarapu891693b2019-09-16 12:33:49 +0530639 }
640 for _, tt := range tests {
641 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000642 if err := tt.devicehandler.DisableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530643 t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
644 }
645 })
646 }
647}
648
649func TestDeviceHandler_ReenableDevice(t *testing.T) {
650 dh1 := newMockDeviceHandler()
651 dh2 := negativeDeviceHandler()
652 type args struct {
653 device *voltha.Device
654 }
655 tests := []struct {
656 name string
657 devicehandler *DeviceHandler
658 args args
659 wantErr bool
660 }{
661 {"ReenableDevice-1", dh1, args{device: dh1.device}, false},
662 {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true},
663 {"ReenableDevice-3", dh2, args{device: dh1.device}, false},
664 }
665 for _, tt := range tests {
666 t.Run(tt.name, func(t *testing.T) {
667 dh := tt.devicehandler
Neha Sharma96b7bf22020-06-15 10:37:32 +0000668 if err := dh.ReenableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530669 t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr)
670 }
671 })
672 }
673}
674
675func TestDeviceHandler_RebootDevice(t *testing.T) {
676 dh1 := newMockDeviceHandler()
677 dh2 := newMockDeviceHandler()
678 type args struct {
679 device *voltha.Device
680 }
681 tests := []struct {
682 name string
683 devicehandler *DeviceHandler
684 args args
685 wantErr bool
686 }{
687 // TODO: Add test cases.
688 {"RebootDevice-1", dh1, args{device: dh1.device}, false},
689 {"RebootDevice-2", dh1, args{device: dh2.device}, true},
690 {"RebootDevice-3", dh2, args{device: dh2.device}, false},
691 }
692 for _, tt := range tests {
693 t.Run(tt.name, func(t *testing.T) {
694
Neha Sharma96b7bf22020-06-15 10:37:32 +0000695 if err := tt.devicehandler.RebootDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530696 t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr)
697 }
698 })
699 }
700}
701
702func TestDeviceHandler_handleIndication(t *testing.T) {
703 dh1 := newMockDeviceHandler()
704 dh2 := negativeDeviceHandler()
705 dh3 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530706 dh3.onus = sync.Map{}
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530707 dh3.onus.Store("onu1", NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1", false))
708 dh3.onus.Store("onu2", NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2", false))
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530709
kdarapu891693b2019-09-16 12:33:49 +0530710 type args struct {
711 indication *oop.Indication
712 }
713 tests := []struct {
714 name string
715 deviceHandler *DeviceHandler
716 args args
717 }{
718 // TODO: Add test cases.
719 {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
720 {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
721 {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
722 {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
723 {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
724 {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
725 {"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")}}}}}},
726 {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
727 {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
728 {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
729 {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
730 {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
731 {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
732 {"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}}}}},
733 {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
734 {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
735 {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}},
736 {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}},
737
738 // Negative testcases
739 {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}},
740 {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}},
741 {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}},
742 {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}},
743 {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}},
744 {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}},
745 {"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")}}}}}},
746 {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
747 {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
748 {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
749 {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
750 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}},
751 {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}},
752 {"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}}}}},
753 {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}},
754 {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}},
755 //
756 {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}},
757 {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}},
758 {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}},
759 {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}},
760 {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
761 {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}},
762 }
763 for _, tt := range tests {
764 t.Run(tt.name, func(t *testing.T) {
765 dh := tt.deviceHandler
npujarec5762e2020-01-01 14:08:48 +0530766 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
767 defer cancel()
768 dh.handleIndication(ctx, tt.args.indication)
kdarapu891693b2019-09-16 12:33:49 +0530769 })
770 }
771}
772
773func TestDeviceHandler_addPort(t *testing.T) {
774 dh1 := newMockDeviceHandler()
775 dh2 := negativeDeviceHandler()
776 type args struct {
777 intfID uint32
778 portType voltha.Port_PortType
779 state string
780 }
781 tests := []struct {
782 name string
783 devicehandler *DeviceHandler
784 args args
785 }{
786 // State up
787 {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}},
788 {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}},
789 {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}},
790 {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
791 {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
792 {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}},
793 {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}},
794 {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}},
795 // state discovery
796 {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}},
797 {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}},
798 {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}},
799 {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
800 {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
801 {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}},
802 {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}},
803 {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}},
804
805 {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up"}},
806 {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}},
807 {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down"}},
808 {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}},
809 }
810 for _, tt := range tests {
811 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400812 _ = tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state)
813 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530814 })
815 }
816}
817
818func Test_macAddressToUint32Array(t *testing.T) {
819 type args struct {
820 mac string
821 }
822 tests := []struct {
823 name string
824 args args
825 want []uint32
826 }{
827 // TODO: Add test cases.
828 {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}},
829 {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}},
830 {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}},
831 }
832 for _, tt := range tests {
833 t.Run(tt.name, func(t *testing.T) {
834 if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) {
835 t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want)
836 }
837 })
838 }
839}
840
841func TestDeviceHandler_handleOltIndication(t *testing.T) {
842
843 type args struct {
844 oltIndication *oop.OltIndication
845 }
846 tests := []struct {
847 name string
848 args args
849 }{
850 {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}},
851 {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}},
852 }
853 for _, tt := range tests {
854 t.Run(tt.name, func(t *testing.T) {
855 dh := newMockDeviceHandler()
npujarec5762e2020-01-01 14:08:48 +0530856 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
857 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400858 if err := dh.handleOltIndication(ctx, tt.args.oltIndication); err != nil {
859 t.Error(err)
860 }
kdarapu891693b2019-09-16 12:33:49 +0530861 })
862 }
863}
864
865func TestDeviceHandler_AdoptDevice(t *testing.T) {
866 dh1 := newMockDeviceHandler()
867 dh2 := negativeDeviceHandler()
868 type args struct {
869 device *voltha.Device
870 }
871 tests := []struct {
872 name string
873 devicehandler *DeviceHandler
874 args args
875 }{
876 // TODO: Add test cases.
877 {"AdoptDevice-1", dh1, args{device: dh1.device}},
Naga Manjunath7615e552019-10-11 22:35:47 +0530878 {"AdoptDevice-2", dh2, args{device: dh2.device}},
kdarapu891693b2019-09-16 12:33:49 +0530879 }
880 for _, tt := range tests {
881 t.Run(tt.name, func(t *testing.T) {
882 //dh.doStateInit()
883 // context.
884 //dh.AdoptDevice(tt.args.device)
npujarec5762e2020-01-01 14:08:48 +0530885 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
886 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400887 if err := tt.devicehandler.postInit(ctx); err != nil {
888 t.Error(err)
889 }
kdarapu891693b2019-09-16 12:33:49 +0530890 })
891 }
892}
893
894func TestDeviceHandler_activateONU(t *testing.T) {
895 dh := newMockDeviceHandler()
896 dh1 := negativeDeviceHandler()
897 type args struct {
898 intfID uint32
899 onuID int64
900 serialNum *oop.SerialNumber
901 serialNumber string
902 }
903 tests := []struct {
904 name string
905 devicehandler *DeviceHandler
906 args args
907 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700908 {"activateONU-1", dh, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
909 {"activateONU-2", dh, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
910 {"activateONU-3", dh1, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}},
911 {"activateONU-4", dh1, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}},
kdarapu891693b2019-09-16 12:33:49 +0530912 }
913 for _, tt := range tests {
914 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530915 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
916 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -0400917 _ = tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum, tt.args.serialNumber)
918 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +0530919 })
920 }
921}
922
923func TestDeviceHandler_start(t *testing.T) {
924 dh := newMockDeviceHandler()
925 dh1 := negativeDeviceHandler()
926 dh.start(context.Background())
927 dh.stop(context.Background())
928
929 dh1.start(context.Background())
930 dh1.stop(context.Background())
931
932}
933
934func TestDeviceHandler_PacketOut(t *testing.T) {
935 dh1 := newMockDeviceHandler()
936 dh2 := negativeDeviceHandler()
937 acts := []*ofp.OfpAction{
938 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
939 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
940 fu.Output(1),
941 }
942 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
943 type args struct {
944 egressPortNo int
945 packet *of.OfpPacketOut
946 }
947 tests := []struct {
948 name string
949 devicehandler *DeviceHandler
950 args args
951 wantErr bool
952 }{
953 // TODO: Add test cases.
954 //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true},
955 {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false},
956 {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false},
Matteo Scandolo2c0d2742020-06-10 11:28:42 -0700957 {"PacketOut-3", dh2, args{egressPortNo: 4112, packet: pktout}, false},
958 {"PacketOut-4", dh1, args{egressPortNo: 1048577, packet: pktout}, false},
959 {"PacketOut-5", dh2, args{egressPortNo: 1048576, packet: pktout}, false},
kdarapu891693b2019-09-16 12:33:49 +0530960 }
961 for _, tt := range tests {
962 t.Run(tt.name, func(t *testing.T) {
963 dh := tt.devicehandler
npujarec5762e2020-01-01 14:08:48 +0530964 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
965 defer cancel()
966 if err := dh.PacketOut(ctx, tt.args.egressPortNo, tt.args.packet); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530967 t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr)
968 }
969 })
970 }
971}
972
973//
974func TestDeviceHandler_doStateUp(t *testing.T) {
975 dh1 := newMockDeviceHandler()
976 dh2 := newMockDeviceHandler()
977
Thomas Lee S985938d2020-05-04 11:40:41 +0530978 dh2.device.Id = ""
kdarapu891693b2019-09-16 12:33:49 +0530979 dh3 := negativeDeviceHandler()
980
981 tests := []struct {
982 name string
983 devicehandler *DeviceHandler
984 wantErr bool
985 }{
986 {"dostateup-1", dh1, false},
987 {"dostateup-2", dh2, false},
988 {"dostateup-3", dh3, true},
989 }
990 for _, tt := range tests {
991 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530992 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
993 defer cancel()
994 if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +0530995 t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
996 }
Thomas Lee S85f37312020-04-03 17:06:12 +0530997 tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp
kdarapu891693b2019-09-16 12:33:49 +0530998 })
999 }
1000}
1001func TestDeviceHandler_doStateDown(t *testing.T) {
1002 dh1 := newMockDeviceHandler()
1003 dh2 := negativeDeviceHandler()
1004 dh3 := newMockDeviceHandler()
1005 dh3.device.OperStatus = voltha.OperStatus_UNKNOWN
1006 tests := []struct {
1007 name string
1008 devicehandler *DeviceHandler
1009 wantErr bool
1010 }{
1011 {"dostatedown-1", dh1, false},
1012 {"dostatedown-2", dh2, true},
1013 {"dostatedown-2", dh3, true},
1014 }
1015 for _, tt := range tests {
1016 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301017 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1018 defer cancel()
1019 if err := tt.devicehandler.doStateDown(ctx); (err != nil) != tt.wantErr {
kdarapu891693b2019-09-16 12:33:49 +05301020 t.Logf("DeviceHandler.doStateDown() error = %v", err)
Kent Hagermane6ff1012020-07-14 15:07:53 -04001021 //TODO: should fail this test case (Errorf) if result is not as expected
kdarapu891693b2019-09-16 12:33:49 +05301022 }
1023 })
1024 }
1025}
1026
1027func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) {
1028 dh1 := newMockDeviceHandler()
1029 dh2 := negativeDeviceHandler()
1030 type args struct {
1031 device *voltha.Device
1032 }
1033 tests := []struct {
1034 name string
1035 devicehandler *DeviceHandler
1036 args args
1037 wantErr bool
1038 }{
1039 // TODO: Add test cases.
1040 {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false},
1041 {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false},
1042 {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false},
1043 }
1044 for _, tt := range tests {
1045 t.Run(tt.name, func(t *testing.T) {
1046 dh := tt.devicehandler
1047 _, err := dh.GetOfpDeviceInfo(tt.args.device)
1048 if (err != nil) != tt.wantErr {
1049 t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1050 return
1051 }
1052 })
1053 }
1054}
1055
kdarapu891693b2019-09-16 12:33:49 +05301056func TestDeviceHandler_onuDiscIndication(t *testing.T) {
1057
1058 dh1 := newMockDeviceHandler()
Naga Manjunatha8dc9372019-10-31 23:01:18 +05301059 dh1.discOnus = sync.Map{}
1060 dh1.discOnus.Store("onu1", true)
1061 dh1.discOnus.Store("onu2", false)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +05301062 dh1.discOnus.Store("onu3", true)
1063 dh1.discOnus.Store("onu4", true)
1064 dh1.onus = sync.Map{}
1065 dh1.onus.Store("onu3", NewOnuDevice("onu3", "onu3", "onu3", 3, 3, "onu3", true))
1066 dh1.onus.Store("onu4", NewOnuDevice("onu4", "onu4", "onu4", 4, 4, "onu4", true))
kdarapu891693b2019-09-16 12:33:49 +05301067 dh2 := negativeDeviceHandler()
1068 type args struct {
1069 onuDiscInd *oop.OnuDiscIndication
1070 sn string
1071 }
1072 tests := []struct {
1073 name string
1074 devicehandler *DeviceHandler
1075 args args
1076 }{
1077 // TODO: Add test cases.
1078 {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
1079 {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}},
1080 {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}},
1081 {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}},
1082 {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}},
1083 {"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 +05301084 {"onuDiscIndication-7", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu3"}},
1085 {"onuDiscIndication-8", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu4"}},
1086 {"onuDiscIndication-9", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}},
kdarapu891693b2019-09-16 12:33:49 +05301087 }
1088 for _, tt := range tests {
1089 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301090 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1091 defer cancel()
Mahir Gunyelb0046752021-02-26 13:51:05 -08001092 _ = tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd)
Kent Hagermane6ff1012020-07-14 15:07:53 -04001093 //TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301094 })
1095 }
1096}
1097
1098func TestDeviceHandler_populateDeviceInfo(t *testing.T) {
1099 dh1 := newMockDeviceHandler()
1100 dh2 := negativeDeviceHandler()
1101 tests := []struct {
1102 name string
1103 devicehandler *DeviceHandler
1104
1105 wantErr bool
1106 }{
1107 // TODO: Add test cases.
1108 {"populateDeviceInfo-1", dh1, false},
1109 {"populateDeviceInfo-2", dh1, true},
1110 {"populateDeviceInfo-3", dh1, true},
1111 {"populateDeviceInfo-4", dh1, true},
1112 {"populateDeviceInfo-5", dh2, true},
1113 }
1114 for _, tt := range tests {
1115 t.Run(tt.name, func(t *testing.T) {
1116
Neha Sharma96b7bf22020-06-15 10:37:32 +00001117 _, err := tt.devicehandler.populateDeviceInfo(context.Background())
kdarapu891693b2019-09-16 12:33:49 +05301118 if (err != nil) != tt.wantErr {
1119 t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr)
1120 return
1121 }
1122
1123 })
1124 }
1125}
1126
1127func TestDeviceHandler_readIndications(t *testing.T) {
1128 dh1 := newMockDeviceHandler()
1129 dh2 := newMockDeviceHandler()
kdarapu891693b2019-09-16 12:33:49 +05301130 dh3 := newMockDeviceHandler()
1131 dh3.device.AdminState = voltha.AdminState_DISABLED
1132 dh4 := negativeDeviceHandler()
1133 tests := []struct {
1134 name string
1135 devicehandler *DeviceHandler
1136 }{
1137 // TODO: Add test cases.
1138 {"readIndications-1", dh1},
1139 {"readIndications-2", dh2},
1140 {"readIndications-3", dh2},
1141 {"readIndications-4", dh2},
1142 {"readIndications-5", dh2},
1143 {"readIndications-6", dh3},
1144 {"readIndications-7", dh3},
1145 {"readIndications-8", dh4},
1146 }
1147 for _, tt := range tests {
1148 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301149 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1150 defer cancel()
Kent Hagermane6ff1012020-07-14 15:07:53 -04001151 _ = tt.devicehandler.readIndications(ctx)
1152 // TODO: actually verify test cases
kdarapu891693b2019-09-16 12:33:49 +05301153 })
1154 }
1155}
Naga Manjunath7615e552019-10-11 22:35:47 +05301156
1157func Test_startCollector(t *testing.T) {
1158 type args struct {
1159 dh *DeviceHandler
1160 }
1161 dh := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001162 dh.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301163 {PortNo: 1, Label: "pon", Type: voltha.Port_PON_OLT},
1164 {PortNo: 1048577, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1165 {PortNo: 1048578, Label: "nni", Type: voltha.Port_ETHERNET_NNI},
1166 }
Naga Manjunath7615e552019-10-11 22:35:47 +05301167 dh.portStats.NorthBoundPort = make(map[uint32]*NniPort)
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301168 dh.portStats.NorthBoundPort[1] = &NniPort{Name: "OLT-1"}
1169 dh.portStats.NorthBoundPort[2] = &NniPort{Name: "OLT-1"}
Naga Manjunath7615e552019-10-11 22:35:47 +05301170 dh.portStats.SouthBoundPort = make(map[uint32]*PonPort)
1171 dh.portStats.Device = dh
1172 for i := 0; i < 16; i++ {
1173 dh.portStats.SouthBoundPort[uint32(i)] = &PonPort{DeviceID: "OLT-1"}
1174 }
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301175 dh1 := newMockDeviceHandler()
Kent Hagermanf1db18b2020-07-08 13:38:15 -04001176 dh1.coreProxy.(*mocks.MockCoreProxy).DevicePorts[dh.device.Id] = []*voltha.Port{}
Naga Manjunath7615e552019-10-11 22:35:47 +05301177 tests := []struct {
1178 name string
1179 args args
1180 }{
1181 // TODO: Add test cases.
1182 {"StartCollector-1", args{dh}},
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301183 {"StartCollector-2", args{dh1}},
Naga Manjunath7615e552019-10-11 22:35:47 +05301184 }
1185 for _, tt := range tests {
1186 t.Run(tt.name, func(t *testing.T) {
1187 go func() {
Kishore Darapuaaf9c102020-05-04 13:06:57 +05301188 time.Sleep(1 * time.Second) // simulated wait time to stop startCollector
Naga Manjunath7615e552019-10-11 22:35:47 +05301189 tt.args.dh.stopCollector <- true
1190 }()
Neha Sharma96b7bf22020-06-15 10:37:32 +00001191 startCollector(context.Background(), tt.args.dh)
Naga Manjunath7615e552019-10-11 22:35:47 +05301192 })
1193 }
1194}