P4C
The P4 Compiler
Loading...
Searching...
No Matches
p4_table.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_P4_TABLE_H_
19#define BACKENDS_TOFINO_BF_ASM_P4_TABLE_H_
20
21#include <map>
22#include <string>
23
24#include "asm-types.h"
25#include "backends/tofino/bf-asm/json.h"
26
27class Table;
28class P4Table;
29
30struct alpm_t {
31 std::string partition_field_name = "";
32 unsigned alpm_atcam_table_handle = 0;
33 unsigned alpm_pre_classifier_table_handle = 0;
34 std::set<unsigned> set_partition_action_handle;
35 json::map *alpm_atcam_table_cfg = 0; // handle to cjson alpm table
36 json::map *alpm_pre_classifier_table_cfg = 0; // handle to cjson ternary pre classifier table
37};
38
39class P4Table {
40 int lineno = -1;
41 std::string name, preferred_match_type;
42 std::string stage_table_type;
43 unsigned handle = 0;
44 bool explicit_size = false;
45 bool hidden = false;
46 json::map *config = 0;
47 P4Table() {}
48
49 public:
50 bool disable_atomic_modify = false;
51 unsigned size = 0;
52 std::string match_type, action_profile, how_referenced;
53 enum type {
54 None = 0,
55 MatchEntry = 1,
56 ActionData = 2,
57 Selection = 3,
58 Statistics = 4,
59 Meter = 5,
60 Stateful = 6,
61 NUM_TABLE_TYPES = 7
62 };
63 enum alpm_type { PreClassifier = 1, Atcam = 2 };
64 static const char *type_name[];
65
66 private:
67 static std::map<unsigned, P4Table *> by_handle;
68 static std::map<type, std::map<std::string, P4Table *>> by_name;
69 static unsigned max_handle[];
70
71 public:
72 static P4Table *get(type t, VECTOR(pair_t) & d);
73 static P4Table *alloc(type t, Table *tbl);
74 void check(Table *tbl);
75 const char *p4_name() const { return name.empty() ? nullptr : name.c_str(); }
76 unsigned get_handle() { return handle; }
77 unsigned p4_size() { return size; }
78 std::string p4_stage_table_type() { return stage_table_type; }
79 json::map *base_tbl_cfg(json::vector &out, int size, const Table *table) const;
80 void base_alpm_tbl_cfg(json::map &out, int size, const Table *table,
81 P4Table::alpm_type atype) const;
82 bool is_alpm() const {
83 if (match_type == "alpm") return true;
84 return false;
85 }
86 void set_partition_action_handle(unsigned handle);
87 void set_partition_field_name(std::string name);
88 std::string get_partition_field_name() const;
89 std::set<unsigned> get_partition_action_handle() const;
90 unsigned get_alpm_atcam_table_handle() const;
91 static std::string direction_name(gress_t);
92};
93
94#endif /* BACKENDS_TOFINO_BF_ASM_P4_TABLE_H_ */
Definition p4_table.h:39
Definition tables.h:98
Definition backends/tofino/bf-asm/json.h:300
Definition backends/tofino/bf-asm/json.h:222
Definition action_format.cpp:30
Definition p4_table.h:30
Definition asm-types.h:150