1#ifndef CLICK_FLOWLEVEL_HH
2#define CLICK_FLOWLEVEL_HH 1
9#define FLOW_LEVEL_DEFINE(T,fnt) \
10 static FlowNodeData get_data_ptr(void* thunk, Packet* p) {\
11 return static_cast<T*>(thunk)->fnt(p);\
22 FlowControlBlock* leaf;
26 FlowNodePtr() : _is_leaf(false), ptr(0) {
30 FlowNodePtr(FlowNode* n) : _is_leaf(false), node(n) {
34 FlowNodePtr(FlowControlBlock* sfcb) : _is_leaf(true), leaf(sfcb) {
38 inline FlowNodeData data();
40 inline FlowNode* parent()
const;
42 inline void set_data(FlowNodeData data);
44 inline void set_parent(FlowNode* parent);
46 inline void set_leaf(FlowControlBlock* l) {
51 inline void set_node(FlowNode* n) {
57 inline bool is_leaf()
const {
61 inline bool is_node()
const {
73 void print(
int data_offset = -1)
const;
83 inline void traverse_all_leaves(std::function<
void(FlowNodePtr*)>);
87 bool replace_leaf_with_node(FlowNode*,
bool discard,
Element* origin);
89 void node_combine_ptr(FlowNode* parent, FlowNodePtr,
bool as_child,
bool priority,
bool no_dynamic,
Element* origin);
90 void default_combine(FlowNode* parent, FlowNodePtr*,
bool as_child,
bool priority,
Element* origin);
100#if HAVE_LONG_CLASSIFICATION
101 bool _islong =
false;
110 typedef FlowNodeData (*GetDataFn)(
void*,
Packet* packet);
113 virtual ~FlowLevel() {};
120 virtual long unsigned get_max_value() = 0;
122 virtual void add_offset(
int offset) {};
124 virtual bool is_mt_safe()
const {
return false;};
126 virtual bool is_usefull() {
135 virtual bool prune(FlowLevel*) {
return false;};
137 virtual FlowNodePtr prune(FlowLevel* other, FlowNodeData data, FlowNode* node,
bool &changed);
144 virtual bool equals(FlowLevel* level) {
145 return typeid(*this) ==
typeid(*level) &&
146#if HAVE_LONG_CLASSIFICATION
147 _islong == level->_islong &&
149 _dynamic == level->_dynamic;
152 inline FlowNodeData get_data(
Packet* p) {
153 flow_assert(_get_data);
155 return _get_data(
this,p);
158 int current_level = 0;
160 FlowNode* create_node(FlowNode* parent,
bool better,
bool better_impl);
174 virtual String print() = 0;
175#if HAVE_LONG_CLASSIFICATION
176 inline bool is_long()
const {
180 inline bool is_long()
const {
184 FlowLevel* assign(FlowLevel* l) {
185 _dynamic = l->_dynamic;
187#if HAVE_LONG_CLASSIFICATION
188 _islong = l->_islong;
193 virtual FlowLevel *duplicate() = 0;
195 virtual FlowLevel *optimize(FlowNode*) {
200 virtual int to_dpdk_flow(FlowNodeData data, rte_flow_item_type last_layer,
int offset, rte_flow_item_type &next_layer,
int &next_layer_offset,
Vector<rte_flow_item> &pattern,
bool is_default) {
215 _get_data = &get_data_ptr;
219 inline long unsigned get_max_value() {
223 inline FlowNodeData get_data_dummy(
Packet* packet) {
226 return FlowNodeData();
233 FlowLevel* duplicate()
override {
238 virtual int to_dpdk_flow(FlowNodeData data, rte_flow_item_type last_layer,
int offset, rte_flow_item_type &next_layer,
int &next_layer_offset,
Vector<rte_flow_item> &pattern,
bool is_default)
override {
240 pat.type = RTE_FLOW_ITEM_TYPE_VOID;
241 next_layer = last_layer;
242 next_layer_offset = offset;
257 _get_data = &get_data_ptr;
261 _get_data = &get_data_ptr;
269 inline long unsigned get_max_value() {
273 inline FlowNodeData get_data_agg(
Packet* packet) {
275 data.data_32 = (AGGREGATE_ANNO(packet) >> offset) & mask;
283 FlowLevel* duplicate()
override {
296 _get_data = &get_data_ptr;
300 virtual bool is_mt_safe()
const override {
return true;};
301 inline long unsigned get_max_value() {
302 return _numthreads - 1;
305 inline FlowNodeData get_data_thread(
Packet*) {
306 return FlowNodeData((uint32_t)click_current_cpu_id());
313 FlowLevel* duplicate()
override {
318class FlowLevelOffset :
public FlowLevel {
324 FlowLevelOffset(
int offset) : _offset(offset) {
327 FlowLevelOffset() : FlowLevelOffset(0) {
331 void add_offset(
int offset) {
339 virtual int mask_size()
const = 0;
341 virtual uint8_t get_mask(
int o)
const = 0;
343 bool equals(FlowLevel* level) {
344 return ((FlowLevel::equals(level))&& (_offset ==
dynamic_cast<FlowLevelOffset*
>(level)->_offset));
348 virtual int to_dpdk_flow(FlowNodeData data, rte_flow_item_type last_layer,
int offset, rte_flow_item_type &next_layer,
int &next_layer_offset,
Vector<rte_flow_item> &pattern,
bool is_default)
override;
352static const char hex[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F',
'F'};
363 FlowLevelGeneric(T mask,
int offset) : FlowLevelOffset(offset), _mask(mask) {
364 _get_data = &get_data_ptr;
371 void set_match(
int offset, T mask) {
380 virtual int mask_size()
const {
384 virtual uint8_t get_mask(
int o)
const override {
387 if (o >= _offset + mask_size())
389 return ((uint8_t*)&_mask)[o-_offset];
392 virtual bool is_usefull()
override {
397 virtual bool prune(FlowLevel* other)
override;
402 virtual FlowNodePtr
prune(FlowLevel* other, FlowNodeData data, FlowNode* node,
bool &changed)
override;
404 inline long unsigned get_max_value() {
408 inline FlowNodeData get_data(
Packet* packet) {
409 return FlowNodeData((T)(*((T*)(packet->
data() + _offset)) & _mask));
414 FlowLevel* duplicate()
override {
418 bool equals(FlowLevel* level) {
419 return ((FlowLevelOffset::equals(level)) && (_mask ==
dynamic_cast<FlowLevelGeneric<T>*
>(level)->_mask));
423 virtual FlowLevel *optimize(FlowNode* parent)
override;
434 _get_data = &get_data_ptr;
446 virtual uint8_t get_mask(
int o)
const {
449 if (o >= _offset + mask_size())
454 virtual int mask_size()
const {
458 inline long unsigned get_max_value() {
462 inline FlowNodeData get_data(
Packet* packet) {
464 return FlowNodeData(*(T*)(packet->
data() + _offset));
471 for (
int i = 0; i <
sizeof(T); i++) {
477 FlowLevel* duplicate()
override {
486#if HAVE_LONG_CLASSIFICATION
492#if HAVE_LONG_CLASSIFICATION
Vector of bits.
Definition bitvector.hh:21
Base class for Click elements.
Definition element.hh:42
Definition flow_level.hh:253
Definition flow_level.hh:211
Definition flow_level.hh:430
Definition flow_level.hh:358
virtual bool prune(FlowLevel *other) override
Definition flownode.cc:1085
Definition flow_level.hh:291
A network packet.
Definition packet.hh:68
const unsigned char * data() const
Return the packet's data pointer.
Definition packet.hh:1207
Efficiently build up Strings from pieces.
Definition straccum.hh:28
String take_string()
Return a String object with this StringAccum's contents.
Definition straccum.cc:211
A string of characters.
Definition string.hh:22
Vector template.
Definition vector.hh:111
void push_back(value_argument_type v)
Append element v.
Definition vector.hh:399
The Packet class models packets in Click.