ROFL-pipeline  v0.6.0dev
of1x_l2hash_ma.h
1 #ifndef __OF1X_L2HASH_MATCH_H__
2 #define __OF1X_L2HASH_MATCH_H__
3 
4 #include "rofl.h"
5 #include "../matching_algorithms.h"
6 #include "../../of1x_flow_table.h"
7 
8 //C++ extern C
9 ROFL_BEGIN_DECLS
10 
11 //fwd decl
12 struct l2hash_ht_entry;
13 
14 //Bucket
15 typedef struct l2hash_ht_bucket{
16 
17  //Bucket fields
18  uint64_t eth_dst;
19  uint16_t vid;
20 
21  //Flow entry pointer
22  of1x_flow_entry_t* entry;
23 
24  //Pointer back to the entry
25  struct l2hash_ht_entry* ht_entry;
26 
27  //Double linked list
28  struct l2hash_ht_bucket* prev;
29  struct l2hash_ht_bucket* next;
31 
32 //Hash table entry
33 typedef struct l2hash_ht_entry{
34  unsigned int num_of_buckets;
35  struct l2hash_ht_bucket* bucket_list;
37 
38 //Hash table
39 
40 #define L2HASH_MAX_ENTRIES 0xFFFF
41 
42 typedef struct l2hash_ht_table{
43  unsigned int num_of_entries;
44  l2hash_ht_entry_t table[L2HASH_MAX_ENTRIES];
46 
47 
48 //State
49 typedef struct l2hash_state{
50  //Hash tables
51  l2hash_ht_table_t vlan;
52  l2hash_ht_table_t no_vlan;
54 
55 //Keys
56 typedef struct l2hash_novlan_key{
57  uint64_t eth_dst; //+2 bytes padding
59 
60 typedef struct l2hash_vlan{
61  uint64_t eth_dst; //+2 bytes padding
62  uint16_t vid;
64 
65 
66 
67 #if 0
68 //Matrix of T elements for Pearsons's algorithm
69 extern uint16_t l2hash_ht_T[L2HASH_MAX_ENTRIES];
70 
71 //Hashing functions
72 static inline uint16_t l2hash_ht_hash64(const char* key, unsigned int size){
73 
74  uint16_t hash=0x0;
75  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[0])];
76  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[1])];
77  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[2])];
78  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[3])];
79  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[4])];
80  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[5])];
81  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[6])];
82  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[7])];
83  return hash;
84 }
85 
86 //Hashing functions
87 static inline uint16_t l2hash_ht_hash96(const char* key, unsigned int size){
88 
89  uint16_t hash=0x0;
90  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[0])];
91  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[1])];
92  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[2])];
93  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[3])];
94  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[4])];
95  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[5])];
96  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[6])];
97  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[7])];
98  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[8])];
99  hash = l2hash_ht_T[hash ^ (L2HASH_MAX_ENTRIES & key[9])];
100  return hash;
101 }
102 #else
103 
108 #define L2_HASH_FNV_MASK_16 0xFFFF
109 #define L2_HASH_FNV_PRIME 0x01000193 //16777619
110 #define L2_HASH_FNV_SEED 0x811C9DC5 //2166136261
111 
112 
113 static inline uint32_t l2hash_fnv1a(unsigned char c, uint32_t hash){
114  return (c ^ hash) * L2_HASH_FNV_PRIME;
115 }
117 static inline uint16_t l2hash_ht_hash64(const char* key, unsigned int size){
118 
119  uint32_t hash = L2_HASH_FNV_SEED;
120 
121  hash = l2hash_fnv1a( key[0], hash);
122  hash = l2hash_fnv1a( key[1], hash);
123  hash = l2hash_fnv1a( key[2], hash);
124  hash = l2hash_fnv1a( key[3], hash);
125  hash = l2hash_fnv1a( key[4], hash);
126  hash = l2hash_fnv1a( key[5], hash);
127  hash = l2hash_fnv1a( key[6], hash);
128  hash = l2hash_fnv1a( key[7], hash);
129 
130  //Fold
131  return (hash>>16) ^ (hash & L2_HASH_FNV_MASK_16);
132 }
133 
134 //96 bit
135 static inline uint16_t l2hash_ht_hash96(const char* key, unsigned int size){
136  uint32_t hash = L2_HASH_FNV_SEED;
137 
138  hash = l2hash_fnv1a( key[0], hash);
139  hash = l2hash_fnv1a( key[1], hash);
140  hash = l2hash_fnv1a( key[2], hash);
141  hash = l2hash_fnv1a( key[3], hash);
142  hash = l2hash_fnv1a( key[4], hash);
143  hash = l2hash_fnv1a( key[5], hash);
144  hash = l2hash_fnv1a( key[6], hash);
145  hash = l2hash_fnv1a( key[7], hash);
146  hash = l2hash_fnv1a( key[8], hash);
147  hash = l2hash_fnv1a( key[9], hash);
148 
149  //Fold
150  return (hash>>16) ^ (hash & L2_HASH_FNV_MASK_16);
151 }
152 
153 #endif
154 //Platform state
155 typedef struct l2hash_entry_ps{
156  bool has_vlan;
157  l2hash_ht_bucket_t* bucket;
159 
160 //C++ xtern C
161 ROFL_END_DECLS
162 
163 #endif //L2HASH_MATCH
OpenFlow v1.0, 1.2 and 1.3.2 flow entry structure.