blob: d5f3a28ac9d3e237f688c0f50e93b4610e1fa99e [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/**
16 * @file
17 * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys.
18 *
19 */
20
Neale Rannsb80c5362016-10-08 13:03:40 +010021#include <vnet/dpo/load_balance.h>
Filip Tehlar4868ff62017-03-09 16:48:39 +010022#include <vnet/lisp-cp/control.h>
Neale Rannsb80c5362016-10-08 13:03:40 +010023#include <vnet/lisp-cp/lisp_types.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010024#include <vnet/lisp-gpe/lisp_gpe_sub_interface.h>
25#include <vnet/lisp-gpe/lisp_gpe_adjacency.h>
26#include <vnet/lisp-gpe/lisp_gpe_tunnel.h>
27#include <vnet/fib/fib_entry.h>
28#include <vnet/adj/adj_midchain.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050029#include <vppinfra/bihash_24_8.h>
30#include <vppinfra/bihash_template.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010031
32/**
33 * Memory pool of all adjacencies
34 */
35static lisp_gpe_adjacency_t *lisp_adj_pool;
36
37/**
38 * Hash table of all adjacencies. key:{nh, itf}
39 * We never have an all zeros address since the interfaces are multi-access,
40 * therefore there is no ambiguity between a v4 and v6 next-hop, so we don't
41 * need to add the protocol to the key.
42 */
43static
44BVT (clib_bihash)
45 lisp_adj_db;
46
47#define LISP_ADJ_SET_KEY(_key, _itf, _nh) \
48{ \
49 _key.key[0] = (_nh)->ip.v6.as_u64[0]; \
50 _key.key[1] = (_nh)->ip.v6.as_u64[1]; \
51 _key.key[2] = (_itf); \
52}
53
54 static index_t lisp_adj_find (const ip_address_t * addr, u32 sw_if_index)
55{
56 BVT (clib_bihash_kv) kv;
57
58 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
59
60 if (BV (clib_bihash_search) (&lisp_adj_db, &kv, &kv) < 0)
61 {
62 return (INDEX_INVALID);
63 }
64 else
65 {
66 return (kv.value);
67 }
68}
69
70static void
71lisp_adj_insert (const ip_address_t * addr, u32 sw_if_index, index_t ai)
72{
73 BVT (clib_bihash_kv) kv;
74
75 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
76 kv.value = ai;
77
78 BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 1);
79}
80
81static void
82lisp_adj_remove (const ip_address_t * addr, u32 sw_if_index)
83{
84 BVT (clib_bihash_kv) kv;
85
86 LISP_ADJ_SET_KEY (kv, sw_if_index, addr);
87
88 BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 0);
89}
90
91static lisp_gpe_adjacency_t *
92lisp_gpe_adjacency_get_i (index_t lai)
93{
94 return (pool_elt_at_index (lisp_adj_pool, lai));
95}
96
97fib_forward_chain_type_t
98lisp_gpe_adj_get_fib_chain_type (const lisp_gpe_adjacency_t * ladj)
99{
100 switch (ip_addr_version (&ladj->remote_rloc))
101 {
102 case IP4:
103 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
104 case IP6:
105 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
106 default:
107 ASSERT (0);
108 break;
109 }
110 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
111}
112
Neale Rannsb80c5362016-10-08 13:03:40 +0100113static void
114ip46_address_to_ip_address (const ip46_address_t * a, ip_address_t * b)
115{
116 if (ip46_address_is_ip4 (a))
117 {
118 memset (b, 0, sizeof (*b));
119 ip_address_set (b, &a->ip4, IP4);
120 }
121 else
122 {
123 ip_address_set (b, &a->ip6, IP6);
124 }
125}
126
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100127/**
128 * @brief Stack the tunnel's midchain on the IP forwarding chain of the via
129 */
130static void
Neale Rannsb80c5362016-10-08 13:03:40 +0100131lisp_gpe_adj_stack_one (lisp_gpe_adjacency_t * ladj, adj_index_t ai)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100132{
Neale Ranns5e575b12016-10-03 09:40:25 +0100133 const lisp_gpe_tunnel_t *lgt;
Neale Ranns948e00f2016-10-20 13:39:34 +0100134 dpo_id_t tmp = DPO_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100135
136 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
137 fib_entry_contribute_forwarding (lgt->fib_entry_index,
138 lisp_gpe_adj_get_fib_chain_type (ladj),
139 &tmp);
140
Neale Rannsb80c5362016-10-08 13:03:40 +0100141 if (DPO_LOAD_BALANCE == tmp.dpoi_type)
142 {
143 /*
144 * post LISP rewrite we will load-balance. However, the LISP encap
145 * is always the same for this adjacency/tunnel and hence the IP/UDP src,dst
146 * hash is always the same result too. So we do that hash now and
147 * stack on the choice.
148 * If the choice is an incomplete adj then we will need a poke when
149 * it becomes complete. This happens since the adj update walk propagates
150 * as far a recursive paths.
151 */
152 const dpo_id_t *choice;
153 load_balance_t *lb;
154 int hash;
155
156 lb = load_balance_get (tmp.dpoi_index);
157
158 if (IP4 == ip_addr_version (&ladj->remote_rloc))
159 {
160 hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai),
161 lb->lb_hash_config);
162 }
163 else
164 {
165 hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai),
166 lb->lb_hash_config);
167 }
168
169 choice =
170 load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1);
171 dpo_copy (&tmp, choice);
172 }
173
174 adj_nbr_midchain_stack (ai, &tmp);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100175 dpo_reset (&tmp);
176}
177
Neale Rannsb80c5362016-10-08 13:03:40 +0100178/**
179 * @brief Call back when restacking all adjacencies on a GRE interface
180 */
181static adj_walk_rc_t
182lisp_gpe_adj_walk_cb (adj_index_t ai, void *ctx)
183{
184 lisp_gpe_adjacency_t *ladj = ctx;
185
186 lisp_gpe_adj_stack_one (ladj, ai);
187
188 return (ADJ_WALK_RC_CONTINUE);
189}
190
191static void
192lisp_gpe_adj_stack (lisp_gpe_adjacency_t * ladj)
193{
194 fib_protocol_t nh_proto;
195 ip46_address_t nh;
196
197 ip_address_to_46 (&ladj->remote_rloc, &nh, &nh_proto);
198
199 /*
200 * walk all the adjacencies on th lisp interface and restack them
201 */
202 adj_nbr_walk_nh (ladj->sw_if_index,
203 nh_proto, &nh, lisp_gpe_adj_walk_cb, ladj);
204}
205
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100206static lisp_gpe_next_protocol_e
Neale Ranns924d03a2016-10-19 08:25:46 +0100207lisp_gpe_adj_proto_from_vnet_link_type (vnet_link_t linkt)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100208{
209 switch (linkt)
210 {
Neale Ranns924d03a2016-10-19 08:25:46 +0100211 case VNET_LINK_IP4:
Neale Ranns5e575b12016-10-03 09:40:25 +0100212 return (LISP_GPE_NEXT_PROTO_IP4);
Neale Ranns924d03a2016-10-19 08:25:46 +0100213 case VNET_LINK_IP6:
Neale Ranns5e575b12016-10-03 09:40:25 +0100214 return (LISP_GPE_NEXT_PROTO_IP6);
Neale Ranns924d03a2016-10-19 08:25:46 +0100215 case VNET_LINK_ETHERNET:
Neale Ranns5e575b12016-10-03 09:40:25 +0100216 return (LISP_GPE_NEXT_PROTO_ETHERNET);
Florin Corasce1b4c72017-01-26 14:25:34 -0800217 case VNET_LINK_NSH:
218 return (LISP_GPE_NEXT_PROTO_NSH);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100219 default:
220 ASSERT (0);
221 }
Neale Ranns5e575b12016-10-03 09:40:25 +0100222 return (LISP_GPE_NEXT_PROTO_IP4);
223}
224
225#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
226
Filip Tehlar4868ff62017-03-09 16:48:39 +0100227static lisp_afi_e
228lisp_afi_from_vnet_link_type (vnet_link_t link)
229{
230 switch (link)
231 {
232 case VNET_LINK_IP4:
233 return LISP_AFI_IP;
234 case VNET_LINK_IP6:
235 return LISP_AFI_IP6;
236 case VNET_LINK_ETHERNET:
237 return LISP_AFI_MAC;
238 default:
239 return LISP_AFI_NO_ADDR;
240 }
241}
242
243static void
244lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, ip_adjacency_t * adj,
245 vlib_buffer_t * b)
246{
247 lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
248 lisp_gpe_adjacency_t *ladj;
249 ip_address_t rloc;
250 index_t lai;
251 u32 si, di;
252 gid_address_t src, dst;
Filip Tehlar4868ff62017-03-09 16:48:39 +0100253 uword *feip;
254
255 ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc);
256 si = vnet_buffer (b)->sw_if_index[VLIB_TX];
257 lai = lisp_adj_find (&rloc, si);
258 ASSERT (INDEX_INVALID != lai);
259
260 ladj = pool_elt_at_index (lisp_adj_pool, lai);
261
262 u8 *lisp_data = (u8 *) vlib_buffer_get_current (b);
263
264 /* skip IP header */
265 if (is_v4_packet (lisp_data))
266 lisp_data += sizeof (ip4_header_t);
267 else
268 lisp_data += sizeof (ip6_header_t);
269
270 /* skip UDP header */
271 lisp_data += sizeof (udp_header_t);
272 // TODO: skip TCP?
273
274 /* skip LISP GPE header */
275 lisp_data += sizeof (lisp_gpe_header_t);
276
277 i16 saved_current_data = b->current_data;
278 b->current_data = lisp_data - b->data;
279
280 lisp_afi_e afi = lisp_afi_from_vnet_link_type (adj->ia_link);
281 get_src_and_dst_eids_from_buffer (lcm, b, &src, &dst, afi);
282 b->current_data = saved_current_data;
283 di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, &src);
284 if (PREDICT_FALSE (~0 == di))
285 {
286 clib_warning ("dst mapping not found (%U, %U)", format_gid_address,
287 &src, format_gid_address, &dst);
288 return;
289 }
290
291 feip = hash_get (lcm->fwd_entry_by_mapping_index, di);
292 if (PREDICT_FALSE (!feip))
293 return;
294
295 lisp_stats_key_t key;
296 memset (&key, 0, sizeof (key));
297 key.fwd_entry_index = feip[0];
298 key.tunnel_index = ladj->tunnel_index;
299
300 uword *p = hash_get_mem (lgm->lisp_stats_index_by_key, &key);
Filip Tehlar21511912017-04-07 10:41:42 +0200301 ASSERT (p);
Filip Tehlar4868ff62017-03-09 16:48:39 +0100302
Filip Tehlar4868ff62017-03-09 16:48:39 +0100303 /* compute payload length starting after GPE */
Filip Tehlar21511912017-04-07 10:41:42 +0200304 u32 bytes = b->current_length - (lisp_data - b->data - b->current_data);
305 vlib_increment_combined_counter (&lgm->counters, os_get_cpu_number (),
306 p[0], 1, bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +0100307}
308
Neale Ranns5e575b12016-10-03 09:40:25 +0100309static void
310lisp_gpe_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b)
311{
Filip Tehlar4868ff62017-03-09 16:48:39 +0100312 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
313
314 if (lcm->flags & LISP_FLAG_STATS_ENABLED)
315 lisp_gpe_increment_stats_counters (lcm, adj, b);
316
Neale Ranns5e575b12016-10-03 09:40:25 +0100317 /* Fixup the checksum and len fields in the LISP tunnel encap
318 * that was applied at the midchain node */
319 ip_udp_fixup_one (vm, b, is_v4_packet (vlib_buffer_get_current (b)));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100320}
321
Neale Rannsb80c5362016-10-08 13:03:40 +0100322/**
323 * @brief The LISP-GPE interface registered function to update, i.e.
324 * provide an rewrite string for, an adjacency.
325 */
326void
327lisp_gpe_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
328{
329 const lisp_gpe_tunnel_t *lgt;
330 lisp_gpe_adjacency_t *ladj;
331 ip_adjacency_t *adj;
332 ip_address_t rloc;
333 vnet_link_t linkt;
334 index_t lai;
335
336 adj = adj_get (ai);
337 ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc);
338
339 /*
340 * find an existing or create a new adj
341 */
342 lai = lisp_adj_find (&rloc, sw_if_index);
343
344 ASSERT (INDEX_INVALID != lai);
345
346 ladj = pool_elt_at_index (lisp_adj_pool, lai);
347 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
348 linkt = adj_get_link_type (ai);
Neale Rannsb80c5362016-10-08 13:03:40 +0100349 adj_nbr_midchain_update_rewrite
350 (ai, lisp_gpe_fixup,
351 (VNET_LINK_ETHERNET == linkt ?
Neale Rannsfa5d1982017-02-20 14:19:51 -0800352 ADJ_FLAG_MIDCHAIN_NO_COUNT :
353 ADJ_FLAG_NONE),
Florin Corasce1b4c72017-01-26 14:25:34 -0800354 lisp_gpe_tunnel_build_rewrite (lgt, ladj,
355 lisp_gpe_adj_proto_from_vnet_link_type
356 (linkt)));
Neale Rannsb80c5362016-10-08 13:03:40 +0100357
358 lisp_gpe_adj_stack_one (ladj, ai);
359}
360
361u8 *
362lisp_gpe_build_rewrite (vnet_main_t * vnm,
363 u32 sw_if_index,
364 vnet_link_t link_type, const void *dst_address)
365{
366 ASSERT (0);
367 return (NULL);
368}
369
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100370index_t
371lisp_gpe_adjacency_find_or_create_and_lock (const locator_pair_t * pair,
372 u32 overlay_table_id, u32 vni)
373{
Neale Rannsb80c5362016-10-08 13:03:40 +0100374 const lisp_gpe_sub_interface_t *l3s;
Neale Ranns5e575b12016-10-03 09:40:25 +0100375 const lisp_gpe_tunnel_t *lgt;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100376 lisp_gpe_adjacency_t *ladj;
377 index_t lai, l3si;
378
379 /*
380 * first find the L3 sub-interface that corresponds to the loacl-rloc and vni
381 */
382 l3si = lisp_gpe_sub_interface_find_or_create_and_lock (&pair->lcl_loc,
383 overlay_table_id,
384 vni);
Neale Rannsb80c5362016-10-08 13:03:40 +0100385 l3s = lisp_gpe_sub_interface_get (l3si);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100386
387 /*
388 * find an existing or create a new adj
389 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100390 lai = lisp_adj_find (&pair->rmt_loc, l3s->sw_if_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100391
392 if (INDEX_INVALID == lai)
393 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100394
395 pool_get (lisp_adj_pool, ladj);
396 memset (ladj, 0, sizeof (*ladj));
397 lai = (ladj - lisp_adj_pool);
398
Neale Rannsb80c5362016-10-08 13:03:40 +0100399 ip_address_copy (&ladj->remote_rloc, &pair->rmt_loc);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100400 ladj->vni = vni;
401 /* transfer the lock to the adj */
402 ladj->lisp_l3_sub_index = l3si;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100403 ladj->sw_if_index = l3s->sw_if_index;
404
405 /* if vni is non-default */
406 if (ladj->vni)
407 ladj->flags = LISP_GPE_FLAGS_I;
408
409 /* work in lisp-gpe not legacy mode */
410 ladj->flags |= LISP_GPE_FLAGS_P;
411
412 /*
413 * find the tunnel that will provide the underlying transport
414 * and hence the rewrite.
415 * The RLOC FIB index is default table - always.
416 */
417 ladj->tunnel_index = lisp_gpe_tunnel_find_or_create_and_lock (pair, 0);
418
419 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
420
421 /*
422 * become of child of the RLOC FIB entry so we are updated when
423 * its reachability changes, allowing us to re-stack the midcahins
424 */
425 ladj->fib_entry_child_index = fib_entry_child_add (lgt->fib_entry_index,
426 FIB_NODE_TYPE_LISP_ADJ,
427 lai);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100428
Neale Rannsb80c5362016-10-08 13:03:40 +0100429 lisp_adj_insert (&ladj->remote_rloc, ladj->sw_if_index, lai);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100430 }
431 else
432 {
433 /* unlock the interface from the find. */
434 lisp_gpe_sub_interface_unlock (l3si);
435 ladj = lisp_gpe_adjacency_get_i (lai);
436 }
437
438 ladj->locks++;
439
440 return (lai);
441}
442
443/**
444 * @brief Get a pointer to a tunnel from a pointer to a FIB node
445 */
446static lisp_gpe_adjacency_t *
447lisp_gpe_adjacency_from_fib_node (const fib_node_t * node)
448{
449 return ((lisp_gpe_adjacency_t *)
450 ((char *) node -
451 STRUCT_OFFSET_OF (lisp_gpe_adjacency_t, fib_node)));
452}
453
454static void
455lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_t * ladj)
456{
Neale Rannsb80c5362016-10-08 13:03:40 +0100457 const lisp_gpe_tunnel_t *lgt;
458
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100459 /*
460 * no children so we are not counting locks. no-op.
461 * at least not counting
462 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100463 lisp_adj_remove (&ladj->remote_rloc, ladj->sw_if_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100464
465 /*
466 * unlock the resources this adj holds
467 */
Neale Rannsb80c5362016-10-08 13:03:40 +0100468 lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
469
470 fib_entry_child_remove (lgt->fib_entry_index, ladj->fib_entry_child_index);
471
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100472 lisp_gpe_tunnel_unlock (ladj->tunnel_index);
473 lisp_gpe_sub_interface_unlock (ladj->lisp_l3_sub_index);
474
475 pool_put (lisp_adj_pool, ladj);
476}
477
478void
479lisp_gpe_adjacency_unlock (index_t lai)
480{
481 lisp_gpe_adjacency_t *ladj;
482
483 ladj = lisp_gpe_adjacency_get_i (lai);
484
485 ladj->locks--;
486
487 if (0 == ladj->locks)
488 {
489 lisp_gpe_adjacency_last_lock_gone (ladj);
490 }
491}
492
493const lisp_gpe_adjacency_t *
494lisp_gpe_adjacency_get (index_t lai)
495{
496 return (lisp_gpe_adjacency_get_i (lai));
497}
498
499
500/**
501 * @brief LISP GPE tunnel back walk
502 *
503 * The FIB entry through which this tunnel resolves has been updated.
504 * re-stack the midchain on the new forwarding.
505 */
506static fib_node_back_walk_rc_t
507lisp_gpe_adjacency_back_walk (fib_node_t * node,
508 fib_node_back_walk_ctx_t * ctx)
509{
510 lisp_gpe_adj_stack (lisp_gpe_adjacency_from_fib_node (node));
511
512 return (FIB_NODE_BACK_WALK_CONTINUE);
513}
514
515static fib_node_t *
516lisp_gpe_adjacency_get_fib_node (fib_node_index_t index)
517{
518 lisp_gpe_adjacency_t *ladj;
519
520 ladj = pool_elt_at_index (lisp_adj_pool, index);
521 return (&ladj->fib_node);
522}
523
524static void
525lisp_gpe_adjacency_last_fib_lock_gone (fib_node_t * node)
526{
527 lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_from_fib_node (node));
528}
529
530const static fib_node_vft_t lisp_gpe_tuennel_vft = {
531 .fnv_get = lisp_gpe_adjacency_get_fib_node,
532 .fnv_back_walk = lisp_gpe_adjacency_back_walk,
533 .fnv_last_lock = lisp_gpe_adjacency_last_fib_lock_gone,
534};
535
536u8 *
537format_lisp_gpe_adjacency (u8 * s, va_list * args)
538{
539 lisp_gpe_adjacency_t *ladj = va_arg (*args, lisp_gpe_adjacency_t *);
540 lisp_gpe_adjacency_format_flags_t flags =
Billy McFallcfcf1e22016-10-14 09:51:49 -0400541 va_arg (*args, lisp_gpe_adjacency_format_flags_t);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100542
543 if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL)
544 {
545 s =
546 format (s, "index %d locks:%d\n", ladj - lisp_adj_pool, ladj->locks);
547 }
548
549 s = format (s, " vni: %d,", ladj->vni);
550 s = format (s, " remote-RLOC: %U,", format_ip_address, &ladj->remote_rloc);
551
552 if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL)
553 {
554 s = format (s, " %U\n",
555 format_lisp_gpe_sub_interface,
556 lisp_gpe_sub_interface_get (ladj->lisp_l3_sub_index));
557 s = format (s, " %U\n",
558 format_lisp_gpe_tunnel,
559 lisp_gpe_tunnel_get (ladj->tunnel_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100560 }
561 else
562 {
563 s = format (s, " LISP L3 sub-interface index: %d,",
564 ladj->lisp_l3_sub_index);
565 s = format (s, " LISP tunnel index: %d", ladj->tunnel_index);
566 }
567
568
569 return (s);
570}
571
572static clib_error_t *
573lisp_gpe_adjacency_show (vlib_main_t * vm,
574 unformat_input_t * input, vlib_cli_command_t * cmd)
575{
576 lisp_gpe_adjacency_t *ladj;
577 index_t index;
578
579 if (pool_elts (lisp_adj_pool) == 0)
580 vlib_cli_output (vm, "No lisp-gpe Adjacencies");
581
582 if (unformat (input, "%d", &index))
583 {
584 ladj = lisp_gpe_adjacency_get_i (index);
585 vlib_cli_output (vm, "%U", format_lisp_gpe_adjacency, ladj,
586 LISP_GPE_ADJ_FORMAT_FLAG_DETAIL);
587 }
588 else
589 {
590 /* *INDENT-OFF* */
591 pool_foreach (ladj, lisp_adj_pool,
592 ({
593 vlib_cli_output (vm, "[%d] %U\n",
594 ladj - lisp_adj_pool,
595 format_lisp_gpe_adjacency, ladj,
596 LISP_GPE_ADJ_FORMAT_FLAG_NONE);
597 }));
598 /* *INDENT-ON* */
599 }
600
601 return 0;
602}
603
604/* *INDENT-OFF* */
605VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) =
606{
Filip Tehlar82786c42017-02-20 15:20:37 +0100607 .path = "show gpe adjacency",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100608 .function = lisp_gpe_adjacency_show,
609};
610/* *INDENT-ON* */
611
612#define LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS (256)
613#define LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE (1<<20)
614
615static clib_error_t *
616lisp_gpe_adj_module_init (vlib_main_t * vm)
617{
618 BV (clib_bihash_init) (&lisp_adj_db,
619 "Adjacency Neighbour table",
620 LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS,
621 LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE);
622
623 fib_node_register_type (FIB_NODE_TYPE_LISP_ADJ, &lisp_gpe_tuennel_vft);
624 return (NULL);
625}
626
627VLIB_INIT_FUNCTION (lisp_gpe_adj_module_init)
628/*
629 * fd.io coding-style-patch-verification: ON
630 *
631 * Local Variables:
632 * eval: (c-set-style "gnu")
633 * End:
634 */