-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SDR repo reservations and two-part reads (#66)
- Loading branch information
Showing
12 changed files
with
201 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ipmi | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
|
||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/layers" | ||
) | ||
|
||
// ReserveSDRRepositoryRsp represents the response to a Reserve SDR Repository | ||
// command, specified in 33.11 of IPMI v2.0. | ||
type ReserveSDRRepositoryRsp struct { | ||
layers.BaseLayer | ||
|
||
ReservationID ReservationID | ||
} | ||
|
||
func (*ReserveSDRRepositoryRsp) LayerType() gopacket.LayerType { | ||
return LayerTypeReserveSDRRepositoryRsp | ||
} | ||
|
||
func (r *ReserveSDRRepositoryRsp) CanDecode() gopacket.LayerClass { | ||
return r.LayerType() | ||
} | ||
|
||
func (*ReserveSDRRepositoryRsp) NextLayerType() gopacket.LayerType { | ||
return gopacket.LayerTypePayload | ||
} | ||
|
||
func (r *ReserveSDRRepositoryRsp) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { | ||
if len(data) < 2 { | ||
df.SetTruncated() | ||
return fmt.Errorf("response must be at least 2 bytes, got %v", len(data)) | ||
} | ||
|
||
r.BaseLayer.Contents = data[:2] | ||
r.ReservationID = ReservationID(binary.LittleEndian.Uint16(data[0:2])) | ||
return nil | ||
} | ||
|
||
type ReserveSDRRepositoryCmd struct { | ||
Rsp ReserveSDRRepositoryRsp | ||
} | ||
|
||
// Name returns "Reserve SDR Repository". | ||
func (*ReserveSDRRepositoryCmd) Name() string { | ||
return "Reserve SDR Repository" | ||
} | ||
|
||
// Operation returns &OperationReserveSDRRepositoryReq. | ||
func (*ReserveSDRRepositoryCmd) Operation() *Operation { | ||
return &OperationReserveSDRRepositoryReq | ||
} | ||
|
||
func (c *ReserveSDRRepositoryCmd) RemoteLUN() LUN { | ||
return LUNBMC | ||
} | ||
|
||
func (c *ReserveSDRRepositoryCmd) Request() gopacket.SerializableLayer { | ||
return nil | ||
} | ||
|
||
func (c *ReserveSDRRepositoryCmd) Response() gopacket.DecodingLayer { | ||
return &c.Rsp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ipmi | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/layers" | ||
"testing" | ||
) | ||
|
||
func TestReserveSDRRepositoryRspDecodeFomBytes(t *testing.T) { | ||
tests := []struct { | ||
in []byte | ||
want *ReserveSDRRepositoryRsp | ||
}{ | ||
{ | ||
in: []byte{0x20, 0x58}, | ||
want: &ReserveSDRRepositoryRsp{ | ||
BaseLayer: layers.BaseLayer{Contents: []byte{0x20, 0x58}}, | ||
ReservationID: 22560, | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
rsp := &ReserveSDRRepositoryRsp{} | ||
if err := rsp.DecodeFromBytes(test.in, gopacket.NilDecodeFeedback); err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if diff := cmp.Diff(test.want, rsp); diff != "" { | ||
t.Errorf("decode %v = %v, want %v: %v", test.in, rsp, test.want, diff) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters