File: test_stat1.b

package info (click to toggle)
bpfcc 0.18.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,368 kB
  • sloc: ansic: 132,727; python: 36,226; cpp: 26,973; sh: 710; yacc: 525; makefile: 141; lex: 94
file content (66 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (2)
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;
  }
}