1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #5148 from OlegHahm/ccnl_update

pkg ccn-lite: update version
This commit is contained in:
Oleg Hahm 2016-03-24 18:55:41 +01:00
commit 66c011d45d
7 changed files with 238 additions and 53 deletions

View File

@ -6,6 +6,11 @@ ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += gnrc_conn_udp
endif
ifneq (,$(filter ccn-lite,$(USEPKG)))
export CFLAGS += -DCCNL_RIOT
endif
ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += conn_udp
USEMODULE += xtimer

View File

@ -11,12 +11,10 @@ RIOTBASE ?= $(CURDIR)/../..
CFLAGS += -DDEVELHELP
CFLAGS += -DUSE_LINKLAYER
CFLAGS += -DUSE_IPV6
CFLAGS += -DCCNL_UAPI_H_
CFLAGS += -DUSE_SUITE_NDNTLV
CFLAGS += -DNEEDS_PREFIX_MATCHING
CFLAGS += -DNEEDS_PACKET_CRAFTING
CFLAGS += -DUSE_HMAC256
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

View File

@ -16,19 +16,31 @@ RIOT provides three shell to interact with the CCN-Lite stack:
incorrect ID, you should get an error message.) You have to
call this command, before you can actually send or receive
anything.
* `ccnl_int` - generates and sends out an Interest. The command expects one
mandatory and one optional parameter. The first parameter
specifies the exact name (or a prefix) to request, the second
parameter specifies the link-layer address of the relay to use.
If the second parameter is omitted, the Interest will be
broadcasted. You may call it like this:
`ccnl_int /riot/peter/schmerzl b6:e5:94:26:ab:da`
* `ccnl_cont` - generates and populates Content. The command expects one
mandatory and one optional parameter. The first parameter
specifies the name of the content to be created, the second
parameter specifies the content itself. The second parameter may
include spaces, e.g. you can call:
`ccnl_cont /riot/peter/schmerzl Hello World! Hello RIOT!`
* `ccnl_int` - generates and sends out an Interest. The command expects one
mandatory and one optional parameter. The first parameter
specifies the exact name (or a prefix) to request, the second
parameter specifies the link-layer address of the relay to use.
If the second parameter is omitted, the Interest will be
broadcasted. You may call it like this:
`ccnl_int /riot/peter/schmerzl b6:e5:94:26:ab:da`
* `ccnl_cont` - generates and populates content. The command expects one
mandatory and one optional parameter. The first parameter
specifies the name of the content to be created, the second
parameter specifies the content itself. The second parameter
may include spaces, e.g. you can call:
`ccnl_cont /riot/peter/schmerzl Hello World! Hello RIOT!`
* `ccnl_fib` - modifies the FIB or shows its current state. If the command is
called without parameters, it will print the current state of
the FIB. It can also be called with the action parameters `add`
or `del` to add or delete an entry from the FIB, e.g.
`ccnl_fib add /riot/peter/schmerzl ab:cd:ef:01:23:45:67:89`
will add an entry for `/riot/peter/schmerzl` with
`ab:cd:ef:01:23:45:67:89` as a next hop and
`ccnl_fib del /riot/peter/schmerzl`
will remove the entry for `/riot/peter/schmerzl` and
`ccnl_fib del ab:cd:ef:01:23:45:67:89`
will remove all entries with `ab:cd:ef:01:23:45:67:89` as a
next hop.
## Example setup
@ -39,11 +51,32 @@ An example usage of this application could be setup like this:
windows.
3. Call `make -B clean all term` in the first terminal and `PORT=tap1 make
term` in the second one.
4. Enter `open 3` in both terminals.
4. Enter `ccnl_open 3` in both terminals.
5. Enter `ccnl_cont /riot/peter/schmerzl Hello World! Hello RIOT!` on the first
terminal.
6. Enter `ccnl_int /riot/peter/schmerzl` in the second terminal.
7. See the content being displayed. Be happy!
6. Add a FIB entry for this prefix on the second node, e.g. using the broadcast
address: `ccnl_fib add /riot/peter/schmerzl ff:ff:ff:ff:ff:ff`
7. Enter `ccnl_int /riot/peter/schmerzl` in the second terminal.
8. See the content being displayed. Be happy!
## Makefile configuration
The ccn-lite package provides several configuration options through defines
that can be set in the application Makefile. The following options are
mandatory for now:
* `CFLAGS += -DUSE_LINKLAYER` - use CCN directly over the link layer
* `CFLAGS += -DCCNL_UAPI_H_` - tell ccn-lite to use the UAPI
* `CFLAGS += -DUSE_SUITE_NDNTLV` - use NDNTLV packet format
* `CFLAGS += -DNEEDS_PREFIX_MATCHING` - enables prefix matching
* `CFLAGS += -DNEEDS_PACKET_CRAFTING` - enable userspace packet creation
Here's a list of some additional interesting options:
* `CFLAGS += -DUSE_RONR` - enable Reactive Optimistic Name-based
Routing (RONR)
* `CFLAGS += -DUSE_STATS` - enable statistics
* `CFLAGS += -DUSE_DUP_CHECK` - enable duplicate checks when forwarding
* `CFLAGS += -DUSE_HMAC256` - HMAC256 signed packets for CCNx1.0
encoding
## Wireshark dissector

