1 // Copyright 2014 Google, Inc. All rights reserved.
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
9 "github.com/google/gopacket"
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,
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,
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,
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,
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,
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,
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,
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,
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())
287 checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t)
288 if got, ok := p.TransportLayer().(*UDP); ok {
290 BaseLayer: BaseLayer{SFlowTestPacket1[34:42], SFlowTestPacket1[42:]},
291 sPort: []byte{199, 87},
292 dPort: []byte{24, 199},
298 if !reflect.DeepEqual(want, got) {
299 t.Errorf("UDP layer mismatch, \nwant %#v\ngot %#v\n", want, got)
302 t.Error("Transport layer packet not UDP")
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())
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{
325 SequenceNumber: 0x2627e8,
327 SourceIDIndex: 0x213,
328 SamplingRate: 0x3e80,
329 SamplePool: 0x50bde580,
331 InputInterface: 0x213,
332 OutputInterface: 0x0,
334 Records: []SFlowRecord{
335 SFlowRawPacketFlowRecord{
336 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
339 FlowDataLength: 0x90,
345 Header: gopacket.NewPacket(SFlowTestPacket1[134:262], LayerTypeEthernet, gopacket.Default),
347 SFlowExtendedSwitchFlowRecord{
348 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
351 FlowDataLength: 0x10,
354 IncomingVLANPriority: 0x0,
356 OutgoingVLANPriority: 0x0,
364 SequenceNumber: 0x15e5c1e,
366 SourceIDIndex: 0x257,
368 SamplePool: 0xb12fa290,
370 InputInterface: 0x257,
371 OutputInterface: 0x0,
373 Records: []SFlowRecord{
374 SFlowRawPacketFlowRecord{
375 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
378 FlowDataLength: 0x90,
384 Header: gopacket.NewPacket(SFlowTestPacket1[350:478], LayerTypeEthernet, gopacket.Default),
386 SFlowExtendedSwitchFlowRecord{
387 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
390 FlowDataLength: 0x10,
393 IncomingVLANPriority: 0x0,
395 OutgoingVLANPriority: 0x0,
403 SequenceNumber: 0x15acdd0,
405 SourceIDIndex: 0x255,
407 SamplePool: 0x9567e130,
409 InputInterface: 0x255,
410 OutputInterface: 0x0,
412 Records: []SFlowRecord{
413 SFlowRawPacketFlowRecord{
414 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
417 FlowDataLength: 0x90,
423 Header: gopacket.NewPacket(SFlowTestPacket1[566:694], LayerTypeEthernet, gopacket.Default),
425 SFlowExtendedSwitchFlowRecord{
426 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
429 FlowDataLength: 0x10,
432 IncomingVLANPriority: 0x0,
434 OutgoingVLANPriority: 0x0,
442 SequenceNumber: 0x15e5c1f,
444 SourceIDIndex: 0x257,
446 SamplePool: 0xb12faa60,
448 InputInterface: 0x257,
449 OutputInterface: 0x0,
451 Records: []SFlowRecord{
452 SFlowRawPacketFlowRecord{
453 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
456 FlowDataLength: 0x90,
462 Header: gopacket.NewPacket(SFlowTestPacket1[958:1086], LayerTypeEthernet, gopacket.Default),
464 SFlowExtendedSwitchFlowRecord{
465 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
468 FlowDataLength: 0x10,
471 IncomingVLANPriority: 0x0,
473 OutgoingVLANPriority: 0x0,
481 SequenceNumber: 0x15acdd1,
483 SourceIDIndex: 0x255,
485 SamplePool: 0x9567e900,
487 InputInterface: 0x255,
488 OutputInterface: 0x257,
490 Records: []SFlowRecord{
491 SFlowRawPacketFlowRecord{
492 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
495 FlowDataLength: 0x90,
501 Header: gopacket.NewPacket(SFlowTestPacket1[1174:1302], LayerTypeEthernet, gopacket.Default),
503 SFlowExtendedSwitchFlowRecord{
504 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
507 FlowDataLength: 0x10,
510 IncomingVLANPriority: 0x0,
512 OutgoingVLANPriority: 0x0,
520 SequenceNumber: 0x15e5c20,
522 SourceIDIndex: 0x257,
524 SamplePool: 0xb12fb230,
526 InputInterface: 0x257,
527 OutputInterface: 0x0,
529 Records: []SFlowRecord{
530 SFlowRawPacketFlowRecord{
531 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
534 FlowDataLength: 0x54,
540 Header: gopacket.NewPacket(SFlowTestPacket1[1390:1458], LayerTypeEthernet, gopacket.Default),
542 SFlowExtendedSwitchFlowRecord{
543 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
546 FlowDataLength: 0x10,
549 IncomingVLANPriority: 0x0,
551 OutgoingVLANPriority: 0x0,
556 CounterSamples: []SFlowCounterSample{
560 SequenceNumber: 0x20f2,
562 SourceIDIndex: 0x20a,
564 Records: []SFlowRecord{
565 SFlowGenericInterfaceCounters{
566 SFlowBaseCounterRecord: SFlowBaseCounterRecord{
569 FlowDataLength: 0x58,
573 IfSpeed: 0x2540be400,
576 IfInOctets: 0x129826db06c0b,
577 IfInUcastPkts: 0xcb0ddd96,
578 IfInMulticastPkts: 0x6a8c6,
579 IfInBroadcastPkts: 0x7b,
582 IfInUnknownProtos: 0x0,
583 IfOutOctets: 0x340235587c9e,
584 IfOutUcastPkts: 0x56642571,
585 IfOutMulticastPkts: 0x705ac4,
586 IfOutBroadcastPkts: 0x908f1,
589 IfPromiscuousMode: 0x0,
591 SFlowEthernetCounters{
592 SFlowBaseCounterRecord: SFlowBaseCounterRecord{
595 FlowDataLength: 0x34,
597 AlignmentErrors: 0x0,
599 SingleCollisionFrames: 0x0,
600 MultipleCollisionFrames: 0x0,
602 DeferredTransmissions: 0x0,
604 ExcessiveCollisions: 0x0,
605 InternalMacTransmitErrors: 0x0,
606 CarrierSenseErrors: 0x0,
608 InternalMacReceiveErrors: 0x0,
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)
619 t.Error("Application layer packet not UDP")
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())
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{
642 SequenceNumber: 139118,
649 OutputInterface: 1073741823,
651 Records: []SFlowRecord{
652 SFlowExtendedURLRecord{
653 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
658 Direction: SFlowURLsrc,
659 URL: "http://www.sflow.org",
660 Host: "host1.sflow.org",
662 SFlowExtendedUserFlow{
663 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
668 SourceCharSet: SFlowCSUTF8,
669 SourceUserID: "source user",
670 DestinationCharSet: SFlowCSUTF8,
671 DestinationUserID: "destination user",
673 SFlowExtendedGatewayFlowRecord{
674 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
679 NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a},
684 ASPath: []SFlowASDestination{
686 Type: SFlowASSequence,
688 Members: []uint32{123, 456, 789},
693 Members: []uint32{11111, 22222, 33333},
696 Type: SFlowASSequence,
698 Members: []uint32{777, 888, 999},
701 Communities: []uint32{12, 13},
704 SFlowRawPacketFlowRecord{
705 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
714 Header: gopacket.NewPacket(SFlowTestPacket2[350:418], LayerTypeEthernet, gopacket.Default),
722 SequenceNumber: 139119,
728 InputInterface: 1073741823,
731 Records: []SFlowRecord{
732 SFlowExtendedURLRecord{
733 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
738 Direction: SFlowURLsrc,
739 URL: "http://www.sflow.org",
740 Host: "host1.sflow.org",
742 SFlowExtendedUserFlow{
743 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
748 SourceCharSet: SFlowCSUTF8,
749 SourceUserID: "source user",
750 DestinationCharSet: SFlowCSUTF8,
751 DestinationUserID: "destination user",
753 SFlowExtendedGatewayFlowRecord{
754 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
759 NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a},
764 ASPath: []SFlowASDestination{
766 Type: SFlowASSequence,
768 Members: []uint32{123, 456, 789},
773 Members: []uint32{11111, 22222, 33333},
776 Type: SFlowASSequence,
778 Members: []uint32{777, 888, 999},
781 Communities: []uint32{12, 13},
784 SFlowRawPacketFlowRecord{
785 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
794 Header: gopacket.NewPacket(SFlowTestPacket2[698:826], LayerTypeEthernet, gopacket.Default),
802 SequenceNumber: 139120,
809 OutputInterface: 1073741823,
811 Records: []SFlowRecord{
812 SFlowExtendedURLRecord{
813 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
818 Direction: SFlowURLsrc,
819 URL: "http://www.sflow.org",
820 Host: "host1.sflow.org",
822 SFlowExtendedUserFlow{
823 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
828 SourceCharSet: SFlowCSUTF8,
829 SourceUserID: "source user",
830 DestinationCharSet: SFlowCSUTF8,
831 DestinationUserID: "destination user",
833 SFlowExtendedGatewayFlowRecord{
834 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
839 NextHop: []byte{0x0d, 0x0c, 0x0b, 0x0a},
844 ASPath: []SFlowASDestination{
846 Type: SFlowASSequence,
848 Members: []uint32{123, 456, 789},
853 Members: []uint32{11111, 22222, 33333},
856 Type: SFlowASSequence,
858 Members: []uint32{777, 888, 999},
861 Communities: []uint32{12, 13},
864 SFlowRawPacketFlowRecord{
865 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
874 Header: gopacket.NewPacket(SFlowTestPacket2[1106:1174], LayerTypeEthernet, gopacket.Default),
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)
884 t.Error("Application layer packet not UDP")
888 func TestDecodeProcessorCounter(t *testing.T) {
889 p := gopacket.NewPacket(SFlowTestPacket3, LayerTypeSFlow, gopacket.Default)
891 if p.ErrorLayer() != nil {
892 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
894 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
896 got := p.ApplicationLayer().(*SFlowDatagram)
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{
907 Format: SFlowTypeExpandedCounterSample,
909 SequenceNumber: 0x0178e0,
913 Records: []SFlowRecord{
914 SFlowProcessorCounters{
915 SFlowBaseCounterRecord: SFlowBaseCounterRecord{
917 Format: SFlowTypeProcessorCounters,
918 FlowDataLength: 0x1c,
923 TotalMemory: 0xe78d7000,
924 FreeMemory: 0x55e77000,
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)
935 func TestDecodeExtendedSwitchFlow(t *testing.T) {
936 p := gopacket.NewPacket(SFlowTestPacket4, LayerTypeSFlow, gopacket.Default)
938 if p.ErrorLayer() != nil {
939 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
941 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
943 got := p.ApplicationLayer().(*SFlowDatagram)
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{
954 Format: SFlowTypeFlowSample,
956 SequenceNumber: 0x123,
962 InputInterfaceFormat: 0x00,
963 InputInterface: 0x1d,
964 OutputInterfaceFormat: 0x00,
965 OutputInterface: 0x04,
967 Records: []SFlowRecord{
968 SFlowExtendedSwitchFlowRecord{
969 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
971 Format: SFlowTypeExtendedSwitchFlow,
972 FlowDataLength: 0x10,
975 IncomingVLANPriority: 0x02,
977 OutgoingVLANPriority: 0xffffffff,
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)
988 func TestDecodeExtendedRouterFlow(t *testing.T) {
989 p := gopacket.NewPacket(SFlowTestPacket5, LayerTypeSFlow, gopacket.Default)
991 if p.ErrorLayer() != nil {
992 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
994 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
996 got := p.ApplicationLayer().(*SFlowDatagram)
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{
1007 Format: SFlowTypeFlowSample,
1009 SequenceNumber: 0x123,
1010 SourceIDClass: 0x00,
1011 SourceIDIndex: 0x1d,
1012 SamplingRate: 0x100,
1015 InputInterfaceFormat: 0x00,
1016 InputInterface: 0x1d,
1017 OutputInterfaceFormat: 0x00,
1018 OutputInterface: 0x04,
1020 Records: []SFlowRecord{
1021 SFlowExtendedRouterFlowRecord{
1022 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1024 Format: SFlowTypeExtendedRouterFlow,
1025 FlowDataLength: 0x10,
1027 NextHop: []byte{0xc0, 0xa8, 0x01, 0x21},
1028 NextHopSourceMask: 0xffffffff,
1029 NextHopDestinationMask: 0xffffff80,
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)
1040 func TestDecodeExtendedRouterFlowIPv6(t *testing.T) {
1041 p := gopacket.NewPacket(SFlowTestPacket8, LayerTypeSFlow, gopacket.Default)
1043 if p.ErrorLayer() != nil {
1044 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1046 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1048 got := p.ApplicationLayer().(*SFlowDatagram)
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{
1059 Format: SFlowTypeFlowSample,
1061 SequenceNumber: 0x123,
1062 SourceIDClass: 0x00,
1063 SourceIDIndex: 0x1d,
1064 SamplingRate: 0x100,
1067 InputInterfaceFormat: 0x00,
1068 InputInterface: 0x1d,
1069 OutputInterfaceFormat: 0x00,
1070 OutputInterface: 0x04,
1072 Records: []SFlowRecord{
1073 SFlowExtendedRouterFlowRecord{
1074 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1076 Format: SFlowTypeExtendedRouterFlow,
1077 FlowDataLength: 0x1c,
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,
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)
1092 func TestDecodeExtendedIpv4TunnelIngressFlow(t *testing.T) {
1093 p := gopacket.NewPacket(SFlowTestPacket6, LayerTypeSFlow, gopacket.Default)
1095 if p.ErrorLayer() != nil {
1096 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1098 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1100 got := p.ApplicationLayer().(*SFlowDatagram)
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{
1111 Format: SFlowTypeFlowSample,
1113 SequenceNumber: 0x74,
1115 SourceIDIndex: 0x20003e8,
1119 InputInterfaceFormat: 0x0,
1120 InputInterface: 0x0,
1121 OutputInterfaceFormat: 0x0,
1122 OutputInterface: 0x80000001,
1124 Records: []SFlowRecord{
1125 SFlowExtendedIpv4TunnelIngressRecord{
1126 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1128 Format: SFlowTypeExtendedIpv4TunnelIngressFlow,
1129 FlowDataLength: 0x20,
1131 SFlowIpv4Record: SFlowIpv4Record{
1134 IPSrc: net.IP{0xc0, 0xa8, 0x0, 0x54},
1135 IPDst: net.IP{0xc0, 0xa8, 0x0, 0x53},
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)
1151 func TestDecodeExtendedIpv4TunnelEgressFlow(t *testing.T) {
1152 p := gopacket.NewPacket(SFlowTestPacket7, LayerTypeSFlow, gopacket.Default)
1154 if p.ErrorLayer() != nil {
1155 t.Error("Failed to decode packet:", p.ErrorLayer().Error())
1157 checkLayers(p, []gopacket.LayerType{LayerTypeSFlow}, t)
1159 got := p.ApplicationLayer().(*SFlowDatagram)
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{
1170 Format: SFlowTypeFlowSample,
1172 SequenceNumber: 0x12,
1174 SourceIDIndex: 0x20003e9,
1178 InputInterfaceFormat: 0x0,
1179 InputInterface: 0x6c,
1180 OutputInterfaceFormat: 0x0,
1181 OutputInterface: 0x80000001,
1183 Records: []SFlowRecord{
1184 SFlowExtendedIpv4TunnelEgressRecord{
1185 SFlowBaseFlowRecord: SFlowBaseFlowRecord{
1187 Format: SFlowTypeExtendedIpv4TunnelEgressFlow,
1188 FlowDataLength: 0x20,
1190 SFlowIpv4Record: SFlowIpv4Record{
1193 IPSrc: net.IP{0x0, 0x0, 0x0, 0x0},
1194 IPDst: net.IP{0xc0, 0xa8, 0x0, 0x54},
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)
1210 func BenchmarkDecodeSFlowPacket1(b *testing.B) {
1211 for i := 0; i < b.N; i++ {
1212 gopacket.NewPacket(SFlowTestPacket1, LinkTypeEthernet, gopacket.NoCopy)
1216 func BenchmarkDecodeSFlowPacket2(b *testing.B) {
1217 for i := 0; i < b.N; i++ {
1218 gopacket.NewPacket(SFlowTestPacket2, LinkTypeEthernet, gopacket.NoCopy)
1222 func BenchmarkDecodeSFlowPacket3(b *testing.B) {
1223 for i := 0; i < b.N; i++ {
1224 gopacket.NewPacket(SFlowTestPacket3, LinkTypeEthernet, gopacket.NoCopy)
1228 func BenchmarkDecodeSFlowPacket4(b *testing.B) {
1229 for i := 0; i < b.N; i++ {
1230 gopacket.NewPacket(SFlowTestPacket4, LinkTypeEthernet, gopacket.NoCopy)
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)
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)