blob: a9dc9cce97a58f7d82441af82f721b4a29e0537d [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 Bakerf1b096c2019-11-01 12:36:30 -070020 ofp "github.com/opencord/voltha-protos/v2/go/openflow_13"
Scott Baker456b8932019-10-24 10:36:39 -070021 "github.com/stretchr/testify/assert"
22 "google.golang.org/grpc/codes"
23 "google.golang.org/grpc/status"
24 "strings"
25 "testing"
26)
27
28var (
29 timeoutError error
30 taskFailureError error
31)
32
33func init() {
Scott Baker456b8932019-10-24 10:36:39 -070034 timeoutError = status.Errorf(codes.Aborted, "timeout")
35 taskFailureError = status.Error(codes.Internal, "test failure task")
36 timeoutError = status.Errorf(codes.Aborted, "timeout")
37}
38
39func TestFlowsAndGroups_AddFlow(t *testing.T) {
40 fg := NewFlowsAndGroups()
41 allFlows := fg.ListFlows()
42 assert.Equal(t, 0, len(allFlows))
43 fg.AddFlow(nil)
44 allFlows = fg.ListFlows()
45 assert.Equal(t, 0, len(allFlows))
46
47 var fa *FlowArgs
48 fa = &FlowArgs{
49 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
324 var fa *FlowArgs
325 fa = &FlowArgs{
326 KV: OfpFlowModArgs{"priority": 500},
327 MatchFields: []*ofp.OfpOxmOfbField{
328 InPort(2),
329 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
330 Metadata_ofp(1000),
331 TunnelId(uint64(1)),
332 VlanPcp(0),
333 },
334 Actions: []*ofp.OfpAction{
335 PopVlan(),
336 Output(1),
337 },
338 }
339 flow := MkFlowStat(fa)
340 dr.AddFlow("123456", flow)
341 rules = dr.GetRules()
342 assert.True(t, len(rules) == 1)
343 val, ok = rules["123456"]
344 assert.True(t, ok)
345 assert.Equal(t, 1, len(val.ListFlows()))
346 assert.True(t, FlowMatch(flow, val.ListFlows()[0]))
347 assert.Equal(t, 0, len(val.ListGroups()))
348}
349
350func TestDeviceRules_AddFlowsAndGroup(t *testing.T) {
351 fg := NewFlowsAndGroups()
352 var fa *FlowArgs
353 var ga *GroupArgs
354
355 str := fg.String()
356 assert.True(t, str == "")
357
358 fa = &FlowArgs{
359 KV: OfpFlowModArgs{"priority": 2000},
360 MatchFields: []*ofp.OfpOxmOfbField{
361 InPort(2),
362 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
363 Metadata_ofp(1000),
364 TunnelId(uint64(1)),
365 VlanPcp(0),
366 },
367 Actions: []*ofp.OfpAction{
368 PopVlan(),
369 Output(1),
370 },
371 }
372 flow := MkFlowStat(fa)
373 fg.AddFlow(flow)
374
375 ga = &GroupArgs{
376 GroupId: 10,
377 Buckets: []*ofp.OfpBucket{
378 {Actions: []*ofp.OfpAction{
379 PopVlan(),
380 Output(1),
381 },
382 },
383 },
384 }
385 group := MkGroupStat(ga)
386 fg.AddGroup(group)
387
388 dr := NewDeviceRules()
389 dr.AddFlowsAndGroup("123456", fg)
390 rules := dr.GetRules()
391 assert.True(t, len(rules) == 1)
392 val, ok := rules["123456"]
393 assert.True(t, ok)
394 assert.Equal(t, 1, len(val.ListFlows()))
395 assert.Equal(t, 1, len(val.ListGroups()))
396 assert.True(t, FlowMatch(flow, val.ListFlows()[0]))
397 assert.Equal(t, 10, int(val.ListGroups()[0].Desc.GroupId))
398}
399
400func TestFlowHasOutPort(t *testing.T) {
401 var flow *ofp.OfpFlowStats
402 assert.False(t, FlowHasOutPort(flow, 1))
403
404 fa := &FlowArgs{
405 KV: OfpFlowModArgs{"priority": 2000},
406 MatchFields: []*ofp.OfpOxmOfbField{
407 InPort(2),
408 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
409 Metadata_ofp(1000),
410 TunnelId(uint64(1)),
411 VlanPcp(0),
412 },
413 Actions: []*ofp.OfpAction{
414 PopVlan(),
415 Output(1),
416 },
417 }
418 flow = MkFlowStat(fa)
419 assert.True(t, FlowHasOutPort(flow, 1))
420 assert.False(t, FlowHasOutPort(flow, 2))
421
422 fa = &FlowArgs{
423 KV: OfpFlowModArgs{"priority": 2000},
424 MatchFields: []*ofp.OfpOxmOfbField{
425 InPort(2),
426 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
427 },
428 }
429 flow = MkFlowStat(fa)
430 assert.False(t, FlowHasOutPort(flow, 1))
431}
432
433func TestFlowHasOutGroup(t *testing.T) {
434 var flow *ofp.OfpFlowStats
435 assert.False(t, FlowHasOutGroup(flow, 10))
436
437 fa := &FlowArgs{
438 KV: OfpFlowModArgs{"priority": 500},
439 MatchFields: []*ofp.OfpOxmOfbField{
440 InPort(2),
441 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
442 VlanPcp(0),
443 EthType(0x800),
444 Ipv4Dst(0xe00a0a0a),
445 },
446 Actions: []*ofp.OfpAction{
447 Group(10),
448 },
449 }
450 flow = MkFlowStat(fa)
451 assert.True(t, FlowHasOutGroup(flow, 10))
452 assert.False(t, FlowHasOutGroup(flow, 11))
453
454 fa = &FlowArgs{
455 KV: OfpFlowModArgs{"priority": 500},
456 MatchFields: []*ofp.OfpOxmOfbField{
457 InPort(2),
458 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
459 VlanPcp(0),
460 EthType(0x800),
461 Ipv4Dst(0xe00a0a0a),
462 },
463 Actions: []*ofp.OfpAction{
464 Output(1),
465 },
466 }
467 flow = MkFlowStat(fa)
468 assert.False(t, FlowHasOutGroup(flow, 1))
469}
470
471func TestMatchFlow(t *testing.T) {
472 assert.False(t, FlowMatch(nil, nil))
473 fa := &FlowArgs{
474 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
475 MatchFields: []*ofp.OfpOxmOfbField{
476 InPort(2),
477 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
478 VlanPcp(0),
479 EthType(0x800),
480 Ipv4Dst(0xe00a0a0a),
481 },
482 Actions: []*ofp.OfpAction{
483 Group(10),
484 },
485 }
486 flow1 := MkFlowStat(fa)
487 assert.False(t, FlowMatch(flow1, nil))
488
489 fa = &FlowArgs{
490 KV: OfpFlowModArgs{"priority": 500},
491 MatchFields: []*ofp.OfpOxmOfbField{
492 InPort(2),
493 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
494 VlanPcp(0),
495 EthType(0x800),
496 Ipv4Dst(0xe00a0a0a),
497 },
498 Actions: []*ofp.OfpAction{
499 Group(10),
500 },
501 }
502 flow2 := MkFlowStat(fa)
503 assert.False(t, FlowMatch(flow1, flow2))
504 assert.False(t, FlowMatch(nil, flow2))
505
506 fa = &FlowArgs{
507 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
508 MatchFields: []*ofp.OfpOxmOfbField{
509 InPort(2),
510 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
511 VlanPcp(0),
512 EthType(0x800),
513 Ipv4Dst(0xe00a0a0a),
514 },
515 }
516 flow2 = MkFlowStat(fa)
517 assert.True(t, FlowMatch(flow1, flow2))
518
519 fa = &FlowArgs{
520 KV: OfpFlowModArgs{"priority": 501, "table_id": 1, "cookie": 38268468, "flags": 12},
521 MatchFields: []*ofp.OfpOxmOfbField{
522 InPort(2),
523 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
524 VlanPcp(0),
525 EthType(0x800),
526 Ipv4Dst(0xe00a0a0a),
527 },
528 Actions: []*ofp.OfpAction{
529 Group(10),
530 },
531 }
532 flow2 = MkFlowStat(fa)
533 assert.False(t, FlowMatch(flow1, flow2))
534
535 fa = &FlowArgs{
536 KV: OfpFlowModArgs{"priority": 500, "table_id": 2, "cookie": 38268468, "flags": 12},
537 MatchFields: []*ofp.OfpOxmOfbField{
538 InPort(2),
539 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
540 VlanPcp(0),
541 EthType(0x800),
542 Ipv4Dst(0xe00a0a0a),
543 },
544 }
545 flow2 = MkFlowStat(fa)
546 assert.False(t, FlowMatch(flow1, flow2))
547
548 fa = &FlowArgs{
549 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268467, "flags": 12},
550 MatchFields: []*ofp.OfpOxmOfbField{
551 InPort(2),
552 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
553 VlanPcp(0),
554 EthType(0x800),
555 Ipv4Dst(0xe00a0a0a),
556 },
557 }
558 flow2 = MkFlowStat(fa)
559 assert.False(t, FlowMatch(flow1, flow2))
560
561 fa = &FlowArgs{
562 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 14},
563 MatchFields: []*ofp.OfpOxmOfbField{
564 InPort(2),
565 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
566 VlanPcp(0),
567 EthType(0x800),
568 Ipv4Dst(0xe00a0a0a),
569 },
570 }
571 flow2 = MkFlowStat(fa)
572 assert.False(t, FlowMatch(flow1, flow2))
573
574 fa = &FlowArgs{
575 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
576 MatchFields: []*ofp.OfpOxmOfbField{
577 InPort(4),
578 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
579 VlanPcp(0),
580 EthType(0x800),
581 Ipv4Dst(0xe00a0a0a),
582 },
583 }
584 flow2 = MkFlowStat(fa)
585 assert.False(t, FlowMatch(flow1, flow2))
586
587 fa = &FlowArgs{
588 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
589 MatchFields: []*ofp.OfpOxmOfbField{
590 InPort(2),
591 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
592 VlanPcp(0),
593 EthType(0x800),
594 },
595 }
596 flow2 = MkFlowStat(fa)
597 assert.False(t, FlowMatch(flow1, flow2))
598
599 fa = &FlowArgs{
600 KV: OfpFlowModArgs{"priority": 500, "table_id": 1, "cookie": 38268468, "flags": 12},
601 MatchFields: []*ofp.OfpOxmOfbField{
602 InPort(2),
603 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
604 VlanPcp(0),
605 EthType(0x800),
606 Ipv4Dst(0xe00a0a0a),
607 },
608 Actions: []*ofp.OfpAction{
609 PopVlan(),
610 Output(1),
611 },
612 }
613 flow2 = MkFlowStat(fa)
614 assert.True(t, FlowMatch(flow1, flow2))
615}
616
617func TestFlowMatchesMod(t *testing.T) {
618 assert.False(t, FlowMatchesMod(nil, nil))
619 fa := &FlowArgs{
620 KV: OfpFlowModArgs{"priority": 500, "table_id": 1},
621 MatchFields: []*ofp.OfpOxmOfbField{
622 InPort(2),
623 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
624 VlanPcp(0),
625 EthType(0x800),
626 Ipv4Dst(0xe00a0a0a),
627 },
628 Actions: []*ofp.OfpAction{
629 Output(1),
630 Group(10),
631 },
632 }
633 flow := MkFlowStat(fa)
634 assert.False(t, FlowMatchesMod(flow, nil))
635
636 fa = &FlowArgs{
637 KV: OfpFlowModArgs{"priority": 500, "table_id": 1},
638 MatchFields: []*ofp.OfpOxmOfbField{
639 InPort(2),
640 VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
641 VlanPcp(0),
642 EthType(0x800),
643 Ipv4Dst(0xe00a0a0a),
644 },
645 Actions: []*ofp.OfpAction{
646 PopVlan(),
647 Output(1),
648 },
649 }
650 flowMod := MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
651 assert.False(t, FlowMatchesMod(nil, flowMod))
652 assert.False(t, FlowMatchesMod(flow, flowMod))
653 assert.True(t, FlowMatch(flow, FlowStatsEntryFromFlowModMessage(flowMod)))
654
655 fa = &FlowArgs{
656 KV: OfpFlowModArgs{"table_id": uint64(ofp.OfpTable_OFPTT_ALL),
657 "cookie_mask": 0,
658 "out_port": uint64(ofp.OfpPortNo_OFPP_ANY),
659 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
660 },
661 }
662 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
663 assert.True(t, FlowMatchesMod(flow, flowMod))
664
665 fa = &FlowArgs{
666 KV: OfpFlowModArgs{"table_id": 1,
667 "cookie_mask": 0,
668 "out_port": uint64(ofp.OfpPortNo_OFPP_ANY),
669 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
670 },
671 }
672 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
673 assert.True(t, FlowMatchesMod(flow, flowMod))
674
675 fa = &FlowArgs{
676 KV: OfpFlowModArgs{"table_id": 1,
677 "cookie_mask": 0,
678 "out_port": 1,
679 "out_group": uint64(ofp.OfpGroup_OFPG_ANY),
680 },
681 }
682 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
683 assert.True(t, FlowMatchesMod(flow, flowMod))
684
685 fa = &FlowArgs{
686 KV: OfpFlowModArgs{"table_id": 1,
687 "cookie_mask": 0,
688 "out_port": 1,
689 "out_group": 10,
690 },
691 }
692 flowMod = MkSimpleFlowMod(ToOfpOxmField(fa.MatchFields), fa.Actions, fa.Command, fa.KV)
693 assert.True(t, FlowMatchesMod(flow, flowMod))
694}
Esin Karaman20b6de92019-11-05 08:29:16 +0000695
696func TestIsMulticastIpAddress(t *testing.T) {
697 isMcastIp := IsMulticastIp(3776315393) //225.22.0.1
698 assert.True(t, isMcastIp)
699 isMcastIp = IsMulticastIp(3232243777) //192.168.32.65
700 assert.True(t, !isMcastIp)
701}
702
703func TestConvertToMulticastMac(t *testing.T) {
704 mcastIp := uint32(4001431809) //238.129.1.1
705 expectedMacInBytes := []byte{1, 0, 94, 1, 1, 1} //01:00:5e:01:01:01
706 macInBytes := ConvertToMulticastMacBytes(mcastIp)
707 assert.True(t, bytes.Compare(macInBytes, expectedMacInBytes) == 0)
708}