ROFL-pipeline  v0.6.0dev
of1x_timers.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_TIMERSH__
6 #define __OF1X_TIMERSH__
7 
8 #include <stdlib.h>
9 #include <inttypes.h>
10 #include <sys/time.h>
11 #include "rofl.h"
12 
22 /*
23 * OF1X Timers. Implementation assumes (and enforces) that ALL timers will expire in a multiple of OF1X_TIMER_SLOT_MS ms
24 */
25 #define OF1X_TIMER_SLOT_MS 1000 //1s
26 
27 //Flag to define the usage of static allocation of slots for the timers
28 #ifdef OF1X_TIMER_DYNAMIC_ALLOCATION_SLOTS
29  #error "Dynamic timers are not yet supported."
30  #define OF1X_TIMER_STATIC_ALLOCATION_SLOTS 0
31 #else
32  #define OF1X_TIMER_STATIC_ALLOCATION_SLOTS 1
33 #endif
34 
35 #define OF1X_TIMER_GROUPS_MAX 65536 //timeouts are given in a uint16_t=> 2^16
36 
37 //fwd declarations
38 struct of1x_pipeline;
39 struct of1x_flow_entry;
40 struct of1x_flow_table;
41 struct of1x_timer_group;
42 
43 typedef enum{
44  HARD_TO=0,
45  IDLE_TO=1,
46 }of1x_timer_timeout_type_t;
47 
48 typedef struct of1x_entry_timer{
49  struct of1x_flow_entry* entry;
50  struct of1x_timer_group* group;
51 
52  //linked list
53  struct of1x_entry_timer* prev;
54  struct of1x_entry_timer* next;
55  of1x_timer_timeout_type_t type;
57 
58 typedef struct of1x_timers_info{
59  uint32_t hard_timeout;
60  uint32_t idle_timeout;
61 
62  // time when the entry was last used (0 for hard timeouts)
63  //struct timeval time_last_update;
64  //checks the number of packets that hit the entry to implement a lazy expiration
65  // less accurate but more eficient
66  uint64_t last_packet_count;
67 
68  of1x_entry_timer_t * idle_timer_entry;
69  of1x_entry_timer_t * hard_timer_entry;
70 
72 
73 typedef struct of1x_timer_list{
74  unsigned int num_of_timers;
75  of1x_entry_timer_t* head;
76  of1x_entry_timer_t* tail;
78 
79 
80 
81 typedef struct of1x_timer_group{
82  uint64_t timeout; //Expiration time in ms (slot)
83  of1x_timer_list_t list; //List of entries that expire at this timeout
84 
85 #if ! OF1X_TIMER_STATIC_ALLOCATION_SLOTS
86  struct of1x_timer_group* prev; //linked list
87  struct of1x_timer_group* next;
88 #endif
89 
91 
92 //C++ extern C
93 ROFL_BEGIN_DECLS
94 
95 //Timer functions outside tu
96 rofl_result_t __of1x_add_timer(struct of1x_flow_table* const table, struct of1x_flow_entry* const entry);
97 rofl_result_t __of1x_destroy_timer_entries(struct of1x_flow_entry * entry);
98 
99 void __of1x_process_pipeline_tables_timeout_expirations(struct of1x_pipeline *const pipeline);
100 
102 rofl_result_t __of1x_timer_group_static_init(struct of1x_flow_table* table);
104 //void __of1x_timer_update_entry(struct of1x_flow_entry * flow_entry, struct timeval ts);
105 void __of1x_fill_new_timer_entry_info(struct of1x_flow_entry * entry, uint32_t hard_timeout, uint32_t idle_timeout);
106 // public for testing
107 uint64_t __of1x_get_expiration_time_slotted (uint32_t timeout,struct timeval *now);
108 inline uint64_t __of1x_get_time_ms(struct timeval *time);
109 
110 static inline
111 void __of1x_reset_last_packet_count_idle_timeout(of1x_timers_info_t *timer_info){
112  timer_info->last_packet_count=0;
113 }
114 
115 //C++ extern C
116 ROFL_END_DECLS
117 
118 #endif //OF1X_TIMERS
rofl_result_t __of1x_destroy_timer_entries(struct of1x_flow_entry *entry)
of1x_destroy_timer_entry When a flow entry is removed from the table this function will be called in ...
Definition: of1x_timers.c:335
void __of1x_timer_group_static_destroy(struct of1x_flow_table *table)
of1x_timer_group_static_destroy Destroys the timers table initializes the values for the entry lists ...
Definition: of1x_timers.c:151
OpenFlow v1.0, 1.2 and 1.3.2 flow entry structure.
OpenFlow v1.0, 1.2 and 1.3.2 flow table abstraction.
void __of1x_fill_new_timer_entry_info(struct of1x_flow_entry *entry, uint32_t hard_timeout, uint32_t idle_timeout)
of1x_fill_new_timer_entry_info initialize the values for a new the timer entry
Definition: of1x_timers.c:21
void __of1x_dump_timers_structure(of1x_timer_group_t *timer_group)
of1x_dump_timers_structure this function is ment to show the timer groups existing and the entries re...
Definition: of1x_timers.c:52
OpenFlow v1.0, 1.2 and 1.3.2 pipeline abstraction data structure.
Definition: of1x_pipeline.h:50
rofl_result_t __of1x_timer_group_static_init(struct of1x_flow_table *table)
of1x_timer_group_static_init initializes the timeout values initializes the values for the entry list...
Definition: of1x_timers.c:121
Definition: of1x_timers.h:48
uint64_t __of1x_get_expiration_time_slotted(uint32_t timeout, struct timeval *now)
of1x_get_expiration_time_slotted
Definition: of1x_timers.c:100
uint64_t __of1x_get_time_ms(struct timeval *time)
transforms the timeval to a single uint64_t unit time in miliseconds
Definition: of1x_timers.c:89