FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
vpp_echo_proto_tcp.c
Go to the documentation of this file.
1 /*
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:
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 
16 #include <stdio.h>
17 #include <signal.h>
18 
20 
21 static void
23 {
24  echo_main_t *em = &echo_main;
25  echo_session_t *ls;
26  ASSERT (s->session_state < ECHO_SESSION_STATE_CLOSED);
27  if (parent_died)
30  {
33  }
34 
35 
37  s->session_state = ECHO_SESSION_STATE_CLOSED;
38  if (!em->n_clients_connected)
39  em->state = STATE_DATA_DONE;
40 }
41 
42 static void
44  u32 session_index, u8 is_failed)
45 {
46  static u32 client_index = 0;
47  echo_main_t *em = &echo_main;
48  echo_session_t *session = pool_elt_at_index (em->sessions, session_index);
49  if (is_failed)
50  {
51  ECHO_FAIL (ECHO_FAIL_TCP_BAPI_CONNECT,
52  "Bapi connect errored on session %u", session_index);
53  return; /* Dont handle bapi connect errors for now */
54  }
55 
56  ECHO_LOG (2, "Connected session 0x%lx -> URI",
57  ((session_connected_msg_t *) mp)->handle);
58  session->session_type = ECHO_SESSION_TYPE_STREAM;
59  session->accepted_session_count = 0;
61  session->bytes_to_send = em->bytes_to_send;
62  session->bytes_to_receive = em->bytes_to_receive;
63  session->session_state = ECHO_SESSION_STATE_READY;
64  em->data_thread_args[client_index++] = session->session_index;
65 
66  if (em->n_clients_connected == em->n_clients && em->state < STATE_READY)
67  {
69  em->state = STATE_READY;
70  }
71 }
72 
73 static void
75 {
76  static u32 client_index = 0;
77  echo_main_t *em = &echo_main;
78  echo_session_t *ls;
79 
81  ls = pool_elt_at_index (em->sessions, session->listener_index);
82  session->session_type = ECHO_SESSION_TYPE_STREAM;
86 
87  session->bytes_to_send = em->bytes_to_send;
88  session->bytes_to_receive = em->bytes_to_receive;
89  em->data_thread_args[client_index++] = session->session_index;
90  session->session_state = ECHO_SESSION_STATE_READY;
91 
92  if (em->n_clients_connected == em->n_clients && em->state < STATE_READY)
93  {
95  em->state = STATE_READY;
96  }
97 }
98 
99 static void
101 {
102  s->session_state = ECHO_SESSION_STATE_CLOSING;
103 }
104 
105 static void
107 {
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;
112  else
113  s->session_state = ECHO_SESSION_STATE_CLOSING;
115 }
116 
117 static void
119 {
120  echo_main_t *em = &echo_main;
122  s->session_state = ECHO_SESSION_STATE_CLOSING;
123 }
124 
127  .connected_cb = tcp_echo_connected_cb,
128  .accepted_cb = tcp_echo_accepted_cb,
129  .reset_cb = tcp_echo_reset_cb,
130  .sent_disconnect_cb = tcp_echo_sent_disconnect_cb,
131  .cleanup_cb = tcp_echo_cleanup_cb,
132 };
133 
136  .connected_cb = tcp_echo_connected_cb,
137  .accepted_cb = tcp_echo_accepted_cb,
138  .reset_cb = tcp_echo_reset_cb,
139  .sent_disconnect_cb = tcp_echo_sent_disconnect_cb,
140  .cleanup_cb = tcp_echo_cleanup_cb,
141 };
142 
143 ECHO_REGISTER_PROTO (TRANSPORT_PROTO_TCP, echo_tcp_proto_cb_vft);
144 ECHO_REGISTER_PROTO (TRANSPORT_PROTO_TLS, echo_tls_proto_cb_vft);
145 
146 /*
147  * fd.io coding-style-patch-verification: ON
148  *
149  * Local Variables:
150  * eval: (c-set-style "gnu")
151  * End:
152  */
echo_main_t::data_thread_args
u32 *volatile data_thread_args
Definition: vpp_echo_common.h:346
ECHO_FAIL
#define ECHO_FAIL(fail, _fmt, _args...)
Definition: vpp_echo_common.h:128
echo_main_t::sessions
echo_session_t * sessions
Definition: vpp_echo_common.h:289
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
echo_main_t::n_clients_connected
volatile u32 n_clients_connected
Definition: vpp_echo_common.h:353
echo_session_t
Definition: vpp_echo_common.h:159
echo_tcp_proto_cb_vft
echo_proto_cb_vft_t echo_tcp_proto_cb_vft
Definition: vpp_echo_proto_tcp.c:125
echo_session_t::accepted_session_count
volatile u64 accepted_session_count
Definition: vpp_echo_common.h:173
ECHO_EVT_FIRST_QCONNECT
@ ECHO_EVT_FIRST_QCONNECT
Definition: vpp_echo_common.h:225
echo_main_t::state
volatile connection_state_t state
Definition: vpp_echo_common.h:308
SESSION_INVALID_INDEX
#define SESSION_INVALID_INDEX
Definition: session_types.h:22
ECHO_SESSION_TYPE_STREAM
@ ECHO_SESSION_TYPE_STREAM
Definition: vpp_echo_common.h:195
session_connected_msg_
Definition: application_interface.h:426
tcp_echo_disconnected_cb
static void tcp_echo_disconnected_cb(session_disconnected_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_proto_tcp.c:106
echo_proto_cb_vft_
Definition: vpp_echo_common.h:238
vpp_echo_common.h
ECHO_SESSION_STATE_READY
@ ECHO_SESSION_STATE_READY
Definition: vpp_echo_common.h:202
echo_main_t::bytes_to_send
u64 bytes_to_send
Definition: vpp_echo_common.h:322
teardown_stat_::s
u32 s
Definition: vpp_echo_common.h:264
STATE_READY
@ STATE_READY
Definition: vpp_echo_common.h:215
echo_session_print_stats
void echo_session_print_stats(echo_main_t *em, echo_session_t *session)
Definition: vpp_echo_common.c:616
echo_session_t::bytes_to_send
u64 bytes_to_send
Definition: vpp_echo_common.h:167
echo_main_t::stats
echo_stats_t stats
Definition: vpp_echo_common.h:362
tcp_echo_connected_cb
static void tcp_echo_connected_cb(session_connected_bundled_msg_t *mp, u32 session_index, u8 is_failed)
Definition: vpp_echo_proto_tcp.c:43
ECHO_SESSION_STATE_AWAIT_DATA
@ ECHO_SESSION_STATE_AWAIT_DATA
Definition: vpp_echo_common.h:204
ECHO_SESSION_STATE_CLOSING
@ ECHO_SESSION_STATE_CLOSING
Definition: vpp_echo_common.h:205
echo_tls_proto_cb_vft
echo_proto_cb_vft_t echo_tls_proto_cb_vft
Definition: vpp_echo_proto_tcp.c:134
session_connected_bundled_msg_
Definition: vpp_echo_common.h:233
ECHO_EVT_FIRST_SCONNECT
@ ECHO_EVT_FIRST_SCONNECT
Definition: vpp_echo_common.h:227
clib_atomic_sub_fetch
#define clib_atomic_sub_fetch(a, b)
Definition: atomics.h:31
clib_atomic_fetch_add
#define clib_atomic_fetch_add(a, b)
Definition: atomics.h:23
session_disconnected_msg_
Definition: application_interface.h:458
tcp_echo_accepted_cb
static void tcp_echo_accepted_cb(session_accepted_msg_t *mp, echo_session_t *session)
Definition: vpp_echo_proto_tcp.c:74
session_reset_msg_
Definition: application_interface.h:472
echo_session_t::bytes_to_receive
volatile u64 bytes_to_receive
Definition: vpp_echo_common.h:169
echo_main_t::n_clients
u32 n_clients
Definition: vpp_echo_common.h:350
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
ECHO_EVT_LAST_SCONNECTED
@ ECHO_EVT_LAST_SCONNECTED
Definition: vpp_echo_common.h:228
echo_stats_::reset_count
teardown_stat_t reset_count
Definition: vpp_echo_common.h:273
echo_main_t
Definition: vpp_echo_common.h:281
tcp_echo_sent_disconnect_cb
static void tcp_echo_sent_disconnect_cb(echo_session_t *s)
Definition: vpp_echo_proto_tcp.c:100
echo_stats_::clean_count
teardown_stat_t clean_count
Definition: vpp_echo_common.h:276
echo_main
echo_main_t echo_main
Definition: vpp_echo.c:24
STATE_DATA_DONE
@ STATE_DATA_DONE
Definition: vpp_echo_common.h:216
u8
unsigned char u8
Definition: types.h:56
echo_main_t::bytes_to_receive
u64 bytes_to_receive
Definition: vpp_echo_common.h:323
tcp_echo_reset_cb
static void tcp_echo_reset_cb(session_reset_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_proto_tcp.c:118
ECHO_LOG
#define ECHO_LOG(lvl, _fmt, _args...)
Definition: vpp_echo_common.h:143
echo_session_t::listener_index
u32 listener_index
Definition: vpp_echo_common.h:171
echo_stats_::close_count
teardown_stat_t close_count
Definition: vpp_echo_common.h:274
echo_proto_cb_vft_::disconnected_cb
void(* disconnected_cb)(session_disconnected_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_common.h:244
ECHO_SESSION_STATE_CLOSED
@ ECHO_SESSION_STATE_CLOSED
Definition: vpp_echo_common.h:206
session_accepted_msg_
Definition: application_interface.h:372
echo_notify_event
void echo_notify_event(echo_main_t *em, echo_test_evt_t e)
Definition: vpp_echo_common.c:604
tcp_echo_cleanup_cb
static void tcp_echo_cleanup_cb(echo_session_t *s, u8 parent_died)
Definition: vpp_echo_proto_tcp.c:22
ECHO_REGISTER_PROTO
ECHO_REGISTER_PROTO(TRANSPORT_PROTO_TCP, echo_tcp_proto_cb_vft)