added support for string type
[govpp.git] / vendor / github.com / google / gopacket / layers / sflow_test.go
1 // Copyright 2014 Google, Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree.
6 package layers
7
8 import (
9         "github.com/google/gopacket"
10         "net"
11         "reflect"
12         "testing"
13 )
14
15 // Test packet collected from live network. See the test below for contents
16 var SFlowTestPacket1 = []byte{
17         0x84, 0x2b, 0x2b, 0x16, 0x8b, 0x62, 0xf0, 0x50, 0x56, 0x85, 0x3a, 0xfd, 0x08, 0x00, 0x45, 0x00,
18         0x05, 0xbc, 0x9c, 0x04, 0x40, 0x00, 0xff, 0x11, 0xc7, 0x00, 0x0a, 0x01, 0xff, 0x0e, 0x0a, 0x01,
19         0x00, 0x1b, 0xc7, 0x57, 0x18, 0xc7, 0x05, 0xa8, 0x22, 0x3b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
20         0x00, 0x01, 0x0a, 0x01, 0xf8, 0x16, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x9d, 0xfb, 0x40, 0x49,
21         0xc6, 0xcd, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x26,
22         0x27, 0xe8, 0x00, 0x00, 0x02, 0x13, 0x00, 0x00, 0x3e, 0x80, 0x50, 0xbd, 0xe5, 0x80, 0x00, 0x00,
23         0x00, 0x00, 0x00, 0x00, 0x02, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
24         0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x05, 0xd2, 0x00, 0x00,
25         0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x3c, 0x8a, 0xb0, 0xe7, 0x54, 0x41, 0xb8, 0xca, 0x3a, 0x6d,
26         0xf0, 0x40, 0x08, 0x00, 0x45, 0x00, 0x05, 0xc0, 0x6b, 0xaa, 0x40, 0x00, 0x40, 0x06, 0x8f, 0x41,
27         0x0a, 0x01, 0x0e, 0x16, 0x36, 0xf0, 0xeb, 0x45, 0x76, 0xfd, 0x00, 0x50, 0xca, 0x77, 0xef, 0x96,
28         0xfc, 0x28, 0x63, 0x40, 0x50, 0x10, 0x00, 0x3c, 0x64, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
29         0xf4, 0x00, 0x00, 0x02, 0x77, 0x00, 0x00, 0x00, 0xfd, 0x3b, 0x8c, 0xe7, 0x04, 0x4a, 0x2d, 0xb2,
30         0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x01, 0x48, 0xcc, 0x11, 0x0d, 0xe3, 0x00,
31         0x26, 0x85, 0x30, 0x00, 0x00, 0x07, 0x66, 0x00, 0x02, 0xd0, 0x8a, 0x00, 0x02, 0xce, 0xf0, 0x00,
32         0x29, 0x7e, 0x80, 0x00, 0x02, 0xd0, 0x98, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x26, 0x85, 0x30, 0x00,
33         0x00, 0x00, 0xf4, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
34         0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35         0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x5e, 0x5c, 0x1e, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
36         0x07, 0xd0, 0xb1, 0x2f, 0xa2, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
37         0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00,
38         0x00, 0x01, 0x00, 0x00, 0x05, 0xee, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x3c, 0x8a,
39         0xb0, 0xe7, 0x54, 0x41, 0xb8, 0xca, 0x3a, 0x6f, 0xbe, 0xd8, 0x08, 0x00, 0x45, 0x00, 0x05, 0xdc,
40         0x9f, 0xfd, 0x40, 0x00, 0x40, 0x06, 0x6a, 0xfa, 0x0a, 0x01, 0x0e, 0x10, 0x0a, 0x01, 0x08, 0x13,
41         0x23, 0x84, 0xb7, 0x22, 0x8a, 0xc9, 0x50, 0xb5, 0x4e, 0x10, 0x2a, 0x87, 0x80, 0x10, 0x06, 0x01,
42         0x10, 0xa6, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0xef, 0x1f, 0xf4, 0x07, 0x99, 0x3a, 0xd8, 0x5b,
43         0x01, 0x46, 0x09, 0x00, 0x0c, 0x00, 0x0c, 0x3c, 0xac, 0x4a, 0x1b, 0x06, 0x04, 0x78, 0x78, 0x4e,
44         0xc2, 0x05, 0x46, 0x43, 0x06, 0x04, 0x78, 0x78, 0xee, 0x9c, 0x00, 0x41, 0xef, 0x05, 0x81, 0x32,
45         0x1b, 0x06, 0x04, 0x78, 0x78, 0x56, 0x72, 0x05, 0x4e, 0x92, 0x00, 0x96, 0x39, 0x00, 0xea, 0x3f,
46         0x01, 0x15, 0xa3, 0x08, 0x04, 0x42, 0x6a, 0x82, 0x87, 0x08, 0x05, 0xcc, 0x00, 0x04, 0x00, 0x00,
47         0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x5a,
49         0xcd, 0xd0, 0x00, 0x00, 0x02, 0x55, 0x00, 0x00, 0x07, 0xd0, 0x95, 0x67, 0xe1, 0x30, 0x00, 0x00,
50         0x00, 0x00, 0x00, 0x00, 0x02, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
51         0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x46, 0x00, 0x00,
52         0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x3c, 0x8a, 0xb0, 0xe7, 0x54, 0x41, 0xb8, 0xca, 0x3a, 0x6f,
53         0x11, 0x28, 0x08, 0x00, 0x45, 0x00, 0x04, 0x34, 0xdb, 0x36, 0x40, 0x00, 0x40, 0x06, 0x38, 0xac,
54         0x0a, 0x01, 0x0e, 0x11, 0x0a, 0x01, 0x00, 0xcf, 0x23, 0x84, 0xa0, 0x3f, 0x3c, 0xce, 0xd5, 0x4a,
55         0x72, 0x0b, 0x5d, 0x1a, 0x80, 0x10, 0x06, 0x01, 0x8a, 0x50, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
56         0xef, 0x1f, 0xa2, 0xba, 0xe6, 0xfa, 0xae, 0xb3, 0xfe, 0xcf, 0x00, 0x19, 0xcf, 0x00, 0x00, 0x00,
57         0x00, 0x00, 0x01, 0xb9, 0x79, 0xdd, 0x42, 0x00, 0x00, 0x02, 0x84, 0x9b, 0xa9, 0x02, 0xe2, 0x00,
58         0x00, 0x00, 0x00, 0x00, 0x06, 0x32, 0x39, 0x35, 0x34, 0x33, 0x36, 0x00, 0x00, 0x02, 0x70, 0xcd,
59         0x16, 0x40, 0xa6, 0x98, 0x88, 0x24, 0x06, 0x50, 0xb0, 0xf4, 0xee, 0x03, 0xa6, 0xfa, 0x87, 0xaf,
60         0xc1, 0x99, 0x52, 0x0d, 0x07, 0xa8, 0x00, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
61         0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62         0x00, 0x02, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x20, 0xf2, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00,
63         0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00,
64         0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x54, 0x0b, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
65         0x00, 0x03, 0x00, 0x01, 0x29, 0x82, 0x6d, 0xb0, 0x6c, 0x0b, 0xcb, 0x0d, 0xdd, 0x96, 0x00, 0x06,
66         0xa8, 0xc6, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67         0x00, 0x00, 0x00, 0x00, 0x34, 0x02, 0x35, 0x58, 0x7c, 0x9e, 0x56, 0x64, 0x25, 0x71, 0x00, 0x70,
68         0x5a, 0xc4, 0x00, 0x09, 0x08, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69         0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73         0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x5e, 0x5c, 0x1f, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
74         0x07, 0xd0, 0xb1, 0x2f, 0xaa, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
75         0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00,
76         0x00, 0x01, 0x00, 0x00, 0x05, 0xee, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x3c, 0x8a,
77         0xb0, 0xe7, 0x54, 0x41, 0xb8, 0xca, 0x3a, 0x6f, 0xbe, 0xd8, 0x08, 0x00, 0x45, 0x00, 0x05, 0xdc,
78         0x0f, 0xba, 0x40, 0x00, 0x40, 0x06, 0xf4, 0x3f, 0x0a, 0x01, 0x0e, 0x10, 0x0a, 0x01, 0x0f, 0x11,
79         0x23, 0x84, 0xcd, 0xc0, 0xf4, 0x0e, 0x90, 0x23, 0xd7, 0x32, 0x8b, 0x31, 0x80, 0x10, 0x00, 0x1d,
80         0x6b, 0x12, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0xef, 0x1f, 0xf4, 0x28, 0xef, 0x1f, 0xec, 0x76,
81         0xaa, 0x25, 0x01, 0x04, 0xc0, 0xac, 0xfe, 0x25, 0x01, 0x8e, 0x25, 0x01, 0x16, 0xc7, 0x28, 0xfe,
82         0x7e, 0x70, 0xfe, 0x7e, 0x70, 0x52, 0x7e, 0x70, 0x15, 0x9b, 0xfe, 0x35, 0x01, 0xfe, 0x35, 0x01,
83         0x42, 0x35, 0x01, 0xfe, 0x95, 0x77, 0xfe, 0x95, 0x77, 0xfe, 0x95, 0x77, 0x52, 0x95, 0x77, 0x00,
84         0xd2, 0xfe, 0x70, 0x02, 0x92, 0x70, 0x02, 0x16, 0x60, 0x22, 0x00, 0x7e, 0xb2, 0x15, 0x00, 0x00,
85         0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x5a,
87         0xcd, 0xd1, 0x00, 0x00, 0x02, 0x55, 0x00, 0x00, 0x07, 0xd0, 0x95, 0x67, 0xe9, 0x00, 0x00, 0x00,
88         0x00, 0x00, 0x00, 0x00, 0x02, 0x55, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
89         0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x05, 0xee, 0x00, 0x00,
90         0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0xb8, 0xca, 0x3a, 0x6f, 0xbe, 0xd8, 0xb8, 0xca, 0x3a, 0x6f,
91         0x11, 0x28, 0x08, 0x00, 0x45, 0x00, 0x05, 0xdc, 0xfe, 0x05, 0x40, 0x00, 0x40, 0x06, 0x06, 0xf4,
92         0x0a, 0x01, 0x0e, 0x11, 0x0a, 0x01, 0x0e, 0x10, 0x23, 0x84, 0xfa, 0x29, 0xae, 0xd4, 0x95, 0x03,
93         0x99, 0xb8, 0x77, 0xd0, 0x80, 0x10, 0x00, 0x1d, 0x6f, 0x4f, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
94         0xef, 0x1f, 0xa2, 0xcc, 0xef, 0x1f, 0xf4, 0x2c, 0xfe, 0xdb, 0x05, 0xa1, 0xdb, 0x04, 0x9e, 0xc0,
95         0xfe, 0x30, 0x08, 0xb2, 0x30, 0x08, 0xda, 0x2b, 0xbd, 0xfe, 0x2a, 0x01, 0xfe, 0x2a, 0x01, 0x21,
96         0x2a, 0x00, 0xb2, 0xfe, 0x57, 0xb0, 0xb6, 0x57, 0xb0, 0x14, 0x74, 0xf4, 0xf0, 0x4c, 0x05, 0x68,
97         0xfe, 0x54, 0x02, 0xfe, 0x54, 0x02, 0xd2, 0x54, 0x02, 0x00, 0xbe, 0xfe, 0x32, 0x0f, 0xb6, 0x32,
98         0x0f, 0x14, 0x2e, 0x16, 0xaf, 0x47, 0x00, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
99         0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100         0x00, 0x01, 0x00, 0x00, 0x00, 0x94, 0x01, 0x5e, 0x5c, 0x20, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
101         0x07, 0xd0, 0xb1, 0x2f, 0xb2, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x57, 0x00, 0x00,
102         0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00,
103         0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x42, 0x3c, 0x8a,
104         0xb0, 0xe7, 0x54, 0x41, 0xb8, 0xca, 0x3a, 0x6f, 0xbe, 0xd8, 0x08, 0x00, 0x45, 0x00, 0x00, 0x34,
105         0xa8, 0x23, 0x40, 0x00, 0x40, 0x06, 0x61, 0x7f, 0x0a, 0x01, 0x0e, 0x10, 0x0a, 0x01, 0x0f, 0x10,
106         0x97, 0x91, 0x23, 0x84, 0x24, 0xfa, 0x91, 0xf7, 0xb4, 0xe8, 0xf3, 0x2d, 0x80, 0x10, 0x00, 0xab,
107         0x7b, 0x7d, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0xef, 0x1f, 0xf4, 0x36, 0xef, 0x1f, 0xdc, 0xde,
108         0x00, 0x00, 0x00, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00,
109         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 }
111
112 // Test collected from the SFlow reference agent. Contains dummy data for several record types
113 // that wern't available on an actual network for sampling.
114 var SFlowTestPacket2 = []byte{
115         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
116         0x04, 0x88, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11, 0x38, 0x63, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00,
117         0x00, 0x01, 0xdc, 0xb8, 0x18, 0xc7, 0x04, 0x74, 0x02, 0x88, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
118         0x00, 0x01, 0xc0, 0xa8, 0x5b, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0x3a, 0x00, 0x00,
119         0xcb, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x54, 0x00, 0x02,
120         0x1f, 0x6e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x1f, 0x6e, 0x00, 0x00,
121         0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
122         0x03, 0xed, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x68, 0x74,
123         0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x6f,
124         0x72, 0x67, 0x00, 0x00, 0x00, 0x0f, 0x68, 0x6f, 0x73, 0x74, 0x31, 0x2e, 0x73, 0x66, 0x6c, 0x6f,
125         0x77, 0x2e, 0x6f, 0x72, 0x67, 0x06, 0x00, 0x00, 0x03, 0xec, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00,
126         0x00, 0x6a, 0x00, 0x00, 0x00, 0x0b, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x75, 0x73, 0x65,
127         0x72, 0xdc, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x10, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e,
128         0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x00, 0x00, 0x03, 0xeb, 0x00, 0x00,
129         0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x0c, 0x0b, 0x0a, 0x00, 0x00, 0xfd, 0xe9, 0x00, 0x00,
130         0x00, 0x7b, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
131         0x00, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x01, 0xc8, 0x00, 0x00, 0x03, 0x15, 0x00, 0x00,
132         0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x2b, 0x67, 0x00, 0x00, 0x56, 0xce, 0x00, 0x00,
133         0x82, 0x35, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x09, 0x00, 0x00,
134         0x03, 0x78, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
135         0x00, 0x0d, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00,
136         0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0c,
137         0x29, 0x67, 0xa0, 0xe5, 0x00, 0x50, 0x56, 0xc0, 0x00, 0x09, 0x08, 0x00, 0x45, 0x10, 0x00, 0x34,
138         0x92, 0xc3, 0x40, 0x00, 0x40, 0x06, 0x70, 0x8d, 0xc0, 0xa8, 0x5b, 0x01, 0xc0, 0xa8, 0x5b, 0x11,
139         0xd3, 0xdd, 0x00, 0x16, 0xe3, 0x2e, 0x84, 0x77, 0x13, 0x6d, 0xc5, 0x53, 0x80, 0x10, 0x1f, 0xf7,
140         0xe7, 0x7d, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x2e, 0xc6, 0x70, 0x3a, 0x00, 0x0f, 0x84, 0x7a,
141         0xbc, 0xd2, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x90, 0x00, 0x02, 0x1f, 0x6f, 0x00, 0x00,
142         0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x1f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
143         0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0xed, 0x00, 0x00,
144         0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f,
145         0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x6f, 0x72, 0x67, 0x00, 0x00,
146         0x00, 0x0f, 0x68, 0x6f, 0x73, 0x74, 0x31, 0x2e, 0x73, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x6f, 0x72,
147         0x67, 0x03, 0x00, 0x00, 0x03, 0xec, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00,
148         0x00, 0x0b, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x75, 0x73, 0x65, 0x72, 0x77, 0x00, 0x00,
149         0x00, 0x6a, 0x00, 0x00, 0x00, 0x10, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f,
150         0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x00, 0x00, 0x03, 0xeb, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00,
151         0x00, 0x01, 0x0d, 0x0c, 0x0b, 0x0a, 0x00, 0x00, 0xfd, 0xe9, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00,
152         0x03, 0xe7, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
153         0x00, 0x7b, 0x00, 0x00, 0x01, 0xc8, 0x00, 0x00, 0x03, 0x15, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
154         0x00, 0x03, 0x00, 0x00, 0x2b, 0x67, 0x00, 0x00, 0x56, 0xce, 0x00, 0x00, 0x82, 0x35, 0x00, 0x00,
155         0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x09, 0x00, 0x00, 0x03, 0x78, 0x00, 0x00,
156         0x03, 0xe7, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00,
157         0x01, 0xb0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
158         0x01, 0x86, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x50, 0x56, 0xc0, 0x00, 0x09,
159         0x00, 0x0c, 0x29, 0x67, 0xa0, 0xe5, 0x08, 0x00, 0x45, 0x10, 0x01, 0x74, 0xbb, 0xfa, 0x40, 0x00,
160         0x40, 0x06, 0x46, 0x16, 0xc0, 0xa8, 0x5b, 0x11, 0xc0, 0xa8, 0x5b, 0x01, 0x00, 0x16, 0xd3, 0xdd,
161         0x13, 0x6d, 0xc5, 0x53, 0xe3, 0x2e, 0x84, 0x77, 0x80, 0x18, 0x01, 0x10, 0x38, 0xca, 0x00, 0x00,
162         0x01, 0x01, 0x08, 0x0a, 0x00, 0x0f, 0x84, 0x7d, 0x2e, 0xc6, 0x70, 0x3a, 0xe3, 0x92, 0x97, 0x1a,
163         0x67, 0x3b, 0xac, 0xec, 0xfa, 0x43, 0x71, 0x5e, 0x36, 0xa1, 0x0a, 0xc6, 0x1a, 0x6a, 0xed, 0x08,
164         0xac, 0xf4, 0xbe, 0xd8, 0x36, 0x59, 0xf6, 0xe2, 0x3d, 0x34, 0x26, 0xf2, 0x42, 0xbd, 0x32, 0xd3,
165         0x37, 0x52, 0xb8, 0xf4, 0x38, 0xf0, 0xf4, 0xeb, 0x76, 0x3b, 0xda, 0x23, 0xf1, 0x92, 0x96, 0xca,
166         0xbb, 0x9c, 0x20, 0x0a, 0x38, 0x37, 0x6f, 0xd9, 0x26, 0xe6, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
167         0x01, 0x54, 0x00, 0x02, 0x1f, 0x70, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,
168         0x1f, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x00,
169         0x00, 0x04, 0x00, 0x00, 0x03, 0xed, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
170         0x00, 0x14, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x66, 0x6c,
171         0x6f, 0x77, 0x2e, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x00, 0x0f, 0x68, 0x6f, 0x73, 0x74, 0x31, 0x2e,
172         0x73, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x6f, 0x72, 0x67, 0xff, 0x00, 0x00, 0x03, 0xec, 0x00, 0x00,
173         0x00, 0x2c, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x0b, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
174         0x20, 0x75, 0x73, 0x65, 0x72, 0x77, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x10, 0x64, 0x65,
175         0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x75, 0x73, 0x65, 0x72, 0x00, 0x00,
176         0x03, 0xeb, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x0c, 0x0b, 0x0a, 0x00, 0x00,
177         0xfd, 0xe9, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
178         0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x01, 0xc8, 0x00, 0x00,
179         0x03, 0x15, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x2b, 0x67, 0x00, 0x00,
180         0x56, 0xce, 0x00, 0x00, 0x82, 0x35, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
181         0x03, 0x09, 0x00, 0x00, 0x03, 0x78, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
182         0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x01, 0xb0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
183         0x00, 0x54, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
184         0x00, 0x42, 0x00, 0x0c, 0x29, 0x67, 0xa0, 0xe5, 0x00, 0x50, 0x56, 0xc0, 0x00, 0x09, 0x08, 0x00,
185         0x45, 0x10, 0x00, 0x34, 0x65, 0x7d, 0x40, 0x00, 0x40, 0x06, 0x9d, 0xd3, 0xc0, 0xa8, 0x5b, 0x01,
186         0xc0, 0xa8, 0x5b, 0x11, 0xd3, 0xdd, 0x00, 0x16, 0xe3, 0x2e, 0x84, 0x77, 0x13, 0x6d, 0xc6, 0x93,
187         0x80, 0x10, 0x1f, 0xec, 0xe6, 0x43, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x2e, 0xc6, 0x70, 0x3c,
188         0x00, 0x0f, 0x84, 0x7d, 0x00, 0x50,
189 }
190
191 // processor counter sample
192 var SFlowTestPacket3 = []byte{
193         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01,
194         0x0a, 0x14, 0x04, 0x00, 0x00, 0x00, 0x00, 0x64,
195         0x00, 0x01, 0x78, 0xe0, 0x73, 0x03, 0x48, 0x78,
196         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,
197         0x00, 0x00, 0x00, 0x34, 0x00, 0x01, 0x78, 0xe0,
198         0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
199         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xe9,
200         0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x05, 0xaa,
201         0x00, 0x00, 0x05, 0x5a, 0x00, 0x00, 0x05, 0x32,
202         0x00, 0x00, 0x00, 0x00, 0xe7, 0x8d, 0x70, 0x00,
203         0x00, 0x00, 0x00, 0x00, 0x55, 0xe7, 0x70, 0x00,
204 }
205
206 // expanded flow sample - extended switch flow record
207 var SFlowTestPacket4 = []byte{
208         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01,
209         0xc0, 0xa8, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00,
210         0x00, 0x00, 0x02, 0x7e, 0x32, 0xe0, 0xe4, 0x7c,
211         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
212         0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x01, 0x23,
213         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x01, 0x00,
214         0x00, 0x00, 0x03, 0x37, 0x00, 0x00, 0x56, 0x23,
215         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x04,
216         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xe9,
217         0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03,
218         0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05,
219         0xff, 0xff, 0xff, 0xff,
220 }
221
222 // expanded flow sample - extended router flow record
223 var SFlowTestPacket5 = []byte{
224         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01,
225         0xc0, 0xa8, 0x01, 0x12, 0x00, 0x00, 0x00, 0x00,
226         0x00, 0x00, 0x02, 0x7e, 0x32, 0xe0, 0xe4, 0x7c,
227         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
228         0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x01, 0x23,
229         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x01, 0x00,
230         0x00, 0x00, 0x03, 0x34, 0x00, 0x00, 0x56, 0x02,
231         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x04,
232         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xea,
233         0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01,
234         0xc0, 0xa8, 0x01, 0x21, 0xff, 0xff, 0xff, 0xff,
235         0xff, 0xff, 0xff, 0x80,
236 }
237
238 // expanded flow sample - Ipv4 Tunnel Ingress record
239 var SFlowTestPacket6 = []byte{
240         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01,
241         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x00, 0x01, 0xbd, 0x50,
242         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48,
243         0x00, 0x00, 0x00, 0x74, 0x02, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x01,
244         0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245         0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0x00,
246         0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f,
247         0xc0, 0xa8, 0x00, 0x54, 0xc0, 0xa8, 0x00, 0x53, 0x00, 0x00, 0x00, 0x00,
248         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 }
250
251 // expanded flow sample - Ipv4 Tunnel Egress record
252 var SFlowTestPacket7 = []byte{
253         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01,
254         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x42, 0x68,
255         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48,
256         0x00, 0x00, 0x00, 0x12, 0x02, 0x00, 0x03, 0xe9, 0x00, 0x00, 0x00, 0x01,
257         0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c,
258         0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
259         0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
260         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x00, 0x54,
261         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262         0x00, 0x00, 0x00, 0x00,
263 }
264
265 // expanded flow sample - extended router flow record IPv6 next hop
266 var SFlowTestPacket8 = []byte{
267         0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01,
268         0xc0, 0xa8, 0x01, 0x12, 0x00, 0x00, 0x00, 0x00,
269         0x00, 0x00, 0x02, 0x7e, 0x32, 0xe0, 0xe4, 0x7c,
270         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
271         0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x01, 0x23,
272         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x01, 0x00,
273         0x00, 0x00, 0x03, 0x34, 0x00, 0x00, 0x56, 0x02,
274         0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x04,
275         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xea,
276         0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02,
277         0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
278         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279         0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80,
280 }
281
282 func TestDecodeUDPSFlow(t *testing.T) {
283         p := gopacket.NewPacket(SFlowTestPacket1, LayerTypeEthernet, gopacket.Default)
284         if p.ErrorLayer() != nil {
285                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
286         }
287         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t)
288         if got, ok := p.TransportLayer().(*UDP); ok {
289                 want := &UDP{
290                         BaseLayer: BaseLayer{SFlowTestPacket1[34:42], SFlowTestPacket1[42:]},
291                         sPort:     []byte{199, 87},
292                         dPort:     []byte{24, 199},
293                         SrcPort:   51031,
294                         DstPort:   6343,
295                         Checksum:  8763,
296                         Length:    1448,
297                 }
298                 if !reflect.DeepEqual(want, got) {
299                         t.Errorf("UDP layer mismatch, \nwant  %#v\ngot %#v\n", want, got)
300                 }
301         } else {
302                 t.Error("Transport layer packet not UDP")
303         }
304 }
305
306 func TestDecodeSFlowDatagram(t *testing.T) {
307         p := gopacket.NewPacket(SFlowTestPacket1, LayerTypeEthernet, gopacket.Default)
308         if p.ErrorLayer() != nil {
309                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
310         }
311         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t)
312         if got, ok := p.ApplicationLayer().(*SFlowDatagram); ok {
313                 want := &SFlowDatagram{
314                         DatagramVersion: uint32(5),
315                         AgentAddress:    []byte{0xa, 0x1, 0xf8, 0x16},
316                         SubAgentID:      uint32(17),
317                         SequenceNumber:  uint32(40443),
318                         AgentUptime:     uint32(1078576845),
319                         SampleCount:     uint32(7),
320                         FlowSamples: []SFlowFlowSample{
321                                 SFlowFlowSample{
322                                         EnterpriseID:    0x0,
323                                         Format:          0x1,
324                                         SampleLength:    0xd0,
325                                         SequenceNumber:  0x2627e8,
326                                         SourceIDClass:   0x0,
327                                         SourceIDIndex:   0x213,
328                                         SamplingRate:    0x3e80,
329                                         SamplePool:      0x50bde580,
330                                         Dropped:         0x0,
331                                         InputInterface:  0x213,
332                                         OutputInterface: 0x0,
333                                         RecordCount:     0x2,
334                                         Records: []SFlowRecord{
335                                                 SFlowRawPacketFlowRecord{
336                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
337                                                                 EnterpriseID:   0x0,
338                                                                 Format:         0x1,
339                                                                 FlowDataLength: 0x90,
340                                                         },
341                                                         HeaderProtocol: 0x1,
342                                                         FrameLength:    0x5d2,
343                                                         PayloadRemoved: 0x4,
344                                                         HeaderLength:   0x80,
345                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[134:262], LayerTypeEthernet, gopacket.Default),
346                                                 },
347                                                 SFlowExtendedSwitchFlowRecord{
348                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
349                                                                 EnterpriseID:   0x0,
350                                                                 Format:         0x3e9,
351                                                                 FlowDataLength: 0x10,
352                                                         },
353                                                         IncomingVLAN:         0x202,
354                                                         IncomingVLANPriority: 0x0,
355                                                         OutgoingVLAN:         0x0,
356                                                         OutgoingVLANPriority: 0x0,
357                                                 },
358                                         },
359                                 },
360                                 SFlowFlowSample{
361                                         EnterpriseID:    0x0,
362                                         Format:          0x1,
363                                         SampleLength:    0xd0,
364                                         SequenceNumber:  0x15e5c1e,
365                                         SourceIDClass:   0x0,
366                                         SourceIDIndex:   0x257,
367                                         SamplingRate:    0x7d0,
368                                         SamplePool:      0xb12fa290,
369                                         Dropped:         0x0,
370                                         InputInterface:  0x257,
371                                         OutputInterface: 0x0,
372                                         RecordCount:     0x2,
373                                         Records: []SFlowRecord{
374                                                 SFlowRawPacketFlowRecord{
375                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
376                                                                 EnterpriseID:   0x0,
377                                                                 Format:         0x1,
378                                                                 FlowDataLength: 0x90,
379                                                         },
380                                                         HeaderProtocol: 0x1,
381                                                         FrameLength:    0x5ee,
382                                                         PayloadRemoved: 0x4,
383                                                         HeaderLength:   0x80,
384                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[350:478], LayerTypeEthernet, gopacket.Default),
385                                                 },
386                                                 SFlowExtendedSwitchFlowRecord{
387                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
388                                                                 EnterpriseID:   0x0,
389                                                                 Format:         0x3e9,
390                                                                 FlowDataLength: 0x10,
391                                                         },
392                                                         IncomingVLAN:         0x202,
393                                                         IncomingVLANPriority: 0x0,
394                                                         OutgoingVLAN:         0x0,
395                                                         OutgoingVLANPriority: 0x0,
396                                                 },
397                                         },
398                                 },
399                                 SFlowFlowSample{
400                                         EnterpriseID:    0x0,
401                                         Format:          0x1,
402                                         SampleLength:    0xd0,
403                                         SequenceNumber:  0x15acdd0,
404                                         SourceIDClass:   0x0,
405                                         SourceIDIndex:   0x255,
406                                         SamplingRate:    0x7d0,
407                                         SamplePool:      0x9567e130,
408                                         Dropped:         0x0,
409                                         InputInterface:  0x255,
410                                         OutputInterface: 0x0,
411                                         RecordCount:     0x2,
412                                         Records: []SFlowRecord{
413                                                 SFlowRawPacketFlowRecord{
414                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
415                                                                 EnterpriseID:   0x0,
416                                                                 Format:         0x1,
417                                                                 FlowDataLength: 0x90,
418                                                         },
419                                                         HeaderProtocol: 0x1,
420                                                         FrameLength:    0x446,
421                                                         PayloadRemoved: 0x4,
422                                                         HeaderLength:   0x80,
423                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[566:694], LayerTypeEthernet, gopacket.Default),
424                                                 },
425                                                 SFlowExtendedSwitchFlowRecord{
426                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
427                                                                 EnterpriseID:   0x0,
428                                                                 Format:         0x3e9,
429                                                                 FlowDataLength: 0x10,
430                                                         },
431                                                         IncomingVLAN:         0x202,
432                                                         IncomingVLANPriority: 0x0,
433                                                         OutgoingVLAN:         0x0,
434                                                         OutgoingVLANPriority: 0x0,
435                                                 },
436                                         },
437                                 },
438                                 SFlowFlowSample{
439                                         EnterpriseID:    0x0,
440                                         Format:          0x1,
441                                         SampleLength:    0xd0,
442                                         SequenceNumber:  0x15e5c1f,
443                                         SourceIDClass:   0x0,
444                                         SourceIDIndex:   0x257,
445                                         SamplingRate:    0x7d0,
446                                         SamplePool:      0xb12faa60,
447                                         Dropped:         0x0,
448                                         InputInterface:  0x257,
449                                         OutputInterface: 0x0,
450                                         RecordCount:     0x2,
451                                         Records: []SFlowRecord{
452                                                 SFlowRawPacketFlowRecord{
453                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
454                                                                 EnterpriseID:   0x0,
455                                                                 Format:         0x1,
456                                                                 FlowDataLength: 0x90,
457                                                         },
458                                                         HeaderProtocol: 0x1,
459                                                         FrameLength:    0x5ee,
460                                                         PayloadRemoved: 0x4,
461                                                         HeaderLength:   0x80,
462                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[958:1086], LayerTypeEthernet, gopacket.Default),
463                                                 },
464                                                 SFlowExtendedSwitchFlowRecord{
465                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
466                                                                 EnterpriseID:   0x0,
467                                                                 Format:         0x3e9,
468                                                                 FlowDataLength: 0x10,
469                                                         },
470                                                         IncomingVLAN:         0x202,
471                                                         IncomingVLANPriority: 0x0,
472                                                         OutgoingVLAN:         0x0,
473                                                         OutgoingVLANPriority: 0x0,
474                                                 },
475                                         },
476                                 },
477                                 SFlowFlowSample{
478                                         EnterpriseID:    0x0,
479                                         Format:          0x1,
480                                         SampleLength:    0xd0,
481                                         SequenceNumber:  0x15acdd1,
482                                         SourceIDClass:   0x0,
483                                         SourceIDIndex:   0x255,
484                                         SamplingRate:    0x7d0,
485                                         SamplePool:      0x9567e900,
486                                         Dropped:         0x0,
487                                         InputInterface:  0x255,
488                                         OutputInterface: 0x257,
489                                         RecordCount:     0x2,
490                                         Records: []SFlowRecord{
491                                                 SFlowRawPacketFlowRecord{
492                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
493                                                                 EnterpriseID:   0x0,
494                                                                 Format:         0x1,
495                                                                 FlowDataLength: 0x90,
496                                                         },
497                                                         HeaderProtocol: 0x1,
498                                                         FrameLength:    0x5ee,
499                                                         PayloadRemoved: 0x4,
500                                                         HeaderLength:   0x80,
501                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[1174:1302], LayerTypeEthernet, gopacket.Default),
502                                                 },
503                                                 SFlowExtendedSwitchFlowRecord{
504                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
505                                                                 EnterpriseID:   0x0,
506                                                                 Format:         0x3e9,
507                                                                 FlowDataLength: 0x10,
508                                                         },
509                                                         IncomingVLAN:         0x202,
510                                                         IncomingVLANPriority: 0x0,
511                                                         OutgoingVLAN:         0x202,
512                                                         OutgoingVLANPriority: 0x0,
513                                                 },
514                                         },
515                                 },
516                                 SFlowFlowSample{
517                                         EnterpriseID:    0x0,
518                                         Format:          0x1,
519                                         SampleLength:    0x94,
520                                         SequenceNumber:  0x15e5c20,
521                                         SourceIDClass:   0x0,
522                                         SourceIDIndex:   0x257,
523                                         SamplingRate:    0x7d0,
524                                         SamplePool:      0xb12fb230,
525                                         Dropped:         0x0,
526                                         InputInterface:  0x257,
527                                         OutputInterface: 0x0,
528                                         RecordCount:     0x2,
529                                         Records: []SFlowRecord{
530                                                 SFlowRawPacketFlowRecord{
531                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
532                                                                 EnterpriseID:   0x0,
533                                                                 Format:         0x1,
534                                                                 FlowDataLength: 0x54,
535                                                         },
536                                                         HeaderProtocol: 0x1,
537                                                         FrameLength:    0x46,
538                                                         PayloadRemoved: 0x4,
539                                                         HeaderLength:   0x42,
540                                                         Header:         gopacket.NewPacket(SFlowTestPacket1[1390:1458], LayerTypeEthernet, gopacket.Default),
541                                                 },
542                                                 SFlowExtendedSwitchFlowRecord{
543                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
544                                                                 EnterpriseID:   0x0,
545                                                                 Format:         0x3e9,
546                                                                 FlowDataLength: 0x10,
547                                                         },
548                                                         IncomingVLAN:         0x202,
549                                                         IncomingVLANPriority: 0x0,
550                                                         OutgoingVLAN:         0x0,
551                                                         OutgoingVLANPriority: 0x0,
552                                                 },
553                                         },
554                                 },
555                         },
556                         CounterSamples: []SFlowCounterSample{
557                                 SFlowCounterSample{
558                                         Format:         0x2,
559                                         SampleLength:   0xa8,
560                                         SequenceNumber: 0x20f2,
561                                         SourceIDClass:  0x0,
562                                         SourceIDIndex:  0x20a,
563                                         RecordCount:    0x2,
564                                         Records: []SFlowRecord{
565                                                 SFlowGenericInterfaceCounters{
566                                                         SFlowBaseCounterRecord: SFlowBaseCounterRecord{
567                                                                 EnterpriseID:   0x0,
568                                                                 Format:         0x1,
569                                                                 FlowDataLength: 0x58,
570                                                         },
571                                                         IfIndex:            0x20a,
572                                                         IfType:             0x6,
573                                                         IfSpeed:            0x2540be400,
574                                                         IfDirection:        0x1,
575                                                         IfStatus:           0x3,
576                                                         IfInOctets:         0x129826db06c0b,
577                                                         IfInUcastPkts:      0xcb0ddd96,
578                                                         IfInMulticastPkts:  0x6a8c6,
579                                                         IfInBroadcastPkts:  0x7b,
580                                                         IfInDiscards:       0x0,
581                                                         IfInErrors:         0x0,
582                                                         IfInUnknownProtos:  0x0,
583                                                         IfOutOctets:        0x340235587c9e,
584                                                         IfOutUcastPkts:     0x56642571,
585                                                         IfOutMulticastPkts: 0x705ac4,
586                                                         IfOutBroadcastPkts: 0x908f1,
587                                                         IfOutDiscards:      0x0,
588                                                         IfOutErrors:        0x0,
589                                                         IfPromiscuousMode:  0x0,
590                                                 },
591                                                 SFlowEthernetCounters{
592                                                         SFlowBaseCounterRecord: SFlowBaseCounterRecord{
593                                                                 EnterpriseID:   0x0,
594                                                                 Format:         0x2,
595                                                                 FlowDataLength: 0x34,
596                                                         },
597                                                         AlignmentErrors:           0x0,
598                                                         FCSErrors:                 0x0,
599                                                         SingleCollisionFrames:     0x0,
600                                                         MultipleCollisionFrames:   0x0,
601                                                         SQETestErrors:             0x0,
602                                                         DeferredTransmissions:     0x0,
603                                                         LateCollisions:            0x0,
604                                                         ExcessiveCollisions:       0x0,
605                                                         InternalMacTransmitErrors: 0x0,
606                                                         CarrierSenseErrors:        0x0,
607                                                         FrameTooLongs:             0x0,
608                                                         InternalMacReceiveErrors:  0x0,
609                                                         SymbolErrors:              0x0,
610                                                 },
611                                         },
612                                 },
613                         },
614                 }
615                 if !reflect.DeepEqual(want, got) {
616                         t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
617                 }
618         } else {
619                 t.Error("Application layer packet not UDP")
620         }
621 }
622
623 func TestPacketPacket0(t *testing.T) {
624         p := gopacket.NewPacket(SFlowTestPacket2, LinkTypeEthernet, gopacket.Default)
625         if p.ErrorLayer() != nil {
626                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
627         }
628         checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t)
629         if got, ok := p.ApplicationLayer().(*SFlowDatagram); ok {
630                 want := &SFlowDatagram{
631                         DatagramVersion: uint32(5),
632                         AgentAddress:    []byte{192, 168, 91, 17},
633                         SubAgentID:      uint32(0),
634                         SequenceNumber:  uint32(46394),
635                         AgentUptime:     uint32(52000),
636                         SampleCount:     uint32(3),
637                         FlowSamples: []SFlowFlowSample{
638                                 SFlowFlowSample{
639                                         EnterpriseID:    0x0,
640                                         Format:          0x1,
641                                         SampleLength:    340,
642                                         SequenceNumber:  139118,
643                                         SourceIDClass:   0,
644                                         SourceIDIndex:   3,
645                                         SamplingRate:    1,
646                                         SamplePool:      139118,
647                                         Dropped:         0,
648                                         InputInterface:  3,
649                                         OutputInterface: 1073741823,
650                                         RecordCount:     4,
651                                         Records: []SFlowRecord{
652                                                 SFlowExtendedURLRecord{
653                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
654                                                                 EnterpriseID:   0,
655                                                                 Format:         1005,
656                                                                 FlowDataLength: 48,
657                                                         },
658                                                         Direction: SFlowURLsrc,
659                                                         URL:       "http://www.sflow.org",
660                                                         Host:      "host1.sflow.org",
661                                                 },
662                                                 SFlowExtendedUserFlow{
663                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
664                                                                 EnterpriseID:   0,
665                                                                 Format:         1004,
666                                                                 FlowDataLength: 44,
667                                                         },
668                                                         SourceCharSet:      SFlowCSUTF8,
669                                                         SourceUserID:       "source user",
670                                                         DestinationCharSet: SFlowCSUTF8,
671                                                         DestinationUserID:  "destination user",
672                                                 },
673                                                 SFlowExtendedGatewayFlowRecord{
674                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
675                                                                 EnterpriseID:   0,
676                                                                 Format:         1003,
677                                                                 FlowDataLength: 100,
678                                                         },
679                                                         NextHop:     []byte{0x0d, 0x0c, 0x0b, 0x0a},
680                                                         AS:          65001,
681                                                         SourceAS:    123,
682                                                         PeerAS:      999,
683                                                         ASPathCount: 3,
684                                                         ASPath: []SFlowASDestination{
685                                                                 SFlowASDestination{
686                                                                         Type:    SFlowASSequence,
687                                                                         Count:   3,
688                                                                         Members: []uint32{123, 456, 789},
689                                                                 },
690                                                                 SFlowASDestination{
691                                                                         Type:    SFlowASSet,
692                                                                         Count:   3,
693                                                                         Members: []uint32{11111, 22222, 33333},
694                                                                 },
695                                                                 SFlowASDestination{
696                                                                         Type:    SFlowASSequence,
697                                                                         Count:   3,
698                                                                         Members: []uint32{777, 888, 999},
699                                                                 },
700                                                         },
701                                                         Communities: []uint32{12, 13},
702                                                         LocalPref:   432,
703                                                 },
704                                                 SFlowRawPacketFlowRecord{
705                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
706                                                                 EnterpriseID:   0x0,
707                                                                 Format:         0x1,
708                                                                 FlowDataLength: 84,
709                                                         },
710                                                         HeaderProtocol: 1,
711                                                         FrameLength:    70,
712                                                         PayloadRemoved: 4,
713                                                         HeaderLength:   0x42,
714                                                         Header:         gopacket.NewPacket(SFlowTestPacket2[350:418], LayerTypeEthernet, gopacket.Default),
715                                                 },
716                                         },
717                                 },
718                                 SFlowFlowSample{
719                                         EnterpriseID:    0x0,
720                                         Format:          0x1,
721                                         SampleLength:    400,
722                                         SequenceNumber:  139119,
723                                         SourceIDClass:   0,
724                                         SourceIDIndex:   3,
725                                         SamplingRate:    1,
726                                         SamplePool:      139119,
727                                         Dropped:         0,
728                                         InputInterface:  1073741823,
729                                         OutputInterface: 3,
730                                         RecordCount:     4,
731                                         Records: []SFlowRecord{
732                                                 SFlowExtendedURLRecord{
733                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
734                                                                 EnterpriseID:   0,
735                                                                 Format:         1005,
736                                                                 FlowDataLength: 48,
737                                                         },
738                                                         Direction: SFlowURLsrc,
739                                                         URL:       "http://www.sflow.org",
740                                                         Host:      "host1.sflow.org",
741                                                 },
742                                                 SFlowExtendedUserFlow{
743                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
744                                                                 EnterpriseID:   0,
745                                                                 Format:         1004,
746                                                                 FlowDataLength: 44,
747                                                         },
748                                                         SourceCharSet:      SFlowCSUTF8,
749                                                         SourceUserID:       "source user",
750                                                         DestinationCharSet: SFlowCSUTF8,
751                                                         DestinationUserID:  "destination user",
752                                                 },
753                                                 SFlowExtendedGatewayFlowRecord{
754                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
755                                                                 EnterpriseID:   0,
756                                                                 Format:         1003,
757                                                                 FlowDataLength: 100,
758                                                         },
759                                                         NextHop:     []byte{0x0d, 0x0c, 0x0b, 0x0a},
760                                                         AS:          65001,
761                                                         SourceAS:    123,
762                                                         PeerAS:      999,
763                                                         ASPathCount: 3,
764                                                         ASPath: []SFlowASDestination{
765                                                                 SFlowASDestination{
766                                                                         Type:    SFlowASSequence,
767                                                                         Count:   3,
768                                                                         Members: []uint32{123, 456, 789},
769                                                                 },
770                                                                 SFlowASDestination{
771                                                                         Type:    SFlowASSet,
772                                                                         Count:   3,
773                                                                         Members: []uint32{11111, 22222, 33333},
774                                                                 },
775                                                                 SFlowASDestination{
776                                                                         Type:    SFlowASSequence,
777                                                                         Count:   3,
778                                                                         Members: []uint32{777, 888, 999},
779                                                                 },
780                                                         },
781                                                         Communities: []uint32{12, 13},
782                                                         LocalPref:   432,
783                                                 },
784                                                 SFlowRawPacketFlowRecord{
785                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
786                                                                 EnterpriseID:   0x0,
787                                                                 Format:         0x1,
788                                                                 FlowDataLength: 144,
789                                                         },
790                                                         HeaderProtocol: 1,
791                                                         FrameLength:    390,
792                                                         PayloadRemoved: 4,
793                                                         HeaderLength:   0x80,
794                                                         Header:         gopacket.NewPacket(SFlowTestPacket2[698:826], LayerTypeEthernet, gopacket.Default),
795                                                 },
796                                         },
797                                 },
798                                 SFlowFlowSample{
799                                         EnterpriseID:    0x0,
800                                         Format:          0x1,
801                                         SampleLength:    340,
802                                         SequenceNumber:  139120,
803                                         SourceIDClass:   0,
804                                         SourceIDIndex:   3,
805                                         SamplingRate:    1,
806                                         SamplePool:      139120,
807                                         Dropped:         0,
808                                         InputInterface:  3,
809                                         OutputInterface: 1073741823,
810                                         RecordCount:     4,
811                                         Records: []SFlowRecord{
812                                                 SFlowExtendedURLRecord{
813                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
814                                                                 EnterpriseID:   0,
815                                                                 Format:         1005,
816                                                                 FlowDataLength: 48,
817                                                         },
818                                                         Direction: SFlowURLsrc,
819                                                         URL:       "http://www.sflow.org",
820                                                         Host:      "host1.sflow.org",
821                                                 },
822                                                 SFlowExtendedUserFlow{
823                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
824                                                                 EnterpriseID:   0,
825                                                                 Format:         1004,
826                                                                 FlowDataLength: 44,
827                                                         },
828                                                         SourceCharSet:      SFlowCSUTF8,
829                                                         SourceUserID:       "source user",
830                                                         DestinationCharSet: SFlowCSUTF8,
831                                                         DestinationUserID:  "destination user",
832                                                 },
833                                                 SFlowExtendedGatewayFlowRecord{
834                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
835                                                                 EnterpriseID:   0,
836                                                                 Format:         1003,
837                                                                 FlowDataLength: 100,
838                                                         },
839                                                         NextHop:     []byte{0x0d, 0x0c, 0x0b, 0x0a},
840                                                         AS:          65001,
841                                                         SourceAS:    123,
842                                                         PeerAS:      999,
843                                                         ASPathCount: 3,
844                                                         ASPath: []SFlowASDestination{
845                                                                 SFlowASDestination{
846                                                                         Type:    SFlowASSequence,
847                                                                         Count:   3,
848                                                                         Members: []uint32{123, 456, 789},
849                                                                 },
850                                                                 SFlowASDestination{
851                                                                         Type:    SFlowASSet,
852                                                                         Count:   3,
853                                                                         Members: []uint32{11111, 22222, 33333},
854                                                                 },
855                                                                 SFlowASDestination{
856                                                                         Type:    SFlowASSequence,
857                                                                         Count:   3,
858                                                                         Members: []uint32{777, 888, 999},
859                                                                 },
860                                                         },
861                                                         Communities: []uint32{12, 13},
862                                                         LocalPref:   432,
863                                                 },
864                                                 SFlowRawPacketFlowRecord{
865                                                         SFlowBaseFlowRecord: SFlowBaseFlowRecord{
866                                                                 EnterpriseID:   0x0,
867                                                                 Format:         0x1,
868                                                                 FlowDataLength: 84,
869                                                         },
870                                                         HeaderProtocol: 1,
871                                                         FrameLength:    70,
872                                                         PayloadRemoved: 4,
873                                                         HeaderLength:   0x42,
874                                                         Header:         gopacket.NewPacket(SFlowTestPacket2[1106:1174], LayerTypeEthernet, gopacket.Default),
875                                                 },
876                                         },
877                                 },
878                         },
879                 }
880                 if !reflect.DeepEqual(want, got) {
881                         t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
882                 }
883         } else {
884                 t.Error("Application layer packet not UDP")
885         }
886 }
887
888 func TestDecodeProcessorCounter(t *testing.T) {
889         p := gopacket.NewPacket(SFlowTestPacket3, LayerTypeSFlow, gopacket.Default)
890
891         if p.ErrorLayer() != nil {
892                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
893         }
894         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
895
896         got := p.ApplicationLayer().(*SFlowDatagram)
897
898         want := &SFlowDatagram{
899                 DatagramVersion: uint32(5),
900                 AgentAddress:    []byte{0x0a, 0x14, 0x04, 0x00},
901                 SubAgentID:      uint32(0x64),
902                 SequenceNumber:  uint32(96480),
903                 AgentUptime:     uint32(1929595000),
904                 SampleCount:     uint32(1),
905                 CounterSamples: []SFlowCounterSample{
906                         SFlowCounterSample{
907                                 Format:         SFlowTypeExpandedCounterSample,
908                                 SampleLength:   0x34,
909                                 SequenceNumber: 0x0178e0,
910                                 SourceIDClass:  0x00,
911                                 SourceIDIndex:  0x01,
912                                 RecordCount:    0x01,
913                                 Records: []SFlowRecord{
914                                         SFlowProcessorCounters{
915                                                 SFlowBaseCounterRecord: SFlowBaseCounterRecord{
916                                                         EnterpriseID:   0x0,
917                                                         Format:         SFlowTypeProcessorCounters,
918                                                         FlowDataLength: 0x1c,
919                                                 },
920                                                 FiveSecCpu:  0x05aa,
921                                                 OneMinCpu:   0x055a,
922                                                 FiveMinCpu:  0x0532,
923                                                 TotalMemory: 0xe78d7000,
924                                                 FreeMemory:  0x55e77000,
925                                         },
926                                 },
927                         },
928                 },
929         }
930         if !reflect.DeepEqual(want, got) {
931                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
932         }
933 }
934
935 func TestDecodeExtendedSwitchFlow(t *testing.T) {
936         p := gopacket.NewPacket(SFlowTestPacket4, LayerTypeSFlow, gopacket.Default)
937
938         if p.ErrorLayer() != nil {
939                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
940         }
941         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
942
943         got := p.ApplicationLayer().(*SFlowDatagram)
944
945         want := &SFlowDatagram{
946                 DatagramVersion: uint32(5),
947                 AgentAddress:    []byte{0xc0, 0xa8, 0x01, 0x07},
948                 SubAgentID:      uint32(0x00),
949                 SequenceNumber:  uint32(0x027e),
950                 AgentUptime:     uint32(0x32e0e47c),
951                 SampleCount:     uint32(1),
952                 FlowSamples: []SFlowFlowSample{
953                         SFlowFlowSample{
954                                 Format:                SFlowTypeFlowSample,
955                                 SampleLength:          0x38,
956                                 SequenceNumber:        0x123,
957                                 SourceIDClass:         0x00,
958                                 SourceIDIndex:         0x1d,
959                                 SamplingRate:          0x100,
960                                 SamplePool:            0x337,
961                                 Dropped:               0x5623,
962                                 InputInterfaceFormat:  0x00,
963                                 InputInterface:        0x1d,
964                                 OutputInterfaceFormat: 0x00,
965                                 OutputInterface:       0x04,
966                                 RecordCount:           0x01,
967                                 Records: []SFlowRecord{
968                                         SFlowExtendedSwitchFlowRecord{
969                                                 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
970                                                         EnterpriseID:   0x0,
971                                                         Format:         SFlowTypeExtendedSwitchFlow,
972                                                         FlowDataLength: 0x10,
973                                                 },
974                                                 IncomingVLAN:         0x03,
975                                                 IncomingVLANPriority: 0x02,
976                                                 OutgoingVLAN:         0x05,
977                                                 OutgoingVLANPriority: 0xffffffff,
978                                         },
979                                 },
980                         },
981                 },
982         }
983         if !reflect.DeepEqual(want, got) {
984                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
985         }
986 }
987
988 func TestDecodeExtendedRouterFlow(t *testing.T) {
989         p := gopacket.NewPacket(SFlowTestPacket5, LayerTypeSFlow, gopacket.Default)
990
991         if p.ErrorLayer() != nil {
992                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
993         }
994         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
995
996         got := p.ApplicationLayer().(*SFlowDatagram)
997
998         want := &SFlowDatagram{
999                 DatagramVersion: uint32(5),
1000                 AgentAddress:    []byte{0xc0, 0xa8, 0x01, 0x12},
1001                 SubAgentID:      uint32(0x00),
1002                 SequenceNumber:  uint32(0x027e),
1003                 AgentUptime:     uint32(0x32e0e47c),
1004                 SampleCount:     uint32(1),
1005                 FlowSamples: []SFlowFlowSample{
1006                         SFlowFlowSample{
1007                                 Format:                SFlowTypeFlowSample,
1008                                 SampleLength:          0x34,
1009                                 SequenceNumber:        0x123,
1010                                 SourceIDClass:         0x00,
1011                                 SourceIDIndex:         0x1d,
1012                                 SamplingRate:          0x100,
1013                                 SamplePool:            0x334,
1014                                 Dropped:               0x5602,
1015                                 InputInterfaceFormat:  0x00,
1016                                 InputInterface:        0x1d,
1017                                 OutputInterfaceFormat: 0x00,
1018                                 OutputInterface:       0x04,
1019                                 RecordCount:           0x01,
1020                                 Records: []SFlowRecord{
1021                                         SFlowExtendedRouterFlowRecord{
1022                                                 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1023                                                         EnterpriseID:   0x0,
1024                                                         Format:         SFlowTypeExtendedRouterFlow,
1025                                                         FlowDataLength: 0x10,
1026                                                 },
1027                                                 NextHop:                []byte{0xc0, 0xa8, 0x01, 0x21},
1028                                                 NextHopSourceMask:      0xffffffff,
1029                                                 NextHopDestinationMask: 0xffffff80,
1030                                         },
1031                                 },
1032                         },
1033                 },
1034         }
1035         if !reflect.DeepEqual(want, got) {
1036                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
1037         }
1038 }
1039
1040 func TestDecodeExtendedRouterFlowIPv6(t *testing.T) {
1041         p := gopacket.NewPacket(SFlowTestPacket8, LayerTypeSFlow, gopacket.Default)
1042
1043         if p.ErrorLayer() != nil {
1044                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1045         }
1046         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1047
1048         got := p.ApplicationLayer().(*SFlowDatagram)
1049
1050         want := &SFlowDatagram{
1051                 DatagramVersion: uint32(5),
1052                 AgentAddress:    []byte{0xc0, 0xa8, 0x01, 0x12},
1053                 SubAgentID:      uint32(0x00),
1054                 SequenceNumber:  uint32(0x027e),
1055                 AgentUptime:     uint32(0x32e0e47c),
1056                 SampleCount:     uint32(1),
1057                 FlowSamples: []SFlowFlowSample{
1058                         SFlowFlowSample{
1059                                 Format:                SFlowTypeFlowSample,
1060                                 SampleLength:          0x34,
1061                                 SequenceNumber:        0x123,
1062                                 SourceIDClass:         0x00,
1063                                 SourceIDIndex:         0x1d,
1064                                 SamplingRate:          0x100,
1065                                 SamplePool:            0x334,
1066                                 Dropped:               0x5602,
1067                                 InputInterfaceFormat:  0x00,
1068                                 InputInterface:        0x1d,
1069                                 OutputInterfaceFormat: 0x00,
1070                                 OutputInterface:       0x04,
1071                                 RecordCount:           0x01,
1072                                 Records: []SFlowRecord{
1073                                         SFlowExtendedRouterFlowRecord{
1074                                                 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1075                                                         EnterpriseID:   0x0,
1076                                                         Format:         SFlowTypeExtendedRouterFlow,
1077                                                         FlowDataLength: 0x1c,
1078                                                 },
1079                                                 NextHop:                []byte{0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1080                                                 NextHopSourceMask:      0xffffffff,
1081                                                 NextHopDestinationMask: 0xffffff80,
1082                                         },
1083                                 },
1084                         },
1085                 },
1086         }
1087         if !reflect.DeepEqual(want, got) {
1088                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
1089         }
1090 }
1091
1092 func TestDecodeExtendedIpv4TunnelIngressFlow(t *testing.T) {
1093         p := gopacket.NewPacket(SFlowTestPacket6, LayerTypeSFlow, gopacket.Default)
1094
1095         if p.ErrorLayer() != nil {
1096                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1097         }
1098         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1099
1100         got := p.ApplicationLayer().(*SFlowDatagram)
1101
1102         want := &SFlowDatagram{
1103                 DatagramVersion: uint32(5),
1104                 AgentAddress:    []byte{0x7f, 0x0, 0x0, 0x1},
1105                 SubAgentID:      uint32(0),
1106                 SequenceNumber:  uint32(0x72),
1107                 AgentUptime:     uint32(0x1bd50),
1108                 SampleCount:     uint32(1),
1109                 FlowSamples: []SFlowFlowSample{
1110                         SFlowFlowSample{
1111                                 Format:                SFlowTypeFlowSample,
1112                                 SampleLength:          0x48,
1113                                 SequenceNumber:        0x74,
1114                                 SourceIDClass:         0x0,
1115                                 SourceIDIndex:         0x20003e8,
1116                                 SamplingRate:          0x1,
1117                                 SamplePool:            0x74,
1118                                 Dropped:               0x0,
1119                                 InputInterfaceFormat:  0x0,
1120                                 InputInterface:        0x0,
1121                                 OutputInterfaceFormat: 0x0,
1122                                 OutputInterface:       0x80000001,
1123                                 RecordCount:           0x1,
1124                                 Records: []SFlowRecord{
1125                                         SFlowExtendedIpv4TunnelIngressRecord{
1126                                                 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1127                                                         EnterpriseID:   0x0,
1128                                                         Format:         SFlowTypeExtendedIpv4TunnelIngressFlow,
1129                                                         FlowDataLength: 0x20,
1130                                                 },
1131                                                 SFlowIpv4Record: SFlowIpv4Record{
1132                                                         Length:   0x0,
1133                                                         Protocol: 0x2f,
1134                                                         IPSrc:    net.IP{0xc0, 0xa8, 0x0, 0x54},
1135                                                         IPDst:    net.IP{0xc0, 0xa8, 0x0, 0x53},
1136                                                         PortSrc:  0x0,
1137                                                         PortDst:  0x0,
1138                                                         TCPFlags: 0x0,
1139                                                         TOS:      0x0,
1140                                                 },
1141                                         },
1142                                 },
1143                         },
1144                 },
1145         }
1146         if !reflect.DeepEqual(want, got) {
1147                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
1148         }
1149 }
1150
1151 func TestDecodeExtendedIpv4TunnelEgressFlow(t *testing.T) {
1152         p := gopacket.NewPacket(SFlowTestPacket7, LayerTypeSFlow, gopacket.Default)
1153
1154         if p.ErrorLayer() != nil {
1155                 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1156         }
1157         checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1158
1159         got := p.ApplicationLayer().(*SFlowDatagram)
1160
1161         want := &SFlowDatagram{
1162                 DatagramVersion: uint32(5),
1163                 AgentAddress:    []byte{0x7f, 0x0, 0x0, 0x1},
1164                 SubAgentID:      uint32(1),
1165                 SequenceNumber:  uint32(0x12),
1166                 AgentUptime:     uint32(0x4268),
1167                 SampleCount:     uint32(1),
1168                 FlowSamples: []SFlowFlowSample{
1169                         SFlowFlowSample{
1170                                 Format:                SFlowTypeFlowSample,
1171                                 SampleLength:          0x48,
1172                                 SequenceNumber:        0x12,
1173                                 SourceIDClass:         0x0,
1174                                 SourceIDIndex:         0x20003e9,
1175                                 SamplingRate:          0x1,
1176                                 SamplePool:            0x12,
1177                                 Dropped:               0x0,
1178                                 InputInterfaceFormat:  0x0,
1179                                 InputInterface:        0x6c,
1180                                 OutputInterfaceFormat: 0x0,
1181                                 OutputInterface:       0x80000001,
1182                                 RecordCount:           0x1,
1183                                 Records: []SFlowRecord{
1184                                         SFlowExtendedIpv4TunnelEgressRecord{
1185                                                 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1186                                                         EnterpriseID:   0x0,
1187                                                         Format:         SFlowTypeExtendedIpv4TunnelEgressFlow,
1188                                                         FlowDataLength: 0x20,
1189                                                 },
1190                                                 SFlowIpv4Record: SFlowIpv4Record{
1191                                                         Length:   0x0,
1192                                                         Protocol: 0x0,
1193                                                         IPSrc:    net.IP{0x0, 0x0, 0x0, 0x0},
1194                                                         IPDst:    net.IP{0xc0, 0xa8, 0x0, 0x54},
1195                                                         PortSrc:  0x0,
1196                                                         PortDst:  0x0,
1197                                                         TCPFlags: 0x0,
1198                                                         TOS:      0x0,
1199                                                 },
1200                                         },
1201                                 },
1202                         },
1203                 },
1204         }
1205         if !reflect.DeepEqual(want, got) {
1206                 t.Errorf("SFlow layer mismatch, \nwant:\n\n%#v\ngot:\n\n\n%#v\n\n", want, got)
1207         }
1208 }
1209
1210 func BenchmarkDecodeSFlowPacket1(b *testing.B) {
1211         for i := 0; i < b.N; i++ {
1212                 gopacket.NewPacket(SFlowTestPacket1, LinkTypeEthernet, gopacket.NoCopy)
1213         }
1214 }
1215
1216 func BenchmarkDecodeSFlowPacket2(b *testing.B) {
1217         for i := 0; i < b.N; i++ {
1218                 gopacket.NewPacket(SFlowTestPacket2, LinkTypeEthernet, gopacket.NoCopy)
1219         }
1220 }
1221
1222 func BenchmarkDecodeSFlowPacket3(b *testing.B) {
1223         for i := 0; i < b.N; i++ {
1224                 gopacket.NewPacket(SFlowTestPacket3, LinkTypeEthernet, gopacket.NoCopy)
1225         }
1226 }
1227
1228 func BenchmarkDecodeSFlowPacket4(b *testing.B) {
1229         for i := 0; i < b.N; i++ {
1230                 gopacket.NewPacket(SFlowTestPacket4, LinkTypeEthernet, gopacket.NoCopy)
1231         }
1232 }
1233
1234 func BenchmarkDecodeSFlowLayerPacket1(b *testing.B) {
1235         var sflow SFlowDatagram
1236         for i := 0; i < b.N; i++ {
1237                 sflow.DecodeFromBytes(SFlowTestPacket1[ /*eth*/ 14+ /*ipv4*/ 20+ /*udp*/ 8:], gopacket.NilDecodeFeedback)
1238         }
1239 }
1240
1241 func BenchmarkDecodeSFlowLayerPacket2(b *testing.B) {
1242         var sflow SFlowDatagram
1243         for i := 0; i < b.N; i++ {
1244                 sflow.DecodeFromBytes(SFlowTestPacket2[ /*eth*/ 14+ /*ipv4*/ 20+ /*udp*/ 8:], gopacket.NilDecodeFeedback)
1245         }
1246 }