Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: add OLSRv2 #2294

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9f8fb47
add olsr2
benpicco Feb 22, 2014
c09baac
add metrics
benpicco Apr 3, 2014
aed2422
add olsr2 example application
benpicco May 12, 2014
7654e2a
add BOARD_WHITELIST to olsr2 example
benpicco Jul 7, 2014
0fc674d
remove unnecessary dependency tests
benpicco Jul 9, 2014
ed21054
fix typo
benpicco Jul 9, 2014
838bb96
clean up example makefile
benpicco Jul 9, 2014
e575c61
explicit module name is not needed anymore
benpicco Jul 9, 2014
cc4d068
comments in constants.h
benpicco Jul 9, 2014
63fd43e
prefix constants
benpicco Jul 9, 2014
dff04dc
don't overwrite DEBUG_H_
benpicco Jul 9, 2014
de76308
get rid of capital letter in simple_list
benpicco Jul 9, 2014
608d211
doxygen for list.h
benpicco Jul 23, 2014
1a58d8a
prefix add_neighbor
benpicco Jul 24, 2014
dca2f95
added more parens
benpicco Jul 24, 2014
f04ca05
add @author
benpicco Jul 24, 2014
84567a1
debug.h -> olsr_debug.h
benpicco Jul 24, 2014
cf2febe
astyle --style=linux
benpicco Jul 24, 2014
35ff52f
define SECOND
benpicco Aug 1, 2014
ff1ccac
astyle --options=../../../../.astylerc *
benpicco Aug 3, 2014
2bfb3e7
move list to sys/
benpicco Aug 3, 2014
a7126f8
add single-linked list implementation
benpicco Aug 3, 2014
0cf92a9
adapt to thread api changes
benpicco Aug 3, 2014
21f176a
fix licence
benpicco Aug 3, 2014
367fa9a
add test for slist
benpicco Aug 25, 2014
e29c6d0
get rid of olsr_debug.h
benpicco Sep 2, 2014
a68b76a
[slist] explicit check for NULL
benpicco Sep 2, 2014
974d739
explicit check for NULL
benpicco Sep 2, 2014
10f1695
style fixes
benpicco Sep 2, 2014
8ec3265
use cpuid_get() when availiable
benpicco Sep 2, 2014
2734d22
slist cleanup part 1
benpicco Sep 2, 2014
9be6e21
slist cleanup pt2
benpicco Sep 3, 2014
6804209
slist cleanup pt3
benpicco Sep 3, 2014
d38272a
adapt to net api change
benpicco Oct 6, 2014
9a61bd4
routing.h -> routing_table.h
benpicco Oct 9, 2014
b8ccb7f
introduce new Makefile options
benpicco Oct 9, 2014
291e9cc
silence warnings
benpicco Oct 10, 2014
822ffa5
fix merge conflict
benpicco Oct 30, 2014
469472f
fix warnings in oonf_api
benpicco Oct 10, 2014
9ae960b
fix warning about printf type
benpicco Oct 10, 2014
251540e
explain IF_ID
benpicco Oct 11, 2014
d2adbf8
make nbuf static
benpicco Oct 11, 2014
66a9974
prefix local_name
benpicco Oct 13, 2014
4cfc515
pkg: copy Kijewski's container_of implementation
Oct 29, 2014
64ca5f9
Add patches to fix the rest of the warnings
Oct 29, 2014
c65cd85
use msg_try_send
benpicco Oct 30, 2014
d99a2c1
set address mode
benpicco Oct 30, 2014
b1987b6
should be +=
benpicco Oct 30, 2014
a8faf5f
SQUASH ME: remove exports from application Makefile
OlegHahm Jan 13, 2015
d779e1f
olsr2: added extern c to headers
OlegHahm Jan 13, 2015
696b96e
SQUASH ME: removed unnecessary dependencies
OlegHahm Jan 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += pnet
endif

ifneq (,$(filter olsr2,$(USEMODULE)))
USEMODULE += udp
USEMODULE += slist
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif

