FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
fib_path_ext.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/mpls/mpls.h>
18 #include <vnet/dpo/load_balance.h>
19 #include <vnet/dpo/drop_dpo.h>
20 
21 #include "fib_path_ext.h"
22 #include "fib_path.h"
23 #include "fib_path_list.h"
24 #include "fib_internal.h"
25 
26 u8 *
27 format_fib_path_ext (u8 * s, va_list * args)
28 {
29  fib_path_ext_t *path_ext;
30 
31  path_ext = va_arg (*args, fib_path_ext_t *);
32 
33  s = format(s, "path:%d label:%U",
34  path_ext->fpe_path_index,
36  path_ext->fpe_path.frp_label);
37 
38  return (s);
39 }
40 
41 int
43  const fib_route_path_t *rpath)
44 {
45  return (fib_route_path_cmp(&path_ext->fpe_path, rpath));
46 }
47 
48 static int
50  fib_node_index_t path_index,
51  void *ctx)
52 {
53  fib_path_ext_t *path_ext = ctx;
54 
55  if (!fib_path_cmp_w_route_path(path_index,
56  &path_ext->fpe_path))
57  {
58  path_ext->fpe_path_index = path_index;
59  return (0);
60  }
61  // keep going
62  return (1);
63 }
64 
65 void
67  fib_node_index_t path_list_index)
68 {
69  /*
70  * Find the path on the path list that this is an extension for
71  */
73  fib_path_list_walk(path_list_index,
75  path_ext);
76 }
77 
78 void
80  fib_node_index_t path_list_index,
81  const fib_route_path_t *rpath)
82 {
83  path_ext->fpe_path = *rpath;
85 
86  fib_path_ext_resolve(path_ext, path_list_index);
87 }
88 
91  fib_forward_chain_type_t parent_fct,
93 {
94  fib_forward_chain_type_t child_fct;
96 
97  if (!fib_path_is_resolved(path_ext->fpe_path_index))
98  return (nhs);
99 
100  /*
101  * Since we are stacking this path-extension, it must have a valid out
102  * label. From the chain type request by the child, determine what
103  * chain type we will request from the parent.
104  */
105  switch (parent_fct)
106  {
108  ASSERT(0);
109  return (nhs);
110  break;
113  if (MPLS_IETF_IMPLICIT_NULL_LABEL == path_ext->fpe_label)
114  {
115  /*
116  * implicit-null label for the eos or IP chain, need to pick up
117  * the IP adj
118  */
119  child_fct = parent_fct;
120  }
121  else
122  {
123  /*
124  * we have a label to stack. packets will thus be labelled when
125  * they encounter th child, ergo, non-eos.
126  */
128  }
129  break;
131  child_fct = parent_fct;
132  break;
133  default:
134  return (nhs);
135  break;
136  }
137 
138  dpo_id_t via_dpo = DPO_INVALID;
139 
140  /*
141  * The next object in the graph after the imposition of the label
142  * will be the DPO contributed by the path through which the packets
143  * are to be sent. We stack the MPLS Label DPO on this path DPO
144  */
146  child_fct,
147  &via_dpo);
148 
149  if (dpo_is_drop(&via_dpo) ||
150  load_balance_is_drop(&via_dpo))
151  {
152  /*
153  * don't stack a path extension on a drop. doing so will create
154  * a LB bucket entry on drop, and we will lose a percentage of traffic.
155  */
156  }
157  else
158  {
159  vec_add2(nhs, nh, 1);
161  nh->path_index = path_ext->fpe_path_index;
162  dpo_copy(&nh->path_dpo, &via_dpo);
163 
164  /*
165  * The label is stackable for this chain type
166  * construct the mpls header that will be imposed in the data-path
167  */
168  if (MPLS_IETF_IMPLICIT_NULL_LABEL != path_ext->fpe_label)
169  {
170  dpo_set(&nh->path_dpo,
173  mpls_label_dpo_create(path_ext->fpe_label,
174  (parent_fct == FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS ?
175  MPLS_NON_EOS :
176  MPLS_EOS),
177  255, 0,
178  &nh->path_dpo));
179  }
180  }
181  dpo_reset(&via_dpo);
182 
183  return (nhs);
184 }
int fib_path_is_resolved(fib_node_index_t path_index)
Definition: fib_path.c:1785
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:89
index_t mpls_label_dpo_create(mpls_label_t label, mpls_eos_bit_t eos, u8 ttl, u8 exp, const dpo_id_t *dpo)
fib_node_index_t path_index
The index of the FIB path.
Definition: load_balance.h:70
void fib_path_contribute_forwarding(fib_node_index_t path_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_path.c:1626
void fib_path_ext_resolve(fib_path_ext_t *path_ext, fib_node_index_t path_list_index)
Definition: fib_path_ext.c:66
A representation of a path as described by a route producer.
Definition: fib_types.h:283
int fib_path_ext_cmp(fib_path_ext_t *path_ext, const fib_route_path_t *rpath)
Definition: fib_path_ext.c:42
dpo_id_t path_dpo
ID of the Data-path object.
Definition: load_balance.h:65
int fib_route_path_cmp(const fib_route_path_t *rpath1, const fib_route_path_t *rpath2)
Definition: fib_types.c:177
#define MPLS_IETF_IMPLICIT_NULL_LABEL
Definition: mpls_types.h:16
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:196
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:521
void fib_path_list_walk(fib_node_index_t path_list_index, fib_path_list_walk_fn_t func, void *ctx)
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:85
static int fib_path_ext_match(fib_node_index_t pl_index, fib_node_index_t path_index, void *ctx)
Definition: fib_path_ext.c:49
void fib_path_ext_init(fib_path_ext_t *path_ext, fib_node_index_t path_list_index, const fib_route_path_t *rpath)
Definition: fib_path_ext.c:79
int load_balance_is_drop(const dpo_id_t *dpo)
Definition: load_balance.c:225
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:101
u8 * format_fib_path_ext(u8 *s, va_list *args)
Definition: fib_path_ext.c:27
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:134
#define ASSERT(truth)
mpls_label_t frp_label
The outgoing MPLS label.
Definition: fib_types.h:317
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
int fib_path_get_weight(fib_node_index_t path_index)
Definition: fib_path.c:1558
format_function_t format_mpls_unicast_label
Definition: mpls.h:165
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
unsigned char u8
Definition: types.h:56
u32 path_weight
weight for the path.
Definition: load_balance.h:75
fib_node_index_t fpe_path_index
The index of the path.
Definition: fib_path_ext.h:46
#define DPO_INVALID
An initialiser for DPos declared on the stack.
Definition: dpo.h:164
load_balance_path_t * fib_path_ext_stack(fib_path_ext_t *path_ext, fib_forward_chain_type_t parent_fct, load_balance_path_t *nhs)
Definition: fib_path_ext.c:90
One path from an [EU]CMP set that the client wants to add to a load-balance object.
Definition: load_balance.h:61
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
int dpo_is_drop(const dpo_id_t *dpo)
The Drop DPO will drop all packets, no questions asked.
Definition: drop_dpo.c:33
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:171
A path extension is a per-entry addition to the forwarigind information when packets are sent for tha...
Definition: fib_path_ext.h:32
Contribute an object that is to be used to forward non-end-of-stack MPLS packets. ...
Definition: fib_types.h:94
int fib_path_cmp_w_route_path(fib_node_index_t path_index, const fib_route_path_t *rpath)
Definition: fib_path.c:1205
fib_route_path_t fpe_path
A description of the path that is being extended.
Definition: fib_path_ext.h:39