static void test_ng_netif_add__memfull(void) { for (int i = 0; i < NG_NETIF_NUMOF; i++) { TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8 + i)); } TEST_ASSERT_EQUAL_INT(-ENOMEM, ng_netif_add(TEST_UINT8 - 1)); }
static void test_ng_netif_add__KERNEL_PID_UNDEF(void) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t size; TEST_ASSERT_EQUAL_INT(0, ng_netif_add(KERNEL_PID_UNDEF)); size = ng_netif_get(ifs); TEST_ASSERT_EQUAL_INT(0, size); }
static void test_ng_netif_add__success(void) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t size; TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8)); size = ng_netif_get(ifs); TEST_ASSERT_EQUAL_INT(1, size); TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); }
static void test_ng_netif_get__full(void) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t size; for (int i = 0; i < NG_NETIF_NUMOF; i++) { TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8 + i)); } size = ng_netif_get(ifs); TEST_ASSERT_EQUAL_INT(NG_NETIF_NUMOF, size); }
static void test_ng_netif_add__duplicate_entry(void) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t size; for (int i = 0; i < NG_NETIF_NUMOF + 4; i++) { TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8)); } size = ng_netif_get(ifs); TEST_ASSERT_EQUAL_INT(1, size); TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); }
static void test_netif_add__success_with_ipv6(void) { kernel_pid_t *pids; size_t pid_num; ng_ipv6_netif_t *entry; ng_ipv6_addr_t exp_addr = NG_IPV6_ADDR_ALL_NODES_LINK_LOCAL; ng_netif_add(DEFAULT_TEST_NETIF); TEST_ASSERT_NOT_NULL((pids = ng_netif_get(&pid_num))); TEST_ASSERT_EQUAL_INT(1, pid_num); TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, pids[0]); TEST_ASSERT_NOT_NULL((entry = ng_ipv6_netif_get(DEFAULT_TEST_NETIF))); TEST_ASSERT_EQUAL_INT(DEFAULT_TEST_NETIF, entry->pid); TEST_ASSERT_EQUAL_STRING((char *)exp_addr.u8, (char *)entry->addrs[0].addr.u8); }
ng_nettest_res_t ng_nettest_send_iface(kernel_pid_t pid, ng_pktsnip_t *in, unsigned int exp_pkts, kernel_pid_t exp_senders[], ng_pktsnip_t *exp_out[]) { ng_nettest_res_t res; ng_netif_add(thread_getpid()); res = _pkt_test(NG_NETAPI_MSG_TYPE_SND, pid, in, exp_pkts, exp_senders, exp_out); ng_netif_remove(thread_getpid()); return res; }
static void *_slip(void *args) { ng_slip_dev_t *dev = _SLIP_DEV(args); msg_t msg, reply, msg_q[_SLIP_MSG_QUEUE_SIZE]; msg_init_queue(msg_q, _SLIP_MSG_QUEUE_SIZE); dev->slip_pid = thread_getpid(); ng_netif_add(dev->slip_pid); DEBUG("slip: SLIP runs on UART_%d\n", uart); while (1) { DEBUG("slip: waiting for incoming messages\n"); msg_receive(&msg); switch (msg.type) { case _SLIP_MSG_TYPE: DEBUG("slip: incoming message from UART in buffer\n"); _slip_receive(dev, (size_t)msg.content.value); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("slip: NG_NETAPI_MSG_TYPE_SND received\n"); _slip_send(dev, (ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_GET: case NG_NETAPI_MSG_TYPE_SET: DEBUG("slip: NG_NETAPI_MSG_TYPE_GET or NG_NETAPI_MSG_TYPE_SET received\n"); reply.type = NG_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)(-ENOTSUP); DEBUG("slip: I don't support these but have to reply.\n"); msg_reply(&msg, &reply); break; } } /* should be never reached */ return NULL; }
/* takes one out of the middle of the netif list and checks if all interfaces * are gotten regardless */ static void test_ng_netif_get__success_3_minus_one(void) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t size; int count = 0; for (int i = 0; i < 3; i++) { TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8 + i)); } ng_netif_remove(TEST_UINT8 + 1); size = ng_netif_get(ifs); TEST_ASSERT_EQUAL_INT(2, size); for (size_t i = 0; i < size; i++) { if ((ifs[i] == TEST_UINT8) || ifs[i] == (TEST_UINT8 + 2)) { count++; } } TEST_ASSERT_EQUAL_INT(size, count); }
/** * @brief Startup code and event loop of the NOMAC layer * * @param[in] args expects a pointer to the underlying netdev device * * @return never returns */ static void *_nomac_thread(void *args) { ng_netdev_t *dev = (ng_netdev_t *)args; ng_netapi_opt_t *opt; int res; msg_t msg, reply, msg_queue[NG_NOMAC_MSG_QUEUE_SIZE]; /* setup the MAC layers message queue */ msg_init_queue(msg_queue, NG_NOMAC_MSG_QUEUE_SIZE); /* save the PID to the device descriptor and register the device */ dev->mac_pid = thread_getpid(); ng_netif_add(dev->mac_pid); /* register the event callback with the device driver */ dev->driver->add_event_callback(dev, _event_cb); /* start the event loop */ while (1) { DEBUG("nomac: waiting for incoming messages\n"); msg_receive(&msg); /* dispatch NETDEV and NETAPI messages */ switch (msg.type) { case NG_NETDEV_MSG_TYPE_EVENT: DEBUG("nomac: NG_NETDEV_MSG_TYPE_EVENT received\n"); dev->driver->isr_event(dev, msg.content.value); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("nomac: NG_NETAPI_MSG_TYPE_SND received\n"); dev->driver->send_data(dev, (ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SET: /* TODO: filter out MAC layer options -> for now forward everything to the device driver */ DEBUG("nomac: NG_NETAPI_MSG_TYPE_SET received\n"); /* read incoming options */ opt = (ng_netapi_opt_t *)msg.content.ptr; /* set option for device driver */ res = dev->driver->set(dev, opt->opt, opt->data, opt->data_len); DEBUG("nomac: response of netdev->set: %i\n", res); /* send reply to calling thread */ reply.type = NG_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)res; msg_reply(&msg, &reply); break; case NG_NETAPI_MSG_TYPE_GET: /* TODO: filter out MAC layer options -> for now forward everything to the device driver */ DEBUG("nomac: NG_NETAPI_MSG_TYPE_GET received\n"); /* read incoming options */ opt = (ng_netapi_opt_t *)msg.content.ptr; /* get option from device driver */ res = dev->driver->get(dev, opt->opt, opt->data, opt->data_len); DEBUG("nomac: response of netdev->get: %i\n", res); /* send reply to calling thread */ reply.type = NG_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)res; msg_reply(&msg, &reply); break; default: DEBUG("nomac: Unknown command %" PRIu16 "\n", msg.type); break; } } /* never reached */ return NULL; }