Skip to content

Commit

Permalink
Merge pull request #1554 from OlegHahm/rpl_udp_cleanup
Browse files Browse the repository at this point in the history
examples: rpl_udp cleanup
  • Loading branch information
OlegHahm committed Aug 21, 2014
2 parents 003dd19 + 400fb29 commit 28df569
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 184 deletions.
52 changes: 0 additions & 52 deletions examples/rpl_udp/demo.h

This file was deleted.

6 changes: 3 additions & 3 deletions examples/rpl_udp/helper.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 INRIA
* Copyright (C) 2013, 2014 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -25,9 +25,9 @@
#include "sixlowpan/ip.h"
#include "transceiver.h"
#include "ieee802154_frame.h"
#include "rpl_structs.h"
#include "rpl/rpl_structs.h"

#include "demo.h"
#include "rpl_udp.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand Down
8 changes: 3 additions & 5 deletions examples/rpl_udp/main.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 INRIA
* Copyright (C) 2013, 2014 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand Down Expand Up @@ -27,17 +27,15 @@
#include "board_uart0.h"
#include "destiny.h"

#include "demo.h"
#include "rpl_udp.h"

const shell_command_t shell_commands[] = {
{"init", "Initialize network", rpl_udp_init},
{"set", "Set ID", rpl_udp_set_id},
{"table", "Shows the routing table", rpl_udp_table},
{"dodag", "Shows the dodag", rpl_udp_dodag},
{"loop", "", rpl_udp_loop},
{"server", "Starts a UDP server", udp_server},
{"send", "Send a UDP datagram", udp_send},
{"ign", "ignore node", rpl_udp_ignore},
{"ign", "Ignore a node", rpl_udp_ignore},
{NULL, NULL, NULL}
};

Expand Down
98 changes: 10 additions & 88 deletions examples/rpl_udp/rpl.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 INRIA
* Copyright (C) 2013, 2014 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -26,8 +26,8 @@
#include "sixlowpan.h"
#include "destiny.h"
#include "rpl.h"
#include "rpl_dodag.h"
#include "demo.h"
#include "rpl/rpl_dodag.h"
#include "rpl_udp.h"
#include "transceiver.h"

#define ENABLE_DEBUG (0)
Expand All @@ -37,7 +37,6 @@

char monitor_stack_buffer[MONITOR_STACK_SIZE];
radio_address_t id;
ipv6_addr_t std_addr;

uint8_t is_root = 0;

Expand Down Expand Up @@ -104,18 +103,16 @@ void rpl_udp_init(int argc, char **argv)
return;
}

/* TODO: check if this works as intended */
ipv6_addr_t prefix, tmp;
ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id);
ipv6_addr_init_prefix(&prefix, &std_addr, 64);
ndp_add_prefix_info(0, &prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE,
NDP_OPT_PI_PLIFETIME_INFINITE, 1,
ICMPV6_NDP_OPT_PI_FLAG_AUTONOM);
ipv6_init_as_router();
/* add global address */
ipv6_addr_set_by_eui64(&tmp, 0, &std_addr);
ipv6_addr_t tmp;
/* initialize prefix */
ipv6_addr_init(&tmp, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, id);
/* set host suffix */
ipv6_addr_set_by_eui64(&tmp, 0, &tmp);
ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);

ipv6_init_as_router();

/* set channel to 10 */
tcmd.transceivers = TRANSCEIVER;
tcmd.data = &chan;
Expand All @@ -129,81 +126,6 @@ void rpl_udp_init(int argc, char **argv)
/* start transceiver watchdog */
}

void rpl_udp_loop(int argc, char **argv)
{
(void) argc;
(void) argv;

rpl_routing_entry_t *rtable;

rtable = rpl_get_routing_table();
rpl_dodag_t *mydodag = rpl_get_my_dodag();

if (mydodag == NULL) {
return;
}

printf("---------------------------\n");
printf("OUTPUT\n");
printf("my rank: %d\n", mydodag->my_rank);

if (!is_root) {
printf("my preferred parent:\n");
printf("%s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
(&mydodag->my_preferred_parent->addr)));
printf("parent lifetime: %d\n", mydodag->my_preferred_parent->lifetime);
}

printf("---------------------------$\n");

for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if (rtable[i].used) {
printf("%s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
(&rtable[i].address)));
puts("next hop");
printf("%s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
(&rtable[i].next_hop)));
printf("entry %d lifetime %d\n", i, rtable[i].lifetime);

