Motr  M0
ping.c File Reference
#include "lib/assert.h"
#include "lib/errno.h"
#include "lib/memory.h"
#include "lib/misc.h"
#include "net/net.h"
#include "net/bulk_mem.h"
#include "net/bulk_emulation/st/ping.h"
Include dependency graph for ping.c:

Go to the source code of this file.

Data Structures

struct  ping_work_item
 
struct  ping_msg
 

Macros

#define DEF_RESPONSE   "active pong"
 
#define DEF_SEND   "passive ping"
 
#define SEND_RESP   " pong"
 

Enumerations

enum  { SEND_RETRIES = 3 }
 
enum  ping_msg_type {
  PM_SEND_DESC, PM_RECV_DESC, PM_MSG, PM_SEND_DESC,
  PM_RECV_DESC, PM_MSG
}
 

Functions

static void ping_sleep_secs (int secs)
 
int alloc_buffers (int num, uint32_t segs, m0_bcount_t segsize, struct m0_net_buffer **out)
 
struct m0_net_bufferping_buf_get (struct ping_ctx *ctx)
 
void ping_buf_put (struct ping_ctx *ctx, struct m0_net_buffer *nb)
 
static void netbuf_step (struct m0_bufvec_cursor *cur)
 
int encode_msg (struct m0_net_buffer *nb, const char *str)
 
int encode_desc (struct m0_net_buffer *nb, bool send_desc, const struct m0_net_buf_desc *desc)
 
int decode_msg (struct m0_net_buffer *nb, struct ping_msg *msg)
 
void msg_free (struct ping_msg *msg)
 
static struct ping_ctxbuffer_event_to_ping_ctx (const struct m0_net_buffer_event *ev)
 
void c_m_recv_cb (const struct m0_net_buffer_event *ev)
 
void c_m_send_cb (const struct m0_net_buffer_event *ev)
 
void c_p_recv_cb (const struct m0_net_buffer_event *ev)
 
void c_p_send_cb (const struct m0_net_buffer_event *ev)
 
void c_a_recv_cb (const struct m0_net_buffer_event *ev)
 
void c_a_send_cb (const struct m0_net_buffer_event *ev)
 
void event_cb (const struct m0_net_tm_event *ev)
 
static void server_event_ident (char *buf, const char *ident, const struct m0_net_buffer_event *ev)
 
void s_m_recv_cb (const struct m0_net_buffer_event *ev)
 
void s_m_send_cb (const struct m0_net_buffer_event *ev)
 
void s_p_recv_cb (const struct m0_net_buffer_event *ev)
 
void s_p_send_cb (const struct m0_net_buffer_event *ev)
 
void s_a_recv_cb (const struct m0_net_buffer_event *ev)
 
void s_a_send_cb (const struct m0_net_buffer_event *ev)
 
void ping_fini (struct ping_ctx *ctx)
 
int ping_init (struct ping_ctx *ctx)
 
void ping_server (struct ping_ctx *ctx)
 
void ping_server_should_stop (struct ping_ctx *ctx)
 
int ping_client_msg_send_recv (struct ping_ctx *ctx, struct m0_net_end_point *server_ep, const char *data)
 
int ping_client_passive_recv (struct ping_ctx *ctx, struct m0_net_end_point *server_ep)
 
int ping_client_passive_send (struct ping_ctx *ctx, struct m0_net_end_point *server_ep, const char *data)
 
int ping_client_init (struct ping_ctx *ctx, struct m0_net_end_point **server_ep)
 
int ping_client_fini (struct ping_ctx *ctx, struct m0_net_end_point *server_ep)
 

Variables

bool server_stop = false
 
struct m0_net_buffer_callbacks cbuf_cb
 
struct m0_net_tm_callbacks ctm_cb
 
static struct m0_atomic64 s_msg_recv_counter
 
struct m0_net_buffer_callbacks sbuf_cb
 
struct m0_net_tm_callbacks stm_cb
 

Macro Definition Documentation

◆ DEF_RESPONSE

#define DEF_RESPONSE   "active pong"

Definition at line 31 of file ping.c.

◆ DEF_SEND

#define DEF_SEND   "passive ping"

Definition at line 32 of file ping.c.

◆ SEND_RESP

#define SEND_RESP   " pong"

Definition at line 33 of file ping.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Descriptor for the tlist of buffers.

Enumerator
SEND_RETRIES 

Definition at line 36 of file ping.c.

◆ ping_msg_type

Enumerator
PM_SEND_DESC 

client wants to do passive send, server will active recv

PM_RECV_DESC 

client wants to do active send, server will passive recv

PM_MSG 
PM_SEND_DESC 

client wants to do passive send, server will active recv

PM_RECV_DESC 

client wants to do active send, server will passive recv

PM_MSG 

Definition at line 176 of file ping.c.

Function Documentation

◆ alloc_buffers()

int alloc_buffers ( int  num,
uint32_t  segs,
m0_bcount_t  segsize,
struct m0_net_buffer **  out 
)

Definition at line 52 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buffer_event_to_ping_ctx()

static struct ping_ctx* buffer_event_to_ping_ctx ( const struct m0_net_buffer_event ev)
static

Definition at line 242 of file ping.c.

Here is the caller graph for this function:

◆ c_a_recv_cb()

void c_a_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 444 of file ping.c.

◆ c_a_send_cb()

void c_a_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 451 of file ping.c.

◆ c_m_recv_cb()

void c_m_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 250 of file ping.c.

Here is the call graph for this function:

◆ c_m_send_cb()

void c_m_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 308 of file ping.c.

Here is the call graph for this function:

◆ c_p_recv_cb()

void c_p_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 349 of file ping.c.

