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