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 | "net" |
| 22 | "reflect" |
| 23 | "sync" |
| 24 | "testing" |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 25 | "time" |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 26 | "voltha-go-controller/internal/pkg/controller" |
| 27 | "voltha-go-controller/internal/pkg/intf" |
| 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/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 34 | "github.com/stretchr/testify/assert" |
| 35 | "go.uber.org/atomic" |
| 36 | ) |
| 37 | |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 38 | var test_data = "1234" |
| 39 | |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 40 | func TestVoltApplication_RestoreNbDeviceFromDb(t *testing.T) { |
| 41 | type args struct { |
| 42 | cntx context.Context |
| 43 | deviceID string |
| 44 | } |
| 45 | tests := []struct { |
| 46 | name string |
| 47 | args args |
| 48 | }{ |
| 49 | { |
| 50 | name: "VoltApplication_RestoreNbDeviceFromDb", |
| 51 | args: args{ |
| 52 | cntx: context.Background(), |
| 53 | deviceID: "test_device_id", |
| 54 | }, |
| 55 | }, |
| 56 | { |
| 57 | name: "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type", |
| 58 | args: args{ |
| 59 | cntx: context.Background(), |
| 60 | deviceID: "test_device_id1", |
| 61 | }, |
| 62 | }, |
| 63 | { |
| 64 | name: "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error", |
| 65 | args: args{ |
| 66 | cntx: context.Background(), |
| 67 | deviceID: "test_device_id1", |
| 68 | }, |
| 69 | }, |
| 70 | } |
| 71 | for _, tt := range tests { |
| 72 | t.Run(tt.name, func(t *testing.T) { |
| 73 | va := &VoltApplication{ |
| 74 | NbDevice: sync.Map{}, |
| 75 | } |
| 76 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 77 | db = dbintf |
| 78 | switch tt.name { |
| 79 | case "VoltApplication_RestoreNbDeviceFromDb": |
| 80 | var port PonPortCfg |
| 81 | port = PonPortCfg{ |
| 82 | PortAlarmProfileID: "test", |
| 83 | PortID: 256, |
| 84 | MaxActiveChannels: 256, |
| 85 | ActiveIGMPChannels: 7679, |
| 86 | EnableMulticastKPI: false, |
| 87 | } |
| 88 | b, err := json.Marshal(port) |
| 89 | if err != nil { |
| 90 | panic(err) |
| 91 | } |
| 92 | test := map[string]*kvstore.KVPair{} |
| 93 | test["test_device_id"] = &kvstore.KVPair{ |
| 94 | Key: "test_device_id", |
| 95 | Value: b, |
| 96 | } |
| 97 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 98 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 99 | assert.NotNil(t, got) |
| 100 | case "VoltApplication_RestoreNbDeviceFromDb_invalid_Value_type": |
| 101 | test := map[string]*kvstore.KVPair{} |
| 102 | test["test_device_id"] = &kvstore.KVPair{ |
| 103 | Key: "test_device_id", |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 104 | Value: invalid_value, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 105 | } |
| 106 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 107 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 108 | assert.NotNil(t, got) |
| 109 | case "VoltApplication_RestoreNbDeviceFromDb_unmarshal_error": |
| 110 | b, err := json.Marshal("error") |
| 111 | if err != nil { |
| 112 | panic(err) |
| 113 | } |
| 114 | test := map[string]*kvstore.KVPair{} |
| 115 | test["test_device_id"] = &kvstore.KVPair{ |
| 116 | Key: "test_device_id", |
| 117 | Value: b, |
| 118 | } |
| 119 | dbintf.EXPECT().GetAllNbPorts(gomock.Any(), gomock.Any()).Return(test, nil).Times(1) |
| 120 | got := va.RestoreNbDeviceFromDb(tt.args.cntx, tt.args.deviceID) |
| 121 | assert.NotNil(t, got) |
| 122 | } |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func TestVoltApplication_UpdateDeviceConfig(t *testing.T) { |
| 128 | type args struct { |
| 129 | cntx context.Context |
| 130 | deviceConfig *DeviceConfig |
| 131 | } |
| 132 | |
| 133 | dvcConfg := &DeviceConfig{ |
| 134 | SerialNumber: "SDX6320031", |
| 135 | HardwareIdentifier: "0.0.0.0", |
| 136 | IPAddress: "127.26.1.74", |
| 137 | UplinkPort: "43322", |
| 138 | NasID: "12345", |
| 139 | NniDhcpTrapVid: 123, |
| 140 | } |
| 141 | |
| 142 | voltDev := &VoltDevice{ |
| 143 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 144 | SerialNum: "SDX6320031", |
| 145 | NniDhcpTrapVid: 123, |
| 146 | } |
| 147 | tests := []struct { |
| 148 | name string |
| 149 | args args |
| 150 | }{ |
| 151 | { |
| 152 | name: "SDX6320031", |
| 153 | args: args{ |
| 154 | cntx: context.Background(), |
| 155 | deviceConfig: dvcConfg, |
| 156 | }, |
| 157 | }, |
| 158 | } |
| 159 | |
| 160 | for _, tt := range tests { |
| 161 | t.Run(tt.name, func(t *testing.T) { |
| 162 | va := &VoltApplication{ |
| 163 | DevicesDisc: sync.Map{}, |
| 164 | DevicesConfig: sync.Map{}, |
| 165 | } |
| 166 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 167 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 168 | db = dbintf |
| 169 | dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 170 | |
| 171 | va.UpdateDeviceConfig(tt.args.cntx, tt.args.deviceConfig) |
| 172 | }) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | func TestVoltApplication_RestoreOltFlowService(t *testing.T) { |
| 177 | type fields struct { |
| 178 | OltFlowServiceConfig OltFlowService |
| 179 | } |
| 180 | type args struct { |
| 181 | cntx context.Context |
| 182 | } |
| 183 | tests := []struct { |
| 184 | name string |
| 185 | fields fields |
| 186 | args args |
| 187 | }{ |
| 188 | { |
| 189 | name: "OltFlowService", |
| 190 | args: args{ |
| 191 | cntx: context.Background(), |
| 192 | }, |
| 193 | fields: fields{ |
| 194 | OltFlowServiceConfig: OltFlowService{ |
| 195 | DefaultTechProfileID: 1233, |
| 196 | EnableDhcpOnNni: true, |
| 197 | EnableIgmpOnNni: false, |
| 198 | RemoveFlowsOnDisable: false, |
| 199 | }, |
| 200 | }, |
| 201 | }, |
| 202 | } |
| 203 | for _, tt := range tests { |
| 204 | t.Run(tt.name, func(t *testing.T) { |
| 205 | va := &VoltApplication{ |
| 206 | OltFlowServiceConfig: tt.fields.OltFlowServiceConfig, |
| 207 | } |
| 208 | |
| 209 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 210 | db = dbintf |
| 211 | dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes() |
| 212 | |
| 213 | va.RestoreOltFlowService(tt.args.cntx) |
| 214 | }) |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | func TestVoltApplication_UpdateOltFlowService(t *testing.T) { |
| 219 | type fields struct { |
| 220 | OltFlowServiceConfig OltFlowService |
| 221 | } |
| 222 | type args struct { |
| 223 | cntx context.Context |
| 224 | oltFlowService OltFlowService |
| 225 | } |
| 226 | tests := []struct { |
| 227 | name string |
| 228 | fields fields |
| 229 | args args |
| 230 | }{ |
| 231 | { |
| 232 | name: "OltFlowService", |
| 233 | args: args{ |
| 234 | cntx: context.Background(), |
| 235 | oltFlowService: OltFlowService{ |
| 236 | DefaultTechProfileID: 1233, |
| 237 | EnableDhcpOnNni: true, |
| 238 | EnableIgmpOnNni: false, |
| 239 | RemoveFlowsOnDisable: false, |
| 240 | }, |
| 241 | }, |
| 242 | fields: fields{ |
| 243 | OltFlowServiceConfig: OltFlowService{ |
| 244 | DefaultTechProfileID: 1233, |
| 245 | EnableDhcpOnNni: true, |
| 246 | EnableIgmpOnNni: false, |
| 247 | RemoveFlowsOnDisable: false, |
| 248 | }, |
| 249 | }, |
| 250 | }, |
| 251 | } |
| 252 | for _, tt := range tests { |
| 253 | t.Run(tt.name, func(t *testing.T) { |
| 254 | va := &VoltApplication{ |
| 255 | OltFlowServiceConfig: tt.fields.OltFlowServiceConfig, |
| 256 | } |
| 257 | |
| 258 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 259 | db = dbintf |
| 260 | dbintf.EXPECT().PutOltFlowService(gomock.Any(), gomock.Any()).AnyTimes() |
| 261 | va.UpdateOltFlowService(tt.args.cntx, tt.args.oltFlowService) |
| 262 | }) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | func TestVoltApplication_TriggerPendingVpvDeleteReq(t *testing.T) { |
| 267 | type args struct { |
| 268 | cntx context.Context |
| 269 | device string |
| 270 | } |
| 271 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 272 | test := map[*VoltPortVnet]bool{} |
| 273 | test[&VoltPortVnet{Device: "SDX6320031", Port: "16777472", MacAddr: macAdd}] = true |
| 274 | tests := []struct { |
| 275 | name string |
| 276 | args args |
| 277 | }{ |
| 278 | { |
| 279 | name: "SDX6320031", |
| 280 | args: args{ |
| 281 | cntx: context.Background(), |
| 282 | device: "SDX6320031", |
| 283 | }, |
| 284 | }, |
| 285 | } |
| 286 | for _, tt := range tests { |
| 287 | t.Run(tt.name, func(t *testing.T) { |
| 288 | va := &VoltApplication{ |
| 289 | VoltPortVnetsToDelete: test, |
| 290 | } |
| 291 | va.TriggerPendingVpvDeleteReq(tt.args.cntx, tt.args.device) |
| 292 | }) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | func TestVoltApplication_TriggerPendingProfileDeleteReq(t *testing.T) { |
| 297 | type args struct { |
| 298 | cntx context.Context |
| 299 | device string |
| 300 | } |
| 301 | tests := []struct { |
| 302 | name string |
| 303 | args args |
| 304 | }{ |
| 305 | { |
| 306 | name: "SDX6320031", |
| 307 | args: args{ |
| 308 | cntx: context.Background(), |
| 309 | device: "SDX6320031", |
| 310 | }, |
| 311 | }, |
| 312 | } |
| 313 | for _, tt := range tests { |
| 314 | t.Run(tt.name, func(t *testing.T) { |
| 315 | va := &VoltApplication{ |
| 316 | DevicesDisc: sync.Map{}, |
| 317 | } |
| 318 | va.TriggerPendingProfileDeleteReq(tt.args.cntx, tt.args.device) |
| 319 | }) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func TestVoltApplication_TriggerPendingServiceDeleteReq(t *testing.T) { |
| 324 | type args struct { |
| 325 | cntx context.Context |
| 326 | device string |
| 327 | } |
| 328 | voltServ := &VoltService{ |
| 329 | VoltServiceOper: VoltServiceOper{ |
| 330 | Device: "SDX6320031", |
| 331 | ForceDelete: true, |
| 332 | }, |
| 333 | } |
| 334 | |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 335 | tests := []struct { |
| 336 | name string |
| 337 | args args |
| 338 | }{ |
| 339 | { |
| 340 | name: "Positive_Case_TriggerPendingServiceDeleteReq", |
| 341 | args: args{ |
| 342 | cntx: context.Background(), |
| 343 | device: "SDX6320031", |
| 344 | }, |
| 345 | }, |
| 346 | } |
| 347 | for _, tt := range tests { |
| 348 | t.Run(tt.name, func(t *testing.T) { |
| 349 | va := &VoltApplication{ |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 350 | ServicesToDelete: sync.Map{}, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 351 | ServiceByName: sync.Map{}, |
| 352 | DevicesDisc: sync.Map{}, |
| 353 | } |
| 354 | |
| 355 | va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 356 | va.ServicesToDelete.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", true) |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 357 | |
| 358 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 359 | db = dbintf |
| 360 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 361 | dbintf.EXPECT().DelService(gomock.Any(), gomock.Any()).AnyTimes() |
| 362 | va.TriggerPendingServiceDeleteReq(tt.args.cntx, tt.args.device) |
| 363 | }) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func TestVoltApplication_TriggerPendingVnetDeleteReq(t *testing.T) { |
| 368 | type args struct { |
| 369 | cntx context.Context |
| 370 | device string |
| 371 | } |
| 372 | |
| 373 | vnetToDel := map[string]bool{} |
| 374 | vnetToDel["2310-4096-4096"] = true |
| 375 | |
| 376 | voltVnet := &VoltVnet{ |
| 377 | Version: "v3", |
| 378 | VnetConfig: VnetConfig{ |
| 379 | Name: "2310-4096-4096", |
| 380 | VnetType: "Encapsulation", |
| 381 | SVlan: 2310, |
| 382 | CVlan: 4096, |
| 383 | UniVlan: 4096, |
| 384 | SVlanTpid: 33024, |
| 385 | }, |
| 386 | VnetOper: VnetOper{ |
| 387 | PendingDeviceToDelete: "SDX63200313", |
| 388 | }, |
| 389 | } |
| 390 | voltDev := &VoltDevice{ |
| 391 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 392 | SerialNum: "SDX6320031", |
| 393 | NniDhcpTrapVid: 123, |
| 394 | } |
| 395 | |
| 396 | tests := []struct { |
| 397 | name string |
| 398 | args args |
| 399 | }{ |
| 400 | { |
| 401 | name: "Negative_Case_TriggerPendingVnetDeleteReq", |
| 402 | args: args{ |
| 403 | cntx: context.Background(), |
| 404 | device: "SDX6320031", |
| 405 | }, |
| 406 | }, |
| 407 | } |
| 408 | for _, tt := range tests { |
| 409 | t.Run(tt.name, func(t *testing.T) { |
| 410 | va := &VoltApplication{ |
| 411 | VnetsToDelete: vnetToDel, |
| 412 | DevicesDisc: sync.Map{}, |
| 413 | } |
| 414 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 415 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 416 | va.TriggerPendingVnetDeleteReq(tt.args.cntx, tt.args.device) |
| 417 | }) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | func TestVoltApplication_UpdateMacInPortMap(t *testing.T) { |
| 422 | type args struct { |
| 423 | macAddr net.HardwareAddr |
| 424 | port string |
| 425 | } |
| 426 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 427 | macPort := map[string]string{} |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 428 | macPort[macAdd.String()] = test_data |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 429 | tests := []struct { |
| 430 | name string |
| 431 | args args |
| 432 | }{ |
| 433 | { |
| 434 | name: "Positive_Case_UpdateMacInPortMap", |
| 435 | args: args{ |
| 436 | macAddr: macAdd, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 437 | port: test_data, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 438 | }, |
| 439 | }, |
| 440 | } |
| 441 | for _, tt := range tests { |
| 442 | t.Run(tt.name, func(t *testing.T) { |
| 443 | va := &VoltApplication{ |
| 444 | macPortMap: macPort, |
| 445 | } |
| 446 | va.UpdateMacInPortMap(tt.args.macAddr, tt.args.port) |
| 447 | }) |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | func TestVoltApplication_GetMacInPortMap(t *testing.T) { |
| 452 | type args struct { |
| 453 | macAddr net.HardwareAddr |
| 454 | } |
| 455 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 456 | macPort := map[string]string{} |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 457 | macPort[macAdd.String()] = test_data |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 458 | tests := []struct { |
| 459 | name string |
| 460 | args args |
| 461 | want string |
| 462 | }{ |
| 463 | { |
| 464 | name: "Positive_Case_GetMacInPortMap", |
| 465 | args: args{ |
| 466 | macAddr: macAdd, |
| 467 | }, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 468 | want: test_data, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 469 | }, |
| 470 | } |
| 471 | for _, tt := range tests { |
| 472 | t.Run(tt.name, func(t *testing.T) { |
| 473 | va := &VoltApplication{ |
| 474 | macPortMap: macPort, |
| 475 | } |
| 476 | if got := va.GetMacInPortMap(tt.args.macAddr); got != tt.want { |
| 477 | t.Errorf("VoltApplication.GetMacInPortMap() = %v, want %v", got, tt.want) |
| 478 | } |
| 479 | }) |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | func Test_pushFlowFailureNotif(t *testing.T) { |
| 484 | type args struct { |
| 485 | flowStatus intf.FlowStatus |
| 486 | } |
| 487 | tests := []struct { |
| 488 | name string |
| 489 | args args |
| 490 | }{ |
| 491 | { |
| 492 | name: "Positive_Case_pushFlowFailureNotif", |
| 493 | args: args{ |
| 494 | flowStatus: intf.FlowStatus{ |
| 495 | Device: "SDX6320031", |
| 496 | Cookie: "68786618880", |
| 497 | Status: 0, |
| 498 | Flow: &of.VoltSubFlow{ |
| 499 | Cookie: 68786618880, |
| 500 | TableID: 0, |
| 501 | Priority: 100, |
| 502 | ErrorReason: "", |
| 503 | OldCookie: 0, |
| 504 | }, |
| 505 | }, |
| 506 | }, |
| 507 | }, |
| 508 | } |
| 509 | for _, tt := range tests { |
| 510 | t.Run(tt.name, func(t *testing.T) { |
| 511 | pushFlowFailureNotif(tt.args.flowStatus) |
| 512 | }) |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | func TestGetPonPortIDFromUNIPort(t *testing.T) { |
| 517 | type args struct { |
| 518 | uniPortID uint32 |
| 519 | } |
| 520 | tests := []struct { |
| 521 | name string |
| 522 | args args |
| 523 | want uint32 |
| 524 | }{ |
| 525 | { |
| 526 | name: "Positive_Case_pushFlowFailureNotif", |
| 527 | args: args{ |
| 528 | uniPortID: 1049600, |
| 529 | }, |
| 530 | want: 1, |
| 531 | }, |
| 532 | } |
| 533 | for _, tt := range tests { |
| 534 | t.Run(tt.name, func(t *testing.T) { |
| 535 | if got := GetPonPortIDFromUNIPort(tt.args.uniPortID); got != tt.want { |
| 536 | t.Errorf("GetPonPortIDFromUNIPort() = %v, want %v", got, tt.want) |
| 537 | } |
| 538 | }) |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | func TestVoltApplication_ProcessFlowModResultIndication(t *testing.T) { |
| 543 | type args struct { |
| 544 | cntx context.Context |
| 545 | flowStatus intf.FlowStatus |
| 546 | } |
| 547 | voltDev := &VoltDevice{ |
| 548 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 549 | SerialNum: "SDX6320031", |
| 550 | NniDhcpTrapVid: 123, |
| 551 | FlowAddEventMap: util.NewConcurrentMap(), |
| 552 | } |
| 553 | flowState := intf.FlowStatus{ |
| 554 | Device: "SDX6320031", |
| 555 | Cookie: "68786618880", |
| 556 | Status: 1005, |
| 557 | FlowModType: 0, |
| 558 | Flow: &of.VoltSubFlow{ |
| 559 | Cookie: 68786618880, |
| 560 | OldCookie: 0, |
| 561 | TableID: 0, |
| 562 | State: 0, |
| 563 | Priority: 100, |
| 564 | }, |
| 565 | } |
| 566 | flowAddEvent := map[string]*FlowEvent{} |
| 567 | flowEvent := &FlowEvent{ |
| 568 | device: "SDX6320031", |
| 569 | cookie: "68786618880", |
| 570 | eType: EventTypeControlFlowAdded, |
| 571 | } |
| 572 | flowAddEvent["68786618880"] = flowEvent |
| 573 | voltDev.FlowAddEventMap.Set("6878661888", flowEvent) |
| 574 | tests := []struct { |
| 575 | name string |
| 576 | args args |
| 577 | }{ |
| 578 | { |
| 579 | name: "Positive_Case_ProcessFlowModResultIndication", |
| 580 | args: args{ |
| 581 | cntx: context.Background(), |
| 582 | flowStatus: flowState, |
| 583 | }, |
| 584 | }, |
| 585 | { |
| 586 | name: "Negetive_Case_ProcessFlowModResultIndication", |
| 587 | args: args{ |
| 588 | cntx: context.Background(), |
| 589 | flowStatus: flowState, |
| 590 | }, |
| 591 | }, |
| 592 | } |
| 593 | for _, tt := range tests { |
| 594 | t.Run(tt.name, func(t *testing.T) { |
| 595 | va := &VoltApplication{ |
| 596 | DevicesDisc: sync.Map{}, |
| 597 | } |
| 598 | switch tt.name { |
| 599 | case "Positive_Case_ProcessFlowModResultIndication": |
| 600 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 601 | va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus) |
| 602 | case "Negetive_Case_ProcessFlowModResultIndication": |
| 603 | va.ProcessFlowModResultIndication(tt.args.cntx, tt.args.flowStatus) |
| 604 | } |
| 605 | }) |
| 606 | } |
| 607 | } |
| 608 | func Test_getPendingPoolKey(t *testing.T) { |
| 609 | type args struct { |
| 610 | mvlan of.VlanType |
| 611 | device string |
| 612 | } |
| 613 | |
| 614 | tests := []struct { |
| 615 | name string |
| 616 | args args |
| 617 | want string |
| 618 | }{ |
| 619 | { |
| 620 | name: "Positive_Case_getPendingPoolKey", |
| 621 | args: args{ |
| 622 | mvlan: of.VlanAny, |
| 623 | device: "SDX6320031", |
| 624 | }, |
| 625 | want: "4096_SDX6320031", |
| 626 | }, |
| 627 | } |
| 628 | for _, tt := range tests { |
| 629 | t.Run(tt.name, func(t *testing.T) { |
| 630 | if got := getPendingPoolKey(tt.args.mvlan, tt.args.device); got != tt.want { |
| 631 | t.Errorf("getPendingPoolKey() = %v, want %v", got, tt.want) |
| 632 | } |
| 633 | }) |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | func TestNewVoltPort(t *testing.T) { |
| 638 | type args struct { |
| 639 | device string |
| 640 | name string |
| 641 | id uint32 |
| 642 | } |
| 643 | |
| 644 | voltPort := &VoltPort{ |
| 645 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 646 | Device: "SDX6320031", |
| 647 | ID: 16777472, |
| 648 | State: PortStateDown, |
| 649 | ChannelPerSubAlarmRaised: false, |
| 650 | Type: VoltPortTypeNni, |
| 651 | } |
| 652 | |
| 653 | voltPort1 := &VoltPort{ |
| 654 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 655 | Device: "SDX6320031", |
| 656 | ID: 1049600, |
| 657 | State: PortStateDown, |
| 658 | ChannelPerSubAlarmRaised: false, |
| 659 | PonPort: GetPonPortIDFromUNIPort(1049600), |
| 660 | } |
| 661 | tests := []struct { |
| 662 | name string |
| 663 | args args |
| 664 | want *VoltPort |
| 665 | }{ |
| 666 | { |
| 667 | name: "Positive_Case_TestNewVoltPort", |
| 668 | args: args{ |
| 669 | id: 16777472, |
| 670 | device: "SDX6320031", |
| 671 | name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 672 | }, |
| 673 | want: voltPort, |
| 674 | }, |
| 675 | { |
| 676 | name: "Positive_Case2_TestNewVoltPort", |
| 677 | args: args{ |
| 678 | id: 1049600, |
| 679 | device: "SDX6320031", |
| 680 | name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 681 | }, |
| 682 | want: voltPort1, |
| 683 | }, |
| 684 | } |
| 685 | for _, tt := range tests { |
| 686 | t.Run(tt.name, func(t *testing.T) { |
| 687 | switch tt.name { |
| 688 | case "Positive_Case_TestNewVoltPort": |
| 689 | if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) { |
| 690 | t.Errorf("NewVoltPort() = %v, want %v", got, tt.want) |
| 691 | } |
| 692 | case "Positive_Case2_TestNewVoltPort": |
| 693 | if got := NewVoltPort(tt.args.device, tt.args.name, tt.args.id); !reflect.DeepEqual(got, tt.want) { |
| 694 | t.Errorf("NewVoltPort() = %v, want %v", got, tt.want) |
| 695 | } |
| 696 | } |
| 697 | }) |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | func TestVoltPort_SetPortID(t *testing.T) { |
| 702 | type args struct { |
| 703 | id uint32 |
| 704 | } |
| 705 | tests := []struct { |
| 706 | name string |
| 707 | args args |
| 708 | }{ |
| 709 | { |
| 710 | name: "Positive_Case_TestNewVoltPort", |
| 711 | args: args{ |
| 712 | id: 16777472, |
| 713 | }, |
| 714 | }, |
| 715 | } |
| 716 | for _, tt := range tests { |
| 717 | t.Run(tt.name, func(t *testing.T) { |
| 718 | vp := &VoltPort{ |
| 719 | ID: 16777472, |
| 720 | Type: VoltPortTypeNni, |
| 721 | } |
| 722 | vp.SetPortID(tt.args.id) |
| 723 | }) |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | func TestNewVoltDevice(t *testing.T) { |
| 728 | type args struct { |
| 729 | name string |
| 730 | slno string |
| 731 | southBoundID string |
| 732 | } |
| 733 | |
| 734 | devConfig := &DeviceConfig{ |
| 735 | SerialNumber: "SDX6320033", |
| 736 | NniDhcpTrapVid: 4, |
| 737 | } |
| 738 | voltDevice := &VoltDevice{ |
| 739 | Name: "11c3175b-50f3-4220-9555-93df733ded1d", |
| 740 | SerialNum: "SDX6320033", |
| 741 | SouthBoundID: "68580342-6b3e-57cb-9ea4-06125594e330", |
| 742 | State: controller.DeviceStateDOWN, |
| 743 | NniPort: "", |
| 744 | icmpv6GroupAdded: false, |
| 745 | IgmpDsFlowAppliedForMvlan: make(map[uint16]bool), |
| 746 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 747 | MigratingServices: util.NewConcurrentMap(), |
| 748 | VpvsBySvlan: util.NewConcurrentMap(), |
| 749 | FlowAddEventMap: util.NewConcurrentMap(), |
| 750 | FlowDelEventMap: util.NewConcurrentMap(), |
| 751 | GlobalDhcpFlowAdded: false, |
| 752 | NniDhcpTrapVid: 4, |
| 753 | } |
| 754 | |
| 755 | GetApplication().DevicesConfig.Store("SDX6320033", devConfig) |
| 756 | tests := []struct { |
| 757 | name string |
| 758 | args args |
| 759 | want *VoltDevice |
| 760 | }{ |
| 761 | { |
| 762 | name: "Positive_Case_TestNewVoltDevice", |
| 763 | args: args{ |
| 764 | name: "11c3175b-50f3-4220-9555-93df733ded1d", |
| 765 | slno: "SDX6320033", |
| 766 | southBoundID: "68580342-6b3e-57cb-9ea4-06125594e330", |
| 767 | }, |
| 768 | want: voltDevice, |
| 769 | }, |
| 770 | } |
| 771 | for _, tt := range tests { |
| 772 | t.Run(tt.name, func(t *testing.T) { |
| 773 | if got := NewVoltDevice(tt.args.name, tt.args.slno, tt.args.southBoundID); !reflect.DeepEqual(got, tt.want) { |
| 774 | t.Errorf("NewVoltDevice() = %v, want %v", got, tt.want) |
| 775 | } |
| 776 | }) |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | func TestVoltApplication_GetAssociatedVpvsForDevice(t *testing.T) { |
| 781 | type args struct { |
| 782 | device string |
| 783 | svlan of.VlanType |
| 784 | } |
| 785 | |
| 786 | voltDev := &VoltDevice{ |
| 787 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 788 | SerialNum: "SDX6320033", |
| 789 | NniDhcpTrapVid: 123, |
| 790 | VpvsBySvlan: util.NewConcurrentMap(), |
| 791 | } |
| 792 | |
| 793 | cuncurrentMap := &util.ConcurrentMap{ |
| 794 | Count: atomic.NewUint64(0), |
| 795 | } |
| 796 | |
| 797 | voltDev1 := &VoltDevice{ |
| 798 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 799 | SerialNum: "SDX6320033", |
| 800 | NniDhcpTrapVid: 123, |
| 801 | VpvsBySvlan: cuncurrentMap, |
| 802 | } |
| 803 | tests := []struct { |
| 804 | name string |
| 805 | args args |
| 806 | want *util.ConcurrentMap |
| 807 | }{ |
| 808 | { |
| 809 | name: "Positive_Case_GetAssociatedVpvsForDevice", |
| 810 | args: args{ |
| 811 | device: "SDX6320033", |
| 812 | svlan: of.VlanAny, |
| 813 | }, |
| 814 | want: util.NewConcurrentMap(), |
| 815 | }, |
| 816 | { |
| 817 | name: "Positive_Case2_GetAssociatedVpvsForDevice", |
| 818 | args: args{ |
| 819 | device: "SDX6320033", |
| 820 | svlan: of.VlanAny, |
| 821 | }, |
| 822 | want: cuncurrentMap, |
| 823 | }, |
| 824 | { |
| 825 | name: "Negetive_Case2_GetAssociatedVpvsForDevice", |
| 826 | args: args{ |
| 827 | device: "SDX6320031", |
| 828 | svlan: of.VlanAny, |
| 829 | }, |
| 830 | want: nil, |
| 831 | }, |
| 832 | } |
| 833 | for _, tt := range tests { |
| 834 | t.Run(tt.name, func(t *testing.T) { |
| 835 | switch tt.name { |
| 836 | case "Positive_Case_GetAssociatedVpvsForDevice": |
| 837 | va := &VoltApplication{ |
| 838 | DevicesDisc: sync.Map{}, |
| 839 | VnetsBySvlan: util.NewConcurrentMap(), |
| 840 | } |
| 841 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 842 | if got := va.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 843 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 844 | } |
| 845 | case "Positive_Case2_GetAssociatedVpvsForDevice": |
| 846 | va1 := &VoltApplication{ |
| 847 | DevicesDisc: sync.Map{}, |
| 848 | VnetsBySvlan: cuncurrentMap, |
| 849 | } |
| 850 | va1.DevicesDisc.Store("SDX6320033", voltDev1) |
| 851 | va1.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap) |
| 852 | if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 853 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 854 | } |
| 855 | case "Negetive_Case2_GetAssociatedVpvsForDevice": |
| 856 | va1 := &VoltApplication{ |
| 857 | DevicesDisc: sync.Map{}, |
| 858 | } |
| 859 | if got := va1.GetAssociatedVpvsForDevice(tt.args.device, tt.args.svlan); !reflect.DeepEqual(got, tt.want) { |
| 860 | t.Errorf("VoltApplication.GetAssociatedVpvsForDevice() = %v, want %v", got, tt.want) |
| 861 | } |
| 862 | } |
| 863 | }) |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | func TestVoltApplication_AssociateVpvsToDevice(t *testing.T) { |
| 868 | type args struct { |
| 869 | device string |
| 870 | vpv *VoltPortVnet |
| 871 | } |
| 872 | |
| 873 | vpv := &VoltPortVnet{ |
| 874 | Device: "SDX6320033", |
| 875 | SVlan: of.VlanAny, |
| 876 | } |
| 877 | voltDev := &VoltDevice{ |
| 878 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 879 | SerialNum: "SDX6320033", |
| 880 | NniDhcpTrapVid: 123, |
| 881 | VpvsBySvlan: util.NewConcurrentMap(), |
| 882 | } |
| 883 | tests := []struct { |
| 884 | name string |
| 885 | args args |
| 886 | }{ |
| 887 | { |
| 888 | name: "Positive_Case_AssociateVpvsToDevice", |
| 889 | args: args{ |
| 890 | device: "SDX6320033", |
| 891 | vpv: vpv, |
| 892 | }, |
| 893 | }, |
| 894 | { |
| 895 | name: "Negetive_Case_AssociateVpvsToDevice", |
| 896 | args: args{ |
| 897 | device: "SDX6320033", |
| 898 | vpv: vpv, |
| 899 | }, |
| 900 | }, |
| 901 | } |
| 902 | for _, tt := range tests { |
| 903 | t.Run(tt.name, func(t *testing.T) { |
| 904 | switch tt.name { |
| 905 | case "Positive_Case_AssociateVpvsToDevice": |
| 906 | va := &VoltApplication{ |
| 907 | DevicesDisc: sync.Map{}, |
| 908 | VnetsBySvlan: util.NewConcurrentMap(), |
| 909 | } |
| 910 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 911 | va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv) |
| 912 | case "Negetive_Case_AssociateVpvsToDevice": |
| 913 | va := &VoltApplication{ |
| 914 | DevicesDisc: sync.Map{}, |
| 915 | VnetsBySvlan: util.NewConcurrentMap(), |
| 916 | } |
| 917 | va.AssociateVpvsToDevice(tt.args.device, tt.args.vpv) |
| 918 | } |
| 919 | }) |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | func TestVoltApplication_DisassociateVpvsFromDevice(t *testing.T) { |
| 924 | type args struct { |
| 925 | device string |
| 926 | vpv *VoltPortVnet |
| 927 | } |
| 928 | vpv := &VoltPortVnet{ |
| 929 | Device: "SDX6320033", |
| 930 | SVlan: of.VlanAny, |
| 931 | } |
| 932 | |
| 933 | voltDev := &VoltDevice{ |
| 934 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 935 | SerialNum: "SDX6320033", |
| 936 | NniDhcpTrapVid: 123, |
| 937 | VpvsBySvlan: util.NewConcurrentMap(), |
| 938 | } |
| 939 | tests := []struct { |
| 940 | name string |
| 941 | args args |
| 942 | }{ |
| 943 | { |
| 944 | name: "Positive_Case_DisassociateVpvsFromDevice", |
| 945 | args: args{ |
| 946 | device: "SDX6320033", |
| 947 | vpv: vpv, |
| 948 | }, |
| 949 | }, |
| 950 | { |
| 951 | name: "Negetive_Case_DisassociateVpvsFromDevice", |
| 952 | args: args{ |
| 953 | device: "SDX6320033", |
| 954 | vpv: vpv, |
| 955 | }, |
| 956 | }, |
| 957 | } |
| 958 | for _, tt := range tests { |
| 959 | t.Run(tt.name, func(t *testing.T) { |
| 960 | switch tt.name { |
| 961 | case "Positive_Case_DisassociateVpvsFromDevice": |
| 962 | va := &VoltApplication{ |
| 963 | DevicesDisc: sync.Map{}, |
| 964 | VnetsBySvlan: util.NewConcurrentMap(), |
| 965 | } |
| 966 | va.DevicesDisc.Store("SDX6320033", voltDev) |
| 967 | va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv) |
| 968 | case "Negetive_Case_DisassociateVpvsFromDevice": |
| 969 | va := &VoltApplication{ |
| 970 | DevicesDisc: sync.Map{}, |
| 971 | VnetsBySvlan: util.NewConcurrentMap(), |
| 972 | } |
| 973 | va.DisassociateVpvsFromDevice(tt.args.device, tt.args.vpv) |
| 974 | } |
| 975 | }) |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | func TestVoltDevice_GetPort(t *testing.T) { |
| 980 | type args struct { |
| 981 | port string |
| 982 | } |
| 983 | voltPort := &VoltPort{ |
| 984 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 985 | Device: "SDX6320031", |
| 986 | ID: 16777472, |
| 987 | State: PortStateDown, |
| 988 | ChannelPerSubAlarmRaised: false, |
| 989 | Type: VoltPortTypeNni, |
| 990 | } |
| 991 | tests := []struct { |
| 992 | name string |
| 993 | args args |
| 994 | want *VoltPort |
| 995 | }{ |
| 996 | { |
| 997 | name: "Positive_Case_GetPort", |
| 998 | args: args{ |
| 999 | port: "16777472", |
| 1000 | }, |
| 1001 | want: voltPort, |
| 1002 | }, |
| 1003 | { |
| 1004 | name: "Negetive_Case_GetPort", |
| 1005 | args: args{ |
| 1006 | port: "16777472", |
| 1007 | }, |
| 1008 | want: nil, |
| 1009 | }, |
| 1010 | } |
| 1011 | for _, tt := range tests { |
| 1012 | t.Run(tt.name, func(t *testing.T) { |
| 1013 | d := &VoltDevice{ |
| 1014 | Ports: sync.Map{}, |
| 1015 | } |
| 1016 | switch tt.name { |
| 1017 | case "Positive_Case_GetPort": |
| 1018 | d.Ports.Store("16777472", voltPort) |
| 1019 | if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) { |
| 1020 | t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want) |
| 1021 | } |
| 1022 | case "Negetive_Case_GetPort": |
| 1023 | if got := d.GetPort(tt.args.port); !reflect.DeepEqual(got, tt.want) { |
| 1024 | t.Errorf("VoltDevice.GetPort() = %v, want %v", got, tt.want) |
| 1025 | } |
| 1026 | } |
| 1027 | }) |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | func TestVoltDevice_GetPortNameFromPortID(t *testing.T) { |
| 1032 | type args struct { |
| 1033 | portID uint32 |
| 1034 | } |
| 1035 | voltPort := &VoltPort{ |
| 1036 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1037 | Device: "SDX6320031", |
| 1038 | ID: 16777472, |
| 1039 | State: PortStateDown, |
| 1040 | ChannelPerSubAlarmRaised: false, |
| 1041 | Type: VoltPortTypeNni, |
| 1042 | } |
| 1043 | tests := []struct { |
| 1044 | name string |
| 1045 | args args |
| 1046 | want string |
| 1047 | }{ |
| 1048 | { |
| 1049 | name: "Positive_Case_GetPort", |
| 1050 | args: args{ |
| 1051 | portID: 16777472, |
| 1052 | }, |
| 1053 | want: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1054 | }, |
| 1055 | } |
| 1056 | for _, tt := range tests { |
| 1057 | t.Run(tt.name, func(t *testing.T) { |
| 1058 | d := &VoltDevice{ |
| 1059 | Ports: sync.Map{}, |
| 1060 | } |
| 1061 | d.Ports.Store(16777472, voltPort) |
| 1062 | if got := d.GetPortNameFromPortID(tt.args.portID); got != tt.want { |
| 1063 | t.Errorf("VoltDevice.GetPortNameFromPortID() = %v, want %v", got, tt.want) |
| 1064 | } |
| 1065 | }) |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | func TestVoltDevice_DelPort(t *testing.T) { |
| 1070 | type args struct { |
| 1071 | port string |
| 1072 | } |
| 1073 | voltPort := &VoltPort{ |
| 1074 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1075 | Device: "SDX6320031", |
| 1076 | ID: 16777472, |
| 1077 | State: PortStateDown, |
| 1078 | ChannelPerSubAlarmRaised: false, |
| 1079 | Type: VoltPortTypeNni, |
| 1080 | } |
| 1081 | tests := []struct { |
| 1082 | name string |
| 1083 | args args |
| 1084 | }{ |
| 1085 | { |
| 1086 | name: "Positive_Case_DelPort", |
| 1087 | args: args{ |
| 1088 | port: "16777472", |
| 1089 | }, |
| 1090 | }, |
| 1091 | { |
| 1092 | name: "Negetive_Case_DelPort", |
| 1093 | args: args{ |
| 1094 | port: "16777472", |
| 1095 | }, |
| 1096 | }, |
| 1097 | } |
| 1098 | for _, tt := range tests { |
| 1099 | t.Run(tt.name, func(t *testing.T) { |
| 1100 | d := &VoltDevice{ |
| 1101 | Ports: sync.Map{}, |
| 1102 | } |
| 1103 | switch tt.name { |
| 1104 | case "Positive_Case_DelPort": |
| 1105 | d.Ports.Store("16777472", voltPort) |
| 1106 | d.DelPort(tt.args.port) |
| 1107 | case "Negetive_Case_DelPort": |
| 1108 | d.DelPort(tt.args.port) |
| 1109 | } |
| 1110 | }) |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | func TestVoltDevice_pushFlowsForUnis(t *testing.T) { |
| 1115 | type args struct { |
| 1116 | cntx context.Context |
| 1117 | } |
| 1118 | tests := []struct { |
| 1119 | name string |
| 1120 | args args |
| 1121 | }{ |
| 1122 | { |
| 1123 | name: "Positive_Case_pushFlowsForUnis", |
| 1124 | args: args{ |
| 1125 | cntx: context.Background(), |
| 1126 | }, |
| 1127 | }, |
| 1128 | { |
| 1129 | name: "Negetive_Case_pushFlowsForUnis", |
| 1130 | args: args{ |
| 1131 | cntx: context.Background(), |
| 1132 | }, |
| 1133 | }, |
| 1134 | { |
| 1135 | name: "Negetive_Case1_pushFlowsForUnis", |
| 1136 | args: args{ |
| 1137 | cntx: context.Background(), |
| 1138 | }, |
| 1139 | }, |
| 1140 | } |
| 1141 | for _, tt := range tests { |
| 1142 | t.Run(tt.name, func(t *testing.T) { |
| 1143 | d := &VoltDevice{ |
| 1144 | Name: "SDX6320031", |
| 1145 | SerialNum: "SDX6320031", |
| 1146 | Ports: sync.Map{}, |
| 1147 | } |
| 1148 | switch tt.name { |
| 1149 | case "Positive_Case_pushFlowsForUnis": |
| 1150 | voltPort := &VoltPort{ |
| 1151 | Name: "16777472", |
| 1152 | Device: "SDX6320031", |
| 1153 | ID: 16777472, |
| 1154 | State: PortStateUp, |
| 1155 | ChannelPerSubAlarmRaised: false, |
| 1156 | Type: VoltPortTypeNni, |
| 1157 | } |
| 1158 | d.Ports.Store("16777472", voltPort) |
| 1159 | ga := GetApplication() |
| 1160 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 1161 | voltPortVnet := &VoltPortVnet{ |
| 1162 | Device: "SDX6320031", |
| 1163 | Port: "16777472", |
| 1164 | DeleteInProgress: true, |
| 1165 | } |
| 1166 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 1167 | ga.VnetsByPort.Store("16777472", voltPortVnets) |
| 1168 | |
| 1169 | d.pushFlowsForUnis(tt.args.cntx) |
| 1170 | case "Negetive_Case_pushFlowsForUnis": |
| 1171 | voltPort1 := &VoltPort{ |
| 1172 | Name: "16777472", |
| 1173 | Device: "SDX6320031", |
| 1174 | ID: 16777472, |
| 1175 | State: PortStateDown, |
| 1176 | ChannelPerSubAlarmRaised: false, |
| 1177 | Type: VoltPortTypeNni, |
| 1178 | } |
| 1179 | d.Ports.Store("16777472", voltPort1) |
| 1180 | d.pushFlowsForUnis(tt.args.cntx) |
| 1181 | case "Negetive_Case1_pushFlowsForUnis": |
| 1182 | voltPort2 := &VoltPort{ |
| 1183 | Name: "16777472", |
| 1184 | Device: "SDX6320031", |
| 1185 | ID: 16777472, |
| 1186 | State: PortStateUp, |
| 1187 | ChannelPerSubAlarmRaised: false, |
| 1188 | Type: VoltPortTypeNni, |
| 1189 | } |
| 1190 | d.Ports.Store("1677747", voltPort2) |
| 1191 | d.pushFlowsForUnis(tt.args.cntx) |
| 1192 | } |
| 1193 | }) |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | func TestNewNbDevice(t *testing.T) { |
| 1198 | tests := []struct { |
| 1199 | name string |
| 1200 | want *NbDevice |
| 1201 | }{ |
| 1202 | { |
| 1203 | name: "Positive_Case_pushFlowsForUnis", |
| 1204 | want: &NbDevice{}, |
| 1205 | }, |
| 1206 | } |
| 1207 | for _, tt := range tests { |
| 1208 | t.Run(tt.name, func(t *testing.T) { |
| 1209 | if got := NewNbDevice(); !reflect.DeepEqual(got, tt.want) { |
| 1210 | t.Errorf("NewNbDevice() = %v, want %v", got, tt.want) |
| 1211 | } |
| 1212 | }) |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | func TestNbDevice_WriteToDb(t *testing.T) { |
| 1217 | type args struct { |
| 1218 | cntx context.Context |
| 1219 | portID uint32 |
| 1220 | ponPort *PonPortCfg |
| 1221 | } |
| 1222 | tests := []struct { |
| 1223 | name string |
| 1224 | args args |
| 1225 | }{ |
| 1226 | { |
| 1227 | name: "Positive_Case_pushFlowsForUnis", |
| 1228 | args: args{ |
| 1229 | cntx: context.Background(), |
| 1230 | portID: controller.NNIPortID, |
| 1231 | ponPort: &PonPortCfg{ |
| 1232 | PortID: controller.NNIPortID, |
| 1233 | EnableMulticastKPI: false, |
| 1234 | }, |
| 1235 | }, |
| 1236 | }, |
| 1237 | } |
| 1238 | for _, tt := range tests { |
| 1239 | t.Run(tt.name, func(t *testing.T) { |
| 1240 | nbd := &NbDevice{ |
| 1241 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1242 | } |
| 1243 | switch tt.name { |
| 1244 | case "Positive_Case_pushFlowsForUnis": |
| 1245 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1246 | db = dbintf |
| 1247 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1248 | nbd.WriteToDb(tt.args.cntx, tt.args.portID, tt.args.ponPort) |
| 1249 | } |
| 1250 | }) |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | func TestNbDevice_AddPortToNbDevice(t *testing.T) { |
| 1255 | type args struct { |
| 1256 | cntx context.Context |
| 1257 | portID uint32 |
| 1258 | allowedChannels uint32 |
| 1259 | enableMulticastKPI bool |
| 1260 | portAlarmProfileID string |
| 1261 | } |
| 1262 | ponPort := &PonPortCfg{ |
| 1263 | PortID: controller.NNIPortID, |
| 1264 | MaxActiveChannels: 123, |
| 1265 | EnableMulticastKPI: false, |
| 1266 | PortAlarmProfileID: "16777", |
| 1267 | } |
| 1268 | tests := []struct { |
| 1269 | name string |
| 1270 | args args |
| 1271 | want *PonPortCfg |
| 1272 | }{ |
| 1273 | { |
| 1274 | name: "Positive_Case_AddPortToNbDevice", |
| 1275 | args: args{ |
| 1276 | cntx: context.Background(), |
| 1277 | portID: controller.NNIPortID, |
| 1278 | allowedChannels: 123, |
| 1279 | enableMulticastKPI: false, |
| 1280 | portAlarmProfileID: "16777", |
| 1281 | }, |
| 1282 | want: ponPort, |
| 1283 | }, |
| 1284 | } |
| 1285 | for _, tt := range tests { |
| 1286 | t.Run(tt.name, func(t *testing.T) { |
| 1287 | nbd := &NbDevice{ |
| 1288 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1289 | PonPorts: sync.Map{}, |
| 1290 | } |
| 1291 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1292 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1293 | db = dbintf |
| 1294 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1295 | if got := nbd.AddPortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1296 | t.Errorf("NbDevice.AddPortToNbDevice() = %v, want %v", got, tt.want) |
| 1297 | } |
| 1298 | }) |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | func TestVoltApplication_AddDeviceConfig(t *testing.T) { |
| 1303 | type args struct { |
| 1304 | cntx context.Context |
| 1305 | serialNum string |
| 1306 | hardwareIdentifier string |
| 1307 | nasID string |
| 1308 | ipAddress string |
| 1309 | uplinkPort string |
| 1310 | nniDhcpTrapID int |
| 1311 | } |
| 1312 | dvcConfg := &DeviceConfig{ |
| 1313 | SerialNumber: "SDX6320031", |
| 1314 | HardwareIdentifier: "0.0.0.0", |
| 1315 | IPAddress: "127.26.1.74", |
| 1316 | UplinkPort: "16777216", |
| 1317 | NasID: "12345", |
| 1318 | NniDhcpTrapVid: 123, |
| 1319 | } |
| 1320 | voltDev := &VoltDevice{ |
| 1321 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1322 | SerialNum: "SDX6320031", |
| 1323 | NniDhcpTrapVid: 123, |
| 1324 | } |
| 1325 | tests := []struct { |
| 1326 | name string |
| 1327 | args args |
| 1328 | wantErr bool |
| 1329 | }{ |
| 1330 | { |
| 1331 | name: "Positive_Case_AddDeviceConfig", |
| 1332 | args: args{ |
| 1333 | cntx: context.Background(), |
| 1334 | serialNum: "SDX6320031", |
| 1335 | hardwareIdentifier: "0.0.0.0.", |
| 1336 | nasID: "12345", |
| 1337 | ipAddress: "127.26.1.74", |
| 1338 | uplinkPort: "16777216", |
| 1339 | nniDhcpTrapID: 123, |
| 1340 | }, |
| 1341 | wantErr: false, |
| 1342 | }, |
| 1343 | } |
| 1344 | for _, tt := range tests { |
| 1345 | t.Run(tt.name, func(t *testing.T) { |
| 1346 | va := &VoltApplication{ |
| 1347 | DevicesConfig: sync.Map{}, |
| 1348 | } |
| 1349 | va.DevicesConfig.Store("SDX6320031", dvcConfg) |
| 1350 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1351 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1352 | db = dbintf |
| 1353 | dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1354 | if err := va.AddDeviceConfig(tt.args.cntx, tt.args.serialNum, tt.args.hardwareIdentifier, tt.args.nasID, tt.args.ipAddress, tt.args.uplinkPort, tt.args.nniDhcpTrapID); (err != nil) != tt.wantErr { |
| 1355 | t.Errorf("VoltApplication.AddDeviceConfig() error = %v, wantErr %v", err, tt.wantErr) |
| 1356 | } |
| 1357 | }) |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | func TestVoltApplication_GetDeviceConfig(t *testing.T) { |
| 1362 | type args struct { |
| 1363 | serNum string |
| 1364 | } |
| 1365 | dvcConfg := &DeviceConfig{ |
| 1366 | SerialNumber: "SDX6320031", |
| 1367 | HardwareIdentifier: "0.0.0.0", |
| 1368 | IPAddress: "127.26.1.74", |
| 1369 | UplinkPort: "16777216", |
| 1370 | NasID: "12345", |
| 1371 | NniDhcpTrapVid: 123, |
| 1372 | } |
| 1373 | tests := []struct { |
| 1374 | name string |
| 1375 | args args |
| 1376 | want *DeviceConfig |
| 1377 | }{ |
| 1378 | { |
| 1379 | name: "Positive_Case_GetDeviceConfig", |
| 1380 | args: args{ |
| 1381 | serNum: "SDX6320031", |
| 1382 | }, |
| 1383 | want: dvcConfg, |
| 1384 | }, |
| 1385 | { |
| 1386 | name: "Negetive_Case_GetDeviceConfig", |
| 1387 | args: args{ |
| 1388 | serNum: "SDX6320031", |
| 1389 | }, |
| 1390 | want: nil, |
| 1391 | }, |
| 1392 | } |
| 1393 | for _, tt := range tests { |
| 1394 | t.Run(tt.name, func(t *testing.T) { |
| 1395 | va := &VoltApplication{ |
| 1396 | DevicesConfig: sync.Map{}, |
| 1397 | } |
| 1398 | switch tt.name { |
| 1399 | case "Positive_Case_GetDeviceConfig": |
| 1400 | va.DevicesConfig.Store("SDX6320031", dvcConfg) |
| 1401 | if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) { |
| 1402 | t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want) |
| 1403 | } |
| 1404 | case "Negetive_Case_GetDeviceConfig": |
| 1405 | if got := va.GetDeviceConfig(tt.args.serNum); !reflect.DeepEqual(got, tt.want) { |
| 1406 | t.Errorf("VoltApplication.GetDeviceConfig() = %v, want %v", got, tt.want) |
| 1407 | } |
| 1408 | } |
| 1409 | }) |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | func TestNbDevice_UpdatePortToNbDevice(t *testing.T) { |
| 1414 | type args struct { |
| 1415 | cntx context.Context |
| 1416 | portID uint32 |
| 1417 | allowedChannels uint32 |
| 1418 | enableMulticastKPI bool |
| 1419 | portAlarmProfileID string |
| 1420 | } |
| 1421 | ponPort := &PonPortCfg{ |
| 1422 | PortID: controller.NNIPortID, |
| 1423 | MaxActiveChannels: 123, |
| 1424 | EnableMulticastKPI: false, |
| 1425 | PortAlarmProfileID: "16777", |
| 1426 | } |
| 1427 | tests := []struct { |
| 1428 | name string |
| 1429 | args args |
| 1430 | want *PonPortCfg |
| 1431 | }{ |
| 1432 | { |
| 1433 | name: "Positive_Case_UpdatePortToNbDevice", |
| 1434 | args: args{ |
| 1435 | cntx: context.Background(), |
| 1436 | portID: controller.NNIPortID, |
| 1437 | allowedChannels: 123, |
| 1438 | enableMulticastKPI: false, |
| 1439 | portAlarmProfileID: "16777", |
| 1440 | }, |
| 1441 | want: ponPort, |
| 1442 | }, |
| 1443 | { |
| 1444 | name: "Negetive_Case_UpdatePortToNbDevice", |
| 1445 | args: args{ |
| 1446 | cntx: context.Background(), |
| 1447 | portID: 0, |
| 1448 | allowedChannels: 123, |
| 1449 | enableMulticastKPI: false, |
| 1450 | portAlarmProfileID: "16777", |
| 1451 | }, |
| 1452 | want: nil, |
| 1453 | }, |
| 1454 | } |
| 1455 | for _, tt := range tests { |
| 1456 | t.Run(tt.name, func(t *testing.T) { |
| 1457 | nbd := &NbDevice{ |
| 1458 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1459 | PonPorts: sync.Map{}, |
| 1460 | } |
| 1461 | switch tt.name { |
| 1462 | case "Positive_Case_UpdatePortToNbDevice": |
| 1463 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1464 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1465 | db = dbintf |
| 1466 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 1467 | if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1468 | t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want) |
| 1469 | } |
| 1470 | case "Negetive_Case_UpdatePortToNbDevice": |
| 1471 | if got := nbd.UpdatePortToNbDevice(tt.args.cntx, tt.args.portID, tt.args.allowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); !reflect.DeepEqual(got, tt.want) { |
| 1472 | t.Errorf("NbDevice.UpdatePortToNbDevice() = %v, want %v", got, tt.want) |
| 1473 | } |
| 1474 | } |
| 1475 | }) |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | func TestNbDevice_DeletePortFromNbDevice(t *testing.T) { |
| 1480 | type args struct { |
| 1481 | cntx context.Context |
| 1482 | portID uint32 |
| 1483 | } |
| 1484 | ponPort := &PonPortCfg{ |
| 1485 | PortID: controller.NNIPortID, |
| 1486 | MaxActiveChannels: 123, |
| 1487 | EnableMulticastKPI: false, |
| 1488 | PortAlarmProfileID: "16777", |
| 1489 | } |
| 1490 | tests := []struct { |
| 1491 | name string |
| 1492 | args args |
| 1493 | }{ |
| 1494 | { |
| 1495 | name: "Positive_Case_DeletePortFromNbDevice", |
| 1496 | args: args{ |
| 1497 | portID: controller.NNIPortID, |
| 1498 | }, |
| 1499 | }, |
| 1500 | } |
| 1501 | for _, tt := range tests { |
| 1502 | t.Run(tt.name, func(t *testing.T) { |
| 1503 | nbd := &NbDevice{ |
| 1504 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1505 | PonPorts: sync.Map{}, |
| 1506 | } |
| 1507 | nbd.PonPorts.Store(controller.NNIPortID, ponPort) |
| 1508 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1509 | db = dbintf |
| 1510 | dbintf.EXPECT().DelNbDevicePort(nil, "49686e2d-618f-4e8e-bca0-442ab850a63a", controller.NNIPortID).AnyTimes() |
| 1511 | nbd.DeletePortFromNbDevice(tt.args.cntx, tt.args.portID) |
| 1512 | }) |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | func TestVoltDevice_RegisterFlowAddEvent(t *testing.T) { |
| 1517 | type args struct { |
| 1518 | cookie string |
| 1519 | event *FlowEvent |
| 1520 | } |
| 1521 | flowEvent := &FlowEvent{ |
| 1522 | device: "SDX6320031", |
| 1523 | cookie: "68786618880", |
| 1524 | eType: EventTypeControlFlowAdded, |
| 1525 | } |
| 1526 | tests := []struct { |
| 1527 | name string |
| 1528 | args args |
| 1529 | }{ |
| 1530 | { |
| 1531 | name: "Positive_Case_RegisterFlowAddEvent", |
| 1532 | args: args{ |
| 1533 | cookie: "68786618880", |
| 1534 | event: flowEvent, |
| 1535 | }, |
| 1536 | }, |
| 1537 | } |
| 1538 | for _, tt := range tests { |
| 1539 | t.Run(tt.name, func(t *testing.T) { |
| 1540 | d := &VoltDevice{ |
| 1541 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1542 | } |
| 1543 | d.RegisterFlowAddEvent(tt.args.cookie, tt.args.event) |
| 1544 | }) |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | func TestVoltDevice_RegisterFlowDelEvent(t *testing.T) { |
| 1549 | type args struct { |
| 1550 | cookie string |
| 1551 | event *FlowEvent |
| 1552 | } |
| 1553 | flowEvent := &FlowEvent{ |
| 1554 | device: "SDX6320031", |
| 1555 | cookie: "68786618880", |
| 1556 | eType: EventTypeControlFlowRemoved, |
| 1557 | } |
| 1558 | tests := []struct { |
| 1559 | name string |
| 1560 | args args |
| 1561 | }{ |
| 1562 | { |
| 1563 | name: "Positive_Case_RegisterFlowDelEvent", |
| 1564 | args: args{ |
| 1565 | cookie: "68786618880", |
| 1566 | event: flowEvent, |
| 1567 | }, |
| 1568 | }, |
| 1569 | } |
| 1570 | for _, tt := range tests { |
| 1571 | t.Run(tt.name, func(t *testing.T) { |
| 1572 | d := &VoltDevice{ |
| 1573 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1574 | } |
| 1575 | d.RegisterFlowDelEvent(tt.args.cookie, tt.args.event) |
| 1576 | }) |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | func TestVoltDevice_UnRegisterFlowEvent(t *testing.T) { |
| 1581 | type args struct { |
| 1582 | cookie string |
| 1583 | flowModType of.Command |
| 1584 | } |
| 1585 | tests := []struct { |
| 1586 | name string |
| 1587 | args args |
| 1588 | }{ |
| 1589 | { |
| 1590 | name: "Positive_Case_RegisterFlowDelEvent", |
| 1591 | args: args{ |
| 1592 | cookie: "68786618880", |
| 1593 | flowModType: of.CommandDel, |
| 1594 | }, |
| 1595 | }, |
| 1596 | { |
| 1597 | name: "Negetive_Case_RegisterFlowDelEvent", |
| 1598 | args: args{ |
| 1599 | cookie: "68786618880", |
| 1600 | flowModType: opt82, |
| 1601 | }, |
| 1602 | }, |
| 1603 | } |
| 1604 | for _, tt := range tests { |
| 1605 | t.Run(tt.name, func(t *testing.T) { |
| 1606 | switch tt.name { |
| 1607 | case "Positive_Case_RegisterFlowDelEvent": |
| 1608 | d := &VoltDevice{ |
| 1609 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1610 | } |
| 1611 | d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType) |
| 1612 | case "Negetive_Case_RegisterFlowDelEvent": |
| 1613 | d := &VoltDevice{ |
| 1614 | FlowDelEventMap: util.NewConcurrentMap(), |
| 1615 | } |
| 1616 | d.UnRegisterFlowEvent(tt.args.cookie, tt.args.flowModType) |
| 1617 | } |
| 1618 | }) |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | func TestVoltApplication_InitStaticConfig(t *testing.T) { |
| 1623 | tests := []struct { |
| 1624 | name string |
| 1625 | }{ |
| 1626 | { |
| 1627 | name: "Positive_Case_InitStaticConfig", |
| 1628 | }, |
| 1629 | } |
| 1630 | for _, tt := range tests { |
| 1631 | t.Run(tt.name, func(t *testing.T) { |
| 1632 | va := &VoltApplication{} |
| 1633 | va.InitStaticConfig() |
| 1634 | }) |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | func TestVoltApplication_SetVendorID(t *testing.T) { |
| 1639 | type args struct { |
| 1640 | vendorID string |
| 1641 | } |
| 1642 | tests := []struct { |
| 1643 | name string |
| 1644 | args args |
| 1645 | }{ |
| 1646 | { |
| 1647 | name: "Positive_Case_SetVendorID", |
| 1648 | args: args{ |
| 1649 | vendorID: "DT", |
| 1650 | }, |
| 1651 | }, |
| 1652 | } |
| 1653 | for _, tt := range tests { |
| 1654 | t.Run(tt.name, func(t *testing.T) { |
| 1655 | va := &VoltApplication{} |
| 1656 | va.SetVendorID(tt.args.vendorID) |
| 1657 | }) |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | func TestVoltApplication_GetVendorID(t *testing.T) { |
| 1662 | tests := []struct { |
| 1663 | name string |
| 1664 | want string |
| 1665 | }{ |
| 1666 | { |
| 1667 | name: "Positive_Case_GetVendorID", |
| 1668 | want: "DT", |
| 1669 | }, |
| 1670 | } |
| 1671 | for _, tt := range tests { |
| 1672 | t.Run(tt.name, func(t *testing.T) { |
| 1673 | va := &VoltApplication{ |
| 1674 | vendorID: "DT", |
| 1675 | } |
| 1676 | if got := va.GetVendorID(); got != tt.want { |
| 1677 | t.Errorf("VoltApplication.GetVendorID() = %v, want %v", got, tt.want) |
| 1678 | } |
| 1679 | }) |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | func TestVoltApplication_SetRebootFlag(t *testing.T) { |
| 1684 | type args struct { |
| 1685 | flag bool |
| 1686 | } |
| 1687 | tests := []struct { |
| 1688 | name string |
| 1689 | args args |
| 1690 | }{ |
| 1691 | { |
| 1692 | name: "Positive_Case_SetRebootFlag", |
| 1693 | args: args{ |
| 1694 | flag: true, |
| 1695 | }, |
| 1696 | }, |
| 1697 | } |
| 1698 | for _, tt := range tests { |
| 1699 | t.Run(tt.name, func(t *testing.T) { |
| 1700 | va := &VoltApplication{} |
| 1701 | va.SetRebootFlag(tt.args.flag) |
| 1702 | }) |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | func TestVoltApplication_GetUpgradeFlag(t *testing.T) { |
| 1707 | tests := []struct { |
| 1708 | name string |
| 1709 | want bool |
| 1710 | }{ |
| 1711 | { |
| 1712 | name: "Positive_Case_GetUpgradeFlag", |
| 1713 | want: true, |
| 1714 | }, |
| 1715 | } |
| 1716 | for _, tt := range tests { |
| 1717 | t.Run(tt.name, func(t *testing.T) { |
| 1718 | va := &VoltApplication{} |
| 1719 | isUpgradeComplete = true |
| 1720 | if got := va.GetUpgradeFlag(); got != tt.want { |
| 1721 | t.Errorf("VoltApplication.GetUpgradeFlag() = %v, want %v", got, tt.want) |
| 1722 | } |
| 1723 | }) |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | func TestVoltApplication_SetUpgradeFlag(t *testing.T) { |
| 1728 | type args struct { |
| 1729 | flag bool |
| 1730 | } |
| 1731 | tests := []struct { |
| 1732 | name string |
| 1733 | args args |
| 1734 | }{ |
| 1735 | { |
| 1736 | name: "Positive_Case_GetUpgradeFlag", |
| 1737 | args: args{ |
| 1738 | flag: true, |
| 1739 | }, |
| 1740 | }, |
| 1741 | } |
| 1742 | for _, tt := range tests { |
| 1743 | t.Run(tt.name, func(t *testing.T) { |
| 1744 | va := &VoltApplication{} |
| 1745 | va.SetUpgradeFlag(tt.args.flag) |
| 1746 | }) |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | func TestVoltApplication_AddDevice(t *testing.T) { |
| 1751 | type args struct { |
| 1752 | cntx context.Context |
| 1753 | device string |
| 1754 | slno string |
| 1755 | southBoundID string |
| 1756 | } |
| 1757 | voltDev := &VoltDevice{ |
| 1758 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1759 | SerialNum: "SDX6320031", |
| 1760 | NniDhcpTrapVid: 123, |
| 1761 | NniPort: "16777216", |
| 1762 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1763 | } |
| 1764 | nbd := &NbDevice{ |
| 1765 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1766 | PonPorts: sync.Map{}, |
| 1767 | } |
| 1768 | ponPortCnf := &PonPortCfg{ |
| 1769 | PortID: controller.NNIPortID, |
| 1770 | MaxActiveChannels: 123, |
| 1771 | EnableMulticastKPI: false, |
| 1772 | PortAlarmProfileID: "16777", |
| 1773 | } |
| 1774 | tests := []struct { |
| 1775 | name string |
| 1776 | args args |
| 1777 | }{ |
| 1778 | { |
| 1779 | name: "Positive_Case_AddDevice", |
| 1780 | args: args{ |
| 1781 | cntx: context.Background(), |
| 1782 | device: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1783 | slno: "SDX6320031", |
| 1784 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1785 | }, |
| 1786 | }, |
| 1787 | { |
| 1788 | name: "Negetive_Case_AddDevice", |
| 1789 | args: args{ |
| 1790 | cntx: context.Background(), |
| 1791 | device: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1792 | slno: "SDX6320031", |
| 1793 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1794 | }, |
| 1795 | }, |
| 1796 | } |
| 1797 | for _, tt := range tests { |
| 1798 | t.Run(tt.name, func(t *testing.T) { |
| 1799 | va := &VoltApplication{ |
| 1800 | DevicesDisc: sync.Map{}, |
| 1801 | NbDevice: sync.Map{}, |
| 1802 | } |
| 1803 | switch tt.name { |
| 1804 | case "Positive_Case_AddDevice": |
| 1805 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1806 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a123", nbd) |
| 1807 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 1808 | va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID) |
| 1809 | case "Negetive_Case_AddDevice": |
| 1810 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1811 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 1812 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1813 | db = dbintf |
| 1814 | dbintf.EXPECT().GetAllNbPorts(context.Background(), "49686e2d-618f-4e8e-bca0-442ab850a63a123").AnyTimes() |
| 1815 | va.AddDevice(tt.args.cntx, tt.args.device, tt.args.slno, tt.args.southBoundID) |
| 1816 | } |
| 1817 | }) |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | func TestVoltApplication_DelDevice(t *testing.T) { |
| 1822 | type args struct { |
| 1823 | cntx context.Context |
| 1824 | device string |
| 1825 | } |
| 1826 | voltDev := &VoltDevice{ |
| 1827 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1828 | SerialNum: "SDX6320031", |
| 1829 | NniDhcpTrapVid: 123, |
| 1830 | NniPort: "16777216", |
| 1831 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1832 | } |
| 1833 | tests := []struct { |
| 1834 | name string |
| 1835 | args args |
| 1836 | }{ |
| 1837 | { |
| 1838 | name: "Positive_Case_AddDevice", |
| 1839 | args: args{ |
| 1840 | cntx: context.Background(), |
| 1841 | device: "SDX6320031", |
| 1842 | }, |
| 1843 | }, |
| 1844 | { |
| 1845 | name: "Delete_Case_AddDevice", |
| 1846 | args: args{ |
| 1847 | cntx: context.Background(), |
| 1848 | device: "SDX6320031", |
| 1849 | }, |
| 1850 | }, |
| 1851 | } |
| 1852 | for _, tt := range tests { |
| 1853 | t.Run(tt.name, func(t *testing.T) { |
| 1854 | va := &VoltApplication{ |
| 1855 | DevicesDisc: sync.Map{}, |
| 1856 | } |
| 1857 | switch tt.name { |
| 1858 | case "Positive_Case_AddDevice": |
| 1859 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1860 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1861 | db = dbintf |
| 1862 | dbintf.EXPECT().DelAllRoutesForDevice(context.Background(), "SDX6320031").AnyTimes() |
| 1863 | dbintf.EXPECT().GetAllMigrateServicesReq(context.Background(), "SDX6320031").AnyTimes() |
| 1864 | dbintf.EXPECT().DelAllGroup(context.Background(), "SDX6320031").AnyTimes() |
| 1865 | dbintf.EXPECT().DelAllMeter(context.Background(), "SDX6320031").AnyTimes() |
| 1866 | dbintf.EXPECT().DelAllPorts(context.Background(), "SDX6320031").AnyTimes() |
| 1867 | va.DelDevice(tt.args.cntx, tt.args.device) |
| 1868 | case "Delete_Case_AddDevice": |
| 1869 | va.DelDevice(tt.args.cntx, tt.args.device) |
| 1870 | } |
| 1871 | }) |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | func TestVoltApplication_PortAddInd(t *testing.T) { |
| 1876 | type args struct { |
| 1877 | cntx context.Context |
| 1878 | device string |
| 1879 | id uint32 |
| 1880 | portName string |
| 1881 | } |
| 1882 | voltDev := &VoltDevice{ |
| 1883 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1884 | SerialNum: "SDX6320031", |
| 1885 | NniDhcpTrapVid: 123, |
| 1886 | NniPort: "16777216", |
| 1887 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1888 | } |
| 1889 | tests := []struct { |
| 1890 | name string |
| 1891 | args args |
| 1892 | }{ |
| 1893 | { |
| 1894 | name: "Positive_Case_PortAddInd", |
| 1895 | args: args{ |
| 1896 | cntx: context.Background(), |
| 1897 | device: "SDX6320031", |
| 1898 | id: controller.NNIPortID, |
| 1899 | portName: "16777216", |
| 1900 | }, |
| 1901 | }, |
| 1902 | { |
| 1903 | name: "Negetive_Case_PortAddInd", |
| 1904 | args: args{ |
| 1905 | cntx: context.Background(), |
| 1906 | device: "SDX6320031", |
| 1907 | id: controller.NNIPortID, |
| 1908 | portName: "16777216", |
| 1909 | }, |
| 1910 | }, |
| 1911 | } |
| 1912 | for _, tt := range tests { |
| 1913 | t.Run(tt.name, func(t *testing.T) { |
| 1914 | va := &VoltApplication{ |
| 1915 | DevicesDisc: sync.Map{}, |
| 1916 | } |
| 1917 | switch tt.name { |
| 1918 | case "Positive_Case_PortAddInd": |
| 1919 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1920 | va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName) |
| 1921 | case "Negetive_Case_PortAddInd": |
| 1922 | va.PortAddInd(tt.args.cntx, tt.args.device, tt.args.id, tt.args.portName) |
| 1923 | } |
| 1924 | }) |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | func TestVoltApplication_PortUpdateInd(t *testing.T) { |
| 1929 | type args struct { |
| 1930 | device string |
| 1931 | portName string |
| 1932 | id uint32 |
| 1933 | } |
| 1934 | voltDev := &VoltDevice{ |
| 1935 | Name: "SDX6320031", |
| 1936 | SerialNum: "SDX6320031", |
| 1937 | NniDhcpTrapVid: 123, |
| 1938 | NniPort: "16777216", |
| 1939 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a123", |
| 1940 | } |
| 1941 | tests := []struct { |
| 1942 | name string |
| 1943 | args args |
| 1944 | }{ |
| 1945 | { |
| 1946 | name: "Positive_Case_PortUpdateInd", |
| 1947 | args: args{ |
| 1948 | device: "SDX6320031", |
| 1949 | id: controller.NNIPortID, |
| 1950 | portName: "16777216", |
| 1951 | }, |
| 1952 | }, |
| 1953 | { |
| 1954 | name: "Negetive_Case_PortUpdateInd", |
| 1955 | args: args{ |
| 1956 | device: "SDX6320031", |
| 1957 | id: controller.NNIPortID, |
| 1958 | portName: "16777216", |
| 1959 | }, |
| 1960 | }, |
| 1961 | } |
| 1962 | for _, tt := range tests { |
| 1963 | t.Run(tt.name, func(t *testing.T) { |
| 1964 | va := &VoltApplication{ |
| 1965 | DevicesDisc: sync.Map{}, |
| 1966 | } |
| 1967 | switch tt.name { |
| 1968 | case "Positive_Case_PortAddInd": |
| 1969 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1970 | d := &VoltDevice{ |
| 1971 | Ports: sync.Map{}, |
| 1972 | } |
| 1973 | voltPort := &VoltPort{ |
| 1974 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1975 | Device: "SDX6320031", |
| 1976 | ID: 16777472, |
| 1977 | State: PortStateDown, |
| 1978 | ChannelPerSubAlarmRaised: false, |
| 1979 | Type: VoltPortTypeNni, |
| 1980 | } |
| 1981 | d.Ports.Store(16777472, voltPort) |
| 1982 | va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id) |
| 1983 | case "Negetive_Case_PortUpdateInd": |
| 1984 | va.PortUpdateInd(tt.args.device, tt.args.portName, tt.args.id) |
| 1985 | } |
| 1986 | }) |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | func TestVoltApplication_AddNbPonPort(t *testing.T) { |
| 1991 | type args struct { |
| 1992 | cntx context.Context |
| 1993 | oltSbID string |
| 1994 | portID uint32 |
| 1995 | maxAllowedChannels uint32 |
| 1996 | enableMulticastKPI bool |
| 1997 | portAlarmProfileID string |
| 1998 | } |
| 1999 | voltDev := &VoltDevice{ |
| 2000 | Name: "SDX6320031", |
| 2001 | SerialNum: "SDX6320031", |
| 2002 | NniDhcpTrapVid: 123, |
| 2003 | NniPort: "16777216", |
| 2004 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2005 | } |
| 2006 | nbd := &NbDevice{ |
| 2007 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2008 | } |
| 2009 | tests := []struct { |
| 2010 | name string |
| 2011 | args args |
| 2012 | wantErr bool |
| 2013 | }{ |
| 2014 | { |
| 2015 | name: "Positive_Case_AddNbPonPort", |
| 2016 | args: args{ |
| 2017 | cntx: context.Background(), |
| 2018 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2019 | portID: 16777472, |
| 2020 | maxAllowedChannels: 0, |
| 2021 | enableMulticastKPI: false, |
| 2022 | portAlarmProfileID: "16777", |
| 2023 | }, |
| 2024 | }, |
| 2025 | { |
| 2026 | name: "Negetive_Case_AddNbPonPort", |
| 2027 | args: args{ |
| 2028 | cntx: context.Background(), |
| 2029 | oltSbID: "0", |
| 2030 | portID: 16777472, |
| 2031 | maxAllowedChannels: 0, |
| 2032 | enableMulticastKPI: false, |
| 2033 | portAlarmProfileID: "16777", |
| 2034 | }, |
| 2035 | }, |
| 2036 | } |
| 2037 | for _, tt := range tests { |
| 2038 | t.Run(tt.name, func(t *testing.T) { |
| 2039 | va := &VoltApplication{ |
| 2040 | DevicesDisc: sync.Map{}, |
| 2041 | NbDevice: sync.Map{}, |
| 2042 | } |
| 2043 | switch tt.name { |
| 2044 | case "Positive_Case_AddNbPonPort": |
| 2045 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2046 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2047 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2048 | db = dbintf |
| 2049 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2050 | if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2051 | t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2052 | } |
| 2053 | case "Negetive_Case_AddNbPonPort": |
| 2054 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2055 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2056 | db = dbintf |
| 2057 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2058 | if err := va.AddNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2059 | t.Errorf("VoltApplication.AddNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2060 | } |
| 2061 | } |
| 2062 | }) |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | func TestVoltApplication_UpdateNbPonPort(t *testing.T) { |
| 2067 | type args struct { |
| 2068 | cntx context.Context |
| 2069 | oltSbID string |
| 2070 | portID uint32 |
| 2071 | maxAllowedChannels uint32 |
| 2072 | enableMulticastKPI bool |
| 2073 | portAlarmProfileID string |
| 2074 | } |
| 2075 | voltDev := &VoltDevice{ |
| 2076 | Name: "SDX6320031", |
| 2077 | SerialNum: "SDX6320031", |
| 2078 | NniDhcpTrapVid: 123, |
| 2079 | NniPort: "16777216", |
| 2080 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2081 | ActiveChannelsPerPon: sync.Map{}, |
| 2082 | } |
| 2083 | nbd := &NbDevice{ |
| 2084 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2085 | PonPorts: sync.Map{}, |
| 2086 | } |
| 2087 | ponPortCnf := &PonPortCfg{ |
| 2088 | PortID: controller.NNIPortID, |
| 2089 | MaxActiveChannels: 123, |
| 2090 | EnableMulticastKPI: false, |
| 2091 | PortAlarmProfileID: "16777", |
| 2092 | } |
| 2093 | tests := []struct { |
| 2094 | name string |
| 2095 | args args |
| 2096 | wantErr bool |
| 2097 | }{ |
| 2098 | { |
| 2099 | name: "Positive_Case_UpdateNbPonPort", |
| 2100 | args: args{ |
| 2101 | cntx: context.Background(), |
| 2102 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2103 | portID: controller.NNIPortID, |
| 2104 | maxAllowedChannels: 0, |
| 2105 | enableMulticastKPI: false, |
| 2106 | portAlarmProfileID: "16777", |
| 2107 | }, |
| 2108 | wantErr: false, |
| 2109 | }, |
| 2110 | { |
| 2111 | name: "Negetive_Case_Port_doesn't_exists", |
| 2112 | args: args{ |
| 2113 | cntx: context.Background(), |
| 2114 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2115 | portID: 16777472, |
| 2116 | maxAllowedChannels: 0, |
| 2117 | enableMulticastKPI: false, |
| 2118 | portAlarmProfileID: "16777", |
| 2119 | }, |
| 2120 | wantErr: true, |
| 2121 | }, |
| 2122 | { |
| 2123 | name: "Negetive_Case_Device-doesn't-exists", |
| 2124 | args: args{ |
| 2125 | cntx: context.Background(), |
| 2126 | oltSbID: "0", |
| 2127 | portID: 16777472, |
| 2128 | maxAllowedChannels: 0, |
| 2129 | enableMulticastKPI: false, |
| 2130 | portAlarmProfileID: "16777", |
| 2131 | }, |
| 2132 | wantErr: true, |
| 2133 | }, |
| 2134 | } |
| 2135 | for _, tt := range tests { |
| 2136 | t.Run(tt.name, func(t *testing.T) { |
| 2137 | va := &VoltApplication{ |
| 2138 | DevicesDisc: sync.Map{}, |
| 2139 | NbDevice: sync.Map{}, |
| 2140 | } |
| 2141 | switch tt.name { |
| 2142 | case "Positive_Case_UpdateNbPonPort": |
| 2143 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2144 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 2145 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2146 | voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf) |
| 2147 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2148 | db = dbintf |
| 2149 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2150 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2151 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2152 | } |
| 2153 | case "Negetive_Case_Port_doesn't_exists": |
| 2154 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2155 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2156 | db = dbintf |
| 2157 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2158 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2159 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2160 | } |
| 2161 | case "Negetive_Case_Device-doesn't-exists": |
| 2162 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2163 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2164 | db = dbintf |
| 2165 | dbintf.EXPECT().PutNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2166 | if err := va.UpdateNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID, tt.args.maxAllowedChannels, tt.args.enableMulticastKPI, tt.args.portAlarmProfileID); (err != nil) != tt.wantErr { |
| 2167 | t.Errorf("VoltApplication.UpdateNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2168 | } |
| 2169 | } |
| 2170 | }) |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | func TestVoltApplication_DeleteNbPonPort(t *testing.T) { |
| 2175 | type args struct { |
| 2176 | cntx context.Context |
| 2177 | oltSbID string |
| 2178 | portID uint32 |
| 2179 | } |
| 2180 | voltDev := &VoltDevice{ |
| 2181 | Name: "SDX6320031", |
| 2182 | SerialNum: "SDX6320031", |
| 2183 | NniDhcpTrapVid: 123, |
| 2184 | NniPort: "16777216", |
| 2185 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2186 | ActiveChannelsPerPon: sync.Map{}, |
| 2187 | } |
| 2188 | nbd := &NbDevice{ |
| 2189 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2190 | } |
| 2191 | ponPortCnf := &PonPortCfg{ |
| 2192 | PortID: controller.NNIPortID, |
| 2193 | MaxActiveChannels: 123, |
| 2194 | EnableMulticastKPI: false, |
| 2195 | PortAlarmProfileID: "16777", |
| 2196 | } |
| 2197 | tests := []struct { |
| 2198 | name string |
| 2199 | args args |
| 2200 | wantErr bool |
| 2201 | }{ |
| 2202 | { |
| 2203 | name: "Positive_Case_DeleteNbPonPort", |
| 2204 | args: args{ |
| 2205 | cntx: context.Background(), |
| 2206 | oltSbID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2207 | portID: controller.NNIPortID, |
| 2208 | }, |
| 2209 | wantErr: false, |
| 2210 | }, |
| 2211 | { |
| 2212 | name: "Negetive_Case_DeleteNbPonPort", |
| 2213 | args: args{ |
| 2214 | cntx: context.Background(), |
| 2215 | oltSbID: "0", |
| 2216 | portID: controller.NNIPortID, |
| 2217 | }, |
| 2218 | wantErr: false, |
| 2219 | }, |
| 2220 | } |
| 2221 | for _, tt := range tests { |
| 2222 | t.Run(tt.name, func(t *testing.T) { |
| 2223 | va := &VoltApplication{ |
| 2224 | DevicesDisc: sync.Map{}, |
| 2225 | NbDevice: sync.Map{}, |
| 2226 | } |
| 2227 | switch tt.name { |
| 2228 | case "Positive_Case_DeleteNbPonPort": |
| 2229 | va.NbDevice.Store("49686e2d-618f-4e8e-bca0-442ab850a63a", nbd) |
| 2230 | nbd.PonPorts.Store(controller.NNIPortID, ponPortCnf) |
| 2231 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2232 | voltDev.ActiveChannelsPerPon.Store(controller.NNIPortID, ponPortCnf) |
| 2233 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2234 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2235 | db = dbintf |
| 2236 | dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2237 | if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr { |
| 2238 | t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2239 | } |
| 2240 | case "Negetive_Case_DeleteNbPonPort": |
| 2241 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2242 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2243 | db = dbintf |
| 2244 | dbintf.EXPECT().DelNbDevicePort(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
| 2245 | if err := va.DeleteNbPonPort(tt.args.cntx, tt.args.oltSbID, tt.args.portID); (err != nil) != tt.wantErr { |
| 2246 | t.Errorf("VoltApplication.DeleteNbPonPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2247 | } |
| 2248 | } |
| 2249 | }) |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | func TestVoltApplication_DeviceUpInd(t *testing.T) { |
| 2254 | type args struct { |
| 2255 | device string |
| 2256 | } |
| 2257 | voltDev := &VoltDevice{ |
| 2258 | Name: "SDX6320031", |
| 2259 | SerialNum: "SDX6320031", |
| 2260 | NniDhcpTrapVid: 123, |
| 2261 | NniPort: "16777216", |
| 2262 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2263 | } |
| 2264 | tests := []struct { |
| 2265 | name string |
| 2266 | args args |
| 2267 | }{ |
| 2268 | { |
| 2269 | name: "Positive_Case_DeviceUpInd", |
| 2270 | args: args{ |
| 2271 | device: "SDX6320031", |
| 2272 | }, |
| 2273 | }, |
| 2274 | { |
| 2275 | name: "Negetive_Case_DeviceUpInd", |
| 2276 | args: args{ |
| 2277 | device: "o", |
| 2278 | }, |
| 2279 | }, |
| 2280 | } |
| 2281 | for _, tt := range tests { |
| 2282 | t.Run(tt.name, func(t *testing.T) { |
| 2283 | va := &VoltApplication{ |
| 2284 | DevicesDisc: sync.Map{}, |
| 2285 | } |
| 2286 | switch tt.name { |
| 2287 | case "Positive_Case_DeviceUpInd": |
| 2288 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2289 | va.DeviceUpInd(tt.args.device) |
| 2290 | case "Negetive_Case_DeviceUpInd": |
| 2291 | va.DeviceUpInd(tt.args.device) |
| 2292 | } |
| 2293 | }) |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | func TestVoltApplication_DeviceDownInd(t *testing.T) { |
| 2298 | type args struct { |
| 2299 | device string |
| 2300 | } |
| 2301 | voltDev := &VoltDevice{ |
| 2302 | Name: "SDX6320031", |
| 2303 | SerialNum: "SDX6320031", |
| 2304 | NniDhcpTrapVid: 123, |
| 2305 | NniPort: "16777216", |
| 2306 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2307 | } |
| 2308 | tests := []struct { |
| 2309 | name string |
| 2310 | args args |
| 2311 | }{ |
| 2312 | { |
| 2313 | name: "Positive_Case_DeviceDownInd", |
| 2314 | args: args{ |
| 2315 | device: "SDX6320031", |
| 2316 | }, |
| 2317 | }, |
| 2318 | { |
| 2319 | name: "Negetive_Case_DeviceDownInd", |
| 2320 | args: args{ |
| 2321 | device: "o", |
| 2322 | }, |
| 2323 | }, |
| 2324 | } |
| 2325 | for _, tt := range tests { |
| 2326 | t.Run(tt.name, func(t *testing.T) { |
| 2327 | va := &VoltApplication{ |
| 2328 | DevicesDisc: sync.Map{}, |
| 2329 | } |
| 2330 | switch tt.name { |
| 2331 | case "Positive_Case_DeviceDownInd": |
| 2332 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2333 | va.DeviceDownInd(tt.args.device) |
| 2334 | case "Negetive_Case_DeviceDownInd": |
| 2335 | va.DeviceDownInd(tt.args.device) |
| 2336 | } |
| 2337 | }) |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | func TestVoltApplication_DeviceRebootInd(t *testing.T) { |
| 2342 | type args struct { |
| 2343 | cntx context.Context |
| 2344 | device string |
| 2345 | serialNum string |
| 2346 | southBoundID string |
| 2347 | } |
| 2348 | voltDev := &VoltDevice{ |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2349 | Name: "SDX6320031", |
| 2350 | SerialNum: "SDX6320031", |
| 2351 | State: controller.DeviceStateREBOOTED, |
| 2352 | MigratingServices: util.NewConcurrentMap(), |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 2353 | } |
| 2354 | tests := []struct { |
| 2355 | name string |
| 2356 | args args |
| 2357 | }{ |
| 2358 | { |
| 2359 | name: "Positive_Case_DeviceRebootInd", |
| 2360 | args: args{ |
| 2361 | device: "SDX6320031", |
| 2362 | serialNum: "SDX6320031", |
| 2363 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2364 | }, |
| 2365 | }, |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2366 | { |
| 2367 | name: "Negetive_Case_DeviceRebootInd", |
| 2368 | args: args{ |
| 2369 | device: "SDX6320031", |
| 2370 | serialNum: "SDX6320031", |
| 2371 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2372 | }, |
| 2373 | }, |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 2374 | } |
| 2375 | for _, tt := range tests { |
| 2376 | t.Run(tt.name, func(t *testing.T) { |
| 2377 | va := &VoltApplication{ |
| 2378 | DevicesDisc: sync.Map{}, |
| 2379 | } |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2380 | switch tt.name { |
| 2381 | case "Positive_Case_DeviceRebootInd": |
| 2382 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2383 | va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID) |
| 2384 | case "Negetive_Case_DeviceRebootInd": |
| 2385 | voltDev.State = controller.DeviceStateDOWN |
| 2386 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2387 | GetApplication().DevicesDisc.Store("SDX6320031", voltDev) |
| 2388 | va.DeviceRebootInd(tt.args.cntx, tt.args.device, tt.args.serialNum, tt.args.southBoundID) |
| 2389 | } |
vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 2390 | }) |
| 2391 | } |
| 2392 | } |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2393 | |
| 2394 | func TestVoltApplication_GetDeviceFromPort(t *testing.T) { |
| 2395 | type args struct { |
| 2396 | port string |
| 2397 | } |
| 2398 | voltDev := &VoltDevice{ |
| 2399 | Name: "SDX6320031", |
| 2400 | SerialNum: "SDX6320031", |
| 2401 | NniDhcpTrapVid: 123, |
| 2402 | NniPort: "16777216", |
| 2403 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2404 | Ports: sync.Map{}, |
| 2405 | } |
| 2406 | voltPort := &VoltPort{ |
| 2407 | Name: "16777216", |
| 2408 | Device: "SDX6320031", |
| 2409 | ID: 16777216, |
| 2410 | State: PortStateDown, |
| 2411 | ChannelPerSubAlarmRaised: false, |
| 2412 | Type: VoltPortTypeNni, |
| 2413 | } |
| 2414 | tests := []struct { |
| 2415 | name string |
| 2416 | args args |
| 2417 | want *VoltDevice |
| 2418 | wantErr bool |
| 2419 | }{ |
| 2420 | { |
| 2421 | name: "Positive_Case_GetDeviceFromPort", |
| 2422 | args: args{ |
| 2423 | port: "16777216", |
| 2424 | }, |
| 2425 | want: voltDev, |
| 2426 | wantErr: false, |
| 2427 | }, |
| 2428 | } |
| 2429 | for _, tt := range tests { |
| 2430 | t.Run(tt.name, func(t *testing.T) { |
| 2431 | va := &VoltApplication{ |
| 2432 | DevicesDisc: sync.Map{}, |
| 2433 | PortsDisc: sync.Map{}, |
| 2434 | } |
| 2435 | va.PortsDisc.Store("16777216", voltPort) |
| 2436 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2437 | got, err := va.GetDeviceFromPort(tt.args.port) |
| 2438 | if (err != nil) != tt.wantErr { |
| 2439 | t.Errorf("VoltApplication.GetDeviceFromPort() error = %v, wantErr %v", err, tt.wantErr) |
| 2440 | return |
| 2441 | } |
| 2442 | if !reflect.DeepEqual(got, tt.want) { |
| 2443 | t.Errorf("VoltApplication.GetDeviceFromPort() = %v, want %v", got, tt.want) |
| 2444 | } |
| 2445 | }) |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | func TestVoltApplication_GetPortID(t *testing.T) { |
| 2450 | type args struct { |
| 2451 | port string |
| 2452 | } |
| 2453 | voltPort := &VoltPort{ |
| 2454 | Name: "16777216", |
| 2455 | Device: "SDX6320031", |
| 2456 | ID: 16777216, |
| 2457 | State: PortStateDown, |
| 2458 | ChannelPerSubAlarmRaised: false, |
| 2459 | Type: VoltPortTypeNni, |
| 2460 | } |
| 2461 | tests := []struct { |
| 2462 | name string |
| 2463 | args args |
| 2464 | want uint32 |
| 2465 | wantErr bool |
| 2466 | }{ |
| 2467 | { |
| 2468 | name: "Positive_Case_GetPortID", |
| 2469 | args: args{ |
| 2470 | port: "16777216", |
| 2471 | }, |
| 2472 | want: 16777216, |
| 2473 | wantErr: false, |
| 2474 | }, |
| 2475 | } |
| 2476 | for _, tt := range tests { |
| 2477 | t.Run(tt.name, func(t *testing.T) { |
| 2478 | va := &VoltApplication{ |
| 2479 | PortsDisc: sync.Map{}, |
| 2480 | } |
| 2481 | va.PortsDisc.Store("16777216", voltPort) |
| 2482 | got, err := va.GetPortID(tt.args.port) |
| 2483 | if (err != nil) != tt.wantErr { |
| 2484 | t.Errorf("VoltApplication.GetPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 2485 | return |
| 2486 | } |
| 2487 | if got != tt.want { |
| 2488 | t.Errorf("VoltApplication.GetPortID() = %v, want %v", got, tt.want) |
| 2489 | } |
| 2490 | }) |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | func TestVoltApplication_GetPortName(t *testing.T) { |
| 2495 | type args struct { |
| 2496 | port uint32 |
| 2497 | } |
| 2498 | voltPort := &VoltPort{ |
| 2499 | Name: "16777216", |
| 2500 | Device: "SDX6320031", |
| 2501 | ID: 16777216, |
| 2502 | State: PortStateDown, |
| 2503 | ChannelPerSubAlarmRaised: false, |
| 2504 | Type: VoltPortTypeNni, |
| 2505 | } |
| 2506 | tests := []struct { |
| 2507 | name string |
| 2508 | args args |
| 2509 | want string |
| 2510 | wantErr bool |
| 2511 | }{ |
| 2512 | { |
| 2513 | name: "Positive_Case_GetPortID", |
| 2514 | args: args{ |
| 2515 | port: 16777216, |
| 2516 | }, |
| 2517 | want: "16777216", |
| 2518 | wantErr: false, |
| 2519 | }, |
| 2520 | } |
| 2521 | for _, tt := range tests { |
| 2522 | t.Run(tt.name, func(t *testing.T) { |
| 2523 | va := &VoltApplication{ |
| 2524 | PortsDisc: sync.Map{}, |
| 2525 | } |
| 2526 | va.PortsDisc.Store("16777216", voltPort) |
| 2527 | got, err := va.GetPortName(tt.args.port) |
| 2528 | if (err != nil) != tt.wantErr { |
| 2529 | t.Errorf("VoltApplication.GetPortName() error = %v, wantErr %v", err, tt.wantErr) |
| 2530 | return |
| 2531 | } |
| 2532 | if got != tt.want { |
| 2533 | t.Errorf("VoltApplication.GetPortName() = %v, want %v", got, tt.want) |
| 2534 | } |
| 2535 | }) |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | func TestVoltApplication_PortUpInd(t *testing.T) { |
| 2540 | type args struct { |
| 2541 | cntx context.Context |
| 2542 | device string |
| 2543 | port string |
| 2544 | } |
| 2545 | voltDev := &VoltDevice{ |
| 2546 | Name: "SDX6320031", |
| 2547 | SerialNum: "SDX6320031", |
| 2548 | NniDhcpTrapVid: 123, |
| 2549 | NniPort: "16777472", |
| 2550 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2551 | Ports: sync.Map{}, |
| 2552 | VpvsBySvlan: util.NewConcurrentMap(), |
| 2553 | } |
| 2554 | voltPort := &VoltPort{ |
| 2555 | Name: "16777472", |
| 2556 | Device: "SDX6320031", |
| 2557 | ID: 16777472, |
| 2558 | State: PortStateUp, |
| 2559 | ChannelPerSubAlarmRaised: false, |
| 2560 | Type: VoltPortTypeNni, |
| 2561 | } |
| 2562 | voltServ := &VoltService{ |
| 2563 | VoltServiceOper: VoltServiceOper{ |
| 2564 | Device: "SDX6320031", |
| 2565 | }, |
| 2566 | VoltServiceCfg: VoltServiceCfg{ |
| 2567 | IsActivated: true, |
| 2568 | }, |
| 2569 | } |
| 2570 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 2571 | voltPortVnet := &VoltPortVnet{ |
| 2572 | Device: "SDX6320031", |
| 2573 | Port: "16777472", |
| 2574 | DeleteInProgress: false, |
| 2575 | services: sync.Map{}, |
| 2576 | SVlan: 4096, |
| 2577 | CVlan: 2310, |
| 2578 | UniVlan: 4096, |
| 2579 | SVlanTpid: 65, |
| 2580 | servicesCount: atomic.NewUint64(1), |
| 2581 | } |
| 2582 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 2583 | |
| 2584 | tests := []struct { |
| 2585 | name string |
| 2586 | args args |
| 2587 | }{ |
| 2588 | { |
| 2589 | name: "Positive_Case_PortUpInd", |
| 2590 | args: args{ |
| 2591 | cntx: context.Background(), |
| 2592 | port: "16777472", |
| 2593 | device: "SDX6320031", |
| 2594 | }, |
| 2595 | }, |
| 2596 | } |
| 2597 | for _, tt := range tests { |
| 2598 | t.Run(tt.name, func(t *testing.T) { |
| 2599 | va := &VoltApplication{ |
| 2600 | DevicesDisc: sync.Map{}, |
| 2601 | VnetsByPort: sync.Map{}, |
| 2602 | } |
| 2603 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2604 | voltDev.Ports.Store("16777472", voltPort) |
| 2605 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 2606 | voltPortVnet.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ) |
| 2607 | voltapp := GetApplication() |
| 2608 | voltapp.DevicesDisc.Store("SDX6320031", voltDev) |
| 2609 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2610 | db = dbintf |
| 2611 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2612 | va.PortUpInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 2613 | }) |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | func TestVoltApplication_PortDownInd(t *testing.T) { |
| 2618 | type args struct { |
| 2619 | cntx context.Context |
| 2620 | device string |
| 2621 | port string |
| 2622 | } |
| 2623 | voltDev := &VoltDevice{ |
| 2624 | Name: "SDX6320031", |
| 2625 | SerialNum: "SDX6320031", |
| 2626 | NniDhcpTrapVid: 123, |
| 2627 | NniPort: "16777472", |
| 2628 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2629 | Ports: sync.Map{}, |
| 2630 | VpvsBySvlan: util.NewConcurrentMap(), |
| 2631 | } |
| 2632 | voltPort := &VoltPort{ |
| 2633 | Name: "16777472", |
| 2634 | Device: "SDX6320031", |
| 2635 | ID: 16777472, |
| 2636 | State: PortStateDown, |
| 2637 | ChannelPerSubAlarmRaised: false, |
| 2638 | Type: VoltPortTypeNni, |
| 2639 | } |
| 2640 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 2641 | voltPortVnet := &VoltPortVnet{ |
| 2642 | Device: "SDX6320031", |
| 2643 | Port: "16777472", |
| 2644 | DeleteInProgress: false, |
| 2645 | services: sync.Map{}, |
| 2646 | SVlan: 4096, |
| 2647 | CVlan: 2310, |
| 2648 | UniVlan: 4096, |
| 2649 | SVlanTpid: 65, |
| 2650 | servicesCount: atomic.NewUint64(1), |
| 2651 | } |
| 2652 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 2653 | tests := []struct { |
| 2654 | name string |
| 2655 | args args |
| 2656 | }{ |
| 2657 | { |
| 2658 | name: "Positive_Case_PortDownInd", |
| 2659 | args: args{ |
| 2660 | cntx: context.Background(), |
| 2661 | port: "16777472", |
| 2662 | device: "SDX6320031", |
| 2663 | }, |
| 2664 | }, |
| 2665 | } |
| 2666 | for _, tt := range tests { |
| 2667 | t.Run(tt.name, func(t *testing.T) { |
| 2668 | va := &VoltApplication{} |
| 2669 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2670 | voltDev.Ports.Store("16777472", voltPort) |
| 2671 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 2672 | voltApp := GetApplication() |
| 2673 | voltApp.DevicesDisc.Store("SDX6320031", voltDev) |
| 2674 | va.PortDownInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 2675 | }) |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | func TestVoltApplication_UpdateDeviceSerialNumberList(t *testing.T) { |
| 2680 | type args struct { |
| 2681 | oldOltSlNo string |
| 2682 | newOltSlNo string |
| 2683 | } |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2684 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 2685 | controller.NewController(ctx, appMock) |
| 2686 | devicelist := []string{ |
| 2687 | "SDX6320030", |
| 2688 | "SDX6320031", |
| 2689 | } |
| 2690 | voltVnet := &VoltVnet{ |
| 2691 | Version: "v3", |
| 2692 | VnetConfig: VnetConfig{ |
| 2693 | Name: "2310-4096-4096", |
| 2694 | VnetType: "Encapsulation", |
| 2695 | SVlan: 2310, |
| 2696 | CVlan: 4096, |
| 2697 | UniVlan: 4096, |
| 2698 | SVlanTpid: 33024, |
| 2699 | DevicesList: devicelist, |
| 2700 | }, |
| 2701 | } |
| 2702 | devicesList := make(map[string]OperInProgress) |
| 2703 | devicesList["SDX6320030"] = opt82 |
| 2704 | mvp := &MvlanProfile{ |
| 2705 | Name: "mvlan_test", |
| 2706 | DevicesList: devicesList, |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2707 | } |
| 2708 | tests := []struct { |
| 2709 | name string |
| 2710 | args args |
| 2711 | }{ |
| 2712 | { |
| 2713 | name: "Positive_Case_UpdateDeviceSerialNumberList", |
| 2714 | args: args{ |
| 2715 | oldOltSlNo: "SDX6320030", |
| 2716 | newOltSlNo: "SDX6320031", |
| 2717 | }, |
| 2718 | }, |
| 2719 | } |
| 2720 | for _, tt := range tests { |
| 2721 | t.Run(tt.name, func(t *testing.T) { |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2722 | va := &VoltApplication{ |
| 2723 | VnetsByName: sync.Map{}, |
| 2724 | MvlanProfilesByName: sync.Map{}, |
| 2725 | } |
| 2726 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 2727 | va.MvlanProfilesByName.Store("mvlan_test", mvp) |
vinokuma | 02fbfd0 | 2023-07-05 15:23:33 +0530 | [diff] [blame] | 2728 | va.UpdateDeviceSerialNumberList(tt.args.oldOltSlNo, tt.args.newOltSlNo) |
| 2729 | }) |
| 2730 | } |
| 2731 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2732 | |
| 2733 | func TestVoltApplication_DeleteMacInPortMap(t *testing.T) { |
| 2734 | type args struct { |
| 2735 | macAddr net.HardwareAddr |
| 2736 | } |
| 2737 | |
| 2738 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 2739 | macPort := map[string]string{} |
| 2740 | macPort[macAdd.String()] = test_data |
| 2741 | |
| 2742 | tests := []struct { |
| 2743 | name string |
| 2744 | args args |
| 2745 | }{ |
| 2746 | { |
| 2747 | name: "Positive_Case_DeleteMacInPortMap", |
| 2748 | args: args{ |
| 2749 | macAddr: macAdd, |
| 2750 | }, |
| 2751 | }, |
| 2752 | } |
| 2753 | for _, tt := range tests { |
| 2754 | t.Run(tt.name, func(t *testing.T) { |
| 2755 | va := &VoltApplication{ |
| 2756 | macPortMap: macPort, |
| 2757 | } |
| 2758 | va.DeleteMacInPortMap(tt.args.macAddr) |
| 2759 | }) |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | func TestVoltApplication_TriggerPendingServiceDeactivateReq(t *testing.T) { |
| 2764 | type args struct { |
| 2765 | cntx context.Context |
| 2766 | device string |
| 2767 | } |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2768 | |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2769 | voltServ := &VoltService{ |
| 2770 | VoltServiceOper: VoltServiceOper{ |
| 2771 | Device: "SDX6320031", |
| 2772 | }, |
| 2773 | VoltServiceCfg: VoltServiceCfg{ |
| 2774 | Name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65", |
| 2775 | SVlan: 4096, |
| 2776 | CVlan: 2310, |
| 2777 | UniVlan: 4096, |
| 2778 | Port: "16777472", |
| 2779 | TechProfileID: 65, |
| 2780 | }, |
| 2781 | } |
| 2782 | |
| 2783 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 2784 | voltPortVnet := &VoltPortVnet{ |
| 2785 | Device: "SDX6320031", |
| 2786 | Port: "16777472", |
| 2787 | DeleteInProgress: false, |
| 2788 | services: sync.Map{}, |
| 2789 | SVlan: 4096, |
| 2790 | CVlan: 2310, |
| 2791 | UniVlan: 4096, |
| 2792 | SVlanTpid: 65, |
| 2793 | servicesCount: atomic.NewUint64(1), |
| 2794 | } |
| 2795 | |
| 2796 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 2797 | tests := []struct { |
| 2798 | name string |
| 2799 | args args |
| 2800 | }{ |
| 2801 | { |
| 2802 | name: "Positive_Case_DeleteMacInPortMap", |
| 2803 | args: args{ |
| 2804 | cntx: context.Background(), |
| 2805 | device: "SDX6320031", |
| 2806 | }, |
| 2807 | }, |
| 2808 | } |
| 2809 | |
| 2810 | for _, tt := range tests { |
| 2811 | t.Run(tt.name, func(t *testing.T) { |
| 2812 | va := &VoltApplication{ |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2813 | ServicesToDeactivate: sync.Map{}, |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2814 | ServiceByName: sync.Map{}, |
| 2815 | VnetsByPort: sync.Map{}, |
| 2816 | } |
| 2817 | va.ServiceByName.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ) |
| 2818 | va.VnetsByPort.Store("16777472", voltPortVnets) |
Akash Soni | ef452f1 | 2024-12-12 18:20:28 +0530 | [diff] [blame] | 2819 | va.ServicesToDeactivate.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", true) |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2820 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2821 | db = dbintf |
| 2822 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2823 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 2824 | va.TriggerPendingServiceDeactivateReq(tt.args.cntx, tt.args.device) |
| 2825 | }) |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | func TestVoltApplication_ReadAllFromDb(t *testing.T) { |
| 2830 | type args struct { |
| 2831 | cntx context.Context |
| 2832 | } |
| 2833 | |
| 2834 | migrationInfo := "migration done" |
| 2835 | deviceConfig := DeviceConfig{ |
| 2836 | SerialNumber: "SDX6320031", |
| 2837 | UplinkPort: "16777472", |
| 2838 | HardwareIdentifier: "0.0.0.0", |
| 2839 | IPAddress: "127.26.1.74", |
| 2840 | NasID: "12345", |
| 2841 | NniDhcpTrapVid: 123, |
| 2842 | } |
| 2843 | |
| 2844 | voltVnet := &VoltVnet{ |
| 2845 | Version: "v3", |
| 2846 | VnetConfig: VnetConfig{ |
| 2847 | Name: "2310-4096-4096", |
| 2848 | VnetType: "Encapsulation", |
| 2849 | SVlan: 2310, |
| 2850 | CVlan: 4096, |
| 2851 | UniVlan: 4096, |
| 2852 | SVlanTpid: 33024, |
| 2853 | }, |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2854 | VnetOper: VnetOper{ |
| 2855 | PendingDeviceToDelete: "SDX6320031", |
| 2856 | DeleteInProgress: true, |
| 2857 | }, |
| 2858 | } |
| 2859 | |
| 2860 | cuncurrentMap := &util.ConcurrentMap{ |
| 2861 | Count: atomic.NewUint64(0), |
| 2862 | } |
| 2863 | |
| 2864 | vnetToDelete := map[string]bool{} |
| 2865 | vnetToDelete["2310-4096-4096"] = true |
| 2866 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 2867 | voltPortVnet := &VoltPortVnet{ |
| 2868 | Device: "SDX6320031", |
| 2869 | Port: "16777472", |
| 2870 | DeleteInProgress: true, |
| 2871 | MacAddr: macAdd, |
| 2872 | } |
| 2873 | |
| 2874 | macPortMap := map[string]string{} |
| 2875 | voltPortVnetsToDelete := map[*VoltPortVnet]bool{} |
| 2876 | voltPortVnetsToDelete[voltPortVnet] = true |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2877 | macPortMap[macAdd.String()] = voltPortVnet.Port |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2878 | |
| 2879 | tests := []struct { |
| 2880 | name string |
| 2881 | args args |
| 2882 | }{ |
| 2883 | { |
| 2884 | name: "Positive_Case_ReadAllFromDb", |
| 2885 | args: args{ |
| 2886 | cntx: context.Background(), |
| 2887 | }, |
| 2888 | }, |
| 2889 | } |
| 2890 | |
| 2891 | for _, tt := range tests { |
| 2892 | t.Run(tt.name, func(t *testing.T) { |
| 2893 | va := &VoltApplication{ |
| 2894 | VnetsBySvlan: util.NewConcurrentMap(), |
| 2895 | VnetsToDelete: vnetToDelete, |
| 2896 | macPortMap: macPortMap, |
| 2897 | VoltPortVnetsToDelete: voltPortVnetsToDelete, |
| 2898 | VnetsByName: sync.Map{}, |
| 2899 | } |
| 2900 | |
| 2901 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 2902 | db = dbintf |
| 2903 | dbintf.EXPECT().GetMeters(gomock.Any()).AnyTimes() |
| 2904 | vnet, _ := json.Marshal(voltVnet) |
| 2905 | voltVnets := map[string]*kvstore.KVPair{} |
| 2906 | voltVnets["2310-4096-4096"] = &kvstore.KVPair{ |
| 2907 | Key: "2310-4096-4096", |
| 2908 | Value: vnet, |
| 2909 | } |
| 2910 | |
| 2911 | va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap) |
| 2912 | dbintf.EXPECT().GetVnets(gomock.Any()).AnyTimes().Return(voltVnets, nil).AnyTimes() |
| 2913 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes() |
| 2914 | vpvs, _ := json.Marshal(voltPortVnet) |
| 2915 | voltPort := map[string]*kvstore.KVPair{} |
| 2916 | voltPort["16777472"] = &kvstore.KVPair{ |
| 2917 | Key: "16777472", |
| 2918 | Value: vpvs, |
| 2919 | } |
| 2920 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 2921 | dbintf.EXPECT().GetVpvs(gomock.Any()).AnyTimes().Return(voltPort, nil).AnyTimes() |
| 2922 | dbintf.EXPECT().GetServices(gomock.Any()).AnyTimes() |
| 2923 | dbintf.EXPECT().GetMvlans(gomock.Any()).AnyTimes() |
| 2924 | dbintf.EXPECT().GetIgmpProfiles(gomock.Any()).AnyTimes() |
| 2925 | dbintf.EXPECT().GetMcastConfigs(gomock.Any()).AnyTimes() |
| 2926 | dbintf.EXPECT().GetIgmpGroups(gomock.Any()).AnyTimes() |
| 2927 | dbintf.EXPECT().GetMigrationInfo(gomock.Any()).Return(migrationInfo, nil).AnyTimes() |
| 2928 | dbintf.EXPECT().GetOltFlowService(gomock.Any()).AnyTimes() |
| 2929 | b, _ := json.Marshal(deviceConfig) |
| 2930 | test := map[string]*kvstore.KVPair{} |
| 2931 | test["SDX6320031"] = &kvstore.KVPair{ |
| 2932 | Key: "SDX6320031", |
| 2933 | Value: b, |
| 2934 | } |
| 2935 | dbintf.EXPECT().GetDeviceConfig(gomock.Any()).Return(test, nil).AnyTimes() |
| 2936 | dbintf.EXPECT().PutDeviceConfig(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 2937 | va.ReadAllFromDb(tt.args.cntx) |
| 2938 | }) |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | func TestVoltApplication_RemoveGroupDevicesFromPendingPool(t *testing.T) { |
| 2943 | type args struct { |
| 2944 | ig *IgmpGroup |
| 2945 | } |
| 2946 | pendingGroupForDevice := map[string]time.Time{} |
| 2947 | pendingGroupForDevice[test_device] = time.Now() |
| 2948 | tests := []struct { |
| 2949 | name string |
| 2950 | args args |
| 2951 | }{ |
| 2952 | { |
| 2953 | name: "VoltApplication_RemoveGroupDevicesFromPendingPool", |
| 2954 | args: args{ |
| 2955 | ig: &IgmpGroup{ |
| 2956 | Version: "test_version", |
| 2957 | PendingGroupForDevice: pendingGroupForDevice, |
| 2958 | }, |
| 2959 | }, |
| 2960 | }, |
| 2961 | } |
| 2962 | for _, tt := range tests { |
| 2963 | t.Run(tt.name, func(t *testing.T) { |
| 2964 | va := &VoltApplication{} |
| 2965 | va.RemoveGroupDevicesFromPendingPool(tt.args.ig) |
| 2966 | }) |
| 2967 | } |
| 2968 | } |
Akash Soni | 6f36945 | 2023-09-19 11:18:28 +0530 | [diff] [blame] | 2969 | |
| 2970 | func TestVoltDevice_AddPort(t *testing.T) { |
| 2971 | type args struct { |
| 2972 | port string |
| 2973 | id uint32 |
| 2974 | } |
| 2975 | |
| 2976 | voltPort := &VoltPort{ |
| 2977 | Name: "16777472", |
| 2978 | ID: uint32(256), |
| 2979 | } |
| 2980 | tests := []struct { |
| 2981 | name string |
| 2982 | args args |
| 2983 | want *VoltPort |
| 2984 | }{ |
| 2985 | { |
| 2986 | name: "VoltApplication_AddPort", |
| 2987 | args: args{ |
| 2988 | port: "16777472", |
| 2989 | id: uint32(256), |
| 2990 | }, |
| 2991 | want: voltPort, |
| 2992 | }, |
| 2993 | } |
| 2994 | for _, tt := range tests { |
| 2995 | t.Run(tt.name, func(t *testing.T) { |
| 2996 | d := &VoltDevice{} |
| 2997 | if got := d.AddPort(tt.args.port, tt.args.id); !reflect.DeepEqual(got, tt.want) { |
| 2998 | t.Errorf("VoltDevice.AddPort() = %v, want %v", got, tt.want) |
| 2999 | } |
| 3000 | }) |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | func TestVoltApplication_GetAvailIgmpGroupID(t *testing.T) { |
| 3005 | IgmpGroupIds := []*IgmpGroup{} |
| 3006 | group := &IgmpGroup{ |
| 3007 | GroupName: "group1", |
| 3008 | GroupID: uint32(256), |
| 3009 | } |
| 3010 | IgmpGroupIds = append(IgmpGroupIds, group) |
| 3011 | tests := []struct { |
| 3012 | name string |
| 3013 | want *IgmpGroup |
| 3014 | }{ |
| 3015 | { |
| 3016 | name: "VoltApplication_GetAvailIgmpGroupID", |
| 3017 | want: group, |
| 3018 | }, |
| 3019 | { |
| 3020 | name: "VoltApplication_GetAvailIgmpGroupID_Nil", |
| 3021 | want: group, |
| 3022 | }, |
| 3023 | } |
| 3024 | for _, tt := range tests { |
| 3025 | t.Run(tt.name, func(t *testing.T) { |
| 3026 | switch tt.name { |
| 3027 | case "VoltApplication_GetAvailIgmpGroupID": |
| 3028 | va := &VoltApplication{ |
| 3029 | IgmpGroupIds: IgmpGroupIds, |
| 3030 | } |
| 3031 | got := va.GetAvailIgmpGroupID() |
| 3032 | assert.NotNil(t, got) |
| 3033 | case "VoltApplication_GetAvailIgmpGroupID_Nil": |
| 3034 | va := &VoltApplication{} |
| 3035 | got := va.GetAvailIgmpGroupID() |
| 3036 | assert.Nil(t, got) |
| 3037 | } |
| 3038 | }) |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | func TestVoltApplication_GetIgmpGroupID(t *testing.T) { |
| 3043 | type args struct { |
| 3044 | gid uint32 |
| 3045 | } |
| 3046 | IgmpGroupIds := []*IgmpGroup{} |
| 3047 | group := &IgmpGroup{ |
| 3048 | GroupName: "group1", |
| 3049 | GroupID: uint32(256), |
| 3050 | } |
| 3051 | IgmpGroupIds = append(IgmpGroupIds, group) |
| 3052 | tests := []struct { |
| 3053 | name string |
| 3054 | args args |
| 3055 | want *IgmpGroup |
| 3056 | wantErr bool |
| 3057 | }{ |
| 3058 | { |
| 3059 | name: "VoltApplication_GetIgmpGroupID", |
| 3060 | args: args{ |
| 3061 | gid: uint32(256), |
| 3062 | }, |
| 3063 | want: group, |
| 3064 | wantErr: false, |
| 3065 | }, |
| 3066 | { |
| 3067 | name: "VoltApplication_GetIgmpGroupID_Error", |
| 3068 | args: args{ |
| 3069 | gid: uint32(256), |
| 3070 | }, |
| 3071 | want: group, |
| 3072 | wantErr: true, |
| 3073 | }, |
| 3074 | } |
| 3075 | va := &VoltApplication{} |
| 3076 | for _, tt := range tests { |
| 3077 | t.Run(tt.name, func(t *testing.T) { |
| 3078 | switch tt.name { |
| 3079 | case "VoltApplication_GetIgmpGroupID": |
| 3080 | va = &VoltApplication{ |
| 3081 | IgmpGroupIds: IgmpGroupIds, |
| 3082 | } |
| 3083 | got, err := va.GetIgmpGroupID(tt.args.gid) |
| 3084 | if (err != nil) != tt.wantErr { |
| 3085 | t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr) |
| 3086 | return |
| 3087 | } |
| 3088 | if !reflect.DeepEqual(got, tt.want) { |
| 3089 | t.Errorf("VoltApplication.GetIgmpGroupID() = %v, want %v", got, tt.want) |
| 3090 | } |
| 3091 | case "VoltApplication_GetIgmpGroupID_Error": |
| 3092 | got, err := va.GetIgmpGroupID(tt.args.gid) |
| 3093 | if (err != nil) != tt.wantErr { |
| 3094 | t.Errorf("VoltApplication.GetIgmpGroupID() error = %v, wantErr %v", err, tt.wantErr) |
| 3095 | return |
| 3096 | } |
| 3097 | assert.Nil(t, got) |
| 3098 | } |
| 3099 | }) |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | func TestVoltApplication_PutIgmpGroupID(t *testing.T) { |
| 3104 | type args struct { |
| 3105 | ig *IgmpGroup |
| 3106 | } |
| 3107 | group := &IgmpGroup{ |
| 3108 | GroupName: "group1", |
| 3109 | GroupID: uint32(256), |
| 3110 | } |
| 3111 | tests := []struct { |
| 3112 | name string |
| 3113 | args args |
| 3114 | }{ |
| 3115 | { |
| 3116 | name: "VoltApplication_GetIgmpGroupID", |
| 3117 | args: args{ |
| 3118 | ig: group, |
| 3119 | }, |
| 3120 | }, |
| 3121 | } |
| 3122 | for _, tt := range tests { |
| 3123 | t.Run(tt.name, func(t *testing.T) { |
| 3124 | va := &VoltApplication{} |
| 3125 | va.PutIgmpGroupID(tt.args.ig) |
| 3126 | }) |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | func TestVoltApplication_PortDelInd(t *testing.T) { |
| 3131 | type args struct { |
| 3132 | cntx context.Context |
| 3133 | device string |
| 3134 | port string |
| 3135 | } |
| 3136 | voltDev := &VoltDevice{ |
| 3137 | Name: "49686e2d-618f-4e8e-bca0", |
| 3138 | SerialNum: "SDX6320031", |
| 3139 | NniDhcpTrapVid: 123, |
| 3140 | NniPort: "16777472", |
| 3141 | SouthBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 3142 | Ports: sync.Map{}, |
| 3143 | VpvsBySvlan: util.NewConcurrentMap(), |
| 3144 | } |
| 3145 | |
| 3146 | voltPort := &VoltPort{ |
| 3147 | Name: "16777472", |
| 3148 | Device: "SDX6320031", |
| 3149 | ID: 16777472, |
| 3150 | State: PortStateUp, |
| 3151 | ChannelPerSubAlarmRaised: false, |
| 3152 | } |
| 3153 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 3154 | voltPortVnet := &VoltPortVnet{ |
| 3155 | Device: "SDX6320031", |
| 3156 | Port: "16777472", |
| 3157 | DeleteInProgress: true, |
| 3158 | servicesCount: atomic.NewUint64(0), |
| 3159 | } |
| 3160 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 3161 | |
| 3162 | tests := []struct { |
| 3163 | name string |
| 3164 | args args |
| 3165 | }{ |
| 3166 | { |
| 3167 | name: "VoltApplication_PortDelInd", |
| 3168 | args: args{ |
| 3169 | cntx: context.Background(), |
| 3170 | device: "SDX6320031", |
| 3171 | port: "16777472", |
| 3172 | }, |
| 3173 | }, |
| 3174 | { |
| 3175 | name: "PortDelInd_Device_Not_Found", |
| 3176 | args: args{ |
| 3177 | cntx: context.Background(), |
| 3178 | device: "SDX6320032", |
| 3179 | port: "16777472", |
| 3180 | }, |
| 3181 | }, |
| 3182 | { |
| 3183 | name: "PortDelInd_VnetsByPort_Nil", |
| 3184 | args: args{ |
| 3185 | cntx: context.Background(), |
| 3186 | device: "SDX6320031", |
| 3187 | port: "16777472", |
| 3188 | }, |
| 3189 | }, |
| 3190 | } |
| 3191 | for _, tt := range tests { |
| 3192 | t.Run(tt.name, func(t *testing.T) { |
| 3193 | switch tt.name { |
| 3194 | case "VoltApplication_PortDelInd", "PortDelInd_Device_Not_Found": |
| 3195 | va := &VoltApplication{ |
| 3196 | DevicesDisc: sync.Map{}, |
| 3197 | PortsDisc: sync.Map{}, |
| 3198 | } |
| 3199 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3200 | va.PortsDisc.Store("16777472", voltPort) |
| 3201 | voltDev.Ports.Store("16777472", voltPort) |
| 3202 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 3203 | va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 3204 | case "PortDelInd_VnetsByPort_Nil": |
| 3205 | va := &VoltApplication{ |
| 3206 | DevicesDisc: sync.Map{}, |
| 3207 | PortsDisc: sync.Map{}, |
| 3208 | } |
| 3209 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3210 | va.PortsDisc.Store("16777472", voltPort) |
| 3211 | voltDev.Ports.Store("16777472", voltPort) |
| 3212 | va.PortDelInd(tt.args.cntx, tt.args.device, tt.args.port) |
| 3213 | } |
| 3214 | }) |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | func TestVoltApplication_GetGroupFromPendingPool(t *testing.T) { |
| 3219 | type args struct { |
| 3220 | mvlan of.VlanType |
| 3221 | device string |
| 3222 | } |
| 3223 | igmpPendingPool := map[string]map[*IgmpGroup]bool{} |
| 3224 | devices := map[string]*IgmpGroupDevice{} |
| 3225 | igmpGroup := map[*IgmpGroup]bool{} |
| 3226 | igmpDevice := &IgmpGroupDevice{ |
| 3227 | Device: "SDX6320031", |
| 3228 | SerialNo: "SDX6320032", |
| 3229 | GroupName: "group1", |
| 3230 | Mvlan: of.VlanAny, |
| 3231 | } |
| 3232 | devices["SDX6320031"] = igmpDevice |
| 3233 | group := &IgmpGroup{ |
| 3234 | GroupName: "group1", |
| 3235 | GroupID: uint32(256), |
| 3236 | Mvlan: of.VlanAny, |
| 3237 | Devices: devices, |
| 3238 | } |
| 3239 | |
| 3240 | igmpGroup[group] = true |
| 3241 | igmpPendingPool["4096_SDX6320031"] = igmpGroup |
| 3242 | tests := []struct { |
| 3243 | name string |
| 3244 | args args |
| 3245 | want *IgmpGroup |
| 3246 | }{ |
| 3247 | { |
| 3248 | name: "GetGroupFromPendingPool", |
| 3249 | args: args{ |
| 3250 | device: "SDX6320031", |
| 3251 | mvlan: of.VlanAny, |
| 3252 | }, |
| 3253 | want: nil, |
| 3254 | }, |
| 3255 | } |
| 3256 | for _, tt := range tests { |
| 3257 | t.Run(tt.name, func(t *testing.T) { |
| 3258 | va := &VoltApplication{ |
| 3259 | IgmpPendingPool: igmpPendingPool, |
| 3260 | } |
| 3261 | if got := va.GetGroupFromPendingPool(tt.args.mvlan, tt.args.device); !reflect.DeepEqual(got, tt.want) { |
| 3262 | t.Errorf("VoltApplication.GetGroupFromPendingPool() = %v, want %v", got, tt.want) |
| 3263 | } |
| 3264 | }) |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | func TestVoltApplication_RemoveGroupsFromPendingPool(t *testing.T) { |
| 3269 | type args struct { |
| 3270 | cntx context.Context |
| 3271 | device string |
| 3272 | mvlan of.VlanType |
| 3273 | } |
| 3274 | tests := []struct { |
| 3275 | name string |
| 3276 | args args |
| 3277 | }{ |
| 3278 | { |
| 3279 | name: "PortDelInd_RemoveGroupsFromPendingPool", |
| 3280 | args: args{ |
| 3281 | cntx: context.Background(), |
| 3282 | device: "SDX6320031", |
| 3283 | mvlan: of.VlanAny, |
| 3284 | }, |
| 3285 | }, |
| 3286 | } |
| 3287 | for _, tt := range tests { |
| 3288 | t.Run(tt.name, func(t *testing.T) { |
| 3289 | va := &VoltApplication{ |
| 3290 | IgmpPendingPool: make(map[string]map[*IgmpGroup]bool), |
| 3291 | } |
| 3292 | va.RemoveGroupsFromPendingPool(tt.args.cntx, tt.args.device, tt.args.mvlan) |
| 3293 | }) |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | func TestVoltApplication_AddGroupToPendingPool(t *testing.T) { |
| 3298 | type fields struct{} |
| 3299 | type args struct { |
| 3300 | ig *IgmpGroup |
| 3301 | } |
| 3302 | devices := map[string]*IgmpGroupDevice{} |
| 3303 | igmpDevice := &IgmpGroupDevice{ |
| 3304 | Device: "SDX6320031", |
| 3305 | SerialNo: "SDX6320032", |
| 3306 | GroupName: "group1", |
| 3307 | Mvlan: of.VlanAny, |
| 3308 | } |
| 3309 | devices["SDX6320031"] = igmpDevice |
| 3310 | group := &IgmpGroup{ |
| 3311 | GroupName: "group1", |
| 3312 | GroupID: uint32(256), |
| 3313 | Devices: devices, |
| 3314 | } |
| 3315 | tests := []struct { |
| 3316 | name string |
| 3317 | fields fields |
| 3318 | args args |
| 3319 | }{ |
| 3320 | { |
| 3321 | name: "AddGroupToPendingPool", |
| 3322 | args: args{ |
| 3323 | ig: group, |
| 3324 | }, |
| 3325 | }, |
| 3326 | } |
| 3327 | for _, tt := range tests { |
| 3328 | t.Run(tt.name, func(t *testing.T) { |
| 3329 | va := &VoltApplication{ |
| 3330 | IgmpPendingPool: make(map[string]map[*IgmpGroup]bool), |
| 3331 | } |
| 3332 | va.AddGroupToPendingPool(tt.args.ig) |
| 3333 | }) |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | func TestVoltApplication_removeExpiredGroups(t *testing.T) { |
| 3338 | type args struct { |
| 3339 | cntx context.Context |
| 3340 | } |
| 3341 | group := &IgmpGroup{ |
| 3342 | GroupName: "group1", |
| 3343 | GroupID: uint32(256), |
| 3344 | } |
| 3345 | tests := []struct { |
| 3346 | name string |
| 3347 | args args |
| 3348 | }{ |
| 3349 | { |
| 3350 | name: "removeExpiredGroups", |
| 3351 | args: args{ |
| 3352 | cntx: context.Background(), |
| 3353 | }, |
| 3354 | }, |
| 3355 | } |
| 3356 | for _, tt := range tests { |
| 3357 | t.Run(tt.name, func(t *testing.T) { |
| 3358 | va := &VoltApplication{ |
| 3359 | IgmpGroups: sync.Map{}, |
| 3360 | } |
| 3361 | va.IgmpGroups.Store("group1", group) |
| 3362 | va.removeExpiredGroups(tt.args.cntx) |
| 3363 | }) |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | func TestVoltApplication_GetTaskList(t *testing.T) { |
| 3368 | type args struct { |
| 3369 | device string |
| 3370 | } |
| 3371 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 3372 | controller.NewController(ctx, appMock) |
| 3373 | device := &controller.Device{ |
| 3374 | ID: "SDX6320031", |
| 3375 | } |
| 3376 | dev := map[string]*controller.Device{} |
| 3377 | dev["SDX6320031"] = device |
| 3378 | tests := []struct { |
| 3379 | name string |
| 3380 | args args |
| 3381 | want map[int]*TaskInfo |
| 3382 | }{ |
| 3383 | { |
| 3384 | name: "GetTaskList", |
| 3385 | args: args{ |
| 3386 | device: "SDX6320031", |
| 3387 | }, |
| 3388 | want: map[int]*TaskInfo{}, |
| 3389 | }, |
| 3390 | } |
| 3391 | for _, tt := range tests { |
| 3392 | t.Run(tt.name, func(t *testing.T) { |
| 3393 | va := &VoltApplication{} |
| 3394 | if got := va.GetTaskList(tt.args.device); !reflect.DeepEqual(got, tt.want) { |
| 3395 | t.Errorf("VoltApplication.GetTaskList() = %v, want %v", got, tt.want) |
| 3396 | } |
| 3397 | }) |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | func TestVoltApplication_UpdateMvlanProfilesForDevice(t *testing.T) { |
| 3402 | type args struct { |
| 3403 | cntx context.Context |
| 3404 | device string |
| 3405 | } |
| 3406 | devicesList := make(map[string]OperInProgress) |
| 3407 | devicesList["SDX6320031"] = UpdateInProgress |
| 3408 | mvp := &MvlanProfile{ |
| 3409 | Name: "mvlan_test", |
| 3410 | DevicesList: devicesList, |
| 3411 | } |
| 3412 | voltDev := &VoltDevice{ |
| 3413 | SerialNum: "SDX6320031", |
| 3414 | } |
| 3415 | tests := []struct { |
| 3416 | name string |
| 3417 | args args |
| 3418 | }{ |
| 3419 | { |
| 3420 | name: "UpdateMvlanProfilesForDevice", |
| 3421 | args: args{ |
| 3422 | cntx: context.Background(), |
| 3423 | device: "SDX6320031", |
| 3424 | }, |
| 3425 | }, |
| 3426 | } |
| 3427 | for _, tt := range tests { |
| 3428 | t.Run(tt.name, func(t *testing.T) { |
| 3429 | va := &VoltApplication{ |
| 3430 | DevicesDisc: sync.Map{}, |
| 3431 | MvlanProfilesByName: sync.Map{}, |
| 3432 | } |
| 3433 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 3434 | db = dbintf |
| 3435 | dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 3436 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3437 | va.MvlanProfilesByName.Store("mvlan_test", mvp) |
| 3438 | va.UpdateMvlanProfilesForDevice(tt.args.cntx, tt.args.device) |
| 3439 | }) |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | func TestVoltApplication_HandleFlowClearFlag(t *testing.T) { |
| 3444 | type args struct { |
| 3445 | cntx context.Context |
| 3446 | deviceID string |
| 3447 | serialNum string |
| 3448 | southBoundID string |
| 3449 | } |
| 3450 | mblan := map[uint16]bool{} |
| 3451 | mblan[uint16(256)] = true |
| 3452 | voltDev := &VoltDevice{ |
| 3453 | SerialNum: "SDX6320031", |
| 3454 | MigratingServices: util.NewConcurrentMap(), |
| 3455 | IgmpDsFlowAppliedForMvlan: mblan, |
| 3456 | } |
| 3457 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 3458 | voltPortVnet := &VoltPortVnet{ |
| 3459 | Device: "SDX6320031", |
| 3460 | Port: "16777472", |
| 3461 | DeleteInProgress: true, |
| 3462 | servicesCount: atomic.NewUint64(0), |
| 3463 | IgmpEnabled: true, |
| 3464 | } |
| 3465 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 3466 | tests := []struct { |
| 3467 | name string |
| 3468 | args args |
| 3469 | }{ |
| 3470 | { |
| 3471 | name: "HandleFlowClearFlag", |
| 3472 | args: args{ |
| 3473 | cntx: context.Background(), |
| 3474 | deviceID: "SDX6320031", |
| 3475 | serialNum: "SDX6320031", |
| 3476 | southBoundID: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 3477 | }, |
| 3478 | }, |
| 3479 | } |
| 3480 | for _, tt := range tests { |
| 3481 | t.Run(tt.name, func(t *testing.T) { |
| 3482 | va := &VoltApplication{ |
| 3483 | DevicesDisc: sync.Map{}, |
| 3484 | VnetsByPort: sync.Map{}, |
| 3485 | } |
| 3486 | GetApplication().DevicesDisc.Store("SDX6320031", voltDev) |
| 3487 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3488 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 3489 | va.HandleFlowClearFlag(tt.args.cntx, tt.args.deviceID, tt.args.serialNum, tt.args.southBoundID) |
| 3490 | }) |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | func TestVoltApplication_PacketInInd(t *testing.T) { |
| 3495 | type args struct { |
| 3496 | cntx context.Context |
| 3497 | device string |
| 3498 | port string |
| 3499 | pkt []byte |
| 3500 | } |
| 3501 | tests := []struct { |
| 3502 | name string |
| 3503 | args args |
| 3504 | }{ |
| 3505 | { |
| 3506 | name: "PacketInInd", |
| 3507 | args: args{ |
| 3508 | cntx: context.Background(), |
| 3509 | }, |
| 3510 | }, |
| 3511 | } |
| 3512 | for _, tt := range tests { |
| 3513 | t.Run(tt.name, func(t *testing.T) { |
| 3514 | va := &VoltApplication{} |
| 3515 | va.PacketInInd(tt.args.cntx, tt.args.device, tt.args.port, tt.args.pkt) |
| 3516 | }) |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | func TestReceiverUpInd(t *testing.T) { |
| 3521 | type args struct { |
| 3522 | key interface{} |
| 3523 | value interface{} |
| 3524 | } |
| 3525 | voltServ := &VoltService{ |
| 3526 | VoltServiceOper: VoltServiceOper{ |
| 3527 | Device: "SCOM00001c75", |
| 3528 | Ipv4Addr: AllSystemsMulticastGroupIP, |
| 3529 | Ipv6Addr: AllSystemsMulticastGroupIP, |
| 3530 | }, |
| 3531 | VoltServiceCfg: VoltServiceCfg{ |
| 3532 | IgmpEnabled: true, |
| 3533 | VlanControl: ONUCVlan, |
| 3534 | Port: "16777472", |
| 3535 | }, |
| 3536 | } |
| 3537 | voltDev := &VoltDevice{ |
| 3538 | Name: "SCOM00001c75", |
| 3539 | SerialNum: "SCOM00001c75", |
| 3540 | Ports: sync.Map{}, |
| 3541 | } |
| 3542 | voltPort := &VoltPort{ |
| 3543 | Name: "16777472", |
| 3544 | Device: "SCOM00001c75", |
| 3545 | ID: 16777216, |
| 3546 | State: PortStateDown, |
| 3547 | ChannelPerSubAlarmRaised: false, |
| 3548 | Type: VoltPortTypeNni, |
| 3549 | } |
| 3550 | |
| 3551 | tests := []struct { |
| 3552 | name string |
| 3553 | args args |
| 3554 | want bool |
| 3555 | }{ |
| 3556 | { |
| 3557 | name: "ReceiverUpInd", |
| 3558 | args: args{ |
| 3559 | key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", |
| 3560 | value: voltServ, |
| 3561 | }, |
| 3562 | }, |
| 3563 | { |
| 3564 | name: "ReceiverUpInd_VlanControl", |
| 3565 | args: args{ |
| 3566 | key: "SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", |
| 3567 | value: voltServ, |
| 3568 | }, |
| 3569 | }, |
| 3570 | } |
| 3571 | for _, tt := range tests { |
| 3572 | t.Run(tt.name, func(t *testing.T) { |
| 3573 | switch tt.name { |
| 3574 | case "ReceiverUpInd": |
| 3575 | GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 3576 | GetApplication().DevicesDisc.Store("SCOM00001c75", voltDev) |
| 3577 | GetApplication().PortsDisc.Store("16777472", voltPort) |
| 3578 | voltDev.Ports.Store("16777472", voltPort) |
| 3579 | if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want { |
| 3580 | t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want) |
| 3581 | } |
| 3582 | case "ReceiverUpInd_VlanControl": |
| 3583 | voltServ.VlanControl = OLTSVlan |
| 3584 | GetApplication().ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ) |
| 3585 | if got := ReceiverUpInd(tt.args.key, tt.args.value); got != tt.want { |
| 3586 | t.Errorf("ReceiverUpInd() = %v, want %v", got, tt.want) |
| 3587 | } |
| 3588 | } |
| 3589 | }) |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | func TestVoltApplication_NniVlanIndToIgmp(t *testing.T) { |
| 3594 | type args struct { |
| 3595 | cntx context.Context |
| 3596 | device *VoltDevice |
| 3597 | mvp *MvlanProfile |
| 3598 | addFlow bool |
| 3599 | } |
| 3600 | mblan := map[uint16]bool{} |
| 3601 | mblan[uint16(256)] = true |
| 3602 | voltDev := &VoltDevice{ |
| 3603 | Name: "SDX6320031", |
| 3604 | SerialNum: "SDX6320031", |
| 3605 | IgmpDsFlowAppliedForMvlan: mblan, |
| 3606 | Ports: sync.Map{}, |
| 3607 | NniPort: "16777472", |
| 3608 | } |
| 3609 | devicesList := make(map[string]OperInProgress) |
| 3610 | devicesList["SDX6320030"] = opt82 |
| 3611 | mvp := &MvlanProfile{ |
| 3612 | Name: "mvlan_test", |
| 3613 | DevicesList: devicesList, |
| 3614 | } |
| 3615 | voltPort := &VoltPort{ |
| 3616 | Name: "16777472", |
| 3617 | Device: "SDX6320031", |
| 3618 | ID: 16777216, |
| 3619 | State: PortStateUp, |
| 3620 | } |
| 3621 | voltPortVnets := make([]*VoltPortVnet, 0) |
| 3622 | voltPortVnet := &VoltPortVnet{ |
| 3623 | Device: "SDX6320031", |
| 3624 | Port: "16777472", |
| 3625 | IgmpEnabled: true, |
| 3626 | MvlanProfileName: "mvlan_test", |
| 3627 | services: sync.Map{}, |
| 3628 | } |
| 3629 | voltPortVnets = append(voltPortVnets, voltPortVnet) |
| 3630 | tests := []struct { |
| 3631 | name string |
| 3632 | args args |
| 3633 | }{ |
| 3634 | { |
| 3635 | name: "NniVlanIndToIgmp", |
| 3636 | args: args{ |
| 3637 | device: voltDev, |
| 3638 | mvp: mvp, |
| 3639 | }, |
| 3640 | }, |
| 3641 | { |
| 3642 | name: "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows", |
| 3643 | args: args{ |
| 3644 | cntx: context.Background(), |
| 3645 | device: voltDev, |
| 3646 | mvp: mvp, |
| 3647 | addFlow: true, |
| 3648 | }, |
| 3649 | }, |
| 3650 | { |
| 3651 | name: "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows", |
| 3652 | args: args{ |
| 3653 | cntx: context.Background(), |
| 3654 | device: voltDev, |
| 3655 | mvp: mvp, |
| 3656 | addFlow: false, |
| 3657 | }, |
| 3658 | }, |
| 3659 | } |
| 3660 | for _, tt := range tests { |
| 3661 | t.Run(tt.name, func(t *testing.T) { |
| 3662 | va := &VoltApplication{} |
| 3663 | switch tt.name { |
| 3664 | case "NniVlanIndToIgmp": |
| 3665 | voltDev.Ports.Store("16777472", voltPort) |
| 3666 | va.PortsDisc.Store("16777472", voltPort) |
| 3667 | va.VnetsByPort.Store("16777472", voltPortVnets) |
| 3668 | va.NniVlanIndToIgmp(tt.args.device, tt.args.mvp) |
| 3669 | case "ProcessIgmpDSFlowForMvlan_pushIgmpMcastFlows", "ProcessIgmpDSFlowForMvlan_removeIgmpMcastFlows": |
| 3670 | voltDev.Ports.Store("16777472", voltPort) |
| 3671 | va.ProcessIgmpDSFlowForMvlan(tt.args.cntx, tt.args.device, tt.args.mvp, tt.args.addFlow) |
| 3672 | } |
| 3673 | }) |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | func TestVoltApplication_DeviceDisableInd(t *testing.T) { |
| 3678 | type args struct { |
| 3679 | cntx context.Context |
| 3680 | device string |
| 3681 | } |
| 3682 | voltDev := &VoltDevice{ |
| 3683 | Name: "SDX6320031", |
| 3684 | SerialNum: "SDX6320031", |
| 3685 | Ports: sync.Map{}, |
| 3686 | State: controller.DeviceStateDOWN, |
| 3687 | MigratingServices: util.NewConcurrentMap(), |
| 3688 | } |
| 3689 | tests := []struct { |
| 3690 | name string |
| 3691 | args args |
| 3692 | }{ |
| 3693 | { |
| 3694 | name: "DeviceDisableInd", |
| 3695 | args: args{ |
| 3696 | device: "SDX6320031", |
| 3697 | }, |
| 3698 | }, |
| 3699 | { |
| 3700 | name: "DeviceDisableInd_DEvice_Not_Found", |
| 3701 | args: args{ |
| 3702 | device: "SDX6320032", |
| 3703 | }, |
| 3704 | }, |
| 3705 | } |
| 3706 | for _, tt := range tests { |
| 3707 | t.Run(tt.name, func(t *testing.T) { |
| 3708 | va := &VoltApplication{} |
| 3709 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3710 | GetApplication().DevicesDisc.Store("SDX6320031", voltDev) |
| 3711 | va.DeviceDisableInd(tt.args.cntx, tt.args.device) |
| 3712 | }) |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | func TestVoltApplication_ProcessIgmpDSFlowForDevice(t *testing.T) { |
| 3717 | type args struct { |
| 3718 | cntx context.Context |
| 3719 | d *VoltDevice |
| 3720 | addFlow bool |
| 3721 | } |
| 3722 | voltDev := &VoltDevice{ |
| 3723 | Name: "SDX6320031", |
| 3724 | SerialNum: "SDX6320031", |
| 3725 | MigratingServices: util.NewConcurrentMap(), |
| 3726 | } |
| 3727 | devicesList := make(map[string]OperInProgress) |
| 3728 | devicesList["SDX6320030"] = opt82 |
| 3729 | mvp := &MvlanProfile{ |
| 3730 | Name: "mvlan_test", |
| 3731 | DevicesList: devicesList, |
| 3732 | } |
| 3733 | tests := []struct { |
| 3734 | name string |
| 3735 | args args |
| 3736 | }{ |
| 3737 | { |
| 3738 | name: "DeviceDisableInd_DEvice_Not_Found", |
| 3739 | args: args{ |
| 3740 | cntx: context.Background(), |
| 3741 | d: voltDev, |
| 3742 | addFlow: true, |
| 3743 | }, |
| 3744 | }, |
| 3745 | } |
| 3746 | for _, tt := range tests { |
| 3747 | t.Run(tt.name, func(t *testing.T) { |
| 3748 | va := &VoltApplication{} |
| 3749 | va.MvlanProfilesByName.Store("mvlan_test", mvp) |
| 3750 | va.ProcessIgmpDSFlowForDevice(tt.args.cntx, tt.args.d, tt.args.addFlow) |
| 3751 | }) |
| 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | func TestVoltApplication_GetPonFromUniPort(t *testing.T) { |
| 3756 | type args struct { |
| 3757 | port string |
| 3758 | } |
| 3759 | voltPort := &VoltPort{ |
| 3760 | Name: "16777472", |
| 3761 | Device: "SDX6320031", |
| 3762 | ID: 16777216, |
| 3763 | State: PortStateUp, |
| 3764 | } |
| 3765 | |
| 3766 | tests := []struct { |
| 3767 | name string |
| 3768 | args args |
| 3769 | want string |
| 3770 | wantErr bool |
| 3771 | }{ |
| 3772 | { |
| 3773 | name: "GetPonFromUniPort_PositiveSenario", |
| 3774 | args: args{ |
| 3775 | port: "16777472", |
| 3776 | }, |
| 3777 | want: "16", |
| 3778 | wantErr: false, |
| 3779 | }, |
| 3780 | { |
| 3781 | name: "GetPonFromUniPort_NegetiveSenario", |
| 3782 | args: args{ |
| 3783 | port: "16777472", |
| 3784 | }, |
| 3785 | wantErr: true, |
| 3786 | }, |
| 3787 | } |
| 3788 | for _, tt := range tests { |
| 3789 | t.Run(tt.name, func(t *testing.T) { |
| 3790 | va := &VoltApplication{} |
| 3791 | switch tt.name { |
| 3792 | case "GetPonFromUniPort_PositiveSenario": |
| 3793 | va.PortsDisc.Store("16777472", voltPort) |
| 3794 | got, err := va.GetPonFromUniPort(tt.args.port) |
| 3795 | if (err != nil) != tt.wantErr { |
| 3796 | t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr) |
| 3797 | return |
| 3798 | } |
| 3799 | if got != tt.want { |
| 3800 | t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want) |
| 3801 | } |
| 3802 | case "GetPonFromUniPort_NegetiveSenario": |
| 3803 | got, err := va.GetPonFromUniPort(tt.args.port) |
| 3804 | if (err != nil) != tt.wantErr { |
| 3805 | t.Errorf("VoltApplication.GetPonFromUniPort() error = %v, wantErr %v", err, tt.wantErr) |
| 3806 | return |
| 3807 | } |
| 3808 | if got != tt.want { |
| 3809 | t.Errorf("VoltApplication.GetPonFromUniPort() = %v, want %v", got, tt.want) |
| 3810 | } |
| 3811 | } |
| 3812 | }) |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | func TestVoltApplication_AddIcmpv6Receivers(t *testing.T) { |
| 3817 | type args struct { |
| 3818 | device string |
| 3819 | portID uint32 |
| 3820 | } |
| 3821 | var receiverList []uint32 |
| 3822 | port := uint32(256) |
| 3823 | receiverList = append(receiverList, port) |
| 3824 | tests := []struct { |
| 3825 | name string |
| 3826 | args args |
| 3827 | want []uint32 |
| 3828 | }{ |
| 3829 | { |
| 3830 | name: "AddIcmpv6Receivers", |
| 3831 | args: args{ |
| 3832 | device: "SDX6320031", |
| 3833 | portID: port, |
| 3834 | }, |
| 3835 | want: []uint32{port, port}, |
| 3836 | }, |
| 3837 | { |
| 3838 | name: "DelIcmpv6Receivers", |
| 3839 | args: args{ |
| 3840 | device: "SDX6320031", |
| 3841 | portID: port, |
| 3842 | }, |
| 3843 | want: []uint32{}, |
| 3844 | }, |
| 3845 | } |
| 3846 | for _, tt := range tests { |
| 3847 | t.Run(tt.name, func(t *testing.T) { |
| 3848 | va := &VoltApplication{} |
| 3849 | switch tt.name { |
| 3850 | case "AddIcmpv6Receivers": |
| 3851 | va.Icmpv6Receivers.Store("SDX6320031", receiverList) |
| 3852 | if got := va.AddIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) { |
| 3853 | t.Errorf("VoltApplication.AddIcmpv6Receivers() = %v, want %v", got, tt.want) |
| 3854 | } |
| 3855 | case "DelIcmpv6Receivers": |
| 3856 | va.Icmpv6Receivers.Store("SDX6320031", receiverList) |
| 3857 | if got := va.DelIcmpv6Receivers(tt.args.device, tt.args.portID); !reflect.DeepEqual(got, tt.want) { |
| 3858 | t.Errorf("VoltApplication.DelIcmpv6Receivers() = %v, want %v", got, tt.want) |
| 3859 | } |
| 3860 | } |
| 3861 | }) |
| 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | func TestVoltApplication_ProcessDevFlowForDevice(t *testing.T) { |
| 3866 | type args struct { |
| 3867 | cntx context.Context |
| 3868 | device *VoltDevice |
| 3869 | vnet *VoltVnet |
| 3870 | enabled bool |
| 3871 | } |
| 3872 | voltDev := &VoltDevice{ |
| 3873 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 3874 | SerialNum: "SDX6320031", |
| 3875 | NniDhcpTrapVid: 123, |
| 3876 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 3877 | } |
| 3878 | voltVnet := &VoltVnet{ |
| 3879 | Version: "v3", |
| 3880 | VnetConfig: VnetConfig{ |
| 3881 | Name: "2310-4096-4096", |
| 3882 | VnetType: "Encapsulation", |
| 3883 | SVlan: 2310, |
| 3884 | CVlan: 4096, |
| 3885 | UniVlan: 4096, |
| 3886 | SVlanTpid: 33024, |
| 3887 | }, |
| 3888 | VnetOper: VnetOper{ |
| 3889 | PendingDeviceToDelete: "SDX6320031", |
| 3890 | DeleteInProgress: true, |
| 3891 | }, |
| 3892 | } |
| 3893 | tests := []struct { |
| 3894 | name string |
| 3895 | args args |
| 3896 | }{ |
| 3897 | { |
| 3898 | name: "ProcessDevFlowForDevice_PushDevFlowForVlan", |
| 3899 | args: args{ |
| 3900 | cntx: context.Background(), |
| 3901 | device: voltDev, |
| 3902 | vnet: voltVnet, |
| 3903 | enabled: true, |
| 3904 | }, |
| 3905 | }, |
| 3906 | } |
| 3907 | for _, tt := range tests { |
| 3908 | t.Run(tt.name, func(t *testing.T) { |
| 3909 | va := &VoltApplication{} |
| 3910 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 3911 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 3912 | va.ProcessDevFlowForDevice(tt.args.cntx, tt.args.device, tt.args.vnet, tt.args.enabled) |
| 3913 | }) |
| 3914 | } |
| 3915 | } |