routing_table.cc

Go to the documentation of this file.
00001 
00002 /*
00003  * routing_table.cc
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: routing_table.cc,v 1.5 2005/08/25 18:58:04 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 /********************************************************************/
00048 /* routing_table.cc : Chalermek Intanagonwiwat (USC/ISI)  05/18/99  */
00049 /********************************************************************/
00050 
00051 // Important Note: Work still in progress !
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   // On-demand adding In_List 
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   // On-demand adding In_List 
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   perror("Hey man. How come you send me the negative reinforment?\n");
00223   exit(-1);
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   // On-demand adding In_List 
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   // On-demand adding In_List 
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   // On-demand adding In_List 
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 

Generated on Tue Mar 6 16:47:50 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6