-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstats.go
82 lines (72 loc) · 1.88 KB
/
stats.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package openflow
import (
"fmt"
"time"
"github.com/kandoo/beehive-netctrl/nom"
"github.com/kandoo/beehive-netctrl/openflow/of10"
"github.com/kandoo/beehive-netctrl/openflow/of12"
)
func (d *of10Driver) handleStatsReply(reply of10.StatsReply,
c *ofConn) error {
switch {
case of10.IsFlowStatsReply(reply):
return d.handleFlowStatsReply(of10.NewFlowStatsReplyWithBuf(reply.Buf), c)
default:
return fmt.Errorf("of10Driver: unsupported stats type %v",
reply.StatsType())
}
}
func (d *of10Driver) handleFlowStatsReply(reply of10.FlowStatsReply,
c *ofConn) error {
nomReply := nom.FlowStatsQueryResult{
Node: c.node.UID(),
}
for _, stat := range reply.FlowStats() {
m, err := d.nomMatch(stat.Match())
if err != nil {
return err
}
stat := nom.FlowStats{
Match: m,
Duration: time.Duration(stat.DurationSec())*time.Second +
time.Duration(stat.DurationNsec()),
Packets: stat.PacketCount(),
Bytes: stat.ByteCount(),
}
nomReply.Stats = append(nomReply.Stats, stat)
}
c.ctx.Emit(nomReply)
return nil
}
func (d *of12Driver) handleStatsReply(reply of12.StatsReply,
c *ofConn) error {
switch {
case of12.IsFlowStatsReply(reply):
return d.handleFlowStatsReply(of12.NewFlowStatsReplyWithBuf(reply.Buf), c)
default:
return fmt.Errorf("of12Driver: unsupported stats type %v",
reply.StatsType())
}
}
func (d *of12Driver) handleFlowStatsReply(reply of12.FlowStatsReply,
c *ofConn) error {
nomReply := nom.FlowStatsQueryResult{
Node: c.node.UID(),
}
for _, stat := range reply.FlowStats() {
m, err := d.nomMatch(stat.Match())
if err != nil {
return err
}
stat := nom.FlowStats{
Match: m,
Duration: time.Duration(stat.DurationSec())*time.Second +
time.Duration(stat.DurationNsec()),
Packets: stat.PacketCount(),
Bytes: stat.ByteCount(),
}
nomReply.Stats = append(nomReply.Stats, stat)
}
c.ctx.Emit(nomReply)
return nil
}