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 "sixrd_dpo.h"
17 #include <vnet/ip/ip.h>
20 * pool of all MPLS Label DPOs
22 sixrd_dpo_t *sixrd_dpo_pool;
25 * The register SIXRD DPO type
27 dpo_type_t sixrd_dpo_type;
30 sixrd_dpo_alloc (void)
34 pool_get_aligned(sixrd_dpo_pool, sd, CLIB_CACHE_LINE_BYTES);
35 memset(sd, 0, sizeof(*sd));
41 sixrd_dpo_get_index (sixrd_dpo_t *sd)
43 return (sd - sixrd_dpo_pool);
47 sixrd_dpo_create (dpo_proto_t dproto,
53 sd = sixrd_dpo_alloc();
54 sd->sd_domain = domain_index;
55 sd->sd_proto = dproto;
60 sixrd_dpo_get_index(sd));
64 format_sixrd_dpo (u8 *s, va_list *args)
66 index_t index = va_arg (*args, index_t);
67 CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
70 sd = sixrd_dpo_get(index);
72 return (format(s, "sixrd:[%d]:%U domain:%d",
74 format_dpo_proto, sd->sd_proto,
80 sixrd_dpo_lock (dpo_id_t *dpo)
84 sd = sixrd_dpo_get(dpo->dpoi_index);
90 sixrd_dpo_unlock (dpo_id_t *dpo)
94 sd = sixrd_dpo_get(dpo->dpoi_index);
98 if (0 == sd->sd_locks)
100 pool_put(sixrd_dpo_pool, sd);
104 const static dpo_vft_t sd_vft = {
105 .dv_lock = sixrd_dpo_lock,
106 .dv_unlock = sixrd_dpo_unlock,
107 .dv_format = format_sixrd_dpo,
110 const static char* const sixrd_ip4_nodes[] =
115 const static char* const sixrd_ip6_nodes[] =
121 const static char* const * const sixrd_nodes[DPO_PROTO_NUM] =
123 [DPO_PROTO_IP4] = sixrd_ip4_nodes,
124 [DPO_PROTO_IP6] = sixrd_ip6_nodes,
125 [DPO_PROTO_MPLS] = NULL,
129 sixrd_dpo_module_init (void)
131 sixrd_dpo_type = dpo_register_new_type(&sd_vft, sixrd_nodes);