Skip to content

Commit

Permalink
sc_gnrc_rpl.c: cmd for operation as leaf or router
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundogan committed Oct 5, 2015
1 parent a689867 commit 70c3be6
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions sys/shell/commands/sc_gnrc_rpl.c
Expand Up @@ -296,10 +296,11 @@ int _gnrc_rpl_dodag_show(void)
cleanup = dodag->cleanup_timer.target - xtimer_now();
cleanup = (int32_t) cleanup < 0 ? 0 : cleanup / SEC_IN_USEC;

printf("\tdodag [%s | R: %d | CL: %" PRIu32 "s | "
printf("\tdodag [%s | R: %d | OP: %s | CL: %" PRIu32 "s | "
"TR(I=[%d,%d], k=%d, c=%d, TC=%" PRIu64 "s, TI=%" PRIu64 "s)]\n",
ipv6_addr_to_str(addr_str, &dodag->dodag_id, sizeof(addr_str)),
dodag->my_rank, (((int32_t) cleanup < 0) ? 0 : cleanup/SEC_IN_USEC),
dodag->my_rank, (dodag->node_status == GNRC_RPL_LEAF_NODE ? "Leaf" : "Router"),
(((int32_t) cleanup < 0) ? 0 : cleanup/SEC_IN_USEC),
(1 << dodag->dio_min), dodag->dio_interval_doubl,
dodag->trickle.k, dodag->trickle.c, tc, ti);
gnrc_rpl_parent_t *parent;
Expand All @@ -314,6 +315,48 @@ int _gnrc_rpl_dodag_show(void)
return 0;
}

int _gnrc_rpl_operation(bool leaf, char *arg1, char *arg2)
{
uint8_t instance_id = 0;
ipv6_addr_t dodag_id;
gnrc_rpl_instance_t *inst;
gnrc_rpl_dodag_t *dodag = NULL;
char addr_str[IPV6_ADDR_MAX_STR_LEN];

instance_id = (uint8_t) atoi(arg1);
if (instance_id == 0) {
puts("error: <instance_id> must be a positive number greater than zero");
return 1;
}

if (ipv6_addr_from_str(&dodag_id, arg2) == NULL) {
puts("error: <dodag_id> must be a valid IPv6 address");
return 1;
}

if ((inst = gnrc_rpl_instance_get(instance_id)) == NULL) {
puts("error: could not find the <instance_id>");
return 1;
}

if ((dodag = gnrc_rpl_dodag_get(inst, &dodag_id)) == NULL) {
puts("error: <dodag_id> does not exist for the given <instance_id>");
return 1;
}

if (leaf) {
gnrc_rpl_leaf_operation(dodag);
}
else {
gnrc_rpl_router_operation(dodag);
}

printf("success: operate in DODAG (%s) from instance (%d) as %s\n",
ipv6_addr_to_str(addr_str, &dodag_id, sizeof(addr_str)),
instance_id, leaf ? "leaf" : "router");
return 0;
}

int _gnrc_rpl(int argc, char **argv)
{
if ((argc < 2) || (strcmp(argv[1], "show") == 0)) {
Expand Down Expand Up @@ -349,16 +392,28 @@ int _gnrc_rpl(int argc, char **argv)
return _gnrc_rpl_send_dis();
}
}
else if (strcmp(argv[1], "leaf") == 0) {
if (argc == 4) {
return _gnrc_rpl_operation(true, argv[2], argv[3]);
}
}
else if (strcmp(argv[1], "router") == 0) {
if (argc == 4) {
return _gnrc_rpl_operation(false, argv[2], argv[3]);
}
}

printf("usage: %s [help|init|rm|root|show]\n", argv[0]);
puts("* help\t\t\t\t\t\t- show usage");
puts("* init <if_id>\t\t\t\t\t- initialize RPL on the given interface");
puts("* leaf <instance_id> <dodag_id>\t\t\t- operate as leaf in the dodag");
puts("* trickle reset <instance_id> <dodag_id>\t- reset the trickle timer");
puts("* trickle start <instance_id> <dodag_id>\t- start the trickle timer");
puts("* trickle stop <instance_id> <dodag_id>\t\t- stop the trickle timer");
puts("* rm <instance_id>\t\t\t\t- delete the given instance and all related dodags");
puts("* rm <instance_id> <dodag_id>\t\t\t- delete the dodag in the given instance");
puts("* root <instance_id> <dodag_id>\t\t\t- add a dodag to a new or existing instance");
puts("* router <instance_id> <dodag_id>\t\t\t- operate as router in the dodag");
puts("* send dis\t\t\t\t\t- send a multicast DIS");
puts("* show\t\t\t\t\t\t- show instance and dodag tables");
return 0;
Expand Down

0 comments on commit 70c3be6

Please sign in to comment.