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

requesttable.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 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00026 
00027 /* requesttable.h
00028 
00029    implement a table to keep track of the most current request
00030    number we've heard from a node in terms of that node's id
00031 
00032 */
00033 
00034 #include "path.h"
00035 #include "constants.h"
00036 #include "requesttable.h"
00037 
00038 RequestTable::RequestTable(int s): size(s)
00039 {
00040   table = new Entry[size];
00041   size = size;
00042   ptr = 0;
00043 }
00044 
00045 RequestTable::~RequestTable()
00046 {
00047   delete[] table;
00048 }
00049 
00050 int
00051 RequestTable::find(const ID& net_id, const ID& MAC_id) const
00052 {
00053   for (int c = 0 ; c < size ; c++)
00054           if (table[c].net_id == net_id || table[c].MAC_id == MAC_id)
00055                   return c;
00056   return size;
00057 }
00058 
00059 int
00060 RequestTable::get(const ID& id) const
00061 {
00062   int existing_entry = find(id, id);
00063 
00064   if (existing_entry >= size)    
00065     {
00066       return 0;
00067     }
00068   return table[existing_entry].req_num;
00069 }
00070 
00071 
00072 Entry*
00073 RequestTable::getEntry(const ID& id)
00074 {
00075   int existing_entry = find(id, id);
00076 
00077   if (existing_entry >= size)    
00078     {
00079       table[ptr].MAC_id = ::invalid_addr;
00080       table[ptr].net_id = id;
00081       table[ptr].req_num = 0;
00082       table[ptr].last_arp = 0.0;
00083       table[ptr].rt_reqs_outstanding = 0;
00084       table[ptr].last_rt_req = -(rt_rq_period + 1.0);
00085       existing_entry = ptr;
00086       ptr = (ptr+1)%size;
00087     }
00088   return &(table[existing_entry]);
00089 }
00090 
00091 void
00092 RequestTable::insert(const ID& net_id, int req_num)
00093 {
00094   insert(net_id,::invalid_addr,req_num);
00095 }
00096 
00097 
00098 void
00099 RequestTable::insert(const ID& net_id, const ID& MAC_id, int req_num)
00100 {
00101   int existing_entry = find(net_id, MAC_id);
00102 
00103   if (existing_entry < size)
00104     {
00105       if (table[existing_entry].MAC_id == ::invalid_addr)
00106         table[existing_entry].MAC_id = MAC_id; // handle creations by getEntry
00107       table[existing_entry].req_num = req_num;
00108       return;
00109     }
00110 
00111   // otherwise add it in
00112   table[ptr].MAC_id = MAC_id;
00113   table[ptr].net_id = net_id;
00114   table[ptr].req_num = req_num;
00115   table[ptr].last_arp = 0.0;
00116   table[ptr].rt_reqs_outstanding = 0;
00117   table[ptr].last_rt_req = -(rt_rq_period + 1.0);
00118   ptr = (ptr+1)%size;
00119 }

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