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

Cache Class Reference

Collaboration diagram for Cache:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Private Attributes

Pathcache
int size
int victim_ptr
MobiCacheroutecache
char * name

Friends

class MobiCache

Constructor & Destructor Documentation

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

Definition at line 456 of file mobicache.cc.

References cache, routecache, and victim_ptr.

00457 {
00458   this->name = name;
00459   this->size = size;
00460   cache = new Path[size];
00461   routecache = rtcache;
00462   victim_ptr = 0;
00463 }

Cache::~Cache  ) 
 

Definition at line 465 of file mobicache.cc.

References cache.

00466 {
00467   delete[] cache;
00468 }


Member Function Documentation

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

Definition at line 487 of file mobicache.cc.

References cache, CopyIntoPath(), Path::dump(), ID::dump(), Scheduler::instance(), Path::length(), name, RouteCache::net_id, pickVictim(), Path::reset(), routecache, size, RouteCache::trace(), and verbose_debug.

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

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

Here is the call graph for this function:

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

Definition at line 602 of file mobicache.cc.

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

Referenced by MobiCache::noticeDeadLink().

00605 {  
00606   for (int p = 0 ; p < size ; p++)
00607     { // for all paths in the cache
00608       for (int n = 0 ; n < (cache[p].length()-1) ; n ++)
00609         { // for all nodes in the path
00610           if (cache[p][n] == from && cache[p][n+1] == to)
00611             {
00612               if(verbose_debug)
00613                 routecache->trace("SRC %.9f _%s_ %s truncating %s %s",
00614                                   Scheduler::instance().clock(),
00615                                   routecache->net_id.dump(),
00616                                   name, cache[p].dump(),
00617                                   cache[p].owner().dump());
00618 #ifdef DSR_CACHE_STATS
00619               routecache->checkRoute(&cache[p], ACTION_CHECK_CACHE, 0);
00620               routecache->checkRoute_logall(&cache[p], ACTION_DEAD_LINK, n);
00621 #endif        
00622               if (n == 0)
00623                 cache[p].reset();        // kill the whole path
00624               else {
00625                 cache[p].setLength(n+1); // truncate the path here
00626                 cache[p][n].log_stat = LS_UNLOGGED;
00627               }
00628 
00629               if(verbose_debug)
00630                 routecache->trace("SRC %.9f _%s_ to %s %s",
00631                       Scheduler::instance().clock(), routecache->net_id.dump(),
00632                       cache[p].dump(), cache[p].owner().dump());
00633 
00634               break;
00635             } // end if this is a dead link
00636         } // end for all nodes
00637     } // end for all paths
00638   return;
00639 }

Here is the call graph for this function:

int Cache::pickVictim int  exclude = -1  ) 
 

Definition at line 642 of file mobicache.cc.

References ACTION_CHECK_CACHE, ACTION_EVICT, cache, ID::dump(), Scheduler::instance(), Path::length(), name, RouteCache::net_id, routecache, size, RouteCache::trace(), and victim_ptr.

Referenced by addRoute().

00645 {
00646   for(int c = 0; c < size ; c++)
00647     if (cache[c].length() == 0) return c;
00648   
00649   int victim = victim_ptr;
00650   while (victim == exclude)
00651     {
00652       victim_ptr = (victim_ptr+1 == size) ? 0 : victim_ptr+1;
00653       victim = victim_ptr;
00654     }
00655   victim_ptr = (victim_ptr+1 == size) ? 0 : victim_ptr+1;
00656 
00657 #ifdef DSR_CACHE_STATS
00658   routecache->checkRoute(&cache[victim], ACTION_CHECK_CACHE, 0);
00659   int bad = routecache->checkRoute_logall(&cache[victim], ACTION_EVICT, 0);
00660   routecache->trace("SRC %.9f _%s_ evicting %d %d %s",
00661                     Scheduler::instance().clock(), routecache->net_id.dump(),
00662                     cache[victim].length() - 1, bad, name);
00663 #endif
00664   return victim;
00665 }

Here is the call graph for this function:

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

Definition at line 471 of file mobicache.cc.

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

Referenced by MobiCache::findRoute().

00474 {
00475   for (; index < size; index++)
00476     for (int n = 0 ; n < cache[index].length(); n++)
00477       if (cache[index][n] == dest) 
00478         {
00479           i = n;
00480           path = cache[index];
00481           return true;
00482         }
00483   return false;
00484 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class MobiCache [friend]
 

Definition at line 73 of file mobicache.cc.


Member Data Documentation

Path* Cache::cache [private]
 

Definition at line 92 of file mobicache.cc.

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

char* Cache::name [private]
 

Definition at line 96 of file mobicache.cc.

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

MobiCache* Cache::routecache [private]
 

Definition at line 95 of file mobicache.cc.

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

int Cache::size [private]
 

Definition at line 93 of file mobicache.cc.

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

int Cache::victim_ptr [private]
 

Definition at line 94 of file mobicache.cc.

Referenced by Cache(), and pickVictim().


The documentation for this class was generated from the following file:
Generated on Tue Apr 20 12:35:10 2004 for NS2.26SourcesOriginal by doxygen 1.3.3