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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <vnet/vnet.h>
18 #include <vnet/mfib/mfib_signal.h>
19 #include <vppinfra/dlist.h>
22 * @brief Pool of signals
24 static mfib_signal_t *mfib_signal_pool;
27 * @brief pool of dlist elements
29 static dlist_elt_t *mfib_signal_dlist_pool;
32 * the list/set of interfaces with signals pending
34 typedef struct mfib_signal_q_t_
37 * the dlist indext that is the head of the list
42 * Spin lock to protect the list
48 * @brief The pending queue of signals to deliver to the control plane
50 static mfib_signal_q_t mfib_signal_pending ;
53 mfib_signal_list_init (void)
58 pool_get(mfib_signal_dlist_pool, head);
59 hi = head - mfib_signal_dlist_pool;
61 mfib_signal_pending.mip_head = hi;
62 clib_dlist_init(mfib_signal_dlist_pool, hi);
66 mfib_signal_module_init (void)
68 mfib_signal_list_init();
72 mfib_signal_send_one (struct _unix_shared_memory_queue *q,
78 * with the lock held, pop a signal from the q.
80 while (__sync_lock_test_and_set (&mfib_signal_pending.mip_lock, 1))
83 li = clib_dlist_remove_head(mfib_signal_dlist_pool,
84 mfib_signal_pending.mip_head);
86 mfib_signal_pending.mip_lock = 0;
94 elt = pool_elt_at_index(mfib_signal_dlist_pool, li);
97 mfs = pool_elt_at_index(mfib_signal_pool, si);
98 mfi = mfib_itf_get(mfs->mfs_itf);
99 mfi->mfi_si = INDEX_INVALID;
100 __sync_fetch_and_and(&mfi->mfi_flags,
101 ~MFIB_ITF_FLAG_SIGNAL_PRESENT);
104 vl_mfib_signal_send_one(q, context, mfs);
107 * with the lock held, return the resoruces of the signals posted
109 while (__sync_lock_test_and_set(&mfib_signal_pending.mip_lock, 1))
112 pool_put_index(mfib_signal_pool, si);
113 pool_put_index(mfib_signal_dlist_pool, li);
115 mfib_signal_pending.mip_lock = 0;
123 mfib_signal_push (const mfib_entry_t *mfe,
131 while (__sync_lock_test_and_set (&mfib_signal_pending.mip_lock, 1))
134 pool_get(mfib_signal_pool, mfs);
135 pool_get(mfib_signal_dlist_pool, elt);
137 si = mfs - mfib_signal_pool;
138 li = elt - mfib_signal_dlist_pool;
143 clib_dlist_addhead(mfib_signal_dlist_pool,
144 mfib_signal_pending.mip_head,
147 mfib_signal_pending.mip_lock = 0;
149 mfs->mfs_entry = mfib_entry_get_index(mfe);
150 mfs->mfs_itf = mfib_itf_get_index(mfi);
154 mfs->mfs_buffer_len = b0->current_length;
155 memcpy(mfs->mfs_buffer,
156 vlib_buffer_get_current(b0),
157 (mfs->mfs_buffer_len > MFIB_SIGNAL_BUFFER_SIZE ?
158 MFIB_SIGNAL_BUFFER_SIZE :
159 mfs->mfs_buffer_len));
163 mfs->mfs_buffer_len = 0;
168 mfib_signal_remove_itf (const mfib_itf_t *mfi)
173 * lock the queue to prevent further additions while we fiddle.
177 if (INDEX_INVALID != li)
180 * it's in the pending q
182 while (__sync_lock_test_and_set (&mfib_signal_pending.mip_lock, 1))
188 * with the lock held;
189 * - remove the signal from the pending list
190 * - free up the signal and list entry obejcts
192 clib_dlist_remove(mfib_signal_dlist_pool, li);
194 elt = pool_elt_at_index(mfib_signal_dlist_pool, li);
195 pool_put_index(mfib_signal_pool, elt->value);
196 pool_put(mfib_signal_dlist_pool, elt);
199 mfib_signal_pending.mip_lock = 0;