FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
sixrd_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 "sixrd_dpo.h"
17 #include <vnet/ip/ip.h>
18 
19 /**
20  * pool of all MPLS Label DPOs
21  */
23 
24 /**
25  * The register SIXRD DPO type
26  */
28 
29 static sixrd_dpo_t *
31 {
32  sixrd_dpo_t *sd;
33 
34  pool_get_aligned(sixrd_dpo_pool, sd, CLIB_CACHE_LINE_BYTES);
35  memset(sd, 0, sizeof(*sd));
36 
37  return (sd);
38 }
39 
40 static index_t
42 {
43  return (sd - sixrd_dpo_pool);
44 }
45 
46 void
48  u32 domain_index,
49  dpo_id_t *dpo)
50 {
51  sixrd_dpo_t *sd;
52 
53  sd = sixrd_dpo_alloc();
54  sd->sd_domain = domain_index;
55  sd->sd_proto = dproto;
56 
57  dpo_set(dpo,
59  dproto,
61 }
62 
63 u8*
64 format_sixrd_dpo (u8 *s, va_list *args)
65 {
66  index_t index = va_arg (*args, index_t);
67  CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
68  sixrd_dpo_t *sd;
69 
70  sd = sixrd_dpo_get(index);
71 
72  return (format(s, "sixrd:[%d]:%U domain:%d",
73  index,
75  sd->sd_domain));
76 }
77 
78 
79 static void
81 {
82  sixrd_dpo_t *sd;
83 
84  sd = sixrd_dpo_get(dpo->dpoi_index);
85 
86  sd->sd_locks++;
87 }
88 
89 static void
91 {
92  sixrd_dpo_t *sd;
93 
94  sd = sixrd_dpo_get(dpo->dpoi_index);
95 
96  sd->sd_locks--;
97 
98  if (0 == sd->sd_locks)
99  {
100  pool_put(sixrd_dpo_pool, sd);
101  }
102 }
103 
104 const static dpo_vft_t sd_vft = {
106  .dv_unlock = sixrd_dpo_unlock,
107  .dv_format = format_sixrd_dpo,
108 };
109 
110 const static char* const sixrd_ip4_nodes[] =
111 {
112  "ip4-sixrd",
113  NULL,
114 };
115 const static char* const sixrd_ip6_nodes[] =
116 {
117  "ip6-sixrd",
118  NULL,
119 };
120 
121 const static char* const * const sixrd_nodes[DPO_PROTO_NUM] =
122 {
125  [DPO_PROTO_MPLS] = NULL,
126 };
127 
128 void
130 {
132 }
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:382
static index_t sixrd_dpo_get_index(sixrd_dpo_t *sd)
Definition: sixrd_dpo.c:41
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:377
void sixrd_dpo_create(dpo_proto_t dproto, u32 domain_index, dpo_id_t *dpo)
Definition: sixrd_dpo.c:47
dpo_type_t sixrd_dpo_type
The register SIXRD DPO type.
Definition: sixrd_dpo.c:27
#define NULL
Definition: clib.h:55
static void sixrd_dpo_lock(dpo_id_t *dpo)
Definition: sixrd_dpo.c:80
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
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u32 sd_domain
the SIXRD domain index
Definition: sixrd_dpo.h:35
static const char *const sixrd_ip6_nodes[]
Definition: sixrd_dpo.c:115
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static void sixrd_dpo_unlock(dpo_id_t *dpo)
Definition: sixrd_dpo.c:90
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:322
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
static const char *const sixrd_ip4_nodes[]
Definition: sixrd_dpo.c:110
sixrd_dpo_t * sixrd_dpo_pool
pool of all MPLS Label DPOs
Definition: sixrd_dpo.c:22
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
static sixrd_dpo_t * sixrd_dpo_get(index_t index)
Definition: sixrd_dpo.h:54
dpo_proto_t sd_proto
The dat-plane protocol.
Definition: sixrd_dpo.h:30
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
u8 * format_sixrd_dpo(u8 *s, va_list *args)
Definition: sixrd_dpo.c:64
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:182
unsigned int u32
Definition: types.h:88
static sixrd_dpo_t * sixrd_dpo_alloc(void)
Definition: sixrd_dpo.c:30
#define DPO_PROTO_NUM
Definition: dpo.h:70
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:182
unsigned char u8
Definition: types.h:56
A representation of a 6RD DPO.
Definition: sixrd_dpo.h:25
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:174
static const char *const *const sixrd_nodes[DPO_PROTO_NUM]
Definition: sixrd_dpo.c:121
u16 sd_locks
Number of locks/users of the label.
Definition: sixrd_dpo.h:40
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
void sixrd_dpo_module_init(void)
Definition: sixrd_dpo.c:129