示例#1
0
文件: ng_ndp.c 项目: tuyenth/RIOT
static ng_ipv6_addr_t *_default_router(void)
{
    ng_ipv6_nc_t *router = ng_ipv6_nc_get_next_router(NULL);

    /* first look if there is any reachable router */
    while (router != NULL) {
        if ((ng_ipv6_nc_get_state(router) != NG_IPV6_NC_STATE_INCOMPLETE) &&
            (ng_ipv6_nc_get_state(router) != NG_IPV6_NC_STATE_UNREACHABLE)) {
            _last_router = NULL;

            return &router->ipv6_addr;
        }

        router = ng_ipv6_nc_get_next_router(router);
    }

    /* else take the first one, but keep round-robin in further selections */
    router = ng_ipv6_nc_get_next_router(_last_router);

    if (router == NULL) {   /* end of router list or there is none => wrap around */
        router = ng_ipv6_nc_get_next_router(router);

        if (router == NULL) {   /* still nothing found => no router in list */
            return NULL;
        }
    }

    _last_router = router;

    return &router->ipv6_addr;
}
示例#2
0
文件: sc_ipv6_nc.c 项目: robby14/RIOT
int _ipv6_nc_routers(int argc, char **argv)
{
    kernel_pid_t iface = KERNEL_PID_UNDEF;
    char ipv6_str[IPV6_ADDR_MAX_STR_LEN];

    if (argc > 1) {
        iface = atoi(argv[1]);

        if (!_is_iface(iface)) {
            printf("usage: %s [<iface pid>]\n", argv[0]);
            return 1;
        }
    }

    puts("if  Router                          state      type");
    puts("---------------------------------------------------");

    for (ng_ipv6_nc_t *entry = ng_ipv6_nc_get_next_router(NULL);
         entry != NULL;
         entry = ng_ipv6_nc_get_next_router(entry)) {
        if ((iface != KERNEL_PID_UNDEF) && (iface != entry->iface)) {
            continue;
        }

        printf("%2" PRIkernel_pid "  %-30s  ", entry->iface,
               ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str)));
        _print_nc_state(entry);
        _print_nc_type(entry);
        puts("");
    }

    return 0;
}
示例#3
0
static void test_ipv6_nc_get_next_router__first_entry(void)
{
    ng_ipv6_nc_t *entry = NULL;

    /* adds DEFAULT_TEST_IPV6_ADDR and OTHER_TEST_IPV6_ADDR to DEFAULT_TEST_NETIF */
    test_ipv6_nc_get_next__2_entries();
    TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_next(NULL)));
    entry->flags = (NG_IPV6_NC_STATE_REACHABLE << NG_IPV6_NC_STATE_POS);
    entry->flags |= NG_IPV6_NC_IS_ROUTER;

    TEST_ASSERT_NOT_NULL((entry = ng_ipv6_nc_get_next_router(NULL)));
    TEST_ASSERT_NULL(ng_ipv6_nc_get_next_router(entry));
}
示例#4
0
static void test_ipv6_nc_get_next_router__empty(void)
{
    TEST_ASSERT_NULL(ng_ipv6_nc_get_next_router(NULL));
}