-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathdecoder_test.go
162 lines (134 loc) · 15.6 KB
/
decoder_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
154
155
156
157
158
159
160
161
162
package decoder
import (
"bytes"
"encoding/binary"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
var (
hepPacket = []byte{0x48, 0x45, 0x50, 0x33, 0x3, 0xa, 0x0, 0x0, 0x0, 0x1, 0x0, 0x7, 0x2, 0x0, 0x0, 0x0, 0x2, 0x0, 0x7, 0x11, 0x0, 0x0, 0x0, 0x3, 0x0, 0xa, 0xc0, 0xa8, 0xf7, 0xfa, 0x0, 0x0, 0x0, 0x4, 0x0, 0xa, 0xc0, 0xa8, 0xf5, 0xfa, 0x0, 0x0, 0x0, 0x7, 0x0, 0x8, 0x13, 0xc4, 0x0, 0x0, 0x0, 0x8, 0x0, 0x8, 0x13, 0xc4, 0x0, 0x0, 0x0, 0x9, 0x0, 0xa, 0x5a, 0xa2, 0x9b, 0x98, 0x0, 0x0, 0x0, 0xa, 0x0, 0xa, 0x0, 0x1, 0xd2, 0xf4, 0x0, 0x0, 0x0, 0xb, 0x0, 0x7, 0x1, 0x0, 0x0, 0x0, 0xc, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x0, 0x6, 0x0, 0x0, 0x0, 0xf, 0x2, 0xa7, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x43, 0x61, 0x6c, 0x6c, 0x2d, 0x49, 0x44, 0x3a, 0x20, 0x42, 0x43, 0x30, 0x39, 0x39, 0x38, 0x38, 0x34, 0x40, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0xd, 0xa, 0x43, 0x53, 0x65, 0x71, 0x3a, 0x20, 0x32, 0x31, 0x35, 0x38, 0x33, 0x34, 0x34, 0x38, 0x39, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0xd, 0xa, 0x46, 0x72, 0x6f, 0x6d, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0x2b, 0x31, 0x2b, 0x62, 0x30, 0x61, 0x39, 0x30, 0x30, 0x30, 0x33, 0x2b, 0x63, 0x39, 0x65, 0x66, 0x63, 0x32, 0x30, 0x62, 0xd, 0xa, 0x54, 0x6f, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x3d, 0x75, 0x64, 0x70, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x31, 0x38, 0x30, 0x34, 0x61, 0x34, 0x37, 0x64, 0x2b, 0x31, 0x2b, 0x65, 0x31, 0x30, 0x35, 0x30, 0x34, 0x37, 0x30, 0x2b, 0x62, 0x31, 0x32, 0x38, 0x61, 0x35, 0x36, 0x39, 0xd, 0xa, 0x56, 0x69, 0x61, 0x3a, 0x20, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x2f, 0x55, 0x44, 0x50, 0x20, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3b, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x3d, 0x7a, 0x39, 0x68, 0x47, 0x34, 0x62, 0x4b, 0x2b, 0x32, 0x31, 0x66, 0x31, 0x31, 0x33, 0x65, 0x37, 0x65, 0x33, 0x64, 0x30, 0x34, 0x63, 0x38, 0x34, 0x36, 0x31, 0x34, 0x38, 0x61, 0x39, 0x61, 0x64, 0x37, 0x36, 0x30, 0x37, 0x61, 0x65, 0x66, 0x61, 0x31, 0x2b, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0x2b, 0x31, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x37, 0x38, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x64, 0x70, 0xd, 0xa, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x31, 0x30, 0x30, 0x72, 0x65, 0x6c, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x72, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x65, 0x6e, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x64, 0x70, 0x2c, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x69, 0x73, 0x75, 0x70, 0x2c, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x2f, 0x6d, 0x69, 0x78, 0x65, 0x64, 0xd, 0xa, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x3a, 0x20, 0x49, 0x4e, 0x56, 0x49, 0x54, 0x45, 0x2c, 0x20, 0x41, 0x43, 0x4b, 0x2c, 0x20, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, 0x2c, 0x20, 0x42, 0x59, 0x45, 0x2c, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x2c, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x46, 0x59, 0x2c, 0x20, 0x50, 0x52, 0x41, 0x43, 0x4b, 0x2c, 0x20, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x2c, 0x20, 0x49, 0x4e, 0x46, 0x4f, 0x2c, 0x20, 0x52, 0x45, 0x46, 0x45, 0x52, 0xd, 0xa, 0xd, 0xa, 0x76, 0x3d, 0x30, 0xd, 0xa, 0x6f, 0x3d, 0x2d, 0x20, 0x30, 0x20, 0x30, 0x20, 0x49, 0x4e, 0x20, 0x49, 0x50, 0x34, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0xd, 0xa, 0x73, 0x3d, 0x2d, 0xd, 0xa, 0x63, 0x3d, 0x49, 0x4e, 0x20, 0x49, 0x50, 0x34, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0xd, 0xa, 0x74, 0x3d, 0x30, 0x20, 0x30, 0xd, 0xa, 0x6d, 0x3d, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x30, 0x20, 0x52, 0x54, 0x50, 0x2f, 0x41, 0x56, 0x50, 0x20, 0x38}
//rawPacket = []byte{0x0, 0xa, 0xa0, 0x0, 0xbe, 0xa8, 0x0, 0x26, 0x52, 0xe, 0xd3, 0x41, 0x8, 0x0, 0x45, 0x0, 0x2, 0xbd, 0xa1, 0xc3, 0x0, 0x0, 0x3e, 0x11, 0x69, 0x26, 0xc0, 0xa8, 0xf7, 0xfa, 0xc0, 0xa8, 0xf5, 0xfa, 0x13, 0xc4, 0x13, 0xc4, 0x2, 0xa9, 0x0, 0x0, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x43, 0x61, 0x6c, 0x6c, 0x2d, 0x49, 0x44, 0x3a, 0x20, 0x42, 0x43, 0x30, 0x39, 0x39, 0x38, 0x38, 0x34, 0x40, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0xd, 0xa, 0x43, 0x53, 0x65, 0x71, 0x3a, 0x20, 0x32, 0x31, 0x35, 0x38, 0x33, 0x34, 0x34, 0x38, 0x39, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0xd, 0xa, 0x46, 0x72, 0x6f, 0x6d, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0x2b, 0x31, 0x2b, 0x62, 0x30, 0x61, 0x39, 0x30, 0x30, 0x30, 0x33, 0x2b, 0x63, 0x39, 0x65, 0x66, 0x63, 0x32, 0x30, 0x62, 0xd, 0xa, 0x54, 0x6f, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x3d, 0x75, 0x64, 0x70, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x31, 0x38, 0x30, 0x34, 0x61, 0x34, 0x37, 0x64, 0x2b, 0x31, 0x2b, 0x65, 0x31, 0x30, 0x35, 0x30, 0x34, 0x37, 0x30, 0x2b, 0x62, 0x31, 0x32, 0x38, 0x61, 0x35, 0x36, 0x39, 0xd, 0xa, 0x56, 0x69, 0x61, 0x3a, 0x20, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x2f, 0x55, 0x44, 0x50, 0x20, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x31, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3b, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x3d, 0x7a, 0x39, 0x68, 0x47, 0x34, 0x62, 0x4b, 0x2b, 0x32, 0x31, 0x66, 0x31, 0x31, 0x33, 0x65, 0x37, 0x65, 0x33, 0x64, 0x30, 0x34, 0x63, 0x38, 0x34, 0x36, 0x31, 0x34, 0x38, 0x61, 0x39, 0x61, 0x64, 0x37, 0x36, 0x30, 0x37, 0x61, 0x65, 0x66, 0x61, 0x31, 0x2b, 0x36, 0x64, 0x66, 0x63, 0x66, 0x66, 0x65, 0x38, 0x2b, 0x31, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x37, 0x38, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x64, 0x70, 0xd, 0xa, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x31, 0x30, 0x30, 0x72, 0x65, 0x6c, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x72, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x65, 0x6e, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0xd, 0xa, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x64, 0x70, 0x2c, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x69, 0x73, 0x75, 0x70, 0x2c, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, 0x2f, 0x6d, 0x69, 0x78, 0x65, 0x64, 0xd, 0xa, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x3a, 0x20, 0x49, 0x4e, 0x56, 0x49, 0x54, 0x45, 0x2c, 0x20, 0x41, 0x43, 0x4b, 0x2c, 0x20, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, 0x2c, 0x20, 0x42, 0x59, 0x45, 0x2c, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x2c, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x46, 0x59, 0x2c, 0x20, 0x50, 0x52, 0x41, 0x43, 0x4b, 0x2c, 0x20, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x2c, 0x20, 0x49, 0x4e, 0x46, 0x4f, 0x2c, 0x20, 0x52, 0x45, 0x46, 0x45, 0x52, 0xd, 0xa, 0xd, 0xa, 0x76, 0x3d, 0x30, 0xd, 0xa, 0x6f, 0x3d, 0x2d, 0x20, 0x30, 0x20, 0x30, 0x20, 0x49, 0x4e, 0x20, 0x49, 0x50, 0x34, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0xd, 0xa, 0x73, 0x3d, 0x2d, 0xd, 0xa, 0x63, 0x3d, 0x49, 0x4e, 0x20, 0x49, 0x50, 0x34, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0xd, 0xa, 0x74, 0x3d, 0x30, 0x20, 0x30, 0xd, 0xa, 0x6d, 0x3d, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x30, 0x20, 0x52, 0x54, 0x50, 0x2f, 0x41, 0x56, 0x50, 0x20, 0x38}
hepV2Packet = []byte{0x01, 0x10, 0x02, 0x11, 0x13, 0xc4, 0x13, 0xc4, 0x0a, 0x00, 0x01, 0x64, 0xc0, 0xa8, 0x00, 0xfe, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x46, 0x72, 0x6f, 0x6d, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x6d, 0x6f, 0x64, 0x5f, 0x73, 0x6f, 0x66, 0x69, 0x61, 0x40, 0x34, 0x34, 0x2e, 0x31, 0x32, 0x32, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x32, 0x3a, 0x35, 0x30, 0x36, 0x30, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x61, 0x58, 0x53, 0x31, 0x63, 0x30, 0x72, 0x74, 0x53, 0x67, 0x72, 0x67, 0x44, 0x0d, 0x0a, 0x54, 0x6f, 0x3a, 0x20, 0x3c, 0x73, 0x69, 0x70, 0x3a, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x5f, 0x30, 0x30, 0x40, 0x73, 0x69, 0x70, 0x2e, 0x73, 0x63, 0x69, 0x73, 0x63, 0x69, 0x70, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, 0x3b, 0x74, 0x61, 0x67, 0x3d, 0x38, 0x30, 0x61, 0x62, 0x33, 0x37, 0x63, 0x30, 0x2d, 0x35, 0x63, 0x63, 0x31, 0x37, 0x62, 0x62, 0x62, 0x2d, 0x31, 0x33, 0x63, 0x34, 0x2d, 0x35, 0x36, 0x38, 0x34, 0x38, 0x39, 0x2d, 0x34, 0x32, 0x62, 0x37, 0x65, 0x32, 0x64, 0x34, 0x2d, 0x35, 0x36, 0x38, 0x34, 0x38, 0x39, 0x0d, 0x0a, 0x43, 0x61, 0x6c, 0x6c, 0x2d, 0x49, 0x44, 0x3a, 0x20, 0x63, 0x37, 0x30, 0x37, 0x61, 0x62, 0x32, 0x32, 0x2d, 0x36, 0x65, 0x31, 0x36, 0x2d, 0x31, 0x31, 0x65, 0x63, 0x2d, 0x62, 0x63, 0x38, 0x32, 0x2d, 0x32, 0x37, 0x32, 0x35, 0x32, 0x38, 0x39, 0x65, 0x38, 0x64, 0x63, 0x33, 0x5f, 0x38, 0x30, 0x66, 0x34, 0x39, 0x35, 0x35, 0x63, 0x2d, 0x35, 0x63, 0x63, 0x31, 0x37, 0x62, 0x62, 0x62, 0x2d, 0x31, 0x33, 0x63, 0x34, 0x2d, 0x64, 0x64, 0x39, 0x39, 0x38, 0x2d, 0x32, 0x31, 0x30, 0x34, 0x64, 0x66, 0x36, 0x65, 0x2d, 0x64, 0x64, 0x39, 0x39, 0x38, 0x0d, 0x0a, 0x43, 0x53, 0x65, 0x71, 0x3a, 0x20, 0x32, 0x31, 0x33, 0x34, 0x35, 0x33, 0x30, 0x30, 0x37, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x0d, 0x0a, 0x56, 0x69, 0x61, 0x3a, 0x20, 0x53, 0x49, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x2f, 0x55, 0x44, 0x50, 0x20, 0x31, 0x39, 0x2e, 0x31, 0x31, 0x31, 0x2e, 0x31, 0x31, 0x32, 0x2e, 0x31, 0x31, 0x32, 0x3b, 0x72, 0x70, 0x6f, 0x72, 0x74, 0x3d, 0x35, 0x30, 0x36, 0x30, 0x3b, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x3d, 0x7a, 0x39, 0x68, 0x47, 0x34, 0x62, 0x4b, 0x6a, 0x42, 0x58, 0x33, 0x30, 0x53, 0x42, 0x42, 0x36, 0x74, 0x30, 0x65, 0x4e, 0x0d, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x3a, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x73, 0x2c, 0x31, 0x30, 0x30, 0x72, 0x65, 0x6c, 0x0d, 0x0a, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x3a, 0x20, 0x49, 0x4e, 0x56, 0x49, 0x54, 0x45, 0x2c, 0x20, 0x41, 0x43, 0x4b, 0x2c, 0x20, 0x42, 0x59, 0x45, 0x2c, 0x20, 0x52, 0x45, 0x46, 0x45, 0x52, 0x2c, 0x20, 0x4e, 0x4f, 0x54, 0x49, 0x46, 0x59, 0x2c, 0x20, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, 0x2c, 0x20, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x53, 0x70, 0x65, 0x65, 0x64, 0x54, 0x6f, 0x75, 0x63, 0x68, 0x20, 0x37, 0x38, 0x30, 0x0d, 0x0a, 0x58, 0x2d, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x3a, 0x20, 0x41, 0x41, 0x30, 0x31, 0x30, 0x31, 0x4a, 0x4a, 0x4a, 0x55, 0x54, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x30, 0x0d, 0x0a, 0x0d, 0x0a}
hepLen = []byte{0x00, 0x00}
hepLen7 = []byte{0x00, 0x07}
hepLen8 = []byte{0x00, 0x08}
hepLen10 = []byte{0x00, 0x0a}
chunk16 = []byte{0x00, 0x00}
chunk32 = []byte{0x00, 0x00, 0x00, 0x00}
)
func TestDecodeEncodeHEP(t *testing.T) {
hep, err := DecodeHEP(hepPacket)
if err != nil {
t.Error(err)
}
rawPacket := EncodeHEP(hep)
assert.Equal(t, hepPacket, rawPacket)
//Decode HEPv2
/*
fmt.Println("Decode HEPv2")
if bytes.HasPrefix(hepV2Packet, []byte{0x1}) || bytes.HasPrefix(hepV2Packet, []byte{0x2}) {
fmt.Println("This is HEPv2")
hep := &HEP{}
hep.parseHEP2(hepV2Packet)
fmt.Println("This is HEPv2:", hep)
}
*/
}
func BenchmarkDecodeHEPSIP(b *testing.B) {
for i := 0; i < b.N; i++ {
val, _ := DecodeHEP(hepPacket)
_ = val
}
}
func BenchmarkDecodeHEP(b *testing.B) {
hep := &HEP{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
hep.parseHEP(hepPacket)
}
}
// EncodeHEP creates the HEP Packet which
// will be sent on the wire
func EncodeHEP(h *HEP) []byte {
hepMsg := makeChunks(h)
binary.BigEndian.PutUint16(hepMsg[4:6], uint16(len(hepMsg)))
return hepMsg
}
var w bytes.Buffer
// makeChunks will construct the respective HEP chunk
func makeChunks(h *HEP) []byte {
w.Reset()
w.Write([]byte{0x48, 0x45, 0x50, 0x33})
// hepMsg length placeholder. Will be written later
w.Write(hepLen)
// Chunk IP protocol family (0x02=IPv4, 0x0a=IPv6)
w.Write([]byte{0x00, 0x00, 0x00, 0x01})
w.Write(hepLen7)
w.WriteByte(byte(h.Version))
// Chunk IP protocol ID (0x06=TCP, 0x11=UDP)
w.Write([]byte{0x00, 0x00, 0x00, 0x02})
w.Write(hepLen7)
w.WriteByte(byte(h.Protocol))
// Chunk IPv4 source address
w.Write([]byte{0x00, 0x00, 0x00, 0x03})
binary.BigEndian.PutUint16(hepLen, 6+uint16(len(net.ParseIP(h.SrcIP).To4())))
w.Write(hepLen)
w.Write([]byte(net.ParseIP(h.SrcIP).To4()))
// Chunk IPv4 destination address
w.Write([]byte{0x00, 0x00, 0x00, 0x04})
binary.BigEndian.PutUint16(hepLen, 6+uint16(len(net.ParseIP(h.DstIP).To4())))
w.Write(hepLen)
w.Write([]byte(net.ParseIP(h.DstIP).To4()))
// Chunk protocol source port
w.Write([]byte{0x00, 0x00, 0x00, 0x07})
w.Write(hepLen8)
binary.BigEndian.PutUint16(chunk16, uint16(h.SrcPort))
w.Write(chunk16)
// Chunk protocol destination port
w.Write([]byte{0x00, 0x00, 0x00, 0x08})
w.Write(hepLen8)
binary.BigEndian.PutUint16(chunk16, uint16(h.DstPort))
w.Write(chunk16)
// Chunk unix timestamp, seconds
w.Write([]byte{0x00, 0x00, 0x00, 0x09})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunk32, h.Tsec)
w.Write(chunk32)
// Chunk unix timestamp, microseconds offset
w.Write([]byte{0x00, 0x00, 0x00, 0x0a})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunk32, h.Tmsec)
w.Write(chunk32)
// Chunk protocol type (DNS, LOG, RTCP, SIP)
w.Write([]byte{0x00, 0x00, 0x00, 0x0b})
w.Write(hepLen7)
w.WriteByte(byte(h.ProtoType))
// Chunk capture agent ID
w.Write([]byte{0x00, 0x00, 0x00, 0x0c})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunk32, h.NodeID)
w.Write(chunk32)
// Chunk keep alive timer
//w.Write([]byte{0x00, 0x00, 0x00, 0x0d})
// Chunk authenticate key (plain text / TLS connection)
w.Write([]byte{0x00, 0x00, 0x00, 0x0e})
binary.BigEndian.PutUint16(hepLen, 6+uint16(len(h.NodePW)))
w.Write(hepLen)
w.Write([]byte(h.NodePW))
// Chunk captured packet payload
w.Write([]byte{0x00, 0x00, 0x00, 0x0f})
binary.BigEndian.PutUint16(hepLen, 6+uint16(len(h.Payload)))
w.Write(hepLen)
w.Write([]byte(h.Payload))
// Chunk captured compressed payload (gzip/inflate)
//w.Write([]byte{0x00,0x00, 0x00,0x10})
if h.CID != "" && h.ProtoType != 1 {
// Chunk internal correlation id
w.Write([]byte{0x00, 0x00, 0x00, 0x11})
binary.BigEndian.PutUint16(hepLen, 6+uint16(len(h.CID)))
w.Write(hepLen)
w.Write([]byte(h.CID))
}
return w.Bytes()
}