forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stat1.b
More file actions
66 lines (56 loc) · 1.02 KB
/
test_stat1.b
File metadata and controls
66 lines (56 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) PLUMgrid, Inc.
// Licensed under the Apache License, Version 2.0 (the "License")
struct IPKey {
u32 dip:32;
u32 sip:32;
};
struct IPLeaf {
u32 rx_pkts:64;
u32 tx_pkts:64;
};
Table<IPKey, IPLeaf, FIXED_MATCH, AUTO> stats(1024);
struct skbuff {
u32 type:32;
};
u32 on_packet(struct skbuff *skb) {
u32 ret:32 = 0;
goto proto::ethernet;
state proto::ethernet {
}
state proto::dot1q {
}
state proto::ip {
u32 rx:32 = 0;
u32 tx:32 = 0;
u32 IPKey key;
if $ip.dst > $ip.src {
key.dip = $ip.dst;
key.sip = $ip.src;
rx = 1;
// test arbitrary return stmt
if false {
return 3;
}
} else {
key.dip = $ip.src;
key.sip = $ip.dst;
tx = 1;
ret = 1;
}
struct IPLeaf *leaf;
leaf = stats[key];
on_valid(leaf) {
atomic_add(leaf.rx_pkts, rx);
atomic_add(leaf.tx_pkts, tx);
}
}
state proto::udp {
}
state proto::vxlan {
}
state proto::gre {
}
state EOP {
return ret;
}
}