Ping#
The Ping component implements a ping service using the ICMPv6 protocol. It can send ICMPv6 Echo Request, receive corresponding responses, and calculate round-trip latency.
Applications can emit a single ping packet using the sl_wisun_ping_request() API. To receive the pong response, the sl_wisun_ping_response() API is called. The sl_wisun_ping() function offers a straightforward solution for periodic ping packet transmission and reception. To halt the process, use the sl_wisun_ping_stop() function.
Ping test parameters such as size, number of pings sent, and timeout for response absence are configurable. Initialization of the component is done by calling the sl_wisun_ping_init() function.
The following example demonstrates how the ping request can be called:
#include "sl_wisun_ping.h"
static void ping_remote(void) {
int32_t ret = 0;
sockaddr_in6_t remote_addr = { 0 };
sl_status_t status = SL_STATUS_FAIL;
// Create address structure from ping
ret = inet_pton(AF_INET6,
"2001:db8::1",
&remote_addr.sin6_addr);
if (ret != 1) {
// Error handling
return;
}
// Send and receive ping requests and responses
status = sl_wisun_ping(&remote_addr, // Ping remote_addr IPv6 address
10, // with 10 packets
512, // packet length is 512 bytes
NULL, // Custom statitistic handler is not required
NULL); // Request/Response handler is not required
if (status != SL_STATUS_OK) {
// Error handling
return;
}
}
Modules#
Functions#
Provide a high level ping API.
Initialize the ping service module.
Send a ping request.
Retrieve a ping response.
Stop the current ping process.
Macros#
Ping echo request code field value.
Ping echo response code field value.
Dedicated port for ICMPv6 echo messages.
Max packet length.
Maximum count of ping request/response for message queues.
Minimum packet length with 1 byte payload.
Ping echo request type field value.
Ping echo response type field value.
Function Documentation#
sl_wisun_ping#
sl_status_t sl_wisun_ping (const sockaddr_in6_t *const remote_addr, const uint16_t packet_count, const uint16_t packet_length, sl_wisun_ping_stat_hnd_t stat_hnd, sl_wisun_ping_req_resp_done_hnd_t req_resp_sent_hnd)
Provide a high level ping API.
[in] | remote_addr | Remote destination address |
[in] | packet_count | Count of packets |
[in] | packet_length | ICMPv6 packet length including header |
[in] | stat_hnd | Custom statistic handler function |
[in] | req_resp_sent_hnd | Request/Response sent handler function |
The function provides an interface for periodically sending and receiving ping ICMPv6 packets, and collecting statistic data. Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL or SL_STATUS_ABORT
194
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
sl_wisun_ping_init#
void sl_wisun_ping_init (void )
Initialize the ping service module.
N/A |
This function initializes the service thread, mutex, and message queues.
167
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
sl_wisun_ping_request#
void sl_wisun_ping_request (const sl_wisun_ping_info_t *const ping_request)
Send a ping request.
[in] | ping_request | Ping Request Information |
The function sends a single ICMPv6 request.
174
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
sl_wisun_ping_response#
void sl_wisun_ping_response (sl_wisun_ping_info_t *const ping_response)
Retrieve a ping response.
[out] | ping_response | Ping Response Information |
The function retrieves a ping response information.
181
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
sl_wisun_ping_stop#
void sl_wisun_ping_stop (void )
Stop the current ping process.
N/A |
Reset request and response queues and send a special ping request with interrupt ping status.
205
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
Macro Definition Documentation#
SL_WISUN_PING_CODE_ECHO_REQUEST#
#define SL_WISUN_PING_CODE_ECHO_REQUESTValue:
(0U)
Ping echo request code field value.
73
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_CODE_ECHO_RESPONSE#
#define SL_WISUN_PING_CODE_ECHO_RESPONSEValue:
(0U)
Ping echo response code field value.
76
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_ICMP_PORT#
#define SL_WISUN_PING_ICMP_PORTValue:
(0U)
Dedicated port for ICMPv6 echo messages.
79
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_MAX_PACKET_LENGTH#
#define SL_WISUN_PING_MAX_PACKET_LENGTHValue:
(SL_WISUN_PING_MIN_PACKET_LENGTH - 1 + SL_WISUN_PING_MAX_PAYLOAD_LENGTH)
Max packet length.
64
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_MAX_REQUEST_RESPONSE#
#define SL_WISUN_PING_MAX_REQUEST_RESPONSEValue:
(128U)
Maximum count of ping request/response for message queues.
58
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_MIN_PACKET_LENGTH#
#define SL_WISUN_PING_MIN_PACKET_LENGTHValue:
(9U)
Minimum packet length with 1 byte payload.
61
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_TYPE_ECHO_REQUEST#
#define SL_WISUN_PING_TYPE_ECHO_REQUESTValue:
(128U)
Ping echo request type field value.
67
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h
SL_WISUN_PING_TYPE_ECHO_RESPONSE#
#define SL_WISUN_PING_TYPE_ECHO_RESPONSEValue:
(129U)
Ping echo response type field value.
70
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ping/sl_wisun_ping.h