-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe80211_test.go
106 lines (99 loc) · 2.7 KB
/
frame80211_test.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ethernet
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFrame80211Marshal(t *testing.T) {
type suite struct {
name string
addr1 HardwareAddr
addr2 HardwareAddr
addr3 HardwareAddr
addr4 *HardwareAddr
fc uint16
duration uint16
qos uint16
ht uint32
sc uint16
tag8021q *Tag8021Q
payload []byte
wantLen int
}
testCases := []suite{
{
name: "positive_minimum",
addr1: HardwareAddr{127, 127, 127, 50, 50, 50},
addr2: HardwareAddr{255, 255, 255, 50, 50, 50},
addr3: HardwareAddr{255, 255, 255, 50, 50, 20},
fc: 0x16,
duration: 0x10,
payload: []byte("HELLO"),
wantLen: 26 + 5,
},
{
name: "positive_4addr",
addr1: HardwareAddr{127, 127, 127, 50, 50, 50},
addr2: HardwareAddr{255, 255, 255, 50, 50, 50},
addr3: HardwareAddr{255, 255, 255, 50, 50, 20},
addr4: &HardwareAddr{255, 255, 255, 10, 10, 10},
fc: 0x16,
duration: 0x10,
payload: []byte("HELLO"),
wantLen: 32 + 5,
},
{
name: "positive_sc",
addr1: HardwareAddr{127, 127, 127, 50, 50, 50},
addr2: HardwareAddr{255, 255, 255, 50, 50, 50},
addr3: HardwareAddr{255, 255, 255, 50, 50, 20},
fc: 0x16,
duration: 0x10,
sc: 0x180,
payload: []byte("HELLO"),
wantLen: 28 + 5,
},
{
name: "positive_qos",
addr1: HardwareAddr{127, 127, 127, 50, 50, 50},
addr2: HardwareAddr{255, 255, 255, 50, 50, 50},
addr3: HardwareAddr{255, 255, 255, 50, 50, 20},
fc: 0x16,
duration: 0x10,
qos: 0x4,
payload: []byte("HELLO"),
wantLen: 28 + 5,
},
{
name: "positive_ht",
addr1: HardwareAddr{127, 127, 127, 50, 50, 50},
addr2: HardwareAddr{255, 255, 255, 50, 50, 50},
addr3: HardwareAddr{255, 255, 255, 50, 50, 20},
fc: 0x16,
duration: 0x10,
ht: 0x1222,
payload: []byte("HELLO"),
wantLen: 30 + 5,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
f := NewFrame80211(tc.addr1, tc.addr2, tc.addr3, tc.addr4, tc.fc, tc.duration, tc.payload)
f.SetSC(tc.sc)
f.SetHT(tc.ht)
f.SetQOS(tc.qos)
b := f.Marshal()
assert.NotEmpty(t, b)
assert.Len(t, b, tc.wantLen, "mismatched encoded frame size")
assert.Equal(t, tc.wantLen, f.Size())
//assert.Equal(t, f.Size(), tc.wantLen, "mismatched frame size")
})
}
}
func BenchmarkFrame80211Marshal(b *testing.B) {
payload := generatePayload()
b.ResetTimer()
f := NewFrame80211(HardwareAddr{127, 127, 127, 50, 50, 50}, HardwareAddr{255, 255, 255, 50, 50, 50}, HardwareAddr{255, 255, 255, 50, 50, 10}, nil, 0x50, 0x20, payload)
for i := 0; i < b.N; i++ {
_ = f.Marshal()
}
}