Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

routing_table.cc

Go to the documentation of this file.
00001 // Copyright (c) 2000 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 //
00025 
00026 /********************************************************************/
00027 /* routing_table.cc : Chalermek Intanagonwiwat (USC/ISI)  05/18/99  */
00028 /********************************************************************/
00029 
00030 // Important Note: Work still in progress !
00031 
00032 #include <assert.h>
00033 #include <math.h>
00034 #include <stdio.h>
00035 #include <signal.h>
00036 #include <float.h>
00037 
00038 #include <tcl.h>
00039 #include <stdlib.h>
00040 
00041 #include "diff_header.h"
00042 #include "agent.h"
00043 #include "tclcl.h"
00044 #include "ip.h"
00045 #include "config.h"
00046 #include "packet.h"
00047 #include "trace.h"
00048 #include "random.h"
00049 #include "classifier.h"
00050 #include "node.h"
00051 #include "diffusion.h"
00052 #include "diff_rate.h"
00053 #include "iflist.h"
00054 #include "hash_table.h"
00055 #include "arp.h"
00056 #include "mac.h"
00057 #include "ll.h"
00058 #include "dsr/path.h"
00059 #include "god.h"
00060 #include "routing_table.h"
00061 
00062 
00063 void Diff_Routing_Entry::reset()
00064 {
00065   counter = 0;
00066   num_active = 0;
00067   num_iif = 0;
00068   clear_outlist(active);
00069   clear_outlist(inactive);
00070   clear_inlist(iif);
00071   clear_inlist(down_iif);
00072   clear_agentlist(source);
00073   clear_agentlist(sink);
00074   active = NULL;
00075   inactive = NULL;
00076   iif = NULL;
00077   down_iif = NULL;
00078   source = NULL;
00079   sink = NULL;
00080   last_fwd_time = -2.0*INTEREST_PERIODIC;
00081   new_org_counter = 0;
00082 }
00083 
00084 
00085 void Diff_Routing_Entry::clear_outlist(Out_List *list)
00086 {
00087   Out_List *cur=list;
00088   Out_List *temp = NULL;
00089 
00090   while (cur != NULL) {
00091     temp = OUT_NEXT(cur);
00092     delete cur;
00093     cur = temp;
00094   }
00095   
00096 }
00097 
00098 
00099 void Diff_Routing_Entry::clear_inlist(In_List *list)
00100 {
00101   In_List *cur=list;
00102   In_List *temp = NULL;
00103 
00104   while (cur != NULL) {
00105     temp = IN_NEXT(cur);
00106     delete cur;
00107     cur = temp;
00108   }
00109 }
00110 
00111 
00112 
00113 void Diff_Routing_Entry::clear_agentlist(Agent_List *list)
00114 {
00115   Agent_List *cur=list;
00116   Agent_List *temp = NULL;
00117 
00118   while (cur != NULL) {
00119     temp = AGENT_NEXT(cur);
00120     delete cur;
00121     cur = temp;
00122   }
00123 }
00124 
00125 
00126 int Diff_Routing_Entry::MostRecvOrg()
00127 {
00128   In_List *cur;
00129   int     most = 0;
00130 
00131   for (cur=iif; cur!=NULL; cur = IN_NEXT(cur)) {
00132       most = max(most,NEW_ORG_RECV(cur));
00133   }
00134   return most;
00135 }
00136 
00137 
00138 bool Diff_Routing_Entry::ExistOriginalGradient()
00139 {
00140   Out_List *cur_out;
00141 
00142   for (cur_out = active; cur_out!=NULL; cur_out=OUT_NEXT(cur_out)) {
00143     if (GRADIENT(cur_out) == ORIGINAL)
00144       return true;
00145   }
00146 
00147   return false;
00148 }
00149 
00150 
00151 void Diff_Routing_Entry::IncRecvCnt(ns_addr_t agent_addr)
00152 {
00153   PrvCurPtr RetVal;
00154 
00155   counter++;
00156 
00157   RetVal=INTF_FIND(iif, agent_addr);
00158   if (RetVal.cur != NULL) {
00159      TOTAL_RECV(RetVal.cur)++;
00160      return;
00161   } 
00162 
00163   RetVal=INTF_FIND(source, agent_addr);
00164   if (RetVal.cur != NULL)
00165     return;
00166 
00167   // On-demand adding In_List 
00168 
00169   TOTAL_RECV(AddInList(agent_addr))++;
00170 
00171 }
00172 
00173 
00174 void Diff_Routing_Entry::CntPosSend(ns_addr_t agent_addr)
00175 {
00176   PrvCurPtr RetVal;
00177 
00178   RetVal=INTF_FIND(iif, agent_addr);
00179   if (RetVal.cur != NULL) {
00180      NUM_POS_SEND(RetVal.cur)++;
00181      return;
00182   } 
00183 
00184   // On-demand adding In_List 
00185 
00186   In_List *cur_in = AddInList(agent_addr);
00187   NUM_POS_SEND(cur_in)++;
00188 }
00189 
00190 
00191 void Diff_Routing_Entry::CntNeg(ns_addr_t agent_addr)
00192 {
00193   PrvCurPtr RetVal;
00194 
00195   RetVal=INTF_FIND(active, agent_addr);
00196   if (RetVal.cur != NULL) {
00197      NUM_NEG_RECV(RetVal.cur)++;
00198      return;
00199   } 
00200   /*
00201   perror("Hey man. How come you send me the negative reinforment?\n");
00202   exit(-1);
00203   */
00204 }
00205 
00206 
00207 void Diff_Routing_Entry::CntNewSub(ns_addr_t agent_addr)
00208 {
00209   PrvCurPtr RetVal;
00210 
00211   RetVal=INTF_FIND(iif, agent_addr);
00212   if (RetVal.cur != NULL) {
00213      NEW_SUB_RECV(RetVal.cur)++;
00214      TOTAL_NEW_SUB_RECV(RetVal.cur)++;
00215      LAST_TS_NEW_SUB(RetVal.cur) = NOW;
00216      return;
00217   } 
00218 
00219   RetVal=INTF_FIND(source, agent_addr);
00220   if (RetVal.cur != NULL)
00221     return;
00222 
00223   // On-demand adding In_List 
00224 
00225   In_List *cur_in = AddInList(agent_addr);
00226   NEW_SUB_RECV(cur_in)++;
00227   TOTAL_NEW_SUB_RECV(cur_in)++;
00228   LAST_TS_NEW_SUB(cur_in) = NOW;
00229 }
00230 
00231 
00232 void Diff_Routing_Entry::ClrNewSub(ns_addr_t agent_addr)
00233 {
00234   PrvCurPtr RetVal;
00235 
00236   RetVal=INTF_FIND(iif, agent_addr);
00237   if (RetVal.cur != NULL) {
00238      NEW_SUB_RECV(RetVal.cur)= 0;
00239      LAST_TS_NEW_SUB(RetVal.cur) = -1.0;
00240      return;
00241   } 
00242 }
00243 
00244 
00245 void Diff_Routing_Entry::CntNewOrg(ns_addr_t agent_addr)
00246 {
00247   PrvCurPtr RetVal;
00248 
00249   RetVal=INTF_FIND(iif, agent_addr);
00250   if (RetVal.cur != NULL) {
00251      NEW_ORG_RECV(RetVal.cur)++;
00252      TOTAL_NEW_ORG_RECV(RetVal.cur)++;
00253      return;
00254   } 
00255 
00256   RetVal=INTF_FIND(source, agent_addr);
00257   if (RetVal.cur != NULL)
00258     return;
00259 
00260   // On-demand adding In_List 
00261 
00262   In_List *cur_in = AddInList(agent_addr);
00263   NEW_ORG_RECV(cur_in)++;
00264   TOTAL_NEW_ORG_RECV(cur_in)++;
00265 }
00266 
00267 
00268 void Diff_Routing_Entry::CntOldOrg(ns_addr_t agent_addr)
00269 {
00270   PrvCurPtr RetVal;
00271 
00272   RetVal=INTF_FIND(iif, agent_addr);
00273   if (RetVal.cur != NULL) {
00274      OLD_ORG_RECV(RetVal.cur)++;
00275      TOTAL_OLD_ORG_RECV(RetVal.cur)++;
00276      return;
00277   } 
00278 
00279   RetVal=INTF_FIND(source, agent_addr);
00280   if (RetVal.cur != NULL)
00281     return;
00282 
00283   // On-demand adding In_List 
00284 
00285   In_List *cur_in = AddInList(agent_addr);
00286   OLD_ORG_RECV(cur_in)++;
00287   TOTAL_OLD_ORG_RECV(cur_in)++;
00288 }
00289 
00290 
00291 void Diff_Routing_Entry::ClrAllNewOrg()
00292 {
00293   In_List *cur;
00294 
00295   for (cur = iif; cur!= NULL; cur = IN_NEXT(cur)) {
00296      NEW_ORG_RECV(cur)= 0;
00297   }
00298 }
00299 
00300 
00301 void Diff_Routing_Entry::ClrAllOldOrg()
00302 {
00303   In_List *cur;
00304 
00305   for (cur=iif; cur!=NULL; cur = IN_NEXT(cur) ) {
00306      OLD_ORG_RECV(cur)= 0;
00307   }
00308 }
00309 
00310 
00311 In_List *Diff_Routing_Entry::MostRecentIn()
00312 {
00313   In_List *cur, *ret;
00314   double recent_time;
00315 
00316   ret = NULL;
00317   recent_time = -1.0;
00318   for (cur = iif; cur!=NULL; cur=IN_NEXT(cur)) {
00319     if (LAST_TS_NEW_SUB(cur) > recent_time) {
00320       ret = cur;
00321       recent_time = LAST_TS_NEW_SUB(cur);
00322     }
00323   }
00324   return ret;
00325 }
00326 
00327 
00328 In_List * Diff_Routing_Entry::AddInList(ns_addr_t addr)
00329 {
00330   In_List *inPtr= new In_List;
00331 
00332   AGT_ADDR(inPtr) = addr;
00333   INTF_INSERT(iif, inPtr); 
00334 
00335   num_iif++;
00336   return inPtr;
00337 }
00338 
00339 
00340 Diff_Routing_Entry:: Diff_Routing_Entry() 
00341 { 
00342     last_fwd_time = -2.0*INTEREST_PERIODIC;  
00343     counter      = 0;
00344     new_org_counter = 0;
00345     num_active   = 0;
00346     num_iif      = 0;
00347     active       = NULL; 
00348     inactive     = NULL; 
00349     iif          = NULL;
00350     down_iif     = NULL;
00351     source       = NULL;
00352     sink         = NULL;
00353 }
00354 
00355 

Generated on Tue Apr 20 12:14:30 2004 for NS2.26SourcesOriginal by doxygen 1.3.3