FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
classify_dpo.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/ip/ip.h>
17 #include <vnet/dpo/classify_dpo.h>
18 #include <vnet/mpls/mpls.h>
19 
20 /*
21  * pool of all MPLS Label DPOs
22  */
24 
25 static classify_dpo_t *
27 {
28  classify_dpo_t *cd;
29  vlib_main_t *vm;
30  u8 did_barrier_sync;
31 
32  dpo_pool_barrier_sync (vm, classify_dpo_pool, did_barrier_sync);
34  dpo_pool_barrier_release (vm, did_barrier_sync);
35 
36  clib_memset(cd, 0, sizeof(*cd));
37 
38  return (cd);
39 }
40 
41 static index_t
43 {
44  return (cd - classify_dpo_pool);
45 }
46 
47 index_t
50 {
51  classify_dpo_t *cd;
52 
53  cd = classify_dpo_alloc();
54  cd->cd_proto = proto;
56 
57  return (classify_dpo_get_index(cd));
58 }
59 
60 u8*
61 format_classify_dpo (u8 *s, va_list *args)
62 {
63  index_t index = va_arg (*args, index_t);
64  CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
65  classify_dpo_t *cd;
66 
67  cd = classify_dpo_get(index);
68 
69  return (format(s, "%U-classify:[%d]:table:%d",
71  index, cd->cd_table_index));
72 }
73 
74 static void
76 {
77  classify_dpo_t *cd;
78 
79  cd = classify_dpo_get(dpo->dpoi_index);
80 
81  cd->cd_locks++;
82 }
83 
84 static void
86 {
87  classify_dpo_t *cd;
88 
89  cd = classify_dpo_get(dpo->dpoi_index);
90 
91  cd->cd_locks--;
92 
93  if (0 == cd->cd_locks)
94  {
96  }
97 }
98 
99 static void
101 {
102  fib_show_memory_usage("Classify",
105  sizeof(classify_dpo_t));
106 }
107 
108 const static dpo_vft_t cd_vft = {
110  .dv_unlock = classify_dpo_unlock,
111  .dv_format = format_classify_dpo,
112  .dv_mem_show = classify_dpo_mem_show,
113 };
114 
115 const static char* const classify_ip4_nodes[] =
116 {
117  "ip4-classify",
118  NULL,
119 };
120 const static char* const classify_ip6_nodes[] =
121 {
122  "ip6-classify",
123  NULL,
124 };
125 const static char* const * const classify_nodes[DPO_PROTO_NUM] =
126 {
129  [DPO_PROTO_MPLS] = NULL,
130 };
131 
132 void
134 {
136 }
classify_dpo_lock
static void classify_dpo_lock(dpo_id_t *dpo)
Definition: classify_dpo.c:75
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
classify_dpo_t::cd_locks
u16 cd_locks
Number of locks/users of the label.
Definition: classify_dpo.h:40
classify_dpo_unlock
static void classify_dpo_unlock(dpo_id_t *dpo)
Definition: classify_dpo.c:85
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
pool_get_aligned
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:249
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
classify_dpo_t::cd_table_index
u32 cd_table_index
Definition: classify_dpo.h:35
mpls.h
dpo_pool_barrier_sync
#define dpo_pool_barrier_sync(VM, P, YESNO)
Barrier sync if a dpo pool is about to expand.
Definition: dpo.h:544
classify_dpo_create
index_t classify_dpo_create(dpo_proto_t proto, u32 classify_table_index)
Definition: classify_dpo.c:48
classify_ip6_nodes
const static char *const classify_ip6_nodes[]
Definition: classify_dpo.c:120
classify_dpo_module_init
void classify_dpo_module_init(void)
Definition: classify_dpo.c:133
classify_dpo_t
A representation of an MPLS label for imposition in the data-path.
Definition: classify_dpo.h:26
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
classify_dpo_alloc
static classify_dpo_t * classify_dpo_alloc(void)
Definition: classify_dpo.c:26
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
fib_show_memory_usage
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
Definition: fib_node.c:220
classify_dpo_t::cd_proto
dpo_proto_t cd_proto
Definition: classify_dpo.h:33
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
format_classify_dpo
u8 * format_classify_dpo(u8 *s, va_list *args)
Definition: classify_dpo.c:61
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
classify_dpo_mem_show
static void classify_dpo_mem_show(void)
Definition: classify_dpo.c:100
pool_len
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:139
index
u32 index
Definition: flow_types.api:221
format
description fragment has unexpected format
Definition: map.api:433
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
classify_dpo_get
static classify_dpo_t * classify_dpo_get(index_t index)
Definition: classify_dpo.h:54
DPO_PROTO_MPLS
@ DPO_PROTO_MPLS
Definition: dpo.h:66
ip.h
u32
unsigned int u32
Definition: types.h:88
classify_nodes
const static char *const *const classify_nodes[DPO_PROTO_NUM]
Definition: classify_dpo.c:125
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
classify_ip4_nodes
const static char *const classify_ip4_nodes[]
Definition: classify_dpo.c:115
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
format_dpo_proto
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:180
u8
unsigned char u8
Definition: types.h:56
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
classify_dpo_pool
classify_dpo_t * classify_dpo_pool
Definition: classify_dpo.c:23
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
DPO_CLASSIFY
@ DPO_CLASSIFY
Definition: dpo.h:115
classify_dpo_get_index
static index_t classify_dpo_get_index(classify_dpo_t *cd)
Definition: classify_dpo.c:42
cd_vft
const static dpo_vft_t cd_vft
Definition: classify_dpo.c:108
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
classify_dpo.h
dpo_register
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:329
dpo_pool_barrier_release
#define dpo_pool_barrier_release(VM, YESNO)
Release barrier sync after dpo pool expansion.
Definition: dpo.h:568
classify_table_index
u32 classify_table_index
Definition: fib_types.api:68