ifneq (,$(filter pnet,$(USEMODULE)))
USEMODULE += posix
USEMODULE += socket_base
Expand Down
8 changes: 6 additions & 2 deletions core/include/kernel_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* @author René Kijewski
*/

#ifndef KERNEL_MACROS_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff of this file could be completely moved to its own PR. seems unrelated to OLSR to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#define KERNEL_MACROS_

#include <stddef.h>

#ifdef __cplusplus
Expand All @@ -35,6 +38,7 @@ extern "C" {
* @param[in] MEMBER name of the member of TYPE which PTR points to
* @return Pointer to the container of PTR.
*/
#ifndef container_of
#if __STDC_VERSION__ >= 201112L
# define container_of(PTR, TYPE, MEMBER) \
(_Generic((PTR), \
Expand All @@ -53,11 +57,11 @@ extern "C" {
# define container_of(PTR, TYPE, MEMBER) \
((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER)))
#endif

#endif
#ifdef __cplusplus
}
#endif

/**
* @}
*/
#endif /* KERNEL_MACROS_ */
38 changes: 38 additions & 0 deletions examples/olsr2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
APPLICATION = olsr_node

BOARD ?= native
RIOTBASE ?= $(CURDIR)/../..

# other toolchains lack assert.h used by oonf_api
BOARD_WHITELIST := avsextrem msba2 native

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

USEPKG += oonf_api

CFLAGS += -DRIOT -DENABLE_NAME

# Modules to include.
USEMODULE += rtc
USEMODULE += uart0
USEMODULE += posix
USEMODULE += ps
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += random
USEMODULE += config
USEMODULE += olsr2
USEMODULE += defaulttransceiver

# on msba2 and avsextrem cpuid_get is not implemented
ifneq (,$(filter $(BOARD), msba2 avsextrem))
export CFLAGS += -DENABLE_LEDS -DHAVE_NO_CPUID
endif

include $(RIOTBASE)/Makefile.include
143 changes: 143 additions & 0 deletions examples/olsr2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* 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.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <thread.h>
#include <vtimer.h>
#include <rtc.h>
#include <random.h>
#include <socket_base/socket.h>
#include <transceiver.h>
#include <sixlowpan/icmp.h>

#include <shell.h>
#include <posix_io.h>
#include <board_uart0.h>

#include <olsr2/olsr2.h>

/* Interface ID */
#define IF_ID (0)

#ifdef HAVE_NO_CPUID
#include <config.h>

static uint32_t get_node_id(void) {
return sysconfig.id;
}

#else /* CPU ID availiable */
#include <periph/cpuid.h>

static uint32_t get_node_id(void) {
uint32_t cpuid = 0;
cpuid_get(&cpuid);
return cpuid;
}

#endif /* get_node_id */

#ifdef ENABLE_NAME

static void ping(int argc, char **argv) {
static uint16_t id = 0;

if (argc < 2) {
puts("usage: ping [node]");
return;
}

id++;
int packets = 10;

ipv6_addr_t* dest = get_ip_by_name(argv[1]);
if (dest == NULL) {
printf("Unknown node: %s\n", argv[1]);
return;
}

char addr_str[IPV6_MAX_ADDR_STR_LEN];
ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, dest);

uint8_t payload[] = "foobar";

for (int i = 0; i < packets; ++i) {
printf("sending %u bytes to %s\n", sizeof payload, addr_str);
icmpv6_send_echo_request(dest, id, i, payload, sizeof payload);
vtimer_usleep(1000000);
}
}
#endif /* ENABLE_NAME */

static void set_id(int argc, char **argv) {
if (argc < 2) {
puts("usage: set_id [id] [name]");
return;
}

uint16_t id = atoi(argv[1]);
sysconfig.id = id;
sysconfig.radio_address = (uint8_t) id;

#ifdef ENABLE_NAME
if (argc > 2)
strncpy(sysconfig.name, argv[2], CONFIG_NAME_LEN);
#endif
config_save();
}

static void print_routes(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
print_topology_set();
}

static void init(void) {
ipv6_addr_t tmp;

rtc_enable();
genrand_init(get_node_id());
net_if_set_src_address_mode(IF_ID, NET_IF_TRANS_ADDR_M_SHORT);
net_if_set_hardware_address(IF_ID, get_node_id());

ipv6_addr_set_link_local_prefix(&tmp);
ipv6_addr_set_by_eui64(&tmp, IF_ID, &tmp);
ipv6_net_if_add_addr(IF_ID, &tmp, NDP_ADDR_STATE_PREFERRED,
NDP_OPT_PI_VLIFETIME_INFINITE,
NDP_OPT_PI_PLIFETIME_INFINITE, 0);

ipv6_addr_set_all_nodes_addr(&tmp);
ipv6_net_if_add_addr(IF_ID, &tmp, NDP_ADDR_STATE_PREFERRED,
NDP_OPT_PI_VLIFETIME_INFINITE,
NDP_OPT_PI_PLIFETIME_INFINITE, 0);

olsr_init();
}

const shell_command_t shell_commands[] = {
{"routes", "print all known nodes and routes", print_routes},
{"set_id", "set node ID and name", set_id},
#ifdef ENABLE_NAME
{"ping", "send packets to a node", ping},
#endif
{NULL, NULL, NULL}
};

int main(void) {
init();

posix_open(uart0_handler_pid, 0);

shell_t shell;
shell_init(&shell, shell_commands, UART0_BUFSIZE, uart0_readc, uart0_putc);

shell_run(&shell);

return 0;
}
29 changes: 29 additions & 0 deletions pkg/oonf_api/0005-only-define-container_of-when-necessary.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From d81d24b9d4c897c508799cb390b13cb018758709 Mon Sep 17 00:00:00 2001
From: Benjamin Valentin <[email protected]>
Date: Fri, 10 Oct 2014 02:05:01 +0200
Subject: [PATCH] only define container_of when necessary

---
src-api/common/container_of.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src-api/common/container_of.h b/src-api/common/container_of.h
index 9fd1893..fcb38fe 100644
--- a/src-api/common/container_of.h
+++ b/src-api/common/container_of.h
@@ -58,10 +58,12 @@
* @param member name of node inside struct
* @return pointer to surrounding struct
*/
+#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof(((type *)0)->member ) *__tempptr = (ptr); \
(type *)((char *)__tempptr - offsetof(type,member)); \
})
+#endif

