FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
map_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/map/map_dpo.h>
18 
19 /**
20  * pool of all MPLS Label DPOs
21  */
23 
24 /**
25  * The register MAP DPO type
26  */
29 
30 static map_dpo_t *
32 {
33  map_dpo_t *md;
34 
35  pool_get_aligned(map_dpo_pool, md, CLIB_CACHE_LINE_BYTES);
36  memset(md, 0, sizeof(*md));
37 
38  return (md);
39 }
40 
41 static index_t
43 {
44  return (md - map_dpo_pool);
45 }
46 
47 void
49  u32 domain_index,
50  dpo_id_t *dpo)
51 {
52  map_dpo_t *md;
53 
54  md = map_dpo_alloc();
55  md->md_domain = domain_index;
56  md->md_proto = dproto;
57 
58  dpo_set(dpo,
60  dproto,
61  map_dpo_get_index(md));
62 }
63 
64 void
66  u32 domain_index,
67  dpo_id_t *dpo)
68 {
69  map_dpo_t *md;
70 
71  md = map_dpo_alloc();
72  md->md_domain = domain_index;
73  md->md_proto = dproto;
74 
75  dpo_set(dpo,
77  dproto,
78  map_dpo_get_index(md));
79 }
80 
81 
82 u8*
83 format_map_dpo (u8 *s, va_list *args)
84 {
85  index_t index = va_arg (*args, index_t);
86  CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
87  map_dpo_t *md;
88 
89  md = map_dpo_get(index);
90 
91  return (format(s, "map:[%d]:%U domain:%d",
92  index,
94  md->md_domain));
95 }
96 
97 u8*
98 format_map_t_dpo (u8 *s, va_list *args)
99 {
100  index_t index = va_arg (*args, index_t);
101  CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
102  map_dpo_t *md;
103 
104  md = map_dpo_get(index);
105 
106  return (format(s, "map-t:[%d]:%U domain:%d",
107  index,
109  md->md_domain));
110 }
111 
112 
113 static void
115 {
116  map_dpo_t *md;
117 
118  md = map_dpo_get(dpo->dpoi_index);
119 
120  md->md_locks++;
121 }
122 
123 static void
125 {
126  map_dpo_t *md;
127 
128  md = map_dpo_get(dpo->dpoi_index);
129 
130  md->md_locks--;
131 
132  if (0 == md->md_locks)
133  {
134  pool_put(map_dpo_pool, md);
135  }
136 }
137 
138 const static dpo_vft_t md_vft = {
140  .dv_unlock = map_dpo_unlock,
141  .dv_format = format_map_dpo,
142 };
143 
144 const static char* const map_ip4_nodes[] =
145 {
146  "ip4-map",
147  NULL,
148 };
149 const static char* const map_ip6_nodes[] =
150 {
151  "ip6-map",
152  NULL,
153 };
154 
155 const static char* const * const map_nodes[DPO_PROTO_NUM] =
156 {
159  [DPO_PROTO_MPLS] = NULL,
160 };
161 
162 const static dpo_vft_t md_t_vft = {
164  .dv_unlock = map_dpo_unlock,
165  .dv_format = format_map_t_dpo,
166 };
167 
168 const static char* const map_t_ip4_nodes[] =
169 {
170  "ip4-map-t",
171  NULL,
172 };
173 const static char* const map_t_ip6_nodes[] =
174 {
175  "ip6-map-t",
176  NULL,
177 };
178 
179 const static char* const * const map_t_nodes[DPO_PROTO_NUM] =
180 {
183  [DPO_PROTO_MPLS] = NULL,
184 };
185 
186 void
188 {
191 }
static map_dpo_t * map_dpo_get(index_t index)
Definition: map_dpo.h:60
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:327
static const char *const map_t_ip6_nodes[]
Definition: map_dpo.c:173
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:322
#define NULL
Definition: clib.h:55
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
map_dpo_t * map_dpo_pool
pool of all MPLS Label DPOs
Definition: map_dpo.c:22
void map_dpo_create(dpo_proto_t dproto, u32 domain_index, dpo_id_t *dpo)
Definition: map_dpo.c:48
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
static const char *const map_ip4_nodes[]
Definition: map_dpo.c:144
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static map_dpo_t * map_dpo_alloc(void)
Definition: map_dpo.c:31
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:258
u8 * format_map_t_dpo(u8 *s, va_list *args)
Definition: map_dpo.c:98
dpo_proto_t md_proto
The dat-plane protocol.
Definition: map_dpo.h:30
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
u8 * format_map_dpo(u8 *s, va_list *args)
Definition: map_dpo.c:83
static void map_dpo_lock(dpo_id_t *dpo)
Definition: map_dpo.c:114
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:214
void map_t_dpo_create(dpo_proto_t dproto, u32 domain_index, dpo_id_t *dpo)
Definition: map_dpo.c:65
static const char *const map_ip6_nodes[]
Definition: map_dpo.c:149
void map_dpo_module_init(void)
Definition: map_dpo.c:187
static void map_dpo_unlock(dpo_id_t *dpo)
Definition: map_dpo.c:124
dpo_type_t map_dpo_type
The register MAP DPO type.
Definition: map_dpo.c:27
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
u16 md_locks
Number of locks/users of the label.
Definition: map_dpo.h:40
static const char *const map_t_ip4_nodes[]
Definition: map_dpo.c:168
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:154
A representation of a MAP DPO.
Definition: map_dpo.h:25
unsigned int u32
Definition: types.h:88
static const char *const *const map_t_nodes[DPO_PROTO_NUM]
Definition: map_dpo.c:179
static const char *const *const map_nodes[DPO_PROTO_NUM]
Definition: map_dpo.c:155
#define DPO_PROTO_NUM
Definition: dpo.h:72
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:154
unsigned char u8
Definition: types.h:56
dpo_type_t map_t_dpo_type
Definition: map_dpo.c:28
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:146
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static index_t map_dpo_get_index(map_dpo_t *md)
Definition: map_dpo.c:42
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u32 md_domain
the MAP domain index
Definition: map_dpo.h:35