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