NetSim Source Code Help
Loading...
Searching...
No Matches
RPL.h
Go to the documentation of this file.
1#pragma once
2/************************************************************************************
3* Copyright (C) 2020 *
4* TETCOS, Bangalore. India *
5* *
6* Tetcos owns the intellectual property rights in the Product and its content. *
7* The copying, redistribution, reselling or publication of any or all of the *
8* Product or its content without express prior written consent of Tetcos is *
9* prohibited. Ownership and / or any other right relating to the software and all *
10* intellectual property rights therein shall remain at all times with Tetcos. *
11* *
12* Author: Shashi Kant Suman *
13* *
14* ---------------------------------------------------------------------------------*/
15
16/************** RFC's **************************************************************
17https://tools.ietf.org/html/rfc6550 //RPL
18https://tools.ietf.org/html/rfc6206 //The Trickle Algorithm
19************************************************************************************/
20#ifndef _NETSIM_RPL_H_
21#define _NETSIM_RPL_H_
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26 //Log settings
27// #define DEBUG_RPL
28#ifdef DEBUG_RPL
29#define DEBUG_RPL_PRINT_DAO_ROUTE_INFOMATION
30//#define DEBUG_RPL_TRICKLE
31#endif
32
33
34#include "RPL_Message.h"
35
36 //Include necessary lib's
37#pragma comment(lib,"NetworkStack.lib")
38#pragma comment(lib,"RPLlib.lib")
39
40
41 /*
42 * Maximum amount of timer doubling.
43 *
44 * The maximum interval will by default be 2^(12+8) ms = 1048.576 s.
45 * RFC 6550 suggests a default value of 20
46 */
47#define DEFAULT_DIO_INTERVAL_DOUBLINGS 20
48
49 /*
50 * The DIO interval (n) represents 2^n ms.
51 *
52 * According to the specification, the default value is 3 which
53 * means 8 milliseconds.
54 */
55#define DEFAULT_DIO_INTERVAL_MIN 3
56 /*
57 * DIO redundancy. To learn more about this, see RFC 6206.
58 *
59 * RFC 6550 suggests a default value of 10.
60 */
61#define DEFAULT_DIO_REDUNDANCY_CONSTANT 10
62 /*
63 * MinHopRankIncrease is the minimum increase in Rank between a node and any of its DODAG parents
64 * RFC 6550 suggests a default value of 256
65 */
66#define DEFAULT_MIN_HOP_RANK_INCREASE 256
67#define DEFAULT_DAO_DELAY 1 //Second
68
69//Config parameter
70#define RPL_NODE_TYPE_DEFAULT _strdup("ROUTER")
71#define RPL_INSTANCE_ID_DEFAULT 15
72#define RPL_DIOIntervalDoublings_DEFAULT DEFAULT_DIO_INTERVAL_DOUBLINGS
73#define RPL_DIOIntervalMin_DEFAULT DEFAULT_DIO_INTERVAL_MIN
74#define RPL_DIORedundancyConstant_DEFAULT DEFAULT_DIO_REDUNDANCY_CONSTANT
75#define RPL_MinHopRankIncrease_DEFAULT DEFAULT_MIN_HOP_RANK_INCREASE
76#define RPL_DODAGPreference_DEFAULT 0
77#define RPL_DAO_DELAY_DEFAULT DEFAULT_DAO_DELAY
78#define RPL_DIS_INITIAL_DELAY_DEFAULT 200 //Millisecond
79#define RPL_DIS_INTERVAL_DEFAULT 100 //Millisecond
80
81#define INFINITE_RANK 0xFFFF
82#define RPL_RANK_ROOT 1
83#define RPL_MINIMUM_RANK_INCREMENT 1
84#define RPL_MAXIMUM_RANK_INCREMENT 16
85#define RPL_DEFAULT_DAG_PREF 0 /* least preferred */
86#define RPL_DEFAULT_MOP 2 /*Storing Mode of Operation with no Multicast support*/
87#define RPL_DEFAULT_POISON_COUNT 4
88#define RPL_DEFAULT_DAO_REMOVE_TIMEOUT (2500*MILLISECOND)
89
92
93 //USEFUL MACRO
94#define is_rpl_control_packet(packet) ((packet)->nControlDataType/100==NW_PROTOCOL_RPL)
95#define is_rpl_configured(d) (DEVICE_NWLAYER((d)) && DEVICE_NWLAYER((d))->nRoutingProtocolId==NW_PROTOCOL_RPL)
96
97
98 typedef enum
99 {
104
105 /* used to coordinate the sequence numbers when multiple roots share the same DODAG id */
106 typedef struct seq_num_mapping_t
107 {
108
111
113
114 typedef struct stru_rpl_neighbor
115 {
121
122 typedef struct stru_rpl_root
123 {
130
134
137
140
141 typedef struct stru_rpl_dodag
142 {
148
152
155
159
166
167 typedef struct stru_rpl_node
168 {
169 //Config variable
175
176
180
181 //RFC 6206 Section 4.1
183 {
184 double Imin; // pow(2, dio_interval_min)
185 UINT Imax; // dio_interval_doublings
186 UINT k; // redundancy_constant
187
188 double t; // trickle_i_doublings_so_far
189 double I; // trickle_i
190 UINT8 C; // trickle_c
191
192 //Sim parameter
193 unsigned long long int trickle_i_eventid;
194 unsigned long long int trickle_t_eventid;
198
201
203
204 double last_dio_send_time; /* used for detecting collisions by simulating a risk window */
205
207
208 //simulation parameter
209 unsigned long long int dao_send_eventid;
210
212#define GET_RPL_NODE(d) ((PRPL_NODE)DEVICE_NWROUTINGVAR(d))
213
214
215
216
217
218 /************************************************************************/
219 /* Function Prototype */
220 /************************************************************************/
221 void print_rpl_log(char* format, ...);
222
223 //Init Function
224 void rpl_node_init(NETSIM_ID d);
225 void start_as_root(NETSIM_ID d);
226
227 //RPL Utility function
233
234 //Trickle
235 void rpl_trickle_reset(NETSIM_ID nDevId);
238
239 //DODAG
241 void rpl_dodag_destroy(PRPL_DODAG dodag);
243 void update_dodag_config(NETSIM_ID node, PRPL_CTRL_MSG dio_pdu);
244
245 //RPL Message
248 NetSim_PACKET* create_current_dio_message(NETSIM_ID ndevId, double time, bool include_dodag_config);
249 void rpl_option_destroy(PRPL_OPTION option);
251
252 /***RPL Message Processing***/
255 void rpl_node_send_msg(NETSIM_ID ndevid, NetSim_PACKET* packet);
256
257 //DIO
258 PRPL_CTRL_MSG get_preferred_dodag_dio_pdu(NETSIM_ID d, bool *same, double time);
259 NetSim_PACKET* create_root_dio_message(NETSIM_ID ndevId, double time, bool include_dodag_config, bool include_seq_num);
260 void rpl_process_dio_msg();
263 void rpl_dio_msg_copy(const NetSim_PACKET* destPacket, const NetSim_PACKET* srcPacket);
265
266 //DAO
267 NetSim_PACKET* create_dao_message(NETSIM_ID ndevid, double time, NETSIM_ID parent);
269 void rpl_send_dao();
270 void rpl_process_dao_msg();
272 void rpl_dao_msg_copy(const NetSim_PACKET* destPacket, const NetSim_PACKET* srcPacket);
274
275 //DIS
276 void rpl_process_dis_msg();
277 void rpl_dis_pdu_send();
278 NetSim_PACKET* create_dis_message(NETSIM_ID ndevid, double time);
280 void rpl_dis_msg_copy(const NetSim_PACKET* destPacket, const NetSim_PACKET* srcPacket);
281 /******/
282
283 //Sequence Number
286
287 /*** RPL Neighbor ****/
288
289 //Neighbor
295
296 //Parent
300#define rpl_node_has_parent(node, parent) (rpl_node_find_parent(node, parent) != NULL)
301
302 //Siblings
306#define rpl_node_has_sibling(node, sibling) (rpl_node_find_sibling(node, sibling) != NULL)
307
309 /*******************/
310
311 //RPL IP Routing
314
315 //Global
316 #define RPL_IP_TO_STR(ip) ((ip)->str_ip)
317
318#ifdef __cplusplus
319}
320#endif
321#endif
unsigned int NETSIM_ID
Definition: Animation.h:45
#define UINT
Definition: Linux.h:38
#define UINT16
Definition: Linux.h:33
#define UINT8
Definition: Linux.h:31
void rpl_dis_msg_copy(const NetSim_PACKET *destPacket, const NetSim_PACKET *srcPacket)
Definition: DIS.c:62
void rpl_dio_msg_copy(const NetSim_PACKET *destPacket, const NetSim_PACKET *srcPacket)
Definition: DIO.c:339
bool rpl_node_is_isolated(PRPL_NODE rpl)
void rpl_delete_all_route(NETSIM_ID d)
struct stru_rpl_dodag RPL_DODAG
void rpl_process_dis_msg()
Definition: DIS.c:40
void * get_option_from_msg(PRPL_CTRL_MSG msg, RPL_OPTION_TYPE type)
Definition: RPL_Message.c:60
struct stru_rpl_node RPL_NODE
void update_dodag_config(NETSIM_ID node, PRPL_CTRL_MSG dio_pdu)
Definition: DODAG.c:112
void rpl_node_add_sibling(NETSIM_ID d, PRPL_NEIGHBOR sibling)
Definition: Neighbor.c:122
bool rpl_node_is_joined(PRPL_NODE r)
PRPL_CTRL_MSG get_preferred_dodag_dio_pdu(NETSIM_ID d, bool *same, double time)
Definition: DIO.c:78
void rpl_dis_pdu_send()
Definition: DIS.c:20
void rpl_dis_msg_destroy(NetSim_PACKET *packet)
Definition: DIS.c:51
NetSim_PACKET * create_dis_message(NETSIM_ID ndevid, double time)
Definition: RPL_Message.c:408
void join_dodag_iteration(NETSIM_ID d, PRPL_CTRL_MSG dio_pdu)
Definition: DODAG.c:73
void rpl_node_init(NETSIM_ID d)
Definition: RPL.c:181
struct stru_rpl_neighbor RPL_NEIGHBOR
void rpl_dio_pdu_free(PRPL_CTRL_MSG dio)
Definition: RPL_Message.c:343
UINT16 RPL_RANK
Definition: RPL.h:90
struct stru_rpl_dodag * PRPL_DODAG
void start_as_root(NETSIM_ID d)
Definition: RPL.c:197
void rpl_add_route_to_parent(NETSIM_ID d, NETSIM_ID parent)
bool rpl_node_is_root(PRPL_NODE r)
void rpl_dao_msg_copy(const NetSim_PACKET *destPacket, const NetSim_PACKET *srcPacket)
Definition: DAO.c:232
void print_rpl_log(char *format,...)
PRPL_NEIGHBOR rpl_node_find_sibling(NETSIM_ID d, NETSIM_ID sibling)
Definition: Neighbor.c:135
void rpl_dio_msg_destroy(NetSim_PACKET *packet)
Definition: DIO.c:346
PRPL_NEIGHBOR rpl_node_find_parent(NETSIM_ID d, NETSIM_ID parent)
Definition: Neighbor.c:76
void rpl_process_dao_msg()
Definition: DAO.c:104
void start_dio_poisoning(NETSIM_ID d)
Definition: DIO.c:60
void forget_neighbor_messages(PRPL_NODE rpl)
Definition: Neighbor.c:107
void rpl_node_remove_all_siblings(NETSIM_ID d)
Definition: Neighbor.c:153
void rpl_dao_msg_destroy(NetSim_PACKET *packet)
Definition: DAO.c:218
void choose_parents_and_siblings(NETSIM_ID d)
Definition: Neighbor.c:189
void rpl_trickle_handle_t_timeout()
Definition: Trickle.c:76
bool rpl_node_is_poisoning(PRPL_NODE r)
RPLNODETYPE
Definition: RPL.h:99
@ RPLNODETYPE_LEAF
Definition: RPL.h:102
@ RPLNODETYPE_ROUTER
Definition: RPL.h:101
@ RPLNODETYPE_ROOT
Definition: RPL.h:100
void rpl_process_ctrl_msg()
Definition: RPL_Message.c:433
PRPL_NEIGHBOR rpl_find_neighbor(NETSIM_ID d, NETSIM_ID r)
Definition: Neighbor.c:19
void rpl_send_dao()
Definition: DAO.c:43
void update_neighbor_dio_message(PRPL_NEIGHBOR neighbor, PRPL_CTRL_MSG dio_pdu)
Definition: Neighbor.c:58
void rpl_node_add_parent(NETSIM_ID d, PRPL_NEIGHBOR parent)
Definition: Neighbor.c:64
NetSim_PACKET * create_current_dio_message(NETSIM_ID ndevId, double time, bool include_dodag_config)
Definition: RPL_Message.c:293
void rpl_trickle_handle_i_timeout()
Definition: Trickle.c:86
struct stru_rpl_neighbor * PRPL_NEIGHBOR
void rpl_add_to_neighbor_list()
Definition: Neighbor.c:44
NETSIM_IPAddress DODAGID
Definition: RPL.h:91
void rpl_trickle_reset(NETSIM_ID nDevId)
Definition: Trickle.c:23
void seq_num_mapping_cleanup()
NetSim_PACKET * create_root_dio_message(NETSIM_ID ndevId, double time, bool include_dodag_config, bool include_seq_num)
Definition: RPL_Message.c:225
void create_and_add_rpl_target_option(NetSim_PACKET *dao_pdu, UINT8 prefix_len, NETSIM_IPAddress dest)
Definition: RPL_Message.c:379
PRPL_DODAG rpl_dodag_create(PRPL_CTRL_MSG dio_pdu)
Definition: DODAG.c:18
PRPL_OPTION rpl_option_copy(PRPL_OPTION option)
Definition: RPL_Message.c:114
void rpl_node_send_msg(NETSIM_ID ndevid, NetSim_PACKET *packet)
Definition: RPL_Message.c:418
void free_all_neighbor(PRPL_NODE rpl)
Definition: Neighbor.c:407
void ** get_all_option_from_msg(PRPL_CTRL_MSG msg, RPL_OPTION_TYPE type, UINT *count)
Definition: RPL_Message.c:73
struct stru_rpl_root RPL_ROOT
PRPL_ROOT get_global_root_info()
NetSim_PACKET * create_dao_message(NETSIM_ID ndevid, double time, NETSIM_ID parent)
Definition: RPL_Message.c:370
void rpl_option_destroy(PRPL_OPTION option)
Definition: RPL_Message.c:96
seq_num_mapping_t * seq_num_mapping_get(NETSIM_IPAddress dodag_id)
void rpl_node_remove_all_parents(NETSIM_ID d)
Definition: Neighbor.c:94
void rpl_dao_route_timeout()
Definition: DAO.c:183
void rpl_dodag_destroy(PRPL_DODAG dodag)
Definition: DODAG.c:53
void rpl_process_dio_msg()
Definition: DIO.c:191
PRPL_CTRL_MSG rpl_dio_pdu_duplicate(PRPL_CTRL_MSG dio)
Definition: RPL_Message.c:314
struct stru_rpl_node * PRPL_NODE
struct stru_rpl_root * PRPL_ROOT
enum enum_rpl_option_type RPL_OPTION_TYPE
NETSIM_IPAddress dodag_id
Definition: RPL.h:110
UINT8 seq_num
Definition: RPL.h:109
UINT8 dio_interval_min
Definition: RPL.h:150
UINT8 dio_redundancy_constant
Definition: RPL.h:151
UINT16 rank
Definition: RPL.h:158
UINT16 lowest_rank
Definition: RPL.h:157
UINT16 min_hop_rank_inc
Definition: RPL.h:154
PRPL_NEIGHBOR pref_parent
Definition: RPL.h:164
UINT dodag_pref
Definition: RPL.h:144
PRPL_NEIGHBOR * sibling_list
Definition: RPL.h:162
bool dao_trigger
Definition: RPL.h:147
DODAGID dodag_id
Definition: RPL.h:143
UINT16 parent_count
Definition: RPL.h:161
PRPL_NEIGHBOR * parent_list
Definition: RPL.h:160
UINT8 seq_num
Definition: RPL.h:156
bool dao_supported
Definition: RPL.h:146
UINT8 dio_interval_doublings
Definition: RPL.h:149
UINT16 max_rank_inc
Definition: RPL.h:153
UINT16 sibling_count
Definition: RPL.h:163
bool grounded
Definition: RPL.h:145
RPL_RANK rank
Definition: RPL.h:117
bool isParent
Definition: RPL.h:118
NETSIM_ID nodeId
Definition: RPL.h:116
PRPL_CTRL_MSG lastDIOMSG
Definition: RPL.h:119
unsigned long long int trickle_t_eventid
Definition: RPL.h:194
unsigned long long int trickle_i_eventid
Definition: RPL.h:193
double last_trickle_t_schedule_time
Definition: RPL.h:196
double last_trickle_i_schedule_time
Definition: RPL.h:195
UINT8 DaoSequence
Definition: RPL.h:206
bool storing
Definition: RPL.h:179
double DISInitDelay
Definition: RPL.h:173
PRPL_DODAG joined_dodag
Definition: RPL.h:178
double last_dio_send_time
Definition: RPL.h:204
PRPL_ROOT root_info
Definition: RPL.h:177
UINT16 neighbor_count
Definition: RPL.h:200
double DAODelayTime
Definition: RPL.h:172
RPLNODETYPE nodeType
Definition: RPL.h:171
UINT8 RPLInstanceId
Definition: RPL.h:170
PRPL_NEIGHBOR * neighbor_list
Definition: RPL.h:199
UINT8 poison_count_so_far
Definition: RPL.h:202
double DISInterval
Definition: RPL.h:174
struct stru_rpl_node::stru_trickle trickle
unsigned long long int dao_send_eventid
Definition: RPL.h:209
DODAGID configured_dodag_id
Definition: RPL.h:125
UINT8 dio_interval_doublings
Definition: RPL.h:131
UINT8 seq_num
Definition: RPL.h:138
UINT8 dodag_pref
Definition: RPL.h:126
UINT16 max_rank_inc
Definition: RPL.h:135
UINT8 dio_interval_min
Definition: RPL.h:132
UINT8 dio_redundancy_constant
Definition: RPL.h:133
DODAGID dodag_id
Definition: RPL.h:124
UINT16 min_hop_rank_inc
Definition: RPL.h:136
bool grounded
Definition: RPL.h:127
bool dao_supported
Definition: RPL.h:128
bool dao_trigger
Definition: RPL.h:129