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

add olsr2 example application #98

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions olsr2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
####
#### Sample Makefile for building apps with the RIOT OS
####
#### The Sample Filesystem Layout is:
#### /this makefile
#### ../../RIOT
#### ../../boards for board definitions (if you have one or more)
####

# name of your project
export PROJECT =olsr_node

# for easy switching of boards
ifeq ($(strip $(BOARD)),)
export BOARD = native
endif

# this has to be the absolute path of the RIOT-base dir
export RIOTBASE = $(CURDIR)/../RIOT

USEPKG += oonf_api

export CFLAGS = -DRIOT -DENABLE_NAME -ggdb

## Modules to include.

USEMODULE += auto_init
USEMODULE += rtc
USEMODULE += uart0
USEMODULE += posix
USEMODULE += ps
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += random
USEMODULE += config
USEMODULE += olsr2
ifeq ($(BOARD),native)
USEMODULE += nativenet
export CFLAGS += -DBOARD_NATIVE -DINIT_ON_START
endif
ifeq ($(BOARD),msba2)
USEMODULE += gpioint
USEMODULE += cc110x_ng
export CFLAGS += -DBOARD_MSBA2 -DINIT_ON_START -DENABLE_LEDS
endif

export INCLUDES += -I$(RIOTBASE)/sys/net/include -I$(RIOTBASE)/sys/posix/include

include $(RIOTBASE)/Makefile.include
131 changes: 131 additions & 0 deletions olsr2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

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

#include <olsr2/olsr2.h>

#define IF_ID (0)

#if defined(BOARD_NATIVE)
#include <unistd.h>
#include <sys/types.h>
static uint16_t get_node_id(void) {
return getpid();
}
#elif defined(BOARD_MSBA2)
#include <config.h>

static uint16_t get_node_id(void) {
return sysconfig.id;
}
#endif

#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], sizeof sysconfig.name);
#endif
config_save();
}

static void init(int argc, char **argv) {
ipv6_addr_t tmp;

rtc_enable();
genrand_init(get_node_id());
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[] = {
#ifndef INIT_ON_START
{"init", "start the IP stack with OLSRv2", init},
#endif
{"routes", "print all known nodes and routes", print_topology_set},
{"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) {
config_load();
#ifdef INIT_ON_START
init(0, 0);
#endif

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;
}