ROFL-pipeline  v0.6.0dev
of1x_flow_table.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef __OF1X_FLOW_TABLEH__
6 #define __OF1X_FLOW_TABLEH__
7 
8 #include <stdlib.h>
9 #include <stdbool.h>
10 #include <inttypes.h>
11 #include <stdint.h>
12 #include "rofl.h"
13 #include "../../../common/bitmap.h"
14 #include "../../../threading.h"
15 #include "of1x_flow_entry.h"
16 #include "of1x_timers.h"
17 #include "of1x_statistics.h"
18 #include "of1x_utils.h"
19 #include "matching_algorithms/matching_algorithms.h"
20 
45 #define OF1X_FIRST_FLOW_TABLE_INDEX 0 //As per 1.2 spec
46 #define OF1X_MAX_NUMBER_OF_TABLE_ENTRIES 0xFFFFFFFF
47 #define OF1X_MAX_TABLE_NAME_LEN 32
48 
49 //fwd decl
50 struct of1x_timer_group;
51 struct of1x_pipeline;
52 
53 //Agnostic auxiliary matching structures.
54 typedef void matching_auxiliary_t;
55 
59 typedef enum{
60  OF1X_TABLE_MISS_CONTROLLER = 0, /* Send to controller. */
61  OF1X_TABLE_MISS_CONTINUE = 1 << 0, /* Continue to the next table in the */
62  OF1X_TABLE_MISS_DROP = 1 << 1, /* Drop the packet. */
63  OF1X_TABLE_MISS_MASK = 3
65 
66 
67 //To str()
68 #define __OF1X_TABLE_MISS_MAX OF1X_TABLE_MISS_MASK+1
69 extern const char* __of1x_flow_table_miss_config_str[__OF1X_TABLE_MISS_MAX];
70 
74 typedef struct{
75  //Configuration stuff
76  bitmap128_t match; /* Bitmap of (1 << OF1X_MATCH_*) that indicate the fields the table can match on. */
77  bitmap128_t wildcards; /* Bitmap of (1 << OF1X_MATCH_*) wildcards that are supported by the table. */
78  bitmap128_t write_actions; /* Bitmap of (1 << OF1X_AT_* that are supported by the table with OFPIT_WRITE_ACTIONS. */
79  bitmap128_t apply_actions; /* Bitmap of (1 << OF1X_AT_* that are supported by the table with OFPIT_APPLY_ACTIONS. */
80  bitmap64_t metadata_match; /* Bits of metadata table can match. */
81  bitmap64_t metadata_write; /* Bits of metadata table can write. */
82  bitmap32_t instructions; /* Bitmap of OF1X_IT_* values supported. */
83  bitmap32_t table_miss_config; /* Bitmap of OF1X_TABLE_MISS_* values */
85 
86 
90 typedef struct of1x_flow_table{
91 
92  //Table number
93  unsigned int number;
94 
95  //Table name
96  char name[OF1X_MAX_TABLE_NAME_LEN];
97 
104  unsigned int num_of_entries;
105  unsigned int max_entries; /* Max number of entries supported. */
106 
107  //Timers associated
108 #if OF1X_TIMER_STATIC_ALLOCATION_SLOTS
109  unsigned int current_timer_group; /*in case of static allocation indicates the timer group*/
110 #endif
111  struct of1x_timer_group* timers;
112 
113  //Table config
114  of1x_flow_table_miss_config_t default_action;
116 
117  //statistics
118  of1x_stats_table_t stats;
119 
124  matching_auxiliary_t* matching_aux[2];
125 
126 #ifdef ROFL_PIPELINE_LOCKLESS
127  tid_presence_t tid_presence_mask;
128 #endif
129 
130  //Mutexes
131  platform_mutex_t* mutex; //Mutual exclusion among insertion/deletion threads
132  platform_rwlock_t* rwlock; //Readers mutex
133 
134  //Reference back
135  struct of1x_pipeline* pipeline;
136 
137  /*
138  * Matching algorithm identifier
139  */
140  enum of1x_matching_algorithm_available matching_algorithm;
141 
143 
148 
149 /*
150 *
151 * Function prototypes
152 *
153 */
154 
155 //C++ extern C
156 ROFL_BEGIN_DECLS
157 
158 /*
159 * Table init and destroy
160 */
161 rofl_result_t __of1x_init_table(struct of1x_pipeline* pipeline, of1x_flow_table_t* table, const unsigned int table_index, const enum of1x_matching_algorithm_available algorithm);
162 
163 //Set defaults for OF1.0, 1.2 and 1.3
164 void __of10_set_table_defaults(of1x_flow_table_t* table);
165 void __of12_set_table_defaults(of1x_flow_table_t* table);
166 void __of13_set_table_defaults(of1x_flow_table_t* table);
167 
168 rofl_result_t __of1x_destroy_table(of1x_flow_table_t* table);
169 
170 /*
171 * Flow-mod installation, modify and removal
172 */
173 
199 rofl_of1x_fm_result_t of1x_add_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t **const entry, bool check_overlap, bool reset_counts);
200 
223 rofl_result_t of1x_modify_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t **const entry, const enum of1x_flow_removal_strictness strict, bool reset_counts);
224 
246 rofl_result_t of1x_remove_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t* entry, const enum of1x_flow_removal_strictness strict, uint32_t out_port, uint32_t out_group);
247 
248 //This API call is meant to ONLY be used internally within the pipeline library (timers)
249 rofl_result_t __of1x_remove_specific_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t *const specific_entry, of1x_flow_remove_reason_t reason, of1x_mutex_acquisition_required_t mutex_acquired);
250 
251 /*
252 * Table dumping. Not recommended to use it directly
253 *
254 * @param raw_nbo Show values in the pipeline internal byte order (NBO). Warning: some values are intentionally unaligned.
255 */
256 void of1x_dump_table(of1x_flow_table_t* table, bool raw_nbo);
257 
258 //C++ extern C
259 ROFL_END_DECLS
260 
261 #endif //OF1X_FLOW_TABLE
rofl_result_t of1x_modify_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t **const entry, const enum of1x_flow_removal_strictness strict, bool reset_counts)
Modify flow_entry(s) in the table.
Table configuration.
OpenFlow v1.0, 1.2 and 1.3.2 flow entry structure.
enum of1x_flow_remove_reason of1x_flow_remove_reason_t
Flow remove reasons (enum ofp_flow_removed_reason)
rofl_result_t of1x_remove_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t *entry, const enum of1x_flow_removal_strictness strict, uint32_t out_port, uint32_t out_group)
Removes a flow_entry from the table.
OpenFlow v1.0, 1.2 and 1.3.2 flow table abstraction.
of1x_flow_removal_strictness
Flow removal operations strictness.
rofl_of1x_fm_result_t of1x_add_flow_entry_table(struct of1x_pipeline *const pipeline, const unsigned int table_id, of1x_flow_entry_t **const entry, bool check_overlap, bool reset_counts)
Add a flow_entry to a table.
OpenFlow v1.0, 1.2 and 1.3.2 timers subsystem.
of1x_flow_table_miss_config_t
Table miss behaviour (ofp_table_config)
matching_auxiliary_t * matching_aux[2]
Place-holder to allow matching algorithms keep its own state.
enum rofl_of1x_fm_result rofl_of1x_fm_result_t
Extended flowmod return codes.
of1x_flow_entry_t * entries
This pointer may or may not be used depending on the matching algorithm.
OpenFlow v1.0, 1.2 and 1.3.2 flow entry abstraction.
OpenFlow v1.0, 1.2 and 1.3.2 pipeline abstraction data structure.
Definition: of1x_pipeline.h:50
OpenFlow v1.0, 1.2 and 1.3.2 statistics subsystem.
struct of1x_flow_table of1x_flow_table_t
OpenFlow v1.0, 1.2 and 1.3.2 flow table abstraction.
of1x_flow_table_t __of1x_flow_table_snapshot_t
Table snapshot.