-
Notifications
You must be signed in to change notification settings - Fork 24
/
query.go
65 lines (55 loc) · 1.22 KB
/
query.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
package nom
import (
"encoding/gob"
"time"
)
// NodeQuery queries the information of a node.
type NodeQuery struct {
Node UID
}
// NodeQueryResult is the result for NodeQuery.
type NodeQueryResult struct {
Err error
Node Node
}
// PortQuery queries the information of a port.
type PortQuery struct {
Port UID
}
// PortQueryResult is the result for a PortQuery.
type PortQueryResult struct {
Err error
Port Port
}
// FlowStatsQuery queries the flows that would match the query. If Exact is
// false, it removes all flow entries that are subsumed by the given match.
type FlowStatsQuery struct {
Node UID
Match Match
}
// FlowStatsQueryResult is the result for a FlowStatQuery
type FlowStatsQueryResult struct {
Node UID
Stats []FlowStats
}
// FlowStats is the statistics of flow
type FlowStats struct {
Match Match
Duration time.Duration
Packets uint64
Bytes uint64
}
func (stats FlowStats) BW() Bandwidth {
if stats.Duration == 0 {
return 0
}
return Bandwidth(stats.Bytes / uint64(stats.Duration))
}
func init() {
gob.Register(FlowStatsQuery{})
gob.Register(FlowStatsQueryResult{})
gob.Register(NodeQuery{})
gob.Register(NodeQueryResult{})
gob.Register(PortQuery{})
gob.Register(PortQueryResult{})
}