aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session/session_test.c
blob: a8a9327b892dd1e94c0e43124312d34c0dd58079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* SPDX-License-Identifier: Apache-2.0
 * Copyright(c) 2021 Cisco Systems, Inc.
 */

#include <vat/vat.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vppinfra/error.h>
#include <vpp/api/types.h>

#include <vnet/ip/ip_types_api.h>

#define __plugin_msg_base session_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>

#include <vlibmemory/vlib.api_enum.h>
#include <vlibmemory/vlib.api_types.h>

/* Declare message IDs */
#include <vnet/format_fns.h>
#include <vnet/session/session.api_enum.h>
#include <vnet/session/session.api_types.h>

#define vl_endianfun /* define message structures */
#include <vnet/session/session.api.h>
#undef vl_endianfun

typedef struct
{
  /* API message ID base */
  u16 msg_id_base;
  u32 ping_id;
  vat_main_t *vat_main;
} session_test_main_t;

static session_test_main_t session_test_main;

static int
api_session_rule_add_del (vat_main_t *vam)
{
  vl_api_session_rule_add_del_t *mp;
  unformat_input_t *i = vam->input;
  u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
  u32 appns_index = 0, scope = 0;
  ip4_address_t lcl_ip4, rmt_ip4;
  ip6_address_t lcl_ip6, rmt_ip6;
  u8 is_ip4 = 1, conn_set = 0;
  u8 is_add = 1, *tag = 0;
  int ret;
  fib_prefix_t lcl, rmt;

  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (i, "del"))
	is_add = 0;
      else if (unformat (i, "add"))
	;
      else if (unformat (i, "proto tcp"))
	proto = 0;
      else if (unformat (i, "proto udp"))
	proto = 1;
      else if (unformat (i, "appns %d", &appns_index))
	;
      else if (unformat (i, "scope %d", &scope))
	;
      else if (unformat (i, "tag %_%v%_", &tag))
	;
      else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip4_address,
			 &lcl_ip4, &lcl_plen, &lcl_port, unformat_ip4_address,
			 &rmt_ip4, &rmt_plen, &rmt_port))
	{
	  is_ip4 = 1;
	  conn_set = 1;
	}
      else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip6_address,
			 &lcl_ip6, &lcl_plen, &lcl_port, unformat_ip6_address,
			 &rmt_ip6, &rmt_plen, &rmt_port))
	{
	  is_ip4 = 0;
	  conn_set = 1;
	}
      else if (unformat (i, "action %d", &action))
	;
      else
	break;
    }
  if (proto == ~0 || !conn_set || action == ~0)
    {
      errmsg ("transport proto, connection and action must be set");
      return -99;
    }

  if (scope > 3)
    {
      errmsg ("scope should be 0-3");
      return -99;
    }

  M (SESSION_RULE_ADD_DEL, mp);

  clib_memset (&lcl, 0, sizeof (lcl));
  clib_memset (&rmt, 0, sizeof (rmt));
  if (is_ip4)
    {
      ip_set (&lcl.fp_addr, &lcl_ip4, 1);
      ip_set (&rmt.fp_addr, &rmt_ip4, 1);
      lcl.fp_len = lcl_plen;
      rmt.fp_len = rmt_plen;
    }
  else
    {
      ip_set (&lcl.fp_addr, &lcl_ip6, 0);
      ip_set (&rmt.fp_addr, &rmt_ip6, 0);
      lcl.fp_len = lcl_plen;
      rmt.fp_len = rmt_plen;
    }

  ip_prefix_encode (&lcl, &mp->lcl);
  ip_prefix_encode (&rmt, &mp->rmt);
  mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
  mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
  mp->transport_proto =
    proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
  mp->action_index = clib_host_to_net_u32 (action);
  mp->appns_index = clib_host_to_net_u32 (appns_index);
  mp->scope = scope;
  mp->is_add = is_add;
  if (tag)
    {
      clib_memcpy (mp->tag, tag, vec_len (tag));
      vec_free (tag);
    }

  S (mp);
  W (ret);
  return ret;
}

static void
vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t *mp)
{
}

static void
vl_api_app_add_cert_key_pair_reply_t_handler (
  vl_api_app_add_cert_key_pair_reply_t *mp)
{
}

static int
api_app_attach (vat_main_t *vat)
{
  return -1;
}

static int
api_application_detach (vat_main_t *vat)
{
  return -1;
}

static int
api_app_del_cert_key_pair (vat_main_t *vat)
{
  return -1;
}

static int
api_app_add_cert_key_pair (vat_main_t *vat)
{
  return -1;
}

