• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) PLUMgrid, Inc.
2// Licensed under the Apache License, Version 2.0 (the "License")
3struct IPKey {
4  u32 dip:32;
5  u32 sip:32;
6};
7struct IPLeaf {
8  u32 rx_pkts:64;
9  u32 tx_pkts:64;
10};
11Table<IPKey, IPLeaf, FIXED_MATCH, AUTO> stats(1024);
12
13struct skbuff {
14  u32 type:32;
15};
16
17u32 on_packet(struct skbuff *skb) {
18  u32 ret:32 = 0;
19
20  goto proto::ethernet;
21
22  state proto::ethernet {
23  }
24
25  state proto::dot1q {
26  }
27
28  state proto::ip {
29    u32 rx:32 = 0;
30    u32 tx:32 = 0;
31    u32 IPKey key;
32    if $ip.dst > $ip.src {
33      key.dip = $ip.dst;
34      key.sip = $ip.src;
35      rx = 1;
36      // test arbitrary return stmt
37      if false {
38        return 3;
39      }
40    } else {
41      key.dip = $ip.src;
42      key.sip = $ip.dst;
43      tx = 1;
44      ret = 1;
45    }
46    struct IPLeaf *leaf;
47    leaf = stats[key];
48    on_valid(leaf) {
49      atomic_add(leaf.rx_pkts, rx);
50      atomic_add(leaf.tx_pkts, tx);
51    }
52  }
53
54  state proto::udp {
55  }
56
57  state proto::vxlan {
58  }
59
60  state proto::gre {
61  }
62
63  state EOP {
64    return ret;
65  }
66}
67