16 #ifndef __HICN_MAPME__
17 #define __HICN_MAPME__
19 #include <vnet/dpo/load_balance.h>
20 #include <vnet/buffer.h>
21 #include <hicn/mapme.h>
49 #define HICN_MAPME_ALLOW_LOCATORS 1
53 #define NOT_A_NOTIFICATION false
54 #define TIMER_NO_REPEAT false
58 STATIC_ASSERT (
sizeof (u32) ==
sizeof (
seq_t),
"seq_t is not 4 bytes");
66 vlib_log_class_t log_class;
72 #define foreach_hicn_mapme_event \
84 #define _(a) HICN_MAPME_EVENT_##a,
89 typedef hicn_dpo_ctx_t hicn_mapme_tfib_t;
98 STATIC_ASSERT (
sizeof (hicn_mapme_tfib_t) <=
sizeof (hicn_dpo_ctx_t),
99 "hicn_mapme_tfib_t is greater than hicn_dpo_ctx_t");
101 #define TFIB(dpo_ctx) ((hicn_mapme_tfib_t *) (dpo_ctx))
103 static_always_inline
int
104 hicn_mapme_nh_set (hicn_mapme_tfib_t *tfib, hicn_face_id_t face_id)
106 hicn_dpo_ctx_t *strategy_ctx = (hicn_dpo_ctx_t *) tfib;
107 const fib_prefix_t *prefix =
108 fib_entry_get_prefix (strategy_ctx->fib_entry_index);
110 u32 n_entries = tfib->entry_count;
112 for (
int i = 0; i < n_entries; i++)
115 ip_adjacency_t *adj = adj_get (face->dpo.dpoi_index);
117 &adj->sub_type.nbr.next_hop, face->sw_if);
128 static_always_inline
int
131 for (u8 pos = 0; pos < tfib->entry_count; pos++)
132 if (tfib->next_hops[pos] == face_id)
137 hicn_dpo_ctx_t *strategy_ctx = (hicn_dpo_ctx_t *) tfib;
138 const fib_prefix_t *prefix =
139 fib_entry_get_prefix (strategy_ctx->fib_entry_index);
152 static_always_inline
int
155 u8 pos = HICN_PARAM_FIB_ENTRY_NHOPS_MAX - tfib->tfib_entry_count;
159 for (u8 pos2 = pos; pos2 < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos2++)
160 if (tfib->next_hops[pos2] == face_id)
164 if (pos <= tfib->entry_count)
167 tfib->next_hops[pos - 1] = face_id;
168 tfib->tfib_entry_count++;
179 static_always_inline
int
180 hicn_mapme_tfib_clear (hicn_mapme_tfib_t *tfib)
182 hicn_face_id_t invalid = NEXT_HOP_INVALID;
187 u8 start_pos = HICN_PARAM_FIB_ENTRY_NHOPS_MAX - tfib->tfib_entry_count;
189 for (pos = start_pos; pos < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos++)
192 tfib->next_hops[pos] = invalid;
196 tfib->tfib_entry_count = 0;
201 static_always_inline
int
202 hicn_mapme_tfib_del (hicn_mapme_tfib_t *tfib, hicn_face_id_t face_id)
204 hicn_face_id_t invalid = NEXT_HOP_INVALID;
209 u8 start_pos = HICN_PARAM_FIB_ENTRY_NHOPS_MAX - tfib->tfib_entry_count;
211 for (pos = start_pos; pos < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos++)
212 if (tfib->next_hops[pos] == face_id)
215 tfib->next_hops[pos] = invalid;
218 if (pos == HICN_PARAM_FIB_ENTRY_NHOPS_MAX)
222 tfib->tfib_entry_count--;
225 if (PREDICT_TRUE (pos > start_pos))
226 memmove (tfib->next_hops + start_pos + 1, tfib->next_hops + start_pos,
227 (pos - start_pos) * sizeof (hicn_face_id_t));
236 static_always_inline dpo_id_t *
239 fib_prefix_t fib_pfx;
240 fib_node_index_t fib_entry_index;
245 const dpo_id_t *load_balance_dpo_id;
248 fib_prefix_from_ip46_addr (addr, &fib_pfx);
249 fib_pfx.fp_len = plen;
252 fib_index = fib_table_find (fib_pfx.fp_proto, HICN_FIB_TABLE);
254 fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx);
255 if (fib_entry_index == FIB_NODE_INDEX_INVALID)
258 load_balance_dpo_id = fib_entry_contribute_ip_forwarding (fib_entry_index);
261 if (load_balance_dpo_id->dpoi_type != DPO_LOAD_BALANCE)
265 lb = load_balance_get (load_balance_dpo_id->dpoi_index);
275 for (
int i = 0; i < lb->lb_n_buckets; i++)
278 dpo_id = (dpo_id_t *) load_balance_get_bucket_i (lb, i);
285 return (dpo_id_t *) load_balance_dpo_id;
290 extern dpo_type_t hicn_face_udp_type;
291 extern dpo_type_t hicn_face_ip_type;
296 extern u32 strategy_face_ip4_vlib_edge;
297 extern u32 strategy_face_ip6_vlib_edge;
299 extern u32 strategy_face_udp4_vlib_edge;
300 extern u32 strategy_face_udp6_vlib_edge;
312 if (dpo->dpoi_type == hicn_face_ip_type)
314 switch (dpo->dpoi_proto)
317 return strategy_face_ip4_vlib_edge;
319 return strategy_face_ip6_vlib_edge;
324 else if (dpo->dpoi_type == hicn_face_udp_type)
326 switch (dpo->dpoi_proto)
329 return strategy_face_udp4_vlib_edge;
331 return strategy_face_udp6_vlib_edge;
350 switch (face->dpo.dpoi_proto)
353 return "hicn4-face-output";
355 return "hicn6-face-output";
361 #define DEBUG(...) // vlib_log_debug(mapme_main.log_class, __VA_ARGS__)
362 #define WARN(...) // vlib_log_warn(mapme_main.log_class, __VA_ARGS__)
363 #define ERROR(...) // vlib_log_err(mapme_main.log_class, __VA_ARGS__)