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
|
package dhcpv6
import (
"net"
"testing"
"github.com/insomniacslk/dhcp/iana"
"github.com/stretchr/testify/require"
)
func TestParseOptServerId(t *testing.T) {
data := []byte{
0, 3, // DUID_LL
0, 1, // hwtype ethernet
0, 1, 2, 3, 4, 5, // hw addr
}
opt, err := ParseOptServerId(data)
require.NoError(t, err)
require.Equal(t, opt.Sid.Type, DUID_LL)
require.Equal(t, opt.Sid.HwType, iana.HwTypeEthernet)
require.Equal(t, opt.Sid.LinkLayerAddr, net.HardwareAddr([]byte{0, 1, 2, 3, 4, 5}))
}
func TestOptServerIdToBytes(t *testing.T) {
opt := OptServerId{
Sid: Duid{
Type: DUID_LL,
HwType: iana.HwTypeEthernet,
LinkLayerAddr: net.HardwareAddr([]byte{5, 4, 3, 2, 1, 0}),
},
}
expected := []byte{
0, 2, // OPTION_SERVERID
0, 10, // length
0, 3, // DUID_LL
0, 1, // hwtype ethernet
5, 4, 3, 2, 1, 0, // hw addr
}
require.Equal(t, expected, opt.ToBytes())
}
func TestOptServerIdDecodeEncode(t *testing.T) {
data := []byte{
0, 3, // DUID_LL
0, 1, // hwtype ethernet
5, 4, 3, 2, 1, 0, // hw addr
}
expected := append([]byte{
0, 2, // OPTION_SERVERID
0, 10, // length
}, data...)
opt, err := ParseOptServerId(data)
require.NoError(t, err)
require.Equal(t, expected, opt.ToBytes())
}
func TestOptionServerId(t *testing.T) {
opt := OptServerId{
Sid: Duid{
Type: DUID_LL,
HwType: iana.HwTypeEthernet,
LinkLayerAddr: net.HardwareAddr([]byte{0xde, 0xad, 0, 0, 0xbe, 0xef}),
},
}
require.Equal(t, opt.Length(), 10)
require.Equal(t, opt.Code(), OPTION_SERVERID)
}
|