/**
* Helper function for NULL safe container_of macro
--
1.9.1

25 changes: 25 additions & 0 deletions pkg/oonf_api/0006-if_index-is-not-used.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 40651f114bd6e1b4b2ebc89bdf8fb06d1243eb55 Mon Sep 17 00:00:00 2001
From: Benjamin Valentin <[email protected]>
Date: Fri, 10 Oct 2014 02:08:32 +0200
Subject: [PATCH] if_index is not used

---
src-api/common/netaddr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src-api/common/netaddr.c b/src-api/common/netaddr.c
index ed44341..fa528ca 100644
--- a/src-api/common/netaddr.c
+++ b/src-api/common/netaddr.c
@@ -319,7 +319,7 @@ netaddr_create_host_bin(struct netaddr *host, const struct netaddr *netmask,
*/
int
netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
- uint16_t port, unsigned if_index) {
+ uint16_t port, unsigned if_index __attribute__((unused))) {
/* initialize memory block */
memset(combined, 0, sizeof(*combined));

--
1.9.1

45 changes: 45 additions & 0 deletions pkg/oonf_api/0007-Use-RIOT-s-container_of-implementation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From b2ad2073ac282f1bc6315e47ffbd12c3f6a9ae1a Mon Sep 17 00:00:00 2001
From: Hinnerk van Bruinehsen <[email protected]>
Date: Wed, 29 Oct 2014 11:37:05 +0100
Subject: [PATCH] Use RIOT's container_of implementation

---
src-api/common/container_of.h | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src-api/common/container_of.h b/src-api/common/container_of.h
index fcb38fe..b49d836 100644
--- a/src-api/common/container_of.h
+++ b/src-api/common/container_of.h
@@ -59,10 +59,24 @@
* @return pointer to surrounding struct
*/
#ifndef container_of
-#define container_of(ptr, type, member) ({ \
- const typeof(((type *)0)->member ) *__tempptr = (ptr); \
- (type *)((char *)__tempptr - offsetof(type,member)); \
- })
+#if __STDC_VERSION__ >= 201112L
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question: why is this the same as in core/include/kernel_macros.h. Is it possible to reduce the redundance anywhere?

