Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 16 | #include <math.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 17 | #include <vlib/vlib.h> |
| 18 | #include <vnet/vnet.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 19 | #include <vppinfra/elog.h> |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 20 | #include <vnet/session/transport.h> |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 21 | #include <vnet/session/session.h> |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 22 | #include <vnet/session/application.h> |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 23 | #include <vnet/session/application_interface.h> |
Florin Coras | ba7d8f5 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 24 | #include <vnet/session/application_local.h> |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 25 | #include <vnet/session/session_debug.h> |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 26 | #include <svm/queue.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 27 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 28 | static void session_mq_accepted_reply_handler (void *data); |
| 29 | |
| 30 | static void |
| 31 | accepted_notify_cb (void *data, u32 data_len) |
| 32 | { |
| 33 | session_mq_accepted_reply_handler (data); |
| 34 | } |
| 35 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 36 | static void |
| 37 | session_mq_accepted_reply_handler (void *data) |
| 38 | { |
| 39 | session_accepted_reply_msg_t *mp = (session_accepted_reply_msg_t *) data; |
| 40 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 41 | session_state_t old_state; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 42 | app_worker_t *app_wrk; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 43 | session_t *s; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 44 | |
| 45 | /* Server isn't interested, kill the session */ |
| 46 | if (mp->retval) |
| 47 | { |
| 48 | a->app_index = mp->context; |
| 49 | a->handle = mp->handle; |
| 50 | vnet_disconnect_session (a); |
| 51 | return; |
| 52 | } |
| 53 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 54 | /* Mail this back from the main thread. We're not polling in main |
| 55 | * thread so we're using other workers for notifications. */ |
| 56 | if (vlib_num_workers () && vlib_get_thread_index () != 0 |
| 57 | && session_thread_from_handle (mp->handle) == 0) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 58 | { |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 59 | vl_api_rpc_call_main_thread (accepted_notify_cb, data, |
| 60 | sizeof (session_accepted_reply_msg_t)); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | s = session_get_from_handle_if_valid (mp->handle); |
| 65 | if (!s) |
| 66 | return; |
| 67 | |
| 68 | app_wrk = app_worker_get (s->app_wrk_index); |
| 69 | if (app_wrk->app_index != mp->context) |
| 70 | { |
| 71 | clib_warning ("app doesn't own session"); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (!session_has_transport (s)) |
| 76 | { |
| 77 | if (ct_session_connect_notify (s)) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 78 | return; |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 79 | s->session_state = SESSION_STATE_READY; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 80 | } |
| 81 | else |
| 82 | { |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 83 | old_state = s->session_state; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 84 | s->session_state = SESSION_STATE_READY; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 85 | if (!svm_fifo_is_empty (s->rx_fifo)) |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 86 | app_worker_lock_and_send_event (app_wrk, s, FIFO_EVENT_APP_RX); |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 87 | |
| 88 | /* Closed while waiting for app to reply. Resend disconnect */ |
| 89 | if (old_state >= SESSION_STATE_TRANSPORT_CLOSING) |
| 90 | { |
| 91 | application_t *app = application_get (app_wrk->app_index); |
| 92 | app->cb_fns.session_disconnect_callback (s); |
| 93 | s->session_state = old_state; |
| 94 | return; |
| 95 | } |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | static void |
| 100 | session_mq_reset_reply_handler (void *data) |
| 101 | { |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 102 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 103 | session_reset_reply_msg_t *mp; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 104 | app_worker_t *app_wrk; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 105 | session_t *s; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 106 | application_t *app; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 107 | u32 index, thread_index; |
| 108 | |
| 109 | mp = (session_reset_reply_msg_t *) data; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 110 | app = application_lookup (mp->context); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 111 | if (!app) |
| 112 | return; |
| 113 | |
| 114 | session_parse_handle (mp->handle, &index, &thread_index); |
| 115 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 116 | |
| 117 | /* Session was already closed or already cleaned up */ |
| 118 | if (!s || s->session_state != SESSION_STATE_TRANSPORT_CLOSING) |
| 119 | return; |
| 120 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 121 | app_wrk = app_worker_get (s->app_wrk_index); |
| 122 | if (!app_wrk || app_wrk->app_index != app->app_index) |
| 123 | { |
| 124 | clib_warning ("App % does not own handle 0x%lx!", app->app_index, |
| 125 | mp->handle); |
| 126 | return; |
| 127 | } |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 128 | |
| 129 | /* Client objected to resetting the session, log and continue */ |
| 130 | if (mp->retval) |
| 131 | { |
| 132 | clib_warning ("client retval %d", mp->retval); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | /* This comes as a response to a reset, transport only waiting for |
| 137 | * confirmation to remove connection state, no need to disconnect */ |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 138 | a->handle = mp->handle; |
| 139 | a->app_index = app->app_index; |
| 140 | vnet_disconnect_session (a); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void |
| 144 | session_mq_disconnected_handler (void *data) |
| 145 | { |
| 146 | session_disconnected_reply_msg_t *rmp; |
| 147 | vnet_disconnect_args_t _a, *a = &_a; |
| 148 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 149 | session_disconnected_msg_t *mp; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 150 | app_worker_t *app_wrk; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 151 | session_event_t *evt; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 152 | session_t *s; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 153 | application_t *app; |
| 154 | int rv = 0; |
| 155 | |
| 156 | mp = (session_disconnected_msg_t *) data; |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 157 | if (!(s = session_get_from_handle_if_valid (mp->handle))) |
| 158 | { |
| 159 | clib_warning ("could not disconnect handle %llu", mp->handle); |
| 160 | return; |
| 161 | } |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 162 | app_wrk = app_worker_get (s->app_wrk_index); |
| 163 | app = application_lookup (mp->client_index); |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 164 | if (!(app_wrk && app && app->app_index == app_wrk->app_index)) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 165 | { |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 166 | clib_warning ("could not disconnect session: %llu app: %u", |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 167 | mp->handle, mp->client_index); |
Florin Coras | 3d0fadc | 2018-07-17 05:35:47 -0700 | [diff] [blame] | 168 | return; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 169 | } |
Florin Coras | 3d0fadc | 2018-07-17 05:35:47 -0700 | [diff] [blame] | 170 | |
| 171 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 172 | a->app_index = app_wrk->wrk_index; |
Florin Coras | 3d0fadc | 2018-07-17 05:35:47 -0700 | [diff] [blame] | 173 | rv = vnet_disconnect_session (a); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 174 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 175 | svm_msg_q_lock_and_alloc_msg_w_ring (app_wrk->event_queue, |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 176 | SESSION_MQ_CTRL_EVT_RING, |
| 177 | SVM_Q_WAIT, msg); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 178 | svm_msg_q_unlock (app_wrk->event_queue); |
| 179 | evt = svm_msg_q_msg_data (app_wrk->event_queue, msg); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 180 | clib_memset (evt, 0, sizeof (*evt)); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 181 | evt->event_type = SESSION_CTRL_EVT_DISCONNECTED_REPLY; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 182 | rmp = (session_disconnected_reply_msg_t *) evt->data; |
| 183 | rmp->handle = mp->handle; |
| 184 | rmp->context = mp->context; |
| 185 | rmp->retval = rv; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 186 | svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void |
| 190 | session_mq_disconnected_reply_handler (void *data) |
| 191 | { |
| 192 | session_disconnected_reply_msg_t *mp; |
| 193 | vnet_disconnect_args_t _a, *a = &_a; |
| 194 | application_t *app; |
| 195 | |
| 196 | mp = (session_disconnected_reply_msg_t *) data; |
| 197 | |
| 198 | /* Client objected to disconnecting the session, log and continue */ |
| 199 | if (mp->retval) |
| 200 | { |
| 201 | clib_warning ("client retval %d", mp->retval); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | /* Disconnect has been confirmed. Confirm close to transport */ |
| 206 | app = application_lookup (mp->context); |
| 207 | if (app) |
| 208 | { |
| 209 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 210 | a->app_index = app->app_index; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 211 | vnet_disconnect_session (a); |
| 212 | } |
| 213 | } |
| 214 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 215 | static void |
| 216 | session_mq_worker_update_handler (void *data) |
| 217 | { |
| 218 | session_worker_update_msg_t *mp = (session_worker_update_msg_t *) data; |
| 219 | session_worker_update_reply_msg_t *rmp; |
| 220 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 221 | app_worker_t *app_wrk; |
| 222 | u32 owner_app_wrk_map; |
| 223 | session_event_t *evt; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 224 | session_t *s; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 225 | application_t *app; |
| 226 | |
| 227 | app = application_lookup (mp->client_index); |
| 228 | if (!app) |
| 229 | return; |
| 230 | if (!(s = session_get_from_handle_if_valid (mp->handle))) |
| 231 | { |
| 232 | clib_warning ("invalid handle %llu", mp->handle); |
| 233 | return; |
| 234 | } |
| 235 | app_wrk = app_worker_get (s->app_wrk_index); |
| 236 | if (app_wrk->app_index != app->app_index) |
| 237 | { |
| 238 | clib_warning ("app %u does not own session %llu", app->app_index, |
| 239 | mp->handle); |
| 240 | return; |
| 241 | } |
| 242 | owner_app_wrk_map = app_wrk->wrk_map_index; |
| 243 | app_wrk = application_get_worker (app, mp->wrk_index); |
| 244 | |
| 245 | /* This needs to come from the new owner */ |
| 246 | if (mp->req_wrk_index == owner_app_wrk_map) |
| 247 | { |
| 248 | session_req_worker_update_msg_t *wump; |
| 249 | |
| 250 | svm_msg_q_lock_and_alloc_msg_w_ring (app_wrk->event_queue, |
| 251 | SESSION_MQ_CTRL_EVT_RING, |
| 252 | SVM_Q_WAIT, msg); |
| 253 | svm_msg_q_unlock (app_wrk->event_queue); |
| 254 | evt = svm_msg_q_msg_data (app_wrk->event_queue, msg); |
| 255 | clib_memset (evt, 0, sizeof (*evt)); |
| 256 | evt->event_type = SESSION_CTRL_EVT_REQ_WORKER_UPDATE; |
| 257 | wump = (session_req_worker_update_msg_t *) evt->data; |
| 258 | wump->session_handle = mp->handle; |
| 259 | svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | app_worker_own_session (app_wrk, s); |
| 264 | |
| 265 | /* |
| 266 | * Send reply |
| 267 | */ |
| 268 | svm_msg_q_lock_and_alloc_msg_w_ring (app_wrk->event_queue, |
| 269 | SESSION_MQ_CTRL_EVT_RING, |
| 270 | SVM_Q_WAIT, msg); |
| 271 | svm_msg_q_unlock (app_wrk->event_queue); |
| 272 | evt = svm_msg_q_msg_data (app_wrk->event_queue, msg); |
| 273 | clib_memset (evt, 0, sizeof (*evt)); |
| 274 | evt->event_type = SESSION_CTRL_EVT_WORKER_UPDATE_REPLY; |
| 275 | rmp = (session_worker_update_reply_msg_t *) evt->data; |
| 276 | rmp->handle = mp->handle; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 277 | rmp->rx_fifo = pointer_to_uword (s->rx_fifo); |
| 278 | rmp->tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 279 | rmp->segment_handle = session_segment_handle (s); |
| 280 | svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT); |
| 281 | |
| 282 | /* |
| 283 | * Retransmit messages that may have been lost |
| 284 | */ |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 285 | if (s->tx_fifo && !svm_fifo_is_empty (s->tx_fifo)) |
| 286 | session_send_io_evt_to_thread (s->tx_fifo, FIFO_EVENT_APP_TX); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 287 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 288 | if (s->rx_fifo && !svm_fifo_is_empty (s->rx_fifo)) |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 289 | app_worker_lock_and_send_event (app_wrk, s, FIFO_EVENT_APP_RX); |
| 290 | |
| 291 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING) |
| 292 | app->cb_fns.session_disconnect_callback (s); |
| 293 | } |
| 294 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 295 | vlib_node_registration_t session_queue_node; |
| 296 | |
| 297 | typedef struct |
| 298 | { |
| 299 | u32 session_index; |
| 300 | u32 server_thread_index; |
| 301 | } session_queue_trace_t; |
| 302 | |
| 303 | /* packet trace format function */ |
| 304 | static u8 * |
| 305 | format_session_queue_trace (u8 * s, va_list * args) |
| 306 | { |
| 307 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 308 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 309 | session_queue_trace_t *t = va_arg (*args, session_queue_trace_t *); |
| 310 | |
| 311 | s = format (s, "SESSION_QUEUE: session index %d, server thread index %d", |
| 312 | t->session_index, t->server_thread_index); |
| 313 | return s; |
| 314 | } |
| 315 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 316 | #define foreach_session_queue_error \ |
| 317 | _(TX, "Packets transmitted") \ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 318 | _(TIMER, "Timer events") \ |
| 319 | _(NO_BUFFER, "Out of buffers") |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 320 | |
| 321 | typedef enum |
| 322 | { |
| 323 | #define _(sym,str) SESSION_QUEUE_ERROR_##sym, |
| 324 | foreach_session_queue_error |
| 325 | #undef _ |
| 326 | SESSION_QUEUE_N_ERROR, |
| 327 | } session_queue_error_t; |
| 328 | |
| 329 | static char *session_queue_error_strings[] = { |
| 330 | #define _(sym,string) string, |
| 331 | foreach_session_queue_error |
| 332 | #undef _ |
| 333 | }; |
| 334 | |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 335 | enum |
| 336 | { |
| 337 | SESSION_TX_NO_BUFFERS = -2, |
| 338 | SESSION_TX_NO_DATA, |
| 339 | SESSION_TX_OK |
| 340 | }; |
| 341 | |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 342 | static void |
| 343 | session_tx_trace_frame (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 344 | u32 next_index, u32 * to_next, u16 n_segs, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 345 | session_t * s, u32 n_trace) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 346 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 347 | session_queue_trace_t *t; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 348 | vlib_buffer_t *b; |
| 349 | int i; |
| 350 | |
| 351 | for (i = 0; i < clib_min (n_trace, n_segs); i++) |
| 352 | { |
| 353 | b = vlib_get_buffer (vm, to_next[i - n_segs]); |
| 354 | vlib_trace_buffer (vm, node, next_index, b, 1 /* follow_chain */ ); |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 355 | t = vlib_add_trace (vm, node, b, sizeof (*t)); |
| 356 | t->session_index = s->session_index; |
| 357 | t->server_thread_index = s->thread_index; |
| 358 | } |
Florin Coras | 4df3871 | 2018-06-20 12:44:16 -0700 | [diff] [blame] | 359 | vlib_set_trace_count (vm, node, n_trace - i); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 360 | } |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 361 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 362 | always_inline void |
| 363 | session_tx_fifo_chain_tail (vlib_main_t * vm, session_tx_context_t * ctx, |
| 364 | vlib_buffer_t * b, u16 * n_bufs, u8 peek_data) |
| 365 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 366 | vlib_buffer_t *chain_b, *prev_b; |
| 367 | u32 chain_bi0, to_deq, left_from_seg; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 368 | session_manager_worker_t *wrk; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 369 | u16 len_to_deq, n_bytes_read; |
| 370 | u8 *data, j; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 371 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 372 | wrk = session_manager_get_worker (ctx->s->thread_index); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 373 | b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 374 | b->total_length_not_including_first_buffer = 0; |
| 375 | |
| 376 | chain_b = b; |
| 377 | left_from_seg = clib_min (ctx->snd_mss - b->current_length, |
| 378 | ctx->left_to_snd); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 379 | to_deq = left_from_seg; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 380 | for (j = 1; j < ctx->n_bufs_per_seg; j++) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 381 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 382 | prev_b = chain_b; |
| 383 | len_to_deq = clib_min (to_deq, ctx->deq_per_buf); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 384 | |
| 385 | *n_bufs -= 1; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 386 | chain_bi0 = wrk->tx_buffers[*n_bufs]; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 387 | chain_b = vlib_get_buffer (vm, chain_bi0); |
| 388 | chain_b->current_data = 0; |
| 389 | data = vlib_buffer_get_current (chain_b); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 390 | if (peek_data) |
| 391 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 392 | n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 393 | ctx->tx_offset, len_to_deq, data); |
| 394 | ctx->tx_offset += n_bytes_read; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 395 | } |
| 396 | else |
| 397 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 398 | if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM) |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 399 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 400 | svm_fifo_t *f = ctx->s->tx_fifo; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 401 | session_dgram_hdr_t *hdr = &ctx->hdr; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 402 | u16 deq_now; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 403 | deq_now = clib_min (hdr->data_length - hdr->data_offset, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 404 | len_to_deq); |
| 405 | n_bytes_read = svm_fifo_peek (f, hdr->data_offset, deq_now, |
| 406 | data); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 407 | ASSERT (n_bytes_read > 0); |
| 408 | |
| 409 | hdr->data_offset += n_bytes_read; |
| 410 | if (hdr->data_offset == hdr->data_length) |
shubing guo | aea5f39 | 2018-08-30 13:29:49 +0800 | [diff] [blame] | 411 | { |
| 412 | u32 offset = hdr->data_length + SESSION_CONN_HDR_LEN; |
| 413 | svm_fifo_dequeue_drop (f, offset); |
| 414 | } |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 415 | } |
| 416 | else |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 417 | n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->tx_fifo, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 418 | len_to_deq, data); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 419 | } |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 420 | ASSERT (n_bytes_read == len_to_deq); |
| 421 | chain_b->current_length = n_bytes_read; |
| 422 | b->total_length_not_including_first_buffer += chain_b->current_length; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 423 | |
| 424 | /* update previous buffer */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 425 | prev_b->next_buffer = chain_bi0; |
| 426 | prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 427 | |
| 428 | /* update current buffer */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 429 | chain_b->next_buffer = 0; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 430 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 431 | to_deq -= n_bytes_read; |
| 432 | if (to_deq == 0) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 433 | break; |
| 434 | } |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 435 | ASSERT (to_deq == 0 |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 436 | && b->total_length_not_including_first_buffer == left_from_seg); |
| 437 | ctx->left_to_snd -= left_from_seg; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 440 | always_inline void |
| 441 | session_tx_fill_buffer (vlib_main_t * vm, session_tx_context_t * ctx, |
| 442 | vlib_buffer_t * b, u16 * n_bufs, u8 peek_data) |
| 443 | { |
| 444 | u32 len_to_deq; |
| 445 | u8 *data0; |
| 446 | int n_bytes_read; |
| 447 | |
| 448 | /* |
| 449 | * Start with the first buffer in chain |
| 450 | */ |
| 451 | b->error = 0; |
| 452 | b->flags = VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 453 | b->current_data = 0; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 454 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 455 | data0 = vlib_buffer_make_headroom (b, TRANSPORT_MAX_HDRS_LEN); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 456 | len_to_deq = clib_min (ctx->left_to_snd, ctx->deq_per_first_buf); |
| 457 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 458 | if (peek_data) |
| 459 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 460 | n_bytes_read = svm_fifo_peek (ctx->s->tx_fifo, ctx->tx_offset, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 461 | len_to_deq, data0); |
| 462 | ASSERT (n_bytes_read > 0); |
| 463 | /* Keep track of progress locally, transport is also supposed to |
| 464 | * increment it independently when pushing the header */ |
| 465 | ctx->tx_offset += n_bytes_read; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 466 | } |
| 467 | else |
| 468 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 469 | if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM) |
| 470 | { |
| 471 | session_dgram_hdr_t *hdr = &ctx->hdr; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 472 | svm_fifo_t *f = ctx->s->tx_fifo; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 473 | u16 deq_now; |
| 474 | u32 offset; |
| 475 | |
| 476 | ASSERT (hdr->data_length > hdr->data_offset); |
| 477 | deq_now = clib_min (hdr->data_length - hdr->data_offset, |
| 478 | len_to_deq); |
| 479 | offset = hdr->data_offset + SESSION_CONN_HDR_LEN; |
| 480 | n_bytes_read = svm_fifo_peek (f, offset, deq_now, data0); |
| 481 | ASSERT (n_bytes_read > 0); |
| 482 | |
| 483 | if (ctx->s->session_state == SESSION_STATE_LISTENING) |
| 484 | { |
| 485 | ip_copy (&ctx->tc->rmt_ip, &hdr->rmt_ip, ctx->tc->is_ip4); |
| 486 | ctx->tc->rmt_port = hdr->rmt_port; |
| 487 | } |
| 488 | hdr->data_offset += n_bytes_read; |
| 489 | if (hdr->data_offset == hdr->data_length) |
| 490 | { |
| 491 | offset = hdr->data_length + SESSION_CONN_HDR_LEN; |
| 492 | svm_fifo_dequeue_drop (f, offset); |
| 493 | } |
| 494 | } |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 495 | else |
| 496 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 497 | n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->tx_fifo, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 498 | len_to_deq, data0); |
| 499 | ASSERT (n_bytes_read > 0); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 502 | b->current_length = n_bytes_read; |
| 503 | ctx->left_to_snd -= n_bytes_read; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 504 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 505 | /* |
| 506 | * Fill in the remaining buffers in the chain, if any |
| 507 | */ |
| 508 | if (PREDICT_FALSE (ctx->n_bufs_per_seg > 1 && ctx->left_to_snd)) |
| 509 | session_tx_fifo_chain_tail (vm, ctx, b, n_bufs, peek_data); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 510 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 511 | /* *INDENT-OFF* */ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 512 | SESSION_EVT_DBG(SESSION_EVT_DEQ, ctx->s, ({ |
| 513 | ed->data[0] = FIFO_EVENT_APP_TX; |
| 514 | ed->data[1] = ctx->max_dequeue; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 515 | ed->data[2] = len_to_deq; |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 516 | ed->data[3] = ctx->left_to_snd; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 517 | })); |
| 518 | /* *INDENT-ON* */ |
| 519 | } |
| 520 | |
| 521 | always_inline u8 |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 522 | session_tx_not_ready (session_t * s, u8 peek_data) |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 523 | { |
| 524 | if (peek_data) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 525 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 526 | /* Can retransmit for closed sessions but can't send new data if |
| 527 | * session is not ready or closed */ |
| 528 | if (s->session_state < SESSION_STATE_READY) |
| 529 | return 1; |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 530 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED) |
Florin Coras | ca1c8f3 | 2018-05-23 21:01:30 -0700 | [diff] [blame] | 531 | return 2; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 532 | } |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 533 | return 0; |
| 534 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 535 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 536 | always_inline transport_connection_t * |
| 537 | session_tx_get_transport (session_tx_context_t * ctx, u8 peek_data) |
| 538 | { |
| 539 | if (peek_data) |
| 540 | { |
| 541 | return ctx->transport_vft->get_connection (ctx->s->connection_index, |
| 542 | ctx->s->thread_index); |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | if (ctx->s->session_state == SESSION_STATE_LISTENING) |
| 547 | return ctx->transport_vft->get_listener (ctx->s->connection_index); |
| 548 | else |
| 549 | { |
| 550 | return ctx->transport_vft->get_connection (ctx->s->connection_index, |
| 551 | ctx->s->thread_index); |
| 552 | } |
| 553 | } |
| 554 | } |
Florin Coras | 6a9b68b | 2017-11-21 04:20:42 -0800 | [diff] [blame] | 555 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 556 | always_inline void |
| 557 | session_tx_set_dequeue_params (vlib_main_t * vm, session_tx_context_t * ctx, |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 558 | u32 max_segs, u8 peek_data) |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 559 | { |
| 560 | u32 n_bytes_per_buf, n_bytes_per_seg; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 561 | ctx->max_dequeue = svm_fifo_max_dequeue (ctx->s->tx_fifo); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 562 | if (peek_data) |
| 563 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 564 | /* Offset in rx fifo from where to peek data */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 565 | ctx->tx_offset = ctx->transport_vft->tx_fifo_offset (ctx->tc); |
| 566 | if (PREDICT_FALSE (ctx->tx_offset >= ctx->max_dequeue)) |
| 567 | { |
| 568 | ctx->max_len_to_snd = 0; |
| 569 | return; |
| 570 | } |
| 571 | ctx->max_dequeue -= ctx->tx_offset; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 572 | } |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 573 | else |
| 574 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 575 | if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM) |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 576 | { |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 577 | if (ctx->max_dequeue <= sizeof (ctx->hdr)) |
| 578 | { |
| 579 | ctx->max_len_to_snd = 0; |
| 580 | return; |
| 581 | } |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 582 | svm_fifo_peek (ctx->s->tx_fifo, 0, sizeof (ctx->hdr), |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 583 | (u8 *) & ctx->hdr); |
| 584 | ASSERT (ctx->hdr.data_length > ctx->hdr.data_offset); |
| 585 | ctx->max_dequeue = ctx->hdr.data_length - ctx->hdr.data_offset; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 588 | ASSERT (ctx->max_dequeue > 0); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 589 | |
| 590 | /* Ensure we're not writing more than transport window allows */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 591 | if (ctx->max_dequeue < ctx->snd_space) |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 592 | { |
| 593 | /* Constrained by tx queue. Try to send only fully formed segments */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 594 | ctx->max_len_to_snd = |
| 595 | (ctx->max_dequeue > ctx->snd_mss) ? |
| 596 | ctx->max_dequeue - ctx->max_dequeue % ctx->snd_mss : ctx->max_dequeue; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 597 | /* TODO Nagle ? */ |
| 598 | } |
| 599 | else |
| 600 | { |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 601 | /* Expectation is that snd_space0 is already a multiple of snd_mss */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 602 | ctx->max_len_to_snd = ctx->snd_space; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 603 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 604 | |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 605 | /* Check if we're tx constrained by the node */ |
| 606 | ctx->n_segs_per_evt = ceil ((f64) ctx->max_len_to_snd / ctx->snd_mss); |
| 607 | if (ctx->n_segs_per_evt > max_segs) |
| 608 | { |
| 609 | ctx->n_segs_per_evt = max_segs; |
| 610 | ctx->max_len_to_snd = max_segs * ctx->snd_mss; |
| 611 | } |
| 612 | |
Damjan Marion | 8934a04 | 2019-02-09 23:29:26 +0100 | [diff] [blame] | 613 | n_bytes_per_buf = vlib_buffer_get_default_data_size (vm); |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 614 | ASSERT (n_bytes_per_buf > TRANSPORT_MAX_HDRS_LEN); |
| 615 | n_bytes_per_seg = TRANSPORT_MAX_HDRS_LEN + ctx->snd_mss; |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 616 | ctx->n_bufs_per_seg = ceil ((f64) n_bytes_per_seg / n_bytes_per_buf); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 617 | ctx->deq_per_buf = clib_min (ctx->snd_mss, n_bytes_per_buf); |
| 618 | ctx->deq_per_first_buf = clib_min (ctx->snd_mss, |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 619 | n_bytes_per_buf - |
| 620 | TRANSPORT_MAX_HDRS_LEN); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 621 | } |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 622 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 623 | always_inline int |
| 624 | session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 625 | session_manager_worker_t * wrk, |
| 626 | session_event_t * e, int *n_tx_packets, |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 627 | u8 peek_data) |
| 628 | { |
Florin Coras | 2068fd4 | 2019-01-31 14:35:50 -0800 | [diff] [blame] | 629 | u32 next_index, next0, next1, *to_next, n_left_to_next, n_left, pbi; |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 630 | u32 n_trace = vlib_get_trace_count (vm, node), n_bufs_needed = 0; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 631 | session_manager_main_t *smm = &session_manager_main; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 632 | session_tx_context_t *ctx = &wrk->ctx; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 633 | transport_proto_t tp; |
| 634 | vlib_buffer_t *pb; |
Florin Coras | ca1c8f3 | 2018-05-23 21:01:30 -0700 | [diff] [blame] | 635 | u16 n_bufs, rv; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 636 | |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 637 | if (PREDICT_FALSE ((rv = session_tx_not_ready (ctx->s, peek_data)))) |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 638 | { |
Florin Coras | ca1c8f3 | 2018-05-23 21:01:30 -0700 | [diff] [blame] | 639 | if (rv < 2) |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 640 | vec_add1 (wrk->pending_event_vector, *e); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 641 | return SESSION_TX_NO_DATA; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 644 | next_index = smm->session_type_to_next[ctx->s->session_type]; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 645 | next0 = next1 = next_index; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 646 | |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 647 | tp = session_get_transport_proto (ctx->s); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 648 | ctx->transport_vft = transport_protocol_get_vft (tp); |
| 649 | ctx->tc = session_tx_get_transport (ctx, peek_data); |
| 650 | ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc); |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 651 | |
| 652 | if (PREDICT_FALSE (e->event_type == SESSION_IO_EVT_TX_FLUSH)) |
| 653 | { |
| 654 | if (ctx->transport_vft->flush_data) |
| 655 | ctx->transport_vft->flush_data (ctx->tc); |
| 656 | } |
| 657 | |
| 658 | ctx->snd_space = transport_connection_snd_space (ctx->tc, |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 659 | vm->clib_time. |
| 660 | last_cpu_time, |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 661 | ctx->snd_mss); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 662 | if (ctx->snd_space == 0 || ctx->snd_mss == 0) |
| 663 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 664 | vec_add1 (wrk->pending_event_vector, *e); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 665 | return SESSION_TX_NO_DATA; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* Allow enqueuing of a new event */ |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 669 | svm_fifo_unset_event (ctx->s->tx_fifo); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 670 | |
| 671 | /* Check how much we can pull. */ |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 672 | session_tx_set_dequeue_params (vm, ctx, VLIB_FRAME_SIZE - *n_tx_packets, |
| 673 | peek_data); |
| 674 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 675 | if (PREDICT_FALSE (!ctx->max_len_to_snd)) |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 676 | return SESSION_TX_NO_DATA; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 677 | |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 678 | n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg; |
Florin Coras | 2068fd4 | 2019-01-31 14:35:50 -0800 | [diff] [blame] | 679 | vec_validate_aligned (wrk->tx_buffers, n_bufs_needed - 1, |
| 680 | CLIB_CACHE_LINE_BYTES); |
| 681 | n_bufs = vlib_buffer_alloc (vm, wrk->tx_buffers, n_bufs_needed); |
| 682 | if (PREDICT_FALSE (n_bufs < n_bufs_needed)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 683 | { |
Florin Coras | 2068fd4 | 2019-01-31 14:35:50 -0800 | [diff] [blame] | 684 | if (n_bufs) |
| 685 | vlib_buffer_free (vm, wrk->tx_buffers, n_bufs); |
| 686 | vec_add1 (wrk->pending_event_vector, *e); |
| 687 | return SESSION_TX_NO_BUFFERS; |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 688 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 689 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 690 | /* |
| 691 | * Write until we fill up a frame |
| 692 | */ |
| 693 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 694 | if (PREDICT_FALSE (ctx->n_segs_per_evt > n_left_to_next)) |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 695 | { |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 696 | ctx->n_segs_per_evt = n_left_to_next; |
| 697 | ctx->max_len_to_snd = ctx->snd_mss * n_left_to_next; |
| 698 | } |
| 699 | ctx->left_to_snd = ctx->max_len_to_snd; |
| 700 | n_left = ctx->n_segs_per_evt; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 701 | |
| 702 | while (n_left >= 4) |
| 703 | { |
| 704 | vlib_buffer_t *b0, *b1; |
| 705 | u32 bi0, bi1; |
| 706 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 707 | pbi = wrk->tx_buffers[n_bufs - 3]; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 708 | pb = vlib_get_buffer (vm, pbi); |
| 709 | vlib_prefetch_buffer_header (pb, STORE); |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 710 | pbi = wrk->tx_buffers[n_bufs - 4]; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 711 | pb = vlib_get_buffer (vm, pbi); |
| 712 | vlib_prefetch_buffer_header (pb, STORE); |
| 713 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 714 | to_next[0] = bi0 = wrk->tx_buffers[--n_bufs]; |
| 715 | to_next[1] = bi1 = wrk->tx_buffers[--n_bufs]; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 716 | |
| 717 | b0 = vlib_get_buffer (vm, bi0); |
| 718 | b1 = vlib_get_buffer (vm, bi1); |
| 719 | |
| 720 | session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data); |
| 721 | session_tx_fill_buffer (vm, ctx, b1, &n_bufs, peek_data); |
| 722 | |
| 723 | ctx->transport_vft->push_header (ctx->tc, b0); |
| 724 | ctx->transport_vft->push_header (ctx->tc, b1); |
| 725 | |
| 726 | to_next += 2; |
| 727 | n_left_to_next -= 2; |
| 728 | n_left -= 2; |
| 729 | |
| 730 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0); |
| 731 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1); |
| 732 | |
| 733 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 734 | n_left_to_next, bi0, bi1, next0, |
| 735 | next1); |
| 736 | } |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 737 | while (n_left) |
| 738 | { |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 739 | vlib_buffer_t *b0; |
| 740 | u32 bi0; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 741 | |
Florin Coras | 91ca462 | 2018-06-30 11:27:59 -0700 | [diff] [blame] | 742 | if (n_left > 1) |
| 743 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 744 | pbi = wrk->tx_buffers[n_bufs - 2]; |
Florin Coras | 91ca462 | 2018-06-30 11:27:59 -0700 | [diff] [blame] | 745 | pb = vlib_get_buffer (vm, pbi); |
| 746 | vlib_prefetch_buffer_header (pb, STORE); |
| 747 | } |
| 748 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 749 | to_next[0] = bi0 = wrk->tx_buffers[--n_bufs]; |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 750 | b0 = vlib_get_buffer (vm, bi0); |
| 751 | session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data); |
Florin Coras | 81a13db | 2018-03-16 08:48:31 -0700 | [diff] [blame] | 752 | |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 753 | /* Ask transport to push header after current_length and |
| 754 | * total_length_not_including_first_buffer are updated */ |
| 755 | ctx->transport_vft->push_header (ctx->tc, b0); |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame] | 756 | |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 757 | to_next += 1; |
| 758 | n_left_to_next -= 1; |
| 759 | n_left -= 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 760 | |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 761 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 762 | |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 763 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 764 | n_left_to_next, bi0, next0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 765 | } |
Florin Coras | 66cf5e0 | 2018-06-08 09:17:39 -0700 | [diff] [blame] | 766 | |
| 767 | if (PREDICT_FALSE (n_trace > 0)) |
| 768 | session_tx_trace_frame (vm, node, next_index, to_next, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 769 | ctx->n_segs_per_evt, ctx->s, n_trace); |
Florin Coras | 2068fd4 | 2019-01-31 14:35:50 -0800 | [diff] [blame] | 770 | if (PREDICT_FALSE (n_bufs)) |
| 771 | { |
| 772 | clib_warning ("not all buffers consumed"); |
| 773 | vlib_buffer_free (vm, wrk->tx_buffers, n_bufs); |
| 774 | } |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 775 | *n_tx_packets += ctx->n_segs_per_evt; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 776 | transport_connection_update_tx_stats (ctx->tc, ctx->max_len_to_snd); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 777 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 778 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 779 | /* If we couldn't dequeue all bytes mark as partially read */ |
Florin Coras | f08f26d | 2018-05-10 13:20:47 -0700 | [diff] [blame] | 780 | ASSERT (ctx->left_to_snd == 0); |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 781 | if (ctx->max_len_to_snd < ctx->max_dequeue) |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 782 | if (svm_fifo_set_event (ctx->s->tx_fifo)) |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 783 | vec_add1 (wrk->pending_event_vector, *e); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 784 | |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 785 | if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 786 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 787 | /* Fix dgram pre header */ |
Florin Coras | 8e43d04 | 2018-05-04 15:46:57 -0700 | [diff] [blame] | 788 | if (ctx->max_len_to_snd < ctx->max_dequeue) |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 789 | svm_fifo_overwrite_head (ctx->s->tx_fifo, (u8 *) & ctx->hdr, |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 790 | sizeof (session_dgram_pre_hdr_t)); |
| 791 | /* More data needs to be read */ |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 792 | else if (svm_fifo_max_dequeue (ctx->s->tx_fifo) > 0) |
| 793 | if (svm_fifo_set_event (ctx->s->tx_fifo)) |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 794 | vec_add1 (wrk->pending_event_vector, *e); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 795 | } |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 796 | return SESSION_TX_OK; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | int |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 800 | session_tx_fifo_peek_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 801 | session_manager_worker_t * wrk, |
| 802 | session_event_t * e, int *n_tx_pkts) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 803 | { |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 804 | return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | int |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 808 | session_tx_fifo_dequeue_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 809 | session_manager_worker_t * wrk, |
| 810 | session_event_t * e, int *n_tx_pkts) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 811 | { |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 812 | return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 813 | } |
| 814 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 815 | int |
| 816 | session_tx_fifo_dequeue_internal (vlib_main_t * vm, |
| 817 | vlib_node_runtime_t * node, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 818 | session_manager_worker_t * wrk, |
| 819 | session_event_t * e, int *n_tx_pkts) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 820 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 821 | session_t *s = wrk->ctx.s; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 822 | application_t *app; |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 823 | |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 824 | if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED)) |
| 825 | return 0; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 826 | app = application_get (s->t_app_index); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 827 | svm_fifo_unset_event (s->tx_fifo); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 828 | return app->cb_fns.builtin_app_tx_callback (s); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 829 | } |
| 830 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 831 | always_inline session_t * |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 832 | session_event_get_session (session_event_t * e, u8 thread_index) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 833 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 834 | return session_get_if_valid (e->fifo->master_session_index, thread_index); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 837 | static void |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 838 | session_update_dispatch_period (session_manager_worker_t * wrk, f64 now, |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 839 | u32 thread_index) |
| 840 | { |
Florin Coras | efefc6b | 2018-11-07 12:49:19 -0800 | [diff] [blame] | 841 | if (wrk->last_tx_packets) |
Florin Coras | c44a558 | 2018-11-01 16:30:54 -0700 | [diff] [blame] | 842 | { |
| 843 | f64 sample = now - wrk->last_vlib_time; |
Florin Coras | c44a558 | 2018-11-01 16:30:54 -0700 | [diff] [blame] | 844 | wrk->dispatch_period = (wrk->dispatch_period + sample) * 0.5; |
| 845 | } |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 846 | wrk->last_vlib_time = now; |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 849 | static uword |
| 850 | session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 851 | vlib_frame_t * frame) |
| 852 | { |
| 853 | session_manager_main_t *smm = vnet_get_session_manager_main (); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 854 | u32 thread_index = vm->thread_index, n_to_dequeue, n_events; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 855 | session_manager_worker_t *wrk = &smm->wrk[thread_index]; |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 856 | session_event_t *e, *fifo_events; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 857 | svm_msg_q_msg_t _msg, *msg = &_msg; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 858 | f64 now = vlib_time_now (vm); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 859 | int n_tx_packets = 0, i, rv; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 860 | app_worker_t *app_wrk; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 861 | application_t *app; |
| 862 | svm_msg_q_t *mq; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 863 | void (*fp) (void *); |
| 864 | |
| 865 | SESSION_EVT_DBG (SESSION_EVT_POLL_GAP_TRACK, smm, thread_index); |
| 866 | |
| 867 | /* |
| 868 | * Update transport time |
| 869 | */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 870 | session_update_dispatch_period (wrk, now, thread_index); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 871 | transport_update_time (now, thread_index); |
| 872 | |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 873 | SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0); |
| 874 | |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 875 | /* Make sure postponed events are handled first */ |
| 876 | fifo_events = wrk->free_event_vector; |
| 877 | vec_append (fifo_events, wrk->postponed_event_vector); |
Florin Coras | 36ee9f1 | 2018-11-02 12:52:10 -0700 | [diff] [blame] | 878 | _vec_len (wrk->postponed_event_vector) = 0; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 879 | |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 880 | /* Try to dequeue what is available. Don't wait for lock. |
| 881 | * XXX: we may need priorities here */ |
| 882 | mq = wrk->vpp_event_queue; |
| 883 | n_to_dequeue = svm_msg_q_size (mq); |
| 884 | if (n_to_dequeue && svm_msg_q_try_lock (mq) == 0) |
| 885 | { |
| 886 | for (i = 0; i < n_to_dequeue; i++) |
| 887 | { |
| 888 | vec_add2 (fifo_events, e, 1); |
| 889 | svm_msg_q_sub_w_lock (mq, msg); |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 890 | /* Works because reply messages are smaller than a session evt. |
| 891 | * If we ever need to support bigger messages this needs to be |
| 892 | * fixed */ |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 893 | clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), sizeof (*e)); |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 894 | svm_msg_q_free_msg (mq, msg); |
| 895 | } |
| 896 | svm_msg_q_unlock (mq); |
| 897 | } |
| 898 | |
| 899 | vec_append (fifo_events, wrk->pending_event_vector); |
| 900 | vec_append (fifo_events, wrk->pending_disconnects); |
| 901 | |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 902 | _vec_len (wrk->pending_event_vector) = 0; |
Florin Coras | 36ee9f1 | 2018-11-02 12:52:10 -0700 | [diff] [blame] | 903 | _vec_len (wrk->pending_disconnects) = 0; |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 904 | |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 905 | n_events = vec_len (fifo_events); |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 906 | if (PREDICT_FALSE (!n_events)) |
| 907 | return 0; |
| 908 | |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 909 | for (i = 0; i < n_events; i++) |
| 910 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 911 | session_t *s; /* $$$ prefetch 1 ahead maybe */ |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 912 | session_event_t *e; |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 913 | u8 need_tx_ntf; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 914 | |
| 915 | e = &fifo_events[i]; |
| 916 | switch (e->event_type) |
| 917 | { |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 918 | case SESSION_IO_EVT_TX_FLUSH: |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 919 | case FIFO_EVENT_APP_TX: |
| 920 | /* Don't try to send more that one frame per dispatch cycle */ |
| 921 | if (n_tx_packets == VLIB_FRAME_SIZE) |
| 922 | { |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 923 | vec_add1 (wrk->postponed_event_vector, *e); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | |
| 927 | s = session_event_get_session (e, thread_index); |
| 928 | if (PREDICT_FALSE (!s)) |
| 929 | { |
Florin Coras | 326b81e | 2018-10-04 19:03:05 -0700 | [diff] [blame] | 930 | clib_warning ("session was freed!"); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 931 | continue; |
| 932 | } |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 933 | wrk->ctx.s = s; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 934 | /* Spray packets in per session type frames, since they go to |
| 935 | * different nodes */ |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 936 | rv = (smm->session_tx_fns[s->session_type]) (vm, node, wrk, e, |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 937 | &n_tx_packets); |
| 938 | if (PREDICT_TRUE (rv == SESSION_TX_OK)) |
| 939 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 940 | need_tx_ntf = svm_fifo_needs_tx_ntf (s->tx_fifo, |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 941 | wrk->ctx.max_len_to_snd); |
| 942 | if (PREDICT_FALSE (need_tx_ntf)) |
| 943 | session_dequeue_notify (s); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 944 | } |
| 945 | else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS)) |
| 946 | { |
| 947 | vlib_node_increment_counter (vm, node->node_index, |
| 948 | SESSION_QUEUE_ERROR_NO_BUFFER, 1); |
| 949 | continue; |
| 950 | } |
| 951 | break; |
| 952 | case FIFO_EVENT_DISCONNECT: |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 953 | s = session_get_from_handle_if_valid (e->session_handle); |
| 954 | if (PREDICT_FALSE (!s)) |
| 955 | break; |
| 956 | |
Florin Coras | e96bf63 | 2018-12-18 22:44:27 -0800 | [diff] [blame] | 957 | /* Make sure session disconnects run after the pending list is |
| 958 | * drained, i.e., postpone if the first time. If not the first |
| 959 | * and the tx queue is still not empty, try to wait for some |
| 960 | * dispatch cycles */ |
| 961 | if (!e->postponed |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 962 | || (e->postponed < 200 && svm_fifo_max_dequeue (s->tx_fifo))) |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 963 | { |
Florin Coras | e96bf63 | 2018-12-18 22:44:27 -0800 | [diff] [blame] | 964 | e->postponed += 1; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 965 | vec_add1 (wrk->pending_disconnects, *e); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 966 | continue; |
| 967 | } |
| 968 | |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 969 | session_transport_close (s); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 970 | break; |
| 971 | case FIFO_EVENT_BUILTIN_RX: |
| 972 | s = session_event_get_session (e, thread_index); |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 973 | if (PREDICT_FALSE (!s || s->session_state >= SESSION_STATE_CLOSING)) |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 974 | continue; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 975 | svm_fifo_unset_event (s->rx_fifo); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 976 | app_wrk = app_worker_get (s->app_wrk_index); |
| 977 | app = application_get (app_wrk->app_index); |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 978 | app->cb_fns.builtin_app_rx_callback (s); |
| 979 | break; |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 980 | case FIFO_EVENT_BUILTIN_TX: |
| 981 | s = session_get_from_handle_if_valid (e->session_handle); |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 982 | wrk->ctx.s = s; |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 983 | if (PREDICT_TRUE (s != 0)) |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 984 | session_tx_fifo_dequeue_internal (vm, node, wrk, e, |
| 985 | &n_tx_packets); |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 986 | break; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 987 | case FIFO_EVENT_RPC: |
| 988 | fp = e->rpc_args.fp; |
| 989 | (*fp) (e->rpc_args.arg); |
| 990 | break; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 991 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 992 | session_mq_disconnected_handler (e->data); |
| 993 | break; |
| 994 | case SESSION_CTRL_EVT_ACCEPTED_REPLY: |
| 995 | session_mq_accepted_reply_handler (e->data); |
| 996 | break; |
| 997 | case SESSION_CTRL_EVT_CONNECTED_REPLY: |
| 998 | break; |
| 999 | case SESSION_CTRL_EVT_DISCONNECTED_REPLY: |
| 1000 | session_mq_disconnected_reply_handler (e->data); |
| 1001 | break; |
| 1002 | case SESSION_CTRL_EVT_RESET_REPLY: |
| 1003 | session_mq_reset_reply_handler (e->data); |
| 1004 | break; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1005 | case SESSION_CTRL_EVT_WORKER_UPDATE: |
| 1006 | session_mq_worker_update_handler (e->data); |
| 1007 | break; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 1008 | default: |
| 1009 | clib_warning ("unhandled event type %d", e->event_type); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | _vec_len (fifo_events) = 0; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1014 | wrk->free_event_vector = fifo_events; |
Florin Coras | c44a558 | 2018-11-01 16:30:54 -0700 | [diff] [blame] | 1015 | wrk->last_tx_packets = n_tx_packets; |
Florin Coras | 0d60a0f | 2018-06-29 02:02:08 -0700 | [diff] [blame] | 1016 | |
| 1017 | vlib_node_increment_counter (vm, session_queue_node.index, |
| 1018 | SESSION_QUEUE_ERROR_TX, n_tx_packets); |
| 1019 | |
| 1020 | SESSION_EVT_DBG (SESSION_EVT_DISPATCH_END, smm, thread_index); |
| 1021 | |
| 1022 | return n_tx_packets; |
| 1023 | } |
| 1024 | |
| 1025 | /* *INDENT-OFF* */ |
| 1026 | VLIB_REGISTER_NODE (session_queue_node) = |
| 1027 | { |
| 1028 | .function = session_queue_node_fn, |
| 1029 | .name = "session-queue", |
| 1030 | .format_trace = format_session_queue_trace, |
| 1031 | .type = VLIB_NODE_TYPE_INPUT, |
| 1032 | .n_errors = ARRAY_LEN (session_queue_error_strings), |
| 1033 | .error_strings = session_queue_error_strings, |
| 1034 | .state = VLIB_NODE_STATE_DISABLED, |
| 1035 | }; |
| 1036 | /* *INDENT-ON* */ |
| 1037 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1038 | void |
| 1039 | dump_thread_0_event_queue (void) |
| 1040 | { |
| 1041 | session_manager_main_t *smm = vnet_get_session_manager_main (); |
| 1042 | vlib_main_t *vm = &vlib_global_main; |
| 1043 | u32 my_thread_index = vm->thread_index; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 1044 | session_event_t _e, *e = &_e; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1045 | svm_msg_q_ring_t *ring; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1046 | session_t *s0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1047 | svm_msg_q_msg_t *msg; |
| 1048 | svm_msg_q_t *mq; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1049 | int i, index; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1050 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1051 | mq = smm->wrk[my_thread_index].vpp_event_queue; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1052 | index = mq->q->head; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1053 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1054 | for (i = 0; i < mq->q->cursize; i++) |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1055 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1056 | msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index); |
| 1057 | ring = svm_msg_q_ring (mq, msg->ring_index); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1058 | clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1059 | |
| 1060 | switch (e->event_type) |
| 1061 | { |
| 1062 | case FIFO_EVENT_APP_TX: |
| 1063 | s0 = session_event_get_session (e, my_thread_index); |
| 1064 | fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index); |
| 1065 | break; |
| 1066 | |
| 1067 | case FIFO_EVENT_DISCONNECT: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1068 | s0 = session_get_from_handle (e->session_handle); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1069 | fformat (stdout, "[%04d] disconnect session %d\n", i, |
| 1070 | s0->session_index); |
| 1071 | break; |
| 1072 | |
| 1073 | case FIFO_EVENT_BUILTIN_RX: |
| 1074 | s0 = session_event_get_session (e, my_thread_index); |
| 1075 | fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index); |
| 1076 | break; |
| 1077 | |
| 1078 | case FIFO_EVENT_RPC: |
| 1079 | fformat (stdout, "[%04d] RPC call %llx with %llx\n", |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 1080 | i, (u64) (uword) (e->rpc_args.fp), |
| 1081 | (u64) (uword) (e->rpc_args.arg)); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1082 | break; |
| 1083 | |
| 1084 | default: |
| 1085 | fformat (stdout, "[%04d] unhandled event type %d\n", |
| 1086 | i, e->event_type); |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | index++; |
| 1091 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1092 | if (index == mq->q->maxsize) |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1093 | index = 0; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1097 | static u8 |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 1098 | session_node_cmp_event (session_event_t * e, svm_fifo_t * f) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1099 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1100 | session_t *s; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1101 | switch (e->event_type) |
| 1102 | { |
| 1103 | case FIFO_EVENT_APP_RX: |
| 1104 | case FIFO_EVENT_APP_TX: |
| 1105 | case FIFO_EVENT_BUILTIN_RX: |
| 1106 | if (e->fifo == f) |
| 1107 | return 1; |
| 1108 | break; |
| 1109 | case FIFO_EVENT_DISCONNECT: |
| 1110 | break; |
| 1111 | case FIFO_EVENT_RPC: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1112 | s = session_get_from_handle (e->session_handle); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1113 | if (!s) |
| 1114 | { |
| 1115 | clib_warning ("session has event but doesn't exist!"); |
| 1116 | break; |
| 1117 | } |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1118 | if (s->rx_fifo == f || s->tx_fifo == f) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1119 | return 1; |
| 1120 | break; |
| 1121 | default: |
| 1122 | break; |
| 1123 | } |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
| 1127 | u8 |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 1128 | session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1129 | { |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 1130 | session_event_t *pending_event_vector, *evt; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1131 | session_manager_worker_t *wrk; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1132 | int i, index, found = 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1133 | svm_msg_q_msg_t *msg; |
| 1134 | svm_msg_q_ring_t *ring; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1135 | svm_msg_q_t *mq; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1136 | u8 thread_index; |
| 1137 | |
| 1138 | ASSERT (e); |
| 1139 | thread_index = f->master_thread_index; |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1140 | wrk = session_manager_get_worker (thread_index); |
| 1141 | |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1142 | /* |
| 1143 | * Search evt queue |
| 1144 | */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1145 | mq = wrk->vpp_event_queue; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1146 | index = mq->q->head; |
| 1147 | for (i = 0; i < mq->q->cursize; i++) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1148 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1149 | msg = (svm_msg_q_msg_t *) (&mq->q->data[0] + mq->q->elsize * index); |
| 1150 | ring = svm_msg_q_ring (mq, msg->ring_index); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1151 | clib_memcpy_fast (e, svm_msg_q_msg_data (mq, msg), ring->elsize); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1152 | found = session_node_cmp_event (e, f); |
| 1153 | if (found) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1154 | return 1; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1155 | if (++index == mq->q->maxsize) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1156 | index = 0; |
| 1157 | } |
| 1158 | /* |
| 1159 | * Search pending events vector |
| 1160 | */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1161 | pending_event_vector = wrk->pending_event_vector; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1162 | vec_foreach (evt, pending_event_vector) |
| 1163 | { |
| 1164 | found = session_node_cmp_event (evt, f); |
| 1165 | if (found) |
| 1166 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1167 | clib_memcpy_fast (e, evt, sizeof (*evt)); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | return found; |
| 1172 | } |
| 1173 | |
Dave Barach | 2a86391 | 2017-11-28 10:11:42 -0500 | [diff] [blame] | 1174 | static clib_error_t * |
| 1175 | session_queue_exit (vlib_main_t * vm) |
| 1176 | { |
| 1177 | if (vec_len (vlib_mains) < 2) |
| 1178 | return 0; |
| 1179 | |
| 1180 | /* |
| 1181 | * Shut off (especially) worker-thread session nodes. |
| 1182 | * Otherwise, vpp can crash as the main thread unmaps the |
| 1183 | * API segment. |
| 1184 | */ |
| 1185 | vlib_worker_thread_barrier_sync (vm); |
| 1186 | session_node_enable_disable (0 /* is_enable */ ); |
| 1187 | vlib_worker_thread_barrier_release (vm); |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | VLIB_MAIN_LOOP_EXIT_FUNCTION (session_queue_exit); |
| 1192 | |
Florin Coras | fd542f1 | 2018-05-16 19:28:24 -0700 | [diff] [blame] | 1193 | static uword |
| 1194 | session_queue_process (vlib_main_t * vm, vlib_node_runtime_t * rt, |
| 1195 | vlib_frame_t * f) |
| 1196 | { |
| 1197 | f64 now, timeout = 1.0; |
| 1198 | uword *event_data = 0; |
| 1199 | uword event_type; |
| 1200 | |
| 1201 | while (1) |
| 1202 | { |
| 1203 | vlib_process_wait_for_event_or_clock (vm, timeout); |
| 1204 | now = vlib_time_now (vm); |
| 1205 | event_type = vlib_process_get_events (vm, (uword **) & event_data); |
| 1206 | |
| 1207 | switch (event_type) |
| 1208 | { |
| 1209 | case SESSION_Q_PROCESS_FLUSH_FRAMES: |
| 1210 | /* Flush the frames by updating all transports times */ |
| 1211 | transport_update_time (now, 0); |
| 1212 | break; |
| 1213 | case SESSION_Q_PROCESS_STOP: |
| 1214 | timeout = 100000.0; |
| 1215 | break; |
| 1216 | case ~0: |
| 1217 | /* Timed out. Update time for all transports to trigger all |
| 1218 | * outstanding retransmits. */ |
| 1219 | transport_update_time (now, 0); |
| 1220 | break; |
| 1221 | } |
| 1222 | vec_reset_length (event_data); |
| 1223 | } |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | /* *INDENT-OFF* */ |
| 1228 | VLIB_REGISTER_NODE (session_queue_process_node) = |
| 1229 | { |
| 1230 | .function = session_queue_process, |
| 1231 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1232 | .name = "session-queue-process", |
| 1233 | .state = VLIB_NODE_STATE_DISABLED, |
| 1234 | }; |
| 1235 | /* *INDENT-ON* */ |
| 1236 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1237 | /* |
| 1238 | * fd.io coding-style-patch-verification: ON |
| 1239 | * |
| 1240 | * Local Variables: |
| 1241 | * eval: (c-set-style "gnu") |
| 1242 | * End: |
| 1243 | */ |