File: cmd_get_ip_statistics.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (87 lines) | stat: -rw-r--r-- 2,773 bytes parent folder | download
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
package ipmi

import (
	"context"
	"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 ErrUnpackedDataTooShortWith(len(msg), 18)
	}

	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\n", res.IPPacketsReceived) +
		fmt.Sprintf("IP Rx Header Errors       : %d\n", res.IPHeaderErrorsReceived) +
		fmt.Sprintf("IP Rx Address Errors      : %d\n", res.IPAddressErrorsReceived) +
		fmt.Sprintf("IP Rx Fragmented          : %d\n", res.IPPacketsFragmentedReceived) +
		fmt.Sprintf("IP Tx Packet              : %d\n", res.IPPacketsTransmitted) +
		fmt.Sprintf("UDP Rx Packet             : %d\n", res.UDPPacketsReceived) +
		fmt.Sprintf("RMCP Rx Valid             : %d\n", res.RMCPPacketsValidReceived) +
		fmt.Sprintf("UDP Proxy Packet Received : %d\n", res.UDPProxyPacketsReceived) +
		fmt.Sprintf("UDP Proxy Packet Dropped  : %d\n", res.UDPProxyPacketsDropped)
}

func (c *Client) GetIPStatistics(ctx context.Context, channelNumber uint8, clearAllStatistics bool) (response *GetIPStatisticsResponse, err error) {
	request := &GetIPStatisticsRequest{
		ChannelNumber:      channelNumber,
		ClearAllStatistics: clearAllStatistics,
	}
	response = &GetIPStatisticsResponse{}
	err = c.Exchange(ctx, request, response)
	return
}