예제 #1
0
static void test_ipv6_netif_find_best_src_addr__success(void)
{
    ng_ipv6_addr_t ll_addr1 = NG_IPV6_ADDR_UNSPECIFIED;
    ng_ipv6_addr_t ll_addr2 = NG_IPV6_ADDR_UNSPECIFIED;
    ng_ipv6_addr_t mc_addr = NG_IPV6_ADDR_ALL_NODES_LINK_LOCAL;
    ng_ipv6_addr_t *out = NULL;

    ll_addr1.u8[15] = 1;
    ng_ipv6_addr_set_link_local_prefix(&ll_addr1);
    ll_addr2.u8[15] = 2;
    ng_ipv6_addr_set_link_local_prefix(&ll_addr2);

    TEST_ASSERT_EQUAL_INT(126, ng_ipv6_addr_match_prefix(&ll_addr2, &ll_addr1));

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
    TEST_ASSERT_EQUAL_INT(0, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &mc_addr,
                          DEFAULT_TEST_PREFIX_LEN, false));
    TEST_ASSERT_EQUAL_INT(0, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &ll_addr1,
                          DEFAULT_TEST_PREFIX_LEN, false));

    TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &ll_addr2)));
    TEST_ASSERT(out != &ll_addr1);
    TEST_ASSERT(out != &ll_addr2);
    TEST_ASSERT_EQUAL_INT(true, ng_ipv6_addr_equal(out, &ll_addr1));
}
예제 #2
0
static void test_ipv6_netif_add_addr__despite_free_entry(void)
{
    /* Tests for possible duplicates as described in http://github.com/RIOT-OS/RIOT/issues/2965 */
    ipv6_addr_t *entry_1;
    ipv6_addr_t *entry_2;

    ipv6_addr_t default_addr = DEFAULT_TEST_IPV6_ADDR;
    ipv6_addr_t ll_addr;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    /* add addresses to the interface */
    TEST_ASSERT_NOT_NULL((entry_1 = ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &default_addr, DEFAULT_TEST_PREFIX_LEN, 0)));

    /* remove default_addr, but not the others (corresponding lla, solicited-node addr)
     * that came with it */
    ng_ipv6_netif_remove_addr(DEFAULT_TEST_NETIF, &default_addr);

    /* create and re-add corresponding lla and check that it hasn't taken
     * the old place of default_addr*/
    ll_addr.u64[1] = default_addr.u64[1];
    ipv6_addr_set_link_local_prefix(&ll_addr);
    TEST_ASSERT_NOT_NULL((entry_2 = ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &ll_addr, DEFAULT_TEST_PREFIX_LEN, 0)));

    TEST_ASSERT(entry_1 != entry_2);
}
예제 #3
0
static void test_ipv6_netif_add_addr__addr_NULL(void)
{
    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_EQUAL_INT(-EINVAL, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF,
                          NULL, DEFAULT_TEST_PREFIX_LEN, false));
}
예제 #4
0
static void test_ipv6_netif_add_addr__no_iface1(void)
{
    ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;

    TEST_ASSERT_EQUAL_INT(-ENOENT, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF,
                          &addr, DEFAULT_TEST_PREFIX_LEN, false));
}
예제 #5
0
static void test_ipv6_netif_add_addr__success(void)
{
    ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_NOT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));
}
예제 #6
0
static void test_ipv6_netif_add_addr__addr_unspecified(void)
{
    ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));
}
예제 #7
0
static void test_ipv6_netif_add_addr__addr_unspecified(void)
{
    ng_ipv6_addr_t addr = NG_IPV6_ADDR_UNSPECIFIED;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_EQUAL_INT(-EINVAL, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF,
                          &addr, DEFAULT_TEST_PREFIX_LEN, false));
}
예제 #8
0
static void test_ipv6_netif_add_addr__success(void)
{
    ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_EQUAL_INT(0, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr,
                          DEFAULT_TEST_PREFIX_LEN, false));
}
예제 #9
0
static void test_ipv6_netif_find_best_src_addr__no_unicast(void)
{
    ipv6_addr_t ll_addr1 = IPV6_ADDR_UNSPECIFIED;
    ipv6_addr_t ll_addr2 = IPV6_ADDR_UNSPECIFIED;
    ipv6_addr_t mc_addr = IPV6_ADDR_ALL_NODES_LINK_LOCAL;

    ll_addr1.u8[15] = 1;
    ipv6_addr_set_link_local_prefix(&ll_addr1);
    ll_addr2.u8[15] = 2;
    ipv6_addr_set_link_local_prefix(&ll_addr2);

    TEST_ASSERT_EQUAL_INT(126, ipv6_addr_match_prefix(&ll_addr2, &ll_addr1));

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
    TEST_ASSERT_NOT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &mc_addr, DEFAULT_TEST_PREFIX_LEN,
                         0));
    TEST_ASSERT_NOT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &ll_addr1, DEFAULT_TEST_PREFIX_LEN,
                         NG_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST));

    TEST_ASSERT_NULL(ng_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &ll_addr2));
}
예제 #10
0
static void test_ipv6_netif_addr_is_non_unicast__multicast1(void)
{
    ipv6_addr_t addr = IPV6_ADDR_ALL_ROUTERS_LINK_LOCAL;
    ipv6_addr_t *out = NULL;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_NOT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));

    TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
    TEST_ASSERT_EQUAL_INT(true, ng_ipv6_netif_addr_is_non_unicast(out));
}
예제 #11
0
static void test_ipv6_netif_addr_is_non_unicast__anycast(void)
{
    ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
    ng_ipv6_addr_t *out = NULL;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_EQUAL_INT(0, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr,
                          DEFAULT_TEST_PREFIX_LEN, true));

    TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
    TEST_ASSERT_EQUAL_INT(true, ng_ipv6_netif_addr_is_non_unicast(out));
}
예제 #12
0
static void test_ipv6_netif_add_addr__full(void)
{
    ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR, *res = &addr;
    int i;

    /* make link local to avoid automatic link local adding */
    ipv6_addr_set_link_local_prefix(&addr);

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    for (i = 0; res != NULL; i++, addr.u8[15]++) {
        res =  ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0);
    }
}
예제 #13
0
static void test_ipv6_netif_add_addr__ENOMEM(void)
{
    ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
    int res = 0, i;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    for (i = 0; res != -ENOMEM; i++, addr.u8[15]++) {
        res =  ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr,
                                      DEFAULT_TEST_PREFIX_LEN, false);
    }

    TEST_ASSERT_EQUAL_INT(NG_IPV6_NETIF_ADDR_NUMOF, i);
}
예제 #14
0
static void test_ipv6_netif_find_best_src_addr__other_subnet(void)
{
    ipv6_addr_t addr1 = DEFAULT_TEST_IPV6_ADDR;
    ipv6_addr_t addr2 = OTHER_TEST_IPV6_ADDR;

    ipv6_addr_t *out = NULL;

    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
    TEST_ASSERT_NOT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr1, DEFAULT_TEST_PREFIX_LEN,
                         0));

    TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_best_src_addr(DEFAULT_TEST_NETIF, &addr2)));
    TEST_ASSERT(out != &addr1);
    TEST_ASSERT_EQUAL_INT(true, ipv6_addr_equal(out, &addr1));
}
예제 #15
0
static void test_ipv6_netif_add_addr__no_iface1(void)
{
    ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;

    TEST_ASSERT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, &addr, DEFAULT_TEST_PREFIX_LEN, 0));
}
예제 #16
0
static void test_ipv6_netif_add_addr__addr_NULL(void)
{
    test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */

    TEST_ASSERT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, NULL, DEFAULT_TEST_PREFIX_LEN, 0));
}
예제 #17
0
static void test_ipv6_netif_add_addr__no_iface2(void)
{
    TEST_ASSERT_NULL(ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF, NULL, DEFAULT_TEST_PREFIX_LEN, 0));
}
예제 #18
0
static void test_ipv6_netif_add_addr__no_iface2(void)
{
    TEST_ASSERT_EQUAL_INT(-ENOENT, ng_ipv6_netif_add_addr(DEFAULT_TEST_NETIF,
                          NULL, DEFAULT_TEST_PREFIX_LEN, false));
}
예제 #19
0
파일: sc_netif.c 프로젝트: 4dahalibut/RIOT
static int _netif_add(char *cmd_name, kernel_pid_t dev, int argc, char **argv)
{
#ifdef MODULE_NG_IPV6_NETIF
    enum {
        _UNICAST = 0,
        _MULTICAST,     /* multicast value just to check if given addr is mc */
        _ANYCAST
    } type = _UNICAST;
    char *addr_str = argv[0];
    ng_ipv6_addr_t addr;
    uint8_t prefix_len;

    if (argc > 1) {
        if (strcmp(argv[0], "anycast") == 0) {
            type = _ANYCAST;
            addr_str = argv[1];
        }
        else if (strcmp(argv[0], "multicast") == 0) {
            type = _MULTICAST;
            addr_str = argv[1];
        }
        else if (strcmp(argv[0], "unicast") == 0) {
            /* type already set to unicast */
            addr_str = argv[1];
        }
        else {
            _add_usage(cmd_name);
            return 1;
        }
    }

    prefix_len = _get_prefix_len(addr_str);

    if (ng_ipv6_addr_from_str(&addr, addr_str) == NULL) {
        puts("error: unable to parse IPv6 address.");
        return 1;
    }

    if ((argc > 1) && (ng_ipv6_addr_is_multicast(&addr)) && (type != _MULTICAST)) {
        puts("error: address was not a multicast address.");
        return 1;
    }

    if (ng_ipv6_netif_add_addr(dev, &addr, prefix_len,
                               (type == _ANYCAST) ?
                               NG_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST :
                               NG_IPV6_NETIF_ADDR_FLAGS_UNICAST) == NULL) {
        printf("error: unable to add IPv6 address\n");
        return 1;
    }

    printf("success: added %s/%d to interface %" PRIkernel_pid "\n", addr_str,
           prefix_len, dev);

    return 0;
#else
    (void)cmd_name;
    (void)dev;
    (void)argc;
    (void)argv;
    puts("error: unable to add IPv6 address.");

    return 1;
#endif
}