FD.io VPP  v17.01-9-ge7dcee4
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 static receive_dpo_t *
30 {
31  receive_dpo_t *rd;
32 
33  pool_get_aligned(receive_dpo_pool, rd, CLIB_CACHE_LINE_BYTES);
34  memset(rd, 0, sizeof(*rd));
35 
36  return (rd);
37 }
38 
39 static receive_dpo_t *
41 {
42  ASSERT(DPO_RECEIVE == dpo->dpoi_type);
43 
44  return (receive_dpo_get(dpo->dpoi_index));
45 }
46 
47 
48 /*
49  * receive_dpo_add_or_lock
50  *
51  * The next_hop address here is used for source address selection in the DP.
52  * The local adj is added to an interface's receive prefix, the next-hop
53  * passed here is the local prefix on the same interface.
54  */
55 void
57  u32 sw_if_index,
58  const ip46_address_t *nh_addr,
59  dpo_id_t *dpo)
60 {
61  receive_dpo_t *rd;
62 
63  rd = receive_dpo_alloc();
64 
65  rd->rd_sw_if_index = sw_if_index;
66  if (NULL != nh_addr)
67  {
68  rd->rd_addr = *nh_addr;
69  }
70 
71  dpo_set(dpo, DPO_RECEIVE, proto, (rd - receive_dpo_pool));
72 }
73 
74 static void
76 {
77  receive_dpo_t *rd;
78 
79  rd = receive_dpo_get_from_dpo(dpo);
80  rd->rd_locks++;
81 }
82 
83 static void
85 {
86  receive_dpo_t *rd;
87 
88  rd = receive_dpo_get_from_dpo(dpo);
89  rd->rd_locks--;
90 
91  if (0 == rd->rd_locks)
92  {
93  pool_put(receive_dpo_pool, rd);
94  }
95 }
96 
97 static u8*
98 format_receive_dpo (u8 *s, va_list *ap)
99 {
100  CLIB_UNUSED(index_t index) = va_arg(*ap, index_t);
101  CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
102  vnet_main_t * vnm = vnet_get_main();
103  receive_dpo_t *rd;
104 
105  rd = receive_dpo_get(index);
106 
107  if (~0 != rd->rd_sw_if_index)
108  {
109  return (format(s, "dpo-receive: %U on %U",
113  }
114  else
115  {
116  return (format(s, "dpo-receive"));
117  }
118 }
119 
120 static void
122 {
123  fib_show_memory_usage("Receive",
124  pool_elts(receive_dpo_pool),
125  pool_len(receive_dpo_pool),
126  sizeof(receive_dpo_t));
127 }
128 
129 const static dpo_vft_t receive_vft = {
131  .dv_unlock = receive_dpo_unlock,
132  .dv_format = format_receive_dpo,
133  .dv_mem_show = receive_dpo_mem_show,
134 };
135 
136 /**
137  * @brief The per-protocol VLIB graph nodes that are assigned to a receive
138  * object.
139  *
140  * this means that these graph nodes are ones from which a receive is the
141  * parent object in the DPO-graph.
142  */
143 const static char* const receive_ip4_nodes[] =
144 {
145  "ip4-local",
146  NULL,
147 };
148 const static char* const receive_ip6_nodes[] =
149 {
150  "ip6-local",
151  NULL,
152 };
153 
154 const static char* const * const receive_nodes[DPO_PROTO_NUM] =
155 {
158  [DPO_PROTO_MPLS] = NULL,
159 };
160 
161 void
163 {
164  dpo_register(DPO_RECEIVE, &receive_vft, receive_nodes);
165 }
format_function_t format_ip46_address
Definition: format.h:61
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:327
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:56
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:322
static void receive_dpo_unlock(dpo_id_t *dpo)
Definition: receive_dpo.c:84
#define NULL
Definition: clib.h:55
static u8 * format_receive_dpo(u8 *s, va_list *ap)
Definition: receive_dpo.c:98
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
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static const char *const receive_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a receive object.
Definition: receive_dpo.c:143
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:121
static receive_dpo_t * receive_dpo_get_from_dpo(const dpo_id_t *dpo)
Definition: receive_dpo.c:40
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
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:246
void receive_dpo_module_init(void)
Definition: receive_dpo.c:162
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:221
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
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
format_function_t format_vnet_sw_interface_name
dpo_type_t dpoi_type
the type
Definition: dpo.h:142
static const char *const *const receive_nodes[DPO_PROTO_NUM]
Definition: receive_dpo.c:154
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:214
static void receive_dpo_lock(dpo_id_t *dpo)
Definition: receive_dpo.c:75
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
static receive_dpo_t * receive_dpo_alloc(void)
Definition: receive_dpo.c:29
static const char *const receive_ip6_nodes[]
Definition: receive_dpo.c:148
static receive_dpo_t * receive_dpo_get(index_t index)
Definition: receive_dpo.h:57
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
#define ASSERT(truth)
u32 rd_sw_if_index
The Software interface index on which traffic is received.
Definition: receive_dpo.h:31
unsigned int u32
Definition: types.h:88
The data-path object representing receiveing the packet, i.e.
Definition: receive_dpo.h:26
#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
receive_dpo_t * receive_dpo_pool
The data-path object representing receiveing the packet, i.e.
Definition: receive_dpo.c:26
ip46_address_t rd_addr
The address on the receive interface.
Definition: receive_dpo.h:36
static void receive_dpo_mem_show(void)
Definition: receive_dpo.c:121
u16 rd_locks
number oflocks.
Definition: receive_dpo.h:41
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109