static int
api_session_rules_dump (vat_main_t *vam)
{
  vl_api_session_rules_dump_t *mp;
  vl_api_control_ping_t *mp_ping;
  int ret;

  if (!vam->json_output)
    {
      print (vam->ofp, "%=20s", "Session Rules");
    }

  M (SESSION_RULES_DUMP, mp);
  /* send it... */
  S (mp);

  /* Use a control ping for synchronization */
  PING (&session_test_main, mp_ping);
  S (mp_ping);

  /* Wait for a reply... */
  W (ret);
  return ret;
}

static void
vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t *mp)
{
  vat_main_t *vam = &vat_main;
  fib_prefix_t lcl, rmt;

  ip_prefix_decode (&mp->lcl, &lcl);
  ip_prefix_decode (&mp->rmt, &rmt);

  if (lcl.fp_proto == FIB_PROTOCOL_IP4)
    {
      print (vam->ofp,
	     "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
	     clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
	     mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
	     clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
	     &rmt.fp_addr.ip4, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
	     clib_net_to_host_u32 (mp->action_index), mp->tag);
    }
  else
    {
      print (vam->ofp,
	     "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
	     clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
	     mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
	     clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
	     &rmt.fp_addr.ip6, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
	     clib_net_to_host_u32 (mp->action_index), mp->tag);
    }
}

static void
vl_api_app_namespace_add_del_reply_t_handler (
  vl_api_app_namespace_add_del_reply_t *mp)
{
  vat_main_t *vam = &vat_main;
  i32 retval = ntohl (mp->retval);
  if (vam->async_mode)
    {
      vam->async_errors += (retval < 0);
    }
  else
    {
      vam->retval = retval;
      if (retval == 0)
	errmsg ("app ns index %d\n", ntohl (mp->appns_index));
      vam->result_ready = 1;
    }
}

static void
vl_api_app_namespace_add_del_v2_reply_t_handler (
  vl_api_app_namespace_add_del_v2_reply_t *vat)
{
}

static void
vl_api_app_worker_add_del_reply_t_handler (
  vl_api_app_worker_add_del_reply_t *vat)
{
}

static int
api_app_namespace_add_del_v2 (vat_main_t *vat)
{
  return -1;
}

static int
api_session_enable_disable (vat_main_t *vat)
{
  return -1;
}

static int
api_app_worker_add_del (vat_main_t *vat)
{
  return -1;
}

static int
api_application_tls_key_add (vat_main_t *vat)
{
  return -1;
}

static int
api_app_namespace_add_del (vat_main_t *vam)
{
  vl_api_app_namespace_add_del_t *mp;
  unformat_input_t *i = vam->input;
  u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
  u32 sw_if_index, ip4_fib_id, ip6_fib_id;
  u64 secret;
  int ret;

  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (i, "id %_%v%_", &ns_id))
	;
      else if (unformat (i, "secret %lu", &secret))
	secret_set = 1;
      else if (unformat (i, "sw_if_index %d", &sw_if_index))
	sw_if_index_set = 1;
      else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
	;
      else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
	;
      else
	break;
    }
  if (!ns_id || !secret_set || !sw_if_index_set)
    {
      errmsg ("namespace id, secret and sw_if_index must be set");
      return -99;
    }
  if (vec_len (ns_id) > 64)
    {
      errmsg ("namespace id too long");
      return -99;
    }
  M (APP_NAMESPACE_ADD_DEL, mp);

  vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
  mp->secret = clib_host_to_net_u64 (secret);
  mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
  mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
  mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
  vec_free (ns_id);
  S (mp);
  W (ret);
  return ret;
}

static int
api_application_tls_cert_add (vat_main_t *vat)
{
  return -1;
}

static void
vl_api_app_namespace_add_del_v3_reply_t_handler (
  vl_api_app_namespace_add_del_v3_reply_t *mp)
{
}

static int
api_app_namespace_add_del_v3 (vat_main_t *vat)
{
  return -1;
}

static int
api_session_sapi_enable_disable (vat_main_t *vat)
{
  return -1;
}

#include <vnet/session/session.api_test.c>

