FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
vpp_echo_proto_udp.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 
36  s->session_state = ECHO_SESSION_STATE_CLOSED;
37  if (!em->n_clients_connected)
38  em->state = STATE_DATA_DONE;
39 }
40 
41 static void
43  u32 session_index, u8 is_failed)
44 {
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);
48  if (is_failed)
49  {
50  ECHO_FAIL (ECHO_FAIL_UDP_BAPI_CONNECT,
51  "Bapi connect errored on session %u", session_index);
52  return; /* Dont handle bapi connect errors for now */
53  }
54 
55  session->accepted_session_count = 0;
56  session->session_type = ECHO_SESSION_TYPE_STREAM;
57 
58  session->bytes_to_send = em->bytes_to_send;
59  session->bytes_to_receive = em->bytes_to_receive;
60  session->session_state = ECHO_SESSION_STATE_READY;
61  session->is_dgram = 1;
62 
63  em->data_thread_args[client_index++] = session->session_index;
64 
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  session->is_dgram = 1;
90  em->data_thread_args[client_index++] = session->session_index;
91  session->session_state = ECHO_SESSION_STATE_READY;
92 
93  if (em->n_clients_connected == em->n_clients && em->state < STATE_READY)
94  {
96  em->state = STATE_READY;
97  }
98 }
99 
100 static void
102 {
103  s->session_state = ECHO_SESSION_STATE_CLOSING;
104 }
105 
106 static void
108 {
109  echo_main_t *em = &echo_main;
110  echo_session_print_stats (em, s);
111  if (s->bytes_to_receive || s->bytes_to_send)
112  s->session_state = ECHO_SESSION_STATE_AWAIT_DATA;
113  else
114  s->session_state = ECHO_SESSION_STATE_CLOSING;
116 }
117 
118 static void
120 {
121  echo_main_t *em = &echo_main;
123  s->session_state = ECHO_SESSION_STATE_CLOSING;
124 }
125 
126 static void
128 {
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)
132  return;
133 
135  mp->vpp_evt_q, session))
136  {
137  ECHO_FAIL (ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC,
138  "accepted wait_for_segment_allocation errored");
139  return;
140  }
141 
142  session->transport.is_ip4 = mp->lcl_is_ip4;
143  clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip,
144  sizeof (ip46_address_t));
145  session->transport.lcl_port = mp->lcl_port;
146 
148  session->session_type = ECHO_SESSION_TYPE_STREAM;
151 
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;
157 
159  em->state = STATE_READY;
160 }
161 
162 
165  .connected_cb = udp_echo_connected_cb,
166  .accepted_cb = udp_echo_accepted_cb,
167  .reset_cb = udp_echo_reset_cb,
168  .sent_disconnect_cb = udp_echo_sent_disconnect_cb,
169  .cleanup_cb = udp_echo_cleanup_cb,
170  .bound_uri_cb = udp_echo_bound_uri_cb,
171 };
172 
173 ECHO_REGISTER_PROTO (TRANSPORT_PROTO_UDP, echo_udp_proto_cb_vft);
174 
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */
udp_echo_accepted_cb
static void udp_echo_accepted_cb(session_accepted_msg_t *mp, echo_session_t *session)
Definition: vpp_echo_proto_udp.c:74
echo_main_t::i_am_master
int i_am_master
Definition: vpp_echo_common.h:280
echo_main_t::data_thread_args
u32 *volatile data_thread_args
Definition: vpp_echo_common.h:332
echo_attach_session
int echo_attach_session(uword segment_handle, uword rxf_offset, uword txf_offset, uword mq_offset, echo_session_t *s)
Definition: vpp_echo_bapi.c:294
ECHO_FAIL
#define ECHO_FAIL(fail, _fmt, _args...)
Definition: vpp_echo_common.h:114
echo_main_t::sessions
echo_session_t * sessions
Definition: vpp_echo_common.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
udp_echo_disconnected_cb
static void udp_echo_disconnected_cb(session_disconnected_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_proto_udp.c:107
echo_main_t::n_clients_connected
volatile u32 n_clients_connected
Definition: vpp_echo_common.h:339
echo_session_t
Definition: vpp_echo_common.h:145
session_bound_msg_::segment_handle
u64 segment_handle
Definition: application_interface.h:355
echo_session_t::accepted_session_count
volatile u64 accepted_session_count
Definition: vpp_echo_common.h:159
session_bound_msg_::rx_fifo
uword rx_fifo
Definition: application_interface.h:352
ECHO_EVT_FIRST_QCONNECT
@ ECHO_EVT_FIRST_QCONNECT
Definition: vpp_echo_common.h:211
echo_main_t::state
volatile connection_state_t state
Definition: vpp_echo_common.h:294
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:181
echo_proto_cb_vft_
Definition: vpp_echo_common.h:224
session_bound_msg_::lcl_port
u16 lcl_port
Definition: application_interface.h:351
echo_main_t::transport_proto
u32 transport_proto
Definition: vpp_echo_common.h:363
vpp_echo_common.h
ECHO_SESSION_STATE_READY
@ ECHO_SESSION_STATE_READY
Definition: vpp_echo_common.h:188
session_bound_msg_::tx_fifo
uword tx_fifo
Definition: application_interface.h:353
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
echo_main_t::bytes_to_send
u64 bytes_to_send
Definition: vpp_echo_common.h:308
teardown_stat_::s
u32 s
Definition: vpp_echo_common.h:250
STATE_READY
@ STATE_READY
Definition: vpp_echo_common.h:201
session_bound_msg_::lcl_ip
u8 lcl_ip[16]
Definition: application_interface.h:350
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:153
echo_main_t::stats
echo_stats_t stats
Definition: vpp_echo_common.h:348
udp_echo_connected_cb
static void udp_echo_connected_cb(session_connected_bundled_msg_t *mp, u32 session_index, u8 is_failed)
Definition: vpp_echo_proto_udp.c:42
ECHO_REGISTER_PROTO
ECHO_REGISTER_PROTO(TRANSPORT_PROTO_UDP, echo_udp_proto_cb_vft)
ECHO_SESSION_STATE_AWAIT_DATA
@ ECHO_SESSION_STATE_AWAIT_DATA
Definition: vpp_echo_common.h:190
ECHO_SESSION_STATE_CLOSING
@ ECHO_SESSION_STATE_CLOSING
Definition: vpp_echo_common.h:191
udp_echo_reset_cb
static void udp_echo_reset_cb(session_reset_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_proto_udp.c:119
session_connected_bundled_msg_
Definition: vpp_echo_common.h:219
ECHO_EVT_FIRST_SCONNECT
@ ECHO_EVT_FIRST_SCONNECT
Definition: vpp_echo_common.h:213
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
udp_echo_sent_disconnect_cb
static void udp_echo_sent_disconnect_cb(echo_session_t *s)
Definition: vpp_echo_proto_udp.c:101
session_disconnected_msg_
Definition: application_interface.h:458
session_bound_msg_::vpp_evt_q
uword vpp_evt_q
Definition: application_interface.h:354
session_reset_msg_
Definition: application_interface.h:472
echo_session_t::bytes_to_receive
volatile u64 bytes_to_receive
Definition: vpp_echo_common.h:155
session_bound_msg_::lcl_is_ip4
u8 lcl_is_ip4
Definition: application_interface.h:349
echo_main_t::n_clients
u32 n_clients
Definition: vpp_echo_common.h:336
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
udp_echo_bound_uri_cb
static void udp_echo_bound_uri_cb(session_bound_msg_t *mp, echo_session_t *session)
Definition: vpp_echo_proto_udp.c:127
u32
unsigned int u32
Definition: types.h:88
ECHO_EVT_LAST_SCONNECTED
@ ECHO_EVT_LAST_SCONNECTED
Definition: vpp_echo_common.h:214
echo_stats_::reset_count
teardown_stat_t reset_count
Definition: vpp_echo_common.h:259
echo_main_t
Definition: vpp_echo_common.h:267
echo_stats_::clean_count
teardown_stat_t clean_count
Definition: vpp_echo_common.h:262
echo_main
echo_main_t echo_main
Definition: vpp_echo.c:24
STATE_DATA_DONE
@ STATE_DATA_DONE
Definition: vpp_echo_common.h:202
u8
unsigned char u8
Definition: types.h:56
udp_echo_cleanup_cb
static void udp_echo_cleanup_cb(echo_session_t *s, u8 parent_died)
Definition: vpp_echo_proto_udp.c:22
echo_main_t::bytes_to_receive
u64 bytes_to_receive
Definition: vpp_echo_common.h:309
session_bound_msg_
Definition: application_interface.h:344
echo_main_t::uri_elts
struct echo_main_t::@691 uri_elts
echo_session_t::listener_index
u32 listener_index
Definition: vpp_echo_common.h:157
echo_stats_::close_count
teardown_stat_t close_count
Definition: vpp_echo_common.h:260
echo_udp_proto_cb_vft
echo_proto_cb_vft_t echo_udp_proto_cb_vft
Definition: vpp_echo_proto_udp.c:163
echo_proto_cb_vft_::disconnected_cb
void(* disconnected_cb)(session_disconnected_msg_t *mp, echo_session_t *s)
Definition: vpp_echo_common.h:230
ECHO_SESSION_STATE_CLOSED
@ ECHO_SESSION_STATE_CLOSED
Definition: vpp_echo_common.h:192
session_accepted_msg_
Definition: application_interface.h:374
echo_notify_event
void echo_notify_event(echo_main_t *em, echo_test_evt_t e)
Definition: vpp_echo_common.c:604