forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_ip_statistics.go
93 lines (79 loc) · 2.5 KB
/
cmd_get_ip_statistics.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
83
84
85
86
87
88
89
90
91
92
93
package ipmi
import "fmt"
// 23.4 Get IP/UDP/RMCP Statistics Command
type GetIPStatisticsRequest struct {
ChannelNumber uint8
ClearAllStatistics bool
}
type GetIPStatisticsResponse struct {
IPPacketsReceived uint16
IPHeaderErrorsReceived uint16
IPAddressErrorsReceived uint16
IPPacketsFragmentedReceived uint16
IPPacketsTransmitted uint16
UDPPacketsReceived uint16
RMCPPacketsValidReceived uint16
UDPProxyPacketsReceived uint16
UDPProxyPacketsDropped uint16
}
func (req *GetIPStatisticsRequest) Pack() []byte {
out := make([]byte, 2)
packUint8(req.ChannelNumber, out, 0)
var b uint8
if req.ClearAllStatistics {
b = setBit0(b)
}
packUint8(b, out, 1)
return out
}
func (req *GetIPStatisticsRequest) Command() Command {
return CommandGetIpStatistics
}
func (res *GetIPStatisticsResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetIPStatisticsResponse) Unpack(msg []byte) error {
if len(msg) < 18 {
return ErrUnpackedDataTooShort
}
res.IPPacketsReceived, _, _ = unpackUint16L(msg, 0)
res.IPHeaderErrorsReceived, _, _ = unpackUint16L(msg, 2)
res.IPAddressErrorsReceived, _, _ = unpackUint16L(msg, 4)
res.IPPacketsFragmentedReceived, _, _ = unpackUint16L(msg, 6)
res.IPPacketsTransmitted, _, _ = unpackUint16L(msg, 8)
res.UDPPacketsReceived, _, _ = unpackUint16L(msg, 10)
res.RMCPPacketsValidReceived, _, _ = unpackUint16L(msg, 12)
res.UDPProxyPacketsReceived, _, _ = unpackUint16L(msg, 14)
res.UDPProxyPacketsDropped, _, _ = unpackUint16L(msg, 16)
return nil
}
func (res *GetIPStatisticsResponse) Format() string {
return fmt.Sprintf(`IP Rx Packet : %d
IP Rx Header Errors : %d
IP Rx Address Errors : %d
IP Rx Fragmented : %d
IP Tx Packet : %d
UDP Rx Packet : %d
RMCP Rx Valid : %d
UDP Proxy Packet Received : %d
UDP Proxy Packet Dropped : %d`,
res.IPPacketsReceived,
res.IPHeaderErrorsReceived,
res.IPAddressErrorsReceived,
res.IPPacketsFragmentedReceived,
res.IPPacketsTransmitted,
res.UDPPacketsReceived,
res.RMCPPacketsValidReceived,
res.UDPProxyPacketsReceived,
res.UDPProxyPacketsDropped,
)
}
func (c *Client) GetIPStatistics(channelNubmer uint8, clearAllStatistics bool) (response *GetIPStatisticsResponse, err error) {
request := &GetIPStatisticsRequest{
ChannelNumber: channelNubmer,
ClearAllStatistics: clearAllStatistics,
}
response = &GetIPStatisticsResponse{}
err = c.Exchange(request, response)
return
}