Cache Class Reference

Collaboration diagram for Cache:

Collaboration graph
[legend]

Detailed Description

Definition at line 97 of file mobicache.cc.

Public Member Functions

PathaddRoute (Path &route, int &prefix_len)
 Cache (char *name, int size, MobiCache *rtcache)
void noticeDeadLink (const ID &from, const ID &to)
int pickVictim (int exclude=-1)
bool searchRoute (const ID &dest, int &i, Path &path, int &index)
 ~Cache ()

Private Attributes

Pathcache
char * name
MobiCacheroutecache
int size
int victim_ptr

Friends

class MobiCache


Constructor & Destructor Documentation

Cache::Cache char *  name,
int  size,
MobiCache rtcache
 

Definition at line 481 of file mobicache.cc.

References cache, routecache, and victim_ptr.

00482 {
00483   this->name = name;
00484   this->size = size;
00485   cache = new Path[size];
00486   routecache = rtcache;
00487   victim_ptr = 0;
00488 }

Cache::~Cache  ) 
 

Definition at line 490 of file mobicache.cc.

References cache.

00491 {
00492   delete[] cache;
00493 }


Member Function Documentation

Path * Cache::addRoute Path route,
int &  prefix_len
 

Definition at line 512 of file mobicache.cc.

References cache, Path::length(), and size.

Referenced by MobiCache::addRoute(), and MobiCache::noticeRouteUsed().

00513 {
00514   int index, m, n;
00515   int victim;
00516 
00517   // see if this route is already in the cache
00518   for (index = 0 ; index < size ; index++)
00519     { // for all paths in the cache
00520       for (n = 0 ; n < cache[index].length() ; n ++)
00521     { // for all nodes in the path
00522       if (n >= path.length()) break;
00523       if (cache[index][n] != path[n]) break;
00524     }
00525       if (n == cache[index].length()) 
00526     { // new rt completely contains cache[index] (or cache[index] is empty)
00527           common_prefix_len = n;
00528           for ( ; n < path.length() ; n++)
00529             cache[index].appendToPath(path[n]);
00530       if (verbose_debug)
00531         routecache->trace("SRC %.9f _%s_ %s suffix-rule (len %d/%d) %s",
00532           Scheduler::instance().clock(), routecache->net_id.dump(),
00533               name, n, path.length(), path.dump()); 
00534       goto done;
00535     }
00536       else if (n == path.length())
00537     { // new route already contained in the cache
00538           common_prefix_len = n;
00539       if (verbose_debug)
00540         routecache->trace("SRC %.9f _%s_ %s prefix-rule (len %d/%d) %s",
00541           Scheduler::instance().clock(), routecache->net_id.dump(),
00542           name, n, cache[index].length(), cache[index].dump()); 
00543       goto done;
00544     }
00545       else 
00546     { // keep looking at the rest of the cache 
00547     }
00548     } 
00549 
00550   // there are some new goodies in the new route
00551   victim = pickVictim();
00552   if(verbose_debug) {
00553     routecache->trace("SRC %.9f _%s_ %s evicting %s",
00554               Scheduler::instance().clock(), routecache->net_id.dump(),
00555               name, cache[victim].dump());  
00556     routecache->trace("SRC %.9f _%s_ while adding %s",
00557               Scheduler::instance().clock(), routecache->net_id.dump(),
00558               path.dump()); 
00559   }
00560   cache[victim].reset();
00561   CopyIntoPath(cache[victim], path, 0, path.length() - 1);
00562   common_prefix_len = 0;
00563   index = victim; // remember which cache line we stuck the path into
00564 
00565 done:
00566 
00567 #ifdef DEBUG
00568   {
00569     Path &p = path;
00570     int c;
00571     char buf[1000];
00572     char *ptr = buf;
00573     ptr += sprintf(buf,"Sdebug %.9f _%s_ adding ", 
00574            Scheduler::instance().clock(), routecache->net_id.dump());
00575     for (c = 0 ; c < p.length(); c++)
00576       ptr += sprintf(ptr,"%s [%d %.9f] ",p[c].dump(), p[c].link_type, p[c].t);
00577     routecache->trace(buf);
00578   }
00579 #endif //DEBUG
00580 
00581   // freshen all the timestamps on the links in the cache
00582   for (m = 0 ; m < size ; m++)
00583     { // for all paths in the cache
00584 
00585 #ifdef DEBUG
00586   {
00587     if (cache[m].length() == 0) continue;
00588 
00589     Path &p = cache[m];
00590     int c;
00591     char buf[1000];
00592     char *ptr = buf;
00593     ptr += sprintf(buf,"Sdebug %.9f _%s_ checking ", 
00594            Scheduler::instance().clock(), routecache->net_id.dump());
00595     for (c = 0 ; c < p.length(); c++)
00596       ptr += sprintf(ptr,"%s [%d %.9f] ",p[c].dump(), p[c].link_type, p[c].t);
00597     routecache->trace(buf);
00598   }
00599 #endif //DEBUG
00600       
00601       for (n = 0 ; n < cache[m].length() - 1 ; n ++)
00602     { // for all nodes in the path
00603       if (n >= path.length() - 1) break;
00604       if (cache[m][n] != path[n]) break;
00605       if (cache[m][n+1] == path[n+1])
00606         { // freshen the timestamps and type of the link          
00607 
00608 #ifdef DEBUG
00609 routecache->trace("Sdebug %.9f _%s_ freshening %s->%s to %d %.9f",
00610           Scheduler::instance().clock(), routecache->net_id.dump(),
00611           path[n].dump(), path[n+1].dump(), path[n].link_type,
00612           path[n].t);
00613 #endif //DEBUG
00614 
00615           cache[m][n].t = path[n].t;
00616           cache[m][n].link_type = path[n].link_type;
00617           /* NOTE: we don't check to see if we're turning a TESTED
00618          into an UNTESTED link.  Last change made rules -dam 5/19/98 */
00619         }
00620     }
00621     }
00622   return &cache[index];
00623 }

