2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
19 #include <hs_apps/sapi/vpp_echo_common.h>
22 udp_echo_cleanup_cb (echo_session_t * s, u8 parent_died)
24 echo_main_t *em = &echo_main;
26 ASSERT (s->session_state < ECHO_SESSION_STATE_CLOSED);
28 clib_atomic_fetch_add (&em->stats.clean_count.s, 1);
29 else if (s->listener_index != SESSION_INVALID_INDEX)
31 ls = pool_elt_at_index (em->sessions, s->listener_index);
32 clib_atomic_sub_fetch (&ls->accepted_session_count, 1);
35 clib_atomic_sub_fetch (&em->n_clients_connected, 1);
36 s->session_state = ECHO_SESSION_STATE_CLOSED;
37 if (!em->n_clients_connected)
38 em->state = STATE_DATA_DONE;
42 udp_echo_connected_cb (session_connected_bundled_msg_t * mp,
43 u32 session_index, u8 is_failed)
45 static u32 client_index = 0;
46 echo_main_t *em = &echo_main;
47 echo_session_t *session = pool_elt_at_index (em->sessions, session_index);
50 ECHO_FAIL ("Bapi connect errored");
51 return; /* Dont handle bapi connect errors for now */
54 session->accepted_session_count = 0;
55 session->session_type = ECHO_SESSION_TYPE_STREAM;
57 session->bytes_to_send = em->bytes_to_send;
58 session->bytes_to_receive = em->bytes_to_receive;
59 session->session_state = ECHO_SESSION_STATE_READY;
60 session->is_dgram = 1;
62 em->data_thread_args[client_index++] = session->session_index;
64 clib_atomic_fetch_add (&em->n_clients_connected, 1);
65 if (em->n_clients_connected == em->n_clients && em->state < STATE_READY)
67 echo_notify_event (em, ECHO_EVT_LAST_SCONNECTED);
68 em->state = STATE_READY;
73 udp_echo_accepted_cb (session_accepted_msg_t * mp, echo_session_t * session)
75 static u32 client_index = 0;
76 echo_main_t *em = &echo_main;
79 echo_notify_event (em, ECHO_EVT_FIRST_QCONNECT);
80 ls = pool_elt_at_index (em->sessions, session->listener_index);
81 session->session_type = ECHO_SESSION_TYPE_STREAM;
82 echo_notify_event (em, ECHO_EVT_FIRST_SCONNECT);
83 clib_atomic_fetch_add (&ls->accepted_session_count, 1);
84 clib_atomic_fetch_add (&em->n_clients_connected, 1);
86 session->bytes_to_send = em->bytes_to_send;
87 session->bytes_to_receive = em->bytes_to_receive;
88 session->is_dgram = 1;
89 em->data_thread_args[client_index++] = session->session_index;
90 session->session_state = ECHO_SESSION_STATE_READY;
92 if (em->n_clients_connected == em->n_clients && em->state < STATE_READY)
94 echo_notify_event (em, ECHO_EVT_LAST_SCONNECTED);
95 em->state = STATE_READY;
100 udp_echo_disconnected_reply_cb (echo_session_t * s)
102 s->session_state = ECHO_SESSION_STATE_CLOSING;
106 udp_echo_disconnected_cb (session_disconnected_msg_t * mp, echo_session_t * s)
108 echo_main_t *em = &echo_main;
109 echo_session_print_stats (em, s);
110 if (s->bytes_to_receive || s->bytes_to_send)
111 s->session_state = ECHO_SESSION_STATE_AWAIT_DATA;
113 s->session_state = ECHO_SESSION_STATE_CLOSING;
114 clib_atomic_fetch_add (&em->stats.close_count.s, 1);
118 udp_echo_reset_cb (session_reset_msg_t * mp, echo_session_t * s)
120 echo_main_t *em = &echo_main;
121 clib_atomic_fetch_add (&em->stats.reset_count.s, 1);
122 s->session_state = ECHO_SESSION_STATE_CLOSING;
126 udp_echo_bound_uri_cb (session_bound_msg_t * mp, echo_session_t * session)
128 svm_fifo_t *rx_fifo, *tx_fifo;
129 echo_main_t *em = &echo_main;
130 u32 session_index = session->session_index;
131 if (!em->i_am_master || em->uri_elts.transport_proto != TRANSPORT_PROTO_UDP)
134 rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *);
135 tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *);
136 rx_fifo->client_session_index = session_index;
137 tx_fifo->client_session_index = session_index;
139 session->rx_fifo = rx_fifo;
140 session->tx_fifo = tx_fifo;
141 session->transport.is_ip4 = mp->lcl_is_ip4;
142 clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip,
143 sizeof (ip46_address_t));
144 session->transport.lcl_port = mp->lcl_port;
145 session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
147 echo_notify_event (em, ECHO_EVT_FIRST_QCONNECT);
148 session->session_type = ECHO_SESSION_TYPE_STREAM;
149 echo_notify_event (em, ECHO_EVT_FIRST_SCONNECT);
150 clib_atomic_fetch_add (&em->n_clients_connected, 1);
152 session->bytes_to_send = em->bytes_to_send;
153 session->bytes_to_receive = em->bytes_to_receive;
154 session->is_dgram = 1;
155 em->data_thread_args[0] = session_index;
156 session->session_state = ECHO_SESSION_STATE_READY;
158 echo_notify_event (em, ECHO_EVT_LAST_SCONNECTED);
159 em->state = STATE_READY;
163 echo_proto_cb_vft_t echo_udp_proto_cb_vft = {
164 .disconnected_cb = udp_echo_disconnected_cb,
165 .connected_cb = udp_echo_connected_cb,
166 .accepted_cb = udp_echo_accepted_cb,
167 .reset_cb = udp_echo_reset_cb,
168 .disconnected_reply_cb = udp_echo_disconnected_reply_cb,
169 .cleanup_cb = udp_echo_cleanup_cb,
170 .bound_uri_cb = udp_echo_bound_uri_cb,
173 ECHO_REGISTER_PROTO (TRANSPORT_PROTO_UDP, echo_udp_proto_cb_vft);
174 ECHO_REGISTER_PROTO (TRANSPORT_PROTO_UDPC, echo_udp_proto_cb_vft);
177 * fd.io coding-style-patch-verification: ON
180 * eval: (c-set-style "gnu")