vinokuma | 703a70b | 2023-07-17 10:06:43 +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" |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 20 | "encoding/json" |
| 21 | "net" |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 22 | "reflect" |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 23 | "sync" |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 24 | "testing" |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 25 | "voltha-go-controller/internal/pkg/controller" |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 26 | cntlr "voltha-go-controller/internal/pkg/controller" |
| 27 | "voltha-go-controller/internal/pkg/of" |
| 28 | "voltha-go-controller/internal/pkg/util" |
| 29 | "voltha-go-controller/internal/test/mocks" |
| 30 | |
| 31 | "github.com/golang/mock/gomock" |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 32 | "github.com/google/gopacket/layers" |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 34 | "github.com/stretchr/testify/assert" |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 35 | "go.uber.org/atomic" |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 36 | ) |
| 37 | |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 38 | const deviceName = "SDX6320031" |
| 39 | |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 40 | func TestVoltPortVnet_JSONMarshal(t *testing.T) { |
| 41 | tests := []struct { |
| 42 | name string |
| 43 | want []byte |
| 44 | wantErr bool |
| 45 | }{ |
| 46 | { |
| 47 | name: "VoltPortVnet_JSONMarshal", |
| 48 | }, |
| 49 | } |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | vpv := &VoltPortVnet{} |
| 53 | _, err := vpv.JSONMarshal() |
| 54 | if (err != nil) != tt.wantErr { |
| 55 | t.Errorf("VoltPortVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr) |
| 56 | return |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestVoltPortVnet_IsServiceActivated(t *testing.T) { |
| 63 | type args struct { |
| 64 | cntx context.Context |
| 65 | } |
| 66 | tests := []struct { |
| 67 | name string |
| 68 | args args |
| 69 | want bool |
| 70 | }{ |
| 71 | { |
| 72 | name: "VoltPortVnet_IsServiceActivated", |
| 73 | args: args{ |
| 74 | cntx: context.Background(), |
| 75 | }, |
| 76 | }, |
| 77 | } |
| 78 | for _, tt := range tests { |
| 79 | t.Run(tt.name, func(t *testing.T) { |
| 80 | vpv := &VoltPortVnet{} |
| 81 | voltServ := &VoltService{ |
| 82 | VoltServiceOper: VoltServiceOper{ |
| 83 | Device: test_device, |
| 84 | ForceDelete: true, |
| 85 | }, |
| 86 | } |
| 87 | vpv.services.Store(test_device, voltServ) |
| 88 | if got := vpv.IsServiceActivated(tt.args.cntx); got != tt.want { |
| 89 | t.Errorf("VoltPortVnet.IsServiceActivated() = %v, want %v", got, tt.want) |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestVoltVnet_JSONMarshal(t *testing.T) { |
| 96 | tests := []struct { |
| 97 | name string |
| 98 | want []byte |
| 99 | wantErr bool |
| 100 | }{ |
| 101 | { |
| 102 | name: "VoltVnet_JSONMarshal", |
| 103 | }, |
| 104 | } |
| 105 | for _, tt := range tests { |
| 106 | t.Run(tt.name, func(t *testing.T) { |
| 107 | vv := &VoltVnet{} |
| 108 | _, err := vv.JSONMarshal() |
| 109 | if (err != nil) != tt.wantErr { |
| 110 | t.Errorf("VoltVnet.JSONMarshal() error = %v, wantErr %v", err, tt.wantErr) |
| 111 | return |
| 112 | } |
| 113 | }) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func TestVoltVnet_TriggerAssociatedFlowDelete(t *testing.T) { |
| 118 | type args struct { |
| 119 | cntx context.Context |
| 120 | device string |
| 121 | } |
| 122 | tests := []struct { |
| 123 | name string |
| 124 | args args |
| 125 | want bool |
| 126 | }{ |
| 127 | { |
| 128 | name: "VoltVnet_TriggerAssociatedFlowDelete", |
| 129 | args: args{ |
| 130 | cntx: context.Background(), |
| 131 | device: test_device, |
| 132 | }, |
| 133 | want: true, |
| 134 | }, |
| 135 | { |
| 136 | name: "cookieList_empty", |
| 137 | args: args{ |
| 138 | cntx: context.Background(), |
| 139 | device: test_device, |
| 140 | }, |
| 141 | want: false, |
| 142 | }, |
| 143 | } |
| 144 | for _, tt := range tests { |
| 145 | t.Run(tt.name, func(t *testing.T) { |
| 146 | vv := &VoltVnet{} |
| 147 | switch tt.name { |
| 148 | case "VoltVnet_TriggerAssociatedFlowDelete": |
| 149 | cookie := map[string]bool{} |
| 150 | cookie["1234"] = true |
| 151 | pendingDeleteFlow := map[string]map[string]bool{} |
| 152 | pendingDeleteFlow[test_device] = cookie |
| 153 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 154 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 155 | db = dbintf |
| 156 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 157 | if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want { |
| 158 | t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 159 | } |
| 160 | case "cookieList_empty": |
| 161 | if got := vv.TriggerAssociatedFlowDelete(tt.args.cntx, tt.args.device); got != tt.want { |
| 162 | t.Errorf("VoltVnet.TriggerAssociatedFlowDelete() = %v, want %v", got, tt.want) |
| 163 | } |
| 164 | } |
| 165 | }) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | func TestVoltApplication_GetMatchingMcastService(t *testing.T) { |
| 170 | type args struct { |
| 171 | port string |
| 172 | device string |
| 173 | cvlan of.VlanType |
| 174 | } |
| 175 | tests := []struct { |
| 176 | name string |
| 177 | args args |
| 178 | want *VoltService |
| 179 | }{ |
| 180 | { |
| 181 | name: "VoltApplication_GetMatchingMcastService", |
| 182 | args: args{ |
| 183 | port: "test_port", |
| 184 | device: test_device, |
| 185 | cvlan: of.VlanAny, |
| 186 | }, |
| 187 | }, |
| 188 | { |
| 189 | name: "dIntf_error", |
| 190 | args: args{ |
| 191 | port: "test_port", |
| 192 | device: test_device, |
| 193 | cvlan: of.VlanAny, |
| 194 | }, |
| 195 | }, |
| 196 | { |
| 197 | name: "port == d.NniPort", |
| 198 | args: args{ |
| 199 | port: "test_port", |
| 200 | device: test_device, |
| 201 | cvlan: of.VlanAny, |
| 202 | }, |
| 203 | }, |
| 204 | { |
| 205 | name: "vnets_error", |
| 206 | args: args{ |
| 207 | port: "", |
| 208 | device: test_device, |
| 209 | cvlan: of.VlanAny, |
| 210 | }, |
| 211 | }, |
| 212 | } |
| 213 | for _, tt := range tests { |
| 214 | t.Run(tt.name, func(t *testing.T) { |
| 215 | va := &VoltApplication{} |
| 216 | switch tt.name { |
| 217 | case "VoltApplication_GetMatchingMcastService": |
| 218 | va.DevicesDisc.Store(test_device, voltDevice) |
| 219 | va.VnetsByPort.Store("test_port", voltPortVnet1) |
| 220 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 221 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 222 | } |
| 223 | case "dIntf_error": |
| 224 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 225 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 226 | } |
| 227 | case "port == d.NniPort": |
| 228 | va.DevicesDisc.Store(test_device, voltDevice) |
| 229 | voltDevice.NniPort = "test_port" |
| 230 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 231 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 232 | } |
| 233 | case "vnets_error": |
| 234 | va.DevicesDisc.Store(test_device, voltDevice) |
| 235 | va.VnetsByPort.Store("test_port1", voltPortVnet1) |
| 236 | if got := va.GetMatchingMcastService(tt.args.port, tt.args.device, tt.args.cvlan); !reflect.DeepEqual(got, tt.want) { |
| 237 | t.Errorf("VoltApplication.GetMatchingMcastService() = %v, want %v", got, tt.want) |
| 238 | } |
| 239 | } |
| 240 | }) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | func TestVoltPortVnet_IgmpFlowInstallFailure(t *testing.T) { |
| 245 | type args struct { |
| 246 | cookie string |
| 247 | errorCode uint32 |
| 248 | errReason string |
| 249 | } |
| 250 | tests := []struct { |
| 251 | name string |
| 252 | args args |
| 253 | }{ |
| 254 | { |
| 255 | name: "VoltPortVnet_IgmpFlowInstallFailure", |
| 256 | args: args{ |
| 257 | cookie: "test_cookie", |
| 258 | errorCode: uint32(1), |
| 259 | errReason: "errReason", |
| 260 | }, |
| 261 | }, |
| 262 | } |
| 263 | for _, tt := range tests { |
| 264 | t.Run(tt.name, func(t *testing.T) { |
| 265 | vpv := &VoltPortVnet{} |
| 266 | switch tt.name { |
| 267 | case "VoltPortVnet_IgmpFlowInstallFailure": |
| 268 | voltService.IgmpEnabled = true |
| 269 | vpv.services.Store("test_cookie", voltService) |
| 270 | vpv.IgmpFlowInstallFailure(tt.args.cookie, tt.args.errorCode, tt.args.errReason) |
| 271 | } |
| 272 | }) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | func TestVoltVnet_FlowRemoveFailure(t *testing.T) { |
| 277 | type args struct { |
| 278 | cntx context.Context |
| 279 | cookie string |
| 280 | device string |
| 281 | errorCode uint32 |
| 282 | errReason string |
| 283 | } |
| 284 | tests := []struct { |
| 285 | name string |
| 286 | args args |
| 287 | }{ |
| 288 | { |
| 289 | name: "VoltVnet_FlowRemoveFailure", |
| 290 | args: args{ |
| 291 | cntx: context.Background(), |
| 292 | cookie: "1234", |
| 293 | device: test_device, |
| 294 | }, |
| 295 | }, |
| 296 | { |
| 297 | name: "mismatch_cookie", |
| 298 | args: args{ |
| 299 | cntx: context.Background(), |
| 300 | cookie: "1234", |
| 301 | device: test_device, |
| 302 | }, |
| 303 | }, |
| 304 | } |
| 305 | for _, tt := range tests { |
| 306 | t.Run(tt.name, func(t *testing.T) { |
| 307 | vv := &VoltVnet{} |
| 308 | switch tt.name { |
| 309 | case "VoltVnet_FlowRemoveFailure": |
| 310 | cookie := map[string]bool{} |
| 311 | cookie["1234"] = true |
| 312 | pendingDeleteFlow := map[string]map[string]bool{} |
| 313 | pendingDeleteFlow[test_device] = cookie |
| 314 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 315 | vv.DeleteInProgress = true |
| 316 | vv.Name = "test_name" |
| 317 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 318 | db = dbintf |
| 319 | dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1) |
| 320 | vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 321 | case "mismatch_cookie": |
| 322 | cookie := map[string]bool{} |
| 323 | cookie["12345"] = true |
| 324 | pendingDeleteFlow := map[string]map[string]bool{} |
| 325 | pendingDeleteFlow[test_device] = cookie |
| 326 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 327 | vv.DeleteInProgress = true |
| 328 | vv.Name = "test_name" |
| 329 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 330 | db = dbintf |
| 331 | dbintf.EXPECT().DelVnet(tt.args.cntx, "test_name").Return(nil).Times(1) |
| 332 | vv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 333 | } |
| 334 | }) |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | func TestVoltVnet_FlowRemoveSuccess(t *testing.T) { |
| 339 | type args struct { |
| 340 | cntx context.Context |
| 341 | cookie string |
| 342 | device string |
| 343 | } |
| 344 | tests := []struct { |
| 345 | name string |
| 346 | args args |
| 347 | }{ |
| 348 | { |
| 349 | name: "VoltVnet_FlowRemoveSuccess", |
| 350 | args: args{ |
| 351 | cntx: context.Background(), |
| 352 | cookie: "1234", |
| 353 | device: test_device, |
| 354 | }, |
| 355 | }, |
| 356 | } |
| 357 | for _, tt := range tests { |
| 358 | t.Run(tt.name, func(t *testing.T) { |
| 359 | vv := &VoltVnet{} |
| 360 | cookie := map[string]bool{} |
| 361 | cookie["1234"] = true |
| 362 | pendingDeleteFlow := map[string]map[string]bool{} |
| 363 | pendingDeleteFlow[test_device] = cookie |
| 364 | vv.PendingDeleteFlow = pendingDeleteFlow |
| 365 | ga := GetApplication() |
| 366 | voltDevice.ConfiguredVlanForDeviceFlows = util.NewConcurrentMap() |
| 367 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 368 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 369 | db = dbintf |
| 370 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 371 | vv.FlowRemoveSuccess(tt.args.cntx, tt.args.cookie, tt.args.device) |
| 372 | }) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | func TestVoltPortVnet_FlowRemoveFailure(t *testing.T) { |
| 377 | type args struct { |
| 378 | cntx context.Context |
| 379 | cookie string |
| 380 | device string |
| 381 | errorCode uint32 |
| 382 | errReason string |
| 383 | } |
| 384 | tests := []struct { |
| 385 | name string |
| 386 | args args |
| 387 | }{ |
| 388 | { |
| 389 | name: "VoltPortVnet_FlowRemoveFailure", |
| 390 | args: args{ |
| 391 | cntx: context.Background(), |
| 392 | cookie: "1234", |
| 393 | device: test_device, |
| 394 | }, |
| 395 | }, |
| 396 | { |
| 397 | name: "DeleteInProgress_false", |
| 398 | args: args{ |
| 399 | cntx: context.Background(), |
| 400 | cookie: "1234", |
| 401 | device: test_device, |
| 402 | }, |
| 403 | }, |
| 404 | } |
| 405 | for _, tt := range tests { |
| 406 | t.Run(tt.name, func(t *testing.T) { |
| 407 | vpv := &VoltPortVnet{} |
| 408 | switch tt.name { |
| 409 | case "VoltPortVnet_FlowRemoveFailure": |
| 410 | vpv.services.Store("1234", voltService) |
| 411 | vpv.DeleteInProgress = true |
| 412 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 413 | db = dbintf |
| 414 | dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 415 | vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 416 | case "DeleteInProgress_false": |
| 417 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 418 | db = dbintf |
| 419 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 420 | vpv.FlowRemoveFailure(tt.args.cntx, tt.args.cookie, tt.args.device, tt.args.errorCode, tt.args.errReason) |
| 421 | } |
| 422 | }) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | func TestVoltPortVnet_PushFlows(t *testing.T) { |
| 427 | type args struct { |
| 428 | cntx context.Context |
| 429 | device *VoltDevice |
| 430 | flow *of.VoltFlow |
| 431 | } |
| 432 | vsf := make(map[uint64]*of.VoltSubFlow) |
| 433 | vsf[uint64(1)] = &of.VoltSubFlow{ |
| 434 | Cookie: uint64(1234), |
| 435 | } |
| 436 | tests := []struct { |
| 437 | name string |
| 438 | args args |
| 439 | wantErr bool |
| 440 | }{ |
| 441 | { |
| 442 | name: "VoltPortVnet_PushFlows", |
| 443 | args: args{ |
| 444 | cntx: context.Background(), |
| 445 | device: voltDevice, |
| 446 | flow: &of.VoltFlow{ |
| 447 | PortName: "test_port", |
| 448 | SubFlows: vsf, |
| 449 | }, |
| 450 | }, |
| 451 | }, |
| 452 | } |
| 453 | for _, tt := range tests { |
| 454 | t.Run(tt.name, func(t *testing.T) { |
| 455 | vpv := &VoltPortVnet{} |
| 456 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 457 | err := vpv.PushFlows(tt.args.cntx, tt.args.device, tt.args.flow) |
| 458 | assert.NotNil(t, err) |
| 459 | }) |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | func TestVoltPortVnet_isVlanMatching(t *testing.T) { |
| 464 | type args struct { |
| 465 | cvlan of.VlanType |
| 466 | svlan of.VlanType |
| 467 | } |
| 468 | tests := []struct { |
| 469 | name string |
| 470 | args args |
| 471 | want bool |
| 472 | }{ |
| 473 | { |
| 474 | name: "VoltPortVnet_isVlanMatching", |
| 475 | args: args{ |
| 476 | cvlan: of.VlanAny, |
| 477 | svlan: of.VlanAny, |
| 478 | }, |
| 479 | want: true, |
| 480 | }, |
| 481 | { |
| 482 | name: "vpv.VlanControl_nil", |
| 483 | args: args{ |
| 484 | cvlan: of.VlanAny, |
| 485 | svlan: of.VlanAny, |
| 486 | }, |
| 487 | want: true, |
| 488 | }, |
| 489 | } |
| 490 | for _, tt := range tests { |
| 491 | t.Run(tt.name, func(t *testing.T) { |
| 492 | vpv := &VoltPortVnet{} |
| 493 | switch tt.name { |
| 494 | case "VoltPortVnet_isVlanMatching": |
| 495 | vpv.VlanControl = ONUCVlanOLTSVlan |
| 496 | vpv.SVlan = of.VlanAny |
| 497 | vpv.CVlan = of.VlanAny |
| 498 | if got := vpv.isVlanMatching(tt.args.cvlan, tt.args.svlan); got != tt.want { |
| 499 | t.Errorf("VoltPortVnet.isVlanMatching() = %v, want %v", got, tt.want) |
| 500 | } |
| 501 | } |
| 502 | }) |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | func TestProcessIcmpv6McGroup(t *testing.T) { |
| 507 | type args struct { |
| 508 | device string |
| 509 | delete bool |
| 510 | } |
| 511 | tests := []struct { |
| 512 | name string |
| 513 | args args |
| 514 | wantErr bool |
| 515 | }{ |
| 516 | { |
| 517 | name: "TestProcessIcmpv6McGroup", |
| 518 | args: args{ |
| 519 | device: test_device, |
| 520 | delete: false, |
| 521 | }, |
| 522 | }, |
| 523 | } |
| 524 | for _, tt := range tests { |
| 525 | t.Run(tt.name, func(t *testing.T) { |
| 526 | err := ProcessIcmpv6McGroup(tt.args.device, tt.args.delete) |
| 527 | assert.NotNil(t, err) |
| 528 | }) |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | func TestVoltVnet_setPbitRemarking(t *testing.T) { |
| 533 | tests := []struct { |
| 534 | name string |
| 535 | want uint32 |
| 536 | }{ |
| 537 | { |
| 538 | name: "VoltVnet_setPbitRemarking", |
| 539 | }, |
| 540 | } |
| 541 | for _, tt := range tests { |
| 542 | t.Run(tt.name, func(t *testing.T) { |
| 543 | vv := &VoltVnet{} |
| 544 | a := make(map[of.PbitType]of.PbitType) |
| 545 | a[of.PbitMatchAll] = of.PbitMatchAll |
| 546 | vv.CtrlPktPbitRemark = a |
| 547 | if got := vv.setPbitRemarking(); got != tt.want { |
| 548 | t.Errorf("VoltVnet.setPbitRemarking() = %v, want %v", got, tt.want) |
| 549 | } |
| 550 | }) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | func TestBuildDSArpFlow(t *testing.T) { |
| 555 | type args struct { |
| 556 | inport uint32 |
| 557 | vnet *VoltVnet |
| 558 | } |
| 559 | tests := []struct { |
| 560 | name string |
| 561 | args args |
| 562 | want *of.VoltFlow |
| 563 | }{ |
| 564 | { |
| 565 | name: "BuildDSArpFlow", |
| 566 | args: args{ |
| 567 | inport: uint32(1), |
| 568 | vnet: &VoltVnet{ |
| 569 | Version: "test_version", |
| 570 | }, |
| 571 | }, |
| 572 | }, |
| 573 | } |
| 574 | for _, tt := range tests { |
| 575 | t.Run(tt.name, func(t *testing.T) { |
| 576 | switch tt.name { |
| 577 | case "BuildDSArpFlow": |
| 578 | got := BuildDSArpFlow(tt.args.inport, tt.args.vnet) |
| 579 | assert.NotNil(t, got) |
| 580 | } |
| 581 | }) |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | func TestBuildICMPv6Flow(t *testing.T) { |
| 586 | type args struct { |
| 587 | inport uint32 |
| 588 | vnet *VoltVnet |
| 589 | } |
| 590 | tests := []struct { |
| 591 | name string |
| 592 | args args |
| 593 | want *of.VoltFlow |
| 594 | }{ |
| 595 | { |
| 596 | name: "BuildICMPv6Flow", |
| 597 | args: args{ |
| 598 | inport: uint32(1), |
| 599 | vnet: &VoltVnet{ |
| 600 | Version: "test_version", |
| 601 | }, |
| 602 | }, |
| 603 | }, |
| 604 | } |
| 605 | for _, tt := range tests { |
| 606 | t.Run(tt.name, func(t *testing.T) { |
| 607 | got := BuildICMPv6Flow(tt.args.inport, tt.args.vnet) |
| 608 | assert.NotNil(t, got) |
| 609 | }) |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | func TestVoltApplication_DeleteDevFlowForVlanFromDevice(t *testing.T) { |
| 614 | type args struct { |
| 615 | cntx context.Context |
| 616 | vnet *VoltVnet |
| 617 | deviceSerialNum string |
| 618 | } |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 619 | voltDev := &VoltDevice{ |
| 620 | Name: "SDX6320031", |
| 621 | SerialNum: "SDX6320031", |
| 622 | NniDhcpTrapVid: 123, |
| 623 | State: cntlr.DeviceStateUP, |
| 624 | NniPort: "16777472", |
| 625 | Ports: sync.Map{}, |
| 626 | FlowDelEventMap: util.NewConcurrentMap(), |
| 627 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 628 | } |
| 629 | voltVnet = &VoltVnet{ |
| 630 | Version: "v3", |
| 631 | VnetConfig: VnetConfig{ |
| 632 | Name: "2310-4096-4096", |
| 633 | VnetType: "Encapsulation", |
| 634 | }, |
| 635 | VnetOper: VnetOper{ |
| 636 | PendingDeviceToDelete: "SDX6320031", |
| 637 | DeleteInProgress: true, |
| 638 | PendingDeleteFlow: make(map[string]map[string]bool), |
| 639 | }, |
| 640 | } |
| 641 | voltPort := &VoltPort{ |
| 642 | Name: "16777472", |
| 643 | Device: "SDX6320031", |
| 644 | ID: 16777472, |
| 645 | State: PortStateUp, |
| 646 | ChannelPerSubAlarmRaised: false, |
| 647 | } |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 648 | tests := []struct { |
| 649 | name string |
| 650 | args args |
| 651 | }{ |
| 652 | { |
| 653 | name: "device.SerialNum != deviceSerialNum", |
| 654 | args: args{ |
| 655 | cntx: context.Background(), |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 656 | vnet: voltVnet, |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 657 | }, |
| 658 | }, |
| 659 | { |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 660 | name: "DeleteDevFlowForVlanFromDevice", |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 661 | args: args{ |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 662 | cntx: context.Background(), |
| 663 | deviceSerialNum: "SDX6320031", |
| 664 | vnet: voltVnet, |
| 665 | }, |
| 666 | }, |
| 667 | { |
| 668 | name: "DeleteDevFlowForVlanFromDevice_PortStateDown", |
| 669 | args: args{ |
| 670 | cntx: context.Background(), |
| 671 | deviceSerialNum: "SDX6320031", |
| 672 | vnet: voltVnet, |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 673 | }, |
| 674 | }, |
| 675 | } |
| 676 | for _, tt := range tests { |
| 677 | t.Run(tt.name, func(t *testing.T) { |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 678 | va := &VoltApplication{ |
| 679 | DevicesDisc: sync.Map{}, |
| 680 | } |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 681 | switch tt.name { |
| 682 | case "device.SerialNum != deviceSerialNum": |
| 683 | va.DevicesDisc.Store(test_device, voltDevice) |
| 684 | va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 685 | case "DeleteDevFlowForVlanFromDevice": |
| 686 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 687 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 688 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 689 | va.PortsDisc.Store("16777472", voltPort) |
| 690 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 691 | cntlr.NewController(ctx, appMock) |
| 692 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 693 | portsByName := map[string]*cntlr.DevicePort{} |
| 694 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 695 | Name: "16777472", |
| 696 | ID: 256, |
| 697 | State: cntlr.PortStateUp, |
| 698 | } |
| 699 | device := &cntlr.Device{ |
| 700 | ID: "SDX6320031", |
| 701 | PortsByName: portsByName, |
| 702 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 703 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 704 | va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum) |
| 705 | case "DeleteDevFlowForVlanFromDevice_PortStateDown": |
| 706 | voltDev.Name = "" |
| 707 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 708 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 709 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 710 | va.PortsDisc.Store("16777472", voltPort) |
| 711 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 712 | cntlr.NewController(ctx, appMock) |
| 713 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 714 | portsByName := map[string]*cntlr.DevicePort{} |
| 715 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 716 | Name: "16777472", |
| 717 | ID: 256, |
| 718 | State: cntlr.PortStateUp, |
| 719 | } |
| 720 | device := &cntlr.Device{ |
| 721 | ID: "SDX6320031", |
| 722 | PortsByName: portsByName, |
| 723 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 724 | vc.Devices.Store("SDX6320031", device) |
vinokuma | 703a70b | 2023-07-17 10:06:43 +0530 | [diff] [blame] | 725 | va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum) |
| 726 | } |
| 727 | }) |
| 728 | } |
| 729 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 730 | |
| 731 | func TestVoltApplication_RestoreVnetsFromDb(t *testing.T) { |
| 732 | type args struct { |
| 733 | cntx context.Context |
| 734 | } |
| 735 | tests := []struct { |
| 736 | name string |
| 737 | args args |
| 738 | }{ |
| 739 | { |
| 740 | name: "VoltApplication_RestoreVnetsFromDb", |
| 741 | args: args{ |
| 742 | cntx: context.Background(), |
| 743 | }, |
| 744 | }, |
| 745 | } |
| 746 | for _, tt := range tests { |
| 747 | t.Run(tt.name, func(t *testing.T) { |
| 748 | vnetsToDelete := map[string]bool{} |
| 749 | vnetsToDelete["test_name"] = true |
| 750 | va := &VoltApplication{ |
| 751 | VnetsBySvlan: util.NewConcurrentMap(), |
| 752 | VnetsToDelete: vnetsToDelete, |
| 753 | } |
| 754 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 755 | db = dbintf |
| 756 | vnets := map[string]*kvstore.KVPair{} |
| 757 | voltVnet.SVlan = of.VlanAny |
| 758 | b, err := json.Marshal(voltVnet) |
| 759 | if err != nil { |
| 760 | panic(err) |
| 761 | } |
| 762 | vnets["test_device_id"] = &kvstore.KVPair{ |
| 763 | Key: "test_device_id", |
| 764 | Value: b, |
| 765 | } |
| 766 | dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 767 | dbintf.EXPECT().GetVnets(tt.args.cntx).Return(vnets, nil) |
| 768 | va.RestoreVnetsFromDb(tt.args.cntx) |
| 769 | }) |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | func TestVoltApplication_DeleteDevFlowForDevice(t *testing.T) { |
| 774 | type args struct { |
| 775 | cntx context.Context |
| 776 | device *VoltDevice |
| 777 | } |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 778 | voltDev := &VoltDevice{ |
| 779 | Name: "SDX6320031", |
| 780 | SerialNum: "SDX6320031", |
| 781 | NniDhcpTrapVid: 123, |
| 782 | State: cntlr.DeviceStateUP, |
| 783 | NniPort: "16777472", |
| 784 | FlowDelEventMap: util.NewConcurrentMap(), |
| 785 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 786 | icmpv6GroupAdded: true, |
| 787 | } |
| 788 | voltVnet = &VoltVnet{ |
| 789 | Version: "v3", |
| 790 | VnetConfig: VnetConfig{ |
| 791 | Name: "2310-4096-4096", |
| 792 | VnetType: "Encapsulation", |
| 793 | }, |
| 794 | VnetOper: VnetOper{ |
| 795 | PendingDeviceToDelete: "SDX6320031", |
| 796 | DeleteInProgress: true, |
| 797 | PendingDeleteFlow: make(map[string]map[string]bool), |
| 798 | }, |
| 799 | } |
| 800 | voltPort := &VoltPort{ |
| 801 | Name: "16777472", |
| 802 | Device: "SDX6320031", |
| 803 | ID: 16777472, |
| 804 | State: PortStateUp, |
| 805 | ChannelPerSubAlarmRaised: false, |
| 806 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 807 | tests := []struct { |
| 808 | name string |
| 809 | args args |
| 810 | }{ |
| 811 | { |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 812 | name: "DeleteDevFlowForDevice", |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 813 | args: args{ |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 814 | cntx: context.Background(), |
| 815 | device: voltDev, |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 816 | }, |
| 817 | }, |
| 818 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 819 | for _, tt := range tests { |
| 820 | t.Run(tt.name, func(t *testing.T) { |
| 821 | va := &VoltApplication{} |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 822 | switch tt.name { |
| 823 | case "DeleteDevFlowForDevice": |
| 824 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 825 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 826 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 827 | va.PortsDisc.Store("16777472", voltPort) |
| 828 | voltApp := GetApplication() |
| 829 | voltApp.DevicesDisc.Store("SDX6320031", voltDev) |
| 830 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 831 | cntlr.NewController(ctx, appMock) |
| 832 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 833 | portsByName := map[string]*cntlr.DevicePort{} |
| 834 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 835 | Name: "16777472", |
| 836 | ID: 256, |
| 837 | State: cntlr.PortStateUp, |
| 838 | } |
| 839 | device := &cntlr.Device{ |
| 840 | ID: "SDX6320031", |
| 841 | PortsByName: portsByName, |
| 842 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 843 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 844 | va.DeleteDevFlowForDevice(tt.args.cntx, tt.args.device) |
| 845 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 846 | }) |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | func TestVoltApplication_DelVnetFromPort(t *testing.T) { |
| 851 | macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 852 | vpv_test := []*VoltPortVnet{ |
| 853 | { |
| 854 | Device: test_device, |
| 855 | Port: "test_port", |
| 856 | MacAddr: macAdd, |
| 857 | VnetName: "test_vnet_name", |
| 858 | }, |
| 859 | } |
| 860 | type args struct { |
| 861 | cntx context.Context |
| 862 | port string |
| 863 | vpv *VoltPortVnet |
| 864 | } |
| 865 | tests := []struct { |
| 866 | name string |
| 867 | args args |
| 868 | }{ |
| 869 | { |
| 870 | name: "VoltApplication_DelVnetFromPort", |
| 871 | args: args{ |
| 872 | cntx: context.Background(), |
| 873 | port: "test_port", |
| 874 | vpv: &VoltPortVnet{ |
| 875 | Device: test_device, |
| 876 | Port: "test_port", |
| 877 | MacAddr: macAdd, |
| 878 | VnetName: "test_vnet_name", |
| 879 | }, |
| 880 | }, |
| 881 | }, |
| 882 | } |
| 883 | for _, tt := range tests { |
| 884 | t.Run(tt.name, func(t *testing.T) { |
| 885 | va := &VoltApplication{} |
| 886 | va.VnetsByPort.Store("test_port", vpv_test) |
| 887 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 888 | db = dbintf |
| 889 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 890 | dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 891 | va.VnetsByName.Store("test_vnet_name", &VoltVnet{ |
| 892 | Version: "test_version", |
| 893 | }) |
| 894 | va.DelVnetFromPort(tt.args.cntx, tt.args.port, tt.args.vpv) |
| 895 | }) |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | func TestVoltApplication_PushDevFlowForVlan(t *testing.T) { |
| 900 | type args struct { |
| 901 | cntx context.Context |
| 902 | vnet *VoltVnet |
| 903 | } |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 904 | voltDev := &VoltDevice{ |
| 905 | Name: "SDX6320031", |
| 906 | SerialNum: "SDX6320031", |
| 907 | NniDhcpTrapVid: 123, |
| 908 | State: cntlr.DeviceStateUP, |
| 909 | NniPort: "16777472", |
| 910 | FlowDelEventMap: util.NewConcurrentMap(), |
| 911 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 912 | icmpv6GroupAdded: true, |
| 913 | VlanPortStatus: sync.Map{}, |
| 914 | } |
| 915 | voltVnet := &VoltVnet{ |
| 916 | Version: "v3", |
| 917 | VnetConfig: VnetConfig{ |
| 918 | Name: "2310-4096-4096", |
| 919 | VnetType: "Encapsulation", |
| 920 | DevicesList: []string{"SDX6320031"}, |
| 921 | SVlan: 0, |
| 922 | }, |
| 923 | VnetOper: VnetOper{ |
| 924 | PendingDeviceToDelete: "SDX6320031", |
| 925 | DeleteInProgress: true, |
| 926 | PendingDeleteFlow: make(map[string]map[string]bool), |
| 927 | }, |
| 928 | } |
| 929 | voltPort := &VoltPort{ |
| 930 | Name: "16777216", |
| 931 | Device: "SDX6320031", |
| 932 | ID: 16777216, |
| 933 | State: PortStateUp, |
| 934 | ChannelPerSubAlarmRaised: false, |
| 935 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 936 | tests := []struct { |
| 937 | name string |
| 938 | args args |
| 939 | }{ |
| 940 | { |
| 941 | name: "VoltApplication_PushDevFlowForVlan", |
| 942 | args: args{ |
| 943 | cntx: context.Background(), |
| 944 | vnet: &VoltVnet{ |
| 945 | Version: "test_version", |
| 946 | VnetConfig: VnetConfig{ |
| 947 | DevicesList: []string{"test_serialNum"}, |
| 948 | SVlan: of.VlanAny, |
| 949 | }, |
| 950 | }, |
| 951 | }, |
| 952 | }, |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 953 | // { |
| 954 | // name: "PushDevFlowForVlan", |
| 955 | // args: args{ |
| 956 | // cntx: context.Background(), |
| 957 | // vnet: voltVnet, |
| 958 | // }, |
| 959 | // }, |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 960 | } |
| 961 | for _, tt := range tests { |
| 962 | t.Run(tt.name, func(t *testing.T) { |
| 963 | va := &VoltApplication{} |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 964 | switch tt.name { |
| 965 | case "VoltApplication_PushDevFlowForVlan": |
| 966 | voltDevice.SerialNum = "test_serialNum" |
| 967 | voltDevice.VlanPortStatus.Store(uint16(of.VlanAny), true) |
| 968 | voltDevice.Name = test_device |
| 969 | va.DevicesDisc.Store(test_device, voltDevice) |
| 970 | va.PortsDisc.Store("16777216", voltPort) |
| 971 | ga := GetApplication() |
| 972 | ga.DevicesDisc.Store(test_device, voltDevice) |
| 973 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 974 | va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet) |
| 975 | case "PushDevFlowForVlan": |
| 976 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 977 | voltDevice.VlanPortStatus.Store(uint16(0), true) |
| 978 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 979 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 980 | va.PortsDisc.Store("16777472", voltPort) |
| 981 | voltApp := GetApplication() |
| 982 | voltApp.DevicesDisc.Store("SDX6320031", voltDev) |
| 983 | _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t))) |
| 984 | va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet) |
| 985 | } |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 986 | }) |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | func TestVoltApplication_PushDevFlowForDevice(t *testing.T) { |
| 991 | type args struct { |
| 992 | cntx context.Context |
| 993 | device *VoltDevice |
| 994 | } |
| 995 | tests := []struct { |
| 996 | name string |
| 997 | args args |
| 998 | }{ |
| 999 | { |
| 1000 | name: "device.ConfiguredVlanForDeviceFlows is ok", |
| 1001 | args: args{ |
| 1002 | cntx: context.Background(), |
| 1003 | device: &VoltDevice{ |
| 1004 | Name: test_device, |
| 1005 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 1006 | }, |
| 1007 | }, |
| 1008 | }, |
| 1009 | { |
| 1010 | name: "device.VlanPortStatus is false", |
| 1011 | args: args{ |
| 1012 | cntx: context.Background(), |
| 1013 | device: &VoltDevice{ |
| 1014 | Name: test_device, |
| 1015 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 1016 | NniPort: "test_nni_port", |
| 1017 | }, |
| 1018 | }, |
| 1019 | }, |
| 1020 | { |
| 1021 | name: "device.VlanPortStatus is true", |
| 1022 | args: args{ |
| 1023 | cntx: context.Background(), |
| 1024 | device: &VoltDevice{ |
| 1025 | Name: test_device, |
| 1026 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 1027 | NniPort: "test_nni_port", |
| 1028 | VlanPortStatus: sync.Map{}, |
| 1029 | }, |
| 1030 | }, |
| 1031 | }, |
| 1032 | } |
| 1033 | for _, tt := range tests { |
| 1034 | t.Run(tt.name, func(t *testing.T) { |
| 1035 | va := &VoltApplication{} |
| 1036 | switch tt.name { |
| 1037 | case "device.ConfiguredVlanForDeviceFlows is ok": |
| 1038 | va.VnetsByName.Store("test_vnet_name", &VoltVnet{ |
| 1039 | Version: "test_version", |
| 1040 | }) |
| 1041 | tt.args.device.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 1042 | va.PushDevFlowForDevice(tt.args.cntx, tt.args.device) |
| 1043 | case "device.VlanPortStatus is false": |
| 1044 | va.VnetsByName.Store("test_vnet_name", &VoltVnet{ |
| 1045 | Version: "test_version", |
| 1046 | }) |
| 1047 | va.PortsDisc.Store("test_nni_port", &VoltPort{ |
| 1048 | Name: "test_name", |
| 1049 | }) |
| 1050 | va.PushDevFlowForDevice(tt.args.cntx, tt.args.device) |
| 1051 | case "device.VlanPortStatus is true": |
| 1052 | va.VnetsByName.Store("test_vnet_name", &VoltVnet{ |
| 1053 | Version: "test_version", |
| 1054 | VnetConfig: VnetConfig{ |
| 1055 | SVlan: of.VlanAny, |
| 1056 | }, |
| 1057 | }) |
| 1058 | va.PortsDisc.Store("test_nni_port", &VoltPort{ |
| 1059 | Name: "test_name", |
| 1060 | }) |
| 1061 | tt.args.device.VlanPortStatus.Store(uint16(of.VlanAny), true) |
| 1062 | va.PushDevFlowForDevice(tt.args.cntx, tt.args.device) |
| 1063 | } |
| 1064 | }) |
| 1065 | } |
| 1066 | } |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 1067 | |
| 1068 | func TestNewVoltPortVnet(t *testing.T) { |
| 1069 | type args struct { |
| 1070 | vnet *VoltVnet |
| 1071 | } |
| 1072 | usDhcpPbit := []of.PbitType{} |
| 1073 | usDhcpPbit = append(usDhcpPbit, PbitMatchNone) |
| 1074 | tests := []struct { |
| 1075 | name string |
| 1076 | args args |
| 1077 | want *VoltPortVnet |
| 1078 | }{ |
| 1079 | { |
| 1080 | name: "NewVoltPortVnet", |
| 1081 | args: args{ |
| 1082 | vnet: &VoltVnet{ |
| 1083 | VnetConfig: VnetConfig{ |
| 1084 | UsDhcpPbit: usDhcpPbit, |
| 1085 | }, |
| 1086 | }, |
| 1087 | }, |
| 1088 | want: &VoltPortVnet{}, |
| 1089 | }, |
| 1090 | } |
| 1091 | for _, tt := range tests { |
| 1092 | t.Run(tt.name, func(t *testing.T) { |
| 1093 | got := NewVoltPortVnet(tt.args.vnet) |
| 1094 | assert.NotNil(t, got) |
| 1095 | }) |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | func TestVoltPortVnet_GetCircuitID(t *testing.T) { |
| 1100 | vpv := &VoltPortVnet{} |
| 1101 | got := vpv.GetCircuitID() |
| 1102 | assert.Nil(t, got) |
| 1103 | got1 := vpv.GetRemoteID() |
| 1104 | assert.Nil(t, got1) |
| 1105 | got3 := vpv.GetDhcpState() |
| 1106 | assert.NotNil(t, got3) |
| 1107 | got4 := vpv.GetPppoeIaState() |
| 1108 | assert.NotNil(t, got4) |
| 1109 | got5 := vpv.GetDhcpv6State() |
| 1110 | assert.NotNil(t, got5) |
| 1111 | } |
| 1112 | |
| 1113 | func TestVoltPortVnet_GetNniVlans(t *testing.T) { |
| 1114 | tests := []struct { |
| 1115 | name string |
| 1116 | want uint16 |
| 1117 | want1 uint16 |
| 1118 | }{ |
| 1119 | { |
| 1120 | name: "GetNniVlans", |
| 1121 | want: uint16(of.VlanAny), |
| 1122 | want1: uint16(of.VlanAny), |
| 1123 | }, |
| 1124 | { |
| 1125 | name: "GetNniVlans_OLTSVlan", |
| 1126 | want: uint16(of.VlanAny), |
| 1127 | want1: uint16(of.VlanNone), |
| 1128 | }, |
| 1129 | { |
| 1130 | name: "GetNniVlans_Default", |
| 1131 | want: uint16(of.VlanNone), |
| 1132 | want1: uint16(of.VlanNone), |
| 1133 | }, |
| 1134 | } |
| 1135 | for _, tt := range tests { |
| 1136 | t.Run(tt.name, func(t *testing.T) { |
| 1137 | vpv := &VoltPortVnet{ |
| 1138 | VlanControl: ONUCVlanOLTSVlan, |
| 1139 | SVlan: of.VlanAny, |
| 1140 | CVlan: of.VlanAny, |
| 1141 | } |
| 1142 | switch tt.name { |
| 1143 | case "GetNniVlans": |
| 1144 | got, got1 := vpv.GetNniVlans() |
| 1145 | if got != tt.want { |
| 1146 | t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want) |
| 1147 | } |
| 1148 | if got1 != tt.want1 { |
| 1149 | t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1) |
| 1150 | } |
| 1151 | case "GetNniVlans_OLTSVlan": |
| 1152 | vpv.VlanControl = OLTSVlan |
| 1153 | got, got1 := vpv.GetNniVlans() |
| 1154 | if got != tt.want { |
| 1155 | t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want) |
| 1156 | } |
| 1157 | if got1 != tt.want1 { |
| 1158 | t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1) |
| 1159 | } |
| 1160 | case "GetNniVlans_Default": |
| 1161 | vpv.VlanControl = opt82 |
| 1162 | got, got1 := vpv.GetNniVlans() |
| 1163 | if got != tt.want { |
| 1164 | t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want) |
| 1165 | } |
| 1166 | if got1 != tt.want1 { |
| 1167 | t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1) |
| 1168 | } |
| 1169 | } |
| 1170 | }) |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | func TestVoltPortVnet_GetService(t *testing.T) { |
| 1175 | type args struct { |
| 1176 | name string |
| 1177 | } |
| 1178 | voltServ := &VoltService{ |
| 1179 | VoltServiceOper: VoltServiceOper{ |
| 1180 | Device: "SDX6320031", |
| 1181 | }, |
| 1182 | VoltServiceCfg: VoltServiceCfg{ |
| 1183 | IsActivated: true, |
| 1184 | }, |
| 1185 | } |
| 1186 | tests := []struct { |
| 1187 | name string |
| 1188 | args args |
| 1189 | want *VoltService |
| 1190 | want1 bool |
| 1191 | }{ |
| 1192 | { |
| 1193 | name: "GetService", |
| 1194 | args: args{ |
| 1195 | name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65", |
| 1196 | }, |
| 1197 | want: voltServ, |
| 1198 | want1: true, |
| 1199 | }, |
| 1200 | } |
| 1201 | for _, tt := range tests { |
| 1202 | t.Run(tt.name, func(t *testing.T) { |
| 1203 | vpv := &VoltPortVnet{} |
| 1204 | vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ) |
| 1205 | got, got1 := vpv.GetService(tt.args.name) |
| 1206 | if !reflect.DeepEqual(got, tt.want) { |
| 1207 | t.Errorf("VoltPortVnet.GetService() got = %v, want %v", got, tt.want) |
| 1208 | } |
| 1209 | if got1 != tt.want1 { |
| 1210 | t.Errorf("VoltPortVnet.GetService() got1 = %v, want %v", got1, tt.want1) |
| 1211 | } |
| 1212 | }) |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | func TestVoltPortVnet_ProcessDhcpSuccess(t *testing.T) { |
| 1217 | type args struct { |
| 1218 | cntx context.Context |
| 1219 | res *layers.DHCPv4 |
| 1220 | } |
| 1221 | tests := []struct { |
| 1222 | name string |
| 1223 | args args |
| 1224 | }{ |
| 1225 | { |
| 1226 | name: "ProcessDhcpSuccess", |
| 1227 | args: args{ |
| 1228 | cntx: context.Background(), |
| 1229 | res: &layers.DHCPv4{}, |
| 1230 | }, |
| 1231 | }, |
| 1232 | } |
| 1233 | for _, tt := range tests { |
| 1234 | t.Run(tt.name, func(t *testing.T) { |
| 1235 | vpv := &VoltPortVnet{ |
| 1236 | servicesCount: atomic.NewUint64(0), |
| 1237 | } |
| 1238 | vpv.ProcessDhcpSuccess(tt.args.cntx, tt.args.res) |
| 1239 | }) |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | func TestVoltPortVnet_ProcessDhcpResult(t *testing.T) { |
| 1244 | type args struct { |
| 1245 | cntx context.Context |
| 1246 | res *layers.DHCPv4 |
| 1247 | } |
| 1248 | tests := []struct { |
| 1249 | name string |
| 1250 | args args |
| 1251 | }{ |
| 1252 | { |
| 1253 | name: "ProcessDhcpResult", |
| 1254 | args: args{ |
| 1255 | cntx: context.Background(), |
| 1256 | res: &layers.DHCPv4{}, |
| 1257 | }, |
| 1258 | }, |
| 1259 | } |
| 1260 | for _, tt := range tests { |
| 1261 | t.Run(tt.name, func(t *testing.T) { |
| 1262 | vpv := &VoltPortVnet{} |
| 1263 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1264 | db = dbintf |
| 1265 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1266 | vpv.ProcessDhcpResult(tt.args.cntx, tt.args.res) |
| 1267 | }) |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | func TestVoltVnet_associatePortToVnet(t *testing.T) { |
| 1272 | type args struct { |
| 1273 | port string |
| 1274 | } |
| 1275 | tests := []struct { |
| 1276 | name string |
| 1277 | args args |
| 1278 | }{ |
| 1279 | { |
| 1280 | name: "ProcessDhcpResult", |
| 1281 | args: args{ |
| 1282 | port: "SDX6320031-1", |
| 1283 | }, |
| 1284 | }, |
| 1285 | } |
| 1286 | for _, tt := range tests { |
| 1287 | t.Run(tt.name, func(t *testing.T) { |
| 1288 | vv := &VoltVnet{} |
| 1289 | vv.associatePortToVnet(tt.args.port) |
| 1290 | }) |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | func TestVoltPortVnet_ProcessDhcpv6Result(t *testing.T) { |
| 1295 | type args struct { |
| 1296 | cntx context.Context |
| 1297 | ipv6Addr net.IP |
| 1298 | leaseTime uint32 |
| 1299 | } |
| 1300 | tests := []struct { |
| 1301 | name string |
| 1302 | args args |
| 1303 | }{ |
| 1304 | { |
| 1305 | name: "ProcessDhcpResult", |
| 1306 | args: args{ |
| 1307 | cntx: context.Background(), |
| 1308 | ipv6Addr: AllSystemsMulticastGroupIP, |
| 1309 | leaseTime: uint32(128), |
| 1310 | }, |
| 1311 | }, |
| 1312 | } |
| 1313 | for _, tt := range tests { |
| 1314 | t.Run(tt.name, func(t *testing.T) { |
| 1315 | vpv := &VoltPortVnet{} |
| 1316 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1317 | db = dbintf |
| 1318 | dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1319 | vpv.ProcessDhcpv6Result(tt.args.cntx, tt.args.ipv6Addr, tt.args.leaseTime) |
| 1320 | }) |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | func TestAddSvcUsMeterToDevice(t *testing.T) { |
| 1325 | type args struct { |
| 1326 | cntx context.Context |
| 1327 | key interface{} |
| 1328 | value interface{} |
| 1329 | flag bool |
| 1330 | } |
| 1331 | vpv := &VoltApplication{} |
| 1332 | voltServ := &VoltService{ |
| 1333 | VoltServiceOper: VoltServiceOper{ |
| 1334 | Device: test_device, |
| 1335 | ForceDelete: true, |
| 1336 | }, |
| 1337 | } |
| 1338 | vpv.ServiceByName.Store(test_device, voltServ) |
| 1339 | tests := []struct { |
| 1340 | name string |
| 1341 | args args |
| 1342 | want bool |
| 1343 | }{ |
| 1344 | { |
| 1345 | name: "ProcessDhcpResult", |
| 1346 | args: args{ |
| 1347 | cntx: context.Background(), |
| 1348 | key: test_device, |
| 1349 | value: voltServ, |
| 1350 | }, |
| 1351 | }, |
| 1352 | } |
| 1353 | for _, tt := range tests { |
| 1354 | t.Run(tt.name, func(t *testing.T) { |
| 1355 | if got := AddSvcUsMeterToDevice(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want { |
| 1356 | t.Errorf("AddSvcUsMeterToDevice() = %v, want %v", got, tt.want) |
| 1357 | } |
| 1358 | }) |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | func TestClearFlagsInService(t *testing.T) { |
| 1363 | type args struct { |
| 1364 | cntx context.Context |
| 1365 | key interface{} |
| 1366 | value interface{} |
| 1367 | flag bool |
| 1368 | } |
| 1369 | vpv := &VoltPortVnet{} |
| 1370 | voltServ := &VoltService{ |
| 1371 | VoltServiceOper: VoltServiceOper{ |
| 1372 | Device: "SDX6320031", |
| 1373 | }, |
| 1374 | VoltServiceCfg: VoltServiceCfg{ |
| 1375 | IsActivated: true, |
| 1376 | }, |
| 1377 | } |
| 1378 | vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ) |
| 1379 | tests := []struct { |
| 1380 | name string |
| 1381 | args args |
| 1382 | want bool |
| 1383 | }{ |
| 1384 | { |
| 1385 | name: "ClearFlagsInService", |
| 1386 | args: args{ |
| 1387 | cntx: context.Background(), |
| 1388 | key: test_device, |
| 1389 | value: voltServ, |
| 1390 | }, |
| 1391 | }, |
| 1392 | } |
| 1393 | for _, tt := range tests { |
| 1394 | t.Run(tt.name, func(t *testing.T) { |
| 1395 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1396 | db = dbintf |
| 1397 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() |
| 1398 | got := ClearFlagsInService(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag) |
| 1399 | assert.NotNil(t, got) |
| 1400 | }) |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | func TestVoltPortVnet_DelDhcpFlows(t *testing.T) { |
| 1405 | type args struct { |
| 1406 | cntx context.Context |
| 1407 | } |
| 1408 | tests := []struct { |
| 1409 | name string |
| 1410 | args args |
| 1411 | }{ |
| 1412 | { |
| 1413 | name: "DelDhcpFlows", |
| 1414 | args: args{ |
| 1415 | cntx: context.Background(), |
| 1416 | }, |
| 1417 | }, |
| 1418 | } |
| 1419 | for _, tt := range tests { |
| 1420 | t.Run(tt.name, func(t *testing.T) { |
| 1421 | vpv := &VoltPortVnet{} |
| 1422 | vpv.DelDhcpFlows(tt.args.cntx) |
| 1423 | }) |
| 1424 | } |
| 1425 | } |
| 1426 | |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1427 | func TestVoltPortVnet_PushFlowsForPortVnet(t *testing.T) { |
| 1428 | type args struct { |
| 1429 | cntx context.Context |
| 1430 | d *VoltDevice |
| 1431 | } |
| 1432 | va := GetApplication() |
| 1433 | voltDev := &VoltDevice{ |
| 1434 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1435 | SerialNum: "SDX6320031", |
| 1436 | NniDhcpTrapVid: 123, |
| 1437 | State: cntlr.DeviceStateUP, |
| 1438 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1439 | Ports: sync.Map{}, |
| 1440 | } |
| 1441 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1442 | voltPort := &VoltPort{ |
| 1443 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1444 | Device: "SDX6320031", |
| 1445 | ID: 16777472, |
| 1446 | State: PortStateUp, |
| 1447 | Type: VoltPortTypeNni, |
| 1448 | } |
| 1449 | voltDev.Ports.Store("16777472", voltPort) |
| 1450 | tests := []struct { |
| 1451 | name string |
| 1452 | args args |
| 1453 | }{ |
| 1454 | { |
| 1455 | name: "PushFlowsForPortVnet", |
| 1456 | args: args{ |
| 1457 | cntx: context.Background(), |
| 1458 | d: voltDev, |
| 1459 | }, |
| 1460 | }, |
| 1461 | { |
| 1462 | name: "PushFlowsForPortVnet_PortDown", |
| 1463 | args: args{ |
| 1464 | cntx: context.Background(), |
| 1465 | d: voltDev, |
| 1466 | }, |
| 1467 | }, |
| 1468 | } |
| 1469 | for _, tt := range tests { |
| 1470 | t.Run(tt.name, func(t *testing.T) { |
| 1471 | vpv := &VoltPortVnet{} |
| 1472 | switch tt.name { |
| 1473 | case "PushFlowsForPortVnet_PortDown": |
| 1474 | vpv.PushFlowsForPortVnet(tt.args.cntx, tt.args.d) |
| 1475 | case "PushFlowsForPortVnet": |
| 1476 | vpv.Port = "16777472" |
| 1477 | vpv.PushFlowsForPortVnet(tt.args.cntx, tt.args.d) |
| 1478 | } |
| 1479 | }) |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | func TestVoltPortVnet_setLearntMAC(t *testing.T) { |
| 1484 | type args struct { |
| 1485 | cntx context.Context |
| 1486 | key interface{} |
| 1487 | value interface{} |
| 1488 | flag bool |
| 1489 | } |
| 1490 | voltServ := &VoltService{ |
| 1491 | VoltServiceOper: VoltServiceOper{ |
| 1492 | Device: test_device, |
| 1493 | ForceDelete: true, |
| 1494 | }, |
| 1495 | } |
| 1496 | tests := []struct { |
| 1497 | name string |
| 1498 | args args |
| 1499 | want bool |
| 1500 | }{ |
| 1501 | { |
| 1502 | name: "setLearntMAC", |
| 1503 | args: args{ |
| 1504 | cntx: context.Background(), |
| 1505 | key: test_device, |
| 1506 | value: voltServ, |
| 1507 | }, |
| 1508 | want: true, |
| 1509 | }, |
| 1510 | { |
| 1511 | name: "updateIPv4AndProvisionFlows", |
| 1512 | args: args{ |
| 1513 | cntx: context.Background(), |
| 1514 | key: test_device, |
| 1515 | value: voltServ, |
| 1516 | }, |
| 1517 | want: true, |
| 1518 | }, |
| 1519 | { |
| 1520 | name: "updateIPv6AndProvisionFlows", |
| 1521 | args: args{ |
| 1522 | cntx: context.Background(), |
| 1523 | key: test_device, |
| 1524 | value: voltServ, |
| 1525 | }, |
| 1526 | want: true, |
| 1527 | }, |
| 1528 | } |
| 1529 | for _, tt := range tests { |
| 1530 | t.Run(tt.name, func(t *testing.T) { |
| 1531 | vpv := &VoltPortVnet{ |
| 1532 | MacAddr: net.HardwareAddr(pendingPoolTimer), |
| 1533 | Ipv4Addr: AllSystemsMulticastGroupIP, |
| 1534 | Ipv6Addr: AllSystemsMulticastGroupIP, |
| 1535 | } |
| 1536 | vpv.services.Store(test_device, voltServ) |
| 1537 | dbintf := mocks.NewMockDBIntf(gomock.NewController(t)) |
| 1538 | db = dbintf |
| 1539 | dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) |
| 1540 | switch tt.name { |
| 1541 | case "setLearntMAC": |
| 1542 | if got := vpv.setLearntMAC(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want { |
| 1543 | t.Errorf("VoltPortVnet.setLearntMAC() = %v, want %v", got, tt.want) |
| 1544 | } |
| 1545 | case "updateIPv4AndProvisionFlows": |
| 1546 | if got := vpv.updateIPv4AndProvisionFlows(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want { |
| 1547 | t.Errorf("VoltPortVnet.updateIPv4AndProvisionFlows() = %v, want %v", got, tt.want) |
| 1548 | } |
| 1549 | case "updateIPv6AndProvisionFlows": |
| 1550 | if got := vpv.updateIPv6AndProvisionFlows(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want { |
| 1551 | t.Errorf("VoltPortVnet.updateIPv6AndProvisionFlows() = %v, want %v", got, tt.want) |
| 1552 | } |
| 1553 | } |
| 1554 | }) |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | func TestAddMeterToDevice(t *testing.T) { |
| 1559 | type args struct { |
| 1560 | cntx context.Context |
| 1561 | key interface{} |
| 1562 | value interface{} |
| 1563 | flag bool |
| 1564 | } |
| 1565 | voltServ := &VoltService{ |
| 1566 | VoltServiceOper: VoltServiceOper{ |
| 1567 | Device: test_device, |
| 1568 | ForceDelete: true, |
| 1569 | }, |
| 1570 | } |
| 1571 | tests := []struct { |
| 1572 | name string |
| 1573 | args args |
| 1574 | want bool |
| 1575 | }{ |
| 1576 | { |
| 1577 | name: "TestAddMeterToDevice", |
| 1578 | args: args{ |
| 1579 | cntx: context.Background(), |
| 1580 | key: test_device, |
| 1581 | value: voltServ, |
| 1582 | }, |
| 1583 | want: true, |
| 1584 | }, |
| 1585 | } |
| 1586 | for _, tt := range tests { |
| 1587 | t.Run(tt.name, func(t *testing.T) { |
| 1588 | if got := AddMeterToDevice(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want { |
| 1589 | t.Errorf("AddMeterToDevice() = %v, want %v", got, tt.want) |
| 1590 | } |
| 1591 | }) |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | func TestVoltPortVnet_AddUsArpFlows(t *testing.T) { |
| 1596 | type args struct { |
| 1597 | cntx context.Context |
| 1598 | } |
| 1599 | va := GetApplication() |
| 1600 | voltDev := &VoltDevice{ |
| 1601 | Name: "SDX6320031", |
| 1602 | SerialNum: "SDX6320031", |
| 1603 | NniDhcpTrapVid: 123, |
| 1604 | State: cntlr.DeviceStateUP, |
| 1605 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1606 | Ports: sync.Map{}, |
| 1607 | } |
| 1608 | voltPort := &VoltPort{ |
| 1609 | Name: "16777472", |
| 1610 | Device: "SDX6320031", |
| 1611 | ID: 16777472, |
| 1612 | State: PortStateUp, |
| 1613 | ChannelPerSubAlarmRaised: false, |
| 1614 | } |
| 1615 | tests := []struct { |
| 1616 | name string |
| 1617 | args args |
| 1618 | wantErr bool |
| 1619 | }{ |
| 1620 | { |
| 1621 | name: "AddUsArpFlows", |
| 1622 | args: args{ |
| 1623 | cntx: context.Background(), |
| 1624 | }, |
| 1625 | wantErr: true, |
| 1626 | }, |
| 1627 | { |
| 1628 | name: "AddUsArpFlows_DeviceNotFound", |
| 1629 | args: args{ |
| 1630 | cntx: context.Background(), |
| 1631 | }, |
| 1632 | wantErr: true, |
| 1633 | }, |
| 1634 | { |
| 1635 | name: "AddUsArpFlows_DeviceStateDOWN", |
| 1636 | args: args{ |
| 1637 | cntx: context.Background(), |
| 1638 | }, |
| 1639 | }, |
| 1640 | } |
| 1641 | for _, tt := range tests { |
| 1642 | t.Run(tt.name, func(t *testing.T) { |
| 1643 | vpv := &VoltPortVnet{ |
| 1644 | Device: deviceName, |
| 1645 | MacLearning: MacLearningNone, |
| 1646 | MacAddr: BroadcastMAC, |
| 1647 | Port: "16777472", |
| 1648 | } |
| 1649 | va.DevicesDisc.Store(deviceName, voltDev) |
| 1650 | va.PortsDisc.Store("16777472", voltPort) |
| 1651 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 1652 | cntlr.NewController(ctx, appMock) |
| 1653 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1654 | portsByName := map[string]*cntlr.DevicePort{} |
| 1655 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 1656 | Name: "16777472", |
| 1657 | ID: 256, |
| 1658 | } |
| 1659 | device := &cntlr.Device{ |
| 1660 | ID: deviceName, |
| 1661 | PortsByName: portsByName, |
| 1662 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 1663 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1664 | switch tt.name { |
| 1665 | case "AddUsArpFlows": |
| 1666 | if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1667 | t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1668 | } |
| 1669 | case "AddUsArpFlows_DeviceNotFound": |
| 1670 | vpv.Device = "" |
| 1671 | if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1672 | t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1673 | } |
| 1674 | case "AddUsArpFlows_DeviceStateDOWN": |
| 1675 | vpv.Device = deviceName |
| 1676 | voltDev.State = cntlr.DeviceStateDOWN |
| 1677 | if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1678 | t.Errorf("VoltPortVnet.AddUsArpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1679 | } |
| 1680 | } |
| 1681 | }) |
| 1682 | } |
| 1683 | } |
| 1684 | |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 1685 | func TestVoltPortVnet_AddDsDhcpFlows(t *testing.T) { |
| 1686 | type args struct { |
| 1687 | cntx context.Context |
| 1688 | } |
| 1689 | va := GetApplication() |
| 1690 | voltDev := &VoltDevice{ |
| 1691 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1692 | SerialNum: "SDX6320031", |
| 1693 | NniDhcpTrapVid: 123, |
| 1694 | State: cntlr.DeviceStateUP, |
| 1695 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1696 | } |
| 1697 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1698 | voltPort := &VoltPort{ |
| 1699 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 1700 | Device: "SDX6320031", |
| 1701 | ID: 16777472, |
| 1702 | State: PortStateDown, |
| 1703 | ChannelPerSubAlarmRaised: false, |
| 1704 | Type: VoltPortTypeNni, |
| 1705 | } |
| 1706 | tests := []struct { |
| 1707 | name string |
| 1708 | args args |
| 1709 | wantErr bool |
| 1710 | }{ |
| 1711 | { |
| 1712 | name: "AddDsDhcpFlows", |
| 1713 | args: args{ |
| 1714 | cntx: context.Background(), |
| 1715 | }, |
| 1716 | }, |
| 1717 | { |
| 1718 | name: "AddDsDhcpFlows_DeviceNotFound", |
| 1719 | args: args{ |
| 1720 | cntx: context.Background(), |
| 1721 | }, |
| 1722 | wantErr: true, |
| 1723 | }, |
| 1724 | { |
| 1725 | name: "AddDsDhcpFlows_StateDown", |
| 1726 | args: args{ |
| 1727 | cntx: context.Background(), |
| 1728 | }, |
| 1729 | }, |
| 1730 | { |
| 1731 | name: "AddDsDhcpFlows_GlobalDhcpFlowAdded", |
| 1732 | args: args{ |
| 1733 | cntx: context.Background(), |
| 1734 | }, |
| 1735 | }, |
| 1736 | { |
| 1737 | name: "AddDsDhcpFlows_PositiveSenario", |
| 1738 | args: args{ |
| 1739 | cntx: context.Background(), |
| 1740 | }, |
| 1741 | }, |
| 1742 | } |
| 1743 | for _, tt := range tests { |
| 1744 | t.Run(tt.name, func(t *testing.T) { |
| 1745 | vpv := &VoltPortVnet{ |
| 1746 | Device: "SDX6320031", |
| 1747 | } |
| 1748 | switch tt.name { |
| 1749 | case "AddDsDhcpFlows": |
| 1750 | if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1751 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1752 | } |
| 1753 | case "AddDsDhcpFlows_DeviceNotFound": |
| 1754 | vpv.Device = "" |
| 1755 | if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1756 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1757 | } |
| 1758 | case "AddDsDhcpFlows_StateDown": |
| 1759 | voltDev.State = cntlr.DeviceStateDOWN |
| 1760 | if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1761 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1762 | } |
| 1763 | case "AddDsDhcpFlows_GlobalDhcpFlowAdded": |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1764 | vpv.Device = deviceName |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 1765 | voltDev.State = cntlr.DeviceStateUP |
| 1766 | voltDev.GlobalDhcpFlowAdded = true |
| 1767 | if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1768 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1769 | } |
| 1770 | case "AddDsDhcpFlows_PositiveSenario": |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1771 | vpv.Device = deviceName |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 1772 | voltDev.State = cntlr.DeviceStateUP |
| 1773 | voltDev.GlobalDhcpFlowAdded = false |
| 1774 | voltDev.NniPort = "16777472" |
| 1775 | va.PortsDisc.Store("16777472", voltPort) |
| 1776 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 1777 | cntlr.NewController(ctx, appMock) |
| 1778 | vc := cntlr.GetController() |
| 1779 | device := &cntlr.Device{ |
| 1780 | ID: "SDX6320031", |
| 1781 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 1782 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 1783 | if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1784 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1785 | } |
| 1786 | } |
| 1787 | }) |
| 1788 | } |
| 1789 | } |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1790 | |
| 1791 | func TestVoltPortVnet_AddUsDhcpFlows(t *testing.T) { |
| 1792 | type args struct { |
| 1793 | cntx context.Context |
| 1794 | } |
| 1795 | va := GetApplication() |
| 1796 | voltDev := &VoltDevice{ |
| 1797 | Name: "SDX6320031", |
| 1798 | SerialNum: "SDX6320031", |
| 1799 | NniDhcpTrapVid: 123, |
| 1800 | State: cntlr.DeviceStateUP, |
| 1801 | NniPort: "16777472", |
| 1802 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1803 | } |
| 1804 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1805 | voltPort := &VoltPort{ |
| 1806 | Name: "16777472", |
| 1807 | Device: "SDX6320031", |
| 1808 | ID: 16777472, |
| 1809 | State: PortStateDown, |
| 1810 | ChannelPerSubAlarmRaised: false, |
| 1811 | Type: VoltPortTypeNni, |
| 1812 | } |
| 1813 | tests := []struct { |
| 1814 | name string |
| 1815 | args args |
| 1816 | wantErr bool |
| 1817 | }{ |
| 1818 | { |
| 1819 | name: "AddUsDhcpFlows_PositiveSenario", |
| 1820 | args: args{ |
| 1821 | cntx: context.Background(), |
| 1822 | }, |
| 1823 | }, |
| 1824 | { |
| 1825 | name: "AddUsDhcpFlows_StateDown", |
| 1826 | args: args{ |
| 1827 | cntx: context.Background(), |
| 1828 | }, |
| 1829 | }, |
| 1830 | { |
| 1831 | name: "AddUsDhcpFlows_DeviceNotFound", |
| 1832 | args: args{ |
| 1833 | cntx: context.Background(), |
| 1834 | }, |
| 1835 | wantErr: true, |
| 1836 | }, |
| 1837 | { |
| 1838 | name: "AddUsDhcpFlows_GlobalDhcpFlowAdded", |
| 1839 | args: args{ |
| 1840 | cntx: context.Background(), |
| 1841 | }, |
| 1842 | }, |
| 1843 | } |
| 1844 | for _, tt := range tests { |
| 1845 | t.Run(tt.name, func(t *testing.T) { |
| 1846 | vpv := &VoltPortVnet{ |
| 1847 | Device: "SDX6320031", |
| 1848 | VnetType: DpuMgmtTraffic, |
| 1849 | Port: "16777472", |
| 1850 | } |
| 1851 | switch tt.name { |
| 1852 | case "AddUsDhcpFlows_PositiveSenario": |
| 1853 | va.PortsDisc.Store("16777472", voltPort) |
| 1854 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 1855 | cntlr.NewController(ctx, appMock) |
| 1856 | vc := cntlr.GetController() |
| 1857 | device := &cntlr.Device{ |
| 1858 | ID: "SDX6320031", |
| 1859 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 1860 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1861 | if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1862 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1863 | } |
| 1864 | case "AddUsDhcpFlows_DeviceNotFound": |
| 1865 | vpv.Device = "" |
| 1866 | if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1867 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1868 | } |
| 1869 | case "AddUsDhcpFlows_StateDown": |
| 1870 | voltDev.State = cntlr.DeviceStateDOWN |
| 1871 | if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1872 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1873 | } |
| 1874 | case "AddUsDhcpFlows_GlobalDhcpFlowAdded": |
| 1875 | vpv.Device = "SDX6320031" |
| 1876 | voltDev.State = cntlr.DeviceStateUP |
| 1877 | vpv.Port = "" |
| 1878 | if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1879 | t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1880 | } |
| 1881 | } |
| 1882 | }) |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | func TestVoltPortVnet_AddUsPppoeFlows(t *testing.T) { |
| 1887 | type args struct { |
| 1888 | cntx context.Context |
| 1889 | } |
| 1890 | va := GetApplication() |
| 1891 | voltDev := &VoltDevice{ |
| 1892 | Name: "SDX6320031", |
| 1893 | SerialNum: "SDX6320031", |
| 1894 | NniDhcpTrapVid: 123, |
| 1895 | State: cntlr.DeviceStateUP, |
| 1896 | NniPort: "16777472", |
| 1897 | FlowAddEventMap: util.NewConcurrentMap(), |
| 1898 | } |
| 1899 | voltPort := &VoltPort{ |
| 1900 | Name: "16777472", |
| 1901 | Device: "SDX6320031", |
| 1902 | ID: 16777472, |
| 1903 | State: PortStateUp, |
| 1904 | ChannelPerSubAlarmRaised: false, |
| 1905 | } |
| 1906 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 1907 | va.PortsDisc.Store("16777472", voltPort) |
| 1908 | tests := []struct { |
| 1909 | name string |
| 1910 | args args |
| 1911 | wantErr bool |
| 1912 | }{ |
| 1913 | { |
| 1914 | name: "AddUsPppoeFlows", |
| 1915 | args: args{ |
| 1916 | cntx: context.Background(), |
| 1917 | }, |
| 1918 | wantErr: true, |
| 1919 | }, |
| 1920 | { |
| 1921 | name: "AddDsPppoeFlows", |
| 1922 | args: args{ |
| 1923 | cntx: context.Background(), |
| 1924 | }, |
| 1925 | wantErr: true, |
| 1926 | }, |
| 1927 | { |
| 1928 | name: "AddUsPppoeFlows_StateDown", |
| 1929 | args: args{ |
| 1930 | cntx: context.Background(), |
| 1931 | }, |
| 1932 | }, |
| 1933 | { |
| 1934 | name: "AddDsPppoeFlows_StateDown", |
| 1935 | args: args{ |
| 1936 | cntx: context.Background(), |
| 1937 | }, |
| 1938 | }, |
| 1939 | { |
| 1940 | name: "AddUsPppoeFlows_DeviceNotFound", |
| 1941 | args: args{ |
| 1942 | cntx: context.Background(), |
| 1943 | }, |
| 1944 | wantErr: true, |
| 1945 | }, |
| 1946 | { |
| 1947 | name: "AddDsPppoeFlows_DeviceNotFound", |
| 1948 | args: args{ |
| 1949 | cntx: context.Background(), |
| 1950 | }, |
| 1951 | wantErr: true, |
| 1952 | }, |
| 1953 | } |
| 1954 | for _, tt := range tests { |
| 1955 | t.Run(tt.name, func(t *testing.T) { |
| 1956 | vpv := &VoltPortVnet{ |
| 1957 | Device: "SDX6320031", |
| 1958 | MacLearning: MacLearningNone, |
| 1959 | MacAddr: net.HardwareAddr(pendingPoolTimer), |
| 1960 | } |
| 1961 | switch tt.name { |
| 1962 | case "AddUsPppoeFlows": |
| 1963 | if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1964 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1965 | } |
| 1966 | case "AddDsPppoeFlows": |
| 1967 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 1968 | cntlr.NewController(ctx, appMock) |
| 1969 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1970 | portsByName := map[string]*cntlr.DevicePort{} |
| 1971 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 1972 | Name: "16777472", |
| 1973 | ID: 256, |
| 1974 | } |
| 1975 | device := &cntlr.Device{ |
| 1976 | ID: "SDX6320031", |
| 1977 | PortsByName: portsByName, |
| 1978 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 1979 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 1980 | if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1981 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1982 | } |
| 1983 | case "AddUsPppoeFlows_StateDown": |
| 1984 | voltDev.State = cntlr.DeviceStateDOWN |
| 1985 | if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1986 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1987 | } |
| 1988 | case "AddDsPppoeFlows_StateDown": |
| 1989 | voltDev.State = cntlr.DeviceStateDOWN |
| 1990 | if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1991 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1992 | } |
| 1993 | case "AddUsPppoeFlows_DeviceNotFound": |
| 1994 | vpv.Device = "" |
| 1995 | if err := vpv.AddUsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 1996 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 1997 | } |
| 1998 | case "AddDsPppoeFlows_DeviceNotFound": |
| 1999 | vpv.Device = "" |
| 2000 | if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 2001 | t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 2002 | } |
| 2003 | } |
| 2004 | }) |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | func TestVoltPortVnet_AddIgmpFlows(t *testing.T) { |
| 2009 | type args struct { |
| 2010 | cntx context.Context |
| 2011 | } |
| 2012 | var voltPortTest = &VoltPort{ |
| 2013 | Name: "test_name", |
| 2014 | State: PortStateUp, |
| 2015 | } |
| 2016 | tests := []struct { |
| 2017 | name string |
| 2018 | args args |
| 2019 | wantErr bool |
| 2020 | }{ |
| 2021 | { |
| 2022 | name: "AddIgmpFlows", |
| 2023 | args: args{ |
| 2024 | cntx: context.Background(), |
| 2025 | }, |
| 2026 | wantErr: true, |
| 2027 | }, |
| 2028 | } |
| 2029 | for _, tt := range tests { |
| 2030 | t.Run(tt.name, func(t *testing.T) { |
| 2031 | vpv := &VoltPortVnet{ |
| 2032 | MvlanProfileName: "mvlan_profile", |
| 2033 | } |
| 2034 | va := GetApplication() |
| 2035 | va.PortsDisc.Store("test_port", voltPortTest) |
| 2036 | if err := vpv.AddIgmpFlows(tt.args.cntx); (err != nil) != tt.wantErr { |
| 2037 | t.Errorf("VoltPortVnet.AddIgmpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 2038 | } |
| 2039 | }) |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | func TestVoltPortVnet_BuildUsDhcp6Flows(t *testing.T) { |
| 2044 | voltPort := &VoltPort{ |
| 2045 | Name: "16777216", |
| 2046 | Device: "SDX6320031", |
| 2047 | ID: 16777216, |
| 2048 | State: PortStateDown, |
| 2049 | ChannelPerSubAlarmRaised: false, |
| 2050 | Type: VoltPortTypeNni, |
| 2051 | } |
| 2052 | voltService := &VoltService{ |
| 2053 | Version: "test_version", |
| 2054 | VoltServiceCfg: VoltServiceCfg{ |
| 2055 | VnetID: "test_vnet_id", |
| 2056 | Port: "16777216", |
| 2057 | SVlan: of.VlanAny, |
| 2058 | CVlan: of.VlanAny, |
| 2059 | UniVlan: of.VlanAny, |
| 2060 | }, |
| 2061 | } |
| 2062 | voltDev := &VoltDevice{ |
| 2063 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2064 | SerialNum: "SDX6320031", |
| 2065 | NniDhcpTrapVid: 123, |
| 2066 | State: cntlr.DeviceStateUP, |
| 2067 | NniPort: "16777216", |
| 2068 | Ports: sync.Map{}, |
| 2069 | } |
| 2070 | tests := []struct { |
| 2071 | name string |
| 2072 | want *of.VoltFlow |
| 2073 | wantErr bool |
| 2074 | }{ |
| 2075 | { |
| 2076 | name: "BuildUsDhcp6Flows", |
| 2077 | want: &of.VoltFlow{}, |
| 2078 | }, |
| 2079 | { |
| 2080 | name: "BuildDsDhcp6Flows", |
| 2081 | want: &of.VoltFlow{}, |
| 2082 | }, |
| 2083 | { |
| 2084 | name: "BuildDsDhcp6Flows_DeviceNotFound", |
| 2085 | want: &of.VoltFlow{}, |
| 2086 | wantErr: true, |
| 2087 | }, |
| 2088 | { |
| 2089 | name: "BuildUsDhcp6Flows_portnotfound", |
| 2090 | want: &of.VoltFlow{}, |
| 2091 | wantErr: true, |
| 2092 | }, |
| 2093 | { |
| 2094 | name: "BuildDsDhcp6Flows_portnotfound", |
| 2095 | want: &of.VoltFlow{}, |
| 2096 | wantErr: true, |
| 2097 | }, |
| 2098 | } |
| 2099 | for _, tt := range tests { |
| 2100 | t.Run(tt.name, func(t *testing.T) { |
| 2101 | vpv := &VoltPortVnet{ |
| 2102 | Port: "16777216", |
| 2103 | services: sync.Map{}, |
| 2104 | AllowTransparent: true, |
| 2105 | Device: "SDX6320031", |
| 2106 | } |
| 2107 | va := GetApplication() |
| 2108 | va.PortsDisc.Store("16777216", voltPort) |
| 2109 | vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltService) |
| 2110 | switch tt.name { |
| 2111 | case "BuildUsDhcp6Flows": |
| 2112 | got, err := vpv.BuildUsDhcp6Flows() |
| 2113 | if (err != nil) != tt.wantErr { |
| 2114 | t.Errorf("VoltPortVnet.BuildUsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr) |
| 2115 | return |
| 2116 | } |
| 2117 | assert.NotNil(t, got) |
| 2118 | case "BuildDsDhcp6Flows": |
| 2119 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2120 | got, err := vpv.BuildDsDhcp6Flows() |
| 2121 | if (err != nil) != tt.wantErr { |
| 2122 | t.Errorf("VoltPortVnet.BuildDsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr) |
| 2123 | return |
| 2124 | } |
| 2125 | assert.NotNil(t, got) |
| 2126 | case "BuildDsDhcp6Flows_DeviceNotFound": |
| 2127 | vpv.Device = "" |
| 2128 | got, err := vpv.BuildDsDhcp6Flows() |
| 2129 | if (err != nil) != tt.wantErr { |
| 2130 | t.Errorf("VoltPortVnet.BuildDsDhcp6Flows() error = %v, wantErr %v", err, tt.wantErr) |
| 2131 | return |
| 2132 | } |
| 2133 | assert.Nil(t, got) |
| 2134 | case "BuildUsDhcp6Flows_portnotfound": |
| 2135 | vpv.Port = "" |
| 2136 | got, err := vpv.BuildUsDhcp6Flows() |
| 2137 | if (err != nil) != tt.wantErr { |
| 2138 | t.Errorf("VoltPortVnet.BuildUsDhcp6Flows_portnotfound() error = %v, wantErr %v", err, tt.wantErr) |
| 2139 | return |
| 2140 | } |
| 2141 | assert.Nil(t, got) |
| 2142 | case "BuildDsDhcp6Flows_portnotfound": |
| 2143 | voltDev.NniPort = "abc" |
| 2144 | got, err := vpv.BuildDsDhcp6Flows() |
| 2145 | if (err != nil) != tt.wantErr { |
| 2146 | t.Errorf("VoltPortVnet.BuildDsDhcp6Flows_portnotfound() error = %v, wantErr %v", err, tt.wantErr) |
| 2147 | return |
| 2148 | } |
| 2149 | assert.Nil(t, got) |
| 2150 | } |
| 2151 | }) |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | func TestVoltPortVnet_setUsMatchVlan(t *testing.T) { |
| 2156 | type args struct { |
| 2157 | flow *of.VoltSubFlow |
| 2158 | } |
| 2159 | tests := []struct { |
| 2160 | name string |
| 2161 | args args |
| 2162 | wantErr bool |
| 2163 | }{ |
| 2164 | { |
| 2165 | name: "setUsMatchVlan", |
| 2166 | args: args{ |
| 2167 | flow: &of.VoltSubFlow{}, |
| 2168 | }, |
| 2169 | }, |
| 2170 | { |
| 2171 | name: "OLTCVlanOLTSVlan", |
| 2172 | args: args{ |
| 2173 | flow: &of.VoltSubFlow{}, |
| 2174 | }, |
| 2175 | }, |
| 2176 | { |
| 2177 | name: "ONUCVlan", |
| 2178 | args: args{ |
| 2179 | flow: &of.VoltSubFlow{}, |
| 2180 | }, |
| 2181 | }, |
| 2182 | { |
| 2183 | name: "OLTSVlan", |
| 2184 | args: args{ |
| 2185 | flow: &of.VoltSubFlow{}, |
| 2186 | }, |
| 2187 | }, |
| 2188 | { |
| 2189 | name: "Default", |
| 2190 | args: args{ |
| 2191 | flow: &of.VoltSubFlow{}, |
| 2192 | }, |
| 2193 | wantErr: true, |
| 2194 | }, |
| 2195 | { |
| 2196 | name: "setDsMatchVlan_OLTCVlanOLTSVlan", |
| 2197 | args: args{ |
| 2198 | flow: &of.VoltSubFlow{}, |
| 2199 | }, |
| 2200 | }, |
| 2201 | { |
| 2202 | name: "setDsMatchVlan_Default", |
| 2203 | args: args{ |
| 2204 | flow: &of.VoltSubFlow{}, |
| 2205 | }, |
| 2206 | }, |
| 2207 | } |
| 2208 | for _, tt := range tests { |
| 2209 | t.Run(tt.name, func(t *testing.T) { |
| 2210 | vpv := &VoltPortVnet{ |
| 2211 | VlanControl: ONUCVlanOLTSVlan, |
| 2212 | } |
| 2213 | switch tt.name { |
| 2214 | case "setUsMatchVlan": |
| 2215 | if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr { |
| 2216 | t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr) |
| 2217 | } |
| 2218 | case "OLTCVlanOLTSVlan": |
| 2219 | vpv.VlanControl = OLTCVlanOLTSVlan |
| 2220 | if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr { |
| 2221 | t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr) |
| 2222 | } |
| 2223 | case "ONUCVlan": |
| 2224 | vpv.VlanControl = ONUCVlan |
| 2225 | if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr { |
| 2226 | t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr) |
| 2227 | } |
| 2228 | case "OLTSVlan": |
| 2229 | vpv.VlanControl = OLTSVlan |
| 2230 | if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr { |
| 2231 | t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr) |
| 2232 | } |
| 2233 | case "Default": |
| 2234 | vpv.VlanControl = opt82 |
| 2235 | if err := vpv.setUsMatchVlan(tt.args.flow); (err != nil) != tt.wantErr { |
| 2236 | t.Errorf("VoltPortVnet.setUsMatchVlan() error = %v, wantErr %v", err, tt.wantErr) |
| 2237 | } |
| 2238 | case "setDsMatchVlan_OLTCVlanOLTSVlan": |
| 2239 | vpv.VlanControl = OLTCVlanOLTSVlan |
| 2240 | vpv.setDsMatchVlan(tt.args.flow) |
| 2241 | case "setDsMatchVlan_Default": |
| 2242 | vpv.VlanControl = opt82 |
| 2243 | vpv.setDsMatchVlan(tt.args.flow) |
| 2244 | } |
| 2245 | }) |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | func TestVoltPortVnet_BuildIgmpFlows(t *testing.T) { |
| 2250 | va := GetApplication() |
| 2251 | devicesList := make(map[string]OperInProgress) |
| 2252 | devicesList["SDX6320030"] = opt82 |
| 2253 | mvp := &MvlanProfile{ |
| 2254 | Name: "mvlan_test", |
| 2255 | DevicesList: devicesList, |
| 2256 | } |
| 2257 | va.MvlanProfilesByName.Store("mvlan_test", mvp) |
| 2258 | voltPort := &VoltPort{ |
| 2259 | Name: "16777472", |
| 2260 | Device: "SDX6320031", |
| 2261 | ID: 16777472, |
| 2262 | State: PortStateUp, |
| 2263 | ChannelPerSubAlarmRaised: false, |
| 2264 | } |
| 2265 | va.PortsDisc.Store("16777472", voltPort) |
| 2266 | tests := []struct { |
| 2267 | name string |
| 2268 | want *of.VoltFlow |
| 2269 | wantErr bool |
| 2270 | }{ |
| 2271 | { |
| 2272 | name: "BuildIgmpFlows", |
| 2273 | want: &of.VoltFlow{}, |
| 2274 | }, |
| 2275 | { |
| 2276 | name: "BuildIgmpFlows_McastService_False", |
| 2277 | want: &of.VoltFlow{}, |
| 2278 | }, |
| 2279 | { |
| 2280 | name: "BuildIgmpFlows_PortNotFound", |
| 2281 | want: nil, |
| 2282 | wantErr: true, |
| 2283 | }, |
| 2284 | } |
| 2285 | for _, tt := range tests { |
| 2286 | t.Run(tt.name, func(t *testing.T) { |
| 2287 | vpv := &VoltPortVnet{ |
| 2288 | Port: "16777472", |
| 2289 | MvlanProfileName: "mvlan_test", |
| 2290 | MacLearning: MacLearningNone, |
| 2291 | MacAddr: util.Uint32ToByte(uint32(23)), |
| 2292 | McastService: true, |
| 2293 | AllowTransparent: true, |
| 2294 | } |
| 2295 | |
| 2296 | switch tt.name { |
| 2297 | case "BuildIgmpFlows": |
| 2298 | got, err := vpv.BuildIgmpFlows() |
| 2299 | if (err != nil) != tt.wantErr { |
| 2300 | t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 2301 | return |
| 2302 | } |
| 2303 | assert.NotNil(t, got) |
| 2304 | case "BuildIgmpFlows_McastService_False": |
| 2305 | vpv.McastService = false |
| 2306 | vpv.services.Store("16777472", &VoltService{}) |
| 2307 | got, err := vpv.BuildIgmpFlows() |
| 2308 | if (err != nil) != tt.wantErr { |
| 2309 | t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 2310 | return |
| 2311 | } |
| 2312 | assert.NotNil(t, got) |
| 2313 | case "BuildIgmpFlows_PortNotFound": |
| 2314 | vpv.Port = "" |
| 2315 | got, err := vpv.BuildIgmpFlows() |
| 2316 | if (err != nil) != tt.wantErr { |
| 2317 | t.Errorf("VoltPortVnet.BuildIgmpFlows() error = %v, wantErr %v", err, tt.wantErr) |
| 2318 | return |
| 2319 | } |
| 2320 | assert.Nil(t, got) |
| 2321 | } |
| 2322 | }) |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | func TestVoltPortVnet_SetMacAddr(t *testing.T) { |
| 2327 | type args struct { |
| 2328 | cntx context.Context |
| 2329 | addr net.HardwareAddr |
| 2330 | } |
| 2331 | addr, _ := net.ParseMAC("00:00:11:00:00:00") |
| 2332 | macAddr, _ := net.ParseMAC("00:00:00:00:00:11") |
| 2333 | tests := []struct { |
| 2334 | name string |
| 2335 | args args |
| 2336 | }{ |
| 2337 | { |
| 2338 | name: "SetMacAddr", |
| 2339 | args: args{ |
| 2340 | cntx: context.Background(), |
| 2341 | addr: addr, |
| 2342 | }, |
| 2343 | }, |
| 2344 | } |
| 2345 | for _, tt := range tests { |
| 2346 | t.Run(tt.name, func(t *testing.T) { |
| 2347 | vpv := &VoltPortVnet{ |
| 2348 | MacAddr: macAddr, |
| 2349 | MacLearning: MaxLenDhcpv6DUID, |
| 2350 | FlowsApplied: true, |
| 2351 | } |
| 2352 | switch tt.name { |
| 2353 | case "SetMacAddr": |
| 2354 | vpv.SetMacAddr(tt.args.cntx, tt.args.addr) |
| 2355 | } |
| 2356 | }) |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | func TestVoltPortVnet_AddTrapFlows(t *testing.T) { |
| 2361 | type args struct { |
| 2362 | cntx context.Context |
| 2363 | } |
| 2364 | tests := []struct { |
| 2365 | name string |
| 2366 | args args |
| 2367 | }{ |
| 2368 | { |
| 2369 | name: "AddTrapFlows", |
| 2370 | args: args{ |
| 2371 | cntx: context.Background(), |
| 2372 | }, |
| 2373 | }, |
| 2374 | { |
| 2375 | name: "AddTrapFlows_ArpRelay", |
| 2376 | args: args{ |
| 2377 | cntx: context.Background(), |
| 2378 | }, |
| 2379 | }, |
| 2380 | { |
| 2381 | name: "AddTrapFlows_PppoeIa", |
| 2382 | args: args{ |
| 2383 | cntx: context.Background(), |
| 2384 | }, |
| 2385 | }, |
| 2386 | } |
| 2387 | for _, tt := range tests { |
| 2388 | t.Run(tt.name, func(t *testing.T) { |
| 2389 | vpv := &VoltPortVnet{ |
| 2390 | DhcpRelay: true, |
| 2391 | DeleteInProgress: true, |
| 2392 | } |
| 2393 | switch tt.name { |
| 2394 | case "AddTrapFlows": |
| 2395 | vpv.AddTrapFlows(tt.args.cntx) |
| 2396 | case "AddTrapFlows_ArpRelay": |
| 2397 | vpv.DhcpRelay = false |
| 2398 | vpv.ArpRelay = true |
| 2399 | vpv.AddTrapFlows(tt.args.cntx) |
| 2400 | case "AddTrapFlows_PppoeIa": |
| 2401 | vpv.DhcpRelay = false |
| 2402 | vpv.ArpRelay = false |
| 2403 | vpv.PppoeIa = true |
| 2404 | vpv.AddTrapFlows(tt.args.cntx) |
| 2405 | } |
| 2406 | }) |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | func TestVoltPortVnet_DelTrapFlows(t *testing.T) { |
| 2411 | type args struct { |
| 2412 | cntx context.Context |
| 2413 | } |
| 2414 | tests := []struct { |
| 2415 | name string |
| 2416 | args args |
| 2417 | }{ |
| 2418 | { |
| 2419 | name: "DelTrapFlows", |
| 2420 | args: args{ |
| 2421 | cntx: context.Background(), |
| 2422 | }, |
| 2423 | }, |
| 2424 | } |
| 2425 | for _, tt := range tests { |
| 2426 | t.Run(tt.name, func(t *testing.T) { |
| 2427 | vpv := &VoltPortVnet{ |
| 2428 | FlowsApplied: true, |
| 2429 | DhcpRelay: true, |
| 2430 | DeleteInProgress: true, |
| 2431 | } |
| 2432 | switch tt.name { |
| 2433 | case "DelTrapFlows": |
| 2434 | vpv.DelTrapFlows(tt.args.cntx) |
| 2435 | } |
| 2436 | }) |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | func TestVoltPortVnet_delDsDhcp4Flows(t *testing.T) { |
| 2441 | type args struct { |
| 2442 | cntx context.Context |
| 2443 | device *VoltDevice |
| 2444 | } |
| 2445 | voltDev := &VoltDevice{ |
| 2446 | Name: "49686e2d-618f-4e8e-bca0-442ab850a63a", |
| 2447 | SerialNum: "SDX6320031", |
| 2448 | NniDhcpTrapVid: 123, |
| 2449 | State: cntlr.DeviceStateUP, |
| 2450 | NniPort: "16777472", |
| 2451 | Ports: sync.Map{}, |
| 2452 | FlowDelEventMap: util.NewConcurrentMap(), |
| 2453 | } |
| 2454 | va := GetApplication() |
| 2455 | devicesList := make(map[string]OperInProgress) |
| 2456 | devicesList["SDX6320031"] = opt82 |
| 2457 | mvp := &MvlanProfile{ |
| 2458 | Name: "mvlan_test", |
| 2459 | DevicesList: devicesList, |
| 2460 | } |
| 2461 | va.MvlanProfilesByName.Store("mvlan_test", mvp) |
| 2462 | voltPort := &VoltPort{ |
| 2463 | Name: "16777472", |
| 2464 | Device: "SDX6320031", |
| 2465 | ID: 16777472, |
| 2466 | State: PortStateUp, |
| 2467 | ChannelPerSubAlarmRaised: false, |
| 2468 | } |
| 2469 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2470 | va.PortsDisc.Store("16777472", voltPort) |
| 2471 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 2472 | controller.NewController(ctx, appMock) |
| 2473 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2474 | portsByName := map[string]*cntlr.DevicePort{} |
| 2475 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 2476 | Name: "16777472", |
| 2477 | ID: 256, |
| 2478 | } |
| 2479 | device := &cntlr.Device{ |
| 2480 | ID: deviceName, |
| 2481 | PortsByName: portsByName, |
| 2482 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 2483 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2484 | tests := []struct { |
| 2485 | name string |
| 2486 | args args |
| 2487 | wantErr bool |
| 2488 | }{ |
| 2489 | { |
| 2490 | name: "delDsDhcp4Flows", |
| 2491 | args: args{ |
| 2492 | cntx: context.Background(), |
| 2493 | device: voltDev, |
| 2494 | }, |
| 2495 | wantErr: true, |
| 2496 | }, |
| 2497 | } |
| 2498 | for _, tt := range tests { |
| 2499 | t.Run(tt.name, func(t *testing.T) { |
| 2500 | vpv := &VoltPortVnet{ |
| 2501 | Device: "SDX6320031", |
| 2502 | Port: "16777472", |
| 2503 | MvlanProfileName: "mvlan_test", |
| 2504 | MacLearning: MacLearningNone, |
| 2505 | MacAddr: util.Uint32ToByte(uint32(23)), |
| 2506 | McastService: true, |
| 2507 | AllowTransparent: true, |
| 2508 | PendingDeleteFlow: make(map[string]bool), |
| 2509 | } |
| 2510 | if err := vpv.delDsDhcp4Flows(tt.args.cntx, tt.args.device); (err != nil) != tt.wantErr { |
| 2511 | t.Errorf("VoltPortVnet.delDsDhcp4Flows() error = %v, wantErr %v", err, tt.wantErr) |
| 2512 | } |
| 2513 | }) |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | func TestVoltApplication_DeleteDevFlowForVlan(t *testing.T) { |
| 2518 | type args struct { |
| 2519 | cntx context.Context |
| 2520 | vnet *VoltVnet |
| 2521 | } |
| 2522 | voltDev := &VoltDevice{ |
| 2523 | Name: "SDX6320031", |
| 2524 | SerialNum: "SDX6320031", |
| 2525 | NniDhcpTrapVid: 123, |
| 2526 | State: cntlr.DeviceStateUP, |
| 2527 | NniPort: "16777472", |
| 2528 | Ports: sync.Map{}, |
| 2529 | FlowDelEventMap: util.NewConcurrentMap(), |
| 2530 | ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(), |
| 2531 | } |
| 2532 | voltVnet := &VoltVnet{ |
| 2533 | Version: "v3", |
| 2534 | VnetConfig: VnetConfig{ |
| 2535 | Name: "2310-4096-4096", |
| 2536 | VnetType: "Encapsulation", |
| 2537 | }, |
| 2538 | VnetOper: VnetOper{ |
| 2539 | PendingDeviceToDelete: "SDX6320031", |
| 2540 | DeleteInProgress: true, |
| 2541 | PendingDeleteFlow: make(map[string]map[string]bool), |
| 2542 | }, |
| 2543 | } |
| 2544 | voltPort := &VoltPort{ |
| 2545 | Name: "16777472", |
| 2546 | Device: "SDX6320031", |
| 2547 | ID: 16777472, |
| 2548 | State: PortStateUp, |
| 2549 | ChannelPerSubAlarmRaised: false, |
| 2550 | } |
| 2551 | tests := []struct { |
| 2552 | name string |
| 2553 | args args |
| 2554 | }{ |
| 2555 | { |
| 2556 | name: "DeleteDevFlowForVlan", |
| 2557 | args: args{ |
| 2558 | cntx: context.Background(), |
| 2559 | vnet: voltVnet, |
| 2560 | }, |
| 2561 | }, |
| 2562 | { |
| 2563 | name: "DeleteDevFlowForVlan_PortStateDown", |
| 2564 | args: args{ |
| 2565 | cntx: context.Background(), |
| 2566 | vnet: voltVnet, |
| 2567 | }, |
| 2568 | }, |
| 2569 | } |
| 2570 | for _, tt := range tests { |
| 2571 | t.Run(tt.name, func(t *testing.T) { |
| 2572 | va := &VoltApplication{} |
| 2573 | switch tt.name { |
| 2574 | case "DeleteDevFlowForVlan": |
| 2575 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2576 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 2577 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 2578 | va.PortsDisc.Store("16777472", voltPort) |
| 2579 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 2580 | cntlr.NewController(ctx, appMock) |
| 2581 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2582 | portsByName := map[string]*cntlr.DevicePort{} |
| 2583 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 2584 | Name: "16777472", |
| 2585 | ID: 256, |
| 2586 | State: cntlr.PortStateUp, |
| 2587 | } |
| 2588 | device := &cntlr.Device{ |
| 2589 | ID: "SDX6320031", |
| 2590 | PortsByName: portsByName, |
| 2591 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 2592 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2593 | va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet) |
| 2594 | case "DeleteDevFlowForVlan_PortStateDown": |
| 2595 | voltDev.Name = "" |
| 2596 | va.DevicesDisc.Store("SDX6320031", voltDev) |
| 2597 | va.VnetsByName.Store("2310-4096-4096", voltVnet) |
| 2598 | voltDev.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap()) |
| 2599 | va.PortsDisc.Store("16777472", voltPort) |
| 2600 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 2601 | cntlr.NewController(ctx, appMock) |
| 2602 | vc := cntlr.GetController() |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2603 | portsByName := map[string]*cntlr.DevicePort{} |
| 2604 | portsByName["16777472"] = &cntlr.DevicePort{ |
| 2605 | Name: "16777472", |
| 2606 | ID: 256, |
| 2607 | State: cntlr.PortStateUp, |
| 2608 | } |
| 2609 | device := &cntlr.Device{ |
| 2610 | ID: "SDX6320031", |
| 2611 | PortsByName: portsByName, |
| 2612 | } |
bseeniva | a8cb94c | 2024-12-16 13:37:17 +0530 | [diff] [blame] | 2613 | vc.Devices.Store("SDX6320031", device) |
Akash Soni | b03636c | 2023-10-31 12:30:59 +0530 | [diff] [blame] | 2614 | va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet) |
| 2615 | } |
| 2616 | }) |
| 2617 | } |
| 2618 | } |