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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/mpls/mpls_types.h>
17 #include <vnet/dpo/drop_dpo.h>
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>
25 * Source initialisation Function
28 fib_entry_src_mpls_init (fib_entry_src_t *src)
32 src->fes_flags = FIB_ENTRY_FLAG_NONE;
33 src->mpls.fesm_label = MPLS_LABEL_INVALID;
35 FOR_EACH_MPLS_EOS_BIT(eos)
37 src->mpls.fesm_lfes[eos] = FIB_NODE_INDEX_INVALID;
42 * Source deinitialisation Function
45 fib_entry_src_mpls_deinit (fib_entry_src_t *src)
50 fib_entry_src_mpls_remove (fib_entry_src_t *src)
52 src->fes_pl = FIB_NODE_INDEX_INVALID;
53 src->mpls.fesm_label = MPLS_LABEL_INVALID;
57 fib_entry_src_mpls_add (fib_entry_src_t *src,
58 const fib_entry_t *entry,
59 fib_entry_flag_t flags,
64 fib_path_list_create_special(proto,
65 FIB_PATH_LIST_FLAG_DROP,
66 drop_dpo_get(fib_proto_to_dpo(proto)));
70 fib_entry_src_mpls_fwd_update (fib_entry_src_t *src,
71 const fib_entry_t *fib_entry,
72 fib_source_t best_source)
74 dpo_id_t dpo = DPO_NULL;
77 FOR_EACH_MPLS_EOS_BIT(eos)
79 fib_entry_contribute_forwarding(fib_entry_get_index(fib_entry),
81 FIB_FORW_CHAIN_TYPE_MPLS_EOS :
82 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS),
85 fib_table_entry_special_dpo_update(src->mpls.fesm_lfes[eos],
87 FIB_ENTRY_FLAG_EXCLUSIVE,
94 fib_entry_src_mpls_set_data (fib_entry_src_t *src,
95 const fib_entry_t *entry,
98 dpo_proto_t payload_proto;
104 * post MPLS table alloc and the possible rea-alloc of fib entrys
105 * the entry pointer will no longer be valid. so save its index
107 payload_proto = entry->fe_prefix.fp_proto;
108 fei = fib_entry_get_index(entry);
109 label = *(mpls_label_t*)data;
111 if (MPLS_LABEL_INVALID == label)
114 * removing the local label
116 FOR_EACH_MPLS_EOS_BIT(eos)
118 fib_table_entry_delete_index(src->mpls.fesm_lfes[eos],
121 fib_table_unlock(MPLS_FIB_DEFAULT_TABLE_ID, FIB_PROTOCOL_MPLS);
122 src->mpls.fesm_label = label;
126 fib_prefix_t prefix = {
127 .fp_proto = FIB_PROTOCOL_MPLS,
130 fib_node_index_t fib_index;
131 dpo_id_t dpo = DPO_NULL;
134 * adding a new local label. make sure the MPLS fib exists.
136 if (MPLS_LABEL_INVALID == src->mpls.fesm_label)
139 fib_table_find_or_create_and_lock(FIB_PROTOCOL_MPLS,
140 MPLS_FIB_DEFAULT_TABLE_ID);
144 fib_index = mpls_fib_index_from_table_id(MPLS_FIB_DEFAULT_TABLE_ID);
147 src->mpls.fesm_label = label;
149 FOR_EACH_MPLS_EOS_BIT(eos)
152 prefix.fp_payload_proto = fib_proto_to_dpo(payload_proto);
154 fib_entry_contribute_forwarding(fei,
156 FIB_FORW_CHAIN_TYPE_MPLS_EOS :
157 FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS),
159 src->mpls.fesm_lfes[eos] =
160 fib_table_entry_special_dpo_add(fib_index,
163 FIB_ENTRY_FLAG_EXCLUSIVE,
171 fib_entry_src_mpls_get_data (fib_entry_src_t *src,
172 const fib_entry_t *entry)
174 return (&(src->mpls.fesm_label));
178 fib_entry_src_mpls_format (fib_entry_src_t *src,
181 return (format(s, "MPLS local-label:%d", src->mpls.fesm_label));
184 const static fib_entry_src_vft_t mpls_src_vft = {
185 .fesv_init = fib_entry_src_mpls_init,
186 .fesv_deinit = fib_entry_src_mpls_deinit,
187 .fesv_add = fib_entry_src_mpls_add,
188 .fesv_remove = fib_entry_src_mpls_remove,
189 .fesv_format = fib_entry_src_mpls_format,
190 .fesv_fwd_update = fib_entry_src_mpls_fwd_update,
191 .fesv_set_data = fib_entry_src_mpls_set_data,
192 .fesv_get_data = fib_entry_src_mpls_get_data,
196 fib_entry_src_mpls_register (void)
198 fib_entry_src_register(FIB_SOURCE_MPLS, &mpls_src_vft);