1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use community::Community;
use dst_as_path;
use error;
use ipaddress;
use types::ReadSeeker;
use utils::ReadBytesLocal;
use std::io::SeekFrom;
#[derive(Debug, Clone)]
pub enum FlowRecord {
SampledHeader(SampledHeader),
SampledIpv4(SampledIpv4),
ExtendedSwitch(ExtendedSwitch),
ExtendedRouter(ExtendedRouter),
ExtendedGateway(ExtendedGateway),
ExtendedUrl(ExtendedUrl),
ExtendedMpls(ExtendedMpls),
ExtendedMplsTunnel(ExtendedMplsTunnel),
}
impl ::utils::Decodeable for FlowRecord {
fn read_and_decode(stream: &mut ReadSeeker) -> Result<FlowRecord, error::Error> {
let format = try!(stream.be_read_u32());
let length = try!(stream.be_read_u32());
match format {
1 => {
let e = try!(SampledHeader::read_and_decode(stream));
return Ok(FlowRecord::SampledHeader(e));
}
3 => {
let e = try!(SampledIpv4::read_and_decode(stream));
return Ok(FlowRecord::SampledIpv4(e));
}
1001 => {
let e = try!(ExtendedSwitch::read_and_decode(stream));
return Ok(FlowRecord::ExtendedSwitch(e));
}
1002 => {
let e = try!(ExtendedRouter::read_and_decode(stream));
return Ok(FlowRecord::ExtendedRouter(e));
}
1003 => {
let e = try!(ExtendedGateway::read_and_decode(stream));
return Ok(FlowRecord::ExtendedGateway(e));
}
1005 => {
let e = try!(ExtendedUrl::read_and_decode(stream));
return Ok(FlowRecord::ExtendedUrl(e));
}
1006 => {
let e = try!(ExtendedMpls::read_and_decode(stream));
return Ok(FlowRecord::ExtendedMpls(e));
}
1008 => {
let e = try!(ExtendedMplsTunnel::read_and_decode(stream));
return Ok(FlowRecord::ExtendedMplsTunnel(e));
}
_ => {
println!("DEBUG: Unknown FlowRecord type {0} skipping {1} bytes.",
format,
length);
try!(stream.seek(SeekFrom::Current(length as i64)));
return Err(error::Error::UnknownType(format!("Unknown FlowRecord type {0} \
skipping {1} bytes.",
format,
length)));
}
}
}
}
add_decoder!{
#[derive(Debug, Clone, Default)]
pub struct ExtendedGateway {
pub next_hop: ipaddress::IPAddress,
pub asn: u32,
pub src_as: u32,
pub src_peer_as: u32,
pub dst_as_path: Vec<dst_as_path::DstASPath>,
pub communities: Vec<Community>,
pub localpref: u32,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct ExtendedUrl {
pub directoin: u32,
pub url: String,
pub host: String,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct SampledIpv4 {
pub length: u32,
pub protocol: u32,
pub src_ip: ipaddress::IPAddress,
pub dst_ip: ipaddress::IPAddress,
pub src_port: u32,
pub dst_port: u32,
pub tcp_flags: u32,
pub tos: u32,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct ExtendedSwitch {
pub src_vlan: u32,
pub src_priority: u32,
pub dst_vlan: u32,
pub dst_priority: u32,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct ExtendedRouter {
pub nexthop: ipaddress::IPAddress,
pub src_mask_len: u32,
pub dst_mask_len: u32,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct SampledHeader {
pub protocol: u32,
pub frame_length: u32,
pub stripped: u32,
pub header: Vec<u8>,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct ExtendedMplsTunnel {
pub tunnel_lsp_name: String,
pub tunnel_id: u32,
pub tunnel_cos: u32,
}
}
add_decoder!{
#[derive(Debug, Clone)]
pub struct ExtendedMpls {
pub nexthop: ipaddress::IPAddress,
pub in_stack: Vec<i32>,
pub out_stack: Vec<i32>,
}
}