-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmatch.go
62 lines (50 loc) · 1.56 KB
/
match.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ofputil
import (
"bytes"
"fmt"
"github.com/netrack/openflow/internal/encoding"
"github.com/netrack/openflow/ofp"
)
func bytesOf(v interface{}) []byte {
var buf bytes.Buffer
_, err := encoding.WriteTo(&buf, v)
if err != nil {
text := "ofputil: unable to marshal %v"
panic(fmt.Errorf(text, err))
}
return buf.Bytes()
}
func ExtendedMatch(xms ...ofp.XM) ofp.Match {
return ofp.Match{ofp.MatchTypeXM, xms}
}
// basic creates an Openflow basic extensible match of the given type.
func basic(t ofp.XMType, val ofp.XMValue, mask ofp.XMValue) ofp.XM {
return ofp.XM{
Class: ofp.XMClassOpenflowBasic,
Type: t, Value: val, Mask: mask,
}
}
// MatchEthType creates an Openflow basic extensible match of Ethernet
// payload type.
func MatchEthType(eth uint16) ofp.XM {
return basic(ofp.XMTypeEthType, bytesOf(eth), nil)
}
// MatchInPort creates an Openflow basic extensible match of in port.
func MatchInPort(port ofp.PortNo) ofp.XM {
return basic(ofp.XMTypeInPort, bytesOf(port), nil)
}
// MatchIPProto creates an Openflow basic extensible match of IP protocol
// payload type.
func MatchIPProto(ipp uint8) ofp.XM {
return basic(ofp.XMTypeIPProto, bytesOf(ipp), nil)
}
// MatchICMPv6Type creates an Openflow basic extensible match of ICMPv6
// message type.
func MatchICMPv6Type(icmpt uint8) ofp.XM {
return basic(ofp.XMTypeICMPv6Type, bytesOf(icmpt), nil)
}
// MatchIPv6ExtHeader creates an Openflow basic extensible match of IPv6
// extension header.
func MatchIPv6ExtHeader(header uint16) ofp.XM {
return basic(ofp.XMTypeIPv6ExtHeader, bytesOf(header), nil)
}