rpl-private.h

00001 /*
00002  * Copyright (c) 2010, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * Author: Joakim Eriksson, Nicolas Tsiftes
00032  */
00033 
00034 #ifndef RPL_PRIVATE_H
00035 #define RPL_PRIVATE_H
00036 
00037 /*
00038  * ContikiRPL - an implementation of the routing protocol for low power and
00039  * lossy networks. See: draft-ietf-roll-rpl-17.
00040  *
00041  * --
00042  * The DIOs handle prefix information option for setting global IP addresses
00043  * on the nodes, but the current handling is not awaiting the join of the DAG
00044  * so it does not currently support multiple DAGs.
00045  */
00046 
00047 #include "net/rpl/rpl.h"
00048 
00049 #include "lib/list.h"
00050 #include "net/uip.h"
00051 #include "sys/clock.h"
00052 #include "sys/ctimer.h"
00053 #include "net/uip-ds6.h"
00054 
00055 /*---------------------------------------------------------------------------*/
00056 /** \brief Is IPv6 address a the link local all rpl nodes multicast address */
00057 #define uip_is_addr_linklocal_rplnodes_mcast(a)     \
00058   ((((a)->u8[0]) == 0xff) &&                        \
00059    (((a)->u8[1]) == 0x02) &&                        \
00060    (((a)->u16[1]) == 0) &&                          \
00061    (((a)->u16[2]) == 0) &&                          \
00062    (((a)->u16[3]) == 0) &&                          \
00063    (((a)->u16[4]) == 0) &&                          \
00064    (((a)->u16[5]) == 0) &&                          \
00065    (((a)->u16[6]) == 0) &&                          \
00066    (((a)->u8[14]) == 0) &&                          \
00067    (((a)->u8[15]) == 0x1a))
00068 
00069 /** \brief set IP address a to the link local all-rpl nodes multicast address */
00070 #define uip_create_linklocal_rplnodes_mcast(a) uip_ip6addr(a, 0xff02, 0, 0, 0, 0, 0, 0, 0x001a)
00071 /*---------------------------------------------------------------------------*/
00072 /* RPL message types */
00073 #define RPL_CODE_DIS                   0x00   /* DAG Information Solicitation */
00074 #define RPL_CODE_DIO                   0x01   /* DAG Information Option */
00075 #define RPL_CODE_DAO                   0x02   /* Destination Advertisement Option */
00076 #define RPL_CODE_DAO_ACK               0x03   /* DAO acknowledgment */
00077 #define RPL_CODE_SEC_DIS               0x80   /* Secure DIS */
00078 #define RPL_CODE_SEC_DIO               0x81   /* Secure DIO */
00079 #define RPL_CODE_SEC_DAO               0x82   /* Secure DAO */
00080 #define RPL_CODE_SEC_DAO_ACK           0x83   /* Secure DAO ACK */
00081 
00082 /* RPL DIO/DAO suboption types */
00083 #define RPL_DIO_SUBOPT_PAD1                     0
00084 #define RPL_DIO_SUBOPT_PADN                     1
00085 #define RPL_DIO_SUBOPT_DAG_METRIC_CONTAINER     2
00086 #define RPL_DIO_SUBOPT_ROUTE_INFO               3
00087 #define RPL_DIO_SUBOPT_DAG_CONF                 4
00088 #define RPL_DIO_SUBOPT_TARGET                   5
00089 #define RPL_DIO_SUBOPT_TRANSIT                  6
00090 #define RPL_DIO_SUBOPT_SOLICITED_INFO           7
00091 #define RPL_DIO_SUBOPT_PREFIX_INFO              8
00092 
00093 #define RPL_DAO_K_FLAG                   0x80 /* DAO ACK requested */
00094 #define RPL_DAO_D_FLAG                   0x40 /* DODAG ID Present */
00095 /*---------------------------------------------------------------------------*/
00096 /* Default values for RPL constants and variables. */
00097 
00098 /* The default value for the DAO timer. */
00099 #define DEFAULT_DAO_LATENCY             (CLOCK_SECOND * 8)
00100 
00101 /* Special value indicating immediate removal. */
00102 #define ZERO_LIFETIME                   0
00103 
00104 /* Special value indicating that a DAO should not expire. */
00105 #define INFINITE_LIFETIME               0xffffffff
00106 
00107 /* Default route lifetime in seconds. */
00108 #define DEFAULT_ROUTE_LIFETIME          INFINITE_LIFETIME
00109 
00110 #define DEFAULT_RPL_LIFETIME_UNIT       0xffff
00111 #define DEFAULT_RPL_DEF_LIFETIME        0xff
00112 
00113 #ifndef RPL_CONF_MIN_HOPRANKINC
00114 #define DEFAULT_MIN_HOPRANKINC          256
00115 #else
00116 #define DEFAULT_MIN_HOPRANKINC RPL_CONF_MIN_HOPRANKINC
00117 #endif
00118 #define DEFAULT_MAX_RANKINC             (3 * DEFAULT_MIN_HOPRANKINC)
00119 
00120 #define DAG_RANK(fixpt_rank, dag)       ((fixpt_rank) / (dag)->min_hoprankinc)
00121 
00122 /* Rank of a virtual root node that coordinates DAG root nodes. */
00123 #define BASE_RANK                       0
00124 
00125 /* Rank of a root node. */
00126 #define ROOT_RANK(dag)                  (dag)->min_hoprankinc
00127 
00128 #define INFINITE_RANK                   0xffff
00129 
00130 #define INITIAL_LINK_METRIC             NEIGHBOR_INFO_ETX2FIX(5)
00131 
00132 /* Represents 2^n ms. */
00133 /* Default value according to the specification is 3 which
00134    means 8 milliseconds, but that is an unreasonable value if
00135    using power-saving / duty-cycling    */
00136 #ifdef RPL_CONF_DIO_INTERVAL_MIN
00137 #define DEFAULT_DIO_INTERVAL_MIN        RPL_CONF_DIO_INTERVAL_MIN
00138 #else
00139 #define DEFAULT_DIO_INTERVAL_MIN        12
00140 #endif
00141 
00142 /* Maximum amount of timer doublings. */
00143 #ifdef RPL_CONF_DIO_INTERVAL_DOUBLINGS
00144 #define DEFAULT_DIO_INTERVAL_DOUBLINGS  RPL_CONF_DIO_INTERVAL_DOUBLINGS
00145 #else
00146 #define DEFAULT_DIO_INTERVAL_DOUBLINGS  8
00147 #endif
00148 
00149 /* Default DIO redundancy. */
00150 #ifdef RPL_CONF_DIO_REDUNDANCY
00151 #define DEFAULT_DIO_REDUNDANCY          RPL_CONF_DIO_REDUNDANCY
00152 #else
00153 #define DEFAULT_DIO_REDUNDANCY          10
00154 #endif
00155 
00156 /* Expire DAOs from neighbors that do not respond in this time. (seconds) */
00157 #define DAO_EXPIRATION_TIMEOUT          60
00158 /*---------------------------------------------------------------------------*/
00159 #define RPL_INSTANCE_LOCAL_FLAG         0x80
00160 #define RPL_INSTANCE_D_FLAG             0x40
00161 
00162 /* Values that tell where a route came from. */
00163 #define RPL_ROUTE_FROM_INTERNAL         0
00164 #define RPL_ROUTE_FROM_UNICAST_DAO      1
00165 #define RPL_ROUTE_FROM_MULTICAST_DAO    2
00166 #define RPL_ROUTE_FROM_DIO              3
00167 
00168 /* DAG Mode of Operation */
00169 #define RPL_MOP_NO_DOWNWARD_ROUTES      0
00170 #define RPL_MOP_NON_STORING             1
00171 #define RPL_MOP_STORING_NO_MULTICAST    2
00172 #define RPL_MOP_STORING_MULTICAST       3
00173 
00174 #ifdef  RPL_CONF_MOP
00175 #define RPL_MOP_DEFAULT                 RPL_CONF_MOP
00176 #else
00177 #define RPL_MOP_DEFAULT                 RPL_MOP_STORING_NO_MULTICAST
00178 #endif
00179 
00180 /*
00181  * The ETX in the metric container is expressed as a fixed-point value 
00182  * whose integer part can be obtained by dividing the value by 
00183  * RPL_DAG_MC_ETX_DIVISOR.
00184  */
00185 #define RPL_DAG_MC_ETX_DIVISOR          128
00186 
00187 /* DIS related */
00188 #define RPL_DIS_SEND                    1
00189 #ifdef  RPL_DIS_INTERVAL_CONF
00190 #define RPL_DIS_INTERVAL                RPL_DIS_INTERVAL_CONF
00191 #else
00192 #define RPL_DIS_INTERVAL                60
00193 #endif
00194 #define RPL_DIS_START_DELAY             5
00195 /*---------------------------------------------------------------------------*/
00196 /* Logical representation of a DAG Information Object (DIO.) */
00197 struct rpl_dio {
00198   uip_ipaddr_t dag_id;
00199   rpl_ocp_t ocp;
00200   rpl_rank_t rank;
00201   uint8_t grounded;
00202   uint8_t mop;
00203   uint8_t preference;
00204   uint8_t version;
00205   uint8_t instance_id;
00206   uint8_t dtsn;
00207   uint8_t dag_intdoubl;
00208   uint8_t dag_intmin;
00209   uint8_t dag_redund;
00210   uint8_t default_lifetime;
00211   uint16_t lifetime_unit;
00212   rpl_rank_t dag_max_rankinc;
00213   rpl_rank_t dag_min_hoprankinc;
00214   rpl_prefix_t destination_prefix;
00215   rpl_prefix_t prefix_info;
00216   struct rpl_metric_container mc;
00217 };
00218 typedef struct rpl_dio rpl_dio_t;
00219 
00220 #if RPL_CONF_STATS
00221 /* Statistics for fault management. */
00222 struct rpl_stats {
00223   uint16_t mem_overflows;
00224   uint16_t local_repairs;
00225   uint16_t global_repairs;
00226   uint16_t malformed_msgs;
00227   uint16_t resets;
00228   uint16_t parent_switch;
00229 };
00230 typedef struct rpl_stats rpl_stats_t;
00231 
00232 extern rpl_stats_t rpl_stats;
00233 #endif
00234 /*---------------------------------------------------------------------------*/
00235 /* RPL macros. */
00236 
00237 #if RPL_CONF_STATS
00238 #define RPL_STAT(code)  (code) 
00239 #else
00240 #define RPL_STAT(code)
00241 #endif /* RPL_CONF_STATS */
00242 /*---------------------------------------------------------------------------*/
00243 /* ICMPv6 functions for RPL. */
00244 void dis_output(uip_ipaddr_t *addr);
00245 void dio_output(rpl_dag_t *, uip_ipaddr_t *uc_addr);
00246 void dao_output(rpl_parent_t *, uint32_t lifetime);
00247 void dao_ack_output(rpl_dag_t *, uip_ipaddr_t *, uint8_t);
00248 void uip_rpl_input(void);
00249 
00250 /* RPL logic functions. */
00251 void rpl_join_dag(rpl_dag_t *);
00252 void rpl_local_repair(rpl_dag_t *dag);
00253 int rpl_set_default_route(rpl_dag_t *dag, uip_ipaddr_t *from);
00254 void rpl_process_dio(uip_ipaddr_t *, rpl_dio_t *);
00255 int rpl_process_parent_event(rpl_dag_t *, rpl_parent_t *);
00256 
00257 /* DAG object management. */
00258 rpl_dag_t *rpl_alloc_dag(uint8_t);
00259 void rpl_free_dag(rpl_dag_t *);
00260 
00261 /* DAG parent management function. */
00262 rpl_parent_t *rpl_add_parent(rpl_dag_t *, rpl_dio_t *dio, uip_ipaddr_t *);
00263 rpl_parent_t *rpl_find_parent(rpl_dag_t *, uip_ipaddr_t *);
00264 int rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
00265 rpl_parent_t *rpl_select_parent(rpl_dag_t *dag);
00266 void rpl_recalculate_ranks(void);
00267 
00268 /* RPL routing table functions. */
00269 void rpl_remove_routes(rpl_dag_t *dag);
00270 uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
00271                                int prefix_len, uip_ipaddr_t *next_hop);
00272 void rpl_purge_routes(void);
00273 
00274 /* Objective function. */
00275 rpl_of_t *rpl_find_of(rpl_ocp_t);
00276 
00277 /* Timer functions. */
00278 void rpl_schedule_dao(rpl_dag_t *);
00279 void rpl_reset_dio_timer(rpl_dag_t *, uint8_t);
00280 void rpl_reset_periodic_timer(void);
00281 
00282 /* Route poisoning. */
00283 void rpl_poison_routes(rpl_dag_t *, rpl_parent_t *);
00284 
00285 #endif /* RPL_PRIVATE_H */

Generated on Mon Apr 11 14:23:31 2011 for Contiki 2.5 by  doxygen 1.6.1