FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
receive_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  * @brief
17  * The data-path object representing receiveing the packet, i.e. it's for-us
18  */
19 #include <vlib/vlib.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/dpo/receive_dpo.h>
22 
23 /**
24  * @brief pool of all receive DPOs
25  */
27 
28 int
30 {
31  return (dpo->dpoi_type == DPO_RECEIVE);
32 }
33 
34 static receive_dpo_t *
36 {
37  receive_dpo_t *rd;
38  vlib_main_t *vm;
39  u8 did_barrier_sync;
40 
41  dpo_pool_barrier_sync (vm, receive_dpo_pool, did_barrier_sync);
43  dpo_pool_barrier_release (vm, did_barrier_sync);
44 
45  clib_memset(rd, 0, sizeof(*rd));
46 
47  return (rd);
48 }
49 
50 static receive_dpo_t *
52 {
53  ASSERT(DPO_RECEIVE == dpo->dpoi_type);
54 
55  return (receive_dpo_get(dpo->dpoi_index));
56 }
57 
58 
59 /*
60  * receive_dpo_add_or_lock
61  *
62  * The next_hop address here is used for source address selection in the DP.
63  * The local adj is added to an interface's receive prefix, the next-hop
64  * passed here is the local prefix on the same interface.
65  */
66 void
69  const ip46_address_t *nh_addr,
70  dpo_id_t *dpo)
71 {
72  receive_dpo_t *rd;
73 
74  rd = receive_dpo_alloc();
75 
77  if (NULL != nh_addr)
78  {
79  rd->rd_addr = *nh_addr;
80  }
81 
83 }
84 
85 static void
87 {
88  receive_dpo_t *rd;
89 
90  rd = receive_dpo_get_from_dpo(dpo);
91  rd->rd_locks++;
92 }
93 
94 static void
96 {
97  receive_dpo_t *rd;
98 
99  rd = receive_dpo_get_from_dpo(dpo);
100  rd->rd_locks--;
101 
102  if (0 == rd->rd_locks)
103  {
105  }
106 }
107 
108 static u8*
109 format_receive_dpo (u8 *s, va_list *ap)
110 {
111  CLIB_UNUSED(index_t index) = va_arg(*ap, index_t);
112  CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
113  vnet_main_t * vnm = vnet_get_main();
114  receive_dpo_t *rd;
115 
117  {
118  return (format(s, "dpo-receive DELETED"));
119  }
120 
121  rd = receive_dpo_get(index);
122 
123  if (~0 != rd->rd_sw_if_index)
124  {
125  return (format(s, "dpo-receive: %U on %U",
129  }
130  else
131  {
132  return (format(s, "dpo-receive"));
133  }
134 }
135 
136 static void
138 {
139  fib_show_memory_usage("Receive",
142  sizeof(receive_dpo_t));
143 }
144 
145 const static dpo_vft_t receive_vft = {
147  .dv_unlock = receive_dpo_unlock,
148  .dv_format = format_receive_dpo,
149  .dv_mem_show = receive_dpo_mem_show,
150 };
151 
152 /**
153  * @brief The per-protocol VLIB graph nodes that are assigned to a receive
154  * object.
155  *
156  * this means that these graph nodes are ones from which a receive is the
157  * parent object in the DPO-graph.
158  */
159 const static char* const receive_ip4_nodes[] =
160 {
161  "ip4-local",
162  NULL,
163 };
164 const static char* const receive_ip6_nodes[] =
165 {
166  "ip6-local",
167  NULL,
168 };
169 
170 const static char* const * const receive_nodes[DPO_PROTO_NUM] =
171 {
174  [DPO_PROTO_MPLS] = NULL,
175 };
176 
177 void
179 {
181 }
receive_dpo_module_init
void receive_dpo_module_init(void)
Definition: receive_dpo.c:178
vlib.h
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
receive_dpo_get
static receive_dpo_t * receive_dpo_get(index_t index)
Definition: receive_dpo.h:65
receive_dpo_alloc
static receive_dpo_t * receive_dpo_alloc(void)
Definition: receive_dpo.c:35
receive_dpo_mem_show
static void receive_dpo_mem_show(void)
Definition: receive_dpo.c:137
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
dpo_id_t_::dpoi_type
dpo_type_t dpoi_type
the type
Definition: dpo.h:178
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
dpo_is_receive
int dpo_is_receive(const dpo_id_t *dpo)
Definition: receive_dpo.c:29
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
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
receive_dpo_t_::rd_sw_if_index
u32 rd_sw_if_index
The Software interface index on which traffic is received.
Definition: receive_dpo.h:37
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
DPO_RECEIVE
@ DPO_RECEIVE
Definition: dpo.h:112
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
receive_dpo.h
receive_ip4_nodes
const static char *const receive_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a receive object.
Definition: receive_dpo.c:159
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
receive_nodes
const static char *const *const receive_nodes[DPO_PROTO_NUM]
Definition: receive_dpo.c:170
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
receive_dpo_t_::rd_locks
u16 rd_locks
number oflocks.
Definition: receive_dpo.h:47
dpo_vft_t_::dv_lock
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:428
receive_dpo_pool
receive_dpo_t * receive_dpo_pool
The data-path object representing receiveing the packet, i.e.
Definition: receive_dpo.c:26
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
receive_dpo_t_
The data-path object representing receiveing the packet, i.e.
Definition: receive_dpo.h:26
vnet_main_t
Definition: vnet.h:76
pool_len
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:139
index
u32 index
Definition: flow_types.api:221
receive_dpo_lock
static void receive_dpo_lock(dpo_id_t *dpo)
Definition: receive_dpo.c:86
receive_vft
const static dpo_vft_t receive_vft
Definition: receive_dpo.c:145
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
format_receive_dpo
static u8 * format_receive_dpo(u8 *s, va_list *ap)
Definition: receive_dpo.c:109
format_ip46_address
format_function_t format_ip46_address
Definition: ip46_address.h:50
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
DPO_PROTO_MPLS
@ DPO_PROTO_MPLS
Definition: dpo.h:66
ip.h
u32
unsigned int u32
Definition: types.h:88
nh_addr
vl_api_address_t nh_addr
Definition: lisp_gpe.api:222
receive_ip6_nodes
const static char *const receive_ip6_nodes[]
Definition: receive_dpo.c:164
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
receive_dpo_get_from_dpo
static receive_dpo_t * receive_dpo_get_from_dpo(const dpo_id_t *dpo)
Definition: receive_dpo.c:51
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
receive_dpo_add_or_lock
void receive_dpo_add_or_lock(dpo_proto_t proto, u32 sw_if_index, const ip46_address_t *nh_addr, dpo_id_t *dpo)
Definition: receive_dpo.c:67
dpo_vft_t_
A virtual function table regisitered for a DPO type.
Definition: dpo.h:423
u8
unsigned char u8
Definition: types.h:56
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
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
IP46_TYPE_ANY
@ IP46_TYPE_ANY
Definition: ip46_address.h:24
receive_dpo_unlock
static void receive_dpo_unlock(dpo_id_t *dpo)
Definition: receive_dpo.c:95
receive_dpo_t_::rd_addr
ip46_address_t rd_addr
The address on the receive interface.
Definition: receive_dpo.h:42
dpo_set
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:188
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:453
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