Here is the call graph for this function:

◆ c_p_send_cb()

void c_p_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 414 of file ping.c.

Here is the call graph for this function:

◆ decode_msg()

int decode_msg ( struct m0_net_buffer nb,
struct ping_msg msg 
)

decode a net buffer, allocates memory and copies payload

Definition at line 193 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_desc()

int encode_desc ( struct m0_net_buffer nb,
bool  send_desc,
const struct m0_net_buf_desc desc 
)

encode a descriptor into a net buffer, not zero-copy

Definition at line 151 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_msg()

int encode_msg ( struct m0_net_buffer nb,
const char *  str 
)

encode a string message into a net buffer, not zero-copy

Definition at line 130 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event_cb()

void event_cb ( const struct m0_net_tm_event ev)

Definition at line 458 of file ping.c.

◆ msg_free()

void msg_free ( struct ping_msg msg)

Definition at line 233 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netbuf_step()

static void netbuf_step ( struct m0_bufvec_cursor cur)
static

Definition at line 123 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_buf_get()

struct m0_net_buffer* ping_buf_get ( struct ping_ctx ctx)

Get a unused buffer from the context buffer list. On success, marks the buffer as in-use and returns it.

Return values
ptrthe buffer
NULLfailure

Definition at line 86 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_buf_put()

void ping_buf_put ( struct ping_ctx ctx,
struct m0_net_buffer nb 
)

Releases a buffer back to the free buffer pool. The buffer is marked as not in-use.

Definition at line 111 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_client_fini()

int ping_client_fini ( struct ping_ctx ctx,
struct m0_net_end_point server_ep 
)

Definition at line 1292 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_client_init()

int ping_client_init ( struct ping_ctx ctx,
struct m0_net_end_point **  server_ep 
)

Definition at line 1261 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_client_msg_send_recv()

int ping_client_msg_send_recv ( struct ping_ctx ctx,
struct m0_net_end_point server_ep,
const char *  data 
)

Test an RPC-like exchange, sending data in a message to the server and getting back a response.

Parameters
ctxclient context
server_ependpoint of the server
datadata to send, or NULL to send a default "ping"
Return values
0successful test
-errnofailed to send to server

Definition at line 1007 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_client_passive_recv()

int ping_client_passive_recv ( struct ping_ctx ctx,
struct m0_net_end_point server_ep 
)

Definition at line 1088 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_client_passive_send()

int ping_client_passive_send ( struct ping_ctx ctx,
struct m0_net_end_point server_ep,
const char *  data 
)

Definition at line 1172 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_fini()

void ping_fini ( struct ping_ctx ctx)

Definition at line 863 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_init()

int ping_init ( struct ping_ctx ctx)

Initialise a ping client or server. Calls all the required m0_net APIs in the correct order, with cleanup on failure. On success, the transfer machine is started.

Parameters
ctxthe client/server context. pc_xprt, pc_nr_bufs, pc_tm, pc_hostname, pc_port and pc_id must be initialised by the caller.
Return values
0success
-errnofailure

Definition at line 790 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_server()

void ping_server ( struct ping_ctx ctx)

Definition at line 907 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_server_should_stop()

void ping_server_should_stop ( struct ping_ctx ctx)

Definition at line 990 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_sleep_secs()

static void ping_sleep_secs ( int  secs)
static

Definition at line 46 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ s_a_recv_cb()

void s_a_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 684 of file ping.c.

Here is the call graph for this function:

◆ s_a_send_cb()

void s_a_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 741 of file ping.c.

Here is the call graph for this function:

◆ s_m_recv_cb()

void s_m_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 519 of file ping.c.

Here is the call graph for this function:

◆ s_m_send_cb()

void s_m_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 646 of file ping.c.

Here is the call graph for this function:

◆ s_p_recv_cb()

void s_p_recv_cb ( const struct m0_net_buffer_event ev)

Definition at line 670 of file ping.c.

◆ s_p_send_cb()

void s_p_send_cb ( const struct m0_net_buffer_event ev)

Definition at line 677 of file ping.c.

◆ server_event_ident()

static void server_event_ident ( char *  buf,
const char *  ident,
const struct m0_net_buffer_event ev 
)
static

Definition at line 498 of file ping.c.

Here is the caller graph for this function:

Variable Documentation

◆ cbuf_cb

struct m0_net_buffer_callbacks cbuf_cb
Initial value:
= {
.nbc_cb = {
},
}
void c_a_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:451
void c_m_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:250
void c_m_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:308
void c_a_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:444
void c_p_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:414
void c_p_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:349

Definition at line 483 of file ping.c.

◆ ctm_cb

struct m0_net_tm_callbacks ctm_cb
Initial value:
= {
.ntc_event_cb = event_cb
}
void event_cb(const struct m0_net_tm_event *ev)
Definition: ping.c:458

Definition at line 494 of file ping.c.

◆ s_msg_recv_counter

struct m0_atomic64 s_msg_recv_counter
static

Definition at line 516 of file ping.c.

◆ sbuf_cb

struct m0_net_buffer_callbacks sbuf_cb
Initial value:
= {
.nbc_cb = {
},
}
void s_m_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:519
void s_p_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:677
void s_m_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:646
void s_p_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:670
void s_a_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:741
void s_a_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:684

Definition at line 763 of file ping.c.

◆ server_stop

bool server_stop = false

Definition at line 481 of file ping.c.

◆ stm_cb

struct m0_net_tm_callbacks stm_cb
Initial value:
= {
.ntc_event_cb = event_cb
}
void event_cb(const struct m0_net_tm_event *ev)
Definition: ping.c:458

Definition at line 774 of file ping.c.