rpl-of0.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "net/rpl/rpl-private.h"
00043
00044 #define DEBUG DEBUG_NONE
00045 #include "net/uip-debug.h"
00046
00047 #include "net/neighbor-info.h"
00048
00049 static void reset(rpl_dag_t *);
00050 static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
00051 static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
00052 static void update_metric_container(rpl_dag_t *);
00053
00054 rpl_of_t rpl_of0 = {
00055 reset,
00056 NULL,
00057 best_parent,
00058 calculate_rank,
00059 update_metric_container,
00060 0
00061 };
00062
00063 #define DEFAULT_RANK_INCREMENT DEFAULT_MIN_HOPRANKINC
00064
00065 #define MIN_DIFFERENCE (NEIGHBOR_INFO_ETX_DIVISOR + NEIGHBOR_INFO_ETX_DIVISOR / 2)
00066
00067 static void
00068 reset(rpl_dag_t *dag)
00069 {
00070 PRINTF("RPL: Resetting OF0\n");
00071 }
00072
00073 static rpl_rank_t
00074 calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
00075 {
00076 rpl_rank_t increment;
00077 if(base_rank == 0) {
00078 if(p == NULL) {
00079 return INFINITE_RANK;
00080 }
00081 base_rank = p->rank;
00082 }
00083
00084 increment = p != NULL ? p->dag->min_hoprankinc : DEFAULT_RANK_INCREMENT;
00085
00086 if((rpl_rank_t)(base_rank + increment) < base_rank) {
00087 PRINTF("RPL: OF0 rank %d incremented to infinite rank due to wrapping\n",
00088 base_rank);
00089 return INFINITE_RANK;
00090 }
00091 return base_rank + increment;
00092
00093 }
00094
00095 static rpl_parent_t *
00096 best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
00097 {
00098 rpl_rank_t r1, r2;
00099 rpl_dag_t *dag;
00100
00101 PRINTF("RPL: Comparing parent ");
00102 PRINT6ADDR(&p1->addr);
00103 PRINTF(" (confidence %d, rank %d) with parent ",
00104 p1->link_metric, p1->rank);
00105 PRINT6ADDR(&p2->addr);
00106 PRINTF(" (confidence %d, rank %d)\n",
00107 p2->link_metric, p2->rank);
00108
00109
00110 r1 = DAG_RANK(p1->rank, (rpl_dag_t *)p1->dag) * NEIGHBOR_INFO_ETX_DIVISOR +
00111 p1->link_metric;
00112 r2 = DAG_RANK(p2->rank, (rpl_dag_t *)p1->dag) * NEIGHBOR_INFO_ETX_DIVISOR +
00113 p2->link_metric;
00114
00115
00116
00117
00118 dag = (rpl_dag_t *)p1->dag;
00119 if(r1 < r2 + MIN_DIFFERENCE &&
00120 r1 > r2 - MIN_DIFFERENCE) {
00121 return dag->preferred_parent;
00122 } else if(r1 < r2) {
00123 return p1;
00124 } else {
00125 return p2;
00126 }
00127 }
00128
00129 static void
00130 update_metric_container(rpl_dag_t *dag)
00131 {
00132 dag->mc.type = RPL_DAG_MC_NONE;
00133 }