View File

@ -1,6 +1,6 @@
PKG_NAME=ccn-lite
PKG_URL=https://github.com/OlegHahm/ccn-lite/
PKG_VERSION=39b1406c11de9de364220909488eebabe7e81613
PKG_URL=https://github.com/cn-uofbasel/ccn-lite/
PKG_VERSION=9e48d328e162e97f091d913ada0bf50f58d1d3d7
.PHONY: all

View File

@ -19,11 +19,6 @@
* @{
*/
/**
* Use RIOT specific configuration in CCN-Lite
*/
#define CCNL_RIOT
#include <unistd.h>
#include "kernel_types.h"
#include "arpa/inet.h"
@ -105,6 +100,22 @@ extern "C" {
* @}
*/
/**
* @brief Some macro definitions
* @{
*/
#define free_2ptr_list(a,b) ccnl_free(a), ccnl_free(b)
#define free_3ptr_list(a,b,c) ccnl_free(a), ccnl_free(b), ccnl_free(c)
#define free_4ptr_list(a,b,c,d) ccnl_free(a), ccnl_free(b), ccnl_free(c), ccnl_free(d);
#define free_5ptr_list(a,b,c,d,e) ccnl_free(a), ccnl_free(b), ccnl_free(c), ccnl_free(d), ccnl_free(e);
/**
* Frees all memory directly and indirectly allocated for prefix information
*/
#define free_prefix(p) do{ if(p) \
free_5ptr_list(p->bytes,p->comp,p->complen,p->chunknum,p); } while(0)
/**
* Constant string
*/
@ -123,7 +134,7 @@ extern "C" {
/**
* Struct holding CCN-Lite's central relay information
*/
extern struct ccnl_relay_s theRelay;
extern struct ccnl_relay_s ccnl_relay;
/**
* @brief Start the main CCN-Lite event-loop
@ -149,8 +160,6 @@ int ccnl_open_netif(kernel_pid_t if_pid, gnrc_nettype_t netreg_type);
*
* @param[in] suite CCN packet format
* @param[in] name The name that is requested
* @param[in] addr The relay's address to send to
* @param[in] addr_len Length of @p addr
* @param[in] chunknum Number of the requested content chunk
* @param[out] buf Buffer to write the content chunk to
* @param[in] buf_len Size of @p buf
@ -158,17 +167,46 @@ int ccnl_open_netif(kernel_pid_t if_pid, gnrc_nettype_t netreg_type);
* @return 0 on successfully sent Interest
* @return -1 if Interested couldn't be sent
*/
int ccnl_send_interest(int suite, char *name, uint8_t *addr, size_t addr_len,
unsigned int *chunknum, unsigned char *buf,
size_t buf_len);
int ccnl_send_interest(int suite, char *name, unsigned int *chunknum,
unsigned char *buf, size_t buf_len);
/**
* @brief Waits for incoming content chunk
* @brief Wait for incoming content chunk
*
* @pre The thread has to register for CCNL_CONT_CHUNK in @ref netreg first
*
* @post The thread should unregister from @ref netreg after this function returns
*
* @param[out] buf Buffer to stores the received content
* @param[in] buf_len Size of @p buf
* @param[in] timeout Maximum to wait for the chunk, set to a default value if 0
*
* @return 0 if a content was received
* @return -ETIMEDOUT if no chunk was received until timeout
*/
int ccnl_wait_for_chunk(void *buf, size_t buf_len);
int ccnl_wait_for_chunk(void *buf, size_t buf_len, uint64_t timeout);
/**
* @brief Add entry to the CCN-Lite FIB
*
* @par[in] relay Local relay struct
* @par[in] pfx Prefix of the FIB entry
* @par[in] face Face for the FIB entry
*
* @return 0 on success
* @return -1 on error
*/
int ccnl_fib_add_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx,
struct ccnl_face_s *face);
int ccnl_fib_rem_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx, struct ccnl_face_s *face);
/**
* @brief Prints the current CCN-Lite FIB
*
* @par[in] relay Local relay struct
*/
void ccnl_fib_show(struct ccnl_relay_s *relay);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 INRIA.
* Copyright (C) 2015, 2016 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
@ -19,11 +19,12 @@
*/
#include "random.h"
#include "sched.h"
#include "net/gnrc/netif.h"
#include "ccn-lite-riot.h"
#include "ccnl-pkt-ndntlv.h"
#define MAX_CONTENT (64)
#define BUF_SIZE (64)
/**
* Maximum number of Interest retransmissions
@ -32,11 +33,10 @@
#define MAX_ADDR_LEN (8U)
#define BUF_SIZE (128)
static unsigned char _int_buf[BUF_SIZE];
static unsigned char _cont_buf[BUF_SIZE];
static char *_default_content = "Start the RIOT!";
static const char *_default_content = "Start the RIOT!";
static unsigned char _out[CCNL_MAX_PACKET_SIZE];
/* check for one-time initialization */
@ -94,7 +94,7 @@ static void _content_usage(char *argv)
int _ccnl_content(int argc, char **argv)
{
char *body = _default_content;
char *body = (char*) _default_content;
int arg_len = strlen(_default_content) + 1;
int offs = CCNL_MAX_PACKET_SIZE;
if (argc < 2) {
@ -103,13 +103,13 @@ int _ccnl_content(int argc, char **argv)
}
if (argc > 2) {
char buf[MAX_CONTENT];
memset(buf, ' ', MAX_CONTENT);
char buf[BUF_SIZE];
memset(buf, ' ', BUF_SIZE);
char *buf_ptr = buf;
for (int i = 2; (i < argc) && (buf_ptr < (buf + MAX_CONTENT)); i++) {
for (int i = 2; (i < argc) && (buf_ptr < (buf + BUF_SIZE)); i++) {
arg_len = strlen(argv[i]);
if ((buf_ptr + arg_len) > (buf + MAX_CONTENT)) {
arg_len = (buf + MAX_CONTENT) - buf_ptr;
if ((buf_ptr + arg_len) > (buf + BUF_SIZE)) {
arg_len = (buf + BUF_SIZE) - buf_ptr;
}
strncpy(buf_ptr, argv[i], arg_len);
buf_ptr += arg_len + 1;
@ -138,17 +138,65 @@ int _ccnl_content(int argc, char **argv)
struct ccnl_content_s *c = 0;
struct ccnl_pkt_s *pk = ccnl_ndntlv_bytes2pkt(typ, olddata, &data, &arg_len);
c = ccnl_content_new(&theRelay, &pk);
ccnl_content_add2cache(&theRelay, c);
c = ccnl_content_new(&ccnl_relay, &pk);
ccnl_content_add2cache(&ccnl_relay, c);
c->flags |= CCNL_CONTENT_FLAGS_STATIC;
return 0;
}
static struct ccnl_face_s *_intern_face_get(char *addr_str)
{
/* initialize address with 0xFF for broadcast */
size_t addr_len = MAX_ADDR_LEN;
uint8_t relay_addr[MAX_ADDR_LEN];
memset(relay_addr, UINT8_MAX, MAX_ADDR_LEN);
addr_len = gnrc_netif_addr_from_str(relay_addr, sizeof(relay_addr), addr_str);
if (addr_len == 0) {
printf("Error: %s is not a valid link layer address\n", addr_str);
return NULL;
}
sockunion sun;
sun.sa.sa_family = AF_PACKET;
memcpy(&(sun.linklayer.sll_addr), relay_addr, addr_len);
sun.linklayer.sll_halen = addr_len;
sun.linklayer.sll_protocol = htons(ETHERTYPE_NDN);
/* TODO: set correct interface instead of always 0 */
struct ccnl_face_s *fibface = ccnl_get_face_or_create(&ccnl_relay, 0, &sun.sa, sizeof(sun.linklayer));
return fibface;
}
static int _intern_fib_add(char *pfx, char *addr_str)
{
int suite = CCNL_SUITE_NDNTLV;
struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(pfx, suite, NULL, 0);
if (!prefix) {
puts("Error: prefix could not be created!");
return -1;
}
struct ccnl_face_s *fibface = _intern_face_get(addr_str);
if (fibface == NULL) {
return -1;
}
fibface->flags |= CCNL_FACE_FLAGS_STATIC;
if (ccnl_fib_add_entry(&ccnl_relay, prefix, fibface) != 0) {
printf("Error adding (%s : %s) to the FIB\n", pfx, addr_str);
return -1;
}
return 0;
}
static void _interest_usage(char *arg)
{
printf("usage: %s <URI> [relay]\n"
"%% %s /riot/peter/schmerzl (classic lookup)\n",
"%% %s /riot/peter/schmerzl (classic lookup)\n",
arg, arg);
}
@ -159,24 +207,85 @@ int _ccnl_interest(int argc, char **argv)
return -1;
}
/* initialize address with 0xFF for broadcast */
size_t addr_len = MAX_ADDR_LEN;
uint8_t relay_addr[MAX_ADDR_LEN];
memset(relay_addr, UINT8_MAX, MAX_ADDR_LEN);
if (argc > 2) {
addr_len = gnrc_netif_addr_from_str(relay_addr, sizeof(relay_addr), argv[2]);
if (_intern_fib_add(argv[1], argv[2]) < 0) {
_interest_usage(argv[0]);
return -1;
}
}
memset(_int_buf, '\0', BUF_SIZE);
memset(_cont_buf, '\0', BUF_SIZE);
for (int cnt = 0; cnt < CCNL_INTEREST_RETRIES; cnt++) {
ccnl_send_interest(CCNL_SUITE_NDNTLV, argv[1], relay_addr, addr_len, NULL, _int_buf, BUF_SIZE);
if (ccnl_wait_for_chunk(_cont_buf, BUF_SIZE) > 0) {
gnrc_netreg_entry_t _ne;
/* register for content chunks */
_ne.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL;
_ne.pid = sched_active_pid;
gnrc_netreg_register(GNRC_NETTYPE_CCN_CHUNK, &_ne);
ccnl_send_interest(CCNL_SUITE_NDNTLV, argv[1], NULL, _int_buf, BUF_SIZE);
if (ccnl_wait_for_chunk(_cont_buf, BUF_SIZE, 0) > 0) {
gnrc_netreg_unregister(GNRC_NETTYPE_CCN_CHUNK, &_ne);
printf("Content received: %s\n", _cont_buf);
return 0;
}
gnrc_netreg_unregister(GNRC_NETTYPE_CCN_CHUNK, &_ne);
}
printf("Timeout! No content received in response to the Interest for %s.\n", argv[1]);
return -1;
}
static void _ccnl_fib_usage(char *argv)
{
printf("usage: %s [<action> <options>]\n"
"prints the FIB if called without parameters:\n"
"%% %s\n"
"<action> may be one of the following\n"
" * \"add\" - adds an entry to the FIB, requires a prefix and a next-hop address, e.g.\n"
" %s add /riot/peter/schmerzl ab:cd:ef:01:23:45:67:89\n"
" * \"del\" - deletes an entry to the FIB, requires a prefix or a next-hop address, e.g.\n"
" %s del /riot/peter/schmerzl\n"
" %s del ab:cd:ef:01:23:45:67:89\n",
argv, argv, argv, argv, argv);
}
int _ccnl_fib(int argc, char **argv)
{
if (argc < 2) {
ccnl_fib_show(&ccnl_relay);
}
else if ((argc == 3) && (strncmp(argv[1], "del", 3) == 0)) {
int suite = CCNL_SUITE_NDNTLV;
if (strchr(argv[2], '/')) {
struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[2], suite, NULL, 0);
if (!prefix) {
puts("Error: prefix could not be created!");
return -1;
}
int res = ccnl_fib_rem_entry(&ccnl_relay, prefix, NULL);
free_prefix(prefix);
return res;
}
else {
struct ccnl_face_s *face = _intern_face_get(argv[2]);
if (face == NULL) {
printf("There is no face for address %s\n", argv[1]);
return -1;
}
int res = ccnl_fib_rem_entry(&ccnl_relay, NULL, face);
return res;
}
}
else if ((argc == 4) && (strncmp(argv[1], "add", 3) == 0)) {
if (_intern_fib_add(argv[2], argv[3]) < 0) {
_ccnl_fib_usage(argv[0]);
return -1;
}
}
else {
_ccnl_fib_usage(argv[0]);
return -1;
}
return 0;
}

View File

@ -126,6 +126,7 @@ extern int _gnrc_6ctx(int argc, char **argv);
extern int _ccnl_open(int argc, char **argv);
extern int _ccnl_content(int argc, char **argv);
extern int _ccnl_interest(int argc, char **argv);
extern int _ccnl_fib(int argc, char **argv);
#endif
const shell_command_t _shell_command_list[] = {
@ -211,6 +212,7 @@ const shell_command_t _shell_command_list[] = {
{ "ccnl_open", "opens an interface or socket", _ccnl_open},
{ "ccnl_int", "sends an interest", _ccnl_interest},
{ "ccnl_cont", "create content and populated it", _ccnl_content},
{ "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib},
#endif
{NULL, NULL, NULL}
};