blob: 9736ac38087660b3107e3e1a13cd032736b38592 [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
290 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530291 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530292 })
293 }
294}
295
296func TestProcessControlFlowDelEvent(t *testing.T) {
297 type args struct {
298 cntx context.Context
299 event *FlowEvent
300 flowStatus intf.FlowStatus
301 }
302 tests := []struct {
303 name string
304 args args
305 }{
306 {
307 name: "ProcessControlFlowDelEvent",
308 args: args{
309 cntx: context.Background(),
310 event: &FlowEvent{
311 eventData: voltPortVnet,
312 },
313 },
314 },
vinokuma04dc9f82023-07-31 15:47:49 +0530315 {
316 name: "ProcessControlFlowDelEvent_else_condition",
317 args: args{
318 cntx: context.Background(),
319 event: &FlowEvent{
320 eventData: voltPortVnet,
321 },
322 flowStatus: intf.FlowStatus{
323 Status: uint32(1001),
324 },
325 },
326 },
vinokumaf7605fc2023-06-02 18:08:01 +0530327 }
328 for _, tt := range tests {
329 t.Run(tt.name, func(t *testing.T) {
330 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
331 db = dbintf
332 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 +0530333 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530334 })
335 }
336}
337
338func TestProcessMcastFlowDelEvent(t *testing.T) {
339 type args struct {
340 cntx context.Context
341 event *FlowEvent
342 flowStatus intf.FlowStatus
343 }
344 mvlanProfile := &MvlanProfile{
345 Version: "test_version",
346 }
347 tests := []struct {
348 name string
349 args args
350 }{
351 {
352 name: "ProcessMcastFlowDelEvent",
353 args: args{
354 cntx: context.Background(),
355 event: &FlowEvent{
356 eventData: mvlanProfile,
357 },
358 },
359 },
vinokuma04dc9f82023-07-31 15:47:49 +0530360 {
361 name: "ProcessMcastFlowDelEvent_else_condition",
362 args: args{
363 cntx: context.Background(),
364 event: &FlowEvent{
365 eventData: mvlanProfile,
366 },
367 flowStatus: intf.FlowStatus{
368 Status: uint32(1001),
369 },
370 },
371 },
vinokumaf7605fc2023-06-02 18:08:01 +0530372 }
373 for _, tt := range tests {
374 t.Run(tt.name, func(t *testing.T) {
375 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
376 db = dbintf
377 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
Akash Sonief452f12024-12-12 18:20:28 +0530378 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokumaf7605fc2023-06-02 18:08:01 +0530379 })
380 }
381}
vinokuma04dc9f82023-07-31 15:47:49 +0530382
383func TestProcessDeviceFlowDelEvent(t *testing.T) {
384 type args struct {
385 cntx context.Context
386 event *FlowEvent
387 flowStatus intf.FlowStatus
388 }
389 tests := []struct {
390 name string
391 args args
392 }{
393 {
394 name: "ProcessDeviceFlowDelEvent",
395 args: args{
396 cntx: context.Background(),
397 event: &FlowEvent{
398 device: test_device,
399 eventData: voltVnet,
400 },
401 flowStatus: intf.FlowStatus{
402 Device: test_device,
403 },
404 },
405 },
406 {
407 name: "ProcessDeviceFlowDelEvent_else_condition",
408 args: args{
409 cntx: context.Background(),
410 event: &FlowEvent{
411 device: test_device,
412 eventData: voltVnet,
413 },
414 flowStatus: intf.FlowStatus{
415 Device: test_device,
416 Status: uint32(1001),
417 },
418 },
419 },
420 }
421 for _, tt := range tests {
422 t.Run(tt.name, func(t *testing.T) {
423 switch tt.name {
424 case "ProcessDeviceFlowDelEvent":
425 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
426 db = dbintf
427 dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil).AnyTimes()
Akash Sonief452f12024-12-12 18:20:28 +0530428 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530429 case "ProcessDeviceFlowDelEvent_else_condition":
Akash Sonief452f12024-12-12 18:20:28 +0530430 ProcessDeviceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
vinokuma04dc9f82023-07-31 15:47:49 +0530431 }
432 })
433 }
434}