FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
bier_update.c
Go to the documentation of this file.
1 /*
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 #include <vnet/vnet.h>
17 #include <vnet/mpls/mpls.h>
18 
19 #include <vnet/bier/bier_table.h>
20 #include <vnet/bier/bier_types.h>
21 #include <vnet/bier/bier_update.h>
22 
25  unformat_input_t * input,
26  vlib_cli_command_t * cmd)
27 {
28  u32 hdr_len, local_label;
29  clib_error_t * error = 0;
30  bier_table_id_t bti = {
32  };
33  u32 is_add = 0;
34 
35  local_label = MPLS_LABEL_INVALID;
36 
37  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
38  if (unformat (input, "del")) {
39  is_add = 0;
40  } else if (unformat (input, "add")) {
41  is_add = 1;
42  } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
43  } else if (unformat (input, "set %d", &bti.bti_set)) {
44  } else if (unformat (input, "bsl %d", &hdr_len)) {
45  } else if (unformat (input, "mpls %d", &local_label)) {
46  } else {
47  error = unformat_parse_error (input);
48  goto done;
49  }
50  }
51 
52  bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
53  // FIXME
55 
56  if (is_add)
57  {
58  bier_table_add_or_lock(&bti, local_label);
59  }
60  else
61  {
62  bier_table_unlock(&bti);
63  }
64 
65 done:
66  return (error);
67 }
68 
69 VLIB_CLI_COMMAND (bier_table_command) = {
70  .path = "bier table",
71  .short_help = "bier table [add|del] sd <sub-domain> set <SET> bsl <bit-string-length> [mpls <label>]",
72  .function = vnet_bier_table_cmd,
73 };
74 
77  unformat_input_t * input,
78  vlib_cli_command_t * cmd)
79 {
80  clib_error_t * error = NULL;
81  fib_route_path_t *brps = NULL, brp = {
82  .frp_flags = FIB_ROUTE_PATH_BIER_FMASK,
83  };
84  u32 hdr_len, payload_proto;
85  bier_table_id_t bti = {
87  };
88  bier_bp_t bp;
89  u32 add = 1;
90 
91  payload_proto = DPO_PROTO_BIER;
92 
93  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
94  if (unformat (input, "del")) {
95  add = 0;
96  } else if (unformat (input, "add")) {
97  add = 1;
98  } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
99  } else if (unformat (input, "set %d", &bti.bti_set)) {
100  } else if (unformat (input, "bsl %d", &hdr_len)) {
101  } else if (unformat (input, "bp %d", &bp)) {
102  } else if (unformat (input, "via %U",
104  &brp, &payload_proto)) {
105  } else {
106  error = unformat_parse_error (input);
107  goto done;
108  }
109  }
110 
111  vec_add1(brps, brp);
112  bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
113  // FIXME
115 
116  if (add)
117  {
118  bier_table_route_add(&bti, bp, brps);
119  }
120  else
121  {
122  bier_table_route_remove(&bti, bp, brps);
123  }
124 
125 done:
126  vec_free(brps);
127  return (error);
128 }
129 
130 VLIB_CLI_COMMAND (bier_route_command) = {
131  .path = "bier route",
132  .short_help = "bier route [add|del] sd <sud-domain> set <set> bsl <bit-string-length> bp <bit-position> via [next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]",
133  .function = vnet_bier_route_cmd,
134 };
135 
136 static clib_error_t *
138  unformat_input_t * input,
139  vlib_cli_command_t * cmd)
140 {
142  index_t bti, bei;
143  bier_bp_t bp;
144 
145  bp = BIER_BP_INVALID;
146  bti = bei = INDEX_INVALID;
147  flags = BIER_SHOW_BRIEF;
148 
149  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
150  if (unformat (input, "%d %d", &bti, &bp))
151  {
152  flags = BIER_SHOW_DETAIL;
153  }
154  else if (unformat (input, "%d", &bti))
155  {
156  flags = BIER_SHOW_DETAIL;
157  }
158  else
159  {
160  break;
161  }
162  }
163 
164  if (INDEX_INVALID == bti)
165  {
166  bier_table_show_all(vm, flags);
167  }
168  else
169  {
171  {
172  if (BIER_BP_INVALID == bp)
173  {
174  vlib_cli_output (vm, "%U", format_bier_table, bti, flags);
175  }
176  else
177  {
178  vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp);
179  }
180  }
181  }
182  return (NULL);
183 }
184 
185 VLIB_CLI_COMMAND (show_bier_fib_command, static) = {
186  .path = "show bier fib",
187  .short_help = "show bier fib [table-index] [bit-position]",
188  .function = show_bier_fib_command_fn,
189 };
A representation of a path as described by a route producer.
Definition: fib_types.h:455
u8 * format_bier_table(u8 *s, va_list *ap)
Definition: bier_table.c:741
enum bier_show_flags_t_ bier_show_flags_t
Flags to control show output.
uword unformat_fib_route_path(unformat_input_t *input, va_list *args)
Unformat a fib_route_path_t from CLI input.
Definition: fib_types.c:384
#define NULL
Definition: clib.h:55
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
The ID of a table.
Definition: bier_types.h:394
clib_error_t * vnet_bier_table_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_update.c:24
bier_table_ecmp_id_t bti_ecmp
The SUB/ECMP-ID Constructed by FIB to achieve ECMP between BFR-NBRs.
Definition: bier_types.h:414
bier_table_set_id_t bti_set
The SET-ID The control plane divdies the bit-position space into sets in the case the max bit-positio...
Definition: bier_types.h:401
unsigned int u32
Definition: types.h:88
u32 bier_bp_t
A bit positon as assigned to egress PEs.
Definition: bier_types.h:294
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
struct _unformat_input_t unformat_input_t
index_t bier_table_add_or_lock(const bier_table_id_t *btid, mpls_label_t local_label)
Definition: bier_table.c:333
void bier_table_route_add(const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps)
Definition: bier_table.c:513
u32 flags
Definition: vhost_user.h:110
u8 * format_bier_table_entry(u8 *s, va_list *ap)
Definition: bier_table.c:706
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:294
#define MPLS_LABEL_INVALID
Definition: mpls_types.h:48
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:271
#define BIER_BP_INVALID
Definition: bier_types.h:314
bier_table_t * bier_table_pool
Memory pool of all the allocated tables.
Definition: bier_table.c:32
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
void bier_table_unlock(const bier_table_id_t *bti)
Definition: bier_table.c:218
clib_error_t * vnet_bier_route_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_update.c:76
A path that resolves via a BIER F-Mask.
Definition: fib_types.h:350
#define unformat_parse_error(input)
Definition: format.h:268
bier_table_type_t bti_type
The type of the table; SPF or TE, MPLS or IPv6.
Definition: bier_types.h:424
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
bier_table_sub_domain_id_t bti_sub_domain
The Sub-Domain-ID The control plane has the configuration option to specify multiple domains or topol...
Definition: bier_types.h:408
void bier_table_show_all(vlib_main_t *vm, bier_show_flags_t flags)
Definition: bier_table.c:798
void bier_table_route_remove(const bier_table_id_t *btid, bier_bp_t bp, fib_route_path_t *brps)
Definition: bier_table.c:565
#define BIER_ECMP_TABLE_ID_MAIN
Definition of the ID of the BIER main table.
Definition: bier_types.h:389
static bier_hdr_len_id_t bier_hdr_bit_len_to_id(u32 bytes)
Definition: bier_types.h:142
static clib_error_t * show_bier_fib_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_update.c:137
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
BIER over MPLS with SPF.
Definition: bier_types.h:37
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170