NetSim Source Code Help
Loading...
Searching...
No Matches
Trickle.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "RPL.h"
16#include "RPL_enum.h"
17
19{
20 r->trickle.t = ((UINT)NETSIM_RAND() % ((UINT)(r->trickle.I / 2))) + r->trickle.I / 2;
21}
22
24{
26 PRPL_NODE r = GET_RPL_NODE(ndevId);
27
28#ifdef DEBUG_RPL_TRICKLE
29 print_rpl_log("node '%d',Time '%0.3lf ms': resetting trickle timer", ndevId,pstruEventDetails->dEventTime/1000);
30#endif
31
32 if (rpl_node_is_root(r))
33 {
37 }
39 {
43 }
44 else
45 {
46 return; /* no trickle timer in isolated state */
47 }
48
49 r->trickle.I = r->trickle.Imin;
50
52
53 //Delete the old trickle event
56
57 memset(&pevent, 0, sizeof pevent);
58
59 //Schedule the Trickle_t time out event
62 pevent.nDeviceId = ndevId;
63 pevent.nDeviceType = DEVICE_TYPE(ndevId);
64 pevent.nEventType = TIMER_EVENT;
66 pevent.nSubEventType = RPL_TRICKLE_T_TIMEOUT;
68
69 //Schedule the Trickle_i time out event
72 pevent.nSubEventType = RPL_TRICKLE_I_TIMEOUT;
74}
75
77{
79
81
82 if (dio_pdu != NULL)
84}
85
87{
89
90 if (rpl_node_is_root(rpl))
91 {
92 if (rpl->trickle.C < rpl->trickle.Imax)
93 {
94 rpl->trickle.C++;
95 rpl->trickle.I *= 2;
96 }
97 }
98 else if (rpl_node_is_joined(rpl))
99 {
100 if (rpl->trickle.C < rpl->trickle.Imax)
101 {
102 rpl->trickle.C++;
103 rpl->trickle.I *= 2;
104 }
105 }
106 else if (rpl_node_is_poisoning(rpl))
107 {
109 {
110 rpl->poison_count_so_far++;
111 }
112 else
113 { /* enough with poisoning */
114 bool same;
116 &same,
118
119 if (preferred_dodag_pdu != NULL)
120 {
121 join_dodag_iteration(pstruEventDetails->nDeviceId, preferred_dodag_pdu);
123 }
124 else
125 {
127 }
128
129 return;
130 }
131 }
132 else
133 {
134 fnNetSimError("Unknown node status for node %s in rpl\n", pstruEventDetails->nDeviceId);
135 return; /* this should never happen */
136 }
137
139
140#ifdef DEBUG_RPL_TRICKLE
141 print_rpl_log("node '%d': trickle time is generated at t=%0.3lf, i=%0.2lf",
143 (ldEventTime + rpl->trickle.t) / 1000,
144 (ldEventTime + rpl->trickle.I) / 1000);
145#endif
146
147 NetSim_EVENTDETAILS pevent;
148
149 memset(&pevent, 0, sizeof pevent);
150
151 //Schedule the Trickle_t time out event
156 pevent.nEventType = TIMER_EVENT;
158 pevent.nSubEventType = RPL_TRICKLE_T_TIMEOUT;
159 rpl->trickle.trickle_t_eventid = fnpAddEvent(&pevent);
160
161 //Schedule the Trickle_i time out event
164 pevent.nSubEventType = RPL_TRICKLE_I_TIMEOUT;
165 rpl->trickle.trickle_i_eventid = fnpAddEvent(&pevent);
166}
unsigned int NETSIM_ID
Definition: Animation.h:45
PRPL_CTRL_MSG get_preferred_dodag_dio_pdu(NETSIM_ID d, bool *same, double time)
Definition: DIO.c:78
void join_dodag_iteration(NETSIM_ID d, PRPL_CTRL_MSG dio_pdu)
Definition: DODAG.c:73
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define TRUE
Definition: Linux.h:77
void choose_parents_and_siblings(NETSIM_ID d)
Definition: Neighbor.c:189
void start_as_root(NETSIM_ID d)
Definition: RPL.c:197
#define GET_RPL_NODE(d)
Definition: RPL.h:212
bool rpl_node_is_joined(PRPL_NODE r)
bool rpl_node_is_root(PRPL_NODE r)
void print_rpl_log(char *format,...)
bool rpl_node_is_poisoning(PRPL_NODE r)
NetSim_PACKET * create_current_dio_message(NETSIM_ID ndevId, double time, bool include_dodag_config)
Definition: RPL_Message.c:293
void rpl_node_send_msg(NETSIM_ID ndevid, NetSim_PACKET *packet)
Definition: RPL_Message.c:418
#define RPL_DEFAULT_POISON_COUNT
Definition: RPL.h:87
EXPORTED double ldEventTime
Definition: Stack.h:838
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ NW_PROTOCOL_RPL
Definition: Stack.h:200
#define MILLISECOND
Definition: Stack.h:59
@ TIMER_EVENT
Definition: Stack.h:114
int fnDeleteEvent(unsigned long long int nEventId)
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define NETSIM_RAND()
Definition: Stack.h:859
static void set_trickle_t_time(PRPL_NODE r)
Definition: Trickle.c:18
void rpl_trickle_handle_t_timeout()
Definition: Trickle.c:76
void rpl_trickle_handle_i_timeout()
Definition: Trickle.c:86
void rpl_trickle_reset(NETSIM_ID ndevId)
Definition: Trickle.c:23
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
UINT8 dio_interval_min
Definition: RPL.h:150
UINT8 dio_redundancy_constant
Definition: RPL.h:151
UINT8 dio_interval_doublings
Definition: RPL.h:149
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
PRPL_DODAG joined_dodag
Definition: RPL.h:178
PRPL_ROOT root_info
Definition: RPL.h:177
UINT8 poison_count_so_far
Definition: RPL.h:202
struct stru_rpl_node::stru_trickle trickle
UINT8 dio_interval_doublings
Definition: RPL.h:131
UINT8 dio_interval_min
Definition: RPL.h:132
UINT8 dio_redundancy_constant
Definition: RPL.h:133