kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | a6af152 | 2023-01-17 16:06:16 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 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 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 17 | // Package core provides the utility for olt devices, flows and statistics |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 18 | package core |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 21 | "context" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 22 | "net" |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 23 | "reflect" |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 24 | "sync" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 25 | "testing" |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 26 | "time" |
| 27 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 28 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 29 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 30 | |
| 31 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 32 | fu "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 33 | plt "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 34 | "github.com/opencord/voltha-lib-go/v7/pkg/pmmetrics" |
| 35 | ponrmgr "github.com/opencord/voltha-lib-go/v7/pkg/ponresourcemanager" |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 36 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 37 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 38 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 39 | "github.com/opencord/voltha-openolt-adapter/pkg/mocks" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 40 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 41 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 42 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 43 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| 44 | "github.com/opencord/voltha-protos/v5/go/voltha" |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 45 | "github.com/stretchr/testify/assert" |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 46 | ) |
| 47 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 48 | const ( |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 49 | NumPonPorts = 16 |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 50 | OnuIDStart = 1 |
| 51 | OnuIDEnd = 32 |
| 52 | AllocIDStart = 1 |
| 53 | AllocIDEnd = 10 |
| 54 | GemIDStart = 1 |
| 55 | GemIDEnd = 10 |
| 56 | FlowIDStart = 1 |
| 57 | FlowIDEnd = 10 |
| 58 | ) |
| 59 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 60 | func newMockOnuInterAdapterService() *mocks.MockOnuInterAdapterService { |
| 61 | return &mocks.MockOnuInterAdapterService{} |
| 62 | } |
| 63 | |
| 64 | func newMockCoreService() *mocks.MockCoreService { |
| 65 | mcp := mocks.MockCoreService{ |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 66 | Devices: make(map[string]*voltha.Device), |
| 67 | DevicePorts: make(map[string][]*voltha.Port), |
| 68 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 69 | var pm []*voltha.PmConfig |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 70 | mcp.Devices["olt"] = &voltha.Device{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 71 | Id: "olt", |
| 72 | Root: true, |
| 73 | ParentId: "logical_device", |
| 74 | ParentPortNo: 1, |
| 75 | AdapterEndpoint: "mock-olt-endpoint", |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 76 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 77 | DeviceId: "olt", |
| 78 | DeviceType: "onu", |
| 79 | ChannelId: 1, |
| 80 | ChannelGroupId: 1, |
| 81 | }, |
| 82 | ConnectStatus: 1, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 83 | PmConfigs: &voltha.PmConfigs{ |
| 84 | DefaultFreq: 10, |
| 85 | Id: "olt", |
| 86 | FreqOverride: false, |
| 87 | Grouped: false, |
| 88 | Metrics: pm, |
| 89 | }, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 90 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 91 | mcp.DevicePorts["olt"] = []*voltha.Port{ |
| 92 | {PortNo: 1, Label: "pon"}, |
| 93 | {PortNo: 2, Label: "nni"}, |
| 94 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 95 | |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 96 | mcp.Devices["onu1"] = &voltha.Device{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 97 | Id: "1", |
| 98 | Root: false, |
| 99 | ParentId: "olt", |
| 100 | ParentPortNo: 1, |
| 101 | AdapterEndpoint: "mock-onu-endpoint", |
| 102 | OperStatus: 4, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 103 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 104 | OnuId: 1, |
| 105 | ChannelId: 1, |
| 106 | ChannelGroupId: 1, |
| 107 | }, |
| 108 | ConnectStatus: 1, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 109 | PmConfigs: &voltha.PmConfigs{ |
| 110 | DefaultFreq: 10, |
| 111 | Id: "olt", |
| 112 | FreqOverride: false, |
| 113 | Grouped: false, |
| 114 | Metrics: pm, |
| 115 | }, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 116 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 117 | mcp.DevicePorts["onu1"] = []*voltha.Port{ |
| 118 | {PortNo: 1, Label: "pon"}, |
| 119 | {PortNo: 2, Label: "uni"}, |
| 120 | } |
| 121 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 122 | mcp.Devices["onu2"] = &voltha.Device{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 123 | Id: "2", |
| 124 | Root: false, |
| 125 | ParentId: "olt", |
| 126 | OperStatus: 2, |
| 127 | AdapterEndpoint: "mock-onu-endpoint", |
| 128 | ParentPortNo: 1, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 129 | |
| 130 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 131 | OnuId: 2, |
| 132 | ChannelId: 1, |
| 133 | ChannelGroupId: 1, |
| 134 | }, |
| 135 | ConnectStatus: 1, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 136 | PmConfigs: &voltha.PmConfigs{ |
| 137 | DefaultFreq: 10, |
| 138 | Id: "olt", |
| 139 | FreqOverride: false, |
| 140 | Grouped: false, |
| 141 | Metrics: pm, |
| 142 | }, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 143 | } |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 144 | mcp.DevicePorts["onu2"] = []*voltha.Port{ |
| 145 | {PortNo: 1, Label: "pon"}, |
| 146 | {PortNo: 2, Label: "uni"}, |
| 147 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 148 | return &mcp |
| 149 | } |
| 150 | func newMockDeviceHandler() *DeviceHandler { |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 151 | device := &voltha.Device{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 152 | Id: "olt", |
| 153 | Root: true, |
| 154 | ParentId: "logical_device", |
| 155 | AdapterEndpoint: "mock-olt-endpoint", |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 156 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 157 | DeviceId: "olt", |
| 158 | DeviceType: "onu", |
| 159 | ChannelId: 1, |
| 160 | ChannelGroupId: 1, |
| 161 | }, |
Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 162 | ConnectStatus: 2, |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 163 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 164 | mcs := newMockCoreService() |
| 165 | cc := mocks.NewMockCoreClient(mcs) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 166 | ep := &mocks.MockEventProxy{} |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 167 | cm := &conf.ConfigManager{} |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 168 | cm.Backend = &db.Backend{StoreType: "etcd", Client: &mocks.MockKVClient{}} |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 169 | cfg := &config.AdapterFlags{OmccEncryption: true} |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 170 | openOLT := &OpenOLT{eventProxy: ep, config: cfg, KVStoreType: "etcd", KVStoreAddress: "1:2"} |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 171 | dh := NewDeviceHandler(cc, ep, device, openOLT, cm, cfg) |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 172 | dh.kvStore = cm.Backend |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 173 | oopRanges := []*oop.DeviceInfo_DeviceResourceRanges{{ |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 174 | IntfIds: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 175 | Technology: "xgs-pon", |
| 176 | Pools: []*oop.DeviceInfo_DeviceResourceRanges_Pool{{}}, |
| 177 | }} |
| 178 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 179 | deviceInf := &oop.DeviceInfo{Vendor: "openolt", Ranges: oopRanges, Model: "openolt", DeviceId: dh.device.Id, PonPorts: NumPonPorts} |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 180 | dh.deviceInfo = deviceInf |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 181 | dh.device = device |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 182 | dh.resourceMgr = make([]*resourcemanager.OpenOltResourceMgr, deviceInf.PonPorts+1) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 183 | var i uint32 |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 184 | for i = 0; i < deviceInf.PonPorts+1; i++ { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 185 | dh.resourceMgr[i] = &resourcemanager.OpenOltResourceMgr{DeviceID: dh.device.Id, DeviceType: dh.device.Type, DevInfo: deviceInf, |
| 186 | KVStore: &db.Backend{ |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 187 | StoreType: "etcd", |
| 188 | Client: &mocks.MockKVClient{}, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 189 | }} |
| 190 | dh.resourceMgr[i].InitLocalCache() |
| 191 | } |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 192 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 193 | ranges := make(map[string]interface{}) |
| 194 | sharedIdxByType := make(map[string]string) |
| 195 | sharedIdxByType["ALLOC_ID"] = "ALLOC_ID" |
| 196 | sharedIdxByType["ONU_ID"] = "ONU_ID" |
| 197 | sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID" |
| 198 | sharedIdxByType["FLOW_ID"] = "FLOW_ID" |
| 199 | ranges["ONU_ID"] = uint32(0) |
| 200 | ranges["GEMPORT_ID"] = uint32(0) |
| 201 | ranges["ALLOC_ID"] = uint32(0) |
| 202 | ranges["FLOW_ID"] = uint32(0) |
| 203 | ranges["onu_id_shared"] = uint32(0) |
| 204 | ranges["alloc_id_shared"] = uint32(0) |
| 205 | ranges["gemport_id_shared"] = uint32(0) |
| 206 | ranges["flow_id_shared"] = uint32(0) |
| 207 | |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 208 | ponmgr := &ponrmgr.PONResourceManager{} |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 209 | ponmgr.DeviceID = "onu-1" |
| 210 | ponmgr.IntfIDs = []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} |
| 211 | ponmgr.KVStore = &db.Backend{ |
| 212 | Client: &mocks.MockKVClient{}, |
| 213 | } |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 214 | ponmgr.KVStoreForConfig = &db.Backend{ |
| 215 | Client: &mocks.MockKVClient{}, |
| 216 | } |
| 217 | ponmgr.Backend = "etcd" |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 218 | ponmgr.PonResourceRanges = ranges |
| 219 | ponmgr.SharedIdxByType = sharedIdxByType |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 220 | ponmgr.Technology = "XGS-PON" |
| 221 | for i = 0; i < deviceInf.PonPorts; i++ { |
| 222 | dh.resourceMgr[i].PonRsrMgr = ponmgr |
| 223 | } |
| 224 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 225 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 226 | defer cancel() |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 227 | dh.groupMgr = NewGroupManager(ctx, dh, dh.resourceMgr[0]) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 228 | dh.totalPonPorts = NumPonPorts |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 229 | dh.flowMgr = make([]*OpenOltFlowMgr, dh.totalPonPorts+1) |
| 230 | for i = 0; i < dh.totalPonPorts+1; i++ { |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 231 | dh.flowMgr[i] = &OpenOltFlowMgr{} |
| 232 | dh.flowMgr[i].deviceHandler = dh |
| 233 | dh.flowMgr[i].ponPortIdx = i |
| 234 | dh.flowMgr[i].grpMgr = dh.groupMgr |
| 235 | dh.flowMgr[i].resourceMgr = dh.resourceMgr[i] |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 236 | dh.flowMgr[i].techprofile = mocks.MockTechProfile{} |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 237 | dh.flowMgr[i].packetInGemPort = make(map[resourcemanager.PacketInInfoKey]uint32) |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 238 | |
Girish Gowdra | 76a1b09 | 2021-07-28 10:07:04 -0700 | [diff] [blame] | 239 | dh.resourceMgr[i].TechprofileRef = dh.flowMgr[i].techprofile |
| 240 | |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 241 | // Create a slice of buffered channels for handling concurrent flows per ONU. |
| 242 | // The additional entry (+1) is to handle the NNI trap flows on a separate channel from individual ONUs channel |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 243 | dh.flowMgr[i].incomingFlows = make([]chan flowControlBlock, plt.MaxOnusPerPon+1) |
| 244 | dh.flowMgr[i].stopFlowHandlerRoutine = make([]chan bool, plt.MaxOnusPerPon+1) |
| 245 | dh.flowMgr[i].flowHandlerRoutineActive = make([]bool, plt.MaxOnusPerPon+1) |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 246 | for j := range dh.flowMgr[i].incomingFlows { |
| 247 | dh.flowMgr[i].incomingFlows[j] = make(chan flowControlBlock, maxConcurrentFlowsPerOnu) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 248 | dh.flowMgr[i].stopFlowHandlerRoutine[j] = make(chan bool, 1) |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 249 | // Spin up a go routine to handling incoming flows (add/remove). |
| 250 | // There will be on go routine per ONU. |
| 251 | // This routine will be blocked on the flowMgr.incomingFlows[onu-id] channel for incoming flows. |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 252 | dh.flowMgr[i].flowHandlerRoutineActive[j] = true |
| 253 | go dh.flowMgr[i].perOnuFlowHandlerRoutine(j, dh.flowMgr[i].incomingFlows[j], dh.flowMgr[i].stopFlowHandlerRoutine[j]) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 256 | dh.Client = &mocks.MockOpenoltClient{} |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 257 | dh.eventMgr = &OpenOltEventMgr{eventProxy: &mocks.MockEventProxy{}, handler: dh} |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 258 | dh.transitionMap = &TransitionMap{} |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 259 | dh.portStats = &OpenOltStatisticsMgr{} |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 260 | |
| 261 | var pmNames = []string{ |
| 262 | "rx_bytes", |
| 263 | "rx_packets", |
| 264 | "rx_mcast_packets", |
| 265 | "rx_bcast_packets", |
| 266 | "tx_bytes", |
| 267 | "tx_packets", |
| 268 | "tx_mcast_packets", |
| 269 | "tx_bcast_packets", |
| 270 | } |
| 271 | |
| 272 | dh.metrics = pmmetrics.NewPmMetrics(device.Id, pmmetrics.Frequency(2), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames)) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 273 | |
| 274 | // Set the children endpoints |
| 275 | dh.childAdapterClients = map[string]*vgrpc.Client{ |
| 276 | "mock-onu-endpoint": mocks.NewMockChildAdapterClient(newMockOnuInterAdapterService()), |
| 277 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 278 | return dh |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 279 | } |
| 280 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 281 | func negativeDeviceHandler() *DeviceHandler { |
| 282 | dh := newMockDeviceHandler() |
| 283 | device := dh.device |
| 284 | device.Id = "" |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 285 | return dh |
| 286 | } |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 287 | |
| 288 | func negativeDeviceHandlerNilFlowMgr() *DeviceHandler { |
| 289 | dh := newMockDeviceHandler() |
| 290 | dh.flowMgr = nil |
| 291 | return dh |
| 292 | } |
| 293 | |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 294 | func Test_generateMacFromHost(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 295 | ctx := context.Background() |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 296 | type args struct { |
| 297 | host string |
| 298 | } |
| 299 | tests := []struct { |
| 300 | name string |
| 301 | args args |
| 302 | want string |
| 303 | wantErr bool |
| 304 | }{ |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 305 | {"generateMacFromHost-1", args{host: "localhost"}, "00:00:7f:00:00:01", false}, |
| 306 | {"generateMacFromHost-2", args{host: "10.10.10.10"}, "00:00:0a:0a:0a:0a", false}, |
| 307 | //{"generateMacFromHost-3", args{host: "google.com"}, "00:00:d8:3a:c8:8e", false}, |
| 308 | {"generateMacFromHost-4", args{host: "testing3"}, "", true}, |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 309 | } |
| 310 | for _, tt := range tests { |
| 311 | t.Run(tt.name, func(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 312 | got, err := generateMacFromHost(ctx, tt.args.host) |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 313 | if (err != nil) != tt.wantErr { |
| 314 | t.Errorf("generateMacFromHost() error = %v, wantErr %v", err, tt.wantErr) |
| 315 | return |
| 316 | } |
| 317 | if got != tt.want { |
| 318 | t.Errorf("generateMacFromHost() = %v, want %v", got, tt.want) |
| 319 | } |
| 320 | }) |
| 321 | } |
| 322 | } |
| 323 | func Test_macifyIP(t *testing.T) { |
| 324 | type args struct { |
| 325 | ip net.IP |
| 326 | } |
| 327 | tests := []struct { |
| 328 | name string |
| 329 | args args |
| 330 | want string |
| 331 | }{{ |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 332 | "macifyIP-1", |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 333 | args{ip: net.ParseIP("10.10.10.10")}, |
| 334 | "00:00:0a:0a:0a:0a", |
| 335 | }, |
| 336 | { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 337 | "macifyIP-2", |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 338 | args{ip: net.ParseIP("127.0.0.1")}, |
| 339 | "00:00:7f:00:00:01", |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 340 | }, |
| 341 | { |
| 342 | "macifyIP-3", |
| 343 | args{ip: net.ParseIP("127.0.0.1/24")}, |
| 344 | "", |
| 345 | }, |
| 346 | } |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 347 | for _, tt := range tests { |
| 348 | t.Run(tt.name, func(t *testing.T) { |
| 349 | if got := macifyIP(tt.args.ip); got != tt.want { |
| 350 | t.Errorf("macifyIP() = %v, want %v", got, tt.want) |
| 351 | } |
| 352 | }) |
| 353 | } |
| 354 | } |
| 355 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 356 | func sparseCompare(keys []string, spec, target interface{}) bool { |
| 357 | if spec == target { |
| 358 | return true |
| 359 | } |
| 360 | if spec == nil || target == nil { |
| 361 | return false |
| 362 | } |
| 363 | typeSpec := reflect.TypeOf(spec) |
| 364 | typeTarget := reflect.TypeOf(target) |
| 365 | if typeSpec != typeTarget { |
| 366 | return false |
| 367 | } |
| 368 | |
| 369 | vSpec := reflect.ValueOf(spec) |
| 370 | vTarget := reflect.ValueOf(target) |
| 371 | if vSpec.Kind() == reflect.Ptr { |
| 372 | vSpec = vSpec.Elem() |
| 373 | vTarget = vTarget.Elem() |
| 374 | } |
| 375 | |
| 376 | for _, key := range keys { |
| 377 | fSpec := vSpec.FieldByName(key) |
| 378 | fTarget := vTarget.FieldByName(key) |
| 379 | if !reflect.DeepEqual(fSpec.Interface(), fTarget.Interface()) { |
| 380 | return false |
| 381 | } |
| 382 | } |
| 383 | return true |
| 384 | } |
| 385 | |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 386 | func TestDeviceHandler_GetChildDevice(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 387 | ctx := context.Background() |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 388 | dh1 := newMockDeviceHandler() |
| 389 | dh2 := negativeDeviceHandler() |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 390 | type args struct { |
| 391 | parentPort uint32 |
| 392 | onuID uint32 |
| 393 | } |
| 394 | tests := []struct { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 395 | name string |
| 396 | devicehandler *DeviceHandler |
| 397 | args args |
| 398 | want *voltha.Device |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 399 | errType reflect.Type |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 400 | }{ |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 401 | {"GetChildDevice-1", dh1, |
| 402 | args{parentPort: 1, |
| 403 | onuID: 1}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 404 | &voltha.Device{ |
| 405 | Id: "1", |
| 406 | ParentId: "olt", |
| 407 | ParentPortNo: 1, |
| 408 | }, |
| 409 | nil, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 410 | }, |
| 411 | {"GetChildDevice-2", dh2, |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 412 | args{parentPort: 1, |
| 413 | onuID: 1}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 414 | nil, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 415 | reflect.TypeOf(&olterrors.ErrNotFound{}), |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 416 | }, |
| 417 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-1 (0.00s) |
| 421 | 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>) |
| 422 | --- FAIL: TestDeviceHandler_GetChildDevice/GetChildDevice-2 (0.00s) |
| 423 | */ |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 424 | for _, tt := range tests { |
| 425 | t.Run(tt.name, func(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 426 | got, err := tt.devicehandler.GetChildDevice(ctx, tt.args.parentPort, tt.args.onuID) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 427 | if reflect.TypeOf(err) != tt.errType || !sparseCompare([]string{"Id", "ParentId", "ParentPortNo"}, tt.want, got) { |
| 428 | t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)", |
| 429 | tt.want, tt.errType, got, reflect.TypeOf(err)) |
| 430 | return |
| 431 | } |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 432 | t.Log("onu device id", got) |
| 433 | }) |
| 434 | } |
| 435 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 436 | |
| 437 | func TestGetportLabel(t *testing.T) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 438 | invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{}) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 439 | type args struct { |
| 440 | portNum uint32 |
| 441 | portType voltha.Port_PortType |
| 442 | } |
| 443 | tests := []struct { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 444 | name string |
| 445 | args args |
| 446 | want string |
| 447 | errType reflect.Type |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 448 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 449 | {"GetportLabel-1", args{portNum: 0, portType: 0}, "", invalid}, |
| 450 | {"GetportLabel-2", args{portNum: 1, portType: 1}, "nni-1", nil}, |
| 451 | {"GetportLabel-3", args{portNum: 2, portType: 2}, "", invalid}, |
| 452 | {"GetportLabel-4", args{portNum: 3, portType: 3}, "pon-3", nil}, |
| 453 | {"GetportLabel-5", args{portNum: 4, portType: 4}, "", invalid}, |
| 454 | {"GetportLabel-6", args{portNum: 5, portType: 5}, "", invalid}, |
| 455 | {"GetportLabel-7", args{portNum: 6, portType: 6}, "", invalid}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 456 | } |
| 457 | for _, tt := range tests { |
| 458 | t.Run(tt.name, func(t *testing.T) { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 459 | got, err := GetportLabel(tt.args.portNum, tt.args.portType) |
| 460 | if reflect.TypeOf(err) != tt.errType || got != tt.want { |
| 461 | t.Errorf("GetportLabel() => want=(%v, %v) got=(%v, %v)", |
| 462 | tt.want, tt.errType, got, reflect.TypeOf(err)) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 463 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 464 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 465 | }) |
| 466 | } |
| 467 | } |
| 468 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 469 | // func TestDeviceHandler_ProcessInterAdapterMessage(t *testing.T) { |
| 470 | // ctx := context.Background() |
| 471 | // dh := newMockDeviceHandler() |
| 472 | // proxyAddr := dh.device.ProxyAddress |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 473 | // body := &ca.InterAdapterOmciMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 474 | // Message: []byte("asdfasdfasdfasdfas"), |
| 475 | // ProxyAddress: proxyAddr, |
| 476 | // } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 477 | // body2 := &ca.InterAdapterOmciMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 478 | // Message: []byte("asdfasdfasdfasdfas"), |
| 479 | // //ProxyAddress: &voltha.Device_ProxyAddress{}, |
| 480 | // } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 481 | // body3 := &ca.InterAdapterTechProfileDownloadMessage{} |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 482 | // var marshalledData *any.Any |
| 483 | // var err error |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 484 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 485 | // if marshalledData, err = ptypes.MarshalAny(body); err != nil { |
| 486 | // logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"err": err}) |
| 487 | // } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 488 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 489 | // var marshalledData1 *any.Any |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 490 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 491 | // if marshalledData1, err = ptypes.MarshalAny(body2); err != nil { |
| 492 | // logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"err": err}) |
| 493 | // } |
| 494 | // var marshalledData2 *any.Any |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 495 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 496 | // if marshalledData2, err = ptypes.MarshalAny(body3); err != nil { |
| 497 | // logger.Errorw(ctx, "cannot-marshal-request", log.Fields{"err": err}) |
| 498 | // } |
| 499 | // type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 500 | // msg *ca.InterAdapterMessage |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 501 | // } |
| 502 | // invalid := reflect.TypeOf(&olterrors.ErrInvalidValue{}) |
| 503 | // tests := []struct { |
| 504 | // name string |
| 505 | // args args |
| 506 | // wantErr reflect.Type |
| 507 | // }{ |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 508 | // {"ProcessInterAdapterMessage-1", args{msg: &ca.InterAdapterMessage{ |
| 509 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 510 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 511 | // Type: ca.InterAdapterMessageType_FLOW_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 512 | // }, |
| 513 | // Body: marshalledData, |
| 514 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 515 | // {"ProcessInterAdapterMessage-2", args{msg: &ca.InterAdapterMessage{ |
| 516 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 517 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 518 | // Type: ca.InterAdapterMessageType_FLOW_RESPONSE, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 519 | // }, |
| 520 | // Body: marshalledData1, |
| 521 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 522 | // {"ProcessInterAdapterMessage-3", args{msg: &ca.InterAdapterMessage{ |
| 523 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 524 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 525 | // Type: ca.InterAdapterMessageType_OMCI_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 526 | // }, |
| 527 | // Body: marshalledData, |
| 528 | // }}, reflect.TypeOf(&olterrors.ErrCommunication{})}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 529 | // {"ProcessInterAdapterMessage-4", args{msg: &ca.InterAdapterMessage{ |
| 530 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 531 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 532 | // Type: ca.InterAdapterMessageType_OMCI_RESPONSE, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 533 | // }, Body: marshalledData, |
| 534 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 535 | // {"ProcessInterAdapterMessage-5", args{msg: &ca.InterAdapterMessage{ |
| 536 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 537 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 538 | // Type: ca.InterAdapterMessageType_METRICS_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 539 | // }, Body: marshalledData1, |
| 540 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 541 | // {"ProcessInterAdapterMessage-6", args{msg: &ca.InterAdapterMessage{ |
| 542 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 543 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 544 | // Type: ca.InterAdapterMessageType_METRICS_RESPONSE, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 545 | // }, Body: marshalledData, |
| 546 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 547 | // {"ProcessInterAdapterMessage-7", args{msg: &ca.InterAdapterMessage{ |
| 548 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 549 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 550 | // Type: ca.InterAdapterMessageType_ONU_IND_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 551 | // }, Body: marshalledData, |
| 552 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 553 | // {"ProcessInterAdapterMessage-8", args{msg: &ca.InterAdapterMessage{ |
| 554 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 555 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 556 | // Type: ca.InterAdapterMessageType_ONU_IND_RESPONSE, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 557 | // }, Body: marshalledData, |
| 558 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 559 | // {"ProcessInterAdapterMessage-9", args{msg: &ca.InterAdapterMessage{ |
| 560 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 561 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 562 | // Type: ca.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 563 | // }, Body: marshalledData, |
| 564 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 565 | // {"ProcessInterAdapterMessage-10", args{msg: &ca.InterAdapterMessage{ |
| 566 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 567 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 568 | // Type: ca.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 569 | // }, Body: marshalledData2, |
| 570 | // }}, invalid}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 571 | // {"ProcessInterAdapterMessage-11", args{msg: &ca.InterAdapterMessage{ |
| 572 | // Header: &ca.InterAdapterHeader{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 573 | // Id: "012345", |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 574 | // Type: ca.InterAdapterMessageType_DELETE_TCONT_REQUEST, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 575 | // }, Body: marshalledData2, |
| 576 | // }}, invalid}, |
| 577 | // } |
| 578 | // for _, tt := range tests { |
| 579 | // t.Run(tt.name, func(t *testing.T) { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 580 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 581 | // if err := dh.ProcessInterAdapterMessage(ctx, tt.args.msg); reflect.TypeOf(err) != tt.wantErr { |
| 582 | // t.Errorf("DeviceHandler.ProcessInterAdapterMessage() error = %v, wantErr %v", err, tt.wantErr) |
| 583 | // } |
| 584 | // }) |
| 585 | // } |
| 586 | // } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 587 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 588 | func TestDeviceHandler_ProxyOmciMessage(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 589 | ctx := context.Background() |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 590 | dh1 := newMockDeviceHandler() |
| 591 | dh2 := negativeDeviceHandler() |
| 592 | device1 := &voltha.Device{ |
| 593 | Id: "onu1", |
| 594 | Root: false, |
| 595 | ParentId: "logical_device", |
| 596 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 597 | DeviceId: "onu1", |
| 598 | DeviceType: "onu", |
| 599 | ChannelId: 1, |
| 600 | ChannelGroupId: 1, |
| 601 | }, |
| 602 | ConnectStatus: 1, |
| 603 | } |
| 604 | device2 := device1 |
| 605 | device2.ConnectStatus = 2 |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 606 | iaomciMsg1 := &ia.OmciMessage{ |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 607 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 608 | DeviceId: "onu2", |
| 609 | DeviceType: "onu", |
| 610 | ChannelId: 1, |
| 611 | ChannelGroupId: 1, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 612 | }, |
| 613 | ConnectStatus: 1, |
| 614 | } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 615 | iaomciMsg2 := &ia.OmciMessage{ |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 616 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 617 | DeviceId: "onu3", |
| 618 | DeviceType: "onu", |
| 619 | ChannelId: 1, |
| 620 | ChannelGroupId: 1, |
| 621 | }, |
| 622 | ConnectStatus: 1, |
| 623 | } |
| 624 | type args struct { |
| 625 | onuDevice *voltha.Device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 626 | omciMsg *ia.OmciMessage |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 627 | } |
| 628 | tests := []struct { |
| 629 | name string |
| 630 | devicehandler *DeviceHandler |
| 631 | args args |
| 632 | }{ |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 633 | {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ia.OmciMessage{}}}, |
| 634 | {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ia.OmciMessage{}}}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 635 | {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}}, |
| 636 | {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}}, |
| 637 | {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}}, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 638 | {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ia.OmciMessage{}}}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 639 | } |
| 640 | for _, tt := range tests { |
| 641 | t.Run(tt.name, func(t *testing.T) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 642 | _ = tt.devicehandler.ProxyOmciMessage(ctx, tt.args.omciMsg) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 643 | //TODO: actually verify test cases |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 644 | }) |
| 645 | } |
| 646 | } |
| 647 | |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 648 | func TestDeviceHandler_ProxyOmciRequests(t *testing.T) { |
| 649 | ctx := context.Background() |
| 650 | dh1 := newMockDeviceHandler() |
| 651 | dh2 := negativeDeviceHandler() |
| 652 | device1 := &voltha.Device{ |
| 653 | Id: "onu1", |
| 654 | Root: false, |
| 655 | ParentId: "logical_device", |
| 656 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 657 | DeviceId: "onu1", |
| 658 | DeviceType: "onu", |
| 659 | ChannelId: 1, |
| 660 | ChannelGroupId: 1, |
| 661 | }, |
| 662 | ConnectStatus: 1, |
| 663 | } |
| 664 | device2 := device1 |
| 665 | device2.ConnectStatus = 2 |
| 666 | |
| 667 | iaomciMsg1 := &ia.OmciMessages{ |
| 668 | ConnectStatus: 1, |
| 669 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 670 | DeviceId: "onu2", |
| 671 | DeviceType: "onu", |
| 672 | ChannelId: 1, |
| 673 | ChannelGroupId: 1, |
| 674 | }, |
| 675 | } |
| 676 | |
| 677 | iaomciMsg2 := &ia.OmciMessages{ |
| 678 | ConnectStatus: 1, |
| 679 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 680 | DeviceId: "onu3", |
| 681 | DeviceType: "onu", |
| 682 | ChannelId: 1, |
| 683 | ChannelGroupId: 1, |
| 684 | }, |
| 685 | } |
| 686 | |
| 687 | type args struct { |
| 688 | onuDevice *voltha.Device |
| 689 | omciMsg *ia.OmciMessages |
| 690 | } |
| 691 | tests := []struct { |
| 692 | name string |
| 693 | devicehandler *DeviceHandler |
| 694 | args args |
| 695 | }{ |
| 696 | {"sendProxiedMessage-1", dh1, args{onuDevice: device1, omciMsg: &ia.OmciMessages{}}}, |
| 697 | {"sendProxiedMessage-2", dh1, args{onuDevice: device2, omciMsg: &ia.OmciMessages{}}}, |
| 698 | {"sendProxiedMessage-3", dh1, args{onuDevice: nil, omciMsg: iaomciMsg1}}, |
| 699 | {"sendProxiedMessage-4", dh1, args{onuDevice: nil, omciMsg: iaomciMsg2}}, |
| 700 | {"sendProxiedMessage-5", dh2, args{onuDevice: nil, omciMsg: iaomciMsg2}}, |
| 701 | {"sendProxiedMessage-6", dh2, args{onuDevice: device1, omciMsg: &ia.OmciMessages{}}}, |
| 702 | } |
| 703 | for _, tt := range tests { |
| 704 | t.Run(tt.name, func(t *testing.T) { |
| 705 | switch tt.name { |
| 706 | case "sendProxiedMessage-1": |
| 707 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 708 | assert.Contains(t, err.Error(), "no deviceID") |
| 709 | case "sendProxiedMessage-2": |
| 710 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 711 | assert.Contains(t, err.Error(), "no deviceID") |
| 712 | case "sendProxiedMessage-3": |
| 713 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 714 | assert.Contains(t, err.Error(), "failed-communication") |
| 715 | case "sendProxiedMessage-4": |
| 716 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 717 | assert.Contains(t, err.Error(), "failed-communication") |
| 718 | case "sendProxiedMessage-5": |
| 719 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 720 | assert.Contains(t, err.Error(), "failed-communication") |
| 721 | case "sendProxiedMessage-6": |
| 722 | err := tt.devicehandler.ProxyOmciRequests(ctx, tt.args.omciMsg) |
| 723 | assert.Contains(t, err.Error(), "no deviceID") |
| 724 | |
| 725 | } |
| 726 | |
| 727 | }) |
| 728 | } |
| 729 | } |
| 730 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 731 | func TestDeviceHandler_SendPacketInToCore(t *testing.T) { |
| 732 | dh1 := newMockDeviceHandler() |
| 733 | dh2 := negativeDeviceHandler() |
| 734 | |
| 735 | type args struct { |
| 736 | logicalPort uint32 |
| 737 | packetPayload []byte |
| 738 | } |
| 739 | tests := []struct { |
| 740 | name string |
| 741 | devicehandler *DeviceHandler |
| 742 | args args |
| 743 | }{ |
| 744 | {"SendPacketInToCore-1", dh1, args{logicalPort: 1, packetPayload: []byte("test1")}}, |
| 745 | {"SendPacketInToCore-2", dh1, args{logicalPort: 1, packetPayload: []byte("")}}, |
| 746 | {"SendPacketInToCore-3", dh2, args{logicalPort: 1, packetPayload: []byte("test1")}}, |
| 747 | } |
| 748 | for _, tt := range tests { |
| 749 | t.Run(tt.name, func(t *testing.T) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 750 | _ = tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload) |
| 751 | //TODO: actually verify test cases |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 752 | }) |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | func TestDeviceHandler_DisableDevice(t *testing.T) { |
| 757 | dh1 := newMockDeviceHandler() |
| 758 | dh2 := negativeDeviceHandler() |
| 759 | type args struct { |
| 760 | device *voltha.Device |
| 761 | } |
| 762 | tests := []struct { |
| 763 | name string |
| 764 | devicehandler *DeviceHandler |
| 765 | args args |
| 766 | wantErr bool |
| 767 | }{ |
| 768 | {"DisableDevice-1", dh1, args{device: dh1.device}, false}, |
Chaitrashree G S | 3b4c035 | 2019-09-09 20:59:29 -0400 | [diff] [blame] | 769 | {"DisableDevice-2", dh1, args{device: dh2.device}, true}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 770 | } |
| 771 | for _, tt := range tests { |
| 772 | t.Run(tt.name, func(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 773 | if err := tt.devicehandler.DisableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 774 | t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr) |
| 775 | } |
| 776 | }) |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | func TestDeviceHandler_ReenableDevice(t *testing.T) { |
| 781 | dh1 := newMockDeviceHandler() |
| 782 | dh2 := negativeDeviceHandler() |
| 783 | type args struct { |
| 784 | device *voltha.Device |
| 785 | } |
| 786 | tests := []struct { |
| 787 | name string |
| 788 | devicehandler *DeviceHandler |
| 789 | args args |
| 790 | wantErr bool |
| 791 | }{ |
| 792 | {"ReenableDevice-1", dh1, args{device: dh1.device}, false}, |
| 793 | {"ReenableDevice-2", dh1, args{device: &voltha.Device{}}, true}, |
| 794 | {"ReenableDevice-3", dh2, args{device: dh1.device}, false}, |
| 795 | } |
| 796 | for _, tt := range tests { |
| 797 | t.Run(tt.name, func(t *testing.T) { |
| 798 | dh := tt.devicehandler |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 799 | if err := dh.ReenableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 800 | t.Errorf("DeviceHandler.ReenableDevice() error = %v, wantErr %v", err, tt.wantErr) |
| 801 | } |
| 802 | }) |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | func TestDeviceHandler_RebootDevice(t *testing.T) { |
| 807 | dh1 := newMockDeviceHandler() |
| 808 | dh2 := newMockDeviceHandler() |
| 809 | type args struct { |
| 810 | device *voltha.Device |
| 811 | } |
| 812 | tests := []struct { |
| 813 | name string |
| 814 | devicehandler *DeviceHandler |
| 815 | args args |
| 816 | wantErr bool |
| 817 | }{ |
| 818 | // TODO: Add test cases. |
| 819 | {"RebootDevice-1", dh1, args{device: dh1.device}, false}, |
| 820 | {"RebootDevice-2", dh1, args{device: dh2.device}, true}, |
| 821 | {"RebootDevice-3", dh2, args{device: dh2.device}, false}, |
| 822 | } |
| 823 | for _, tt := range tests { |
| 824 | t.Run(tt.name, func(t *testing.T) { |
| 825 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 826 | if err := tt.devicehandler.RebootDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 827 | t.Errorf("DeviceHandler.RebootDevice() error = %v, wantErr %v", err, tt.wantErr) |
| 828 | } |
| 829 | }) |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | func TestDeviceHandler_handleIndication(t *testing.T) { |
| 834 | dh1 := newMockDeviceHandler() |
| 835 | dh2 := negativeDeviceHandler() |
| 836 | dh3 := newMockDeviceHandler() |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 837 | dh3.onus = sync.Map{} |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 838 | dh3.onus.Store("onu1", NewOnuDevice("onu1", "onu1", "onu1", 1, 1, "onu1", false, "mock_endpoint")) |
| 839 | dh3.onus.Store("onu2", NewOnuDevice("onu2", "onu2", "onu2", 2, 2, "onu2", false, "mock_endpoint")) |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 840 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 841 | type args struct { |
| 842 | indication *oop.Indication |
| 843 | } |
| 844 | tests := []struct { |
| 845 | name string |
| 846 | deviceHandler *DeviceHandler |
| 847 | args args |
| 848 | }{ |
| 849 | // TODO: Add test cases. |
| 850 | {"handleIndication-1", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}}, |
| 851 | {"handleIndication-2", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}}, |
| 852 | {"handleIndication-3", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}}, |
| 853 | {"handleIndication-4", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}}, |
| 854 | {"handleIndication-5", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}}, |
| 855 | {"handleIndication-6", dh1, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}}, |
| 856 | {"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")}}}}}}, |
| 857 | {"handleIndication-8", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}}, |
| 858 | {"handleIndication-9", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}}, |
| 859 | {"handleIndication-10", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}}, |
| 860 | {"handleIndication-11", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}}, |
| 861 | {"handleIndication-12", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}}, |
| 862 | {"handleIndication-13", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}}, |
| 863 | {"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}}}}}, |
| 864 | {"handleIndication-15", dh1, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}}, |
| 865 | {"handleIndication-16", dh1, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}}, |
| 866 | {"handleIndication-17", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", FlowId: 1234, PortNo: 1}}}}}, |
| 867 | {"handleIndication-18", dh1, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{}}}}}, |
| 868 | |
| 869 | // Negative testcases |
| 870 | {"handleIndication-19", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "up"}}}}}, |
| 871 | {"handleIndication-20", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OltInd{OltInd: &oop.OltIndication{OperState: "down"}}}}}, |
| 872 | {"handleIndication-21", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "up"}}}}}, |
| 873 | {"handleIndication-22", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfInd{IntfInd: &oop.IntfIndication{IntfId: 1, OperState: "down"}}}}}, |
| 874 | {"handleIndication-23", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "nni", IntfId: 1, OperState: "up"}}}}}, |
| 875 | {"handleIndication-24", dh2, args{indication: &oop.Indication{Data: &oop.Indication_IntfOperInd{IntfOperInd: &oop.IntfOperIndication{Type: "pon", IntfId: 1, OperState: "up"}}}}}, |
| 876 | {"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")}}}}}}, |
| 877 | {"handleIndication-26", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}}, |
| 878 | {"handleIndication-27", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}}, |
| 879 | {"handleIndication-28", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}}, |
| 880 | {"handleIndication-29", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}}, |
| 881 | {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 1, Pkt: []byte("onu123-random value")}}}}}, |
| 882 | {"handleIndication-31", dh2, args{indication: &oop.Indication{Data: &oop.Indication_PktInd{PktInd: &oop.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 1234, PortNo: 1}}}}}, |
| 883 | {"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}}}}}, |
| 884 | {"handleIndication-33", dh2, args{indication: &oop.Indication{Data: &oop.Indication_FlowStats{FlowStats: &oop.FlowStatistics{RxBytes: 100, RxPackets: 100, TxBytes: 100, TxPackets: 100, Timestamp: 1000}}}}}, |
| 885 | {"handleIndication-34", dh2, args{indication: &oop.Indication{Data: &oop.Indication_AlarmInd{AlarmInd: &oop.AlarmIndication{}}}}}, |
| 886 | // |
| 887 | {"handleIndication-35", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "up"}}}}}, |
| 888 | {"handleIndication-36", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "up"}}}}}, |
| 889 | {"handleIndication-37", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "up", AdminState: "down"}}}}}, |
| 890 | {"handleIndication-38", dh3, args{indication: &oop.Indication{Data: &oop.Indication_OnuInd{OnuInd: &oop.OnuIndication{IntfId: 1, OnuId: 1, OperState: "down", AdminState: "down"}}}}}, |
| 891 | {"handleIndication-30", dh1, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}}, |
| 892 | {"handleIndication-30", dh2, args{indication: &oop.Indication{Data: &oop.Indication_OmciInd{OmciInd: &oop.OmciIndication{IntfId: 1, OnuId: 4, Pkt: []byte("onu123-random value")}}}}}, |
| 893 | } |
| 894 | for _, tt := range tests { |
| 895 | t.Run(tt.name, func(t *testing.T) { |
| 896 | dh := tt.deviceHandler |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 897 | time.Sleep(5 * time.Millisecond) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 898 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 899 | defer cancel() |
| 900 | dh.handleIndication(ctx, tt.args.indication) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 901 | }) |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | func TestDeviceHandler_addPort(t *testing.T) { |
| 906 | dh1 := newMockDeviceHandler() |
| 907 | dh2 := negativeDeviceHandler() |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 908 | |
| 909 | const defaultCapacity = uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 910 | type args struct { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 911 | intfID uint32 |
| 912 | portType voltha.Port_PortType |
| 913 | state string |
| 914 | speedMbps uint32 |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 915 | } |
| 916 | tests := []struct { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 917 | name string |
| 918 | devicehandler *DeviceHandler |
| 919 | args args |
| 920 | expectedCapacity uint32 |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 921 | }{ |
| 922 | // State up |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 923 | {"addPort.1", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "up"}, defaultCapacity}, |
| 924 | {"addPort.2", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "up"}, defaultCapacity}, |
| 925 | {"addPort.3", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "up"}, defaultCapacity}, |
| 926 | {"addPort.4", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: defaultPortSpeedMbps}, defaultCapacity}, |
| 927 | {"addPort.5", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}, defaultCapacity}, |
| 928 | {"addPort.6", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "up"}, defaultCapacity}, |
| 929 | {"addPort.7", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "up"}, defaultCapacity}, |
| 930 | {"addPort.8", dh1, args{intfID: 1, portType: 8, state: "up"}, defaultCapacity}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 931 | // state discovery |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 932 | {"addPort.9", dh1, args{intfID: 1, portType: voltha.Port_UNKNOWN, state: "down"}, defaultCapacity}, |
| 933 | {"addPort.10", dh1, args{intfID: 1, portType: voltha.Port_VENET_OLT, state: "down"}, defaultCapacity}, |
| 934 | {"addPort.11", dh1, args{intfID: 1, portType: voltha.Port_VENET_ONU, state: "down"}, defaultCapacity}, |
| 935 | {"addPort.12", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down", speedMbps: defaultPortSpeedMbps}, defaultCapacity}, |
| 936 | {"addPort.13", dh1, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}, defaultCapacity}, |
| 937 | {"addPort.14", dh1, args{intfID: 1, portType: voltha.Port_PON_OLT, state: "down"}, defaultCapacity}, |
| 938 | {"addPort.15", dh1, args{intfID: 1, portType: voltha.Port_PON_ONU, state: "down"}, defaultCapacity}, |
| 939 | {"addPort.16", dh1, args{intfID: 1, portType: 8, state: "down"}, defaultCapacity}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 940 | |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 941 | {"addPort.17", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: defaultPortSpeedMbps}, defaultCapacity}, |
| 942 | {"addPort.18", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "up"}, defaultCapacity}, |
| 943 | {"addPort.19", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "down", speedMbps: defaultPortSpeedMbps}, defaultCapacity}, |
| 944 | {"addPort.20", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_UNI, state: "down"}, defaultCapacity}, |
| 945 | |
| 946 | // NNI speeds |
| 947 | {"addPort.21", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 0}, defaultCapacity}, |
| 948 | {"addPort.22", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 10}, uint32(of.OfpPortFeatures_OFPPF_10MB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 949 | {"addPort.23", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 100}, uint32(of.OfpPortFeatures_OFPPF_100MB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 950 | {"addPort.24", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 1000}, uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 951 | {"addPort.25", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 10000}, uint32(of.OfpPortFeatures_OFPPF_10GB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 952 | {"addPort.26", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 40000}, uint32(of.OfpPortFeatures_OFPPF_40GB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 953 | {"addPort.27", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 100000}, uint32(of.OfpPortFeatures_OFPPF_100GB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 954 | {"addPort.28", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 1000000}, uint32(of.OfpPortFeatures_OFPPF_1TB_FD | of.OfpPortFeatures_OFPPF_FIBER)}, |
| 955 | {"addPort.29", dh2, args{intfID: 1, portType: voltha.Port_ETHERNET_NNI, state: "up", speedMbps: 12345}, uint32(of.OfpPortFeatures_OFPPF_OTHER | of.OfpPortFeatures_OFPPF_FIBER)}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 956 | } |
| 957 | for _, tt := range tests { |
| 958 | t.Run(tt.name, func(t *testing.T) { |
Elia Battiston | 596406d | 2022-02-02 12:19:00 +0100 | [diff] [blame] | 959 | _ = tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state, tt.args.speedMbps) |
| 960 | |
| 961 | //Check if the correct state is stored |
| 962 | storedState, ok := tt.devicehandler.activePorts.Load(tt.args.intfID) |
| 963 | expectedState := tt.args.state == "up" |
| 964 | |
| 965 | if !ok { |
| 966 | t.Errorf("Port state not stored in test %v", tt.name) |
| 967 | } else if storedState != expectedState { |
| 968 | t.Errorf("Expected stored port state: %v, found: %v in test %v", expectedState, storedState, tt.name) |
| 969 | } |
| 970 | |
| 971 | //Check if the reported speed values are correct |
| 972 | ofpPort := makeOfpPort(tt.devicehandler.device.MacAddress, tt.args.speedMbps) |
| 973 | |
| 974 | if ofpPort.Curr != tt.expectedCapacity || |
| 975 | ofpPort.Advertised != tt.expectedCapacity || |
| 976 | ofpPort.Peer != tt.expectedCapacity { |
| 977 | t.Errorf("Expected port capacity: %v, found: (%v,%v,%v) in test %v", tt.expectedCapacity, ofpPort.Curr, ofpPort.Advertised, ofpPort.Peer, tt.name) |
| 978 | } |
| 979 | |
| 980 | var expectedSpeedKbps uint32 |
| 981 | if tt.args.speedMbps == 0 { |
| 982 | expectedSpeedKbps = defaultPortSpeedMbps * 1000 |
| 983 | } else { |
| 984 | expectedSpeedKbps = tt.args.speedMbps * 1000 |
| 985 | } |
| 986 | |
| 987 | if ofpPort.CurrSpeed != expectedSpeedKbps || |
| 988 | ofpPort.MaxSpeed != expectedSpeedKbps { |
| 989 | t.Errorf("Expected port speed: %v, found: (%v,%v) in test %v", expectedSpeedKbps, ofpPort.CurrSpeed, ofpPort.MaxSpeed, tt.name) |
| 990 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 991 | }) |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | func Test_macAddressToUint32Array(t *testing.T) { |
| 996 | type args struct { |
| 997 | mac string |
| 998 | } |
| 999 | tests := []struct { |
| 1000 | name string |
| 1001 | args args |
| 1002 | want []uint32 |
| 1003 | }{ |
| 1004 | // TODO: Add test cases. |
| 1005 | {"macAddressToUint32Array-1", args{mac: "00:00:00:00:00:01"}, []uint32{0, 0, 0, 0, 0, 1}}, |
| 1006 | {"macAddressToUint32Array-2", args{mac: "0abcdef"}, []uint32{11259375}}, |
| 1007 | {"macAddressToUint32Array-3", args{mac: "testing"}, []uint32{1, 2, 3, 4, 5, 6}}, |
| 1008 | } |
| 1009 | for _, tt := range tests { |
| 1010 | t.Run(tt.name, func(t *testing.T) { |
| 1011 | if got := macAddressToUint32Array(tt.args.mac); !reflect.DeepEqual(got, tt.want) { |
| 1012 | t.Errorf("macAddressToUint32Array() = %v, want %v", got, tt.want) |
| 1013 | } |
| 1014 | }) |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | func TestDeviceHandler_handleOltIndication(t *testing.T) { |
| 1019 | |
| 1020 | type args struct { |
| 1021 | oltIndication *oop.OltIndication |
| 1022 | } |
| 1023 | tests := []struct { |
| 1024 | name string |
| 1025 | args args |
| 1026 | }{ |
| 1027 | {"handleOltIndication-1", args{oltIndication: &oop.OltIndication{OperState: "up"}}}, |
| 1028 | {"handleOltIndication-2", args{oltIndication: &oop.OltIndication{OperState: "down"}}}, |
| 1029 | } |
| 1030 | for _, tt := range tests { |
| 1031 | t.Run(tt.name, func(t *testing.T) { |
| 1032 | dh := newMockDeviceHandler() |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1033 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1034 | defer cancel() |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1035 | if err := dh.handleOltIndication(ctx, tt.args.oltIndication); err != nil { |
| 1036 | t.Error(err) |
| 1037 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1038 | }) |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | func TestDeviceHandler_AdoptDevice(t *testing.T) { |
| 1043 | dh1 := newMockDeviceHandler() |
| 1044 | dh2 := negativeDeviceHandler() |
| 1045 | type args struct { |
| 1046 | device *voltha.Device |
| 1047 | } |
| 1048 | tests := []struct { |
| 1049 | name string |
| 1050 | devicehandler *DeviceHandler |
| 1051 | args args |
| 1052 | }{ |
| 1053 | // TODO: Add test cases. |
| 1054 | {"AdoptDevice-1", dh1, args{device: dh1.device}}, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1055 | {"AdoptDevice-2", dh2, args{device: dh2.device}}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1056 | } |
| 1057 | for _, tt := range tests { |
| 1058 | t.Run(tt.name, func(t *testing.T) { |
| 1059 | //dh.doStateInit() |
| 1060 | // context. |
| 1061 | //dh.AdoptDevice(tt.args.device) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1062 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1063 | defer cancel() |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1064 | if err := tt.devicehandler.postInit(ctx); err != nil { |
| 1065 | t.Error(err) |
| 1066 | } |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1067 | }) |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | func TestDeviceHandler_activateONU(t *testing.T) { |
| 1072 | dh := newMockDeviceHandler() |
| 1073 | dh1 := negativeDeviceHandler() |
| 1074 | type args struct { |
| 1075 | intfID uint32 |
| 1076 | onuID int64 |
| 1077 | serialNum *oop.SerialNumber |
| 1078 | serialNumber string |
| 1079 | } |
| 1080 | tests := []struct { |
| 1081 | name string |
| 1082 | devicehandler *DeviceHandler |
| 1083 | args args |
| 1084 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 1085 | {"activateONU-1", dh, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}}, |
| 1086 | {"activateONU-2", dh, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}}, |
| 1087 | {"activateONU-3", dh1, args{intfID: 0, onuID: 1, serialNum: &oop.SerialNumber{VendorId: []byte("onu1")}}}, |
| 1088 | {"activateONU-4", dh1, args{intfID: 1, onuID: 2, serialNum: &oop.SerialNumber{VendorId: []byte("onu2")}}}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1089 | } |
| 1090 | for _, tt := range tests { |
| 1091 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1092 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1093 | defer cancel() |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1094 | _ = tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum, tt.args.serialNumber) |
| 1095 | //TODO: actually verify test cases |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1096 | }) |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | func TestDeviceHandler_start(t *testing.T) { |
| 1101 | dh := newMockDeviceHandler() |
| 1102 | dh1 := negativeDeviceHandler() |
| 1103 | dh.start(context.Background()) |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 1104 | dh.Stop(context.Background()) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1105 | |
| 1106 | dh1.start(context.Background()) |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 1107 | dh1.Stop(context.Background()) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1108 | |
| 1109 | } |
| 1110 | |
| 1111 | func TestDeviceHandler_PacketOut(t *testing.T) { |
| 1112 | dh1 := newMockDeviceHandler() |
| 1113 | dh2 := negativeDeviceHandler() |
| 1114 | acts := []*ofp.OfpAction{ |
| 1115 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))), |
| 1116 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 1117 | fu.Output(1), |
| 1118 | } |
| 1119 | pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUxBgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")} |
| 1120 | type args struct { |
| 1121 | egressPortNo int |
| 1122 | packet *of.OfpPacketOut |
| 1123 | } |
| 1124 | tests := []struct { |
| 1125 | name string |
| 1126 | devicehandler *DeviceHandler |
| 1127 | args args |
| 1128 | wantErr bool |
| 1129 | }{ |
| 1130 | // TODO: Add test cases. |
| 1131 | //{"test1", args{egressPortNo: 0, packet: &ofp.OfpPacketOut{}}, true}, |
| 1132 | {"PacketOut-1", dh1, args{egressPortNo: 0, packet: pktout}, false}, |
| 1133 | {"PacketOut-2", dh2, args{egressPortNo: 1, packet: pktout}, false}, |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 1134 | {"PacketOut-3", dh2, args{egressPortNo: 4112, packet: pktout}, false}, |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 1135 | {"PacketOut-4", dh1, args{egressPortNo: 16777217, packet: pktout}, false}, |
| 1136 | {"PacketOut-5", dh2, args{egressPortNo: 16777216, packet: pktout}, false}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1137 | } |
| 1138 | for _, tt := range tests { |
| 1139 | t.Run(tt.name, func(t *testing.T) { |
| 1140 | dh := tt.devicehandler |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1141 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1142 | defer cancel() |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1143 | if err := dh.PacketOut(ctx, uint32(tt.args.egressPortNo), tt.args.packet); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1144 | t.Errorf("DeviceHandler.PacketOut() error = %v, wantErr %v", err, tt.wantErr) |
| 1145 | } |
| 1146 | }) |
| 1147 | } |
| 1148 | } |
| 1149 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1150 | func TestDeviceHandler_doStateUp(t *testing.T) { |
| 1151 | dh1 := newMockDeviceHandler() |
| 1152 | dh2 := newMockDeviceHandler() |
| 1153 | |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1154 | dh2.device.Id = "" |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1155 | dh3 := negativeDeviceHandler() |
| 1156 | |
| 1157 | tests := []struct { |
| 1158 | name string |
| 1159 | devicehandler *DeviceHandler |
| 1160 | wantErr bool |
| 1161 | }{ |
| 1162 | {"dostateup-1", dh1, false}, |
| 1163 | {"dostateup-2", dh2, false}, |
| 1164 | {"dostateup-3", dh3, true}, |
| 1165 | } |
| 1166 | for _, tt := range tests { |
| 1167 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1168 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1169 | defer cancel() |
| 1170 | if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1171 | t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr) |
| 1172 | } |
Thomas Lee S | 85f3731 | 2020-04-03 17:06:12 +0530 | [diff] [blame] | 1173 | tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1174 | }) |
| 1175 | } |
| 1176 | } |
| 1177 | func TestDeviceHandler_doStateDown(t *testing.T) { |
| 1178 | dh1 := newMockDeviceHandler() |
| 1179 | dh2 := negativeDeviceHandler() |
| 1180 | dh3 := newMockDeviceHandler() |
| 1181 | dh3.device.OperStatus = voltha.OperStatus_UNKNOWN |
| 1182 | tests := []struct { |
| 1183 | name string |
| 1184 | devicehandler *DeviceHandler |
| 1185 | wantErr bool |
| 1186 | }{ |
| 1187 | {"dostatedown-1", dh1, false}, |
| 1188 | {"dostatedown-2", dh2, true}, |
| 1189 | {"dostatedown-2", dh3, true}, |
| 1190 | } |
| 1191 | for _, tt := range tests { |
| 1192 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1193 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1194 | defer cancel() |
| 1195 | if err := tt.devicehandler.doStateDown(ctx); (err != nil) != tt.wantErr { |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1196 | t.Logf("DeviceHandler.doStateDown() error = %v", err) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1197 | //TODO: should fail this test case (Errorf) if result is not as expected |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1198 | } |
| 1199 | }) |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | func TestDeviceHandler_GetOfpDeviceInfo(t *testing.T) { |
| 1204 | dh1 := newMockDeviceHandler() |
| 1205 | dh2 := negativeDeviceHandler() |
| 1206 | type args struct { |
| 1207 | device *voltha.Device |
| 1208 | } |
| 1209 | tests := []struct { |
| 1210 | name string |
| 1211 | devicehandler *DeviceHandler |
| 1212 | args args |
| 1213 | wantErr bool |
| 1214 | }{ |
| 1215 | // TODO: Add test cases. |
| 1216 | {"GetOfpDeviceInfo-1", dh1, args{dh1.device}, false}, |
| 1217 | {"GetOfpDeviceInfo-2", dh1, args{&voltha.Device{}}, false}, |
| 1218 | {"GetOfpDeviceInfo-3", dh2, args{dh1.device}, false}, |
| 1219 | } |
| 1220 | for _, tt := range tests { |
| 1221 | t.Run(tt.name, func(t *testing.T) { |
| 1222 | dh := tt.devicehandler |
| 1223 | _, err := dh.GetOfpDeviceInfo(tt.args.device) |
| 1224 | if (err != nil) != tt.wantErr { |
| 1225 | t.Errorf("DeviceHandler.GetOfpDeviceInfo() error = %v, wantErr %v", err, tt.wantErr) |
| 1226 | return |
| 1227 | } |
| 1228 | }) |
| 1229 | } |
| 1230 | } |
| 1231 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1232 | func TestDeviceHandler_onuDiscIndication(t *testing.T) { |
| 1233 | |
| 1234 | dh1 := newMockDeviceHandler() |
Naga Manjunath | a8dc937 | 2019-10-31 23:01:18 +0530 | [diff] [blame] | 1235 | dh1.discOnus = sync.Map{} |
| 1236 | dh1.discOnus.Store("onu1", true) |
| 1237 | dh1.discOnus.Store("onu2", false) |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1238 | dh1.discOnus.Store("onu3", true) |
| 1239 | dh1.discOnus.Store("onu4", true) |
| 1240 | dh1.onus = sync.Map{} |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1241 | dh1.onus.Store("onu3", NewOnuDevice("onu3", "onu3", "onu3", 3, 3, "onu3", true, "mock_endpoint")) |
| 1242 | dh1.onus.Store("onu4", NewOnuDevice("onu4", "onu4", "onu4", 4, 4, "onu4", true, "mock_endpoint")) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1243 | dh2 := negativeDeviceHandler() |
| 1244 | type args struct { |
| 1245 | onuDiscInd *oop.OnuDiscIndication |
| 1246 | sn string |
| 1247 | } |
| 1248 | tests := []struct { |
| 1249 | name string |
| 1250 | devicehandler *DeviceHandler |
| 1251 | args args |
| 1252 | }{ |
| 1253 | // TODO: Add test cases. |
| 1254 | {"onuDiscIndication-1", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}, |
| 1255 | {"onuDiscIndication-2", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{}}}}, |
| 1256 | {"onuDiscIndication-3", dh1, args{onuDiscInd: &oop.OnuDiscIndication{SerialNumber: &oop.SerialNumber{}}}}, |
| 1257 | {"onuDiscIndication-4", dh1, args{onuDiscInd: &oop.OnuDiscIndication{}}}, |
| 1258 | {"onuDiscIndication-5", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu1"}}, |
| 1259 | {"onuDiscIndication-6", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu2"}}, |
Thiyagarajan Subramani | 34a0028 | 2020-03-10 20:19:31 +0530 | [diff] [blame] | 1260 | {"onuDiscIndication-7", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu3"}}, |
| 1261 | {"onuDiscIndication-8", dh1, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 3, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}, sn: "onu4"}}, |
| 1262 | {"onuDiscIndication-9", dh2, args{onuDiscInd: &oop.OnuDiscIndication{IntfId: 1, SerialNumber: &oop.SerialNumber{VendorId: []byte("TWSH"), VendorSpecific: []byte("1234")}}}}, |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1263 | } |
| 1264 | for _, tt := range tests { |
| 1265 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1266 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1267 | defer cancel() |
Mahir Gunyel | b004675 | 2021-02-26 13:51:05 -0800 | [diff] [blame] | 1268 | _ = tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1269 | //TODO: actually verify test cases |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1270 | }) |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | func TestDeviceHandler_populateDeviceInfo(t *testing.T) { |
| 1275 | dh1 := newMockDeviceHandler() |
| 1276 | dh2 := negativeDeviceHandler() |
| 1277 | tests := []struct { |
| 1278 | name string |
| 1279 | devicehandler *DeviceHandler |
| 1280 | |
| 1281 | wantErr bool |
| 1282 | }{ |
| 1283 | // TODO: Add test cases. |
| 1284 | {"populateDeviceInfo-1", dh1, false}, |
| 1285 | {"populateDeviceInfo-2", dh1, true}, |
| 1286 | {"populateDeviceInfo-3", dh1, true}, |
| 1287 | {"populateDeviceInfo-4", dh1, true}, |
| 1288 | {"populateDeviceInfo-5", dh2, true}, |
| 1289 | } |
| 1290 | for _, tt := range tests { |
| 1291 | t.Run(tt.name, func(t *testing.T) { |
| 1292 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1293 | _, err := tt.devicehandler.populateDeviceInfo(context.Background()) |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1294 | if (err != nil) != tt.wantErr { |
| 1295 | t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr) |
| 1296 | return |
| 1297 | } |
| 1298 | |
| 1299 | }) |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | func TestDeviceHandler_readIndications(t *testing.T) { |
| 1304 | dh1 := newMockDeviceHandler() |
| 1305 | dh2 := newMockDeviceHandler() |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1306 | dh3 := newMockDeviceHandler() |
| 1307 | dh3.device.AdminState = voltha.AdminState_DISABLED |
| 1308 | dh4 := negativeDeviceHandler() |
| 1309 | tests := []struct { |
| 1310 | name string |
| 1311 | devicehandler *DeviceHandler |
| 1312 | }{ |
| 1313 | // TODO: Add test cases. |
| 1314 | {"readIndications-1", dh1}, |
| 1315 | {"readIndications-2", dh2}, |
| 1316 | {"readIndications-3", dh2}, |
| 1317 | {"readIndications-4", dh2}, |
| 1318 | {"readIndications-5", dh2}, |
| 1319 | {"readIndications-6", dh3}, |
| 1320 | {"readIndications-7", dh3}, |
| 1321 | {"readIndications-8", dh4}, |
| 1322 | } |
| 1323 | for _, tt := range tests { |
| 1324 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1325 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1326 | defer cancel() |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1327 | _ = tt.devicehandler.readIndications(ctx) |
| 1328 | // TODO: actually verify test cases |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1329 | }) |
| 1330 | } |
| 1331 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1332 | |
| 1333 | func Test_startCollector(t *testing.T) { |
| 1334 | type args struct { |
| 1335 | dh *DeviceHandler |
| 1336 | } |
| 1337 | dh := newMockDeviceHandler() |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1338 | mcs := newMockCoreService() |
| 1339 | mcs.DevicePorts[dh.device.Id] = []*voltha.Port{ |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1340 | {PortNo: 1, Label: "pon", Type: voltha.Port_PON_OLT}, |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 1341 | {PortNo: 16777216, Label: "nni", Type: voltha.Port_ETHERNET_NNI}, |
| 1342 | {PortNo: 16777218, Label: "nni", Type: voltha.Port_ETHERNET_NNI}, |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1343 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1344 | dh.coreClient.SetService(mcs) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1345 | dh.portStats.NorthBoundPort = make(map[uint32]*NniPort) |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1346 | dh.portStats.NorthBoundPort[1] = &NniPort{Name: "OLT-1"} |
| 1347 | dh.portStats.NorthBoundPort[2] = &NniPort{Name: "OLT-1"} |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1348 | dh.portStats.SouthBoundPort = make(map[uint32]*PonPort) |
| 1349 | dh.portStats.Device = dh |
| 1350 | for i := 0; i < 16; i++ { |
| 1351 | dh.portStats.SouthBoundPort[uint32(i)] = &PonPort{DeviceID: "OLT-1"} |
| 1352 | } |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1353 | dh1 := newMockDeviceHandler() |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1354 | mcs = newMockCoreService() |
| 1355 | mcs.DevicePorts[dh.device.Id] = []*voltha.Port{} |
| 1356 | dh.coreClient.SetService(mcs) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1357 | tests := []struct { |
| 1358 | name string |
| 1359 | args args |
| 1360 | }{ |
| 1361 | // TODO: Add test cases. |
| 1362 | {"StartCollector-1", args{dh}}, |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1363 | {"StartCollector-2", args{dh1}}, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1364 | } |
| 1365 | for _, tt := range tests { |
| 1366 | t.Run(tt.name, func(t *testing.T) { |
| 1367 | go func() { |
Kishore Darapu | aaf9c10 | 2020-05-04 13:06:57 +0530 | [diff] [blame] | 1368 | time.Sleep(1 * time.Second) // simulated wait time to stop startCollector |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1369 | tt.args.dh.stopCollector <- true |
| 1370 | }() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1371 | startCollector(context.Background(), tt.args.dh) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 1372 | }) |
| 1373 | } |
| 1374 | } |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1375 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1376 | /* |
| 1377 | We are not using the adapterPreviouslyConnected and agentPreviouslyConnected flags now to check for reboots and reconnects |
| 1378 | |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1379 | commenting out all the tests related to these |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1380 | func TestDeviceHandler_TestReconcileStatus(t *testing.T) { |
| 1381 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1382 | // olt disconnect (not reboot) |
| 1383 | dh1 := newMockDeviceHandler() |
| 1384 | dh1.adapterPreviouslyConnected = false |
| 1385 | dh1.agentPreviouslyConnected = true |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1386 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1387 | // adapter restart |
| 1388 | dh2 := newMockDeviceHandler() |
| 1389 | dh2.Client = &mocks.MockOpenoltClient{} |
| 1390 | dh2.adapterPreviouslyConnected = true |
| 1391 | dh2.agentPreviouslyConnected = true |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1392 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1393 | // first connection or olt restart |
| 1394 | dh3 := newMockDeviceHandler() |
| 1395 | dh3.Client = &mocks.MockOpenoltClient{} |
| 1396 | dh3.adapterPreviouslyConnected = false |
| 1397 | dh3.agentPreviouslyConnected = false |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1398 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1399 | // olt and adapter restart at the same time (first case) |
| 1400 | dh4 := newMockDeviceHandler() |
| 1401 | dh4.Client = &mocks.MockOpenoltClient{} |
| 1402 | dh4.adapterPreviouslyConnected = true |
| 1403 | dh4.agentPreviouslyConnected = false |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1404 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1405 | // adapter restart and olt disconnect at the same time |
| 1406 | dh5 := newMockDeviceHandler() |
| 1407 | dh5.Client = &mocks.MockOpenoltClient{} |
| 1408 | dh5.adapterPreviouslyConnected = true |
| 1409 | dh5.agentPreviouslyConnected = true |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1410 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 1411 | tests := []struct { |
| 1412 | name string |
| 1413 | devicehandler *DeviceHandler |
| 1414 | expectedRestart bool |
| 1415 | wantErr bool |
| 1416 | }{ |
| 1417 | {"dostateup-1", dh1, true, false}, |
| 1418 | {"dostateup-2", dh2, false, false}, |
| 1419 | {"dostateup-3", dh3, false, false}, |
| 1420 | {"dostateup-4", dh4, true, false}, |
| 1421 | {"dostateup-5", dh5, false, false}, |
| 1422 | } |
| 1423 | for _, tt := range tests { |
| 1424 | t.Run(tt.name, func(t *testing.T) { |
| 1425 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1426 | defer cancel() |
| 1427 | if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr { |
| 1428 | t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr) |
| 1429 | } |
| 1430 | tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp |
| 1431 | isRestarted := tt.devicehandler.Client.(*mocks.MockOpenoltClient).IsRestarted |
| 1432 | if tt.expectedRestart != isRestarted { |
| 1433 | t.Errorf("olt-reboot-failed expected= %v, got= %v", tt.expectedRestart, isRestarted) |
| 1434 | } |
| 1435 | }) |
| 1436 | } |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 1437 | } |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 1438 | */ |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1439 | func Test_UpdateFlowsIncrementallyNegativeTestCases(t *testing.T) { |
| 1440 | dh1 := negativeDeviceHandlerNilFlowMgr() |
| 1441 | tests := []struct { |
| 1442 | name string |
| 1443 | devicehandler *DeviceHandler |
| 1444 | wantErr bool |
| 1445 | }{ |
| 1446 | {"update-flow-when-device-handler-is-nil", dh1, true}, |
| 1447 | } |
| 1448 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1449 | flowMetadata0 := of.FlowMetadata{Meters: []*of.OfpMeterConfig{ |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1450 | { |
| 1451 | Flags: 5, |
| 1452 | MeterId: 1, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1453 | Bands: []*of.OfpMeterBandHeader{ |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1454 | { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1455 | Type: of.OfpMeterBandType_OFPMBT_DROP, |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1456 | Rate: 16000, |
| 1457 | BurstSize: 0, |
| 1458 | }, |
| 1459 | { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1460 | Type: of.OfpMeterBandType_OFPMBT_DROP, |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1461 | Rate: 32000, |
| 1462 | BurstSize: 30, |
| 1463 | }, |
| 1464 | { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1465 | Type: of.OfpMeterBandType_OFPMBT_DROP, |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1466 | Rate: 64000, |
| 1467 | BurstSize: 30, |
| 1468 | }, |
| 1469 | }, |
| 1470 | }, |
| 1471 | }} |
| 1472 | |
| 1473 | kwTable0Meter1 := make(map[string]uint64) |
| 1474 | kwTable0Meter1["table_id"] = 0 |
| 1475 | kwTable0Meter1["meter_id"] = 1 |
| 1476 | kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 1477 | |
| 1478 | // Upstream flow DHCP flow - ONU1 UNI0 PON0 |
| 1479 | fa0 := &fu.FlowArgs{ |
| 1480 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1481 | fu.InPort(536870912), |
| 1482 | fu.Metadata_ofp(1), |
| 1483 | fu.IpProto(17), // dhcp |
| 1484 | fu.VlanPcp(0), |
| 1485 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
| 1486 | fu.TunnelId(256), |
| 1487 | }, |
| 1488 | Actions: []*ofp.OfpAction{ |
| 1489 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1490 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1491 | fu.Output(2147483645), |
| 1492 | fu.PushVlan(0x8100), |
| 1493 | }, |
| 1494 | KV: kwTable0Meter1, |
| 1495 | } |
| 1496 | |
| 1497 | flow0, _ := fu.MkFlowStat(fa0) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1498 | flowAdd := of.Flows{Items: make([]*of.OfpFlowStats, 0)} |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1499 | flowAdd.Items = append(flowAdd.Items, flow0) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1500 | flowRemove := of.Flows{Items: make([]*of.OfpFlowStats, 0)} |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 1501 | flowChanges := &ofp.FlowChanges{ToAdd: &flowAdd, ToRemove: &flowRemove} |
| 1502 | |
| 1503 | for _, tt := range tests { |
| 1504 | t.Run(tt.name, func(t *testing.T) { |
| 1505 | err := tt.devicehandler.UpdateFlowsIncrementally(context.Background(), tt.devicehandler.device, flowChanges, nil, &flowMetadata0) |
| 1506 | if (err != nil) != tt.wantErr { |
| 1507 | t.Errorf("DeviceHandler.populateDeviceInfo() error = %v, wantErr %v", err, tt.wantErr) |
| 1508 | return |
| 1509 | } |
| 1510 | }) |
| 1511 | } |
| 1512 | } |