/*
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
; dpo_id_t dpo = DPO_INVALID; fib_table_find_or_create_and_lock(FIB_PROTOCOL_MPLS, MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_BIER); /* * stack the entry on the forwarding chain prodcued by the * path-list via the ECMP tables. */ fib_path_list_contribute_forwarding(bt->bt_pl, FIB_FORW_CHAIN_TYPE_BIER, FIB_PATH_LIST_FWD_FLAG_COLLAPSE, &dpo); mpls_fib_index = fib_table_find(FIB_PROTOCOL_MPLS, MPLS_FIB_DEFAULT_TABLE_ID); bt->bt_lfei = fib_table_entry_special_dpo_add(mpls_fib_index, &pfx, FIB_SOURCE_BIER, FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); dpo_reset(&dpo); } } static bier_table_t * bier_table_find (const bier_table_id_t *bti) { uword *p; u32 key; key = bier_table_mk_key(bti); p = hash_get(bier_tables_by_key, key); if (NULL != p) { return (bier_table_get(p[0])); } return (NULL); } static bier_table_t * bier_table_mk_ecmp (index_t bti) { fib_route_path_t *rpaths; fib_node_index_t pli; bier_table_t *bt; int ii; rpaths = NULL; bt = bier_table_get(bti); vec_validate(rpaths, BIER_N_ECMP_TABLES-1); vec_foreach_index(ii, rpaths) { rpaths[ii].frp_bier_tbl = bt->bt_id; rpaths[ii].frp_bier_tbl.bti_ecmp = ii; rpaths[ii].frp_flags = FIB_ROUTE_PATH_BIER_TABLE; } /* * no oppotunity to share, this the resolving ECMP tables are unique * to this table. * no need to be a child of the path list, we can do nothing with any * notifications it would generate [not that it will]. */ pli = fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF, rpaths); fib_path_list_lock(pli); /* * constructing the path-list will have created many more BIER tables, * so this main table will no doubt have re-alloc. */ bt = bier_table_get(bti); bt->bt_pl = pli; vec_free(rpaths); return (bt); } static index_t bier_table_create (const bier_table_id_t *btid, mpls_label_t local_label) { /* * add a new table */ bier_table_t *bt; index_t bti; u32 key; key = bier_table_mk_key(btid); pool_get_aligned(bier_table_pool, bt, CLIB_CACHE_LINE_BYTES); bier_table_init(bt, btid, local_label); hash_set(bier_tables_by_key, key, bier_table_get_index(bt)); bti = bier_table_get_index(bt); if (bier_table_is_main(bt)) { bt = bier_table_mk_ecmp(bti); /* * add whichever mpls-fib or bift we need */ if (local_label != MPLS_LABEL_INVALID) { bt->bt_ll = local_label; bier_table_mk_lfib(bt); } else { bier_table_mk_bift(bt); } } return (bti); } index_t bier_table_lock (const bier_table_id_t *btid) { bier_table_t *bt; index_t bti; bt = bier_table_find(btid); if (NULL == bt) { bti = bier_table_create(btid, MPLS_LABEL_INVALID); bt = bier_table_get(bti); } else { bti = bier_table_get_index(bt); } bier_table_lock_i(bt); return (bti); } index_t bier_table_add_or_lock (const bier_table_id_t *btid, mpls_label_t local_label) { bier_table_t *bt; index_t bti; bt = bier_table_find(btid); if (NULL != bt) { /* * modify an existing table. * change the lfib entry to the new local label */ if (bier_table_is_main(bt)) { /* * remove the mpls-fib or bift entry */ if (MPLS_LABEL_INVALID != bt->bt_ll) { bier_table_rm_lfib(bt); } else { bier_table_rm_bift(bt); } /* * reset */ bt->bt_ll = MPLS_LABEL_INVALID; /* * add whichever mpls-fib or bift we need */ if (local_label != MPLS_LABEL_INVALID) { bt->bt_ll = local_label; bier_table_mk_lfib(bt); } else { bier_table_mk_bift(bt); } } bti = bier_table_get_index(bt); } else { bti = bier_table_create(btid, local_label); bt = bier_table_get(bti); } bier_table_lock_i(bt); return (bti); } index_t bier_table_ecmp_create_and_lock (const bier_table_id_t *btid) { return (bier_table_add_or_lock(btid, MPLS_LABEL_INVALID)); } void bier_table_ecmp_unlock (index_t bti) { bier_table_unlock_i(bier_table_get(bti)); } static void bier_table_dpo_lock (dpo_id_t *dpo) { } static void bier_table_dpo_unlock (dpo_id_t *dpo) { } static void bier_table_dpo_mem_show (void) { fib_show_memory_usage("BIER-table", pool_elts(bier_table_pool), pool_len(bier_table_pool), sizeof(bier_table_t)); } static u8 * format_bier_table_dpo (u8 *s, va_list *ap) { index_t bti = va_arg(*ap, index_t); bier_table_t *bt; bt = bier_table_get(bti); return (format(s, "[%U]", format_bier_table_id, &bt->bt_id)); } const static dpo_vft_t bier_table_dpo_vft = { .dv_lock = bier_table_dpo_lock, .dv_unlock = bier_table_dpo_unlock, .dv_format = format_bier_table_dpo, .dv_mem_show = bier_table_dpo_mem_show, }; const static char *const bier_table_mpls_nodes[] = { "bier-input", NULL }; const static char * const * const bier_table_nodes[DPO_PROTO_NUM] = { [DPO_PROTO_BIER] = bier_table_mpls_nodes, }; static clib_error_t * bier_table_module_init (vlib_main_t *vm) { dpo_register(DPO_BIER_TABLE, &bier_table_dpo_vft, bier_table_nodes); return (NULL); } VLIB_INIT_FUNCTION (bier_table_module_init); const bier_table_id_t * bier_table_get_id (index_t bti) { bier_table_t *bt; bt = bier_table_get(bti); return (&bt->bt_id); } static void bier_table_insert (bier_table_t *bt, bier_bp_t bp, index_t bei) { bt->bt_entries[BIER_BP_TO_INDEX(bp)] = bei; } static void bier_table_remove (bier_table_t *bt, bier_bp_t bp) { bt->bt_entries[BIER_BP_TO_INDEX(bp)] = INDEX_INVALID; } void bier_table_route_path_update_i (const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps, u8 is_replace) { index_t bfmi, bti, bei, *bfmip, *bfmis = NULL; fib_route_path_t *brp; bier_table_t *bt; bt = bier_table_find(btid); if (NULL == bt) { return; } bti = bier_table_get_index(bt); bei = bier_table_lookup(bt, bp); /* * set the FIB index in the path to the BIER table index */ vec_foreach(brp, brps) { /* * First use the path to find or construct an FMask object * via the next-hop */ bfmi = bier_fmask_db_find_or_create_and_lock(bti, brp); vec_add1(bfmis, bfmi); /* * then modify the path to resolve via this fmask object * and use it to resolve the BIER entry. */ brp->frp_flags = FIB_ROUTE_PATH_BIER_FMASK; brp->frp_bier_fmask = bfmi; } if (INDEX_INVALID == bei) { bei = bier_entry_create(bti, bp); bier_table_insert(bt, bp, bei); } if (is_replace) { bier_entry_path_update(bei, brps); } else { fib_route_path_t *t_paths = NULL; vec_foreach(brp, brps) { vec_add1(t_paths, *brp); bier_entry_path_add(bei, t_paths); vec_reset_length(t_paths); } vec_free(t_paths); } vec_foreach(bfmip, bfmis) { bier_fmask_unlock(*bfmip); } vec_free(bfmis); } void bier_table_route_path_update (const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps) { bier_table_route_path_update_i(btid, bp, brps, 1); } void bier_table_route_path_add (const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps) { bier_table_route_path_update_i(btid, bp, brps, 0); } void bier_table_route_delete (const bier_table_id_t *btid, bier_bp_t bp) { bier_table_t *bt; index_t bei; bt = bier_table_find(btid); if (NULL == bt) { return; } bei = bier_table_lookup(bt, bp); if (INDEX_INVALID == bei) { /* no such entry */ return; } bier_table_remove(bt, bp); bier_entry_delete(bei); } void bier_table_route_path_remove (const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps) { fib_route_path_t *brp = NULL, *t_paths = NULL; index_t bfmi, bti, bei; bier_table_t *bt; u32 ii; bt = bier_table_find(btid); if (NULL == bt) { return; } bti = bier_table_get_index(bt); bei = bier_table_lookup(bt, bp); if (INDEX_INVALID == bei) { /* no such entry */ return; } /* * set the FIB index in the path to the BIER table index */ vec_foreach_index(ii, brps) { brp = &brps[ii]; bfmi = bier_fmask_db_find(bti, brp); if (INDEX_INVALID == bfmi) { /* * no matching fmask, not a path we can remove */ vec_del1(brps, ii); continue; } /* * then modify the path to resolve via this fmask object * and use it to resolve the BIER entry. */ brp->frp_flags = FIB_ROUTE_PATH_BIER_FMASK; brp->frp_bier_fmask = bfmi; } if (0 == vec_len(brps)) { return; } vec_foreach(brp, brps) { vec_add1(t_paths, *brp); if (0 == bier_entry_path_remove(bei, t_paths)) { /* 0 remaining paths */ bier_table_remove(bt, bp); bier_entry_delete(bei); break; } vec_reset_length(t_paths); } vec_free(t_paths); } void bier_table_contribute_forwarding (index_t bti, dpo_id_t *dpo) { bier_table_t *bt; bt = bier_table_get(bti); if (BIER_ECMP_TABLE_ID_MAIN == bt->bt_id.bti_ecmp) { /* * return the load-balance for the ECMP tables */ fib_path_list_contribute_forwarding(bt->bt_pl, FIB_FORW_CHAIN_TYPE_BIER, FIB_PATH_LIST_FWD_FLAG_COLLAPSE, dpo); } else { dpo_set(dpo, DPO_BIER_TABLE, DPO_PROTO_BIER, bti); } } typedef struct bier_table_ecmp_walk_ctx_t_ { bier_table_ecmp_walk_fn_t fn; void *ctx; } bier_table_ecmp_walk_ctx_t; static fib_path_list_walk_rc_t bier_table_ecmp_walk_path_list (fib_node_index_t pl_index, fib_node_index_t path_index, void *arg) { bier_table_ecmp_walk_ctx_t *ctx = arg; ctx->fn(fib_path_get_resolving_index(path_index), ctx->ctx); /* continue */ return (FIB_PATH_LIST_WALK_CONTINUE); } void bier_table_ecmp_walk (index_t bti, bier_table_ecmp_walk_fn_t fn, void *ctx) { bier_table_ecmp_walk_ctx_t ewc = { .fn = fn, .ctx = ctx, }; bier_table_t *bt; bt = bier_table_get(bti); fib_path_list_walk(bt->bt_pl, bier_table_ecmp_walk_path_list, &ewc); } void bier_table_ecmp_set_fmask (index_t bti, bier_bp_t bp, index_t bfmi) { bier_table_t *bt; bt = bier_table_get(bti); /* * we hold a lock for fmasks in the table */ bier_fmask_lock(bfmi); bier_fmask_unlock(bt->bt_fmasks[BIER_BP_TO_INDEX(bp)]); bt->bt_fmasks[BIER_BP_TO_INDEX(bp)] = bfmi; } u8 * format_bier_table_entry (u8 *s, va_list *ap) { index_t bti = va_arg(*ap, index_t); bier_bp_t bp = va_arg(*ap, bier_bp_t); bier_table_t *bt; bt = bier_table_get(bti); if (bier_table_is_main(bt)) { index_t bei; bei = bier_table_lookup(bier_table_get(bti), bp); if (INDEX_INVALID != bei) { s = format(s, "%U", format_bier_entry, bei, BIER_SHOW_DETAIL); } } else { index_t bfmi; bfmi = bier_table_fwd_lookup(bier_table_get(bti), bp); if (INDEX_INVALID != bfmi) { s = format(s, "%U", format_bier_fmask, bfmi, BIER_SHOW_DETAIL); } } return (s); } u8 * format_bier_table (u8 *s, va_list *ap) { index_t bti = va_arg(*ap, index_t); bier_show_flags_t flags = va_arg(*ap, bier_show_flags_t); bier_table_t *bt; if (pool_is_free_index(bier_table_pool, bti)) { return (format(s, "No BIER table %d", bti)); } bt = bier_table_get(bti); s = format(s, "[@%d] bier-table:[%U local-label:%U", bti, format_bier_table_id, &bt->bt_id, format_mpls_unicast_label, bt->bt_ll); if (flags & BIER_SHOW_DETAIL) { s = format(s, " locks:%d", bt->bt_locks); } s = format(s, "]"); if (flags & BIER_SHOW_DETAIL) { if (bier_table_is_main(bt)) { index_t *bei; vec_foreach (bei, bt->bt_entries) { if (INDEX_INVALID != *bei) { s = format(s, "\n%U", format_bier_entry, *bei, 2); } } } else { u32 ii; vec_foreach_index (ii, bt->bt_fmasks) { if (INDEX_INVALID != bt->bt_fmasks[ii]) { s = format(s, "\n bp:%d\n %U", ii, format_bier_fmask, bt->bt_fmasks[ii], 2); } } } } return (s); } void bier_table_show_all (vlib_main_t * vm, bier_show_flags_t flags) { if (!pool_elts(bier_table_pool)) { vlib_cli_output (vm, "No BIER tables"); } else { int ii; pool_foreach_index(ii, bier_table_pool, ({ vlib_cli_output (vm, "%U", format_bier_table, ii, flags); })); } } void bier_tables_walk (bier_tables_walk_fn_t fn, void *ctx) { ASSERT(0); } void bier_table_walk (const bier_table_id_t *bti, bier_table_walk_fn_t fn, void *ctx) { bier_table_t *bt; bier_entry_t *be; index_t *bei; bt = bier_table_find(bti); if (NULL == bt) { return; } vec_foreach (bei, bt->bt_entries) { if (INDEX_INVALID != *bei) { be = bier_entry_get(*bei); fn(bt, be, ctx); } } }