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/ip/ip.h>
17 #include <vnet/map/map_dpo.h>
20 * pool of all MPLS Label DPOs
22 map_dpo_t *map_dpo_pool;
25 * The register MAP DPO type
27 dpo_type_t map_dpo_type;
28 dpo_type_t map_t_dpo_type;
35 pool_get_aligned(map_dpo_pool, md, CLIB_CACHE_LINE_BYTES);
36 memset(md, 0, sizeof(*md));
42 map_dpo_get_index (map_dpo_t *md)
44 return (md - map_dpo_pool);
48 map_dpo_create (dpo_proto_t dproto,
55 md->md_domain = domain_index;
56 md->md_proto = dproto;
61 map_dpo_get_index(md));
65 map_t_dpo_create (dpo_proto_t dproto,
72 md->md_domain = domain_index;
73 md->md_proto = dproto;
78 map_dpo_get_index(md));
83 format_map_dpo (u8 *s, va_list *args)
85 index_t index = va_arg (*args, index_t);
86 CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
89 md = map_dpo_get(index);
91 return (format(s, "map:[%d]:%U domain:%d",
93 format_dpo_proto, md->md_proto,
98 format_map_t_dpo (u8 *s, va_list *args)
100 index_t index = va_arg (*args, index_t);
101 CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
104 md = map_dpo_get(index);
106 return (format(s, "map-t:[%d]:%U domain:%d",
108 format_dpo_proto, md->md_proto,
114 map_dpo_lock (dpo_id_t *dpo)
118 md = map_dpo_get(dpo->dpoi_index);
124 map_dpo_unlock (dpo_id_t *dpo)
128 md = map_dpo_get(dpo->dpoi_index);
132 if (0 == md->md_locks)
134 pool_put(map_dpo_pool, md);
138 const static dpo_vft_t md_vft = {
139 .dv_lock = map_dpo_lock,
140 .dv_unlock = map_dpo_unlock,
141 .dv_format = format_map_dpo,
144 const static char* const map_ip4_nodes[] =
149 const static char* const map_ip6_nodes[] =
155 const static char* const * const map_nodes[DPO_PROTO_NUM] =
157 [DPO_PROTO_IP4] = map_ip4_nodes,
158 [DPO_PROTO_IP6] = map_ip6_nodes,
159 [DPO_PROTO_MPLS] = NULL,
162 const static dpo_vft_t md_t_vft = {
163 .dv_lock = map_dpo_lock,
164 .dv_unlock = map_dpo_unlock,
165 .dv_format = format_map_t_dpo,
168 const static char* const map_t_ip4_nodes[] =
173 const static char* const map_t_ip6_nodes[] =
179 const static char* const * const map_t_nodes[DPO_PROTO_NUM] =
181 [DPO_PROTO_IP4] = map_t_ip4_nodes,
182 [DPO_PROTO_IP6] = map_t_ip6_nodes,
183 [DPO_PROTO_MPLS] = NULL,
187 map_dpo_module_init (void)
189 map_dpo_type = dpo_register_new_type(&md_vft, map_nodes);
190 map_t_dpo_type = dpo_register_new_type(&md_t_vft, map_t_nodes);