blob: 5219cf35a3f639e8141a9facdc96bf15d4816c71 [file] [log] [blame]
Scott Baker456b8932019-10-24 10:36:39 -07001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package flows
17
18import (
Esin Karaman20b6de92019-11-05 08:29:16 +000019 "bytes"
serkant.uluderyab38671c2019-11-01 09:35:38 -070020 "strings"
21 "testing"
22
23 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
Scott Baker456b8932019-10-24 10:36:39 -070024 "github.com/stretchr/testify/assert"
25 "google.golang.org/grpc/codes"
26 "google.golang.org/grpc/status"
Scott Baker456b8932019-10-24 10:36:39 -070027)
28
29var (
30 timeoutError error
31 taskFailureError error
32)
33
34func init() {
Scott Baker456b8932019-10-24 10:36:39 -070035 timeoutError = status.Errorf(codes.Aborted, "timeout")
36 taskFailureError = status.Error(codes.Internal, "test failure task")
37 timeoutError = status.Errorf(codes.Aborted, "timeout")
38}
39
40func TestFlowsAndGroups_AddFlow(t *testing.T) {
41 fg := NewFlowsAndGroups()
42 allFlows := fg.ListFlows()
43 assert.Equal(t, 0, len(allFlows))
44 fg.AddFlow(nil)
45 allFlows = fg.ListFlows()
46 assert.Equal(t, 0, len(allFlows))
47
David K. Bainbridge7c75cac2020-02-19 08:53:46 -080048 fa := &FlowArgs{
Scott Baker456b8932019-10-24 10:36:39 -070049 KV: OfpFlowModArgs{"priority": 500},
50 MatchFields: []*ofp.OfpOxmOfbField{
51 InPort(1),
52 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1),
53 TunnelId(uint64(1)),
54 EthType(0x0800),
55 Ipv4Dst(0xffffffff),
56 IpProto(17),
57 UdpSrc(68),
58 UdpDst(67),
59 },
60 Actions: []*ofp.OfpAction{
61 PushVlan(0x8100),
62 SetField(VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)),
63 Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
64 },
65 }
66 flow := MkFlowStat(fa)
67 fg.AddFlow(flow)
68
69 allFlows = fg.ListFlows()
70 assert.Equal(t, 1, len(allFlows))
71 assert.True(t, FlowMatch(flow, allFlows[0]))
72}
73
74func TestFlowsAndGroups_AddGroup(t *testing.T) {
75 var ga *GroupArgs
76
77 fg := NewFlowsAndGroups()
78 allGroups := fg.ListGroups()
79 assert.Equal(t, 0, len(allGroups))
80 fg.AddGroup(nil)
81 allGroups = fg.ListGroups()
82 assert.Equal(t, 0, len(allGroups))
83
84 ga = &GroupArgs{
85 GroupId: 10,
86 Buckets: []*ofp.OfpBucket{
87 {Actions: []*ofp.OfpAction{
88 PopVlan(),
89 Output(1),
90 },
91 },
92 },
93 }
94 group := MkGroupStat(ga)
95 fg.AddGroup(group)
96
97 allGroups = fg.ListGroups()
98 assert.Equal(t, 1, len(allGroups))
99 assert.Equal(t, ga.GroupId, allGroups[0].Desc.GroupId)
100}
101
102func TestFlowsAndGroups_Copy(t *testing.T) {
103 fg := NewFlowsAndGroups()
104 var fa *FlowArgs
105 var ga *GroupArgs
106
107 fa = &FlowArgs{
108 KV: OfpFlowModArgs{"priority": 500},
109 MatchFields: []*ofp.OfpOxmOfbField{
110 InPort(2),
111 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
112 },
113 Actions: []*ofp.OfpAction{
114 SetField(VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 10)),
115 Output(1),
116 },
117 }
118 flow := MkFlowStat(fa)
119 fg.AddFlow(flow)
120
121 ga = &GroupArgs{
122 GroupId: 10,
123 Buckets: []*ofp.OfpBucket{
124 {Actions: []*ofp.OfpAction{
125 PopVlan(),
126 Output(1),
127 },
128 },
129 },
130 }
131 group := MkGroupStat(ga)
132 fg.AddGroup(group)
133
134 fgCopy := fg.Copy()
135
136 allFlows := fgCopy.ListFlows()
137 assert.Equal(t, 1, len(allFlows))
138 assert.True(t, FlowMatch(flow, allFlows[0]))
139
140 allGroups := fgCopy.ListGroups()
141 assert.Equal(t, 1, len(allGroups))
142 assert.Equal(t, ga.GroupId, allGroups[0].Desc.GroupId)
143
144 fg = NewFlowsAndGroups()
145 fgCopy = fg.Copy()
146 allFlows = fgCopy.ListFlows()
147 allGroups = fgCopy.ListGroups()
148 assert.Equal(t, 0, len(allFlows))
149 assert.Equal(t, 0, len(allGroups))
150}
151
152func TestFlowsAndGroups_GetFlow(t *testing.T) {
153 fg := NewFlowsAndGroups()
154 var fa1 *FlowArgs
155 var fa2 *FlowArgs
156 var ga *GroupArgs
157
158 fa1 = &FlowArgs{
159 KV: OfpFlowModArgs{"priority": 500},
160 MatchFields: []*ofp.OfpOxmOfbField{
161 InPort(2),
162 Metadata_ofp((1000 << 32) | 1),
163 VlanPcp(0),
164 },
165 Actions: []*ofp.OfpAction{
166 PopVlan(),
167 },
168 }
169 flow1 := MkFlowStat(fa1)
170
171 fa2 = &FlowArgs{
172 KV: OfpFlowModArgs{"priority": 1500},
173 MatchFields: []*ofp.OfpOxmOfbField{
174 InPort(5),
175 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
176 },
177 Actions: []*ofp.OfpAction{
178 PushVlan(0x8100),
179 SetField(VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1000)),
180 SetField(VlanPcp(0)),
181 Output(2),
182 },
183 }
184 flow2 := MkFlowStat(fa2)
185
186 fg.AddFlow(flow1)
187 fg.AddFlow(flow2)
188
189 ga = &GroupArgs{
190 GroupId: 10,
191 Buckets: []*ofp.OfpBucket{
192 {Actions: []*ofp.OfpAction{
193 PopVlan(),
194 Output(1),
195 },
196 },
197 },
198 }
199 group := MkGroupStat(ga)
200 fg.AddGroup(group)
201
202 gf1 := fg.GetFlow(0)
203 assert.True(t, FlowMatch(flow1, gf1))
204
205 gf2 := fg.GetFlow(1)
206 assert.True(t, FlowMatch(flow2, gf2))
207
208 gf3 := fg.GetFlow(2)
209 assert.Nil(t, gf3)
210
211 allFlows := fg.ListFlows()
212 assert.True(t, FlowMatch(flow1, allFlows[0]))
213 assert.True(t, FlowMatch(flow2, allFlows[1]))
214}
215
216func TestFlowsAndGroups_String(t *testing.T) {
217 fg := NewFlowsAndGroups()
218 var fa *FlowArgs
219 var ga *GroupArgs
220
221 str := fg.String()
222 assert.True(t, str == "")
223
224 fa = &FlowArgs{
225 KV: OfpFlowModArgs{"priority": 500},
226 MatchFields: []*ofp.OfpOxmOfbField{
227 InPort(2),
228 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
229 VlanPcp(0),
230 EthType(0x800),
231 Ipv4Dst(0xe00a0a0a),
232 },
233 Actions: []*ofp.OfpAction{
234 Group(10),
235 },
236 }
237 flow := MkFlowStat(fa)
238 fg.AddFlow(flow)
239
240 ga = &GroupArgs{
241 GroupId: 10,
242 Buckets: []*ofp.OfpBucket{
243 {Actions: []*ofp.OfpAction{
244 PopVlan(),
245 Output(1),
246 },
247 },
248 },
249 }
250 group := MkGroupStat(ga)
251 fg.AddGroup(group)
252
253 str = fg.String()
254 assert.True(t, strings.Contains(str, "id: 1143307409938767207"))
255 assert.True(t, strings.Contains(str, "group_id: 10"))
256 assert.True(t, strings.Contains(str, "oxm_class: OFPXMC_OPENFLOW_BASICOFPXMC_OPENFLOW_BASIC"))
257 assert.True(t, strings.Contains(str, "type: OFPXMT_OFB_VLAN_VIDOFPXMT_OFB_VLAN_VID"))
258 assert.True(t, strings.Contains(str, "vlan_vid: 4096"))
259 assert.True(t, strings.Contains(str, "buckets:"))
260}
261
262func TestFlowsAndGroups_AddFrom(t *testing.T) {
263 fg := NewFlowsAndGroups()
264 var fa *FlowArgs
265 var ga *GroupArgs
266
267 str := fg.String()
268 assert.True(t, str == "")
269
270 fa = &FlowArgs{
271 KV: OfpFlowModArgs{"priority": 500},
272 MatchFields: []*ofp.OfpOxmOfbField{
273 InPort(2),
274 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
275 Metadata_ofp(1000),
276 TunnelId(uint64(1)),
277 VlanPcp(0),
278 },
279 Actions: []*ofp.OfpAction{
280 PopVlan(),
281 Output(1),
282 },
283 }
284 flow := MkFlowStat(fa)
285 fg.AddFlow(flow)
286
287 ga = &GroupArgs{
288 GroupId: 10,
289 Buckets: []*ofp.OfpBucket{
290 {Actions: []*ofp.OfpAction{
291 PopVlan(),
292 Output(1),
293 },
294 },
295 },
296 }
297 group := MkGroupStat(ga)
298 fg.AddGroup(group)
299
300 fg1 := NewFlowsAndGroups()
301 fg1.AddFrom(fg)
302
303 allFlows := fg1.ListFlows()
304 allGroups := fg1.ListGroups()
305 assert.Equal(t, 1, len(allFlows))
306 assert.Equal(t, 1, len(allGroups))
307 assert.True(t, FlowMatch(flow, allFlows[0]))
308 assert.Equal(t, group.Desc.GroupId, allGroups[0].Desc.GroupId)
309}
310
311func TestDeviceRules_AddFlow(t *testing.T) {
312 dr := NewDeviceRules()
313 rules := dr.GetRules()
314 assert.True(t, len(rules) == 0)
315
316 dr.AddFlow("123456", nil)
317 rules = dr.GetRules()
318 assert.True(t, len(rules) == 1)
319 val, ok := rules["123456"]
320 assert.True(t, ok)
321 assert.Equal(t, 0, len(val.ListFlows()))
322 assert.Equal(t, 0, len(val.ListGroups()))
323
David K. Bainbridge7c75cac2020-02-19 08:53:46 -0800324 fa := &FlowArgs{
Scott Baker456b8932019-10-24 10:36:39 -0700325 KV: OfpFlowModArgs{"priority": 500},
326 MatchFields: []*ofp.OfpOxmOfbField{
327 InPort(2),
328 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
329 Metadata_ofp(1000),
330 TunnelId(uint64(1)),
331 VlanPcp(0),
332 },
333 Actions: []*ofp.OfpAction{
334 PopVlan(),
335 Output(1),
336 },
337 }
338 flow := MkFlowStat(fa)
339 dr.AddFlow("123456", flow)
340 rules = dr.GetRules()
341 assert.True(t, len(rules) == 1)
342 val, ok = rules["123456"]
343 assert.True(t, ok)
344 assert.Equal(t, 1, len(val.ListFlows()))
345 assert.True(t, FlowMatch(flow, val.ListFlows()[0]))
346 assert.Equal(t, 0, len(val.ListGroups()))
347}
348
349func TestDeviceRules_AddFlowsAndGroup(t *testing.T) {
350 fg := NewFlowsAndGroups()
351 var fa *FlowArgs
352 var ga *GroupArgs
353
354 str := fg.String()
355 assert.True(t, str == "")
356
357 fa = &FlowArgs{
358 KV: OfpFlowModArgs{"priority": 2000},
359 MatchFields: []*ofp.OfpOxmOfbField{
360 InPort(2),
361 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
362 Metadata_ofp(1000),
363 TunnelId(uint64(1)),
364 VlanPcp(0),
365 },
366 Actions: []*ofp.OfpAction{
367 PopVlan(),
368 Output(1),
369 },
370 }
371 flow := MkFlowStat(fa)
372 fg.AddFlow(flow)
373
374 ga = &GroupArgs{
375 GroupId: 10,
376 Buckets: []*ofp.OfpBucket{
377 {Actions: []*ofp.OfpAction{
378 PopVlan(),
379 Output(1),
380 },
381 },
382 },
383 }
384 group := MkGroupStat(ga)
385 fg.AddGroup(group)
386
387 dr := NewDeviceRules()
388 dr.AddFlowsAndGroup("123456", fg)
389 rules := dr.GetRules()
390 assert.True(t, len(rules) == 1)
391 val, ok := rules["123456"]
392 assert.True(t, ok)
393 assert.Equal(t, 1, len(val.ListFlows()))
394 assert.Equal(t, 1, len(val.ListGroups()))
395 assert.True(t, FlowMatch(flow, val.ListFlows()[0]))
396 assert.Equal(t, 10, int(val.ListGroups()[0].Desc.GroupId))
397}
398
399func TestFlowHasOutPort(t *testing.T) {
400 var flow *ofp.OfpFlowStats
401 assert.False(t, FlowHasOutPort(flow, 1))
402
403 fa := &FlowArgs{
404 KV: OfpFlowModArgs{"priority": 2000},
405 MatchFields: []*ofp.OfpOxmOfbField{
406 InPort(2),
407 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
408 Metadata_ofp(1000),
409 TunnelId(uint64(1)),
410 VlanPcp(0),
411 },
412 Actions: []*ofp.OfpAction{
413 PopVlan(),
414 Output(1),
415 },
416 }
417 flow = MkFlowStat(fa)
418 assert.True(t, FlowHasOutPort(flow, 1))
419 assert.False(t, FlowHasOutPort(flow, 2))
420
421 fa = &FlowArgs{
422 KV: OfpFlowModArgs{"priority": 2000},
423 MatchFields: []*ofp.OfpOxmOfbField{
424 InPort(2),
425 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
426 },
427 }
428 flow = MkFlowStat(fa)
429 assert.False(t, FlowHasOutPort(flow, 1))
430}
431
432func TestFlowHasOutGroup(t *testing.T) {
433 var flow *ofp.OfpFlowStats
434 assert.False(t, FlowHasOutGroup(flow, 10))
435
436 fa := &FlowArgs{
437 KV: OfpFlowModArgs{"priority": 500},
438 MatchFields: []*ofp.OfpOxmOfbField{
439 InPort(2),
440 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
441 VlanPcp(0),
442 EthType(0x800),
443 Ipv4Dst(0xe00a0a0a),
444 },
445 Actions: []*ofp.OfpAction{
446 Group(10),
447 },
448 }
449 flow = MkFlowStat(fa)
450 assert.True(t, FlowHasOutGroup(flow, 10))
451 assert.False(t, FlowHasOutGroup(flow, 11))
452
453 fa = &FlowArgs{
454 KV: OfpFlowModArgs{"priority": 500},
455 MatchFields: []*ofp.OfpOxmOfbField{
456 InPort(2),
457 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
458 VlanPcp(0),
459 EthType(0x800),
460 Ipv4Dst(0xe00a0a0a),
461 },
462 Actions: []*ofp.OfpAction{
463 Output(1),
464 },
465 }
466 flow = MkFlowStat(fa)
467 assert.False(t, FlowHasOutGroup(flow, 1))
468}
469
470func TestMatchFlow(t *testing.T) {
471 assert.False(t, FlowMatch(nil, nil))
472 fa := &FlowArgs{
473 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
474 MatchFields: []*ofp.OfpOxmOfbField{
475 InPort(2),
476 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
477 VlanPcp(0),
478 EthType(0x800),
479 Ipv4Dst(0xe00a0a0a),
480 },
481 Actions: []*ofp.OfpAction{
482 Group(10),
483 },
484 }
485 flow1 := MkFlowStat(fa)
486 assert.False(t, FlowMatch(flow1, nil))
487
488 fa = &FlowArgs{
489 KV: OfpFlowModArgs{"priority": 500},
490 MatchFields: []*ofp.OfpOxmOfbField{
491 InPort(2),
492 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
493 VlanPcp(0),
494 EthType(0x800),
495 Ipv4Dst(0xe00a0a0a),
496 },
497 Actions: []*ofp.OfpAction{
498 Group(10),
499 },
500 }
501 flow2 := MkFlowStat(fa)
502 assert.False(t, FlowMatch(flow1, flow2))
503 assert.False(t, FlowMatch(nil, flow2))
504
505 fa = &FlowArgs{
506 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
507 MatchFields: []*ofp.OfpOxmOfbField{
508 InPort(2),
509 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
510 VlanPcp(0),
511 EthType(0x800),
512 Ipv4Dst(0xe00a0a0a),
513 },
514 }
515 flow2 = MkFlowStat(fa)
516 assert.True(t, FlowMatch(flow1, flow2))
517
518 fa = &FlowArgs{
519 KV: OfpFlowModArgs{"priority": 501, "table_id": 1, "cookie": 38268468, "flags": 12},
520 MatchFields: []*ofp.OfpOxmOfbField{
521 InPort(2),
522 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
523 VlanPcp(0),
524 EthType(0x800),
525 Ipv4Dst(0xe00a0a0a),
526 },
527 Actions: []*ofp.OfpAction{
528 Group(10),
529 },
530 }
531 flow2 = MkFlowStat(fa)
532 assert.False(t, FlowMatch(flow1, flow2))
533
534 fa = &FlowArgs{
535 KV: OfpFlowModArgs{"priority": 500, "table_id": 2, "cookie": 38268468, "flags": 12},
536 MatchFields: []*ofp.OfpOxmOfbField{
537 InPort(2),
538 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
539 VlanPcp(0),
540 EthType(0x800),
541 Ipv4Dst(0xe00a0a0a),
542 },
543 }
544 flow2 = MkFlowStat(fa)
545 assert.False(t, FlowMatch(flow1, flow2))
546
547 fa = &FlowArgs{
548 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268467, "flags": 12},
549 MatchFields: []*ofp.OfpOxmOfbField{
550 InPort(2),
551 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
552 VlanPcp(0),
553 EthType(0x800),
554 Ipv4Dst(0xe00a0a0a),
555 },
556 }
557 flow2 = MkFlowStat(fa)
558 assert.False(t, FlowMatch(flow1, flow2))
559
560 fa = &FlowArgs{
561 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 14},
562 MatchFields: []*ofp.OfpOxmOfbField{
563 InPort(2),
564 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
565 VlanPcp(0),
566 EthType(0x800),
567 Ipv4Dst(0xe00a0a0a),
568 },
569 }
570 flow2 = MkFlowStat(fa)
571 assert.False(t, FlowMatch(flow1, flow2))
572
573 fa = &FlowArgs{
574 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
575 MatchFields: []*ofp.OfpOxmOfbField{
576 InPort(4),
577 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
578 VlanPcp(0),
579 EthType(0x800),
580 Ipv4Dst(0xe00a0a0a),
581 },
582 }
583 flow2 = MkFlowStat(fa)
584 assert.False(t, FlowMatch(flow1, flow2))
585
586 fa = &FlowArgs{
587 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
588 MatchFields: []*ofp.OfpOxmOfbField{
589 InPort(2),
590 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
591 VlanPcp(0),
592 EthType(0x800),
593 },
594 }
595 flow2 = MkFlowStat(fa)
596 assert.False(t, FlowMatch(flow1, flow2))
597
598 fa = &FlowArgs{
599 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
600 MatchFields: []*ofp.OfpOxmOfbField{
601 InPort(2),
602 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
603 VlanPcp(0),
604 EthType(0x800),
605 Ipv4Dst(0xe00a0a0a),
606 },
607 Actions: []*ofp.OfpAction{
608 PopVlan(),
609 Output(1),
610 },
611 }
612 flow2 = MkFlowStat(fa)
613 assert.True(t, FlowMatch(flow1, flow2))
614}
615
616func TestFlowMatchesMod(t *testing.T) {
617 assert.False(t, FlowMatchesMod(nil, nil))
618 fa := &FlowArgs{
619 KV: OfpFlowModArgs{"priority": 500, "table_id": 1},
620 MatchFields: []*ofp.OfpOxmOfbField{
621 InPort(2),
622 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
623 VlanPcp(0),
624 EthType(0x800),
625 Ipv4Dst(0xe00a0a0a),
626 },
627 Actions: []*ofp.OfpAction{
628 Output(1),
629 Group(10),
630 },
631 }
632 flow := MkFlowStat(fa)
633 assert.False(t, FlowMatchesMod(flow, nil))
634
635 fa = &FlowArgs{
636 KV: OfpFlowModArgs{"priority": 500, "table_id": 1},
637 MatchFields: []*ofp.OfpOxmOfbField{
638 InPort(2),
639 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
640 VlanPcp(0),
641 EthType(0x800),
642 Ipv4Dst(0xe00a0a0a),
643 },
644 Actions: []*ofp.OfpAction{
645 PopVlan(),
646 Output(1),
647 },
648 }
649 flowMod := MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
650 assert.False(t, FlowMatchesMod(nil, flowMod))
651 assert.False(t, FlowMatchesMod(flow, flowMod))
652 assert.True(t, FlowMatch(flow, FlowStatsEntryFromFlowModMessage(flowMod)))
653
654 fa = &FlowArgs{
655 KV: OfpFlowModArgs{"table_id": uint64(ofp.OfpTable_OFPTT_ALL),
656 "cookie_mask": 0,
657 "out_port": uint64(ofp.OfpPortNo_OFPP_ANY),
658 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
659 },
660 }
661 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
662 assert.True(t, FlowMatchesMod(flow, flowMod))
663
664 fa = &FlowArgs{
665 KV: OfpFlowModArgs{"table_id": 1,
666 "cookie_mask": 0,
667 "out_port": uint64(ofp.OfpPortNo_OFPP_ANY),
668 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
669 },
670 }
671 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
672 assert.True(t, FlowMatchesMod(flow, flowMod))
673
674 fa = &FlowArgs{
675 KV: OfpFlowModArgs{"table_id": 1,
676 "cookie_mask": 0,
677 "out_port": 1,
678 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
679 },
680 }
681 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
682 assert.True(t, FlowMatchesMod(flow, flowMod))
683
684 fa = &FlowArgs{
685 KV: OfpFlowModArgs{"table_id": 1,
686 "cookie_mask": 0,
687 "out_port": 1,
688 "out_group": 10,
689 },
690 }
691 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
692 assert.True(t, FlowMatchesMod(flow, flowMod))
693}
Esin Karaman20b6de92019-11-05 08:29:16 +0000694
695func TestIsMulticastIpAddress(t *testing.T) {
696 isMcastIp := IsMulticastIp(3776315393) //225.22.0.1
697 assert.True(t, isMcastIp)
698 isMcastIp = IsMulticastIp(3232243777) //192.168.32.65
699 assert.True(t, !isMcastIp)
700}
701
702func TestConvertToMulticastMac(t *testing.T) {
703 mcastIp := uint32(4001431809) //238.129.1.1
704 expectedMacInBytes := []byte{1, 0, 94, 1, 1, 1} //01:00:5e:01:01:01
705 macInBytes := ConvertToMulticastMacBytes(mcastIp)
David K. Bainbridge7c75cac2020-02-19 08:53:46 -0800706 assert.True(t, bytes.Equal(macInBytes, expectedMacInBytes))
Esin Karaman20b6de92019-11-05 08:29:16 +0000707}