+# define container_of(PTR, TYPE, MEMBER) \
+ (_Generic((PTR), \
+ const __typeof__ (((TYPE *) 0)->MEMBER) *: \
+ ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))), \
+ __typeof__ (((TYPE *) 0)->MEMBER) *: \
+ ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) \
+ ))
+#elif defined __GNUC__
+# define container_of(PTR, TYPE, MEMBER) \
+ (__extension__ ({ \
+ __extension__ const __typeof__ (((TYPE *) 0)->MEMBER) *__m____ = (PTR); \
+ ((TYPE *) ((char *) __m____ - offsetof(TYPE, MEMBER))); \
+ }))
+#else
+# define container_of(PTR, TYPE, MEMBER) \
+ ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER)))
+#endif
#endif

/**
--
2.1.2

54 changes: 54 additions & 0 deletions pkg/oonf_api/0008-Dissolve-enum-into-single-defines.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From e590e6f26b115da34a943fd4ed6d4c93fd2c64d0 Mon Sep 17 00:00:00 2001
From: Hinnerk van Bruinehsen <[email protected]>
Date: Wed, 29 Oct 2014 12:05:11 +0100
Subject: [PATCH] Dissolve enum into single defines

---
src-api/rfc5444/rfc5444.h | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src-api/rfc5444/rfc5444.h b/src-api/rfc5444/rfc5444.h
index c5d6420..6b5576e 100644
--- a/src-api/rfc5444/rfc5444.h
+++ b/src-api/rfc5444/rfc5444.h
@@ -43,25 +43,23 @@

#include "common/common_types.h"

-enum {
- /* timetlv_max = 14 * 2^28 * 1000 / 1024 = 14000 << 18 = 3 670 016 000 ms */
- RFC5444_TIMETLV_MAX = 0xdac00000,
+/* timetlv_max = 14 * 2^28 * 1000 / 1024 = 14000 << 18 = 3 670 016 000 ms */
+#define RFC5444_TIMETLV_MAX 0xdac00000

- /* timetlv_min = 1000/1024 ms */
- RFC5444_TIMETLV_MIN = 0x00000001,
+/* timetlv_min = 1000/1024 ms */
+#define RFC5444_TIMETLV_MIN 0x00000001

- /* metric_max = 1<<24 - 256 */
- RFC5444_METRIC_MAX = 0xffff00,
+/* metric_max = 1<<24 - 256 */
+#define RFC5444_METRIC_MAX 0xffff00

- /* metric_min = 1 */
- RFC5444_METRIC_MIN = 0x000001,
+/* metric_min = 1 */
+#define RFC5444_METRIC_MIN 0x000001

- /* larger than possible metric value */
- RFC5444_METRIC_INFINITE = 0xffffff,
+/* larger than possible metric value */
+#define RFC5444_METRIC_INFINITE 0xffffff

- /* infinite path cost */
- RFC5444_METRIC_INFINITE_PATH = 0xffffffff,
-};
+/* infinite path cost */
+#define RFC5444_METRIC_INFINITE_PATH 0xffffffff

EXPORT uint8_t rfc5444_timetlv_get_from_vector(
uint8_t *vector, size_t vector_length, uint8_t hopcount);
--
2.1.2

Loading