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