vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/json" |
| 21 | "errors" |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 22 | "net" |
| 23 | "reflect" |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 24 | "sync" |
| 25 | "testing" |
| 26 | "voltha-go-controller/internal/pkg/controller" |
| 27 | cntlr "voltha-go-controller/internal/pkg/controller" |
| 28 | "voltha-go-controller/internal/pkg/of" |
| 29 | "voltha-go-controller/internal/pkg/util" |
| 30 | "voltha-go-controller/internal/test/mocks" |
| 31 | |
| 32 | "github.com/golang/mock/gomock" |
| 33 | "github.com/google/gopacket/layers" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 35 | "github.com/stretchr/testify/assert" |
| 36 | "go.uber.org/atomic" |
| 37 | ) |
| 38 | |
| 39 | var test_device = "test_device" |
| 40 | var voltPort = &VoltPort{ |
| 41 | Name: "test_name", |
| 42 | Device: test_device, |
| 43 | } |
| 44 | var voltDevice = &VoltDevice{ |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 45 | Name: "test_name", |
| 46 | State: controller.DeviceStateUP, |
| 47 | FlowAddEventMap: util.NewConcurrentMap(), |
| 48 | FlowDelEventMap: util.NewConcurrentMap(), |
| 49 | SerialNum: "test_serial_number", |
| 50 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 51 | NniPort: []string{"16777216"}, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | var voltMeter = &VoltMeter{ |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 55 | Name: "test_volt_meter", |
| 56 | Version: "test_version", |
| 57 | AssociatedServices: 3, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | var voltVnet = &VoltVnet{ |
| 61 | Version: "test_version", |
| 62 | VnetConfig: VnetConfig{ |
| 63 | Name: "test_name", |
| 64 | }, |
| 65 | } |
| 66 | |
| 67 | var voltPortVnet1 = []*VoltPortVnet{ |
| 68 | { |
| 69 | Device: "4096-4096-4096", |
| 70 | SVlan: of.VlanAny, |
| 71 | CVlan: of.VlanAny, |
| 72 | UniVlan: of.VlanAny, |
| 73 | IgmpEnabled: true, |
| 74 | servicesCount: &atomic.Uint64{}, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | var voltDevice1 = &VoltDevice{ |
| 79 | State: cntlr.DeviceStateDOWN, |
| 80 | } |
| 81 | |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 82 | var voltDevice2 = &VoltDevice{ |
| 83 | Name: "test_name", |
| 84 | State: controller.DeviceStateUP, |
| 85 | FlowAddEventMap: util.NewConcurrentMap(), |
| 86 | FlowDelEventMap: util.NewConcurrentMap(), |
| 87 | SerialNum: "test_serial_number", |
| 88 | MigratingServices: util.NewConcurrentMap(), |
| 89 | } |
| 90 | |
| 91 | var voltService2 = &VoltService{ |
| 92 | Version: "test_version", |
| 93 | VoltServiceCfg: VoltServiceCfg{ |
| 94 | VnetID: "test_vnet_id", |
| 95 | Port: "test_port", |
| 96 | SVlan: of.VlanAny, |
| 97 | CVlan: of.VlanAny, |
| 98 | UniVlan: of.VlanAny, |
| 99 | }, |
| 100 | } |
| 101 | |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 102 | var GetDeviceFromPort_error = "GetDeviceFromPort_error" |
| 103 | |
| 104 | func TestVoltApplication_RestoreSvcsFromDb(t *testing.T) { |
| 105 | type args struct { |
| 106 | cntx context.Context |
| 107 | } |
| 108 | tests := []struct { |
| 109 | name string |
| 110 | args args |
| 111 | }{ |
| 112 | { |
| 113 | name: "VoltApplication_RestoreSvcsFromDb", |
| 114 | args: args{ |
| 115 | cntx: context.Background(), |
| 116 | }, |
| 117 | }, |
| 118 | { |
| 119 | name: "invalid_value_type", |
| 120 | args: args{ |
| 121 | cntx: context.Background(), |
| 122 | }, |
| 123 | }, |
| 124 | { |
| 125 | name: "unmarshal_error", |
| 126 | args: args{ |
| 127 | cntx: context.Background(), |
| 128 | }, |
| 129 | }, |
| 130 | } |
| 131 | for _, tt := range tests { |
| 132 | t.Run(tt.name, func(t *testing.T) { |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 133 | voltService4 := &VoltService{ |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 134 | VoltServiceOper: VoltServiceOper{ |
| 135 | Device: "SDX6320031", |
| 136 | ForceDelete: true, |
| 137 | DeleteInProgress: true, |
| 138 | }, |
| 139 | VoltServiceCfg: VoltServiceCfg{ |
| 140 | Name: "test_service_name", |
| 141 | }, |
| 142 | } |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 143 | |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 144 | va := &VoltApplication{ |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 145 | ServicesToDelete: sync.Map{}, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 146 | } |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 147 | va.ServicesToDelete.Store(voltService4.VoltServiceCfg.Name, true) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 148 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 149 | db = dbintf |
| 150 | switch tt.name { |
| 151 | case "VoltApplication_RestoreSvcsFromDb": |
| 152 | |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 153 | b, err := json.Marshal(voltService4) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 154 | if err != nil { |
| 155 | panic(err) |
| 156 | } |
| 157 | kvPair := map[string]*kvstore.KVPair{} |
| 158 | kvPair["key"] = &kvstore.KVPair{ |
| 159 | Key: "test_key", |
| 160 | Value: b, |
| 161 | Version: 1, |
| 162 | } |
| 163 | dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1) |
| 164 | va.RestoreSvcsFromDb(tt.args.cntx) |
| 165 | case "invalid_value_type": |
| 166 | kvPair := map[string]*kvstore.KVPair{} |
| 167 | kvPair["key"] = &kvstore.KVPair{ |
| 168 | Key: "test_key", |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 169 | Value: invalid_value, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 170 | Version: 1, |
| 171 | } |
| 172 | dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1) |
| 173 | va.RestoreSvcsFromDb(tt.args.cntx) |
| 174 | case "unmarshal_error": |
| 175 | b, err := json.Marshal("test") |
| 176 | if err != nil { |
| 177 | panic(err) |
| 178 | } |
| 179 | kvPair := map[string]*kvstore.KVPair{} |
| 180 | kvPair["key"] = &kvstore.KVPair{ |
| 181 | Key: "test_key", |
| 182 | Value: b, |
| 183 | Version: 1, |
| 184 | } |
| 185 | dbintf.EXPECT().GetServices(tt.args.cntx).Return(kvPair, nil).Times(1) |
| 186 | va.RestoreSvcsFromDb(tt.args.cntx) |
| 187 | } |
| 188 | }) |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | func TestVoltService_FlowRemoveFailure(t *testing.T) { |
| 193 | type args struct { |
| 194 | cntx context.Context |
| 195 | cookie string |
| 196 | errorCode uint32 |
| 197 | errReason string |
| 198 | } |
| 199 | tests := []struct { |
| 200 | name string |
| 201 | args args |
| 202 | }{ |
| 203 | { |
| 204 | name: "VoltService_FlowRemoveFailure", |
| 205 | args: args{ |
| 206 | cntx: context.Background(), |
| 207 | cookie: "test_cookie", |
| 208 | errorCode: 200, |
| 209 | errReason: "test_reason", |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | name: "cookie_not_found", |
| 214 | args: args{ |
| 215 | cntx: context.Background(), |
| 216 | cookie: "test_cookie", |
| 217 | errorCode: 200, |
| 218 | errReason: "test_reason", |
| 219 | }, |
| 220 | }, |
| 221 | } |
| 222 | for _, tt := range tests { |
| 223 | t.Run(tt.name, func(t *testing.T) { |
| 224 | switch tt.name { |
| 225 | case "VoltService_FlowRemoveFailure": |
| 226 | associatedFlows := map[string]bool{} |
| 227 | associatedFlows["test_cookie"] = true |
| 228 | vs := &VoltService{ |
| 229 | VoltServiceOper: VoltServiceOper{ |
| 230 | AssociatedFlows: associatedFlows, |
| 231 | }, |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 232 | VoltServiceCfg: VoltServiceCfg{}, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 233 | } |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 234 | vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 235 | case "cookie_not_found": |
| 236 | associatedFlows := map[string]bool{} |
| 237 | associatedFlows["cookie"] = true |
| 238 | vs := &VoltService{ |
| 239 | VoltServiceOper: VoltServiceOper{ |
| 240 | AssociatedFlows: associatedFlows, |
| 241 | }, |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 242 | VoltServiceCfg: VoltServiceCfg{}, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 243 | } |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 244 | vs.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 245 | } |
| 246 | }) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | func TestVoltApplication_GetServiceNameFromCookie(t *testing.T) { |
| 251 | type args struct { |
| 252 | cookie uint64 |
| 253 | portName string |
| 254 | pbit uint8 |
| 255 | device string |
| 256 | tableMetadata uint64 |
| 257 | } |
| 258 | tests := []struct { |
| 259 | name string |
| 260 | args args |
| 261 | }{ |
| 262 | { |
| 263 | name: "VoltApplication_GetServiceNameFromCookie", |
| 264 | args: args{ |
| 265 | cookie: uint64(1), |
| 266 | portName: "test_port_name", |
| 267 | device: "SDX6320031", |
| 268 | pbit: 2, |
| 269 | tableMetadata: uint64(2), |
| 270 | }, |
| 271 | }, |
| 272 | } |
| 273 | voltDev := &VoltDevice{ |
| 274 | Name: "SDX6320031", |
| 275 | SerialNum: "SDX6320031", |
| 276 | NniDhcpTrapVid: 123, |
| 277 | } |
| 278 | for _, tt := range tests { |
| 279 | t.Run(tt.name, func(t *testing.T) { |
| 280 | ga := GetApplication() |
| 281 | ga.DevicesDisc.Store("SDX6320031", voltDev) |
| 282 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 283 | voltPortVnet := &VoltPortVnet{ |
| 284 | Device: test_device, |
| 285 | VlanControl: ONUCVlanOLTSVlan, |
| 286 | } |
| 287 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 288 | ga.VnetsByPort.Store("test_port_name", voltPortVnets) |
| 289 | got := ga.GetServiceNameFromCookie(tt.args.cookie, tt.args.portName, tt.args.pbit, tt.args.device, tt.args.tableMetadata) |
| 290 | assert.Nil(t, got) |
| 291 | }) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestVoltService_SvcUpInd(t *testing.T) { |
| 296 | type args struct { |
| 297 | cntx context.Context |
| 298 | } |
| 299 | tests := []struct { |
| 300 | name string |
| 301 | args args |
| 302 | }{ |
| 303 | { |
| 304 | name: "VoltService_SvcUpInd", |
| 305 | args: args{ |
| 306 | cntx: context.Background(), |
| 307 | }, |
| 308 | }, |
| 309 | } |
| 310 | for _, tt := range tests { |
| 311 | t.Run(tt.name, func(t *testing.T) { |
| 312 | vs := &VoltService{ |
| 313 | VoltServiceOper: VoltServiceOper{ |
| 314 | PendingFlows: make(map[string]bool), |
| 315 | }, |
| 316 | VoltServiceCfg: VoltServiceCfg{ |
| 317 | SVlanTpid: layers.EthernetTypeDot1Q, |
| 318 | MacAddr: layers.EthernetBroadcast, |
| 319 | }, |
| 320 | } |
| 321 | vs.Port = test_device |
| 322 | vs.Device = "device" |
| 323 | ga := GetApplication() |
| 324 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 325 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 326 | db = dbintf |
| 327 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 328 | ga.PortsDisc.Store(test_device, voltPort) |
| 329 | ga.DevicesDisc.Store(test_device, voltDevice) |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 330 | ga.DevicesConfig.Store("test_serial_number", &DeviceConfig{UplinkPort: "16777216"}) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 331 | vs.SvcUpInd(tt.args.cntx) |
| 332 | }) |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | func TestVoltService_SvcDownInd(t *testing.T) { |
| 337 | type args struct { |
| 338 | cntx context.Context |
| 339 | } |
| 340 | tests := []struct { |
| 341 | name string |
| 342 | args args |
| 343 | }{ |
| 344 | { |
| 345 | name: "VoltService_SvcDownInd", |
| 346 | args: args{ |
| 347 | cntx: context.Background(), |
| 348 | }, |
| 349 | }, |
| 350 | } |
| 351 | for _, tt := range tests { |
| 352 | t.Run(tt.name, func(t *testing.T) { |
| 353 | vs := &VoltService{ |
| 354 | VoltServiceOper: VoltServiceOper{ |
| 355 | UsHSIAFlowsApplied: true, |
| 356 | DsHSIAFlowsApplied: true, |
| 357 | }, |
| 358 | VoltServiceCfg: VoltServiceCfg{ |
| 359 | SVlanTpid: layers.EthernetTypeQinQ, |
| 360 | MacAddr: layers.EthernetBroadcast, |
| 361 | }, |
| 362 | } |
| 363 | vs.Port = test_device |
| 364 | vs.Device = "device" |
| 365 | ga := GetApplication() |
| 366 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 367 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 368 | db = dbintf |
| 369 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 370 | ga.PortsDisc.Store(test_device, voltPort) |
| 371 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 372 | vs.SvcDownInd(tt.args.cntx) |
| 373 | }) |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | func TestVoltApplication_AddService(t *testing.T) { |
| 378 | type args struct { |
| 379 | cntx context.Context |
| 380 | cfg VoltServiceCfg |
| 381 | oper *VoltServiceOper |
| 382 | } |
| 383 | tests := []struct { |
| 384 | name string |
| 385 | args args |
| 386 | }{ |
| 387 | { |
| 388 | name: "VoltApplication_AddService", |
| 389 | args: args{ |
| 390 | cntx: context.Background(), |
| 391 | cfg: VoltServiceCfg{ |
| 392 | Name: "test_name", |
| 393 | Port: "test_port", |
| 394 | DsMeterProfile: "4096-4096-4096", |
| 395 | UsMeterProfile: "4096-4096-4096", |
| 396 | SVlan: of.VlanAny, |
| 397 | CVlan: of.VlanAny, |
| 398 | UniVlan: of.VlanAny, |
| 399 | MacLearning: Learn, |
| 400 | IsActivated: true, |
| 401 | }, |
| 402 | oper: &VoltServiceOper{ |
| 403 | Device: "4096-4096-4096", |
| 404 | }, |
| 405 | }, |
| 406 | }, |
| 407 | } |
| 408 | for _, tt := range tests { |
| 409 | t.Run(tt.name, func(t *testing.T) { |
| 410 | va := &VoltApplication{ |
| 411 | MeterMgr: MeterMgr{ |
| 412 | Meters: sync.Map{}, |
| 413 | }, |
| 414 | VnetsByPort: sync.Map{}, |
| 415 | VnetsByTag: sync.Map{}, |
| 416 | } |
| 417 | va.MeterMgr.Meters.Store("4096-4096-4096", voltMeter) |
| 418 | va.VnetsByTag.Store("4096-4096-4096", voltVnet) |
| 419 | voltPortVnet1[0].SVlan = of.VlanAny |
| 420 | voltPortVnet1[0].CVlan = of.VlanAny |
| 421 | voltPortVnet1[0].UniVlan = of.VlanAny |
| 422 | voltPortVnet1[0].servicesCount = atomic.NewUint64(uint64(56)) |
| 423 | voltPortVnet1[0].MacAddr = layers.EthernetBroadcast |
| 424 | voltPortVnet1[0].Port = "test_port" |
| 425 | va.VnetsByPort.Store("test_port", voltPortVnet1) |
| 426 | ga := GetApplication() |
| 427 | voltPort1 := &VoltPort{ |
| 428 | Name: "test_name", |
| 429 | Device: test_device, |
| 430 | } |
| 431 | deviceConfig := &DeviceConfig{ |
| 432 | SerialNumber: "test_serial_number", |
| 433 | } |
| 434 | ga.PortsDisc.Store("test_port", voltPort1) |
| 435 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 436 | ga.DevicesConfig.Store("test_serial_number", deviceConfig) |
| 437 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 438 | db = dbintf |
| 439 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 440 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 441 | err := va.AddService(tt.args.cntx, tt.args.cfg, tt.args.oper) |
| 442 | assert.Nil(t, err) |
| 443 | }) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | func TestVoltApplication_DelService(t *testing.T) { |
| 448 | type args struct { |
| 449 | cntx context.Context |
| 450 | name string |
| 451 | forceDelete bool |
| 452 | newSvc *VoltServiceCfg |
| 453 | serviceMigration bool |
| 454 | } |
| 455 | tests := []struct { |
| 456 | name string |
| 457 | args args |
| 458 | }{ |
| 459 | { |
| 460 | name: "VoltApplication_DelService", |
| 461 | args: args{ |
| 462 | cntx: context.Background(), |
| 463 | name: "test_name", |
| 464 | forceDelete: true, |
| 465 | newSvc: &VoltServiceCfg{ |
| 466 | Name: "vs_cfg_name", |
| 467 | Port: "test_port", |
| 468 | }, |
| 469 | serviceMigration: true, |
| 470 | }, |
| 471 | }, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 472 | { |
| 473 | name: "GetMeterByID_not_nil", |
| 474 | args: args{ |
| 475 | cntx: context.Background(), |
| 476 | name: "test_name", |
| 477 | forceDelete: true, |
| 478 | newSvc: &VoltServiceCfg{ |
| 479 | Name: "vs_cfg_name", |
| 480 | Port: "test_port", |
| 481 | }, |
| 482 | serviceMigration: true, |
| 483 | }, |
| 484 | }, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 485 | } |
| 486 | for _, tt := range tests { |
| 487 | t.Run(tt.name, func(t *testing.T) { |
| 488 | va := &VoltApplication{ |
| 489 | ServiceByName: sync.Map{}, |
| 490 | VnetsByPort: sync.Map{}, |
| 491 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 492 | voltService3 := &VoltService{ |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 493 | Version: "test_version", |
| 494 | VoltServiceCfg: VoltServiceCfg{ |
| 495 | Port: "4096-4096-4096", |
| 496 | SVlan: of.VlanAny, |
| 497 | CVlan: of.VlanAny, |
| 498 | UniVlan: of.VlanAny, |
| 499 | }, |
| 500 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 501 | switch tt.name { |
| 502 | case "VoltApplication_DelService": |
| 503 | va.ServiceByName.Store(tt.args.name, voltService3) |
| 504 | va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1) |
| 505 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 506 | db = dbintf |
| 507 | dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes() |
| 508 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 509 | va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration) |
| 510 | case "GetMeterByID_not_nil": |
| 511 | va.ServiceByName.Store(tt.args.name, voltService3) |
| 512 | va.VnetsByPort.Store("4096-4096-4096", voltPortVnet1) |
| 513 | voltService3.AggDsMeterID = uint32(1) |
| 514 | voltService3.DsMeterID = uint32(1) |
| 515 | voltService3.UsMeterID = uint32(2) |
| 516 | va.MeterMgr.MetersByID.Store(voltService3.AggDsMeterID, voltMeter) |
| 517 | va.MeterMgr.MetersByID.Store(voltService3.DsMeterID, voltMeter) |
| 518 | va.MeterMgr.MetersByID.Store(voltService3.UsMeterID, voltMeter) |
| 519 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 520 | db = dbintf |
| 521 | dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes() |
| 522 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 523 | va.DelService(tt.args.cntx, tt.args.name, tt.args.forceDelete, tt.args.newSvc, tt.args.serviceMigration) |
| 524 | } |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 525 | }) |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | func TestVoltService_FlowInstallSuccess(t *testing.T) { |
| 530 | type args struct { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 531 | cntx context.Context |
| 532 | cookie string |
| 533 | bwAvailInfo of.BwAvailDetails |
| 534 | flowEventMap *util.ConcurrentMap |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 535 | } |
| 536 | tests := []struct { |
| 537 | name string |
| 538 | args args |
| 539 | }{ |
| 540 | { |
| 541 | name: "VoltService_FlowInstallSuccess", |
| 542 | args: args{ |
| 543 | cntx: context.Background(), |
| 544 | cookie: "test_cookie", |
| 545 | bwAvailInfo: of.BwAvailDetails{ |
| 546 | PrevBw: "test_prev_BW", |
| 547 | PresentBw: "test_present_BW", |
| 548 | }, |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 549 | flowEventMap: util.NewConcurrentMap(), |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 550 | }, |
| 551 | }, |
| 552 | } |
| 553 | for _, tt := range tests { |
| 554 | t.Run(tt.name, func(t *testing.T) { |
| 555 | pendingFlows := map[string]bool{} |
| 556 | pendingFlows["test_cookie"] = true |
| 557 | associatedFlows := map[string]bool{} |
| 558 | associatedFlows["test_cookie"] = true |
| 559 | vs := &VoltService{ |
| 560 | VoltServiceOper: VoltServiceOper{ |
| 561 | PendingFlows: pendingFlows, |
| 562 | AssociatedFlows: associatedFlows, |
| 563 | DsHSIAFlowsApplied: true, |
| 564 | }, |
| 565 | VoltServiceCfg: VoltServiceCfg{ |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 566 | Port: "test_port", |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 567 | }, |
| 568 | } |
| 569 | ga := GetApplication() |
| 570 | ga.PortsDisc.Store("test_port", voltPort) |
| 571 | ga.DevicesDisc.Store(test_device, voltDevice) |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 572 | vs.FlowInstallSuccess(tt.args.cntx, tt.args.cookie, tt.args.bwAvailInfo) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 573 | }) |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | func TestVoltService_AddMeterToDevice(t *testing.T) { |
| 578 | type args struct { |
| 579 | cntx context.Context |
| 580 | } |
| 581 | tests := []struct { |
| 582 | name string |
| 583 | args args |
| 584 | wantErr bool |
| 585 | }{ |
| 586 | { |
| 587 | name: "VoltService_AddMeterToDevice", |
| 588 | args: args{ |
| 589 | cntx: context.Background(), |
| 590 | }, |
| 591 | }, |
| 592 | { |
| 593 | name: GetDeviceFromPort_error, |
| 594 | args: args{ |
| 595 | cntx: context.Background(), |
| 596 | }, |
| 597 | }, |
| 598 | { |
| 599 | name: "DeviceState_down", |
| 600 | args: args{ |
| 601 | cntx: context.Background(), |
| 602 | }, |
| 603 | }, |
| 604 | } |
| 605 | for _, tt := range tests { |
| 606 | t.Run(tt.name, func(t *testing.T) { |
| 607 | switch tt.name { |
| 608 | case "VoltService_AddMeterToDevice": |
| 609 | vs := &VoltService{ |
| 610 | VoltServiceOper: VoltServiceOper{ |
| 611 | DeleteInProgress: true, |
| 612 | }, |
| 613 | VoltServiceCfg: VoltServiceCfg{ |
| 614 | Port: "test_port", |
| 615 | }, |
| 616 | } |
| 617 | ga := GetApplication() |
| 618 | ga.PortsDisc.Store("test_port", voltPort) |
| 619 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 620 | err := vs.AddMeterToDevice(tt.args.cntx) |
| 621 | assert.Nil(t, err) |
| 622 | case GetDeviceFromPort_error: |
| 623 | vs := &VoltService{ |
| 624 | VoltServiceOper: VoltServiceOper{ |
| 625 | DeleteInProgress: true, |
| 626 | }, |
| 627 | VoltServiceCfg: VoltServiceCfg{ |
| 628 | Port: "", |
| 629 | }, |
| 630 | } |
| 631 | err := vs.AddMeterToDevice(tt.args.cntx) |
| 632 | assert.NotNil(t, err) |
| 633 | case "DeviceState_down": |
| 634 | vs := &VoltService{ |
| 635 | VoltServiceOper: VoltServiceOper{ |
| 636 | DeleteInProgress: true, |
| 637 | }, |
| 638 | VoltServiceCfg: VoltServiceCfg{ |
| 639 | Port: "test_port", |
| 640 | }, |
| 641 | } |
| 642 | ga := GetApplication() |
| 643 | ga.PortsDisc.Store("test_port", voltPort) |
| 644 | ga.DevicesDisc.Store(test_device, voltDevice1) |
| 645 | err := vs.AddMeterToDevice(tt.args.cntx) |
| 646 | assert.Nil(t, err) |
| 647 | } |
| 648 | }) |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | func TestVoltService_AddUsHsiaFlows(t *testing.T) { |
| 653 | type args struct { |
| 654 | cntx context.Context |
| 655 | } |
| 656 | tests := []struct { |
| 657 | name string |
| 658 | args args |
| 659 | wantErr bool |
| 660 | }{ |
| 661 | { |
| 662 | name: "DeleteInProgress_true", |
| 663 | args: args{ |
| 664 | cntx: context.Background(), |
| 665 | }, |
| 666 | }, |
| 667 | { |
| 668 | name: "GetDeviceFromPort_error", |
| 669 | args: args{ |
| 670 | cntx: context.Background(), |
| 671 | }, |
| 672 | }, |
| 673 | { |
| 674 | name: "DeviceState_down", |
| 675 | args: args{ |
| 676 | cntx: context.Background(), |
| 677 | }, |
| 678 | }, |
| 679 | } |
| 680 | for _, tt := range tests { |
| 681 | t.Run(tt.name, func(t *testing.T) { |
| 682 | switch tt.name { |
| 683 | case "DeleteInProgress_true": |
| 684 | vs := &VoltService{ |
| 685 | VoltServiceOper: VoltServiceOper{ |
| 686 | DeleteInProgress: true, |
| 687 | }, |
| 688 | } |
| 689 | err := vs.AddUsHsiaFlows(tt.args.cntx) |
| 690 | assert.Nil(t, err) |
| 691 | case "GetDeviceFromPort_error": |
| 692 | vs := &VoltService{ |
| 693 | VoltServiceOper: VoltServiceOper{ |
| 694 | DeleteInProgress: false, |
| 695 | }, |
| 696 | } |
| 697 | err := vs.AddUsHsiaFlows(tt.args.cntx) |
| 698 | assert.NotNil(t, err) |
| 699 | case "DeviceState_down": |
| 700 | vs := &VoltService{ |
| 701 | VoltServiceOper: VoltServiceOper{ |
| 702 | DeleteInProgress: false, |
| 703 | }, |
| 704 | VoltServiceCfg: VoltServiceCfg{ |
| 705 | Port: "test_port", |
| 706 | }, |
| 707 | } |
| 708 | ga := GetApplication() |
| 709 | ga.PortsDisc.Store("test_port", voltPort) |
| 710 | ga.DevicesDisc.Store(test_device, voltDevice1) |
| 711 | err := vs.AddUsHsiaFlows(tt.args.cntx) |
| 712 | assert.Nil(t, err) |
| 713 | } |
| 714 | }) |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | func TestVoltService_AddHsiaFlows(t *testing.T) { |
| 719 | type args struct { |
| 720 | cntx context.Context |
| 721 | } |
| 722 | tests := []struct { |
| 723 | name string |
| 724 | args args |
| 725 | }{ |
| 726 | { |
| 727 | name: "AddUsHsiaFlows_error", |
| 728 | args: args{ |
| 729 | cntx: context.Background(), |
| 730 | }, |
| 731 | }, |
| 732 | } |
| 733 | for _, tt := range tests { |
| 734 | t.Run(tt.name, func(t *testing.T) { |
| 735 | vs := &VoltService{ |
| 736 | VoltServiceCfg: VoltServiceCfg{ |
| 737 | Port: "test_port", |
| 738 | VlanControl: 5, |
| 739 | }, |
| 740 | } |
| 741 | ga := GetApplication() |
| 742 | ga.PortsDisc.Store("test_port", voltPort) |
| 743 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 744 | vs.AddHsiaFlows(tt.args.cntx) |
| 745 | }) |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | func TestVoltService_ForceWriteToDb(t *testing.T) { |
| 750 | type args struct { |
| 751 | cntx context.Context |
| 752 | } |
| 753 | tests := []struct { |
| 754 | name string |
| 755 | args args |
| 756 | }{ |
| 757 | { |
| 758 | name: "PutService_error", |
| 759 | args: args{ |
| 760 | cntx: context.Background(), |
| 761 | }, |
| 762 | }, |
| 763 | } |
| 764 | for _, tt := range tests { |
| 765 | t.Run(tt.name, func(t *testing.T) { |
| 766 | switch tt.name { |
| 767 | case "PutService_error": |
| 768 | vs := &VoltService{} |
| 769 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 770 | db = dbintf |
| 771 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).AnyTimes() |
| 772 | vs.ForceWriteToDb(tt.args.cntx) |
| 773 | } |
| 774 | }) |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | func TestVoltService_isDataRateAttrPresent(t *testing.T) { |
| 779 | tests := []struct { |
| 780 | name string |
| 781 | want bool |
| 782 | }{ |
| 783 | { |
| 784 | name: "VoltService_isDataRateAttrPresent", |
| 785 | }, |
| 786 | } |
| 787 | for _, tt := range tests { |
| 788 | t.Run(tt.name, func(t *testing.T) { |
| 789 | vs := &VoltService{} |
| 790 | if got := vs.isDataRateAttrPresent(); got != tt.want { |
| 791 | t.Errorf("VoltService.isDataRateAttrPresent() = %v, want %v", got, tt.want) |
| 792 | } |
| 793 | }) |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | func TestVoltService_GetServicePbit(t *testing.T) { |
| 798 | tests := []struct { |
| 799 | name string |
| 800 | want int |
| 801 | }{ |
| 802 | { |
| 803 | name: "VoltService_GetServicePbit", |
| 804 | want: -1, |
| 805 | }, |
| 806 | { |
| 807 | name: "!IsPbitExist", |
| 808 | want: 8, |
| 809 | }, |
| 810 | } |
| 811 | for _, tt := range tests { |
| 812 | t.Run(tt.name, func(t *testing.T) { |
| 813 | switch tt.name { |
| 814 | case "VoltService_GetServicePbit": |
| 815 | vs := &VoltService{ |
| 816 | VoltServiceCfg: VoltServiceCfg{ |
| 817 | Pbits: []of.PbitType{of.PbitMatchAll}, |
| 818 | }, |
| 819 | } |
| 820 | if got := vs.GetServicePbit(); got != tt.want { |
| 821 | t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want) |
| 822 | } |
| 823 | case "!IsPbitExist": |
| 824 | vs := &VoltService{} |
| 825 | if got := vs.GetServicePbit(); got != tt.want { |
| 826 | t.Errorf("VoltService.GetServicePbit() = %v, want %v", got, tt.want) |
| 827 | } |
| 828 | } |
| 829 | }) |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | func TestVoltApplication_DeactivateService(t *testing.T) { |
| 834 | type args struct { |
| 835 | cntx context.Context |
| 836 | deviceID string |
| 837 | portNo string |
| 838 | sVlan of.VlanType |
| 839 | cVlan of.VlanType |
| 840 | tpID uint16 |
| 841 | } |
| 842 | tests := []struct { |
| 843 | name string |
| 844 | args args |
| 845 | wantErr bool |
| 846 | }{ |
| 847 | { |
| 848 | name: "VoltApplication_DeactivateService", |
| 849 | args: args{ |
| 850 | cntx: context.Background(), |
| 851 | deviceID: "test_device_id", |
| 852 | portNo: "test_port", |
| 853 | sVlan: of.VlanNone, |
| 854 | cVlan: of.VlanAny, |
| 855 | tpID: AnyVlan, |
| 856 | }, |
| 857 | }, |
| 858 | { |
| 859 | name: "VoltPortVnet_nil", |
| 860 | args: args{ |
| 861 | cntx: context.Background(), |
| 862 | deviceID: "test_device_id", |
| 863 | portNo: "test_port", |
| 864 | sVlan: of.VlanNone, |
| 865 | cVlan: of.VlanAny, |
| 866 | tpID: AnyVlan, |
| 867 | }, |
| 868 | }, |
| 869 | { |
| 870 | name: "sVlan != of.VlanNone", |
| 871 | args: args{ |
| 872 | cntx: context.Background(), |
| 873 | deviceID: "test_device_id", |
| 874 | portNo: "test_port", |
| 875 | sVlan: of.VlanAny, |
| 876 | cVlan: of.VlanAny, |
| 877 | tpID: AnyVlan, |
| 878 | }, |
| 879 | }, |
| 880 | { |
| 881 | name: GetDeviceFromPort_error, |
| 882 | args: args{ |
| 883 | cntx: context.Background(), |
| 884 | deviceID: "test_device_id", |
| 885 | portNo: "test_port", |
| 886 | sVlan: of.VlanNone, |
| 887 | cVlan: of.VlanAny, |
| 888 | tpID: AnyVlan, |
| 889 | }, |
| 890 | }, |
| 891 | } |
| 892 | for _, tt := range tests { |
| 893 | t.Run(tt.name, func(t *testing.T) { |
| 894 | va := &VoltApplication{ |
| 895 | ServiceByName: sync.Map{}, |
| 896 | VnetsByPort: sync.Map{}, |
| 897 | DevicesDisc: sync.Map{}, |
| 898 | PortsDisc: sync.Map{}, |
| 899 | } |
| 900 | voltServiceTest := &VoltService{ |
| 901 | VoltServiceOper: VoltServiceOper{ |
| 902 | Device: test_device, |
| 903 | }, |
| 904 | Version: "test_version", |
| 905 | VoltServiceCfg: VoltServiceCfg{ |
| 906 | Port: "test_port", |
| 907 | Name: "test_name", |
| 908 | IsActivated: true, |
| 909 | CVlan: of.VlanAny, |
| 910 | SVlan: of.VlanAny, |
| 911 | UniVlan: of.VlanAny, |
| 912 | }, |
| 913 | } |
| 914 | switch tt.name { |
| 915 | case "VoltApplication_DeactivateService": |
| 916 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 917 | va.PortsDisc.Store("test_port", voltPort) |
| 918 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 919 | db = dbintf |
| 920 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 921 | va.DevicesDisc.Store(test_device, voltDevice) |
| 922 | voltDevice.Ports.Store("test_port", voltPort) |
| 923 | va.VnetsByPort.Store("test_port", voltPortVnet1) |
| 924 | voltPortVnet1[0].servicesCount.Store(uint64(1)) |
| 925 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 926 | if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr { |
| 927 | t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr) |
| 928 | } |
| 929 | case "VoltPortVnet_nil": |
| 930 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 931 | va.PortsDisc.Store("test_port", voltPort) |
| 932 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 933 | db = dbintf |
| 934 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 935 | va.DevicesDisc.Store(test_device, voltDevice) |
| 936 | voltDevice.Ports.Store("test_port", voltPort) |
| 937 | if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr { |
| 938 | t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr) |
| 939 | } |
| 940 | case "sVlan != of.VlanNone": |
| 941 | va.ServiceByName.Store("test_name", voltServiceTest) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 942 | err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID) |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 943 | assert.Nil(t, err) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 944 | case GetDeviceFromPort_error: |
| 945 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 946 | if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr { |
| 947 | t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr) |
| 948 | } |
| 949 | } |
| 950 | }) |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | func TestVoltApplication_ActivateService(t *testing.T) { |
| 955 | type args struct { |
| 956 | cntx context.Context |
| 957 | deviceID string |
| 958 | portNo string |
| 959 | sVlan of.VlanType |
| 960 | cVlan of.VlanType |
| 961 | tpID uint16 |
| 962 | } |
| 963 | tests := []struct { |
| 964 | name string |
| 965 | args args |
| 966 | wantErr bool |
| 967 | }{ |
| 968 | { |
| 969 | name: "VoltApplication_ActivateService", |
| 970 | args: args{ |
| 971 | cntx: context.Background(), |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 972 | deviceID: DeviceAny, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 973 | portNo: "test_port", |
| 974 | sVlan: of.VlanNone, |
| 975 | cVlan: of.VlanAny, |
| 976 | tpID: AnyVlan, |
| 977 | }, |
| 978 | }, |
| 979 | { |
| 980 | name: "VoltPortVnet_nil", |
| 981 | args: args{ |
| 982 | cntx: context.Background(), |
| 983 | deviceID: "test_name", |
| 984 | portNo: "test_port", |
| 985 | sVlan: of.VlanNone, |
| 986 | cVlan: of.VlanAny, |
| 987 | tpID: AnyVlan, |
| 988 | }, |
| 989 | }, |
| 990 | { |
| 991 | name: GetDeviceFromPort_error, |
| 992 | args: args{ |
| 993 | cntx: context.Background(), |
| 994 | deviceID: "test_name", |
| 995 | portNo: "test_port", |
| 996 | sVlan: of.VlanNone, |
| 997 | cVlan: of.VlanAny, |
| 998 | tpID: AnyVlan, |
| 999 | }, |
| 1000 | }, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1001 | { |
| 1002 | name: "deviceID != device.Name", |
| 1003 | args: args{ |
| 1004 | cntx: context.Background(), |
| 1005 | deviceID: "test_name1", |
| 1006 | portNo: "test_port", |
| 1007 | sVlan: of.VlanNone, |
| 1008 | cVlan: of.VlanAny, |
| 1009 | tpID: AnyVlan, |
| 1010 | }, |
| 1011 | }, |
| 1012 | { |
| 1013 | name: "sVlan != of.VlanNone && sVlan != vs.SVlan", |
| 1014 | args: args{ |
| 1015 | cntx: context.Background(), |
| 1016 | deviceID: "test_name", |
| 1017 | portNo: "test_port", |
| 1018 | sVlan: 1, |
| 1019 | cVlan: of.VlanAny, |
| 1020 | tpID: AnyVlan, |
| 1021 | }, |
| 1022 | }, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1023 | } |
| 1024 | for _, tt := range tests { |
| 1025 | t.Run(tt.name, func(t *testing.T) { |
| 1026 | va := &VoltApplication{ |
| 1027 | DevicesDisc: sync.Map{}, |
| 1028 | } |
| 1029 | var voltPortTest = &VoltPort{ |
| 1030 | Name: "test_name", |
| 1031 | State: PortStateUp, |
| 1032 | } |
| 1033 | voltServiceTest := &VoltService{ |
| 1034 | VoltServiceOper: VoltServiceOper{ |
| 1035 | Device: test_device, |
| 1036 | }, |
| 1037 | Version: "test_version", |
| 1038 | VoltServiceCfg: VoltServiceCfg{ |
| 1039 | Port: "test_port", |
| 1040 | Name: "test_name", |
| 1041 | IsActivated: false, |
| 1042 | CVlan: of.VlanAny, |
| 1043 | SVlan: of.VlanAny, |
| 1044 | UniVlan: of.VlanAny, |
| 1045 | }, |
| 1046 | } |
| 1047 | switch tt.name { |
| 1048 | case "VoltApplication_ActivateService": |
| 1049 | voltPortTest.Device = test_device |
| 1050 | va.PortsDisc.Store("test_port", voltPortTest) |
| 1051 | va.DevicesDisc.Store(test_device, voltDevice) |
| 1052 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 1053 | va.VnetsByPort.Store("test_port", voltPortVnet1) |
| 1054 | voltDevice.Ports.Store("test_port", voltPortTest) |
| 1055 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1056 | db = dbintf |
| 1057 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1058 | if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr { |
| 1059 | t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr) |
| 1060 | } |
| 1061 | case "VoltPortVnet_nil": |
| 1062 | voltPortTest.Device = test_device |
| 1063 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 1064 | va.PortsDisc.Store("test_port", voltPortTest) |
| 1065 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1066 | db = dbintf |
| 1067 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1068 | va.DevicesDisc.Store(test_device, voltDevice) |
| 1069 | voltDevice.Ports.Store("test_port", voltPortTest) |
| 1070 | if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr { |
| 1071 | t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr) |
| 1072 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1073 | case "deviceID != device.Name": |
| 1074 | var voltPortTest1 = &VoltPort{ |
| 1075 | Name: "test_name", |
| 1076 | State: PortStateUp, |
| 1077 | Device: test_device, |
| 1078 | } |
| 1079 | var voltDevice_test = &VoltDevice{ |
| 1080 | Name: "", |
| 1081 | State: controller.DeviceStateUP, |
| 1082 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1083 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1084 | SerialNum: "test_serial_number", |
| 1085 | } |
| 1086 | va.PortsDisc.Store("test_port", voltPortTest1) |
| 1087 | va.DevicesDisc.Store(test_device, voltDevice_test) |
| 1088 | err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID) |
| 1089 | assert.NotNil(t, err) |
| 1090 | case "sVlan != of.VlanNone && sVlan != vs.SVlan": |
| 1091 | voltPortTest.Device = test_device |
| 1092 | va.PortsDisc.Store("test_port", voltPortTest) |
| 1093 | va.DevicesDisc.Store(test_device, voltDevice) |
| 1094 | va.ServiceByName.Store("test_name", voltServiceTest) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 1095 | err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID) |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 1096 | assert.Nil(t, err) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1097 | } |
| 1098 | }) |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | func TestVoltApplication_GetProgrammedSubscribers(t *testing.T) { |
| 1103 | type args struct { |
| 1104 | cntx context.Context |
| 1105 | deviceID string |
| 1106 | portNo string |
| 1107 | } |
| 1108 | tests := []struct { |
| 1109 | name string |
| 1110 | args args |
| 1111 | want []*VoltService |
| 1112 | wantErr bool |
| 1113 | }{ |
| 1114 | { |
| 1115 | name: "VoltApplication_GetProgrammedSubscribers", |
| 1116 | args: args{ |
| 1117 | cntx: context.Background(), |
| 1118 | deviceID: test_device, |
| 1119 | portNo: "test_port", |
| 1120 | }, |
| 1121 | }, |
| 1122 | { |
| 1123 | name: "portNo_nil", |
| 1124 | args: args{ |
| 1125 | cntx: context.Background(), |
| 1126 | deviceID: test_device, |
| 1127 | }, |
| 1128 | }, |
| 1129 | { |
| 1130 | name: "deviceID_nil", |
| 1131 | args: args{ |
| 1132 | cntx: context.Background(), |
| 1133 | }, |
| 1134 | }, |
| 1135 | } |
| 1136 | for _, tt := range tests { |
| 1137 | t.Run(tt.name, func(t *testing.T) { |
| 1138 | va := &VoltApplication{ |
| 1139 | vendorID: "test_vendor", |
| 1140 | } |
| 1141 | voltServiceTest := &VoltService{ |
| 1142 | VoltServiceOper: VoltServiceOper{ |
| 1143 | Device: test_device, |
| 1144 | }, |
| 1145 | Version: "test_version", |
| 1146 | VoltServiceCfg: VoltServiceCfg{ |
| 1147 | Port: "test_port", |
| 1148 | Name: "test_name", |
| 1149 | IsActivated: false, |
| 1150 | CVlan: of.VlanAny, |
| 1151 | SVlan: of.VlanAny, |
| 1152 | UniVlan: of.VlanAny, |
| 1153 | }, |
| 1154 | } |
| 1155 | switch tt.name { |
| 1156 | case "VoltApplication_GetProgrammedSubscribers": |
| 1157 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 1158 | got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo) |
| 1159 | assert.NotNil(t, got) |
| 1160 | assert.Nil(t, err) |
| 1161 | case "portNo_nil": |
| 1162 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 1163 | got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo) |
| 1164 | assert.NotNil(t, got) |
| 1165 | assert.Nil(t, err) |
| 1166 | case "deviceID_nil": |
| 1167 | va.ServiceByName.Store("test_name", voltServiceTest) |
| 1168 | got, err := va.GetProgrammedSubscribers(tt.args.cntx, tt.args.deviceID, tt.args.portNo) |
| 1169 | assert.NotNil(t, got) |
| 1170 | assert.Nil(t, err) |
| 1171 | } |
| 1172 | }) |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | func TestVoltService_JSONMarshal(t *testing.T) { |
| 1177 | tests := []struct { |
| 1178 | name string |
| 1179 | }{ |
| 1180 | { |
| 1181 | name: "VoltService_JSONMarshal", |
| 1182 | }, |
| 1183 | } |
| 1184 | for _, tt := range tests { |
| 1185 | t.Run(tt.name, func(t *testing.T) { |
| 1186 | vs := &VoltService{ |
| 1187 | VoltServiceOper: VoltServiceOper{ |
| 1188 | Device: test_device, |
| 1189 | }, |
| 1190 | Version: "test_version", |
| 1191 | VoltServiceCfg: VoltServiceCfg{ |
| 1192 | Name: "test_name", |
| 1193 | }, |
| 1194 | } |
| 1195 | got, err := vs.JSONMarshal() |
| 1196 | assert.NotNil(t, got) |
| 1197 | assert.Nil(t, err) |
| 1198 | }) |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | func TestVoltService_triggerServiceInProgressInd(t *testing.T) { |
| 1203 | tests := []struct { |
| 1204 | name string |
| 1205 | }{ |
| 1206 | { |
| 1207 | name: "VoltService_triggerServiceInProgressInd", |
| 1208 | }, |
| 1209 | } |
| 1210 | for _, tt := range tests { |
| 1211 | t.Run(tt.name, func(t *testing.T) { |
| 1212 | vs := &VoltService{ |
| 1213 | Version: "test_version", |
| 1214 | } |
| 1215 | vs.triggerServiceInProgressInd() |
| 1216 | }) |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | func TestVoltService_TriggerAssociatedFlowDelete(t *testing.T) { |
| 1221 | type args struct { |
| 1222 | cntx context.Context |
| 1223 | } |
| 1224 | tests := []struct { |
| 1225 | name string |
| 1226 | args args |
| 1227 | want bool |
| 1228 | }{ |
| 1229 | { |
| 1230 | name: "VoltService_TriggerAssociatedFlowDelete", |
| 1231 | args: args{ |
| 1232 | cntx: context.Background(), |
| 1233 | }, |
| 1234 | want: true, |
| 1235 | }, |
| 1236 | { |
| 1237 | name: "cookieList_nil", |
| 1238 | args: args{ |
| 1239 | cntx: context.Background(), |
| 1240 | }, |
| 1241 | want: false, |
| 1242 | }, |
| 1243 | } |
| 1244 | associatedFlows := map[string]bool{} |
| 1245 | associatedFlows["5765317"] = true |
| 1246 | for _, tt := range tests { |
| 1247 | t.Run(tt.name, func(t *testing.T) { |
| 1248 | switch tt.name { |
| 1249 | case "VoltService_TriggerAssociatedFlowDelete": |
| 1250 | vs := &VoltService{ |
| 1251 | VoltServiceOper: VoltServiceOper{ |
| 1252 | UsHSIAFlowsApplied: true, |
| 1253 | DsHSIAFlowsApplied: true, |
| 1254 | AssociatedFlows: associatedFlows, |
| 1255 | Device: test_device, |
| 1256 | }, |
| 1257 | } |
| 1258 | ga := GetApplication() |
| 1259 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 1260 | if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want { |
| 1261 | t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 1262 | } |
| 1263 | case "cookieList_nil": |
| 1264 | vs := &VoltService{ |
| 1265 | VoltServiceOper: VoltServiceOper{ |
| 1266 | UsHSIAFlowsApplied: true, |
| 1267 | DsHSIAFlowsApplied: true, |
| 1268 | Device: test_device, |
| 1269 | }, |
| 1270 | } |
| 1271 | ga := GetApplication() |
| 1272 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 1273 | if got := vs.TriggerAssociatedFlowDelete(tt.args.cntx); got != tt.want { |
| 1274 | t.Errorf("VoltService.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 1275 | } |
| 1276 | } |
| 1277 | }) |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | func TestVoltApplication_DeepEqualServicecfg(t *testing.T) { |
| 1282 | type args struct { |
| 1283 | evs *VoltServiceCfg |
| 1284 | nvs *VoltServiceCfg |
| 1285 | } |
| 1286 | a := map[int]int{} |
| 1287 | a[0] = 0 |
| 1288 | tests := []struct { |
| 1289 | name string |
| 1290 | args args |
| 1291 | want bool |
| 1292 | }{ |
| 1293 | { |
| 1294 | name: "VoltApplication_DeepEqualServicecfg", |
| 1295 | args: args{ |
| 1296 | evs: &VoltServiceCfg{ |
| 1297 | Port: "test_port", |
| 1298 | }, |
| 1299 | nvs: &VoltServiceCfg{ |
| 1300 | Port: "test_port", |
| 1301 | }, |
| 1302 | }, |
| 1303 | want: true, |
| 1304 | }, |
| 1305 | { |
| 1306 | name: "nvs.Name != evs.Name", |
| 1307 | args: args{ |
| 1308 | evs: &VoltServiceCfg{ |
| 1309 | Name: "test_name", |
| 1310 | }, |
| 1311 | nvs: &VoltServiceCfg{ |
| 1312 | Port: "test_port", |
| 1313 | }, |
| 1314 | }, |
| 1315 | want: false, |
| 1316 | }, |
| 1317 | { |
| 1318 | name: "nvs.UniVlan != evs.UniVlan", |
| 1319 | args: args{ |
| 1320 | evs: &VoltServiceCfg{ |
| 1321 | UniVlan: of.VlanAny, |
| 1322 | }, |
| 1323 | nvs: &VoltServiceCfg{ |
| 1324 | Port: "test_port", |
| 1325 | }, |
| 1326 | }, |
| 1327 | want: false, |
| 1328 | }, |
| 1329 | { |
| 1330 | name: "nvs.CVlan != evs.CVlan", |
| 1331 | args: args{ |
| 1332 | evs: &VoltServiceCfg{ |
| 1333 | CVlan: of.VlanAny, |
| 1334 | }, |
| 1335 | nvs: &VoltServiceCfg{ |
| 1336 | Port: "test_port", |
| 1337 | }, |
| 1338 | }, |
| 1339 | want: false, |
| 1340 | }, |
| 1341 | { |
| 1342 | name: "nvs.SVlan != evs.SVlan", |
| 1343 | args: args{ |
| 1344 | evs: &VoltServiceCfg{ |
| 1345 | SVlan: of.VlanAny, |
| 1346 | }, |
| 1347 | nvs: &VoltServiceCfg{ |
| 1348 | Port: "test_port", |
| 1349 | }, |
| 1350 | }, |
| 1351 | want: false, |
| 1352 | }, |
| 1353 | { |
| 1354 | name: "nvs.SVlanTpid != 0", |
| 1355 | args: args{ |
| 1356 | evs: &VoltServiceCfg{ |
| 1357 | SVlanTpid: layers.EthernetTypeARP, |
| 1358 | }, |
| 1359 | nvs: &VoltServiceCfg{ |
| 1360 | SVlanTpid: layers.EthernetTypeCiscoDiscovery, |
| 1361 | }, |
| 1362 | }, |
| 1363 | want: false, |
| 1364 | }, |
| 1365 | { |
| 1366 | name: "nvs.Pbits != evs.Pbits", |
| 1367 | args: args{ |
| 1368 | evs: &VoltServiceCfg{ |
| 1369 | Pbits: []of.PbitType{ |
| 1370 | PbitMatchAll, |
| 1371 | }, |
| 1372 | }, |
| 1373 | nvs: &VoltServiceCfg{ |
| 1374 | Port: "test_port", |
| 1375 | }, |
| 1376 | }, |
| 1377 | want: false, |
| 1378 | }, |
| 1379 | { |
| 1380 | name: "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap", |
| 1381 | args: args{ |
| 1382 | evs: &VoltServiceCfg{ |
| 1383 | DsRemarkPbitsMap: a, |
| 1384 | }, |
| 1385 | nvs: &VoltServiceCfg{ |
| 1386 | Port: "test_port", |
| 1387 | }, |
| 1388 | }, |
| 1389 | want: false, |
| 1390 | }, |
| 1391 | { |
| 1392 | name: "nvs.TechProfileID != evs.TechProfileID", |
| 1393 | args: args{ |
| 1394 | evs: &VoltServiceCfg{ |
| 1395 | TechProfileID: uint16(1), |
| 1396 | }, |
| 1397 | nvs: &VoltServiceCfg{ |
| 1398 | Port: "test_port", |
| 1399 | }, |
| 1400 | }, |
| 1401 | want: false, |
| 1402 | }, |
| 1403 | { |
| 1404 | name: "nvs.CircuitID != evs.CircuitID", |
| 1405 | args: args{ |
| 1406 | evs: &VoltServiceCfg{ |
| 1407 | CircuitID: "test_circuit_id", |
| 1408 | }, |
| 1409 | nvs: &VoltServiceCfg{ |
| 1410 | Port: "test_port", |
| 1411 | }, |
| 1412 | }, |
| 1413 | want: false, |
| 1414 | }, |
| 1415 | { |
| 1416 | name: "nvs.RemoteID != evs.RemoteID", |
| 1417 | args: args{ |
| 1418 | evs: &VoltServiceCfg{ |
| 1419 | RemoteID: []byte{1}, |
| 1420 | }, |
| 1421 | nvs: &VoltServiceCfg{ |
| 1422 | Port: "test_port", |
| 1423 | }, |
| 1424 | }, |
| 1425 | want: false, |
| 1426 | }, |
| 1427 | { |
| 1428 | name: "nvs.Port != evs.Port", |
| 1429 | args: args{ |
| 1430 | evs: &VoltServiceCfg{}, |
| 1431 | nvs: &VoltServiceCfg{ |
| 1432 | Port: "test_port", |
| 1433 | }, |
| 1434 | }, |
| 1435 | want: false, |
| 1436 | }, |
| 1437 | { |
| 1438 | name: "nvs.PonPort != evs.PonPort", |
| 1439 | args: args{ |
| 1440 | evs: &VoltServiceCfg{}, |
| 1441 | nvs: &VoltServiceCfg{ |
| 1442 | PonPort: uint32(1), |
| 1443 | }, |
| 1444 | }, |
| 1445 | want: false, |
| 1446 | }, |
| 1447 | { |
| 1448 | name: "evs.MacLearning == MacLearningNone", |
| 1449 | args: args{ |
| 1450 | evs: &VoltServiceCfg{ |
| 1451 | MacAddr: layers.EthernetBroadcast, |
| 1452 | }, |
| 1453 | nvs: &VoltServiceCfg{}, |
| 1454 | }, |
| 1455 | want: false, |
| 1456 | }, |
| 1457 | { |
| 1458 | name: "nvs.IgmpEnabled != evs.IgmpEnabled", |
| 1459 | args: args{ |
| 1460 | evs: &VoltServiceCfg{ |
| 1461 | IgmpEnabled: true, |
| 1462 | }, |
| 1463 | nvs: &VoltServiceCfg{}, |
| 1464 | }, |
| 1465 | want: false, |
| 1466 | }, |
| 1467 | { |
| 1468 | name: "nvs.McastService != evs.McastService", |
| 1469 | args: args{ |
| 1470 | evs: &VoltServiceCfg{ |
| 1471 | McastService: true, |
| 1472 | }, |
| 1473 | nvs: &VoltServiceCfg{}, |
| 1474 | }, |
| 1475 | want: false, |
| 1476 | }, |
| 1477 | { |
| 1478 | name: "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification", |
| 1479 | args: args{ |
| 1480 | evs: &VoltServiceCfg{ |
| 1481 | ONTEtherTypeClassification: 1, |
| 1482 | }, |
| 1483 | nvs: &VoltServiceCfg{}, |
| 1484 | }, |
| 1485 | want: false, |
| 1486 | }, |
| 1487 | { |
| 1488 | name: "nvs.UsMeterProfile != evs.UsMeterProfile", |
| 1489 | args: args{ |
| 1490 | evs: &VoltServiceCfg{ |
| 1491 | UsMeterProfile: "UsMeterProfile", |
| 1492 | }, |
| 1493 | nvs: &VoltServiceCfg{}, |
| 1494 | }, |
| 1495 | want: false, |
| 1496 | }, |
| 1497 | { |
| 1498 | name: "nvs.DsMeterProfile != evs.DsMeterProfile", |
| 1499 | args: args{ |
| 1500 | evs: &VoltServiceCfg{ |
| 1501 | DsMeterProfile: "DsMeterProfile", |
| 1502 | }, |
| 1503 | nvs: &VoltServiceCfg{}, |
| 1504 | }, |
| 1505 | want: false, |
| 1506 | }, |
| 1507 | { |
| 1508 | name: "nvs.AggDsMeterProfile != evs.AggDsMeterProfile", |
| 1509 | args: args{ |
| 1510 | evs: &VoltServiceCfg{ |
| 1511 | AggDsMeterProfile: "AggDsMeterProfile", |
| 1512 | }, |
| 1513 | nvs: &VoltServiceCfg{}, |
| 1514 | }, |
| 1515 | want: false, |
| 1516 | }, |
| 1517 | { |
| 1518 | name: "nvs.VnetID != evs.VnetID", |
| 1519 | args: args{ |
| 1520 | evs: &VoltServiceCfg{ |
| 1521 | VnetID: "VnetID", |
| 1522 | }, |
| 1523 | nvs: &VoltServiceCfg{}, |
| 1524 | }, |
| 1525 | want: false, |
| 1526 | }, |
| 1527 | { |
| 1528 | name: "nvs.MvlanProfileName != evs.MvlanProfileName", |
| 1529 | args: args{ |
| 1530 | evs: &VoltServiceCfg{ |
| 1531 | MvlanProfileName: "MvlanProfileName", |
| 1532 | }, |
| 1533 | nvs: &VoltServiceCfg{}, |
| 1534 | }, |
| 1535 | want: false, |
| 1536 | }, |
| 1537 | { |
| 1538 | name: "nvs.RemoteIDType != evs.RemoteIDType", |
| 1539 | args: args{ |
| 1540 | evs: &VoltServiceCfg{ |
| 1541 | RemoteIDType: "RemoteIDType", |
| 1542 | }, |
| 1543 | nvs: &VoltServiceCfg{}, |
| 1544 | }, |
| 1545 | want: false, |
| 1546 | }, |
| 1547 | { |
| 1548 | name: "nvs.SchedID != evs.SchedID", |
| 1549 | args: args{ |
| 1550 | evs: &VoltServiceCfg{ |
| 1551 | SchedID: 1, |
| 1552 | }, |
| 1553 | nvs: &VoltServiceCfg{}, |
| 1554 | }, |
| 1555 | want: false, |
| 1556 | }, |
| 1557 | { |
| 1558 | name: "nvs.AllowTransparent != evs.AllowTransparent", |
| 1559 | args: args{ |
| 1560 | evs: &VoltServiceCfg{ |
| 1561 | AllowTransparent: true, |
| 1562 | }, |
| 1563 | nvs: &VoltServiceCfg{}, |
| 1564 | }, |
| 1565 | want: false, |
| 1566 | }, |
| 1567 | { |
| 1568 | name: "nvs.EnableMulticastKPI != evs.EnableMulticastKPI", |
| 1569 | args: args{ |
| 1570 | evs: &VoltServiceCfg{ |
| 1571 | EnableMulticastKPI: true, |
| 1572 | }, |
| 1573 | nvs: &VoltServiceCfg{}, |
| 1574 | }, |
| 1575 | want: false, |
| 1576 | }, |
| 1577 | { |
| 1578 | name: "nvs.DataRateAttr != evs.DataRateAttr", |
| 1579 | args: args{ |
| 1580 | evs: &VoltServiceCfg{ |
| 1581 | DataRateAttr: "DataRateAttr", |
| 1582 | }, |
| 1583 | nvs: &VoltServiceCfg{}, |
| 1584 | }, |
| 1585 | want: false, |
| 1586 | }, |
| 1587 | { |
| 1588 | name: "nvs.MinDataRateUs != evs.MinDataRateUs", |
| 1589 | args: args{ |
| 1590 | evs: &VoltServiceCfg{ |
| 1591 | MinDataRateUs: uint32(1), |
| 1592 | }, |
| 1593 | nvs: &VoltServiceCfg{}, |
| 1594 | }, |
| 1595 | want: false, |
| 1596 | }, |
| 1597 | { |
| 1598 | name: "nvs.MinDataRateDs != evs.MinDataRateDs", |
| 1599 | args: args{ |
| 1600 | evs: &VoltServiceCfg{ |
| 1601 | MinDataRateDs: uint32(1), |
| 1602 | }, |
| 1603 | nvs: &VoltServiceCfg{}, |
| 1604 | }, |
| 1605 | want: false, |
| 1606 | }, |
| 1607 | { |
| 1608 | name: "nvs.MaxDataRateUs != evs.MaxDataRateUs", |
| 1609 | args: args{ |
| 1610 | evs: &VoltServiceCfg{ |
| 1611 | MaxDataRateUs: uint32(1), |
| 1612 | }, |
| 1613 | nvs: &VoltServiceCfg{}, |
| 1614 | }, |
| 1615 | want: false, |
| 1616 | }, |
| 1617 | { |
| 1618 | name: "nvs.MaxDataRateDs != evs.MaxDataRateDs", |
| 1619 | args: args{ |
| 1620 | evs: &VoltServiceCfg{ |
| 1621 | MaxDataRateDs: uint32(1), |
| 1622 | }, |
| 1623 | nvs: &VoltServiceCfg{}, |
| 1624 | }, |
| 1625 | want: false, |
| 1626 | }, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1627 | { |
| 1628 | name: "nvs.IsOption82Enabled != evs.IsOption82Enabled", |
| 1629 | args: args{ |
| 1630 | evs: &VoltServiceCfg{ |
| 1631 | IsOption82Enabled: true, |
| 1632 | }, |
| 1633 | nvs: &VoltServiceCfg{}, |
| 1634 | }, |
| 1635 | want: false, |
| 1636 | }, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1637 | } |
| 1638 | for _, tt := range tests { |
| 1639 | t.Run(tt.name, func(t *testing.T) { |
| 1640 | va := &VoltApplication{ |
| 1641 | vendorID: "test_vendor_id", |
| 1642 | } |
| 1643 | switch tt.name { |
| 1644 | case "VoltApplication_DeepEqualServicecfg", "nvs.Name != evs.Name", "nvs.UniVlan != evs.UniVlan", |
| 1645 | "nvs.CVlan != evs.CVlan", "nvs.SVlan != evs.SVlan", "nvs.SVlanTpid != 0", "nvs.Pbits != evs.Pbits", |
| 1646 | "nvs.DsRemarkPbitsMap != evs.DsRemarkPbitsMap", "nvs.TechProfileID != evs.TechProfileID", |
| 1647 | "nvs.CircuitID != evs.CircuitID", "nvs.RemoteID != evs.RemoteID", "nvs.Port != evs.Port", |
| 1648 | "evs.MacLearning == MacLearningNone", "nvs.PonPort != evs.PonPort", "nvs.IgmpEnabled != evs.IgmpEnabled", |
| 1649 | "nvs.McastService != evs.McastService", "nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification", |
| 1650 | "nvs.UsMeterProfile != evs.UsMeterProfile", |
| 1651 | "nvs.DsMeterProfile != evs.DsMeterProfile", "nvs.AggDsMeterProfile != evs.AggDsMeterProfile", |
| 1652 | "nvs.VnetID != evs.VnetID", "nvs.MvlanProfileName != evs.MvlanProfileName", |
| 1653 | "nvs.RemoteIDType != evs.RemoteIDType", "nvs.SchedID != evs.SchedID", |
| 1654 | "nvs.AllowTransparent != evs.AllowTransparent", |
| 1655 | "nvs.EnableMulticastKPI != evs.EnableMulticastKPI", "nvs.DataRateAttr != evs.DataRateAttr", |
| 1656 | "nvs.MinDataRateUs != evs.MinDataRateUs", "nvs.MinDataRateDs != evs.MinDataRateDs", |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1657 | "nvs.MaxDataRateUs != evs.MaxDataRateUs", "nvs.MaxDataRateDs != evs.MaxDataRateDs", |
| 1658 | "nvs.IsOption82Enabled != evs.IsOption82Enabled": |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1659 | if got := va.DeepEqualServicecfg(tt.args.evs, tt.args.nvs); got != tt.want { |
| 1660 | t.Errorf("VoltApplication.DeepEqualServicecfg() = %v, want %v", got, tt.want) |
| 1661 | } |
| 1662 | } |
| 1663 | }) |
| 1664 | } |
| 1665 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1666 | |
| 1667 | func Test_forceUpdateAllServices(t *testing.T) { |
| 1668 | type args struct { |
| 1669 | cntx context.Context |
| 1670 | msr *MigrateServicesRequest |
| 1671 | } |
| 1672 | servicesList := map[string]bool{} |
| 1673 | servicesList[test_device] = true |
| 1674 | tests := []struct { |
| 1675 | name string |
| 1676 | args args |
| 1677 | }{ |
| 1678 | { |
| 1679 | name: "forceUpdateAllServices", |
| 1680 | args: args{ |
| 1681 | cntx: context.Background(), |
| 1682 | msr: &MigrateServicesRequest{ |
| 1683 | ID: "test_id", |
| 1684 | ServicesList: servicesList, |
| 1685 | DeviceID: test_device, |
| 1686 | }, |
| 1687 | }, |
| 1688 | }, |
| 1689 | } |
| 1690 | for _, tt := range tests { |
| 1691 | t.Run(tt.name, func(t *testing.T) { |
| 1692 | ga := GetApplication() |
| 1693 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1694 | db = dbintf |
| 1695 | dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1696 | ga.ServiceByName.Store(test_device, voltService2) |
| 1697 | voltService2.VoltServiceOper.Metadata = &MigrateServiceMetadata{ |
| 1698 | NewVnetID: "test_new_vnet_id", |
| 1699 | RequestID: "test_request_id", |
| 1700 | } |
| 1701 | newConcurrentMap := util.NewConcurrentMap() |
| 1702 | ga.DevicesDisc.Store(test_device, voltDevice2) |
| 1703 | voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap) |
| 1704 | migrateServicesRequest := &MigrateServicesRequest{ |
| 1705 | ID: "test_id", |
| 1706 | ServicesList: servicesList, |
| 1707 | } |
| 1708 | newConcurrentMap.Set("test_request_id", migrateServicesRequest) |
| 1709 | dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1710 | forceUpdateAllServices(tt.args.cntx, tt.args.msr) |
| 1711 | }) |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | func TestVoltService_updateVnetProfile(t *testing.T) { |
| 1716 | type args struct { |
| 1717 | cntx context.Context |
| 1718 | deviceID string |
| 1719 | } |
| 1720 | tests := []struct { |
| 1721 | name string |
| 1722 | args args |
| 1723 | }{ |
| 1724 | { |
| 1725 | name: "DeleteInProgress_true", |
| 1726 | args: args{ |
| 1727 | cntx: context.Background(), |
| 1728 | deviceID: test_device, |
| 1729 | }, |
| 1730 | }, |
| 1731 | { |
| 1732 | name: "metadata_nil", |
| 1733 | args: args{ |
| 1734 | cntx: context.Background(), |
| 1735 | deviceID: test_device, |
| 1736 | }, |
| 1737 | }, |
| 1738 | } |
| 1739 | for _, tt := range tests { |
| 1740 | t.Run(tt.name, func(t *testing.T) { |
| 1741 | switch tt.name { |
| 1742 | case "DeleteInProgress_true": |
| 1743 | vs := &VoltService{ |
| 1744 | VoltServiceOper: VoltServiceOper{ |
| 1745 | DeleteInProgress: true, |
| 1746 | }, |
| 1747 | } |
| 1748 | vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID) |
| 1749 | case "metadata_nil": |
| 1750 | vs := &VoltService{ |
| 1751 | VoltServiceOper: VoltServiceOper{ |
| 1752 | Metadata: &MigrateServiceMetadata{}, |
| 1753 | }, |
| 1754 | } |
| 1755 | vs.updateVnetProfile(tt.args.cntx, tt.args.deviceID) |
| 1756 | } |
| 1757 | }) |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | func TestMigrateServicesRequest_serviceMigrated(t *testing.T) { |
| 1762 | type args struct { |
| 1763 | cntx context.Context |
| 1764 | serviceName string |
| 1765 | } |
| 1766 | tests := []struct { |
| 1767 | name string |
| 1768 | args args |
| 1769 | }{ |
| 1770 | { |
| 1771 | name: "ServicesList_nil", |
| 1772 | args: args{ |
| 1773 | cntx: context.Background(), |
| 1774 | serviceName: "test_service_name", |
| 1775 | }, |
| 1776 | }, |
| 1777 | } |
| 1778 | for _, tt := range tests { |
| 1779 | t.Run(tt.name, func(t *testing.T) { |
| 1780 | msr := &MigrateServicesRequest{ |
| 1781 | ServicesList: map[string]bool{}, |
| 1782 | } |
| 1783 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1784 | db = dbintf |
| 1785 | dbintf.EXPECT().DelMigrateServicesReq(gomock.All(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 1786 | msr.serviceMigrated(tt.args.cntx, tt.args.serviceName) |
| 1787 | }) |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | func TestVoltApplication_TriggerPendingMigrateServicesReq(t *testing.T) { |
| 1792 | type args struct { |
| 1793 | cntx context.Context |
| 1794 | device string |
| 1795 | } |
| 1796 | tests := []struct { |
| 1797 | name string |
| 1798 | args args |
| 1799 | }{ |
| 1800 | { |
| 1801 | name: "VoltApplication_TriggerPendingMigrateServicesReq", |
| 1802 | args: args{ |
| 1803 | cntx: context.Background(), |
| 1804 | device: test_device, |
| 1805 | }, |
| 1806 | }, |
| 1807 | } |
| 1808 | for _, tt := range tests { |
| 1809 | t.Run(tt.name, func(t *testing.T) { |
| 1810 | va := &VoltApplication{ |
| 1811 | ServiceByName: sync.Map{}, |
| 1812 | } |
| 1813 | migrateServicesRequest := &MigrateServicesRequest{ |
| 1814 | ID: "test_id", |
| 1815 | OldVnetID: "test_vnet_id", |
| 1816 | DeviceID: test_device, |
| 1817 | } |
| 1818 | b, err := json.Marshal(migrateServicesRequest) |
| 1819 | if err != nil { |
| 1820 | panic(err) |
| 1821 | } |
| 1822 | kvpair := map[string]*kvstore.KVPair{} |
| 1823 | kvpair["test_device_id"] = &kvstore.KVPair{ |
| 1824 | Key: "test_device_id", |
| 1825 | Value: b, |
| 1826 | } |
| 1827 | |
| 1828 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1829 | db = dbintf |
| 1830 | ga := GetApplication() |
| 1831 | ga.DevicesDisc.Store(test_device, voltDevice2) |
| 1832 | newConcurrentMap := util.NewConcurrentMap() |
| 1833 | voltDevice2.MigratingServices.Set("test_vnet_id", newConcurrentMap) |
| 1834 | dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes() |
| 1835 | va.TriggerPendingMigrateServicesReq(tt.args.cntx, tt.args.device) |
| 1836 | }) |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | func TestVoltApplication_FetchAndProcessAllMigrateServicesReq(t *testing.T) { |
| 1841 | type args struct { |
| 1842 | cntx context.Context |
| 1843 | device string |
| 1844 | msrAction func(context.Context, *MigrateServicesRequest) |
| 1845 | } |
| 1846 | tests := []struct { |
| 1847 | name string |
| 1848 | args args |
| 1849 | }{ |
| 1850 | { |
| 1851 | name: "invalid_value_type", |
| 1852 | args: args{ |
| 1853 | cntx: context.Background(), |
| 1854 | device: test_device, |
| 1855 | msrAction: func(ctx context.Context, msr *MigrateServicesRequest) {}, |
| 1856 | }, |
| 1857 | }, |
| 1858 | } |
| 1859 | for _, tt := range tests { |
| 1860 | t.Run(tt.name, func(t *testing.T) { |
| 1861 | va := &VoltApplication{ |
| 1862 | DevicesDisc: sync.Map{}, |
| 1863 | } |
| 1864 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1865 | db = dbintf |
| 1866 | kvpair := map[string]*kvstore.KVPair{} |
| 1867 | kvpair["test_device_id"] = &kvstore.KVPair{ |
| 1868 | Key: "test_device_id", |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 1869 | Value: invalid_value, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 1870 | } |
| 1871 | dbintf.EXPECT().GetAllMigrateServicesReq(gomock.Any(), gomock.Any()).Return(kvpair, nil).AnyTimes() |
| 1872 | va.FetchAndProcessAllMigrateServicesReq(tt.args.cntx, tt.args.device, tt.args.msrAction) |
| 1873 | }) |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | func TestVoltApplication_createMigrateServicesFromString(t *testing.T) { |
| 1878 | type args struct { |
| 1879 | b []byte |
| 1880 | } |
| 1881 | tests := []struct { |
| 1882 | name string |
| 1883 | args args |
| 1884 | }{ |
| 1885 | { |
| 1886 | name: "Unmarshal_error", |
| 1887 | args: args{ |
| 1888 | b: []byte{}, |
| 1889 | }, |
| 1890 | }, |
| 1891 | } |
| 1892 | for _, tt := range tests { |
| 1893 | t.Run(tt.name, func(t *testing.T) { |
| 1894 | va := &VoltApplication{ |
| 1895 | vendorID: test_device, |
| 1896 | } |
| 1897 | got := va.createMigrateServicesFromString(tt.args.b) |
| 1898 | assert.NotNil(t, got) |
| 1899 | }) |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | func TestVoltApplication_getMigrateServicesRequest(t *testing.T) { |
| 1904 | type args struct { |
| 1905 | deviceID string |
| 1906 | oldVnetID string |
| 1907 | requestID string |
| 1908 | } |
| 1909 | tests := []struct { |
| 1910 | name string |
| 1911 | args args |
| 1912 | want *MigrateServicesRequest |
| 1913 | }{ |
| 1914 | { |
| 1915 | name: "GetDevice_nil", |
| 1916 | args: args{ |
| 1917 | deviceID: test_device, |
| 1918 | }, |
| 1919 | }, |
| 1920 | } |
| 1921 | for _, tt := range tests { |
| 1922 | t.Run(tt.name, func(t *testing.T) { |
| 1923 | va := &VoltApplication{ |
| 1924 | vendorID: "vendorID", |
| 1925 | } |
| 1926 | if got := va.getMigrateServicesRequest(tt.args.deviceID, tt.args.oldVnetID, tt.args.requestID); !reflect.DeepEqual(got, tt.want) { |
| 1927 | t.Errorf("VoltApplication.getMigrateServicesRequest() = %v, want %v", got, tt.want) |
| 1928 | } |
| 1929 | }) |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | func TestVoltDevice_AddMigratingServices(t *testing.T) { |
| 1934 | type args struct { |
| 1935 | msr *MigrateServicesRequest |
| 1936 | } |
| 1937 | tests := []struct { |
| 1938 | name string |
| 1939 | args args |
| 1940 | }{ |
| 1941 | { |
| 1942 | name: "MigratingServices_Get_nil", |
| 1943 | args: args{ |
| 1944 | msr: &MigrateServicesRequest{ |
| 1945 | ID: "test_id", |
| 1946 | }, |
| 1947 | }, |
| 1948 | }, |
| 1949 | } |
| 1950 | for _, tt := range tests { |
| 1951 | t.Run(tt.name, func(t *testing.T) { |
| 1952 | d := &VoltDevice{ |
| 1953 | MigratingServices: util.NewConcurrentMap(), |
| 1954 | } |
| 1955 | d.AddMigratingServices(tt.args.msr) |
| 1956 | }) |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | func TestMigrateServicesRequest_ProcessMigrateServicesProfRequest(t *testing.T) { |
| 1961 | type args struct { |
| 1962 | cntx context.Context |
| 1963 | } |
| 1964 | tests := []struct { |
| 1965 | name string |
| 1966 | args args |
| 1967 | }{ |
| 1968 | { |
| 1969 | name: "ServicesList_true", |
| 1970 | args: args{ |
| 1971 | cntx: context.Background(), |
| 1972 | }, |
| 1973 | }, |
| 1974 | { |
| 1975 | name: "ServicesList_false", |
| 1976 | args: args{ |
| 1977 | cntx: context.Background(), |
| 1978 | }, |
| 1979 | }, |
| 1980 | { |
| 1981 | name: "GetVnetByPort_nil", |
| 1982 | args: args{ |
| 1983 | cntx: context.Background(), |
| 1984 | }, |
| 1985 | }, |
| 1986 | { |
| 1987 | name: "UsHSIAFlowsApplied_true", |
| 1988 | args: args{ |
| 1989 | cntx: context.Background(), |
| 1990 | }, |
| 1991 | }, |
| 1992 | { |
| 1993 | name: "ServiceByName_nil", |
| 1994 | args: args{ |
| 1995 | cntx: context.Background(), |
| 1996 | }, |
| 1997 | }, |
| 1998 | } |
| 1999 | for _, tt := range tests { |
| 2000 | t.Run(tt.name, func(t *testing.T) { |
| 2001 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2002 | db = dbintf |
| 2003 | switch tt.name { |
| 2004 | case "ServicesList_true": |
| 2005 | servicesList := map[string]bool{} |
| 2006 | servicesList[test_device] = true |
| 2007 | msr := &MigrateServicesRequest{ |
| 2008 | ServicesList: servicesList, |
| 2009 | } |
| 2010 | dbintf.EXPECT().DelMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2011 | msr.ProcessMigrateServicesProfRequest(tt.args.cntx) |
| 2012 | case "ServicesList_false": |
| 2013 | servicesList := map[string]bool{} |
| 2014 | servicesList[test_device] = false |
| 2015 | msr := &MigrateServicesRequest{ |
| 2016 | ServicesList: servicesList, |
| 2017 | } |
| 2018 | ga := GetApplication() |
| 2019 | ga.ServiceByName.Store(test_device, voltService2) |
| 2020 | ga.VnetsByPort.Store("test_port", voltPortVnet1) |
| 2021 | msr.ProcessMigrateServicesProfRequest(tt.args.cntx) |
| 2022 | case "GetVnetByPort_nil": |
| 2023 | servicesList := map[string]bool{} |
| 2024 | servicesList[test_device] = false |
| 2025 | msr := &MigrateServicesRequest{ |
| 2026 | ServicesList: servicesList, |
| 2027 | } |
| 2028 | ga := GetApplication() |
| 2029 | var voltService1 = &VoltService{ |
| 2030 | Version: "test_version", |
| 2031 | VoltServiceCfg: VoltServiceCfg{ |
| 2032 | VnetID: "test_vnet_id", |
| 2033 | SVlan: of.VlanAny, |
| 2034 | CVlan: of.VlanAny, |
| 2035 | UniVlan: of.VlanAny, |
| 2036 | }, |
| 2037 | } |
| 2038 | ga.ServiceByName.Store(test_device, voltService1) |
| 2039 | ga.VnetsByPort.Store("test_port1", nil) |
| 2040 | msr.ProcessMigrateServicesProfRequest(tt.args.cntx) |
| 2041 | case "UsHSIAFlowsApplied_true": |
| 2042 | servicesList := map[string]bool{} |
| 2043 | servicesList[test_device] = false |
| 2044 | msr := &MigrateServicesRequest{ |
| 2045 | ServicesList: servicesList, |
| 2046 | } |
| 2047 | ga := GetApplication() |
| 2048 | voltService2.UsHSIAFlowsApplied = true |
| 2049 | ga.ServiceByName.Store(test_device, voltService2) |
| 2050 | ga.VnetsByPort.Store("test_port", voltPortVnet1) |
| 2051 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2052 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2053 | msr.ProcessMigrateServicesProfRequest(tt.args.cntx) |
| 2054 | case "ServiceByName_nil": |
| 2055 | servicesList := map[string]bool{} |
| 2056 | servicesList[""] = false |
| 2057 | msr := &MigrateServicesRequest{ |
| 2058 | ServicesList: servicesList, |
| 2059 | } |
| 2060 | msr.ProcessMigrateServicesProfRequest(tt.args.cntx) |
| 2061 | } |
| 2062 | }) |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | func TestVoltApplication_MigrateServices(t *testing.T) { |
| 2067 | type args struct { |
| 2068 | cntx context.Context |
| 2069 | serialNum string |
| 2070 | reqID string |
| 2071 | oldVnetID string |
| 2072 | newVnetID string |
| 2073 | serviceList []string |
| 2074 | } |
| 2075 | tests := []struct { |
| 2076 | name string |
| 2077 | args args |
| 2078 | wantErr bool |
| 2079 | }{ |
| 2080 | { |
| 2081 | name: "VoltApplication_MigrateServices", |
| 2082 | args: args{ |
| 2083 | cntx: context.Background(), |
| 2084 | serialNum: "test_serial_number", |
| 2085 | reqID: "test_reqid", |
| 2086 | oldVnetID: "test_old_vnet_id", |
| 2087 | newVnetID: "test_new_vnet_id", |
| 2088 | serviceList: []string{"test_service_list_1", "test_service_list_2"}, |
| 2089 | }, |
| 2090 | }, |
| 2091 | { |
| 2092 | name: "Old Vnet Id not found", |
| 2093 | args: args{ |
| 2094 | cntx: context.Background(), |
| 2095 | serialNum: "test_serial_number", |
| 2096 | reqID: "test_reqid", |
| 2097 | oldVnetID: "", |
| 2098 | newVnetID: "test_new_vnet_id", |
| 2099 | serviceList: []string{"test_service_list_1", "test_service_list_2"}, |
| 2100 | }, |
| 2101 | }, |
| 2102 | { |
| 2103 | name: "New Vnet Id not found", |
| 2104 | args: args{ |
| 2105 | cntx: context.Background(), |
| 2106 | serialNum: "test_serial_number", |
| 2107 | reqID: "test_reqid", |
| 2108 | oldVnetID: "test_old_vnet_id", |
| 2109 | newVnetID: "", |
| 2110 | serviceList: []string{"test_service_list_1", "test_service_list_2"}, |
| 2111 | }, |
| 2112 | }, |
| 2113 | } |
| 2114 | for _, tt := range tests { |
| 2115 | t.Run(tt.name, func(t *testing.T) { |
| 2116 | va := &VoltApplication{ |
| 2117 | VnetsByName: sync.Map{}, |
| 2118 | } |
| 2119 | voltVnet2 := &VoltVnet{ |
| 2120 | Version: "v3", |
| 2121 | VnetConfig: VnetConfig{ |
| 2122 | Name: "2310-4096-4096", |
| 2123 | VnetType: "Encapsulation", |
| 2124 | SVlan: 2310, |
| 2125 | CVlan: 4096, |
| 2126 | UniVlan: 4096, |
| 2127 | SVlanTpid: 33024, |
| 2128 | }, |
| 2129 | VnetOper: VnetOper{ |
| 2130 | PendingDeviceToDelete: "SDX63200313", |
| 2131 | }, |
| 2132 | } |
| 2133 | switch tt.name { |
| 2134 | case "VoltApplication_MigrateServices": |
| 2135 | va.VnetsByName.Store("test_old_vnet_id", voltVnet2) |
| 2136 | va.VnetsByName.Store("test_new_vnet_id", voltVnet2) |
| 2137 | va.DevicesDisc.Store(test_device, voltDevice2) |
| 2138 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2139 | db = dbintf |
| 2140 | dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2141 | if err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList); (err != nil) != tt.wantErr { |
| 2142 | t.Errorf("VoltApplication.MigrateServices() error = %v, wantErr %v", err, tt.wantErr) |
| 2143 | } |
| 2144 | case "Old Vnet Id not found": |
| 2145 | va.VnetsByName.Store("test_old_vnet_id", voltVnet2) |
| 2146 | err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList) |
| 2147 | assert.NotNil(t, err) |
| 2148 | case "New Vnet Id not found": |
| 2149 | va.VnetsByName.Store("test_old_vnet_id", voltVnet2) |
| 2150 | va.VnetsByName.Store("test_new_vnet_id", voltVnet2) |
| 2151 | err := va.MigrateServices(tt.args.cntx, tt.args.serialNum, tt.args.reqID, tt.args.oldVnetID, tt.args.newVnetID, tt.args.serviceList) |
| 2152 | assert.NotNil(t, err) |
| 2153 | } |
| 2154 | }) |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | func TestMigrateServicesRequest_WriteToDB(t *testing.T) { |
| 2159 | type args struct { |
| 2160 | cntx context.Context |
| 2161 | } |
| 2162 | tests := []struct { |
| 2163 | name string |
| 2164 | args args |
| 2165 | }{ |
| 2166 | { |
| 2167 | name: "PutMigrateServicesReq_error", |
| 2168 | args: args{ |
| 2169 | cntx: context.Background(), |
| 2170 | }, |
| 2171 | }, |
| 2172 | } |
| 2173 | for _, tt := range tests { |
| 2174 | t.Run(tt.name, func(t *testing.T) { |
| 2175 | msr := &MigrateServicesRequest{ |
| 2176 | ID: test_device, |
| 2177 | } |
| 2178 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2179 | db = dbintf |
| 2180 | dbintf.EXPECT().PutMigrateServicesReq(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("error")).Times(1) |
| 2181 | msr.WriteToDB(tt.args.cntx) |
| 2182 | }) |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | func TestVoltService_MatchesVlans(t *testing.T) { |
| 2187 | type args struct { |
| 2188 | vlans []of.VlanType |
| 2189 | } |
| 2190 | tests := []struct { |
| 2191 | name string |
| 2192 | args args |
| 2193 | want bool |
| 2194 | }{ |
| 2195 | { |
| 2196 | name: "vlans_nil", |
| 2197 | args: args{ |
| 2198 | vlans: []of.VlanType{}, |
| 2199 | }, |
| 2200 | want: false, |
| 2201 | }, |
| 2202 | { |
| 2203 | name: "MatchesVlans", |
| 2204 | args: args{ |
| 2205 | vlans: []of.VlanType{ |
| 2206 | of.VlanAny, |
| 2207 | }, |
| 2208 | }, |
| 2209 | want: true, |
| 2210 | }, |
| 2211 | { |
| 2212 | name: "vlans[0] != vs.CVlan", |
| 2213 | args: args{ |
| 2214 | vlans: []of.VlanType{ |
| 2215 | of.VlanNone, |
| 2216 | }, |
| 2217 | }, |
| 2218 | want: false, |
| 2219 | }, |
| 2220 | } |
| 2221 | for _, tt := range tests { |
| 2222 | t.Run(tt.name, func(t *testing.T) { |
| 2223 | vs := &VoltService{ |
| 2224 | VoltServiceCfg: VoltServiceCfg{CVlan: of.VlanAny}, |
| 2225 | } |
| 2226 | switch tt.name { |
| 2227 | case "vlans_nil", "MatchesVlans", "vlans[0] != vs.CVlan": |
| 2228 | if got := vs.MatchesVlans(tt.args.vlans); got != tt.want { |
| 2229 | t.Errorf("VoltService.MatchesVlans() = %v, want %v", got, tt.want) |
| 2230 | } |
| 2231 | } |
| 2232 | }) |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | func TestVoltService_MatchesPbits(t *testing.T) { |
| 2237 | type args struct { |
| 2238 | pbits []of.PbitType |
| 2239 | } |
| 2240 | tests := []struct { |
| 2241 | name string |
| 2242 | args args |
| 2243 | want bool |
| 2244 | }{ |
| 2245 | { |
| 2246 | name: "VoltService_MatchesPbits", |
| 2247 | args: args{ |
| 2248 | pbits: []of.PbitType{ |
| 2249 | of.PbitMatchAll, |
| 2250 | }, |
| 2251 | }, |
| 2252 | want: true, |
| 2253 | }, |
| 2254 | { |
| 2255 | name: "PbitType_nil", |
| 2256 | args: args{ |
| 2257 | pbits: []of.PbitType{}, |
| 2258 | }, |
| 2259 | want: false, |
| 2260 | }, |
| 2261 | } |
| 2262 | for _, tt := range tests { |
| 2263 | t.Run(tt.name, func(t *testing.T) { |
| 2264 | vs := &VoltService{ |
| 2265 | VoltServiceCfg: VoltServiceCfg{ |
| 2266 | Pbits: []of.PbitType{ |
| 2267 | of.PbitMatchAll, |
| 2268 | }, |
| 2269 | }, |
| 2270 | } |
| 2271 | switch tt.name { |
| 2272 | case "VoltService_MatchesPbits", "PbitType_nil": |
| 2273 | if got := vs.MatchesPbits(tt.args.pbits); got != tt.want { |
| 2274 | t.Errorf("VoltService.MatchesPbits() = %v, want %v", got, tt.want) |
| 2275 | } |
| 2276 | } |
| 2277 | }) |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | func TestVoltApplication_DelServiceWithPrefix(t *testing.T) { |
| 2282 | type args struct { |
| 2283 | cntx context.Context |
| 2284 | prefix string |
| 2285 | } |
| 2286 | tests := []struct { |
| 2287 | name string |
| 2288 | args args |
| 2289 | }{ |
| 2290 | { |
| 2291 | name: "VoltApplication_DelServiceWithPrefix", |
| 2292 | args: args{ |
| 2293 | cntx: context.Background(), |
| 2294 | prefix: test_device, |
| 2295 | }, |
| 2296 | }, |
| 2297 | } |
| 2298 | for _, tt := range tests { |
| 2299 | t.Run(tt.name, func(t *testing.T) { |
| 2300 | va := &VoltApplication{ |
| 2301 | VnetsBySvlan: util.NewConcurrentMap(), |
| 2302 | } |
| 2303 | va.ServiceByName.Store(test_device, voltService) |
| 2304 | va.VnetsByName.Store("0-0-0", voltVnet) |
| 2305 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2306 | db = dbintf |
| 2307 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 2308 | cuncurrentMap := &util.ConcurrentMap{ |
| 2309 | Count: atomic.NewUint64(0), |
| 2310 | } |
| 2311 | va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap) |
| 2312 | dbintf.EXPECT().DelVnet(gomock.Any(), gomock.Any()).Return(nil).Times(1) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 2313 | err := va.DelServiceWithPrefix(tt.args.cntx, tt.args.prefix) |
| 2314 | assert.Nil(t, err) |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2315 | }) |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | func TestVoltService_FlowInstallFailure(t *testing.T) { |
| 2320 | type args struct { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2321 | cntx context.Context |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2322 | cookie string |
| 2323 | errorCode uint32 |
| 2324 | errReason string |
| 2325 | } |
| 2326 | tests := []struct { |
| 2327 | name string |
| 2328 | args args |
| 2329 | }{ |
| 2330 | { |
| 2331 | name: "VoltService_FlowInstallFailure", |
| 2332 | args: args{ |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2333 | cntx: context.Background(), |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2334 | cookie: "test_cookie", |
| 2335 | errorCode: uint32(1), |
| 2336 | errReason: "err_reason", |
| 2337 | }, |
| 2338 | }, |
| 2339 | { |
| 2340 | name: "PendingFlows[cookie]_false", |
| 2341 | args: args{ |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2342 | cntx: context.Background(), |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2343 | cookie: "test_cookie", |
| 2344 | errorCode: uint32(1), |
| 2345 | errReason: "err_reason", |
| 2346 | }, |
| 2347 | }, |
| 2348 | } |
| 2349 | pendingFlows := map[string]bool{} |
| 2350 | pendingFlows["test_cookie"] = true |
| 2351 | for _, tt := range tests { |
| 2352 | t.Run(tt.name, func(t *testing.T) { |
| 2353 | vs := &VoltService{ |
| 2354 | VoltServiceOper: VoltServiceOper{}, |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2355 | VoltServiceCfg: VoltServiceCfg{}, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2356 | } |
| 2357 | switch tt.name { |
| 2358 | case "VoltService_FlowInstallFailure": |
| 2359 | vs.PendingFlows = pendingFlows |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2360 | vs.FlowInstallFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2361 | case "PendingFlows[cookie]_false": |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2362 | vs.FlowInstallFailure(tt.args.cntx, tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2363 | } |
| 2364 | }) |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | func TestVoltService_FlowRemoveSuccess(t *testing.T) { |
| 2369 | type args struct { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2370 | cntx context.Context |
| 2371 | cookie string |
| 2372 | flowEventMap *util.ConcurrentMap |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2373 | } |
| 2374 | tests := []struct { |
| 2375 | name string |
| 2376 | args args |
| 2377 | }{ |
| 2378 | { |
| 2379 | name: "GetDevice != nil", |
| 2380 | args: args{ |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2381 | cntx: context.Background(), |
| 2382 | cookie: "test_cookie", |
| 2383 | flowEventMap: util.NewConcurrentMap(), |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2384 | }, |
| 2385 | }, |
| 2386 | } |
| 2387 | for _, tt := range tests { |
| 2388 | t.Run(tt.name, func(t *testing.T) { |
| 2389 | vs := &VoltService{ |
| 2390 | VoltServiceOper: VoltServiceOper{ |
| 2391 | Device: test_device, |
| 2392 | }, |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2393 | VoltServiceCfg: VoltServiceCfg{}, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2394 | } |
| 2395 | ga := GetApplication() |
| 2396 | ga.DevicesDisc.Store(test_device, voltDevice2) |
| 2397 | voltDevice2.State = controller.DeviceStateUP |
| 2398 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2399 | db = dbintf |
| 2400 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2401 | vs.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie) |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2402 | }) |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | func TestVoltService_setDSMatchActionVlanT0(t *testing.T) { |
| 2407 | type args struct { |
| 2408 | flow *of.VoltSubFlow |
| 2409 | } |
| 2410 | tests := []struct { |
| 2411 | name string |
| 2412 | args args |
| 2413 | wantErr bool |
| 2414 | }{ |
| 2415 | { |
| 2416 | name: "VlanControl: ONUCVlanOLTSVlan", |
| 2417 | args: args{ |
| 2418 | flow: &of.VoltSubFlow{ |
| 2419 | ErrorReason: "test_error_reason", |
| 2420 | Cookie: uint64(1), |
| 2421 | OldCookie: uint64(2), |
| 2422 | TableID: uint32(3), |
| 2423 | Priority: uint32(4), |
| 2424 | State: uint8(5), |
| 2425 | }, |
| 2426 | }, |
| 2427 | }, |
| 2428 | { |
| 2429 | name: "VlanControl: OLTCVlanOLTSVlan", |
| 2430 | args: args{ |
| 2431 | flow: &of.VoltSubFlow{ |
| 2432 | ErrorReason: "test_error_reason", |
| 2433 | Cookie: uint64(1), |
| 2434 | OldCookie: uint64(2), |
| 2435 | TableID: uint32(3), |
| 2436 | Priority: uint32(4), |
| 2437 | State: uint8(5), |
| 2438 | }, |
| 2439 | }, |
| 2440 | }, |
| 2441 | { |
| 2442 | name: "VlanControl: ONUCVlan", |
| 2443 | args: args{ |
| 2444 | flow: &of.VoltSubFlow{ |
| 2445 | ErrorReason: "test_error_reason", |
| 2446 | Cookie: uint64(1), |
| 2447 | OldCookie: uint64(2), |
| 2448 | TableID: uint32(3), |
| 2449 | Priority: uint32(4), |
| 2450 | State: uint8(5), |
| 2451 | }, |
| 2452 | }, |
| 2453 | }, |
| 2454 | { |
| 2455 | name: "VlanControl: OLTSVlan", |
| 2456 | args: args{ |
| 2457 | flow: &of.VoltSubFlow{ |
| 2458 | ErrorReason: "test_error_reason", |
| 2459 | Cookie: uint64(1), |
| 2460 | OldCookie: uint64(2), |
| 2461 | TableID: uint32(3), |
| 2462 | Priority: uint32(4), |
| 2463 | State: uint8(5), |
| 2464 | }, |
| 2465 | }, |
| 2466 | }, |
| 2467 | { |
| 2468 | name: "VlanControl: OLTSVlan && UniVlan != of.VlanAny", |
| 2469 | args: args{ |
| 2470 | flow: &of.VoltSubFlow{ |
| 2471 | ErrorReason: "test_error_reason", |
| 2472 | Cookie: uint64(1), |
| 2473 | OldCookie: uint64(2), |
| 2474 | TableID: uint32(3), |
| 2475 | Priority: uint32(4), |
| 2476 | State: uint8(5), |
| 2477 | }, |
| 2478 | }, |
| 2479 | }, |
| 2480 | { |
| 2481 | name: "invalid VlanControl", |
| 2482 | args: args{ |
| 2483 | flow: &of.VoltSubFlow{ |
| 2484 | ErrorReason: "test_error_reason", |
| 2485 | Cookie: uint64(1), |
| 2486 | OldCookie: uint64(2), |
| 2487 | TableID: uint32(3), |
| 2488 | Priority: uint32(4), |
| 2489 | State: uint8(5), |
| 2490 | }, |
| 2491 | }, |
| 2492 | }, |
| 2493 | } |
| 2494 | for _, tt := range tests { |
| 2495 | t.Run(tt.name, func(t *testing.T) { |
| 2496 | vs := &VoltService{ |
| 2497 | VoltServiceCfg: VoltServiceCfg{ |
| 2498 | SVlan: of.VlanAny, |
| 2499 | UniVlan: of.VlanAny, |
| 2500 | VlanControl: ONUCVlanOLTSVlan, |
| 2501 | }, |
| 2502 | } |
| 2503 | switch tt.name { |
| 2504 | case "VlanControl: ONUCVlanOLTSVlan": |
| 2505 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2506 | if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2507 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2508 | } |
| 2509 | case "VlanControl: OLTCVlanOLTSVlan": |
| 2510 | vs.VlanControl = OLTCVlanOLTSVlan |
| 2511 | if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2512 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2513 | } |
| 2514 | case "VlanControl: ONUCVlan": |
| 2515 | vs.VlanControl = ONUCVlan |
| 2516 | if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2517 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2518 | } |
| 2519 | case "VlanControl: OLTSVlan": |
| 2520 | vs.VlanControl = OLTSVlan |
| 2521 | vs.UniVlan = vs.CVlan |
| 2522 | if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2523 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2524 | } |
| 2525 | case "VlanControl: OLTSVlan && UniVlan != of.VlanAny": |
| 2526 | vs.VlanControl = OLTSVlan |
| 2527 | if err := vs.setDSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2528 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2529 | } |
| 2530 | case "invalid VlanControl": |
| 2531 | vs.VlanControl = 5 |
| 2532 | err := vs.setDSMatchActionVlanT0(tt.args.flow) |
| 2533 | assert.NotNil(t, err) |
| 2534 | } |
| 2535 | }) |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | func TestVoltService_setUSMatchActionVlanT1(t *testing.T) { |
| 2540 | type args struct { |
| 2541 | flow *of.VoltSubFlow |
| 2542 | } |
| 2543 | tests := []struct { |
| 2544 | name string |
| 2545 | args args |
| 2546 | wantErr bool |
| 2547 | }{ |
| 2548 | { |
| 2549 | name: "VlanControl: ONUCVlanOLTSVlan", |
| 2550 | args: args{ |
| 2551 | flow: &of.VoltSubFlow{ |
| 2552 | ErrorReason: "test_error_reason", |
| 2553 | Cookie: uint64(1), |
| 2554 | OldCookie: uint64(2), |
| 2555 | TableID: uint32(3), |
| 2556 | Priority: uint32(4), |
| 2557 | State: uint8(5), |
| 2558 | }, |
| 2559 | }, |
| 2560 | }, |
| 2561 | { |
| 2562 | name: "VlanControl: OLTCVlanOLTSVlan", |
| 2563 | args: args{ |
| 2564 | flow: &of.VoltSubFlow{ |
| 2565 | ErrorReason: "test_error_reason", |
| 2566 | Cookie: uint64(1), |
| 2567 | OldCookie: uint64(2), |
| 2568 | TableID: uint32(3), |
| 2569 | Priority: uint32(4), |
| 2570 | State: uint8(5), |
| 2571 | }, |
| 2572 | }, |
| 2573 | }, |
| 2574 | { |
| 2575 | name: "VlanControl: ONUCVlan", |
| 2576 | args: args{ |
| 2577 | flow: &of.VoltSubFlow{ |
| 2578 | ErrorReason: "test_error_reason", |
| 2579 | Cookie: uint64(1), |
| 2580 | OldCookie: uint64(2), |
| 2581 | TableID: uint32(3), |
| 2582 | Priority: uint32(4), |
| 2583 | State: uint8(5), |
| 2584 | }, |
| 2585 | }, |
| 2586 | }, |
| 2587 | { |
| 2588 | name: "VlanControl: OLTSVlan", |
| 2589 | args: args{ |
| 2590 | flow: &of.VoltSubFlow{ |
| 2591 | ErrorReason: "test_error_reason", |
| 2592 | Cookie: uint64(1), |
| 2593 | OldCookie: uint64(2), |
| 2594 | TableID: uint32(3), |
| 2595 | Priority: uint32(4), |
| 2596 | State: uint8(5), |
| 2597 | }, |
| 2598 | }, |
| 2599 | }, |
| 2600 | { |
| 2601 | name: "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone", |
| 2602 | args: args{ |
| 2603 | flow: &of.VoltSubFlow{ |
| 2604 | ErrorReason: "test_error_reason", |
| 2605 | Cookie: uint64(1), |
| 2606 | OldCookie: uint64(2), |
| 2607 | TableID: uint32(3), |
| 2608 | Priority: uint32(4), |
| 2609 | State: uint8(5), |
| 2610 | }, |
| 2611 | }, |
| 2612 | }, |
| 2613 | { |
| 2614 | name: "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone", |
| 2615 | args: args{ |
| 2616 | flow: &of.VoltSubFlow{ |
| 2617 | ErrorReason: "test_error_reason", |
| 2618 | Cookie: uint64(1), |
| 2619 | OldCookie: uint64(2), |
| 2620 | TableID: uint32(3), |
| 2621 | Priority: uint32(4), |
| 2622 | State: uint8(5), |
| 2623 | }, |
| 2624 | }, |
| 2625 | }, |
| 2626 | { |
| 2627 | name: "VlanControl: default", |
| 2628 | args: args{ |
| 2629 | flow: &of.VoltSubFlow{ |
| 2630 | ErrorReason: "test_error_reason", |
| 2631 | Cookie: uint64(1), |
| 2632 | OldCookie: uint64(2), |
| 2633 | TableID: uint32(3), |
| 2634 | Priority: uint32(4), |
| 2635 | State: uint8(5), |
| 2636 | }, |
| 2637 | }, |
| 2638 | }, |
| 2639 | } |
| 2640 | for _, tt := range tests { |
| 2641 | t.Run(tt.name, func(t *testing.T) { |
| 2642 | vs := &VoltService{ |
| 2643 | VoltServiceCfg: VoltServiceCfg{ |
| 2644 | SVlan: of.VlanAny, |
| 2645 | UniVlan: of.VlanAny, |
| 2646 | VlanControl: ONUCVlanOLTSVlan, |
| 2647 | }, |
| 2648 | } |
| 2649 | switch tt.name { |
| 2650 | case "VlanControl: ONUCVlanOLTSVlan": |
| 2651 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2652 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2653 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2654 | } |
| 2655 | case "VlanControl: OLTCVlanOLTSVlan": |
| 2656 | vs.VlanControl = OLTCVlanOLTSVlan |
| 2657 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2658 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2659 | } |
| 2660 | case "VlanControl: ONUCVlan": |
| 2661 | vs.VlanControl = ONUCVlan |
| 2662 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2663 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2664 | } |
| 2665 | case "VlanControl: OLTSVlan": |
| 2666 | vs.VlanControl = OLTSVlan |
| 2667 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2668 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2669 | } |
| 2670 | case "VlanControl: OLTSVlan vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone": |
| 2671 | vs.VlanControl = OLTSVlan |
| 2672 | vs.UniVlan = vs.CVlan |
| 2673 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2674 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2675 | } |
| 2676 | case "VlanControl: OLTSVlan vs.UniVlan == of.VlanNone": |
| 2677 | vs.VlanControl = OLTSVlan |
| 2678 | vs.UniVlan = of.VlanNone |
| 2679 | if err := vs.setUSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2680 | t.Errorf("VoltService.setDSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2681 | } |
| 2682 | case "VlanControl: default": |
| 2683 | vs.VlanControl = 6 |
| 2684 | err := vs.setUSMatchActionVlanT1(tt.args.flow) |
| 2685 | assert.NotNil(t, err) |
| 2686 | } |
| 2687 | }) |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | func TestVoltService_setUSMatchActionVlanT0(t *testing.T) { |
| 2692 | type args struct { |
| 2693 | flow *of.VoltSubFlow |
| 2694 | } |
| 2695 | tests := []struct { |
| 2696 | name string |
| 2697 | args args |
| 2698 | wantErr bool |
| 2699 | }{ |
| 2700 | { |
| 2701 | name: "vs.VlanControl: ONUCVlanOLTSVlan", |
| 2702 | args: args{ |
| 2703 | flow: &of.VoltSubFlow{ |
| 2704 | ErrorReason: "test_error_reason", |
| 2705 | Cookie: uint64(1), |
| 2706 | OldCookie: uint64(2), |
| 2707 | TableID: uint32(3), |
| 2708 | Priority: uint32(4), |
| 2709 | State: uint8(5), |
| 2710 | }, |
| 2711 | }, |
| 2712 | }, |
| 2713 | { |
| 2714 | name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone", |
| 2715 | args: args{ |
| 2716 | flow: &of.VoltSubFlow{ |
| 2717 | ErrorReason: "test_error_reason", |
| 2718 | Cookie: uint64(1), |
| 2719 | OldCookie: uint64(2), |
| 2720 | TableID: uint32(3), |
| 2721 | Priority: uint32(4), |
| 2722 | State: uint8(5), |
| 2723 | }, |
| 2724 | }, |
| 2725 | }, |
| 2726 | { |
| 2727 | name: "vs.VlanControl: OLTCVlanOLTSVlan", |
| 2728 | args: args{ |
| 2729 | flow: &of.VoltSubFlow{ |
| 2730 | ErrorReason: "test_error_reason", |
| 2731 | Cookie: uint64(1), |
| 2732 | OldCookie: uint64(2), |
| 2733 | TableID: uint32(3), |
| 2734 | Priority: uint32(4), |
| 2735 | State: uint8(5), |
| 2736 | }, |
| 2737 | }, |
| 2738 | }, |
| 2739 | { |
| 2740 | name: "vs.VlanControl: ONUCVlan", |
| 2741 | args: args{ |
| 2742 | flow: &of.VoltSubFlow{ |
| 2743 | ErrorReason: "test_error_reason", |
| 2744 | Cookie: uint64(1), |
| 2745 | OldCookie: uint64(2), |
| 2746 | TableID: uint32(3), |
| 2747 | Priority: uint32(4), |
| 2748 | State: uint8(5), |
| 2749 | }, |
| 2750 | }, |
| 2751 | }, |
| 2752 | { |
| 2753 | name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone", |
| 2754 | args: args{ |
| 2755 | flow: &of.VoltSubFlow{ |
| 2756 | ErrorReason: "test_error_reason", |
| 2757 | Cookie: uint64(1), |
| 2758 | OldCookie: uint64(2), |
| 2759 | TableID: uint32(3), |
| 2760 | Priority: uint32(4), |
| 2761 | State: uint8(5), |
| 2762 | }, |
| 2763 | }, |
| 2764 | }, |
| 2765 | { |
| 2766 | name: "vs.VlanControl: OLTSVlan", |
| 2767 | args: args{ |
| 2768 | flow: &of.VoltSubFlow{ |
| 2769 | ErrorReason: "test_error_reason", |
| 2770 | Cookie: uint64(1), |
| 2771 | OldCookie: uint64(2), |
| 2772 | TableID: uint32(3), |
| 2773 | Priority: uint32(4), |
| 2774 | State: uint8(5), |
| 2775 | }, |
| 2776 | }, |
| 2777 | }, |
| 2778 | } |
| 2779 | for _, tt := range tests { |
| 2780 | t.Run(tt.name, func(t *testing.T) { |
| 2781 | vs := &VoltService{} |
| 2782 | switch tt.name { |
| 2783 | case "vs.VlanControl: ONUCVlanOLTSVlan": |
| 2784 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2785 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2786 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2787 | } |
| 2788 | case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone": |
| 2789 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2790 | vs.UniVlan = of.VlanNone |
| 2791 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2792 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2793 | } |
| 2794 | case "vs.VlanControl: OLTCVlanOLTSVlan": |
| 2795 | vs.VlanControl = OLTCVlanOLTSVlan |
| 2796 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2797 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2798 | } |
| 2799 | case "vs.VlanControl: ONUCVlan": |
| 2800 | vs.VlanControl = ONUCVlan |
| 2801 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2802 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2803 | } |
| 2804 | case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone": |
| 2805 | vs.VlanControl = ONUCVlan |
| 2806 | vs.UniVlan = of.VlanNone |
| 2807 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2808 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2809 | } |
| 2810 | case "vs.VlanControl: OLTSVlan": |
| 2811 | vs.VlanControl = OLTSVlan |
| 2812 | if err := vs.setUSMatchActionVlanT0(tt.args.flow); (err != nil) != tt.wantErr { |
| 2813 | t.Errorf("VoltService.setUSMatchActionVlanT0() error = %v, wantErr %v", err, tt.wantErr) |
| 2814 | } |
| 2815 | } |
| 2816 | }) |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | func TestVoltService_setDSMatchActionVlanT1(t *testing.T) { |
| 2821 | type args struct { |
| 2822 | flow *of.VoltSubFlow |
| 2823 | } |
| 2824 | tests := []struct { |
| 2825 | name string |
| 2826 | args args |
| 2827 | wantErr bool |
| 2828 | }{ |
| 2829 | { |
| 2830 | name: "vs.VlanControl: ONUCVlanOLTSVlan", |
| 2831 | args: args{ |
| 2832 | flow: &of.VoltSubFlow{ |
| 2833 | ErrorReason: "test_error_reason", |
| 2834 | Cookie: uint64(1), |
| 2835 | OldCookie: uint64(2), |
| 2836 | TableID: uint32(3), |
| 2837 | Priority: uint32(4), |
| 2838 | State: uint8(5), |
| 2839 | }, |
| 2840 | }, |
| 2841 | }, |
| 2842 | { |
| 2843 | name: "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone", |
| 2844 | args: args{ |
| 2845 | flow: &of.VoltSubFlow{ |
| 2846 | ErrorReason: "test_error_reason", |
| 2847 | Cookie: uint64(1), |
| 2848 | OldCookie: uint64(2), |
| 2849 | TableID: uint32(3), |
| 2850 | Priority: uint32(4), |
| 2851 | State: uint8(5), |
| 2852 | }, |
| 2853 | }, |
| 2854 | }, |
| 2855 | { |
| 2856 | name: "vs.VlanControl: OLTCVlanOLTSVlan", |
| 2857 | args: args{ |
| 2858 | flow: &of.VoltSubFlow{ |
| 2859 | ErrorReason: "test_error_reason", |
| 2860 | Cookie: uint64(1), |
| 2861 | OldCookie: uint64(2), |
| 2862 | TableID: uint32(3), |
| 2863 | Priority: uint32(4), |
| 2864 | State: uint8(5), |
| 2865 | }, |
| 2866 | }, |
| 2867 | }, |
| 2868 | { |
| 2869 | name: "vs.VlanControl: ONUCVlan", |
| 2870 | args: args{ |
| 2871 | flow: &of.VoltSubFlow{ |
| 2872 | ErrorReason: "test_error_reason", |
| 2873 | Cookie: uint64(1), |
| 2874 | OldCookie: uint64(2), |
| 2875 | TableID: uint32(3), |
| 2876 | Priority: uint32(4), |
| 2877 | State: uint8(5), |
| 2878 | }, |
| 2879 | }, |
| 2880 | }, |
| 2881 | { |
| 2882 | name: "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone", |
| 2883 | args: args{ |
| 2884 | flow: &of.VoltSubFlow{ |
| 2885 | ErrorReason: "test_error_reason", |
| 2886 | Cookie: uint64(1), |
| 2887 | OldCookie: uint64(2), |
| 2888 | TableID: uint32(3), |
| 2889 | Priority: uint32(4), |
| 2890 | State: uint8(5), |
| 2891 | }, |
| 2892 | }, |
| 2893 | }, |
| 2894 | { |
| 2895 | name: "vs.VlanControl: OLTSVlan", |
| 2896 | args: args{ |
| 2897 | flow: &of.VoltSubFlow{ |
| 2898 | ErrorReason: "test_error_reason", |
| 2899 | Cookie: uint64(1), |
| 2900 | OldCookie: uint64(2), |
| 2901 | TableID: uint32(3), |
| 2902 | Priority: uint32(4), |
| 2903 | State: uint8(5), |
| 2904 | }, |
| 2905 | }, |
| 2906 | }, |
| 2907 | { |
| 2908 | name: "vs.VlanControl: default", |
| 2909 | args: args{ |
| 2910 | flow: &of.VoltSubFlow{ |
| 2911 | ErrorReason: "test_error_reason", |
| 2912 | Cookie: uint64(1), |
| 2913 | OldCookie: uint64(2), |
| 2914 | TableID: uint32(3), |
| 2915 | Priority: uint32(4), |
| 2916 | State: uint8(5), |
| 2917 | }, |
| 2918 | }, |
| 2919 | }, |
| 2920 | } |
| 2921 | for _, tt := range tests { |
| 2922 | t.Run(tt.name, func(t *testing.T) { |
| 2923 | vs := &VoltService{} |
| 2924 | switch tt.name { |
| 2925 | case "vs.VlanControl: ONUCVlanOLTSVlan": |
| 2926 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2927 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2928 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2929 | } |
| 2930 | case "vs.VlanControl: ONUCVlanOLTSVlan vs.UniVlan == of.VlanNone": |
| 2931 | vs.VlanControl = ONUCVlanOLTSVlan |
| 2932 | vs.UniVlan = of.VlanNone |
| 2933 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2934 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2935 | } |
| 2936 | case "vs.VlanControl: OLTCVlanOLTSVlan": |
| 2937 | vs.VlanControl = OLTCVlanOLTSVlan |
| 2938 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2939 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2940 | } |
| 2941 | case "vs.VlanControl: ONUCVlan": |
| 2942 | vs.VlanControl = ONUCVlan |
| 2943 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2944 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2945 | } |
| 2946 | case "vs.VlanControl: ONUCVlan vs.UniVlan == of.VlanNone": |
| 2947 | vs.VlanControl = ONUCVlan |
| 2948 | vs.UniVlan = of.VlanNone |
| 2949 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2950 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2951 | } |
| 2952 | case "vs.VlanControl: OLTSVlan": |
| 2953 | vs.VlanControl = OLTSVlan |
| 2954 | if err := vs.setDSMatchActionVlanT1(tt.args.flow); (err != nil) != tt.wantErr { |
| 2955 | t.Errorf("VoltService.setDSMatchActionVlanT1() error = %v, wantErr %v", err, tt.wantErr) |
| 2956 | } |
| 2957 | case "vs.VlanControl: default": |
| 2958 | vs.VlanControl = 6 |
| 2959 | err := vs.setDSMatchActionVlanT1(tt.args.flow) |
| 2960 | assert.NotNil(t, err) |
| 2961 | } |
| 2962 | }) |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | func TestVoltService_SetIpv6Addr(t *testing.T) { |
| 2967 | type args struct { |
| 2968 | addr net.IP |
| 2969 | } |
| 2970 | tests := []struct { |
| 2971 | name string |
| 2972 | args args |
| 2973 | }{ |
| 2974 | { |
| 2975 | name: "SetIpv6Addr", |
| 2976 | args: args{ |
| 2977 | addr: AllSystemsMulticastGroupIP, |
| 2978 | }, |
| 2979 | }, |
| 2980 | } |
| 2981 | for _, tt := range tests { |
| 2982 | t.Run(tt.name, func(t *testing.T) { |
| 2983 | vs := &VoltService{} |
| 2984 | vs.SetIpv6Addr(tt.args.addr) |
| 2985 | }) |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | func TestVoltService_SetIpv4Addr(t *testing.T) { |
| 2990 | type args struct { |
| 2991 | addr net.IP |
| 2992 | } |
| 2993 | tests := []struct { |
| 2994 | name string |
| 2995 | args args |
| 2996 | }{ |
| 2997 | { |
| 2998 | name: "VoltService_SetIpv4Addr", |
| 2999 | args: args{ |
| 3000 | addr: AllSystemsMulticastGroupIP, |
| 3001 | }, |
| 3002 | }, |
| 3003 | } |
| 3004 | for _, tt := range tests { |
| 3005 | t.Run(tt.name, func(t *testing.T) { |
| 3006 | vs := &VoltService{} |
| 3007 | vs.SetIpv4Addr(tt.args.addr) |
| 3008 | }) |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | func TestVoltService_SetMacAddr(t *testing.T) { |
| 3013 | type args struct { |
| 3014 | addr net.HardwareAddr |
| 3015 | } |
| 3016 | tests := []struct { |
| 3017 | name string |
| 3018 | args args |
| 3019 | }{ |
| 3020 | { |
| 3021 | name: "VoltService_SetMacAddr", |
| 3022 | args: args{ |
| 3023 | addr: BroadcastMAC, |
| 3024 | }, |
| 3025 | }, |
| 3026 | } |
| 3027 | for _, tt := range tests { |
| 3028 | t.Run(tt.name, func(t *testing.T) { |
| 3029 | vs := &VoltService{} |
| 3030 | vs.SetMacAddr(tt.args.addr) |
| 3031 | }) |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | func TestVoltService_GetCircuitID(t *testing.T) { |
| 3036 | tests := []struct { |
| 3037 | name string |
| 3038 | want []byte |
| 3039 | }{ |
| 3040 | { |
| 3041 | name: "VoltService_GetCircuitID", |
| 3042 | }, |
| 3043 | } |
| 3044 | for _, tt := range tests { |
| 3045 | t.Run(tt.name, func(t *testing.T) { |
| 3046 | vs := &VoltService{} |
| 3047 | _ = vs.GetCircuitID() |
| 3048 | }) |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | func TestVoltService_GetRemoteID(t *testing.T) { |
| 3053 | tests := []struct { |
| 3054 | name string |
| 3055 | want []byte |
| 3056 | }{ |
| 3057 | { |
| 3058 | name: "VoltService_GetRemoteID", |
| 3059 | }, |
| 3060 | } |
| 3061 | for _, tt := range tests { |
| 3062 | t.Run(tt.name, func(t *testing.T) { |
| 3063 | vs := &VoltService{} |
| 3064 | _ = vs.GetRemoteID() |
| 3065 | }) |
| 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | func TestVoltService_IPAssigned(t *testing.T) { |
| 3070 | tests := []struct { |
| 3071 | name string |
| 3072 | want bool |
| 3073 | }{ |
| 3074 | { |
| 3075 | name: "VoltService_IPAssigned", |
| 3076 | }, |
| 3077 | } |
| 3078 | for _, tt := range tests { |
| 3079 | t.Run(tt.name, func(t *testing.T) { |
| 3080 | vs := &VoltService{} |
| 3081 | _ = vs.IPAssigned() |
| 3082 | }) |
| 3083 | } |
| 3084 | } |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 3085 | |
| 3086 | func TestVoltApplication_GetFlowProvisionStatus(t *testing.T) { |
| 3087 | type args struct { |
| 3088 | portNo string |
| 3089 | } |
| 3090 | voltServ := &VoltService{ |
| 3091 | VoltServiceCfg: VoltServiceCfg{ |
| 3092 | Port: "SDX6320031-1", |
| 3093 | IsActivated: true, |
| 3094 | }, |
| 3095 | VoltServiceOper: VoltServiceOper{ |
| 3096 | Device: "SDX6320031", |
| 3097 | DsHSIAFlowsApplied: true, |
| 3098 | UsHSIAFlowsApplied: true, |
| 3099 | }, |
| 3100 | } |
| 3101 | tests := []struct { |
| 3102 | name string |
| 3103 | args args |
| 3104 | want FlowProvisionStatus |
| 3105 | }{ |
| 3106 | { |
| 3107 | name: "ALL_FLOWS_PROVISIONED", |
| 3108 | args: args{ |
| 3109 | portNo: "SDX6320031-1", |
| 3110 | }, |
| 3111 | want: FlowProvisionStatus{ |
| 3112 | FlowProvisionStatus: "ALL_FLOWS_PROVISIONED", |
| 3113 | }, |
| 3114 | }, |
| 3115 | { |
| 3116 | name: "SUBSCRIBER_DISABLED_IN_CONTROLLER", |
| 3117 | args: args{ |
| 3118 | portNo: "SDX6320031-1", |
| 3119 | }, |
| 3120 | want: FlowProvisionStatus{ |
| 3121 | FlowProvisionStatus: "DISABLED_IN_CONTROLLER", |
| 3122 | }, |
| 3123 | }, |
| 3124 | { |
| 3125 | name: "FLOWS_PROVISIONED_PARTIALLY", |
| 3126 | args: args{ |
| 3127 | portNo: "SDX6320031-1", |
| 3128 | }, |
| 3129 | want: FlowProvisionStatus{ |
| 3130 | FlowProvisionStatus: "FLOWS_PROVISIONED_PARTIALLY", |
| 3131 | }, |
| 3132 | }, |
| 3133 | { |
| 3134 | name: "NO_FLOWS_PROVISIONED", |
| 3135 | args: args{ |
| 3136 | portNo: "SDX6320031-1", |
| 3137 | }, |
| 3138 | want: FlowProvisionStatus{ |
| 3139 | FlowProvisionStatus: "NO_FLOWS_PROVISIONED", |
| 3140 | }, |
| 3141 | }, |
| 3142 | } |
| 3143 | for _, tt := range tests { |
| 3144 | t.Run(tt.name, func(t *testing.T) { |
| 3145 | va := &VoltApplication{} |
| 3146 | switch tt.name { |
| 3147 | case "ALL_FLOWS_PROVISIONED": |
| 3148 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 3149 | if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) { |
| 3150 | t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want) |
| 3151 | } |
| 3152 | case "SUBSCRIBER_DISABLED_IN_CONTROLLER": |
| 3153 | voltServ1 := &VoltService{ |
| 3154 | VoltServiceCfg: VoltServiceCfg{ |
| 3155 | Port: "SDX6320031-1", |
| 3156 | IsActivated: false, |
| 3157 | }, |
| 3158 | } |
| 3159 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ1) |
| 3160 | if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) { |
| 3161 | t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want) |
| 3162 | } |
| 3163 | case "FLOWS_PROVISIONED_PARTIALLY": |
| 3164 | pendingFlows := map[string]bool{} |
| 3165 | pendingFlows["test"] = true |
| 3166 | voltServ.PendingFlows = pendingFlows |
| 3167 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 3168 | if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) { |
| 3169 | t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want) |
| 3170 | } |
| 3171 | case "NO_FLOWS_PROVISIONED": |
| 3172 | voltServ.UsHSIAFlowsApplied = false |
| 3173 | voltServ.DsHSIAFlowsApplied = false |
| 3174 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 3175 | if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) { |
| 3176 | t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want) |
| 3177 | } |
| 3178 | } |
| 3179 | }) |
| 3180 | } |
| 3181 | } |