18#ifndef CLICK_FLOWRULEMANAGER_H
19#define CLICK_FLOWRULEMANAGER_H
22#include <click/hashmap.hh>
24#include <click/dpdkdevice.hh>
25#if RTE_VERSION >= RTE_VERSION_NUM(20,2,0,0)
26 #include <click/flowrulecache.hh>
27 #include <click/flowruleparser.hh>
35#if RTE_VERSION >= RTE_VERSION_NUM(20,2,0,0)
41 RuleTiming(portid_t pt_id) : port_id(pt_id) {
53 void update(
const uint32_t &rules_nb) {
54 this->rules_nb = rules_nb;
55 this->latency_ms = (float) (end - start).
usecval() / (float) 1000;
56 this->rules_per_sec = (rules_nb > 0) ? (
float) (rules_nb * 1000) / this->latency_ms : 0;
60class FlowRuleManager {
67 static String DISPATCHING_MODE;
70 static String FLOW_RULE_ADD;
71 static String FLOW_RULE_DEL;
72 static String FLOW_RULE_IDS_GLB;
73 static String FLOW_RULE_IDS_INT;
74 static String FLOW_RULE_PACKET_HITS;
75 static String FLOW_RULE_BYTE_COUNT;
76 static String FLOW_RULE_AGGR_STATS;
77 static String FLOW_RULE_LIST;
78 static String FLOW_RULE_LIST_WITH_HITS;
79 static String FLOW_RULE_COUNT;
80 static String FLOW_RULE_COUNT_WITH_HITS;
81 static String FLOW_RULE_ISOLATE;
82 static String FLOW_RULE_FLUSH;
85 static bool DEF_VERBOSITY;
86 static bool DEF_DEBUG_MODE;
89 static HashMap<int, String> flow_item;
92 static HashMap<int, String> flow_action;
101 static void clean_flow_rule_manager_map();
104 static FlowRuleManager *get_flow_rule_mgr(
const portid_t &port_id,
ErrorHandler *errh = NULL);
107 static struct cmdline *flow_rule_parser(
ErrorHandler *errh);
113 inline void delete_error_handler() {
if (_errh)
delete _errh; };
116 inline void set_port_id(
const portid_t &port_id) {
119 inline portid_t get_port_id() {
return _port_id; };
122 inline void set_active(
const bool &active) {
125 inline bool active() {
return _active; };
128 inline void set_verbose(
const bool &verbose) {
131 inline bool verbose() {
return _verbose; };
133 inline void set_debug_mode(
const bool &debug_mode) {
134 _debug_mode = debug_mode;
136 inline bool debug_mode() {
return _debug_mode; };
139 inline void set_rules_filename(
const String &file) {
140 _rules_filename = file;
142 inline String rules_filename() {
return _rules_filename; };
145 void flow_rule_cache_calibrate(
const uint32_t *int_rule_ids,
const uint32_t &rules_nb);
146 void flow_rule_cache_calibrate(
const HashMap<uint32_t, String> &rules_map);
149 int32_t flow_rules_add_from_file(
const String &filename);
152 int32_t flow_rules_update(
const HashMap<uint32_t, String> &rules_map,
bool by_controller =
true,
int core_id = -1);
155 String flow_rules_from_file_to_string(
const String &filename);
158 int flow_rules_install(
const String &rules,
const uint32_t &rules_nb,
const bool verbose=
true);
159 int flow_rule_install(
160 const uint32_t &int_rule_id,
const uint32_t &rule_id,
161 const int &core_id,
const String &rule,
162 const bool with_cache =
true,
163 const bool verbose=
true
169 int flow_rules_verify_absence(
const Vector<uint32_t> &old_int_rule_ids_vec);
172 struct port_flow *flow_rule_get(
const uint32_t &int_rule_id);
175 int32_t flow_rules_delete(
const Vector<uint32_t> &old_int_rule_ids_vec,
const bool with_cache =
true);
176 int32_t flow_rules_delete(uint32_t *int_rule_ids,
const uint32_t &rules_nb,
const bool with_cache =
true);
179 String flow_rule_query(
const uint32_t &int_rule_id, int64_t &matched_pkts, int64_t &matched_bytes);
182 String flow_rule_aggregate_stats();
185 uint32_t flow_rules_with_hits_count();
188 uint32_t flow_rules_count();
191 uint32_t flow_rules_count_explicit();
194 void nic_and_cache_counts_agree();
197 String flow_rules_list(
const bool only_matching_rules =
false);
200 String flow_rule_ids_internal_counters();
201 String flow_rule_ids_internal_cache();
202 String flow_rule_ids_internal_nic();
203 String flow_rule_ids_internal(
const bool from_nic =
true);
204 String flow_rule_ids_global();
207 uint32_t flow_rules_flush();
210 void flow_rule_consistency_check(
const int32_t &target_number_of_rules);
213 static bool flow_rule_filter(
String &rule);
216 static String fetch_token_after_keyword(
char *rule,
const String &keyword);
219 void min_avg_max(
float &min,
float &mean,
float &max,
const bool install =
true,
const bool latency =
true);
222 static inline void add_rule_inst_stats(
const RuleTiming &rits) {
224 if (!rule_stats_vec) {
227 _rule_inst_stats_map.insert(rits.port_id, new_vec);
232 static inline void add_rule_del_stats(
const RuleTiming &rdts) {
234 if (!rule_stats_vec) {
237 _rule_del_stats_map.insert(rdts.port_id, new_vec);
264 static HashMap<portid_t, bool> _isolated;
267 static struct cmdline *_parser;
270 static HashMap<portid_t, Vector<RuleTiming>> _rule_inst_stats_map;
271 static HashMap<portid_t, Vector<RuleTiming>> _rule_del_stats_map;
274 static int flow_rules_isolate(
const portid_t &port_id,
const int &set);
277 void populate_supported_flow_items_and_actions();
280 void flow_rules_sort(
struct rte_port *port,
struct port_flow **sorted_rules);
283 void nic_consistency_check(
const int32_t &target_number_of_rules);
Error reporting class.
Definition error.hh:90
Base class for ErrorHandlers that forward messages.
Definition error.hh:618
Definition flowrulecache.hh:32
Hash table template.
Definition hashtable.hh:570
A string of characters.
Definition string.hh:22
Represents a moment or interval in time.
Definition timestamp.hh:125
value_type usecval() const
Return this timestamp's interval length in microseconds.
Definition timestamp.hh:281
Vector template.
Definition vector.hh:111
void push_back(value_argument_type v)
Append element v.
Definition vector.hh:399
Flexible error handling classes.
Click's hash table container template.