1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ccn-lite: add shell function to remove FIB entry

This commit is contained in:
Oleg Hahm 2016-02-03 16:46:28 +01:00
parent 08a15b3920
commit 5db537fbab
2 changed files with 55 additions and 15 deletions

View File

@ -204,6 +204,8 @@ int ccnl_wait_for_chunk(void *buf, size_t buf_len, uint64_t timeout);
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
*

View File

@ -145,15 +145,8 @@ int _ccnl_content(int argc, char **argv)
return 0;
}
static int _intern_fib_add(char *pfx, char *addr_str)
static struct ccnl_face_s *_intern_face_get(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;
}
/* initialize address with 0xFF for broadcast */
size_t addr_len = MAX_ADDR_LEN;
uint8_t relay_addr[MAX_ADDR_LEN];
@ -162,7 +155,7 @@ static int _intern_fib_add(char *pfx, char *addr_str)
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 -1;
return NULL;
}
sockunion sun;
@ -173,6 +166,23 @@ static int _intern_fib_add(char *pfx, char *addr_str)
/* 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) {
@ -228,10 +238,16 @@ int _ccnl_interest(int argc, char **argv)
static void _ccnl_fib_usage(char *argv)
{
printf("usage: %s [<URI> <content>]\n"
"%% %s (prints the current FIB)\n"
"%% %s /riot/peter/schmerzl RIOT\n",
argv, argv, 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)
@ -239,8 +255,30 @@ int _ccnl_fib(int argc, char **argv)
if (argc < 2) {
ccnl_fib_show(&ccnl_relay);
}
else if (argc == 3) {
if (_intern_fib_add(argv[1], argv[2]) < 0) {
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;
}