FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
mfib_signal.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 
17 #include <vnet/vnet.h>
18 #include <vnet/mfib/mfib_signal.h>
19 #include <vppinfra/dlist.h>
20 
21 /**
22  * @brief Pool of signals
23  */
25 
26 /**
27  * @brief pool of dlist elements
28  */
30 
31 /**
32  * the list/set of interfaces with signals pending
33  */
34 typedef struct mfib_signal_q_t_
35 {
36  /**
37  * the dlist indext that is the head of the list
38  */
40 
41  /**
42  * Spin lock to protect the list
43  */
44  int mip_lock;
46 
47 /**
48  * @brief The pending queue of signals to deliver to the control plane
49  */
51 
52 static void
54 {
55  dlist_elt_t *head;
56  u32 hi;
57 
59  hi = head - mfib_signal_dlist_pool;
60 
63 }
64 
65 void
67 {
69 }
70 
71 static inline void
73 {
75  ;
76 }
77 
78 static inline void
80 {
82 }
83 
84 #define MFIB_SIGNAL_CRITICAL_SECTION(_body) \
85 { \
86  mfib_signal_lock_aquire(); \
87  do { \
88  _body; \
89  } while (0); \
90  mfib_signal_lock_release(); \
91 }
92 
93 int
95  u32 context)
96 {
97  u32 li, si;
98 
99  /*
100  * with the lock held, pop a signal from the q.
101  */
103  ({
106  }));
107 
108  if (~0 != li)
109  {
110  mfib_signal_t *mfs;
111  mfib_itf_t *mfi;
112  dlist_elt_t *elt;
113 
115  si = elt->value;
116 
118  mfi = mfib_itf_get(mfs->mfs_itf);
119  mfi->mfi_si = INDEX_INVALID;
122 
123 
124  vl_mfib_signal_send_one(reg, context, mfs);
125 
126  /*
127  * with the lock held, return the resoruces of the signals posted
128  */
130  ({
133  }));
134 
135  return (1);
136  }
137  return (0);
138 }
139 
140 void
142  mfib_itf_t *mfi,
143  vlib_buffer_t *b0)
144 {
145  mfib_signal_t *mfs;
146  dlist_elt_t *elt;
147  u32 si, li;
148 
150  ({
153 
154  si = mfs - mfib_signal_pool;
156 
157  elt->value = si;
158  mfi->mfi_si = li;
159 
162  li);
163  }));
164 
165  mfs->mfs_entry = mfib_entry_get_index(mfe);
166  mfs->mfs_itf = mfib_itf_get_index(mfi);
167 
168  if (NULL != b0)
169  {
170  mfs->mfs_buffer_len = b0->current_length;
171  memcpy(mfs->mfs_buffer,
175  mfs->mfs_buffer_len));
176  }
177  else
178  {
179  mfs->mfs_buffer_len = 0;
180  }
181 }
182 
183 void
185 {
186  u32 li;
187 
188  /*
189  * lock the queue to prevent further additions while we fiddle.
190  */
191  li = mfi->mfi_si;
192 
193  if (INDEX_INVALID != li)
194  {
195  /*
196  * it's in the pending q
197  */
199  ({
200  dlist_elt_t *elt;
201 
202  /*
203  * with the lock held;
204  * - remove the signal from the pending list
205  * - free up the signal and list entry obejcts
206  */
208 
212  }));
213  }
214 }
clib_dlist_remove_head
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)
Definition: dlist.h:117
clib_dlist_init
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
Definition: dlist.h:36
mfib_signal_send_one
int mfib_signal_send_one(struct vl_api_registration_ *reg, u32 context)
Definition: mfib_signal.c:94
mfib_signal_pool
static mfib_signal_t * mfib_signal_pool
Pool of signals.
Definition: mfib_signal.c:24
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
mfib_itf_t_::mfi_si
u32 mfi_si
The index of the signal in the pending list.
Definition: mfib_itf.h:45
mfib_signal_q_t_::mip_lock
int mip_lock
Spin lock to protect the list.
Definition: mfib_signal.c:44
dlist.h
mfib_signal_q_t
struct mfib_signal_q_t_ mfib_signal_q_t
the list/set of interfaces with signals pending
mfib_itf_t_::mfi_flags
mfib_itf_flags_t mfi_flags
Forwarding Flags on the entry - checked in the data-path.
Definition: mfib_itf.h:35
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
mfib_entry_get_index
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
mfib_signal_remove_itf
void mfib_signal_remove_itf(const mfib_itf_t *mfi)
Definition: mfib_signal.c:184
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
clib_atomic_release
#define clib_atomic_release(a)
Definition: atomics.h:46
mfib_signal_lock_release
static void mfib_signal_lock_release(void)
Definition: mfib_signal.c:79
mfib_signal_t_
A pair of indicies, for the entry and interface resp.
Definition: mfib_signal.h:29
mfib_signal_push
void mfib_signal_push(const mfib_entry_t *mfe, mfib_itf_t *mfi, vlib_buffer_t *b0)
Definition: mfib_signal.c:141
mfib_signal_pending
static mfib_signal_q_t mfib_signal_pending
The pending queue of signals to deliver to the control plane.
Definition: mfib_signal.c:50
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
clib_atomic_test_and_set
#define clib_atomic_test_and_set(a)
Definition: atomics.h:45
mfib_signal_lock_aquire
static void mfib_signal_lock_aquire(void)
Definition: mfib_signal.c:72
clib_dlist_remove
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
Definition: dlist.h:99
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
dlist_elt_t
Definition: dlist.h:28
mfib_signal_t_::mfs_itf
index_t mfs_itf
Definition: mfib_signal.h:32
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
mfib_signal_q_t_::mip_head
u32 mip_head
the dlist indext that is the head of the list
Definition: mfib_signal.c:39
mfib_itf_get
static mfib_itf_t * mfib_itf_get(index_t mi)
Get the MFIB interface representation.
Definition: mfib_itf.h:83
mfib_signal_module_init
void mfib_signal_module_init(void)
Definition: mfib_signal.c:66
mfib_signal_list_init
static void mfib_signal_list_init(void)
Definition: mfib_signal.c:53
mfib_signal_t_::mfs_buffer_len
u8 mfs_buffer_len
Definition: mfib_signal.h:39
u32
unsigned int u32
Definition: types.h:88
si
vnet_sw_interface_t * si
Definition: interface_output.c:398
mfib_entry_t_
An entry in a FIB table.
Definition: mfib_entry.h:32
MFIB_ITF_FLAG_SIGNAL_PRESENT
@ MFIB_ITF_FLAG_SIGNAL_PRESENT
Definition: mfib_types.h:154
elt
app_rx_mq_elt_t * elt
Definition: application.c:488
mfib_itf_t_
An interface associated with a particular MFIB entry.
Definition: mfib_itf.h:25
clib_atomic_fetch_and
#define clib_atomic_fetch_and(a, b)
Definition: atomics.h:25
mfib_signal.h
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
MFIB_SIGNAL_CRITICAL_SECTION
#define MFIB_SIGNAL_CRITICAL_SECTION(_body)
Definition: mfib_signal.c:84
clib_dlist_addhead
static void clib_dlist_addhead(dlist_elt_t *pool, u32 head_index, u32 new_index)
Definition: dlist.h:71
mfib_itf_get_index
static index_t mfib_itf_get_index(const mfib_itf_t *mfi)
Definition: mfib_itf.h:89
context
u32 context
Definition: ip.api:780
mfib_signal_dlist_pool
static dlist_elt_t * mfib_signal_dlist_pool
pool of dlist elements
Definition: mfib_signal.c:29
mfib_signal_t_::mfs_entry
fib_node_index_t mfs_entry
Definition: mfib_signal.h:31
vnet.h
mfib_signal_t_::mfs_buffer
u8 mfs_buffer[MFIB_SIGNAL_BUFFER_SIZE]
A buffer copied from the DP plane that triggered the signal.
Definition: mfib_signal.h:37
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
MFIB_SIGNAL_BUFFER_SIZE
#define MFIB_SIGNAL_BUFFER_SIZE
Definition: mfib_signal.h:24
mfib_signal_q_t_
the list/set of interfaces with signals pending
Definition: mfib_signal.c:34
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
vl_mfib_signal_send_one
void vl_mfib_signal_send_one(vl_api_registration_t *reg, u32 context, const mfib_signal_t *mfs)
Definition: ip_api.c:1278