The friendly Operating System for the Internet of Things
netdev dummy test driver

Provides a test dummy for the netdev interface. More...

Detailed Description

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 "mutex.h"
#include "net/af.h"
#include "net/conn/udp.h"
#include "net/ipv6/addr.h"
#include "xtimer.h"
#define PKT_NUMBER (1000)
static netdev_test_t dev;
static uint32_t last_start;
static uint32_t sum = 0;
static mutex_t wait = MUTEX_INIT;
int _send_timer(netdev_t *dev, const struct iovec *vector, int count)
{
(void)dev;
(void)vector;
(void)count;
sum += (xtimer_now_usec() - last_start);
mutex_unlock(&wait);
}
int main(void) {
netdev_test_setup(&dev, NULL);
dev->driver->init((netdev_t *)&dev)
// initialize stack and connect `dev` to it
// ...
mutex_lock(&wait);
for (int i = 0; i < PKT_NUMBER; i++) {
last_start = xtimer_now_usec();
conn_udp_sendto("abcd", sizeof("abcd"), NULL, 0, &dst, sizeof(dst),
AF_INET6, 0xcafe, 0xcafe);
mutex_lock(&wait);
}
printf("Average send packet traversal time: %u\n", sum / PKT_NUMBER);
mutex_unlock(&wait);
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.

Files

file  netdev_test.h
 netdev dummy test driver definitions
 

Data Structures

struct  netdev_test_t
 Device descriptor for netdev dummy test driver devices. More...
 

Typedefs

typedef int(* netdev_test_send_cb_t) (netdev_t *dev, const struct iovec *vector, int count)
 Callback type to handle send command. More...
 
typedef int(* netdev_test_recv_cb_t) (netdev_t *dev, char *buf, int len, void *info)
 Callback type to handle receive command. More...
 
typedef int(* netdev_test_init_cb_t) (netdev_t *dev)
 Callback type to handle device initialization. More...
 
typedef void(* netdev_test_isr_cb_t) (netdev_t *dev)
 Callback type to handle user-space ISR events. More...
 
typedef int(* netdev_test_get_cb_t) (netdev_t *dev, void *value, size_t max_len)
 Callback type to handle get commands. More...
 
typedef int(* netdev_test_set_cb_t) (netdev_t *dev, void *value, size_t value_len)
 Callback type to handle set commands. More...
 

Functions

static void netdev_test_set_send_cb (netdev_test_t *dev, netdev_test_send_cb_t send_cb)
 override send callback More...
 
static void netdev_test_set_recv_cb (netdev_test_t *dev, netdev_test_recv_cb_t recv_cb)
 override receive callback More...
 
static void netdev_test_set_init_cb (netdev_test_t *dev, netdev_test_init_cb_t init_cb)
 override initialization callback More...
 
static void netdev_test_set_isr_cb (netdev_test_t *dev, netdev_test_isr_cb_t isr_cb)
 override ISR event handler callback More...
 
static void netdev_test_set_get_cb (netdev_test_t *dev, netopt_t opt, netdev_test_get_cb_t get_cb)
 override get callback for a certain option type More...
 
static void netdev_test_set_set_cb (netdev_test_t *dev, netopt_t opt, netdev_test_set_cb_t set_cb)
 override get callback for a certain option type More...
 
void netdev_test_setup (netdev_test_t *dev, void *state)
 Setup a given netdev dummy test driver device. More...
 
void netdev_test_reset (netdev_test_t *dev)
 Resets all callbacks for the device to NULL. More...
 

Typedef Documentation

typedef int(* netdev_test_get_cb_t) (netdev_t *dev, void *value, size_t max_len)
Parameters
[in]devnetwork device descriptor
[out]valuepointer to store the option's value in
[in]max_lenmaximal amount of bytes that fit into value
Returns
number of bytes written to value
<0 on error

Definition at line 152 of file netdev_test.h.

typedef int(* netdev_test_init_cb_t) (netdev_t *dev)
Parameters
[in]devnetwork device descriptor
Returns
<= on error
0 on success

Definition at line 133 of file netdev_test.h.

typedef void(* netdev_test_isr_cb_t) (netdev_t *dev)
Parameters
[in]devnetwork device descriptor

Definition at line 140 of file netdev_test.h.

typedef int(* netdev_test_recv_cb_t) (netdev_t *dev, char *buf, int len, void *info)
Parameters
[in]devnetwork device descriptor
[out]bufbuffer to write into or NULL
[in]lenmaximum number of bytes to read
[out]infostatus 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 122 of file netdev_test.h.

typedef int(* netdev_test_send_cb_t) (netdev_t *dev, const struct iovec *vector, int count)
Parameters
[in]devnetwork device descriptor
[in]vectorio vector array to send
[in]countnumber of entries in vector
Returns
number of bytes sent
<= 0 on error

Definition at line 104 of file netdev_test.h.

typedef int(* netdev_test_set_cb_t) (netdev_t *dev, void *value, size_t value_len)
Parameters
[in]devnetwork device descriptor
[out]valuevalue to set
[in]value_lenthe length of value
Returns
number of bytes used from value
<0 on error

Definition at line 165 of file netdev_test.h.

Function Documentation

void netdev_test_reset ( netdev_test_t dev)
Parameters
[in]deva netdev dummy test driver device to initialize
static void netdev_test_set_get_cb ( netdev_test_t dev,
netopt_t  opt,
netdev_test_get_cb_t  get_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]optan option type
[in]get_cba get callback for opt

Definition at line 263 of file netdev_test.h.

static void netdev_test_set_init_cb ( netdev_test_t dev,
netdev_test_init_cb_t  init_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]init_cban initialization callback

Definition at line 234 of file netdev_test.h.

static void netdev_test_set_isr_cb ( netdev_test_t dev,
netdev_test_isr_cb_t  isr_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]isr_cban ISR event handler callback

Definition at line 248 of file netdev_test.h.

static void netdev_test_set_recv_cb ( netdev_test_t dev,
netdev_test_recv_cb_t  recv_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]recv_cba receive callback

Definition at line 220 of file netdev_test.h.

static void netdev_test_set_send_cb ( netdev_test_t dev,
netdev_test_send_cb_t  send_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]send_cba send callback

Definition at line 206 of file netdev_test.h.

static void netdev_test_set_set_cb ( netdev_test_t dev,
netopt_t  opt,
netdev_test_set_cb_t  set_cb 
)
inlinestatic
Parameters
[in]deva netdev dummy test driver device
[in]optan option type
[in]set_cba set callback for opt

Definition at line 278 of file netdev_test.h.

void netdev_test_setup ( netdev_test_t dev,
void *  state 
)
Parameters
[in]deva netdev dummy test driver device to initialize
[in]stateexternal state for the device