-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlistener.go
57 lines (45 loc) · 1.18 KB
/
listener.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
package openflow
import (
"errors"
"net"
bh "github.com/kandoo/beehive"
"github.com/kandoo/beehive-netctrl/openflow/of"
"github.com/kandoo/beehive/Godeps/_workspace/src/github.com/golang/glog"
)
type ofListener struct {
proto string // The driver's listening protocol.
addr string // The driver's listening address.
readBufLen int // Maximum number of packets to read.
}
func (l *ofListener) Start(ctx bh.RcvContext) {
nl, err := net.Listen(l.proto, l.addr)
if err != nil {
glog.Errorf("Cannot start the OF listener: %v", err)
return
}
glog.Infof("OF listener started on %s:%s", l.proto, l.addr)
defer func() {
glog.Infof("OF listener closed")
nl.Close()
}()
for {
c, err := nl.Accept()
if err != nil {
glog.Errorf("Error in OF accept: %v", err)
return
}
l.startOFConn(c, ctx)
}
}
func (l *ofListener) startOFConn(conn net.Conn, ctx bh.RcvContext) {
ofc := &ofConn{
HeaderConn: of.NewHeaderConn(conn),
readBufLen: l.readBufLen,
}
ctx.StartDetached(ofc)
}
func (l *ofListener) Stop(ctx bh.RcvContext) {
}
func (l *ofListener) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
return errors.New("No message should be sent to the listener")
}