FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
fib_entry_src_mpls.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_types.h>
17 #include <vnet/dpo/drop_dpo.h>
18 
19 #include <vnet/fib/fib_table.h>
20 #include <vnet/fib/fib_entry.h>
21 #include <vnet/fib/fib_entry_src.h>
22 #include <vnet/fib/mpls_fib.h>
23 
24 /**
25  * Source initialisation Function
26  */
27 static void
29 {
30  mpls_eos_bit_t eos;
31 
33  src->mpls.fesm_label = MPLS_LABEL_INVALID;
34 
36  {
37  src->mpls.fesm_lfes[eos] = FIB_NODE_INDEX_INVALID;
38  }
39 }
40 
41 /**
42  * Source deinitialisation Function
43  */
44 static void
46 {
47 }
48 
49 static void
51 {
53  src->mpls.fesm_label = MPLS_LABEL_INVALID;
54 }
55 
56 static void
58  const fib_entry_t *entry,
60  fib_protocol_t proto,
61  const dpo_id_t *dpo)
62 {
63  src->fes_pl =
67 }
68 
69 static void
71  const fib_entry_t *entry,
72  const void *data)
73 {
74  fib_protocol_t payload_proto;
75  fib_node_index_t fei;
76  mpls_label_t label;
77  mpls_eos_bit_t eos;
78 
79  /*
80  * post MPLS table alloc and the possible rea-alloc of fib entrys
81  * the entry pointer will no longer be valid. so save its index
82  */
83  payload_proto = entry->fe_prefix.fp_proto;
84  fei = fib_entry_get_index(entry);
85  label = *(mpls_label_t*)data;
86 
87  if (MPLS_LABEL_INVALID == label)
88  {
89  /*
90  * removing the local label
91  */
93  {
94  fib_table_entry_delete_index(src->mpls.fesm_lfes[eos],
96  }
98  src->mpls.fesm_label = label;
99  }
100  else
101  {
102  fib_prefix_t prefix = {
104  .fp_label = label,
105  };
106  fib_node_index_t fib_index;
107  dpo_id_t dpo = DPO_INVALID;
108 
109  /*
110  * adding a new local label. make sure the MPLS fib exists.
111  */
112  if (MPLS_LABEL_INVALID == src->mpls.fesm_label)
113  {
114  fib_index =
117  }
118  else
119  {
121 
122  /*
123  * if this is a change in label, reomve the old one first
124  */
125  if (src->mpls.fesm_label != label)
126  {
128  {
129  ASSERT(FIB_NODE_INDEX_INVALID != src->mpls.fesm_lfes[eos]);
130  fib_table_entry_delete_index(src->mpls.fesm_lfes[eos],
132  }
133  }
134  }
135 
136  src->mpls.fesm_label = label;
137 
139  {
140  prefix.fp_eos = eos;
141  prefix.fp_payload_proto = fib_proto_to_dpo(payload_proto);
142 
144  (eos ?
147  &dpo);
148  src->mpls.fesm_lfes[eos] =
150  &prefix,
153  &dpo);
154  dpo_reset(&dpo);
155  }
156  }
157 }
158 
159 static const void *
161  const fib_entry_t *entry)
162 {
163  return (&(src->mpls.fesm_label));
164 }
165 
166 static u8*
168  u8* s)
169 {
170  return (format(s, "MPLS local-label:%d", src->mpls.fesm_label));
171 }
172 
173 const static fib_entry_src_vft_t mpls_src_vft = {
175  .fesv_deinit = fib_entry_src_mpls_deinit,
176  .fesv_add = fib_entry_src_mpls_add,
177  .fesv_remove = fib_entry_src_mpls_remove,
178  .fesv_format = fib_entry_src_mpls_format,
179  .fesv_set_data = fib_entry_src_mpls_set_data,
180  .fesv_get_data = fib_entry_src_mpls_get_data,
181  /*
182  * .fesv_fwd_update = fib_entry_src_mpls_fwd_update,
183  * When the forwarding for the IP entry is updated, any MPLS chains
184  * it has created are also updated. Since the MPLS entry will have already
185  * installed that chain/load-balance there is no need to update the netry
186  * FIXME: later: propagate any walk to the children of the MPLS entry. for SR
187  */
188 };
189 
190 void
192 {
193  fib_entry_src_register(FIB_SOURCE_MPLS, &mpls_src_vft);
194 }
195 
196 
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
static void fib_entry_src_mpls_remove(fib_entry_src_t *src)
fib_entry_src_init_t fesv_init
An entry in a FIB table.
Definition: fib_entry.h:373
static u8 * fib_entry_src_mpls_format(fib_entry_src_t *src, u8 *s)
static const void * fib_entry_src_mpls_get_data(fib_entry_src_t *src, const fib_entry_t *entry)
Virtual function table each FIB entry source will register.
Information related to the source of a FIB entry.
Definition: fib_entry.h:282
void fib_entry_contribute_forwarding(fib_node_index_t fib_entry_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_entry.c:391
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
dpo_proto_t fp_payload_proto
This protocol determines the payload protocol of packets that will be forwarded by this entry once th...
Definition: fib_types.h:193
static void fib_entry_src_mpls_add(fib_entry_src_t *src, const fib_entry_t *entry, fib_entry_flag_t flags, fib_protocol_t proto, const dpo_id_t *dpo)
Aggregrate type for a prefix.
Definition: fib_types.h:160
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:56
static void fib_entry_src_mpls_init(fib_entry_src_t *src)
Source initialisation Function.
MPLS label.
Definition: fib_entry.h:98
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:146
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:97
void fib_table_unlock(u32 fib_index, fib_protocol_t proto)
Take a reference counting lock on the table.
Definition: fib_table.c:1058
Definition: fib_entry.h:231
static void fib_entry_src_mpls_deinit(fib_entry_src_t *src)
Source deinitialisation Function.
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:821
Definition: fib_entry.h:267
#define MPLS_LABEL_INVALID
Definition: mpls_types.h:33
#define MPLS_FIB_DEFAULT_TABLE_ID
Definition: mpls.h:33
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
u32 mpls_fib_index_from_table_id(u32 table_id)
Definition: mpls_fib.c:78
enum fib_entry_flag_t_ fib_entry_flag_t
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:288
#define FOR_EACH_MPLS_EOS_BIT(_eos)
Definition: packet.h:45
#define ASSERT(truth)
fib_entry_src_flag_t fes_flags
Flags on the source.
Definition: fib_entry.h:299
void fib_entry_src_register(fib_source_t source, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:38
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:954
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:220
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:291
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
unsigned char u8
Definition: types.h:56
struct fib_entry_src_t_::@88::@93 mpls
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:173
static void fib_entry_src_mpls_set_data(fib_entry_src_t *src, const fib_entry_t *entry, const void *data)
Special sources.
Definition: fib_entry.h:40
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:194
Contribute an object that is to be used to forward non-end-of-stack MPLS packets. ...
Definition: fib_types.h:90
u32 flags
Definition: vhost-user.h:78
void fib_entry_src_mpls_register(void)
fib_node_index_t fib_path_list_create_special(fib_protocol_t nh_proto, fib_path_list_flags_t flags, const dpo_id_t *dpo)
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:382
mpls_eos_bit_t fp_eos
Definition: fib_types.h:187
enum mpls_eos_bit_t_ mpls_eos_bit_t