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/dpo/classify_dpo.h>
18 #include <vnet/mpls/mpls.h>
21 * pool of all MPLS Label DPOs
23 classify_dpo_t *classify_dpo_pool;
25 static classify_dpo_t *
26 classify_dpo_alloc (void)
32 dpo_pool_barrier_sync (vm, classify_dpo_pool, did_barrier_sync);
33 pool_get_aligned(classify_dpo_pool, cd, CLIB_CACHE_LINE_BYTES);
34 dpo_pool_barrier_release (vm, did_barrier_sync);
36 clib_memset(cd, 0, sizeof(*cd));
42 classify_dpo_get_index (classify_dpo_t *cd)
44 return (cd - classify_dpo_pool);
48 classify_dpo_create (dpo_proto_t proto,
49 u32 classify_table_index)
53 cd = classify_dpo_alloc();
55 cd->cd_table_index = classify_table_index;
57 return (classify_dpo_get_index(cd));
61 format_classify_dpo (u8 *s, va_list *args)
63 index_t index = va_arg (*args, index_t);
64 CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
67 cd = classify_dpo_get(index);
69 return (format(s, "%U-classify:[%d]:table:%d",
70 format_dpo_proto, cd->cd_proto,
71 index, cd->cd_table_index));
75 classify_dpo_lock (dpo_id_t *dpo)
79 cd = classify_dpo_get(dpo->dpoi_index);
85 classify_dpo_unlock (dpo_id_t *dpo)
89 cd = classify_dpo_get(dpo->dpoi_index);
93 if (0 == cd->cd_locks)
95 pool_put(classify_dpo_pool, cd);
100 classify_dpo_mem_show (void)
102 fib_show_memory_usage("Classify",
103 pool_elts(classify_dpo_pool),
104 pool_len(classify_dpo_pool),
105 sizeof(classify_dpo_t));
108 const static dpo_vft_t cd_vft = {
109 .dv_lock = classify_dpo_lock,
110 .dv_unlock = classify_dpo_unlock,
111 .dv_format = format_classify_dpo,
112 .dv_mem_show = classify_dpo_mem_show,
115 const static char* const classify_ip4_nodes[] =
120 const static char* const classify_ip6_nodes[] =
125 const static char* const * const classify_nodes[DPO_PROTO_NUM] =
127 [DPO_PROTO_IP4] = classify_ip4_nodes,
128 [DPO_PROTO_IP6] = classify_ip6_nodes,
129 [DPO_PROTO_MPLS] = NULL,
133 classify_dpo_module_init (void)
135 dpo_register(DPO_CLASSIFY, &cd_vft, classify_nodes);