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

[RFC] add olsr2 routing algorithm #765

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b20fad3
add olsr2
benpicco Feb 22, 2014
59b25c7
add metrics
benpicco Apr 3, 2014
c5e39cf
add olsr2 example application
benpicco May 12, 2014
6db5324
add BOARD_WHITELIST to olsr2 example
benpicco Jul 7, 2014
72f4ba5
remove unnecessary dependency tests
benpicco Jul 9, 2014
83cb9f5
fix typo
benpicco Jul 9, 2014
03114da
clean up example makefile
benpicco Jul 9, 2014
f6336cb
explicit module name is not needed anymore
benpicco Jul 9, 2014
4094738
comments in constants.h
benpicco Jul 9, 2014
e75d7f9
prefix constants
benpicco Jul 9, 2014
fef2f23
don't overwrite DEBUG_H_
benpicco Jul 9, 2014
e00fcb3
get rid of capital letter in simple_list
benpicco Jul 9, 2014
800ca64
doxygen for list.h
benpicco Jul 23, 2014
0ccc9e1
prefix add_neighbor
benpicco Jul 24, 2014
84014e5
added more parens
benpicco Jul 24, 2014
9a5f005
add @author
benpicco Jul 24, 2014
f989a82
debug.h -> olsr_debug.h
benpicco Jul 24, 2014
621a1f4
astyle --style=linux
benpicco Jul 24, 2014
8d59a5f
define SECOND
benpicco Aug 1, 2014
7d2fe2f
astyle --options=../../../../.astylerc *
benpicco Aug 3, 2014
3654a1d
move list to sys/
benpicco Aug 3, 2014
9635f8d
add single-linked list implementation
benpicco Aug 3, 2014
50cd845
adapt to thread api changes
benpicco Aug 3, 2014
598aa63
fix licence
benpicco Aug 3, 2014
bdad777
add test for slist
benpicco Aug 25, 2014
44e2cd3
get rid of olsr_debug.h
benpicco Sep 2, 2014
eb29e39
[slist] explicit check for NULL
benpicco Sep 2, 2014
4196a4d
explicit check for NULL
benpicco Sep 2, 2014
b2f6c02
style fixes
benpicco Sep 2, 2014
97eaa4a
use cpuid_get() when availiable
benpicco Sep 2, 2014
dc53b2f
slist cleanup part 1
benpicco Sep 2, 2014
d482de8
slist cleanup pt2
benpicco Sep 3, 2014
9a04ead
slist cleanup pt3
benpicco Sep 3, 2014
c9b2f5a
adapt to net api change
benpicco Oct 6, 2014
ad03d12
routing.h -> routing_table.h
benpicco Oct 9, 2014
ad42160
introduce new Makefile options
benpicco Oct 9, 2014
cc25083
silence warnings
benpicco Oct 10, 2014
ca235e4
fix merge conflict
benpicco Oct 30, 2014
605f3b9
fix warnings in oonf_api
benpicco Oct 10, 2014
68cc358
fix warning about printf type
benpicco Oct 10, 2014
a8e2b50
explain IF_ID
benpicco Oct 11, 2014
1efb0f5
make nbuf static
benpicco Oct 11, 2014
173bd7d
prefix local_name
benpicco Oct 13, 2014
82ef757
pkg: copy Kijewski's container_of implementation
Oct 29, 2014
98cfc03
Add patches to fix the rest of the warnings
Oct 29, 2014
d6c6214
use msg_try_send
benpicco Oct 30, 2014
d44adc9
set address mode
benpicco Oct 30, 2014
15b66ba
should be +=
benpicco Oct 30, 2014
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
10 changes: 10 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += pnet
endif

ifneq (,$(filter olsr2,$(USEMODULE)))
USEMODULE += vtimer
USEMODULE += socket_base
USEMODULE += udp
USEMODULE += sixlowpan
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_
#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 @@
export APPLICATION = olsr_node

export BOARD ?= native
export 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

export 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this flag do?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this describes the InterFace ID

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, makes sense. The parser in my had saw the token IF and interpreted the line as if there is an ID? It's 0, hence there is none. ;-)

Maybe better be verbose? #define INTERFACE_ID?


#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);
Copy link
Member

Choose a reason for hiding this comment

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

Something like #define SECOND (1000 * 1000) would increase readibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}
}
#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 <benpicco@zedat.fu-berlin.de>
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 <benpicco@zedat.fu-berlin.de>
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 <h.v.bruinehsen@fu-berlin.de>
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
+# 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 <h.v.bruinehsen@fu-berlin.de>
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