FD.io VPP  v19.04.2-12-g66b1689
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 
30  pool_get_aligned(classify_dpo_pool, cd, CLIB_CACHE_LINE_BYTES);
31  clib_memset(cd, 0, sizeof(*cd));
32 
33  return (cd);
34 }
35 
36 static index_t
38 {
39  return (cd - classify_dpo_pool);
40 }
41 
42 index_t
44  u32 classify_table_index)
45 {
46  classify_dpo_t *cd;
47 
48  cd = classify_dpo_alloc();
49  cd->cd_proto = proto;
50  cd->cd_table_index = classify_table_index;
51 
52  return (classify_dpo_get_index(cd));
53 }
54 
55 u8*
56 format_classify_dpo (u8 *s, va_list *args)
57 {
58  index_t index = va_arg (*args, index_t);
59  CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
60  classify_dpo_t *cd;
61 
62  cd = classify_dpo_get(index);
63 
64  return (format(s, "%U-classify:[%d]:table:%d",
66  index, cd->cd_table_index));
67 }
68 
69 static void
71 {
72  classify_dpo_t *cd;
73 
74  cd = classify_dpo_get(dpo->dpoi_index);
75 
76  cd->cd_locks++;
77 }
78 
79 static void
81 {
82  classify_dpo_t *cd;
83 
84  cd = classify_dpo_get(dpo->dpoi_index);
85 
86  cd->cd_locks--;
87 
88  if (0 == cd->cd_locks)
89  {
90  pool_put(classify_dpo_pool, cd);
91  }
92 }
93 
94 static void
96 {
97  fib_show_memory_usage("Classify",
98  pool_elts(classify_dpo_pool),
99  pool_len(classify_dpo_pool),
100  sizeof(classify_dpo_t));
101 }
102 
103 const static dpo_vft_t cd_vft = {
105  .dv_unlock = classify_dpo_unlock,
106  .dv_format = format_classify_dpo,
107  .dv_mem_show = classify_dpo_mem_show,
108 };
109 
110 const static char* const classify_ip4_nodes[] =
111 {
112  "ip4-classify",
113  NULL,
114 };
115 const static char* const classify_ip6_nodes[] =
116 {
117  "ip6-classify",
118  NULL,
119 };
120 const static char* const * const classify_nodes[DPO_PROTO_NUM] =
121 {
124  [DPO_PROTO_MPLS] = NULL,
125 };
126 
127 void
129 {
131 }
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
#define CLIB_UNUSED(x)
Definition: clib.h:82
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
static void classify_dpo_lock(dpo_id_t *dpo)
Definition: classify_dpo.c:70
#define NULL
Definition: clib.h:58
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:41
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static classify_dpo_t * classify_dpo_alloc(void)
Definition: classify_dpo.c:26
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
static const char *const *const classify_nodes[DPO_PROTO_NUM]
Definition: classify_dpo.c:120
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:321
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
A representation of an MPLS label for imposition in the data-path.
Definition: classify_dpo.h:26
unsigned int u32
Definition: types.h:88
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static const char *const classify_ip4_nodes[]
Definition: classify_dpo.c:110
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
index_t classify_dpo_create(dpo_proto_t proto, u32 classify_table_index)
Definition: classify_dpo.c:43
void classify_dpo_module_init(void)
Definition: classify_dpo.c:128
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
dpo_proto_t cd_proto
Definition: classify_dpo.h:33
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
static void classify_dpo_mem_show(void)
Definition: classify_dpo.c:95
u8 * format_classify_dpo(u8 *s, va_list *args)
Definition: classify_dpo.c:56
static const char *const classify_ip6_nodes[]
Definition: classify_dpo.c:115
classify_dpo_t * classify_dpo_pool
Definition: classify_dpo.c:23
#define DPO_PROTO_NUM
Definition: dpo.h:70
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:177
static classify_dpo_t * classify_dpo_get(index_t index)
Definition: classify_dpo.h:54
u16 cd_locks
Number of locks/users of the label.
Definition: classify_dpo.h:40
static void classify_dpo_unlock(dpo_id_t *dpo)
Definition: classify_dpo.c:80
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static index_t classify_dpo_get_index(classify_dpo_t *cd)
Definition: classify_dpo.c:37
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128