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;
}
Global UNIX address family definitions.
#define AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
#define MUTEX_INIT
Static initializer for mutex_t.
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
#define IPV6_ADDR_UNSPECIFIED
Static initializer for the unspecified IPv6 address (::)
void netdev_test_setup(netdev_test_t *dev, void *state)
Setup a given netdev dummy test driver device.
static uint32_t xtimer_now_usec(void)
get the current system time in microseconds since start
Definitions for IPv6 addresses.
Mutex for thread synchronization.
netdev dummy test driver definitions
iolist structure definition
int(* init)(netdev_t *dev)
the driver's initialization function
netdev_t netdev
netdev_t base class
Device descriptor for netdev dummy test driver devices.
netdev_ieee802154_t netdev
netdev fields
Structure to hold driver state.
const struct netdev_driver * driver
ptr to that driver's interface.
Data type to represent an IPv6 address.
xtimer interface definitions
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 145 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 126 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 133 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 115 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 99 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 158 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 252 of file netdev_test.h.
◆ netdev_test_set_init_cb()
override initialization callback
- Parameters
-
Definition at line 223 of file netdev_test.h.
◆ netdev_test_set_isr_cb()
override ISR event handler callback
- Parameters
-
Definition at line 237 of file netdev_test.h.
◆ netdev_test_set_recv_cb()
override receive callback
- Parameters
-
Definition at line 209 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 267 of file netdev_test.h.
◆ netdev_test_setup()