Here is the call graph for this function:

void Cache::noticeDeadLink const ID from,
const ID to
 

Definition at line 627 of file mobicache.cc.

References ACTION_CHECK_CACHE, ACTION_DEAD_LINK, cache, Path::dump(), ID::dump(), Scheduler::instance(), Path::length(), LS_UNLOGGED, name, RouteCache::net_id, Path::owner(), Path::reset(), routecache, Path::setLength(), RouteCache::trace(), and verbose_debug.

Referenced by MobiCache::noticeDeadLink().

00630 {  
00631   for (int p = 0 ; p < size ; p++)
00632     { // for all paths in the cache
00633       for (int n = 0 ; n < (cache[p].length()-1) ; n ++)
00634     { // for all nodes in the path
00635       if (cache[p][n] == from && cache[p][n+1] == to)
00636         {
00637           if(verbose_debug)
00638         routecache->trace("SRC %.9f _%s_ %s truncating %s %s",
00639                                   Scheduler::instance().clock(),
00640                                   routecache->net_id.dump(),
00641                                   name, cache[p].dump(),
00642                                   cache[p].owner().dump());
00643 #ifdef DSR_CACHE_STATS
00644               routecache->checkRoute(&cache[p], ACTION_CHECK_CACHE, 0);
00645               routecache->checkRoute_logall(&cache[p], ACTION_DEAD_LINK, n);
00646 #endif        
00647           if (n == 0)
00648         cache[p].reset();        // kill the whole path
00649           else {
00650         cache[p].setLength(n+1); // truncate the path here
00651                 cache[p][n].log_stat = LS_UNLOGGED;
00652               }
00653 
00654           if(verbose_debug)
00655         routecache->trace("SRC %.9f _%s_ to %s %s",
00656               Scheduler::instance().clock(), routecache->net_id.dump(),
00657               cache[p].dump(), cache[p].owner().dump());
00658 
00659           break;
00660         } // end if this is a dead link
00661     } // end for all nodes
00662     } // end for all paths
00663   return;
00664 }

Here is the call graph for this function:

int Cache::pickVictim int  exclude = -1  ) 
 

Definition at line 667 of file mobicache.cc.

References cache, size, and victim_ptr.

00670 {
00671   for(int c = 0; c < size ; c++)
00672     if (cache[c].length() == 0) return c;
00673   
00674   int victim = victim_ptr;
00675   while (victim == exclude)
00676     {
00677       victim_ptr = (victim_ptr+1 == size) ? 0 : victim_ptr+1;
00678       victim = victim_ptr;
00679     }
00680   victim_ptr = (victim_ptr+1 == size) ? 0 : victim_ptr+1;
00681 
00682 #ifdef DSR_CACHE_STATS
00683   routecache->checkRoute(&cache[victim], ACTION_CHECK_CACHE, 0);
00684   int bad = routecache->checkRoute_logall(&cache[victim], ACTION_EVICT, 0);
00685   routecache->trace("SRC %.9f _%s_ evicting %d %d %s",
00686                     Scheduler::instance().clock(), routecache->net_id.dump(),
00687                     cache[victim].length() - 1, bad, name);
00688 #endif
00689   return victim;
00690 }

bool Cache::searchRoute const ID dest,
int &  i,
Path path,
int &  index
 

Definition at line 496 of file mobicache.cc.

References cache, Path::length(), and size.

Referenced by MobiCache::findRoute().

00499 {
00500   for (; index < size; index++)
00501     for (int n = 0 ; n < cache[index].length(); n++)
00502       if (cache[index][n] == dest) 
00503     {
00504       i = n;
00505       path = cache[index];
00506       return true;
00507     }
00508   return false;
00509 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class MobiCache [friend]
 

Definition at line 98 of file mobicache.cc.


Field Documentation

Path* Cache::cache [private]
 

Definition at line 117 of file mobicache.cc.

Referenced by addRoute(), Cache(), noticeDeadLink(), pickVictim(), searchRoute(), and ~Cache().

char* Cache::name [private]
 

Definition at line 121 of file mobicache.cc.

Referenced by noticeDeadLink().

MobiCache* Cache::routecache [private]
 

Definition at line 120 of file mobicache.cc.

Referenced by Cache(), and noticeDeadLink().

int Cache::size [private]
 

Definition at line 118 of file mobicache.cc.

Referenced by addRoute(), pickVictim(), and searchRoute().

int Cache::victim_ptr [private]
 

Definition at line 119 of file mobicache.cc.

Referenced by Cache(), and pickVictim().


The documentation for this class was generated from the following file:
Generated on Tue Mar 6 17:04:07 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6