• #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
• pro@slogix.in
• +91- 81240 01111

## Selecting the Preferred Parent in RPL Routing Protocol using Contiki Cooja Simulator

### Contiki Cooja Exercise for Selecting the Preferred Parent in RPL Protocol

Description:

In routing network Objective function(OF) is responsible to select nodes itâ€™s preferred parent. Which is classified as both best parent and worst parent.Rpl follows DODAG techniques, which node is preferred shortest range first in forwarding direction.

###### Step-1

Open a file at location:Home/
contiki/core/net/rpl/rpl-mrhof.c

Here the functions handling
the parent selection.

rpl_parent_t *best_parent

Code:

static rpl_parent_t *best_parent
(rpl_parent_t *p1, rpl_parent_t *p2)

{

rpl_dag_t *dag;

rpl_path_metric_t min_diff;

rpl_path_metric_t p1_metric;

rpl_path_metric_t p2_metric;

dag = p1->dag; /* Both parents
are in the same DAG. */

min_diff=RPL_DAG_MC_ETX_DIVISOR/

PARENT_SWITCH_THRESHOL DIV;

p1_metric =
calculate_path_metric(p1);

p2_metric =
calculate_path_metric(p2);

/* Maintain stability of the preferred
parent in case of similar ranks. */

if(p1 == dag->preferred_parent
|| p2 == dag->preferred_parent) {

if(p1_metric < p2_metric + min_diff )

p1_metric > p2_metric - min_diff) {

printf ("RPL: MRHOF hysteresis:
%u <= %u <= %u\n",)

p2_metric - min_diff,

p1_metric,

p2_metric + min_diff);

return dag->preferred_parent;

}

}

return p1_metric
< p2_metric ? p1 : p2;

}

Minimum rank node selected as
parent node.