1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
| //********* Fonction de prédiction de la rupture du lien ************************************************************************************************
bool AODV::predict(AODV *node,nsaddr_t destAddr,nsaddr_t repAddr,double signal, double time)
{
NT *nodetable = node->node_table;
NT_Node* theNoden = NULL;
NT_Node* currentn=NULL;
NT_Node* previousn=NULL;
AODV_PWL_Node *newNode=NULL;
AODV_PWL_Node *ptr=NULL;
double p1, p2, p3,t1, t2, t3,tx,np,x,moy;
double const discovery_period=0.25,DB_THER=3.814e-10;
#ifdef DISPLAY_INFO
printf("\n repnode %d node %d \n",repAddr,index);
#endif
//Find the insertion point. Entries are sorted in increaseing order of node addresses
currentn = nodetable->head;
while ((currentn != NULL) && (currentn->destAddr < destAddr)) {
previousn = currentn;
currentn = currentn->next;
}//while//
if((currentn==NULL)||(currentn->destAddr!=destAddr))
{ //Corresponding entry does not exist. So add entry for this destination and a value in the node table
#ifdef DISPLAY_INFO
printf("\n---> 1 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
#endif
++(nodetable->size);
// initiate feilds of a node in the node table
theNoden = (NT_Node *)malloc(sizeof(NT_Node));
theNoden->destAddr = destAddr;
theNoden->repAddr = repAddr;
theNoden->signal = signal;
theNoden->lasttime = 0;
// initaite the list of power for the correspending node for the first time
theNoden->PowerList.head = NULL;
theNoden->PowerList.tail = NULL;
theNoden->PowerList.size = 0;
if(signal<=DB_THER)//hey
{
newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
newNode->SignalPower = signal;
newNode->Time = time;
newNode->next=NULL;
theNoden->PowerList.head = theNoden->PowerList.tail = newNode;
theNoden->PowerList.size++;
}
if (previousn == NULL)
{
theNoden->next = nodetable->head;
nodetable->head = theNoden;
} // (previousn == NULL)
else
{
theNoden->next = previousn->next;
previousn->next = theNoden;
}
}
else // (currentn!=NULL)&&(currentn->destAddr==destAddr)
{
while ((currentn != NULL) && (currentn->destAddr == destAddr) &&(currentn->repAddr!=repAddr)) {
currentn = currentn->next;
}//while//
if((currentn != NULL) &&(currentn->destAddr==destAddr)&&(currentn->repAddr==repAddr)) //hey
{
if (signal<=DB_THER)//hey
{
if (currentn->PowerList.size < 2)
{
if(currentn->PowerList.tail==NULL || currentn->PowerList.tail->SignalPower != signal) //hey
{
#ifdef DISPLAY_INFO
printf("\n---> 2 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
#endif
// adding a value in the list of power for the correspending node for the 2nd value without redendency of power values
newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
newNode->SignalPower = signal;
newNode->Time = time;
newNode->next=NULL;
if (currentn->PowerList.tail==NULL){ //hey
currentn->PowerList.head = currentn->PowerList.tail = newNode;}
else{
currentn->PowerList.tail->next = newNode;
currentn->PowerList.tail = newNode;
}
currentn->PowerList.size++;
} // SignalPower != signal
else
{
currentn->PowerList.tail->Time = time;
#ifdef DISPLAY_INFO
printf("\n--->2 stop noeud %d destnoeud %d power %g \n",index,destAddr,signal);
#endif
}
} // PowerList.size < 3
else
{
int t= currentn->PowerList.size + 1;
if (t==3)
{
#ifdef DISPLAY_INFO
printf("\n---> 3 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
#endif
if(currentn->PowerList.tail->SignalPower != signal)
{
// adding a value in the list of power for the correspending node for the 3rd value without redendency of power values
newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
newNode->SignalPower = signal;
newNode->Time = time;
newNode->next=NULL;
currentn->PowerList.tail->next = newNode;
currentn->PowerList.tail = newNode;
currentn->PowerList.size++;
//after having 3 value of signal strength - the above value is the 3rd - we must predict the next value of the signal strength using linear extrapolation and testing if this new value reach he thershold of reparing link breakage
ptr=currentn->PowerList.head;
t1 = ptr->Time;
p1 = ptr->SignalPower;
ptr=ptr->next;
t2 = ptr->Time;
p2 = ptr->SignalPower;
ptr=ptr->next;
t3 = ptr->Time;
p3 = ptr->SignalPower;
moy=t3-((t1+t2+t3)/3);//hey
x = t3 + min(moy,discovery_period) ;
//printf("%g:%g %g:%g %g:%g\n",t1,p1,t2,p2,t3,p3);
np=((((x-t2)*(x-t3))/((t1-t2)*(t1-t3)))*p1) +((((x-t1)*(x-t3))/((t2-t1)*(t2-t3)))*p2) + ((((x-t1)*(x-t2))/((t3-t1)*(t3-t2)))*p3);
#ifdef DISPLAY_INFO
printf("\n node %d Now %g predict at time %g power %g dest %d\n",index,time, x ,np,destAddr );
#endif
if((np <= 3.652e-10)&&(p1>p2)&&(p2>p3))
{
#ifdef DISPLAY_INFO
printf("\n 3will disconnect must be repaired \n" );
#endif
while (currentn->PowerList.size!=0){ //hey
ptr=currentn->PowerList.head;
currentn->PowerList.head=currentn->PowerList.head->next;
currentn->PowerList.size--;
delete ptr;
ptr=NULL;
}
currentn->PowerList.tail = NULL;
//printf("\n node %d Now %g predict at time %g power %g dest %d\n",index,time, x ,np,destAddr );
//printf("%g:%g %g:%g %g:%g\n",t1,p1,t2,p2,t3,p3);
return TRUE;
}
else
{
#ifdef DISPLAY_INFO
printf("\n deleting powerList struct\n" );
#endif
ptr=currentn->PowerList.head;
currentn->PowerList.head=currentn->PowerList.head->next;
currentn->PowerList.size--;
delete ptr;
ptr=NULL;
}
} // SignalPower != signal
else
{
#ifdef DISPLAY_INFO
printf("\n--->3 stop noeud %d destnoeud %dpower %g \n",index,destAddr,signal);
#endif
tx = currentn->PowerList.tail->Time; //hey
currentn->PowerList.tail->Time = time;
currentn->PowerList.head->Time=currentn->PowerList.head->Time + (time - tx);
}
}
}
}else //hey
{
while (currentn->PowerList.size!=0){
ptr=currentn->PowerList.head;
currentn->PowerList.head=currentn->PowerList.head->next;
currentn->PowerList.size--;
delete ptr;
ptr=NULL;
}
currentn->PowerList.tail = NULL;
}
}
else // (destAddr==destAddr)&&(repAddr==nodeAddr))
{
#ifdef DISPLAY_INFO
printf("\n---> 1 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
#endif
++(nodetable->size);
// initiate feilds of a node in the node table
theNoden = (NT_Node *)malloc(sizeof(NT_Node));
theNoden->destAddr = destAddr;
theNoden->repAddr = repAddr;
theNoden->signal = signal;
theNoden->lasttime = 0;
// initaite the list of power for the correspending node for the first time
theNoden->PowerList.head = NULL;
theNoden->PowerList.tail = NULL;
theNoden->PowerList.size = 0;
if (signal<=DB_THER){//hey
newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
newNode->SignalPower = signal;
newNode->Time = time;
newNode->next=NULL;
theNoden->PowerList.head = theNoden->PowerList.tail = newNode;
theNoden->PowerList.size++;
}
if (previousn == NULL)
{
theNoden->next = nodetable->head;
nodetable->head = theNoden;
} // (previousn == NULL)
else
{
theNoden->next = previousn->next;
previousn->next = theNoden;
}
}
}
#ifdef DISPLAY_INFO
printf("\n \t\t\t RAS \n" );
#endif
return FALSE ;
}
//endModification |
Partager