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
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <assert.h>
00054 #include <math.h>
00055 #include <stdio.h>
00056 #include <signal.h>
00057 #include <float.h>
00058
00059 #include <tcl.h>
00060 #include <stdlib.h>
00061
00062 #include "diff_header.h"
00063 #include "agent.h"
00064 #include "tclcl.h"
00065 #include "ip.h"
00066 #include "config.h"
00067 #include "packet.h"
00068 #include "trace.h"
00069 #include "random.h"
00070 #include "classifier.h"
00071 #include "node.h"
00072 #include "diffusion.h"
00073 #include "diff_rate.h"
00074 #include "iflist.h"
00075 #include "hash_table.h"
00076 #include "arp.h"
00077 #include "mac.h"
00078 #include "ll.h"
00079 #include "dsr/path.h"
00080 #include "god.h"
00081 #include "routing_table.h"
00082
00083
00084 void Diff_Routing_Entry::reset()
00085 {
00086 counter = 0;
00087 num_active = 0;
00088 num_iif = 0;
00089 clear_outlist(active);
00090 clear_outlist(inactive);
00091 clear_inlist(iif);
00092 clear_inlist(down_iif);
00093 clear_agentlist(source);
00094 clear_agentlist(sink);
00095 active = NULL;
00096 inactive = NULL;
00097 iif = NULL;
00098 down_iif = NULL;
00099 source = NULL;
00100 sink = NULL;
00101 last_fwd_time = -2.0*INTEREST_PERIODIC;
00102 new_org_counter = 0;
00103 }
00104
00105
00106 void Diff_Routing_Entry::clear_outlist(Out_List *list)
00107 {
00108 Out_List *cur=list;
00109 Out_List *temp = NULL;
00110
00111 while (cur != NULL) {
00112 temp = OUT_NEXT(cur);
00113 delete cur;
00114 cur = temp;
00115 }
00116
00117 }
00118
00119
00120 void Diff_Routing_Entry::clear_inlist(In_List *list)
00121 {
00122 In_List *cur=list;
00123 In_List *temp = NULL;
00124
00125 while (cur != NULL) {
00126 temp = IN_NEXT(cur);
00127 delete cur;
00128 cur = temp;
00129 }
00130 }
00131
00132
00133
00134 void Diff_Routing_Entry::clear_agentlist(Agent_List *list)
00135 {
00136 Agent_List *cur=list;
00137 Agent_List *temp = NULL;
00138
00139 while (cur != NULL) {
00140 temp = AGENT_NEXT(cur);
00141 delete cur;
00142 cur = temp;
00143 }
00144 }
00145
00146
00147 int Diff_Routing_Entry::MostRecvOrg()
00148 {
00149 In_List *cur;
00150 int most = 0;
00151
00152 for (cur=iif; cur!=NULL; cur = IN_NEXT(cur)) {
00153 most = max(most,NEW_ORG_RECV(cur));
00154 }
00155 return most;
00156 }
00157
00158
00159 bool Diff_Routing_Entry::ExistOriginalGradient()
00160 {
00161 Out_List *cur_out;
00162
00163 for (cur_out = active; cur_out!=NULL; cur_out=OUT_NEXT(cur_out)) {
00164 if (GRADIENT(cur_out) == ORIGINAL)
00165 return true;
00166 }
00167
00168 return false;
00169 }
00170
00171
00172 void Diff_Routing_Entry::IncRecvCnt(ns_addr_t agent_addr)
00173 {
00174 PrvCurPtr RetVal;
00175
00176 counter++;
00177
00178 RetVal=INTF_FIND(iif, agent_addr);
00179 if (RetVal.cur != NULL) {
00180 TOTAL_RECV(RetVal.cur)++;
00181 return;
00182 }
00183
00184 RetVal=INTF_FIND(source, agent_addr);
00185 if (RetVal.cur != NULL)
00186 return;
00187
00188
00189
00190 TOTAL_RECV(AddInList(agent_addr))++;
00191
00192 }
00193
00194
00195 void Diff_Routing_Entry::CntPosSend(ns_addr_t agent_addr)
00196 {
00197 PrvCurPtr RetVal;
00198
00199 RetVal=INTF_FIND(iif, agent_addr);
00200 if (RetVal.cur != NULL) {
00201 NUM_POS_SEND(RetVal.cur)++;
00202 return;
00203 }
00204
00205
00206
00207 In_List *cur_in = AddInList(agent_addr);
00208 NUM_POS_SEND(cur_in)++;
00209 }
00210
00211
00212 void Diff_Routing_Entry::CntNeg(ns_addr_t agent_addr)
00213 {
00214 PrvCurPtr RetVal;
00215
00216 RetVal=INTF_FIND(active, agent_addr);
00217 if (RetVal.cur != NULL) {
00218 NUM_NEG_RECV(RetVal.cur)++;
00219 return;
00220 }
00221
00222
00223
00224
00225 }
00226
00227
00228 void Diff_Routing_Entry::CntNewSub(ns_addr_t agent_addr)
00229 {
00230 PrvCurPtr RetVal;
00231
00232 RetVal=INTF_FIND(iif, agent_addr);
00233 if (RetVal.cur != NULL) {
00234 NEW_SUB_RECV(RetVal.cur)++;
00235 TOTAL_NEW_SUB_RECV(RetVal.cur)++;
00236 LAST_TS_NEW_SUB(RetVal.cur) = NOW;
00237 return;
00238 }
00239
00240 RetVal=INTF_FIND(source, agent_addr);
00241 if (RetVal.cur != NULL)
00242 return;
00243
00244
00245
00246 In_List *cur_in = AddInList(agent_addr);
00247 NEW_SUB_RECV(cur_in)++;
00248 TOTAL_NEW_SUB_RECV(cur_in)++;
00249 LAST_TS_NEW_SUB(cur_in) = NOW;
00250 }
00251
00252
00253 void Diff_Routing_Entry::ClrNewSub(ns_addr_t agent_addr)
00254 {
00255 PrvCurPtr RetVal;
00256
00257 RetVal=INTF_FIND(iif, agent_addr);
00258 if (RetVal.cur != NULL) {
00259 NEW_SUB_RECV(RetVal.cur)= 0;
00260 LAST_TS_NEW_SUB(RetVal.cur) = -1.0;
00261 return;
00262 }
00263 }
00264
00265
00266 void Diff_Routing_Entry::CntNewOrg(ns_addr_t agent_addr)
00267 {
00268 PrvCurPtr RetVal;
00269
00270 RetVal=INTF_FIND(iif, agent_addr);
00271 if (RetVal.cur != NULL) {
00272 NEW_ORG_RECV(RetVal.cur)++;
00273 TOTAL_NEW_ORG_RECV(RetVal.cur)++;
00274 return;
00275 }
00276
00277 RetVal=INTF_FIND(source, agent_addr);
00278 if (RetVal.cur != NULL)
00279 return;
00280
00281
00282
00283 In_List *cur_in = AddInList(agent_addr);
00284 NEW_ORG_RECV(cur_in)++;
00285 TOTAL_NEW_ORG_RECV(cur_in)++;
00286 }
00287
00288
00289 void Diff_Routing_Entry::CntOldOrg(ns_addr_t agent_addr)
00290 {
00291 PrvCurPtr RetVal;
00292
00293 RetVal=INTF_FIND(iif, agent_addr);
00294 if (RetVal.cur != NULL) {
00295 OLD_ORG_RECV(RetVal.cur)++;
00296 TOTAL_OLD_ORG_RECV(RetVal.cur)++;
00297 return;
00298 }
00299
00300 RetVal=INTF_FIND(source, agent_addr);
00301 if (RetVal.cur != NULL)
00302 return;
00303
00304
00305
00306 In_List *cur_in = AddInList(agent_addr);
00307 OLD_ORG_RECV(cur_in)++;
00308 TOTAL_OLD_ORG_RECV(cur_in)++;
00309 }
00310
00311
00312 void Diff_Routing_Entry::ClrAllNewOrg()
00313 {
00314 In_List *cur;
00315
00316 for (cur = iif; cur!= NULL; cur = IN_NEXT(cur)) {
00317 NEW_ORG_RECV(cur)= 0;
00318 }
00319 }
00320
00321
00322 void Diff_Routing_Entry::ClrAllOldOrg()
00323 {
00324 In_List *cur;
00325
00326 for (cur=iif; cur!=NULL; cur = IN_NEXT(cur) ) {
00327 OLD_ORG_RECV(cur)= 0;
00328 }
00329 }
00330
00331
00332 In_List *Diff_Routing_Entry::MostRecentIn()
00333 {
00334 In_List *cur, *ret;
00335 double recent_time;
00336
00337 ret = NULL;
00338 recent_time = -1.0;
00339 for (cur = iif; cur!=NULL; cur=IN_NEXT(cur)) {
00340 if (LAST_TS_NEW_SUB(cur) > recent_time) {
00341 ret = cur;
00342 recent_time = LAST_TS_NEW_SUB(cur);
00343 }
00344 }
00345 return ret;
00346 }
00347
00348
00349 In_List * Diff_Routing_Entry::AddInList(ns_addr_t addr)
00350 {
00351 In_List *inPtr= new In_List;
00352
00353 AGT_ADDR(inPtr) = addr;
00354 INTF_INSERT(iif, inPtr);
00355
00356 num_iif++;
00357 return inPtr;
00358 }
00359
00360
00361 Diff_Routing_Entry:: Diff_Routing_Entry()
00362 {
00363 last_fwd_time = -2.0*INTEREST_PERIODIC;
00364 counter = 0;
00365 new_org_counter = 0;
00366 num_active = 0;
00367 num_iif = 0;
00368 active = NULL;
00369 inactive = NULL;
00370 iif = NULL;
00371 down_iif = NULL;
00372 source = NULL;
00373 sink = NULL;
00374 }
00375
00376