blob: 04bed122aeb7a08e1b37a56b09f5057bc1b8c09b [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
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
16package application
17
18import (
19 "context"
20 "testing"
21 "voltha-go-controller/internal/pkg/intf"
22 "voltha-go-controller/internal/pkg/of"
23 "voltha-go-controller/internal/pkg/util"
24 "voltha-go-controller/internal/test/mocks"
25
26 "github.com/golang/mock/gomock"
27)
28
29var voltPortVnet = &VoltPortVnet{
30 Device: "test_device",
31}
32var voltService = &VoltService{
33 Version: "test_version",
34}
35
36func TestExecuteFlowEvent(t *testing.T) {
37 type args struct {
38 cntx context.Context
39 vd *VoltDevice
40 cookie string
41 flowStatus intf.FlowStatus
42 }
43 tests := []struct {
44 name string
45 args args
46 want bool
47 }{
48 {
49 name: "ExecuteFlowEvent_add",
50 args: args{
51 cntx: context.Background(),
52 vd: &VoltDevice{
53 SouthBoundID: "test_device_id",
54 FlowAddEventMap: util.NewConcurrentMap(),
55 },
56 cookie: "test_cookie",
57 flowStatus: intf.FlowStatus{
58 Device: "test_device",
59 FlowModType: of.CommandAdd,
60 },
61 },
62 },
63 {
64 name: "ExecuteFlowEvent_del",
65 args: args{
66 cntx: context.Background(),
67 vd: &VoltDevice{
68 SouthBoundID: "test_device_id",
69 FlowDelEventMap: util.NewConcurrentMap(),
70 },
71 cookie: "test_cookie",
72 flowStatus: intf.FlowStatus{
73 Device: "test_device",
74 FlowModType: of.CommandDel,
75 },
76 },
77 },
78 }
79 for _, tt := range tests {
80 t.Run(tt.name, func(t *testing.T) {
81 switch tt.name {
82 case "ExecuteFlowEvent_add":
83 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
84 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
85 }
86 case "ExecuteFlowEvent_del":
87 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
88 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
89 }
90 }
91 })
92 }
93}
94
95func TestInitEventFuncMapper(t *testing.T) {
96 tests := []struct {
97 name string
98 }{
99 {
100 name: "InitEventFuncMapper",
101 },
102 }
103 for _, tt := range tests {
104 t.Run(tt.name, func(t *testing.T) {
105 InitEventFuncMapper()
106 })
107 }
108}
109
110func TestProcessUsIgmpFlowAddEvent(t *testing.T) {
111 type args struct {
112 cntx context.Context
113 event *FlowEvent
114 flowStatus intf.FlowStatus
115 }
116 tests := []struct {
117 name string
118 args args
119 }{
120 {
121 name: "ProcessUsIgmpFlowAddEvent",
122 args: args{
123 cntx: context.Background(),
124 event: &FlowEvent{
125 device: "test_device",
126 eType: EventTypeControlFlowAdded,
127 eventData: voltPortVnet,
128 },
129 flowStatus: intf.FlowStatus{
130 Device: "test_device",
131 Status: uint32(0),
132 },
133 },
134 },
vinokuma04dc9f82023-07-31 15:47:49 +0530135 {
136 name: "ProcessUsIgmpFlowAddEvent_else_condition",
137 args: args{
138 cntx: context.Background(),
139 event: &FlowEvent{
140 device: "test_device",
141 eType: EventTypeControlFlowAdded,
142 eventData: voltPortVnet,
143 },
144 flowStatus: intf.FlowStatus{
145 Device: "test_device",
146 Status: uint32(1001),
147 },
148 },
149 },
vinokumaf7605fc2023-06-02 18:08:01 +0530150 }
151 for _, tt := range tests {
152 t.Run(tt.name, func(t *testing.T) {
Akash Sonief452f12024-12-12 18:20:28 +0530153 ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530154 })
155 }
156}
157
158func TestProcessServiceFlowAddEvent(t *testing.T) {
159 type args struct {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530160 cntx context.Context
161 event *FlowEvent
162 flowStatus intf.FlowStatus
163 flowEventMap *util.ConcurrentMap
164 }
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +0530165
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530166 vs := &VoltService{
Akash Sonief452f12024-12-12 18:20:28 +0530167 VoltServiceCfg: VoltServiceCfg{},
vinokumaf7605fc2023-06-02 18:08:01 +0530168 }
169
170 tests := []struct {
171 name string
172 args args
173 }{
174 {
175 name: "ProcessServiceFlowAddEvent",
176 args: args{
177 cntx: context.Background(),
178 event: &FlowEvent{
179 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530180 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530181 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530182 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530183 },
184 },
vinokuma04dc9f82023-07-31 15:47:49 +0530185 {
186 name: "ProcessServiceFlowAddEvent_else_condition",
187 args: args{
188 cntx: context.Background(),
189 event: &FlowEvent{
190 device: "test_device",
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530191 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530192 },
193 flowStatus: intf.FlowStatus{
194 Status: uint32(1001),
195 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530196 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530197 },
198 },
vinokumaf7605fc2023-06-02 18:08:01 +0530199 }
200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
Akash Sonief452f12024-12-12 18:20:28 +0530202 ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530203 })
204 }
205}
206
207func TestProcessControlFlowAddEvent(t *testing.T) {
208 type args struct {
209 cntx context.Context
210 event *FlowEvent
211 flowStatus intf.FlowStatus
212 }
213 tests := []struct {
214 name string
215 args args
216 }{
217 {
218 name: "ProcessControlFlowAddEvent",
219 args: args{
220 cntx: context.Background(),
221 event: &FlowEvent{
222 eventData: voltPortVnet,
223 },
224 },
225 },
vinokuma04dc9f82023-07-31 15:47:49 +0530226 {
227 name: "ProcessControlFlowAddEvent_else_condition",
228 args: args{
229 cntx: context.Background(),
230 event: &FlowEvent{
231 eventData: voltPortVnet,
232 },
233 flowStatus: intf.FlowStatus{
234 Status: uint32(1001),
235 },
236 },
237 },
vinokumaf7605fc2023-06-02 18:08:01 +0530238 }
239 for _, tt := range tests {
240 t.Run(tt.name, func(t *testing.T) {
Akash Sonief452f12024-12-12 18:20:28 +0530241 ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530242 })
243 }
244}
245
246func TestProcessServiceFlowDelEvent(t *testing.T) {
247 type args struct {
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530248 cntx context.Context
249 event *FlowEvent
250 flowStatus intf.FlowStatus
251 flowEventMap *util.ConcurrentMap
vinokumaf7605fc2023-06-02 18:08:01 +0530252 }
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +0530253
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530254 vs := &VoltService{
Akash Sonief452f12024-12-12 18:20:28 +0530255 VoltServiceCfg: VoltServiceCfg{},
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530256 }
257
vinokumaf7605fc2023-06-02 18:08:01 +0530258 tests := []struct {
259 name string
260 args args
261 }{
262 {
263 name: "ProcessServiceFlowDelEvent",
264 args: args{
265 cntx: context.Background(),
266 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530267 eventData: vs,
vinokumaf7605fc2023-06-02 18:08:01 +0530268 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530269 flowEventMap: util.NewConcurrentMap(),
vinokumaf7605fc2023-06-02 18:08:01 +0530270 },
271 },
vinokuma04dc9f82023-07-31 15:47:49 +0530272 {
273 name: "ProcessServiceFlowDelEvent_else_condition",
274 args: args{
275 cntx: context.Background(),
276 event: &FlowEvent{
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530277 eventData: vs,
vinokuma04dc9f82023-07-31 15:47:49 +0530278 },
279 flowStatus: intf.FlowStatus{
280 Status: uint32(1001),
281 },
Sridhar Ravindra3ec14232024-01-01 19:11:48 +0530282 flowEventMap: util.NewConcurrentMap(),
vinokuma04dc9f82023-07-31 15:47:49 +0530283 },
284 },
vinokumaf7605fc2023-06-02 18:08:01 +0530285 }
286 for _, tt := range tests {
287 t.Run(tt.name, func(t *testing.T) {
288 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
289 db = dbintf
Abhay Kumarfe505f22025-11-10 14:16:31 +0000290 switch tt.name {
291 case "ProcessServiceFlowDelEvent":
292 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
293 case "ProcessServiceFlowDelEvent_else_condition":
294 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
295 }
Akash Sonief452f12024-12-12 18:20:28 +0530296 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530297 })
298 }
299}
300
301func TestProcessControlFlowDelEvent(t *testing.T) {
302 type args struct {
303 cntx context.Context
304 event *FlowEvent
305 flowStatus intf.FlowStatus
306 }
307 tests := []struct {
308 name string
309 args args
310 }{
311 {
312 name: "ProcessControlFlowDelEvent",
313 args: args{
314 cntx: context.Background(),
315 event: &FlowEvent{
316 eventData: voltPortVnet,
317 },
318 },
319 },
vinokuma04dc9f82023-07-31 15:47:49 +0530320 {
321 name: "ProcessControlFlowDelEvent_else_condition",
322 args: args{
323 cntx: context.Background(),
324 event: &FlowEvent{
325 eventData: voltPortVnet,
326 },
327 flowStatus: intf.FlowStatus{
328 Status: uint32(1001),
329 },
330 },
331 },
vinokumaf7605fc2023-06-02 18:08:01 +0530332 }
333 for _, tt := range tests {
334 t.Run(tt.name, func(t *testing.T) {
335 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
336 db = dbintf
337 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530338 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530339 })
340 }
341}
342
343func TestProcessMcastFlowDelEvent(t *testing.T) {
344 type args struct {
345 cntx context.Context
346 event *FlowEvent
347 flowStatus intf.FlowStatus
348 }
349 mvlanProfile := &MvlanProfile{
350 Version: "test_version",
351 }
352 tests := []struct {
353 name string
354 args args
355 }{
356 {
357 name: "ProcessMcastFlowDelEvent",
358 args: args{
359 cntx: context.Background(),
360 event: &FlowEvent{
361 eventData: mvlanProfile,
362 },
363 },
364 },
vinokuma04dc9f82023-07-31 15:47:49 +0530365 {
366 name: "ProcessMcastFlowDelEvent_else_condition",
367 args: args{
368 cntx: context.Background(),
369 event: &FlowEvent{
370 eventData: mvlanProfile,
371 },
372 flowStatus: intf.FlowStatus{
373 Status: uint32(1001),
374 },
375 },
376 },
vinokumaf7605fc2023-06-02 18:08:01 +0530377 }
378 for _, tt := range tests {
379 t.Run(tt.name, func(t *testing.T) {
380 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
381 db = dbintf
Abhay Kumarfe505f22025-11-10 14:16:31 +0000382 switch tt.name {
383 case "ProcessMcastFlowDelEvent":
384 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
385 case "ProcessMcastFlowDelEvent_else_condition":
386 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
387 }
Akash Sonief452f12024-12-12 18:20:28 +0530388 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530389 })
390 }
391}
vinokuma04dc9f82023-07-31 15:47:49 +0530392
393func TestProcessDeviceFlowDelEvent(t *testing.T) {
394 type args struct {
395 cntx context.Context
396 event *FlowEvent
397 flowStatus intf.FlowStatus
398 }
399 tests := []struct {
400 name string
401 args args
402 }{
403 {
404 name: "ProcessDeviceFlowDelEvent",
405 args: args{
406 cntx: context.Background(),
407 event: &FlowEvent{
408 device: test_device,
409 eventData: voltVnet,
410 },
411 flowStatus: intf.FlowStatus{
412 Device: test_device,
413 },
414 },
415 },
416 {
417 name: "ProcessDeviceFlowDelEvent_else_condition",
418 args: args{
419 cntx: context.Background(),
420 event: &FlowEvent{
421 device: test_device,
422 eventData: voltVnet,
423 },
424 flowStatus: intf.FlowStatus{
425 Device: test_device,
426 Status: uint32(1001),
427 },
428 },
429 },
430 }
431 for _, tt := range tests {
432 t.Run(tt.name, func(t *testing.T) {
433 switch tt.name {
434 case "ProcessDeviceFlowDelEvent":
435 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
436 db = dbintf
437 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
Akash Sonief452f12024-12-12 18:20:28 +0530438 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530439 case "ProcessDeviceFlowDelEvent_else_condition":
Akash Sonief452f12024-12-12 18:20:28 +0530440 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530441 }
442 })
443 }
444}