Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
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 <vnet/tcp/tcp.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 20 | #include <vppinfra/elog.h> |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 21 | #include <vnet/session/application.h> |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 22 | #include <vnet/session/session_debug.h> |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 23 | #include <vlibmemory/unix_shared_memory_queue.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 24 | |
| 25 | vlib_node_registration_t session_queue_node; |
| 26 | |
| 27 | typedef struct |
| 28 | { |
| 29 | u32 session_index; |
| 30 | u32 server_thread_index; |
| 31 | } session_queue_trace_t; |
| 32 | |
| 33 | /* packet trace format function */ |
| 34 | static u8 * |
| 35 | format_session_queue_trace (u8 * s, va_list * args) |
| 36 | { |
| 37 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 38 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 39 | session_queue_trace_t *t = va_arg (*args, session_queue_trace_t *); |
| 40 | |
| 41 | s = format (s, "SESSION_QUEUE: session index %d, server thread index %d", |
| 42 | t->session_index, t->server_thread_index); |
| 43 | return s; |
| 44 | } |
| 45 | |
| 46 | vlib_node_registration_t session_queue_node; |
| 47 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 48 | #define foreach_session_queue_error \ |
| 49 | _(TX, "Packets transmitted") \ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 50 | _(TIMER, "Timer events") \ |
| 51 | _(NO_BUFFER, "Out of buffers") |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 52 | |
| 53 | typedef enum |
| 54 | { |
| 55 | #define _(sym,str) SESSION_QUEUE_ERROR_##sym, |
| 56 | foreach_session_queue_error |
| 57 | #undef _ |
| 58 | SESSION_QUEUE_N_ERROR, |
| 59 | } session_queue_error_t; |
| 60 | |
| 61 | static char *session_queue_error_strings[] = { |
| 62 | #define _(sym,string) string, |
| 63 | foreach_session_queue_error |
| 64 | #undef _ |
| 65 | }; |
| 66 | |
| 67 | static u32 session_type_to_next[] = { |
| 68 | SESSION_QUEUE_NEXT_TCP_IP4_OUTPUT, |
| 69 | SESSION_QUEUE_NEXT_IP4_LOOKUP, |
| 70 | SESSION_QUEUE_NEXT_TCP_IP6_OUTPUT, |
| 71 | SESSION_QUEUE_NEXT_IP6_LOOKUP, |
| 72 | }; |
| 73 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 74 | always_inline void |
| 75 | session_tx_fifo_chain_tail (session_manager_main_t * smm, vlib_main_t * vm, |
| 76 | u8 thread_index, svm_fifo_t * fifo, |
| 77 | vlib_buffer_t * b0, u32 bi0, u8 n_bufs_per_seg, |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 78 | u32 left_from_seg, u32 * left_to_snd0, |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 79 | u16 * n_bufs, u32 * tx_offset, u16 deq_per_buf, |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 80 | u8 peek_data) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 81 | { |
| 82 | vlib_buffer_t *chain_b0, *prev_b0; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 83 | u32 chain_bi0, to_deq; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 84 | u16 len_to_deq0, n_bytes_read; |
| 85 | u8 *data0, j; |
| 86 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 87 | b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 88 | b0->total_length_not_including_first_buffer = 0; |
| 89 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 90 | chain_bi0 = bi0; |
| 91 | chain_b0 = b0; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 92 | to_deq = left_from_seg; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 93 | for (j = 1; j < n_bufs_per_seg; j++) |
| 94 | { |
| 95 | prev_b0 = chain_b0; |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 96 | len_to_deq0 = clib_min (to_deq, deq_per_buf); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 97 | |
| 98 | *n_bufs -= 1; |
| 99 | chain_bi0 = smm->tx_buffers[thread_index][*n_bufs]; |
| 100 | _vec_len (smm->tx_buffers[thread_index]) = *n_bufs; |
| 101 | |
| 102 | chain_b0 = vlib_get_buffer (vm, chain_bi0); |
| 103 | chain_b0->current_data = 0; |
| 104 | data0 = vlib_buffer_get_current (chain_b0); |
| 105 | if (peek_data) |
| 106 | { |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 107 | n_bytes_read = svm_fifo_peek (fifo, *tx_offset, len_to_deq0, data0); |
| 108 | *tx_offset += n_bytes_read; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 109 | } |
| 110 | else |
| 111 | { |
| 112 | n_bytes_read = svm_fifo_dequeue_nowait (fifo, len_to_deq0, data0); |
| 113 | } |
| 114 | ASSERT (n_bytes_read == len_to_deq0); |
| 115 | chain_b0->current_length = n_bytes_read; |
| 116 | b0->total_length_not_including_first_buffer += chain_b0->current_length; |
| 117 | |
| 118 | /* update previous buffer */ |
| 119 | prev_b0->next_buffer = chain_bi0; |
| 120 | prev_b0->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 121 | |
| 122 | /* update current buffer */ |
| 123 | chain_b0->next_buffer = 0; |
| 124 | |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 125 | to_deq -= n_bytes_read; |
| 126 | if (to_deq == 0) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 127 | break; |
| 128 | } |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 129 | ASSERT (to_deq == 0 |
| 130 | && b0->total_length_not_including_first_buffer == left_from_seg); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 131 | *left_to_snd0 -= left_from_seg; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 134 | always_inline int |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 135 | session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 136 | session_manager_main_t * smm, |
| 137 | session_fifo_event_t * e0, |
| 138 | stream_session_t * s0, u32 thread_index, |
| 139 | int *n_tx_packets, u8 peek_data) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 140 | { |
| 141 | u32 n_trace = vlib_get_trace_count (vm, node); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 142 | u32 left_to_snd0, max_len_to_snd0, len_to_deq0, snd_space0; |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 143 | u32 n_bufs_per_evt, n_frames_per_evt, n_bufs_per_frame; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 144 | transport_connection_t *tc0; |
| 145 | transport_proto_vft_t *transport_vft; |
| 146 | u32 next_index, next0, *to_next, n_left_to_next, bi0; |
| 147 | vlib_buffer_t *b0; |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 148 | u32 tx_offset = 0, max_dequeue0, n_bytes_per_seg, left_for_seg; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 149 | u16 snd_mss0, n_bufs_per_seg, n_bufs; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 150 | u8 *data0; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 151 | int i, n_bytes_read; |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 152 | u32 n_bytes_per_buf, deq_per_buf, deq_per_first_buf; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 153 | u32 buffers_allocated, buffers_allocated_this_call; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 154 | |
| 155 | next_index = next0 = session_type_to_next[s0->session_type]; |
| 156 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 157 | transport_vft = transport_protocol_get_vft (s0->session_type); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 158 | tc0 = transport_vft->get_connection (s0->connection_index, thread_index); |
| 159 | |
| 160 | /* Make sure we have space to send and there's something to dequeue */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 161 | snd_mss0 = transport_vft->send_mss (tc0); |
Florin Coras | c834341 | 2017-05-04 14:25:50 -0700 | [diff] [blame] | 162 | snd_space0 = transport_vft->send_space (tc0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 163 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 164 | /* Can't make any progress */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 165 | if (snd_space0 == 0 || snd_mss0 == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 166 | { |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 167 | vec_add1 (smm->pending_event_vector[thread_index], *e0); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 168 | return 0; |
| 169 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 170 | |
Florin Coras | 6a9b68b | 2017-11-21 04:20:42 -0800 | [diff] [blame] | 171 | /* Allow enqueuing of a new event */ |
| 172 | svm_fifo_unset_event (s0->server_tx_fifo); |
| 173 | |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 174 | /* Check how much we can pull. */ |
| 175 | max_dequeue0 = svm_fifo_max_dequeue (s0->server_tx_fifo); |
| 176 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 177 | if (peek_data) |
| 178 | { |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 179 | /* Offset in rx fifo from where to peek data */ |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 180 | tx_offset = transport_vft->tx_fifo_offset (tc0); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 181 | if (PREDICT_FALSE (tx_offset >= max_dequeue0)) |
| 182 | max_dequeue0 = 0; |
| 183 | else |
| 184 | max_dequeue0 -= tx_offset; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 187 | /* Nothing to read return */ |
| 188 | if (max_dequeue0 == 0) |
Florin Coras | 6a9b68b | 2017-11-21 04:20:42 -0800 | [diff] [blame] | 189 | return 0; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 190 | |
| 191 | /* Ensure we're not writing more than transport window allows */ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 192 | if (max_dequeue0 < snd_space0) |
| 193 | { |
| 194 | /* Constrained by tx queue. Try to send only fully formed segments */ |
| 195 | max_len_to_snd0 = (max_dequeue0 > snd_mss0) ? |
| 196 | max_dequeue0 - max_dequeue0 % snd_mss0 : max_dequeue0; |
| 197 | /* TODO Nagle ? */ |
| 198 | } |
| 199 | else |
| 200 | { |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 201 | /* Expectation is that snd_space0 is already a multiple of snd_mss */ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 202 | max_len_to_snd0 = snd_space0; |
| 203 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 204 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 205 | n_bytes_per_buf = vlib_buffer_free_list_buffer_size |
| 206 | (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 207 | ASSERT (n_bytes_per_buf > MAX_HDRS_LEN); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 208 | n_bytes_per_seg = MAX_HDRS_LEN + snd_mss0; |
| 209 | n_bufs_per_seg = ceil ((double) n_bytes_per_seg / n_bytes_per_buf); |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 210 | n_bufs_per_evt = ceil ((double) max_len_to_snd0 / n_bytes_per_seg); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 211 | n_frames_per_evt = ceil ((double) n_bufs_per_evt / VLIB_FRAME_SIZE); |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 212 | n_bufs_per_frame = n_bufs_per_seg * VLIB_FRAME_SIZE; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 213 | |
| 214 | deq_per_buf = clib_min (snd_mss0, n_bytes_per_buf); |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 215 | deq_per_first_buf = clib_min (snd_mss0, n_bytes_per_buf - MAX_HDRS_LEN); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 216 | |
| 217 | n_bufs = vec_len (smm->tx_buffers[thread_index]); |
| 218 | left_to_snd0 = max_len_to_snd0; |
| 219 | for (i = 0; i < n_frames_per_evt; i++) |
| 220 | { |
| 221 | /* Make sure we have at least one full frame of buffers ready */ |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 222 | if (PREDICT_FALSE (n_bufs < n_bufs_per_frame)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 223 | { |
| 224 | vec_validate (smm->tx_buffers[thread_index], |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 225 | n_bufs + n_bufs_per_frame - 1); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 226 | buffers_allocated = 0; |
| 227 | do |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 228 | { |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 229 | buffers_allocated_this_call = vlib_buffer_alloc (vm, |
| 230 | &smm->tx_buffers |
| 231 | [thread_index] |
| 232 | [n_bufs + |
| 233 | buffers_allocated], |
| 234 | n_bufs_per_frame |
| 235 | - |
| 236 | buffers_allocated); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 237 | buffers_allocated += buffers_allocated_this_call; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 238 | } |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 239 | while (buffers_allocated_this_call > 0 |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 240 | && ((buffers_allocated + n_bufs < n_bufs_per_frame))); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 241 | |
| 242 | n_bufs += buffers_allocated; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 243 | _vec_len (smm->tx_buffers[thread_index]) = n_bufs; |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 244 | |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 245 | if (PREDICT_FALSE (n_bufs < n_bufs_per_frame)) |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 246 | { |
| 247 | vec_add1 (smm->pending_event_vector[thread_index], *e0); |
| 248 | return -1; |
| 249 | } |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 250 | ASSERT (n_bufs >= n_bufs_per_frame); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 254 | while (left_to_snd0 && n_left_to_next) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 255 | { |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 256 | /* |
| 257 | * Handle first buffer in chain separately |
| 258 | */ |
| 259 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 260 | /* Get free buffer */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 261 | ASSERT (n_bufs >= 1); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 262 | bi0 = smm->tx_buffers[thread_index][--n_bufs]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 263 | _vec_len (smm->tx_buffers[thread_index]) = n_bufs; |
| 264 | |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame] | 265 | /* usual speculation, or the enqueue_x1 macro will barf */ |
| 266 | to_next[0] = bi0; |
| 267 | to_next += 1; |
| 268 | n_left_to_next -= 1; |
| 269 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 270 | b0 = vlib_get_buffer (vm, bi0); |
| 271 | b0->error = 0; |
Florin Coras | 4eeeaaf | 2017-09-05 14:03:37 -0400 | [diff] [blame] | 272 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 273 | b0->current_data = 0; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 274 | b0->total_length_not_including_first_buffer = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 275 | |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 276 | len_to_deq0 = clib_min (left_to_snd0, deq_per_first_buf); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 277 | data0 = vlib_buffer_make_headroom (b0, MAX_HDRS_LEN); |
| 278 | if (peek_data) |
| 279 | { |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 280 | n_bytes_read = svm_fifo_peek (s0->server_tx_fifo, tx_offset, |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 281 | len_to_deq0, data0); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 282 | if (n_bytes_read <= 0) |
| 283 | goto dequeue_fail; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 284 | /* Keep track of progress locally, transport is also supposed to |
| 285 | * increment it independently when pushing the header */ |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 286 | tx_offset += n_bytes_read; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 287 | } |
| 288 | else |
| 289 | { |
| 290 | n_bytes_read = svm_fifo_dequeue_nowait (s0->server_tx_fifo, |
| 291 | len_to_deq0, data0); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 292 | if (n_bytes_read <= 0) |
| 293 | goto dequeue_fail; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 296 | b0->current_length = n_bytes_read; |
| 297 | |
| 298 | left_to_snd0 -= n_bytes_read; |
| 299 | *n_tx_packets = *n_tx_packets + 1; |
| 300 | |
| 301 | /* |
| 302 | * Fill in the remaining buffers in the chain, if any |
| 303 | */ |
Florin Coras | e87216f | 2017-08-17 16:59:22 -0700 | [diff] [blame] | 304 | if (PREDICT_FALSE (n_bufs_per_seg > 1 && left_to_snd0)) |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 305 | { |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 306 | left_for_seg = clib_min (snd_mss0 - n_bytes_read, left_to_snd0); |
| 307 | session_tx_fifo_chain_tail (smm, vm, thread_index, |
| 308 | s0->server_tx_fifo, b0, bi0, |
| 309 | n_bufs_per_seg, left_for_seg, |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 310 | &left_to_snd0, &n_bufs, &tx_offset, |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 311 | deq_per_buf, peek_data); |
| 312 | } |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 313 | |
| 314 | /* Ask transport to push header after current_length and |
| 315 | * total_length_not_including_first_buffer are updated */ |
| 316 | transport_vft->push_header (tc0, b0); |
| 317 | |
| 318 | /* *INDENT-OFF* */ |
| 319 | SESSION_EVT_DBG(SESSION_EVT_DEQ, s0, ({ |
Florin Coras | ec44e34 | 2017-10-16 20:47:56 -0700 | [diff] [blame] | 320 | ed->data[0] = e0->event_type; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 321 | ed->data[1] = max_dequeue0; |
| 322 | ed->data[2] = len_to_deq0; |
| 323 | ed->data[3] = left_to_snd0; |
| 324 | })); |
| 325 | /* *INDENT-ON* */ |
| 326 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 327 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0); |
Florin Coras | f988e69 | 2017-11-27 04:34:14 -0500 | [diff] [blame] | 328 | tcp_trajectory_add_start (b0, 3); |
Florin Coras | 4eeeaaf | 2017-09-05 14:03:37 -0400 | [diff] [blame] | 329 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 330 | if (PREDICT_FALSE (n_trace > 0)) |
| 331 | { |
| 332 | session_queue_trace_t *t0; |
| 333 | vlib_trace_buffer (vm, node, next_index, b0, |
| 334 | 1 /* follow_chain */ ); |
| 335 | vlib_set_trace_count (vm, node, --n_trace); |
| 336 | t0 = vlib_add_trace (vm, node, b0, sizeof (*t0)); |
| 337 | t0->session_index = s0->session_index; |
| 338 | t0->server_thread_index = s0->thread_index; |
| 339 | } |
| 340 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 341 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 342 | to_next, n_left_to_next, |
| 343 | bi0, next0); |
| 344 | } |
| 345 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 346 | } |
| 347 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 348 | /* If we couldn't dequeue all bytes mark as partially read */ |
| 349 | if (max_len_to_snd0 < max_dequeue0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 350 | { |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 351 | /* If we don't already have new event */ |
| 352 | if (svm_fifo_set_event (s0->server_tx_fifo)) |
| 353 | { |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 354 | vec_add1 (smm->pending_event_vector[thread_index], *e0); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 355 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 356 | } |
| 357 | return 0; |
| 358 | |
| 359 | dequeue_fail: |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 360 | /* |
| 361 | * Can't read from fifo. If we don't already have an event, save as partially |
| 362 | * read, return buff to free list and return |
| 363 | */ |
| 364 | clib_warning ("dequeue fail"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 365 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 366 | if (svm_fifo_set_event (s0->server_tx_fifo)) |
| 367 | { |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 368 | vec_add1 (smm->pending_event_vector[thread_index], *e0); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 369 | } |
| 370 | vlib_put_next_frame (vm, node, next_index, n_left_to_next + 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 371 | _vec_len (smm->tx_buffers[thread_index]) += 1; |
| 372 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | int |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 377 | session_tx_fifo_peek_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 378 | session_manager_main_t * smm, |
| 379 | session_fifo_event_t * e0, |
| 380 | stream_session_t * s0, u32 thread_index, |
| 381 | int *n_tx_pkts) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 382 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 383 | return session_tx_fifo_read_and_snd_i (vm, node, smm, e0, s0, thread_index, |
| 384 | n_tx_pkts, 1); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 388 | session_tx_fifo_dequeue_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 389 | session_manager_main_t * smm, |
| 390 | session_fifo_event_t * e0, |
| 391 | stream_session_t * s0, u32 thread_index, |
| 392 | int *n_tx_pkts) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 393 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 394 | return session_tx_fifo_read_and_snd_i (vm, node, smm, e0, s0, thread_index, |
| 395 | n_tx_pkts, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 396 | } |
| 397 | |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 398 | always_inline stream_session_t * |
| 399 | session_event_get_session (session_fifo_event_t * e, u8 thread_index) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 400 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 401 | return session_get_if_valid (e->fifo->master_session_index, thread_index); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 404 | void |
| 405 | dump_thread_0_event_queue (void) |
| 406 | { |
| 407 | session_manager_main_t *smm = vnet_get_session_manager_main (); |
| 408 | vlib_main_t *vm = &vlib_global_main; |
| 409 | u32 my_thread_index = vm->thread_index; |
| 410 | session_fifo_event_t _e, *e = &_e; |
| 411 | stream_session_t *s0; |
| 412 | int i, index; |
| 413 | i8 *headp; |
| 414 | |
| 415 | unix_shared_memory_queue_t *q; |
| 416 | q = smm->vpp_event_queues[my_thread_index]; |
| 417 | |
| 418 | index = q->head; |
| 419 | |
| 420 | for (i = 0; i < q->cursize; i++) |
| 421 | { |
| 422 | headp = (i8 *) (&q->data[0] + q->elsize * index); |
| 423 | clib_memcpy (e, headp, q->elsize); |
| 424 | |
| 425 | switch (e->event_type) |
| 426 | { |
| 427 | case FIFO_EVENT_APP_TX: |
| 428 | s0 = session_event_get_session (e, my_thread_index); |
| 429 | fformat (stdout, "[%04d] TX session %d\n", i, s0->session_index); |
| 430 | break; |
| 431 | |
| 432 | case FIFO_EVENT_DISCONNECT: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 433 | s0 = session_get_from_handle (e->session_handle); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 434 | fformat (stdout, "[%04d] disconnect session %d\n", i, |
| 435 | s0->session_index); |
| 436 | break; |
| 437 | |
| 438 | case FIFO_EVENT_BUILTIN_RX: |
| 439 | s0 = session_event_get_session (e, my_thread_index); |
| 440 | fformat (stdout, "[%04d] builtin_rx %d\n", i, s0->session_index); |
| 441 | break; |
| 442 | |
| 443 | case FIFO_EVENT_RPC: |
| 444 | fformat (stdout, "[%04d] RPC call %llx with %llx\n", |
| 445 | i, (u64) (e->rpc_args.fp), (u64) (e->rpc_args.arg)); |
| 446 | break; |
| 447 | |
| 448 | default: |
| 449 | fformat (stdout, "[%04d] unhandled event type %d\n", |
| 450 | i, e->event_type); |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | index++; |
| 455 | |
| 456 | if (index == q->maxsize) |
| 457 | index = 0; |
| 458 | } |
| 459 | } |
| 460 | |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 461 | static u8 |
| 462 | session_node_cmp_event (session_fifo_event_t * e, svm_fifo_t * f) |
| 463 | { |
| 464 | stream_session_t *s; |
| 465 | switch (e->event_type) |
| 466 | { |
| 467 | case FIFO_EVENT_APP_RX: |
| 468 | case FIFO_EVENT_APP_TX: |
| 469 | case FIFO_EVENT_BUILTIN_RX: |
| 470 | if (e->fifo == f) |
| 471 | return 1; |
| 472 | break; |
| 473 | case FIFO_EVENT_DISCONNECT: |
| 474 | break; |
| 475 | case FIFO_EVENT_RPC: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 476 | s = session_get_from_handle (e->session_handle); |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 477 | if (!s) |
| 478 | { |
| 479 | clib_warning ("session has event but doesn't exist!"); |
| 480 | break; |
| 481 | } |
| 482 | if (s->server_rx_fifo == f || s->server_tx_fifo == f) |
| 483 | return 1; |
| 484 | break; |
| 485 | default: |
| 486 | break; |
| 487 | } |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | u8 |
| 492 | session_node_lookup_fifo_event (svm_fifo_t * f, session_fifo_event_t * e) |
| 493 | { |
| 494 | session_manager_main_t *smm = vnet_get_session_manager_main (); |
| 495 | unix_shared_memory_queue_t *q; |
| 496 | session_fifo_event_t *pending_event_vector, *evt; |
| 497 | int i, index, found = 0; |
| 498 | i8 *headp; |
| 499 | u8 thread_index; |
| 500 | |
| 501 | ASSERT (e); |
| 502 | thread_index = f->master_thread_index; |
| 503 | /* |
| 504 | * Search evt queue |
| 505 | */ |
| 506 | q = smm->vpp_event_queues[thread_index]; |
| 507 | index = q->head; |
| 508 | for (i = 0; i < q->cursize; i++) |
| 509 | { |
| 510 | headp = (i8 *) (&q->data[0] + q->elsize * index); |
| 511 | clib_memcpy (e, headp, q->elsize); |
| 512 | found = session_node_cmp_event (e, f); |
| 513 | if (found) |
| 514 | break; |
| 515 | if (++index == q->maxsize) |
| 516 | index = 0; |
| 517 | } |
| 518 | /* |
| 519 | * Search pending events vector |
| 520 | */ |
| 521 | pending_event_vector = smm->pending_event_vector[thread_index]; |
| 522 | vec_foreach (evt, pending_event_vector) |
| 523 | { |
| 524 | found = session_node_cmp_event (evt, f); |
| 525 | if (found) |
| 526 | { |
| 527 | clib_memcpy (e, evt, sizeof (*evt)); |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | return found; |
| 532 | } |
| 533 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 534 | static uword |
| 535 | session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 536 | vlib_frame_t * frame) |
| 537 | { |
| 538 | session_manager_main_t *smm = vnet_get_session_manager_main (); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 539 | session_fifo_event_t *my_pending_event_vector, *pending_disconnects, *e; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 540 | session_fifo_event_t *my_fifo_events; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 541 | u32 n_to_dequeue, n_events; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 542 | unix_shared_memory_queue_t *q; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 543 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 544 | int n_tx_packets = 0; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 545 | u32 my_thread_index = vm->thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 546 | int i, rv; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 547 | f64 now = vlib_time_now (vm); |
Dave Barach | e5f1d27 | 2017-05-10 13:34:04 -0400 | [diff] [blame] | 548 | void (*fp) (void *); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 549 | |
| 550 | SESSION_EVT_DBG (SESSION_EVT_POLL_GAP_TRACK, smm, my_thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 551 | |
| 552 | /* |
| 553 | * Update TCP time |
| 554 | */ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 555 | tcp_update_time (now, my_thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * Get vpp queue events |
| 559 | */ |
| 560 | q = smm->vpp_event_queues[my_thread_index]; |
| 561 | if (PREDICT_FALSE (q == 0)) |
| 562 | return 0; |
| 563 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 564 | my_fifo_events = smm->free_event_vector[my_thread_index]; |
| 565 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 566 | /* min number of events we can dequeue without blocking */ |
| 567 | n_to_dequeue = q->cursize; |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 568 | my_pending_event_vector = smm->pending_event_vector[my_thread_index]; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 569 | pending_disconnects = smm->pending_disconnects[my_thread_index]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 570 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 571 | if (!n_to_dequeue && !vec_len (my_pending_event_vector) |
| 572 | && !vec_len (pending_disconnects)) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 573 | return 0; |
| 574 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 575 | SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0); |
| 576 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 577 | /* |
| 578 | * If we didn't manage to process previous events try going |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 579 | * over them again without dequeuing new ones. |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 580 | */ |
| 581 | /* XXX: Block senders to sessions that can't keep up */ |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 582 | if (0 && vec_len (my_pending_event_vector) >= 100) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 583 | { |
| 584 | clib_warning ("too many fifo events unsolved"); |
| 585 | goto skip_dequeue; |
| 586 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 587 | |
| 588 | /* See you in the next life, don't be late */ |
| 589 | if (pthread_mutex_trylock (&q->mutex)) |
| 590 | return 0; |
| 591 | |
| 592 | for (i = 0; i < n_to_dequeue; i++) |
| 593 | { |
| 594 | vec_add2 (my_fifo_events, e, 1); |
| 595 | unix_shared_memory_queue_sub_raw (q, (u8 *) e); |
| 596 | } |
| 597 | |
| 598 | /* The other side of the connection is not polling */ |
| 599 | if (q->cursize < (q->maxsize / 8)) |
| 600 | (void) pthread_cond_broadcast (&q->condvar); |
| 601 | pthread_mutex_unlock (&q->mutex); |
| 602 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 603 | vec_append (my_fifo_events, my_pending_event_vector); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 604 | vec_append (my_fifo_events, smm->pending_disconnects[my_thread_index]); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 605 | |
| 606 | _vec_len (my_pending_event_vector) = 0; |
| 607 | smm->pending_event_vector[my_thread_index] = my_pending_event_vector; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 608 | _vec_len (smm->pending_disconnects[my_thread_index]) = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 609 | |
| 610 | skip_dequeue: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 611 | n_events = vec_len (my_fifo_events); |
| 612 | for (i = 0; i < n_events; i++) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 613 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 614 | stream_session_t *s0; /* $$$ prefetch 1 ahead maybe */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 615 | session_fifo_event_t *e0; |
| 616 | |
| 617 | e0 = &my_fifo_events[i]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 618 | |
| 619 | switch (e0->event_type) |
| 620 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 621 | case FIFO_EVENT_APP_TX: |
| 622 | s0 = session_event_get_session (e0, my_thread_index); |
| 623 | |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 624 | if (PREDICT_FALSE (!s0)) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 625 | { |
| 626 | clib_warning ("It's dead, Jim!"); |
| 627 | continue; |
| 628 | } |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 629 | /* Can retransmit for closed sessions but can't do anything if |
| 630 | * session is not ready or closed */ |
| 631 | if (PREDICT_FALSE (s0->session_state < SESSION_STATE_READY)) |
Florin Coras | 93e6580 | 2017-11-29 00:07:11 -0500 | [diff] [blame] | 632 | { |
| 633 | vec_add1 (smm->pending_event_vector[my_thread_index], *e0); |
| 634 | continue; |
| 635 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 636 | /* Spray packets in per session type frames, since they go to |
| 637 | * different nodes */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 638 | rv = (smm->session_tx_fns[s0->session_type]) (vm, node, smm, e0, s0, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 639 | my_thread_index, |
| 640 | &n_tx_packets); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 641 | /* Out of buffers */ |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 642 | if (PREDICT_FALSE (rv < 0)) |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 643 | { |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 644 | vlib_node_increment_counter (vm, node->node_index, |
| 645 | SESSION_QUEUE_ERROR_NO_BUFFER, 1); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 646 | continue; |
| 647 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 648 | break; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 649 | case FIFO_EVENT_DISCONNECT: |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 650 | /* Make sure disconnects run after the pending list is drained */ |
| 651 | if (!e0->postponed) |
| 652 | { |
| 653 | e0->postponed = 1; |
| 654 | vec_add1 (smm->pending_disconnects[my_thread_index], *e0); |
| 655 | continue; |
| 656 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 657 | s0 = session_get_from_handle (e0->session_handle); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 658 | stream_session_disconnect (s0); |
| 659 | break; |
| 660 | case FIFO_EVENT_BUILTIN_RX: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 661 | s0 = session_event_get_session (e0, my_thread_index); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 662 | if (PREDICT_FALSE (!s0)) |
| 663 | continue; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 664 | svm_fifo_unset_event (s0->server_rx_fifo); |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 665 | app = application_get (s0->app_index); |
| 666 | app->cb_fns.builtin_server_rx_callback (s0); |
| 667 | break; |
Dave Barach | e5f1d27 | 2017-05-10 13:34:04 -0400 | [diff] [blame] | 668 | case FIFO_EVENT_RPC: |
| 669 | fp = e0->rpc_args.fp; |
| 670 | (*fp) (e0->rpc_args.arg); |
| 671 | break; |
| 672 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 673 | default: |
| 674 | clib_warning ("unhandled event type %d", e0->event_type); |
| 675 | } |
| 676 | } |
| 677 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 678 | _vec_len (my_fifo_events) = 0; |
| 679 | smm->free_event_vector[my_thread_index] = my_fifo_events; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 680 | |
| 681 | vlib_node_increment_counter (vm, session_queue_node.index, |
| 682 | SESSION_QUEUE_ERROR_TX, n_tx_packets); |
| 683 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 684 | SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 1); |
| 685 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 686 | return n_tx_packets; |
| 687 | } |
| 688 | |
| 689 | /* *INDENT-OFF* */ |
| 690 | VLIB_REGISTER_NODE (session_queue_node) = |
| 691 | { |
| 692 | .function = session_queue_node_fn, |
| 693 | .name = "session-queue", |
| 694 | .format_trace = format_session_queue_trace, |
| 695 | .type = VLIB_NODE_TYPE_INPUT, |
| 696 | .n_errors = ARRAY_LEN (session_queue_error_strings), |
| 697 | .error_strings = session_queue_error_strings, |
| 698 | .n_next_nodes = SESSION_QUEUE_N_NEXT, |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 699 | .state = VLIB_NODE_STATE_DISABLED, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 700 | .next_nodes = |
| 701 | { |
| 702 | [SESSION_QUEUE_NEXT_DROP] = "error-drop", |
| 703 | [SESSION_QUEUE_NEXT_IP4_LOOKUP] = "ip4-lookup", |
| 704 | [SESSION_QUEUE_NEXT_IP6_LOOKUP] = "ip6-lookup", |
| 705 | [SESSION_QUEUE_NEXT_TCP_IP4_OUTPUT] = "tcp4-output", |
| 706 | [SESSION_QUEUE_NEXT_TCP_IP6_OUTPUT] = "tcp6-output", |
| 707 | }, |
| 708 | }; |
| 709 | /* *INDENT-ON* */ |
| 710 | |
Dave Barach | 2a86391 | 2017-11-28 10:11:42 -0500 | [diff] [blame] | 711 | static clib_error_t * |
| 712 | session_queue_exit (vlib_main_t * vm) |
| 713 | { |
| 714 | if (vec_len (vlib_mains) < 2) |
| 715 | return 0; |
| 716 | |
| 717 | /* |
| 718 | * Shut off (especially) worker-thread session nodes. |
| 719 | * Otherwise, vpp can crash as the main thread unmaps the |
| 720 | * API segment. |
| 721 | */ |
| 722 | vlib_worker_thread_barrier_sync (vm); |
| 723 | session_node_enable_disable (0 /* is_enable */ ); |
| 724 | vlib_worker_thread_barrier_release (vm); |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | VLIB_MAIN_LOOP_EXIT_FUNCTION (session_queue_exit); |
| 729 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 730 | /* |
| 731 | * fd.io coding-style-patch-verification: ON |
| 732 | * |
| 733 | * Local Variables: |
| 734 | * eval: (c-set-style "gnu") |
| 735 | * End: |
| 736 | */ |