File: cmd_suspend_bmc_arps.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 (70 lines) | stat: -rw-r--r-- 1,518 bytes parent folder | download | duplicates (2)
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
package ipmi

import "context"

// 23.3 Suspend BMC ARPs Command
type SuspendARPsRequest struct {
	ChannelNumber        uint8
	SuspendARP           bool
	SuspendGratuitousARP bool
}

type SuspendARPsResponse struct {
	// Present state of ARP suspension

	IsARPOccurring           bool
	IsGratuitousARPOccurring bool
}

func (req *SuspendARPsRequest) Pack() []byte {
	out := make([]byte, 2)

	packUint8(req.ChannelNumber, out, 0)

	var b uint8
	if req.SuspendARP {
		b = setBit1(b)
	}
	if req.SuspendGratuitousARP {
		b = setBit0(b)
	}
	packUint8(b, out, 1)

	return out
}

func (req *SuspendARPsRequest) Command() Command {
	return CommandSuspendARPs
}

func (res *SuspendARPsResponse) CompletionCodes() map[uint8]string {
	return map[uint8]string{
		0x80: "parameter not supported.",
	}
}

func (res *SuspendARPsResponse) Unpack(msg []byte) error {
	if len(msg) < 1 {
		return ErrUnpackedDataTooShortWith(len(msg), 1)
	}

	b, _, _ := unpackUint8(msg, 0)
	res.IsARPOccurring = isBit1Set(b)
	res.IsGratuitousARPOccurring = isBit0Set(b)
	return nil
}

func (res *SuspendARPsResponse) Format() string {
	return ""
}

func (c *Client) SuspendARPs(ctx context.Context, channelNumber uint8, suspendARP bool, suspendGratuitousARP bool) (response *SuspendARPsResponse, err error) {
	request := &SuspendARPsRequest{
		ChannelNumber:        channelNumber,
		SuspendARP:           suspendARP,
		SuspendGratuitousARP: suspendGratuitousARP,
	}
	response = &SuspendARPsResponse{}
	err = c.Exchange(ctx, request, response)
	return
}