forked from vishvananda/netlink
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tcp_linux_test.go
153 lines (142 loc) · 3.32 KB
/
tcp_linux_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package netlink
import (
"reflect"
"testing"
)
var (
tcpInfoData []byte
tcpInfo *TCPInfo
)
func init() {
tcpInfoData = []byte{
1, 0, 0, 0, 0, 7, 120, 1, 96, 216, 3, 0, 64,
156, 0, 0, 120, 5, 0, 0, 64, 3, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 236, 216, 0, 0, 0, 0, 0, 0, 56, 216,
0, 0, 144, 39, 0, 0, 220, 5, 0, 0, 88, 250,
0, 0, 79, 190, 0, 0, 7, 5, 0, 0, 255, 255,
255, 127, 10, 0, 0, 0, 168, 5, 0, 0, 3, 0, 0,
0, 0, 0, 0, 0, 144, 56, 0, 0, 0, 0, 0, 0, 1, 197,
8, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
255, 255, 157, 42, 0, 0, 0, 0, 0, 0, 148, 26, 0,
0, 0, 0, 0, 0, 181, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0,
0, 93, 180, 0, 0, 61, 0, 0, 0, 89, 0, 0, 0, 47, 216,
1, 0, 0, 0, 0, 0, 32, 65, 23, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0,
0, 0, 0, 0, 0, 156, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 195, 1, 0,
}
tcpInfo = &TCPInfo{
State: 1,
Options: 7,
Snd_wscale: 7,
Rcv_wscale: 8,
Rto: 252000,
Ato: 40000,
Snd_mss: 1400,
Rcv_mss: 832,
Last_data_sent: 55532,
Last_data_recv: 55352,
Last_ack_recv: 10128,
Pmtu: 1500,
Rcv_ssthresh: 64088,
Rtt: 48719,
Rttvar: 1287,
Snd_ssthresh: 2147483647,
Snd_cwnd: 10,
Advmss: 1448,
Reordering: 3,
Rcv_space: 14480,
Pacing_rate: 574721,
Max_pacing_rate: 18446744073709551615,
Bytes_acked: 10909,
Bytes_received: 6804,
Segs_out: 181,
Segs_in: 95,
Min_rtt: 46173,
Data_segs_in: 61,
Data_segs_out: 89,
Delivery_rate: 120879,
Busy_time: 1524000,
Delivered: 90,
Bytes_sent: 10908,
Snd_wnd: 115456,
}
}
func TestTCPInfoDeserialize(t *testing.T) {
tests := []struct {
name string
input []byte
expected *TCPInfo
wantFail bool
}{
{
name: "Valid data",
input: tcpInfoData,
expected: tcpInfo,
},
}
for _, test := range tests {
tcpbbr := &TCPInfo{}
err := tcpbbr.deserialize(test.input)
if err != nil && !test.wantFail {
t.Errorf("Unexpected failure for test %q", test.name)
continue
}
if err != nil && test.wantFail {
continue
}
if !reflect.DeepEqual(test.expected, tcpbbr) {
t.Errorf("Unexpected failure for test %q", test.name)
}
}
}
func TestTCPBBRInfoDeserialize(t *testing.T) {
tests := []struct {
name string
input []byte
expected *TCPBBRInfo
wantFail bool
}{
{
name: "Valid data",
input: []byte{
100, 0, 0, 0, 0, 0, 0, 0,
111, 0, 0, 0,
222, 0, 0, 0,
123, 0, 0, 0,
},
expected: &TCPBBRInfo{
BBRBW: 100,
BBRMinRTT: 111,
BBRPacingGain: 222,
BBRCwndGain: 123,
},
},
{
name: "Invalid length",
input: []byte{
100, 0, 0, 0, 0, 0, 0, 0,
111, 0, 0, 0,
222, 0, 0, 0,
123, 0, 0,
},
wantFail: true,
},
}
for _, test := range tests {
tcpbbr := &TCPBBRInfo{}
err := tcpbbr.deserialize(test.input)
if err != nil && !test.wantFail {
t.Errorf("Unexpected failure for test %q", test.name)
continue
}
if err != nil && test.wantFail {
continue
}
if !reflect.DeepEqual(test.expected, tcpbbr) {
t.Errorf("Unexpected failure for test %q", test.name)
}
}
}