-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbh.go
68 lines (56 loc) · 1.79 KB
/
bh.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
63
64
65
66
67
68
package openflow
import (
"flag"
"github.com/kandoo/beehive/Godeps/_workspace/src/github.com/golang/glog"
"github.com/kandoo/beehive/bucket"
bh "github.com/kandoo/beehive"
)
var (
proto = flag.String("of.proto", "tcp", "protocol of the OpenFlow listener")
addr = flag.String("of.addr", "0.0.0.0:6633",
"address of the OpenFlow listener in the form of HOST:PORT")
readBufLen = flag.Int("of.rbuflen", 1<<8,
"maximum number of packets to read per each read call")
maxConnRate = flag.Int("of.maxrate", 1<<18,
"maximum number of messages an openflow connection can generate per second")
)
// Option represents an OpenFlow listener option.
type Option func(l *ofListener)
// ListenOn returns an OpenFlow option that sets the address on which the
// OpenFlow service listens.
func ListenOn(addr string) Option {
return func(l *ofListener) {
l.addr = addr
}
}
// UseProto returns an Openflow option that sets the protocol that the OpenFlow
// service uses to listen.
func UseProto(proto string) Option {
return func(l *ofListener) {
l.proto = proto
}
}
// SetReadBufLen returns an OpenFlow option that sets reader buffer length of
// the OpenFlow service.
func SetReadBufLen(rlen int) Option {
return func(l *ofListener) {
l.readBufLen = rlen
}
}
// StartOpenFlow starts the OpenFlow driver on the given hive using the default
// OpenFlow configuration that can be set through command line arguments.
func StartOpenFlow(hive bh.Hive, options ...Option) error {
app := hive.NewApp("OFDriver",
bh.OutRate(bucket.Rate(*maxConnRate), 10*uint64(*maxConnRate)))
l := &ofListener{
proto: *proto,
addr: *addr,
readBufLen: *readBufLen,
}
for _, opt := range options {
opt(l)
}
app.Detached(l)
glog.V(2).Infof("OpenFlow driver registered on %s:%s", l.proto, l.addr)
return nil
}