summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dhcpv6/option_archtype.go8
-rw-r--r--dhcpv6/option_archtype_test.go44
2 files changed, 50 insertions, 2 deletions
diff --git a/dhcpv6/option_archtype.go b/dhcpv6/option_archtype.go
index 9d513c7..802e334 100644
--- a/dhcpv6/option_archtype.go
+++ b/dhcpv6/option_archtype.go
@@ -8,6 +8,7 @@ import (
"fmt"
)
+//ArchType encodes an architecture type in an uint16
type ArchType uint16
// see rfc4578
@@ -24,6 +25,7 @@ const (
EFI_X86_64 ArchType = 9
)
+// ArchTypeToStringMap maps an ArchType to a mnemonic name
var ArchTypeToStringMap = map[ArchType]string{
INTEL_X86PC: "Intel x86PC",
NEC_PC98: "NEC/PC98",
@@ -37,6 +39,7 @@ var ArchTypeToStringMap = map[ArchType]string{
EFI_X86_64: "EFI x86-64",
}
+// OptClientArchType represents an option CLIENT_ARCH_TYPE
type OptClientArchType struct {
ArchType ArchType
}
@@ -65,8 +68,9 @@ func (op *OptClientArchType) String() string {
return fmt.Sprintf("OptClientArchType{archtype=%v}", name)
}
-// build an OptClientArchType structure from a sequence of bytes.
-// The input data does not include option code and length bytes.
+// ParseOptClientArchType builds an OptClientArchType structure from
+// a sequence of bytes The input data does not include option code and
+// length bytes.
func ParseOptClientArchType(data []byte) (*OptClientArchType, error) {
opt := OptClientArchType{}
if len(data) != 2 {
diff --git a/dhcpv6/option_archtype_test.go b/dhcpv6/option_archtype_test.go
new file mode 100644
index 0000000..b446661
--- /dev/null
+++ b/dhcpv6/option_archtype_test.go
@@ -0,0 +1,44 @@
+package dhcpv6
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestParseOptClientArchType(t *testing.T) {
+ data := []byte{
+ 0, 6, // EFI_IA32
+ }
+ opt, err := ParseOptClientArchType(data)
+ require.NoError(t, err)
+ require.Equal(t, opt.ArchType, EFI_IA32)
+}
+
+func TestParseOptClientArchTypeInvalid(t *testing.T) {
+ data := []byte{42}
+ _, err := ParseOptClientArchType(data)
+ require.Error(t, err)
+}
+
+func TestOptClientArchTypeParseAndToBytes(t *testing.T) {
+ data := []byte{
+ 0, 8, // EFI_XSCALE
+ }
+ expected := []byte{
+ 0, 61, // OPTION_CLIENT_ARCH_TYPE
+ 0, 2, // length
+ 0, 8, // EFI_XSCALE
+ }
+ opt, err := ParseOptClientArchType(data)
+ require.NoError(t, err)
+ require.Equal(t, opt.ToBytes(), expected)
+}
+
+func TestOptClientArchType(t *testing.T) {
+ opt := OptClientArchType{
+ ArchType: EFI_ITANIUM,
+ }
+ require.Equal(t, opt.Length(), 2)
+ require.Equal(t, opt.Code(), OPTION_CLIENT_ARCH_TYPE)
+}