Skip to content

Commit 63c11c9

Browse files
author
Kanaga Shanmugam
committed
Added ICMPv6 tests
1 parent d5c96b1 commit 63c11c9

File tree

5 files changed

+201
-15
lines changed

5 files changed

+201
-15
lines changed

ovs/flow_test.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ func TestFlowMarshalText(t *testing.T) {
9595
Priority: 1500,
9696
Protocol: ProtocolICMPv4,
9797
Matches: []Match{
98+
ICMPType(3),
99+
ICMPCode(1),
98100
DataLinkSource("00:11:22:33:44:55"),
99101
},
100102
Actions: []Action{
101103
Resubmit(0, 1),
102104
},
103105
},
104-
s: "priority=1500,icmp,dl_src=00:11:22:33:44:55,table=0,idle_timeout=0,actions=resubmit(,1)",
106+
s: "priority=1500,icmp,icmp_type=3,icmp_code=1,dl_src=00:11:22:33:44:55,table=0,idle_timeout=0,actions=resubmit(,1)",
105107
},
106108
{
107109
desc: "ICMPv6 Flow",
@@ -110,7 +112,7 @@ func TestFlowMarshalText(t *testing.T) {
110112
Protocol: ProtocolICMPv6,
111113
InPort: 74,
112114
Matches: []Match{
113-
ICMPType(135),
115+
ICMP6Type(135),
114116
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
115117
NeighborDiscoverySourceLinkLayer(
116118
net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
@@ -123,7 +125,27 @@ func TestFlowMarshalText(t *testing.T) {
123125
Resubmit(0, 1),
124126
},
125127
},
126-
s: "priority=2024,icmp6,in_port=74,icmp_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
128+
s: "priority=2024,icmp6,in_port=74,icmpv6_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
129+
},
130+
{
131+
desc: "ICMPv6 Type and Code Flow",
132+
f: &Flow{
133+
Priority: 2024,
134+
Protocol: ProtocolICMPv6,
135+
InPort: 74,
136+
Matches: []Match{
137+
ICMP6Type(1),
138+
ICMP6Code(3),
139+
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
140+
},
141+
Table: 0,
142+
IdleTimeout: 0,
143+
Actions: []Action{
144+
ModVLANVID(10),
145+
Resubmit(0, 1),
146+
},
147+
},
148+
s: "priority=2024,icmp6,in_port=74,icmpv6_type=1,icmpv6_code=3,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
127149
},
128150
{
129151
desc: "IPv4 Flow",
@@ -493,11 +515,13 @@ func TestFlowUnmarshalText(t *testing.T) {
493515
},
494516
{
495517
desc: "ICMPv4 Flow",
496-
s: "priority=1500,icmp,dl_src=00:11:22:33:44:55,table=0,idle_timeout=0,actions=resubmit(,1)",
518+
s: "priority=1500,icmp,icmp_type=3,icmp_code=1,dl_src=00:11:22:33:44:55,table=0,idle_timeout=0,actions=resubmit(,1)",
497519
f: &Flow{
498520
Priority: 1500,
499521
Protocol: ProtocolICMPv4,
500522
Matches: []Match{
523+
ICMPType(3),
524+
ICMPCode(1),
501525
DataLinkSource("00:11:22:33:44:55"),
502526
},
503527
Actions: []Action{
@@ -507,13 +531,13 @@ func TestFlowUnmarshalText(t *testing.T) {
507531
},
508532
{
509533
desc: "ICMPv6 Flow",
510-
s: "priority=2024,icmp6,in_port=74,icmp_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
534+
s: "priority=2024,icmp6,in_port=74,icmpv6_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
511535
f: &Flow{
512536
Priority: 2024,
513537
Protocol: ProtocolICMPv6,
514538
InPort: 74,
515539
Matches: []Match{
516-
ICMPType(135),
540+
ICMP6Type(135),
517541
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
518542
NeighborDiscoverySourceLinkLayer(
519543
net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
@@ -527,6 +551,26 @@ func TestFlowUnmarshalText(t *testing.T) {
527551
},
528552
},
529553
},
554+
{
555+
desc: "ICMPv6 Type and Code Flow",
556+
s: "priority=2024,icmp6,in_port=74,icmpv6_type=1,icmpv6_code=3,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,table=0,idle_timeout=0,actions=mod_vlan_vid:10,resubmit(,1)",
557+
f: &Flow{
558+
Priority: 2024,
559+
Protocol: ProtocolICMPv6,
560+
InPort: 74,
561+
Matches: []Match{
562+
ICMP6Type(1),
563+
ICMP6Code(3),
564+
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
565+
},
566+
Table: 0,
567+
IdleTimeout: 0,
568+
Actions: []Action{
569+
ModVLANVID(10),
570+
Resubmit(0, 1),
571+
},
572+
},
573+
},
530574
{
531575
desc: "IPv4 Flow",
532576
s: "priority=2020,ip,in_port=31,dl_src=00:11:22:33:44:55,nw_src=10.0.0.1,table=0,idle_timeout=0,actions=mod_vlan_vid:20,resubmit(,1)",

ovs/match.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func (m *icmpTypeMatch) GoString() string {
472472
return fmt.Sprintf("ovs.ICMPType(%d)", m.typ)
473473
}
474474

475-
// ICMPCode matches packets with the specified ICMP code
475+
// ICMPCode matches packets with the specified ICMP code.
476476
func ICMPCode(code uint8) Match {
477477
return &icmpCodeMatch{
478478
code: code,
@@ -481,7 +481,7 @@ func ICMPCode(code uint8) Match {
481481

482482
var _ Match = &icmpCodeMatch{}
483483

484-
// An icmpCodeMatch is a Match returned by ICMPCode
484+
// An icmpCodeMatch is a Match returned by ICMPCode.
485485
type icmpCodeMatch struct {
486486
code uint8
487487
}
@@ -505,7 +505,7 @@ func ICMP6Type(typ uint8) Match {
505505

506506
var _ Match = &icmp6TypeMatch{}
507507

508-
// An icmpTypeMatch is a Match returned by ICMPType.
508+
// An icmp6TypeMatch is a Match returned by ICMP6Type.
509509
type icmp6TypeMatch struct {
510510
typ uint8
511511
}
@@ -529,7 +529,7 @@ func ICMP6Code(code uint8) Match {
529529

530530
var _ Match = &icmp6CodeMatch{}
531531

532-
// An icmpCodeMatch is a Match returned by ICMP6Code
532+
// An icmp6CodeMatch is a Match returned by ICMP6Code.
533533
type icmp6CodeMatch struct {
534534
code uint8
535535
}

ovs/match_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,120 @@ func TestMatchICMPType(t *testing.T) {
492492
}
493493
}
494494

495+
func TestMatchICMPCode(t *testing.T) {
496+
var tests = []struct {
497+
desc string
498+
code uint8
499+
out string
500+
}{
501+
{
502+
desc: "host unreachable",
503+
code: 1,
504+
out: "icmp_code=1",
505+
},
506+
{
507+
desc: "protocol unreachable",
508+
code: 2,
509+
out: "icmp_code=2",
510+
},
511+
{
512+
desc: "port unreachable",
513+
code: 3,
514+
out: "icmp_code=3",
515+
},
516+
}
517+
518+
for _, tt := range tests {
519+
t.Run(tt.desc, func(t *testing.T) {
520+
out, err := ICMPCode(tt.code).MarshalText()
521+
if err != nil {
522+
t.Fatalf("unexpected error: %v", err)
523+
}
524+
525+
if want, got := tt.out, string(out); want != got {
526+
t.Fatalf("unexpected Match output:\n- want: %q\n- got: %q",
527+
want, got)
528+
}
529+
})
530+
}
531+
}
532+
533+
func TestMatchICMP6Type(t *testing.T) {
534+
var tests = []struct {
535+
desc string
536+
typ uint8
537+
out string
538+
}{
539+
{
540+
desc: "destination unreachable",
541+
typ: 1,
542+
out: "icmpv6_type=1",
543+
},
544+
{
545+
desc: "neighbor solicitation",
546+
typ: 135,
547+
out: "icmpv6_type=135",
548+
},
549+
{
550+
desc: "neighbor advertisement",
551+
typ: 136,
552+
out: "icmpv6_type=136",
553+
},
554+
}
555+
556+
for _, tt := range tests {
557+
t.Run(tt.desc, func(t *testing.T) {
558+
out, err := ICMP6Type(tt.typ).MarshalText()
559+
if err != nil {
560+
t.Fatalf("unexpected error: %v", err)
561+
}
562+
563+
if want, got := tt.out, string(out); want != got {
564+
t.Fatalf("unexpected Match output:\n- want: %q\n- got: %q",
565+
want, got)
566+
}
567+
})
568+
}
569+
}
570+
571+
func TestMatchICMP6Code(t *testing.T) {
572+
var tests = []struct {
573+
desc string
574+
code uint8
575+
out string
576+
}{
577+
{
578+
desc: "no route to destination",
579+
code: 0,
580+
out: "icmpv6_code=0",
581+
},
582+
{
583+
desc: "address unreachable",
584+
code: 3,
585+
out: "icmpv6_code=3",
586+
},
587+
{
588+
desc: "port unreachable",
589+
code: 4,
590+
out: "icmpv6_code=4",
591+
},
592+
}
593+
594+
for _, tt := range tests {
595+
t.Run(tt.desc, func(t *testing.T) {
596+
out, err := ICMP6Code(tt.code).MarshalText()
597+
if err != nil {
598+
t.Fatalf("unexpected error: %v", err)
599+
}
600+
601+
if want, got := tt.out, string(out); want != got {
602+
t.Fatalf("unexpected Match output:\n- want: %q\n- got: %q",
603+
want, got)
604+
}
605+
})
606+
}
607+
}
608+
495609
func TestMatchNetworkProtocol(t *testing.T) {
496610
var tests = []struct {
497611
desc string
@@ -1122,6 +1236,18 @@ func TestMatchGoString(t *testing.T) {
11221236
m: ICMPType(10),
11231237
s: `ovs.ICMPType(10)`,
11241238
},
1239+
{
1240+
m: ICMPCode(1),
1241+
s: `ovs.ICMPCode(1)`,
1242+
},
1243+
{
1244+
m: ICMP6Type(136),
1245+
s: `ovs.ICMP6Type(136)`,
1246+
},
1247+
{
1248+
m: ICMP6Code(2),
1249+
s: `ovs.ICMP6Code(2)`,
1250+
},
11251251
{
11261252
m: NeighborDiscoveryTarget("2001:db8::1"),
11271253
s: `ovs.NeighborDiscoveryTarget("2001:db8::1")`,

ovs/matchflow_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,42 @@ func TestMatchFlowMarshalText(t *testing.T) {
7777
f: &MatchFlow{
7878
Protocol: ProtocolICMPv4,
7979
Matches: []Match{
80+
ICMPType(3),
81+
ICMPCode(1),
8082
DataLinkSource("00:11:22:33:44:55"),
8183
},
8284
},
83-
s: "icmp,dl_src=00:11:22:33:44:55,table=0",
85+
s: "icmp,icmp_type=3,icmp_code=1,dl_src=00:11:22:33:44:55,table=0",
8486
},
8587
{
8688
desc: "ICMPv6 Flow",
8789
f: &MatchFlow{
8890
Protocol: ProtocolICMPv6,
8991
InPort: 74,
9092
Matches: []Match{
91-
ICMPType(135),
93+
ICMP6Type(135),
9294
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
9395
NeighborDiscoverySourceLinkLayer(
9496
net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
9597
),
9698
},
9799
Table: 0,
98100
},
99-
s: "icmp6,in_port=74,icmp_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0",
101+
s: "icmp6,in_port=74,icmpv6_type=135,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,nd_sll=00:11:22:33:44:55,table=0",
102+
},
103+
{
104+
desc: "ICMPv6 Type and Code Flow",
105+
f: &MatchFlow{
106+
Protocol: ProtocolICMPv6,
107+
InPort: 74,
108+
Matches: []Match{
109+
ICMP6Type(1),
110+
ICMP6Code(3),
111+
IPv6Source("fe80:aaaa:bbbb:cccc:dddd::1/124"),
112+
},
113+
Table: 0,
114+
},
115+
s: "icmp6,in_port=74,icmpv6_type=1,icmpv6_code=3,ipv6_src=fe80:aaaa:bbbb:cccc:dddd::1/124,table=0",
100116
},
101117
{
102118
desc: "IPv4 Flow",

ovs/matchparser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func Test_parseMatch(t *testing.T) {
152152
m: ICMP6Type(135),
153153
},
154154
{
155-
s: "icmpv6_code=0",
156-
m: ICMP6Code(0),
155+
s: "icmpv6_code=3",
156+
m: ICMP6Code(3),
157157
},
158158
{
159159
s: "nd_sll=foo",

0 commit comments

Comments
 (0)