-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathdecoder_test.go
More file actions
232 lines (216 loc) · 15.4 KB
/
Copy pathdecoder_test.go
File metadata and controls
232 lines (216 loc) · 15.4 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//: ----------------------------------------------------------------------------
//: Copyright (C) 2017 Verizon. All Rights Reserved.
//: All Rights Reserved
//:
//: file: decoder_test.go
//: details: TODO
//: author: Mehrdad Arshad Rad
//: date: 02/01/2017
//:
//: Licensed under the Apache License, Version 2.0 (the "License");
//: you may not use this file except in compliance with the License.
//: You may obtain a copy of the License at
//:
//: http://www.apache.org/licenses/LICENSE-2.0
//:
//: Unless required by applicable law or agreed to in writing, software
//: distributed under the License is distributed on an "AS IS" BASIS,
//: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//: See the License for the specific language governing permissions and
//: limitations under the License.
//: ----------------------------------------------------------------------------
package ipfix
import (
"net"
"reflect"
"testing"
)
var tpl, optsTpl, multiMessage, unknownDatasetMessage []byte
func init() {
// IPFIX packet including template SetID:2, 25 fields, Domain id 33792
tpl = []byte{
0x0, 0xa, 0x0, 0x7c, 0x58, 0x90, 0xd6, 0x40, 0x28, 0xf7,
0xa0, 0x4a, 0x0, 0x0, 0x84, 0x0, 0x0, 0x2, 0x0, 0x6c, 0x1,
0x0, 0x0, 0x19, 0x0, 0x8, 0x0, 0x4, 0x0, 0xc, 0x0, 0x4,
0x0, 0x5, 0x0, 0x1, 0x0, 0x4, 0x0, 0x1, 0x0, 0x7, 0x0, 0x2,
0x0, 0xb, 0x0, 0x2, 0x0, 0x20, 0x0, 0x2, 0x0, 0xa, 0x0, 0x4,
0x0, 0x3a, 0x0, 0x2, 0x0, 0x9, 0x0, 0x1, 0x0, 0xd, 0x0, 0x1,
0x0, 0x10, 0x0, 0x4, 0x0, 0x11, 0x0, 0x4, 0x0, 0xf, 0x0, 0x4,
0x0, 0x6, 0x0, 0x1, 0x0, 0xe, 0x0, 0x4, 0x0, 0x1, 0x0, 0x8,
0x0, 0x2, 0x0, 0x8, 0x0, 0x34, 0x0, 0x1, 0x0, 0x35, 0x0, 0x1,
0x0, 0x98, 0x0, 0x8, 0x0, 0x99, 0x0, 0x8, 0x0, 0x88, 0x0, 0x1,
0x0, 0xf3, 0x0, 0x2, 0x0, 0xf5, 0x0, 0x2,
}
// IPFIX packet including template SetID:3, 6 fields
optsTpl = []byte{
0x0, 0xa, 0x0, 0x34, 0x58, 0x6c, 0x2e, 0x4f, 0x0, 0x1d, 0x97,
0x9e, 0x0, 0x0, 0x8b, 0x3, 0x0, 0x3, 0x0, 0x24, 0x2, 0x0, 0x0,
0x6, 0x0, 0x1, 0x0, 0x90, 0x0, 0x4, 0x0, 0xa0, 0x0, 0x8, 0x0,
0x82, 0x0, 0x4, 0x0, 0x83, 0x0, 0x10, 0x0, 0xd6, 0x0, 0x1, 0x0,
0xd7, 0x0, 0x1, 0x0, 0x0,
}
// IPFIX packet with multiple template and data sets
multiMessage = []byte{
0x0, 0xa, 0x5, 0x56, 0x59, 0x6f, 0x2b, 0x2a, 0x0, 0x0, 0x0, 0x1, 0x0, 0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0, 0x0, 0x0, 0x0, 0x0, 0x1,
0x90, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x67, 0x20, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x51, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x81, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x34, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34,
}
}
func TestDecodeNoData(t *testing.T) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
body := []byte{}
d := NewDecoder(ip, body)
if _, err := d.Decode(mCache); err == nil {
t.Error("expected err but nothing")
}
}
func TestDecodeTemplate(t *testing.T) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
d := NewDecoder(ip, tpl)
_, err := d.Decode(mCache)
if err != nil {
t.Error("unexpected error happened:", err)
}
}
func TestDecodeOptsTemplate(t *testing.T) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
d := NewDecoder(ip, optsTpl)
_, err := d.Decode(mCache)
if err != nil {
t.Error("unexpected error happened:", err)
}
}
func BenchmarkDecodeTemplate(b *testing.B) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
for i := 0; i < b.N; i++ {
d := NewDecoder(ip, tpl)
d.Decode(mCache)
}
}
func BenchmarkDecodeOptsTemplate(b *testing.B) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
for i := 0; i < b.N; i++ {
d := NewDecoder(ip, optsTpl)
d.Decode(mCache)
}
}
func TestMultiMessage(t *testing.T) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
d := NewDecoder(ip, multiMessage)
r, err := d.Decode(mCache)
if err != nil {
t.Error("unexpected error happened:", err)
}
if l := len(r.DataSets); l != 3 {
t.Error("Expected 3 datasets, but received", l)
}
expectedSets := []int{256, 257, 262, 263, 264, 265, 266, 267, 268, 512}
actualSets := mCache.allSetIds()
if !reflect.DeepEqual(expectedSets, actualSets) {
t.Error("Expected template sets:", expectedSets, ", but received:", actualSets)
}
}
func TestUnknownDatasetsMessage(t *testing.T) {
ip := net.ParseIP("127.0.0.1")
mCache := GetCache("cache.file")
d := NewDecoder(ip, unknownDatasetMessage)
r, err := d.Decode(mCache)
if l := len(r.DataSets); l != 0 {
t.Error("Did not expect any result datasets, but got", l)
}
expectedErrorStr := `Multiple errors:
- 127.0.0.1 unknown ipfix template id# 264 with domain ID 1
- 127.0.0.1 unknown ipfix template id# 264 with domain ID 1`
if err == nil || err.Error() != expectedErrorStr {
t.Error("Received unexpected erorr:", err)
}
}
func TestDecodeDataTpl(t *testing.T) {
var payload = []byte{0, 10, 1, 32, 92, 88, 61, 168, 0, 1, 117, 38, 0, 0, 0, 0, 4, 0, 0, 120, 0, 0, 1, 104, 184, 176, 218, 137, 0, 0, 1, 104, 184, 176, 211, 113, 0, 0, 0, 0, 0, 0, 3, 72, 0, 0, 0, 0, 0, 0, 0, 10, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 2, 15, 216, 58, 215, 99, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 104, 184, 176, 218, 137, 0, 0, 1, 104, 184, 176, 211, 113, 0, 0, 0, 0, 0, 0, 3, 72, 0, 0, 0, 0, 0, 0, 0, 10, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216, 58, 215, 99, 10, 0, 2, 15, 0, 0, 0, 0, 0, 0, 1, 0, 0, 8, 0, 0, 88, 0, 0, 1, 104, 184, 172, 62, 242, 0, 0, 1, 104, 184, 172, 62, 242, 0, 0, 0, 0, 0, 0, 0, 189, 0, 0, 0, 0, 0, 0, 0, 1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 128, 0, 0, 0, 0, 0, 0, 31, 12, 114, 32, 178, 94, 204, 189, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 251, 0, 20, 233, 20, 233, 0, 17, 0, 0, 0, 4, 0, 0, 64, 0, 0, 1, 104, 184, 172, 62, 242, 0, 0, 1, 104, 184, 172, 62, 242, 0, 0, 0, 0, 0, 0, 0, 169, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 2, 15, 224, 0, 0, 251, 20, 233, 20, 233, 0, 0, 17, 0, 0, 0}
var tpl = []byte{0, 10, 1, 32, 92, 88, 61, 152, 0, 1, 117, 22, 0, 0, 0, 0, 0, 2, 0, 68, 4, 0, 0, 15, 0, 153, 0, 8, 0, 152, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8, 0, 60, 0, 1, 0, 10, 0, 4, 0, 14, 0, 4, 0, 61, 0, 1, 0, 8, 0, 4, 0, 12, 0, 4, 0, 7, 0, 2, 0, 11, 0, 2, 0, 5, 0, 1, 0, 6, 0, 1, 0, 4, 0, 1, 0, 2, 0, 68, 4, 1, 0, 15, 0, 153, 0, 8, 0, 152, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8, 0, 60, 0, 1, 0, 10, 0, 4, 0, 14, 0, 4, 0, 61, 0, 1, 0, 8, 0, 4, 0, 12, 0, 4, 0, 7, 0, 2, 0, 11, 0, 2, 0, 5, 0, 1, 0, 6, 0, 1, 0, 4, 0, 1, 0, 2, 0, 68, 8, 0, 0, 15, 0, 153, 0, 8, 0, 152, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8, 0, 60, 0, 1, 0, 10, 0, 4, 0, 14, 0, 4, 0, 61, 0, 1, 0, 27, 0, 16, 0, 28, 0, 16, 0, 5, 0, 1, 0, 7, 0, 2, 0, 11, 0, 2, 0, 6, 0, 1, 0, 4, 0, 1, 0, 2, 0, 68, 8, 1, 0, 15, 0, 153, 0, 8, 0, 152, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8, 0, 60, 0, 1, 0, 10, 0, 4, 0, 14, 0, 4, 0, 61, 0, 1, 0, 27, 0, 16, 0, 28, 0, 16, 0, 5, 0, 1, 0, 7, 0, 2, 0, 11, 0, 2, 0, 6, 0, 1, 0, 4, 0, 1}
ip := net.ParseIP("127.0.0.1")
templates := GetCache("")
d := NewDecoder(ip, tpl)
_, err := d.Decode(templates)
if err != nil {
t.Error(err)
}
d = NewDecoder(ip, payload)
_, err = d.Decode(templates)
if err != nil {
t.Error(err)
}
}