Skip to content

Commit 93af8d3

Browse files
authored
Merge pull request #74 from si74/new_match_ipfrag
ovs ipFrag match
2 parents c06b927 + 27ac329 commit 93af8d3

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

ovs/match.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const (
5656
ipv6DST = "ipv6_dst"
5757
ipv6SRC = "ipv6_src"
5858
ipv6Label = "ipv6_label"
59+
ipFrag = "ip_frag"
5960
metadata = "metadata"
6061
ndSLL = "nd_sll"
6162
ndTLL = "nd_tll"
@@ -1309,3 +1310,39 @@ func matchTransportPort(srcdst string, port uint16, mask uint16) ([]byte, error)
13091310

13101311
return bprintf("tp_%s=0x%04x/0x%04x", srcdst, port, mask), nil
13111312
}
1313+
1314+
// IPFragFlag is a string type which can be used with the IPFragMatch.
1315+
type IPFragFlag string
1316+
1317+
// OvS IP frag flags.
1318+
// Source: http://www.openvswitch.org/support/dist-docs-2.5/ovs-ofctl.8.txt
1319+
const (
1320+
IPFragFlagYes IPFragFlag = "yes"
1321+
IPFragFlagNo IPFragFlag = "no"
1322+
IPFragFlagFirst IPFragFlag = "first"
1323+
IPFragFlagLater IPFragFlag = "later"
1324+
IPFragFlagNotLater IPFragFlag = "not_later"
1325+
)
1326+
1327+
// IPFrag returns an ipFragMatch.
1328+
func IPFrag(flag IPFragFlag) Match {
1329+
return &ipFragMatch{flag: flag}
1330+
}
1331+
1332+
// ipFragMatch implements the Match interface and is a match against
1333+
// a packet fragmentation value.
1334+
type ipFragMatch struct {
1335+
flag IPFragFlag
1336+
}
1337+
1338+
var _ Match = &ipFragMatch{}
1339+
1340+
// GoString implements Match.
1341+
func (m *ipFragMatch) GoString() string {
1342+
return fmt.Sprintf("ovs.IpFrag(%v)", m.flag)
1343+
}
1344+
1345+
// MarshalText implements Match.
1346+
func (m *ipFragMatch) MarshalText() ([]byte, error) {
1347+
return bprintf("%s=%s", ipFrag, m.flag), nil
1348+
}

ovs/match_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,54 @@ func TestMatchARPOperation(t *testing.T) {
14151415
}
14161416
}
14171417

1418+
func TestMatchIPFrag(t *testing.T) {
1419+
var tests = []struct {
1420+
desc string
1421+
m Match
1422+
out string
1423+
}{
1424+
{
1425+
desc: "ip frag is no",
1426+
m: IPFrag(IPFragFlagNo),
1427+
out: "ip_frag=no",
1428+
},
1429+
{
1430+
desc: "ip frag is yes",
1431+
m: IPFrag(IPFragFlagYes),
1432+
out: "ip_frag=yes",
1433+
},
1434+
{
1435+
desc: "ip frag is first",
1436+
m: IPFrag(IPFragFlagFirst),
1437+
out: "ip_frag=first",
1438+
},
1439+
{
1440+
desc: "ip frag is later",
1441+
m: IPFrag(IPFragFlagLater),
1442+
out: "ip_frag=later",
1443+
},
1444+
{
1445+
desc: "ip frag is not later",
1446+
m: IPFrag(IPFragFlagNotLater),
1447+
out: "ip_frag=not_later",
1448+
},
1449+
}
1450+
1451+
for _, tt := range tests {
1452+
t.Run(tt.desc, func(t *testing.T) {
1453+
out, err := tt.m.MarshalText()
1454+
if err != nil {
1455+
t.Fatalf("unexpected error: %v", err)
1456+
}
1457+
1458+
if want, got := tt.out, string(out); want != got {
1459+
t.Fatalf("unexpected Match output:\n- want: %q\n- got: %q",
1460+
want, got)
1461+
}
1462+
})
1463+
}
1464+
}
1465+
14181466
// mustParseMAC is a helper to parse a hardware address from a string using
14191467
// net.ParseMAC, that panic on failure.
14201468
func mustParseMAC(addr string) net.HardwareAddr {

0 commit comments

Comments
 (0)