Provides a test dummy for the netdev interface.
More...
Provides a test dummy for the netdev interface.
See the following simple packet traversal timer for an example. Note that this example assumes that the stack doesn't require any option values from the device and that the stack doesn't create packets on its own or looses packets (neither of those can be assumed for in-production stacks).
#include <stdint.h>
#include "net/conn/udp.h"
#define PKT_NUMBER (1000)
static uint32_t last_start;
static uint32_t sum = 0;
{
(void)dev;
}
int main(void) {
for (int i = 0; i < PKT_NUMBER; i++) {
conn_udp_sendto("abcd", sizeof("abcd"), NULL, 0, &dst, sizeof(dst),
}
printf("Average send packet traversal time: %u\n", sum / PKT_NUMBER);
return 0;
}
To provide options to the stack, the get callbacks for the specific options need to be set. To catch lost packets and additional sent by the stack the send handler needs to be adapted accordingly.
◆ netdev_test_get_cb_t
typedef int(* netdev_test_get_cb_t) (netdev_t *dev, void *value, size_t max_len) |
Callback type to handle get commands.
- Parameters
-
[in] | dev | network device descriptor |
[out] | value | pointer to store the option's value in |
[in] | max_len | maximal amount of bytes that fit into value |
- Returns
- number of bytes written to
value
-
<0 on error
Definition at line 148 of file netdev_test.h.
◆ netdev_test_init_cb_t
typedef int(* netdev_test_init_cb_t) (netdev_t *dev) |
Callback type to handle device initialization.
- Parameters
-
[in] | dev | network device descriptor |
- Returns
- <= on error
-
0 on success
Definition at line 129 of file netdev_test.h.
◆ netdev_test_isr_cb_t
typedef void(* netdev_test_isr_cb_t) (netdev_t *dev) |
Callback type to handle user-space ISR events.
- Parameters
-
[in] | dev | network device descriptor |
Definition at line 136 of file netdev_test.h.
◆ netdev_test_recv_cb_t
typedef int(* netdev_test_recv_cb_t) (netdev_t *dev, char *buf, int len, void *info) |
Callback type to handle receive command.
- Parameters
-
[in] | dev | network device descriptor |
[out] | buf | buffer to write into or NULL |
[in] | len | maximum number of bytes to read |
[out] | info | status information for the received packet. Might be of different type for different netdev devices. May be NULL if not needed or applicable |
- Returns
- <=0 on error
-
number of bytes read if buf != NULL
-
currently received packet size if buf == NULL
Definition at line 118 of file netdev_test.h.
◆ netdev_test_send_cb_t
Callback type to handle send command.
- Parameters
-
[in] | dev | network device descriptor |
[in] | iolist | io vector list to send |
- Returns
- number of bytes sent
-
<= 0 on error
Definition at line 102 of file netdev_test.h.
◆ netdev_test_set_cb_t
typedef int(* netdev_test_set_cb_t) (netdev_t *dev, const void *value, size_t value_len) |
Callback type to handle set commands.
- Parameters
-
[in] | dev | network device descriptor |
[in] | value | value to set |
[in] | value_len | the length of value |
- Returns
- number of bytes used from
value
-
<0 on error
Definition at line 161 of file netdev_test.h.
◆ netdev_test_reset()
Resets all callbacks for the device to NULL.
- Parameters
-
◆ netdev_test_set_get_cb()
override get callback for a certain option type
- Parameters
-
Definition at line 259 of file netdev_test.h.
◆ netdev_test_set_init_cb()
override initialization callback
- Parameters
-
Definition at line 230 of file netdev_test.h.
◆ netdev_test_set_isr_cb()
override ISR event handler callback
- Parameters
-
Definition at line 244 of file netdev_test.h.
◆ netdev_test_set_recv_cb()
override receive callback
- Parameters
-
Definition at line 216 of file netdev_test.h.
◆ netdev_test_set_send_cb()
◆ netdev_test_set_set_cb()
override get callback for a certain option type
- Parameters
-
Definition at line 274 of file netdev_test.h.
◆ netdev_test_setup()