Skip to content

Commit 279de8e

Browse files
committed
pkg ccn-lite: added CCN-Lite FIB shell command
1 parent 587a435 commit 279de8e

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

sys/shell/commands/sc_ccnl.c

+66-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2015 INRIA.
2+
* Copyright (C) 2015, 2016 INRIA.
33
*
44
* This file is subject to the terms and conditions of the GNU Lesser
55
* General Public License v2.1. See the file LICENSE in the top level
@@ -23,7 +23,7 @@
2323
#include "ccn-lite-riot.h"
2424
#include "ccnl-pkt-ndntlv.h"
2525

26-
#define MAX_CONTENT (64)
26+
#define BUF_SIZE (64)
2727

2828
/**
2929
* Maximum number of Interest retransmissions
@@ -32,11 +32,10 @@
3232

3333
#define MAX_ADDR_LEN (8U)
3434

35-
#define BUF_SIZE (128)
3635
static unsigned char _int_buf[BUF_SIZE];
3736
static unsigned char _cont_buf[BUF_SIZE];
3837

39-
static char *_default_content = "Start the RIOT!";
38+
static const char *_default_content = "Start the RIOT!";
4039
static unsigned char _out[CCNL_MAX_PACKET_SIZE];
4140

4241
/* check for one-time initialization */
@@ -94,7 +93,7 @@ static void _content_usage(char *argv)
9493

9594
int _ccnl_content(int argc, char **argv)
9695
{
97-
char *body = _default_content;
96+
char *body = (char*) _default_content;
9897
int arg_len = strlen(_default_content) + 1;
9998
int offs = CCNL_MAX_PACKET_SIZE;
10099
if (argc < 2) {
@@ -103,13 +102,13 @@ int _ccnl_content(int argc, char **argv)
103102
}
104103

105104
if (argc > 2) {
106-
char buf[MAX_CONTENT];
107-
memset(buf, ' ', MAX_CONTENT);
105+
char buf[BUF_SIZE];
106+
memset(buf, ' ', BUF_SIZE);
108107
char *buf_ptr = buf;
109-
for (int i = 2; (i < argc) && (buf_ptr < (buf + MAX_CONTENT)); i++) {
108+
for (int i = 2; (i < argc) && (buf_ptr < (buf + BUF_SIZE)); i++) {
110109
arg_len = strlen(argv[i]);
111-
if ((buf_ptr + arg_len) > (buf + MAX_CONTENT)) {
112-
arg_len = (buf + MAX_CONTENT) - buf_ptr;
110+
if ((buf_ptr + arg_len) > (buf + BUF_SIZE)) {
111+
arg_len = (buf + BUF_SIZE) - buf_ptr;
113112
}
114113
strncpy(buf_ptr, argv[i], arg_len);
115114
buf_ptr += arg_len + 1;
@@ -148,8 +147,9 @@ int _ccnl_content(int argc, char **argv)
148147
static void _interest_usage(char *arg)
149148
{
150149
printf("usage: %s <URI> [relay]\n"
151-
"%% %s /riot/peter/schmerzl (classic lookup)\n",
152-
arg, arg);
150+
"%% %s /riot/peter/schmerzl (classic lookup)\n"
151+
"%% %s /riot/peter/schmerzl 01:02:03:04:05:06\n",
152+
arg, arg, arg);
153153
}
154154

155155
int _ccnl_interest(int argc, char **argv)
@@ -180,3 +180,57 @@ int _ccnl_interest(int argc, char **argv)
180180

181181
return -1;
182182
}
183+
184+
static void _ccnl_fib_usage(char *argv)
185+
{
186+
printf("usage: %s [<URI> <content>]\n"
187+
"%% %s (prints the current FIB)\n"
188+
"%% %s /riot/peter/schmerzl RIOT\n",
189+
argv, argv, argv);
190+
}
191+
192+
int _ccnl_fib(int argc, char **argv)
193+
{
194+
if (argc < 2) {
195+
ccnl_show_fib(&ccnl_relay);
196+
}
197+
else if (argc == 3) {
198+
size_t addr_len = MAX_ADDR_LEN;
199+
uint8_t relay_addr[MAX_ADDR_LEN];
200+
int suite = CCNL_SUITE_NDNTLV;
201+
memset(relay_addr, UINT8_MAX, MAX_ADDR_LEN);
202+
addr_len = gnrc_netif_addr_from_str(relay_addr, sizeof(relay_addr), argv[2]);
203+
204+
if (addr_len == 0) {
205+
printf("Error: %s is not a valid link layer address\n", argv[2]);
206+
return -1;
207+
}
208+
209+
struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[1], suite, NULL, 0);
210+
211+
if (!prefix) {
212+
puts("Error: prefix could not be created!");
213+
return -1;
214+
}
215+
216+
sockunion sun;
217+
sun.sa.sa_family = AF_PACKET;
218+
memcpy(&(sun.linklayer.sll_addr), relay_addr, addr_len);
219+
sun.linklayer.sll_halen = addr_len;
220+
sun.linklayer.sll_protocol = htons(ETHERTYPE_NDN);
221+
222+
/* TODO: set correct interface instead of always 0 */
223+
struct ccnl_face_s *fibface = ccnl_get_face_or_create(&ccnl_relay, 0, &sun.sa, sizeof(sun.linklayer));
224+
fibface->flags |= CCNL_FACE_FLAGS_STATIC;
225+
226+
if (ccnl_add_fib_entry(&ccnl_relay, prefix, fibface) != 0) {
227+
printf("Error adding (%s : %s) to the FIB\n", argv[1], argv[2]);
228+
return -1;
229+
}
230+
}
231+
else {
232+
_ccnl_fib_usage(argv[0]);
233+
return -1;
234+
}
235+
return 0;
236+
}

sys/shell/commands/shell_commands.c

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ extern int _gnrc_6ctx(int argc, char **argv);
126126
extern int _ccnl_open(int argc, char **argv);
127127
extern int _ccnl_content(int argc, char **argv);
128128
extern int _ccnl_interest(int argc, char **argv);
129+
extern int _ccnl_fib(int argc, char **argv);
129130
#endif
130131

131132
const shell_command_t _shell_command_list[] = {
@@ -211,6 +212,7 @@ const shell_command_t _shell_command_list[] = {
211212
{ "ccnl_open", "opens an interface or socket", _ccnl_open},
212213
{ "ccnl_int", "sends an interest", _ccnl_interest},
213214
{ "ccnl_cont", "create content and populated it", _ccnl_content},
215+
{ "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib},
214216
#endif
215217
{NULL, NULL, NULL}
216218
};

0 commit comments

Comments
 (0)