if (!rpl_equal_id(&rtable[i].address, &rtable[i].next_hop)) {
puts("multi-hop");
}

printf("---------------------------$\n");
}
}

printf("########################\n");
}

void rpl_udp_table(int argc, char **argv)
{
(void) argc;
(void) argv;

rpl_routing_entry_t *rtable;
rtable = rpl_get_routing_table();
printf("---------------------------\n");
printf("OUTPUT\n");
printf("---------------------------\n");

for (int i = 0; i < RPL_MAX_ROUTING_ENTRIES; i++) {
if (rtable[i].used) {
printf("%s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN,
(&rtable[i].address)));
printf("entry %d lifetime %d\n", i, rtable[i].lifetime);

if (!rpl_equal_id(&rtable[i].address, &rtable[i].next_hop)) {
puts("multi-hop");
}

printf("--------------\n");
}
}

printf("$\n");
}

void rpl_udp_dodag(int argc, char **argv)
{
(void) argc;
Expand Down
99 changes: 99 additions & 0 deletions examples/rpl_udp/rpl_udp.h
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2014 Oliver Hahm <oliver.hahm@inria.fr>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

#ifndef RPL_UDP_H
#define RPL_UDP_H

#define APP_VERSION "1.2"

#define RADIO_CHANNEL (10)

#define MONITOR_STACK_SIZE (KERNEL_CONF_STACKSIZE_MAIN)
#define RCV_BUFFER_SIZE (32)

/* RPL shell command handlers */
/**
* @brief Shell command to initializes RPL and UDP
*
* @details Usage: init <r|n>
* `init r` will initialize the node as a RPL root node,
* `init n` as a RPL node.
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_init(int argc, char **argv);

/**
* @brief Shell command to set node's ID
*
* @details Usage: set <ID>
* Set the node address
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_set_id(int argc, char **argv);

/**
* @brief Shows the dodag
*
* @details No parameters required
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_dodag(int argc, char **argv);

/**
* @brief Command handler to start a UDP server
*
* @details No parameters required
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void udp_server(int argc, char **argv);

/**
* @brief Sends a UDP datagram
*
* @details Usage: send <ID> <TEXT>
* Sends TEXT to the node with IP address:
* fe80::ff:fe00:<ID>
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void udp_send(int argc, char **argv);

/**
* @brief Ignore a certain node
*
* @details Usage: ignore <ID>
* Ignore the node with IP address:
* fe80::ff:fe00:<ID>
*
* @param[in] argc Argument count
* @param[in] argv Arguments
*/
void rpl_udp_ignore(int argc, char **argv);

/**
* @brief monitoring thread start function
*
* @param arg Unused
*/
void *rpl_udp_monitor(void *arg);

/** @brief The nodes radio address */
extern radio_address_t id;

/** @brief Char array for IP address printing */
extern char addr_str[IPV6_MAX_ADDR_STR_LEN];
#endif /* RPL_UDP_H */
11 changes: 8 additions & 3 deletions examples/rpl_udp/udp.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 INRIA
* Copyright (C) 2013, 2014 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand Down Expand Up @@ -30,7 +30,7 @@

#include "net_help.h"

#include "demo.h"
#include "rpl_udp.h"

#define UDP_BUFFER_SIZE (128)
#define SERVER_PORT (0xFF01)
Expand Down Expand Up @@ -122,7 +122,12 @@ void udp_send(int argc, char **argv)

memset(&sa, 0, sizeof(sa));

ipv6_addr_init(&ipaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00, (uint16_t)address);
if (address) {
ipv6_addr_init(&ipaddr, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x00ff, 0xfe00, (uint16_t)address);
}
else {
ipv6_addr_set_all_nodes_addr(&ipaddr);
}

sa.sin6_family = AF_INET;
memcpy(&sa.sin6_addr, &ipaddr, 16);
Expand Down
10 changes: 5 additions & 5 deletions sys/net/routing/rpl/rpl.h → sys/net/include/rpl.h
@@ -1,9 +1,9 @@
/*
* Copyright (C) 2013 INRIA.
* Copyright (C) 2013, 2014 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
Expand Down Expand Up @@ -33,7 +33,7 @@
#include <mutex.h>
#include <transceiver.h>
#include "ipv6.h"
#include "rpl_dodag.h"
#include "rpl/rpl_dodag.h"

#undef CC1100_RADIO_MODE
#define CC1100_RADIO_MODE CC1100_MODE_WOR
Expand Down

0 comments on commit 28df569

Please sign in to comment.