BrooseBucket Class Reference

#include <BrooseBucket.h>

List of all members.


Detailed Description

Broose bucket module.

This modul contains the bucket of the Broose implementation.

Author:
Jochen Schenk
See also:
Broose


Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual void add (BrooseHandle node)
 adds a broose node handle to the bucket
virtual void remove (BrooseHandle node)
 removes a broose node handle from the bucket
virtual const BrooseHandleget (uint pos=0)
 returns a specific broose handle
virtual const OverlayKeygetDist (uint pos=0)
 returns distance of a specific broose handle
virtual void initializeBucket (int shiftingBits, uint prefix, BrooseHandle node, int size)
 initializes a bucket
virtual uint getSize ()
 returns number of current entries
virtual uint getMaxSize ()
 returns number of maximal entries
virtual bool isEmpty ()
 checks if the bucket is empty
virtual void clear ()
 removes all entries from the bucket
virtual BrooseHandle getClosestNode (const OverlayKey &destKey)
 returns the closest node to a specific key
virtual int longestPrefix (void)
 return the longest prefix of all entries
virtual bool keyInRange (const OverlayKey &key)
 checks if the key close to the owner's id
virtual bool nodeInBucket (const BrooseHandle &node)
 checks if a node is already in the bucket
virtual int getFailedResponses (const BrooseHandle &node)
 returns the number of failed responses to a specific broose handle
virtual void increaseFailedResponses (const BrooseHandle &node)
 increase the number of failed responses to a specific broose handle
virtual void resetFailedResponses (const BrooseHandle &node)
 resets the counter of failed responses to a specific broose handle
virtual void setRTT (BrooseHandle node, simtime_t rpcRTT)
 sets the round trip time to a specific broose handle
virtual simtime_t getRTT (BrooseHandle node)
 returns the round trip time to a specific broose handle
virtual void setLastSeen (BrooseHandle node, simtime_t lastSeen)
 updates the timestamp of a specific node
virtual simtime_t getLastSeen (BrooseHandle node)
 returns the timestamp of a specific node
void output (int maxEntries=0)
 displays the content of the bucket on standard out
void binaryOutput (const OverlayKey &key)
 displays a key in binary form

Protected Member Functions

void test ()

Protected Attributes

std::map< const OverlayKey,
BrooseHandle
bucket
 data structure representing the bucket
std::map< const OverlayKey,
BrooseHandle >::iterator 
bucketIter
 iterator to navigate through the bucket
unsigned int maxSize
 maximal size of the bucket
BrooseHandle thisNode
 node handle to the node managing this bucket
OverlayKey key
 the node's key shifted to fit the bucket and used to measure distance to other keys
int bits
 number of bits the node's key has to be shifted to fit the apropriate bucket


Member Function Documentation

void BrooseBucket::add ( BrooseHandle  node  )  [virtual]

adds a broose node handle to the bucket

Parameters:
node broose handle which will be added
00068 {
00069     OverlayKey tmp = key ^ node.key;
00070     if (bucket.size() < maxSize) {
00071         bucket.insert(make_pair(tmp,node)).second;
00072     } else {
00073         if (bucket.find(tmp) == bucket.end()) {
00074             bucketIter = bucket.end();
00075             bucketIter--;
00076 
00077             // is the new node closer than the one farthest away,
00078             // remove the one and add the other
00079 
00080             if (bucketIter->first > tmp) {
00081                 bucket.erase(bucketIter);
00082                 bucket.insert(make_pair(tmp,node));
00083             }
00084         }
00085     }
00086 
00087 }

void BrooseBucket::binaryOutput ( const OverlayKey key  ) 

displays a key in binary form

Parameters:
key key which is displayed
00326 {
00327     if(key.isUnspecified())
00328         cout << "<unspec>";
00329     else {
00330         for (unsigned int i = 1; i <= key.getLength(); i++)
00331             cout << key.bitAtPlace(i);
00332     }
00333 }

void BrooseBucket::clear (  )  [virtual]

removes all entries from the bucket

00150 {
00151     bucket.clear();
00152 }

const BrooseHandle & BrooseBucket::get ( uint  pos = 0  )  [virtual]

returns a specific broose handle

Parameters:
pos position of the broose handle in the bucket
00102 {
00103     if (pos > bucket.size()) {
00104         error("Index out of bounds(BrooseBucket).");
00105     }
00106 
00107     uint i = 0;
00108     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++){
00109         if (pos == i) {
00110             return bucketIter->second;
00111         }
00112         i++;
00113     }
00114     return BrooseHandle::UNSPECIFIED_NODE;
00115 }

BrooseHandle BrooseBucket::getClosestNode ( const OverlayKey destKey  )  [virtual]

returns the closest node to a specific key

Parameters:
destKey key to compare
Returns:
broose handle of closest node
00155 {
00156     BrooseHandle closestNode;
00157     OverlayKey lastDist = OverlayKey::max();
00158     OverlayKey dist;
00159 
00160     if (bucket.empty()) {
00161         EV << "--- BUCKET EMPTY ---" << endl;
00162     }
00163 
00164     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00165         dist = bucketIter->second.key ^ destKey;
00166         if (dist < lastDist) {
00167             closestNode = bucketIter->second;
00168             lastDist = dist;
00169         }
00170     }
00171     return closestNode;
00172 }

const OverlayKey & BrooseBucket::getDist ( uint  pos = 0  )  [virtual]

returns distance of a specific broose handle

Parameters:
pos position of the broose handle in the bucket
00118 {
00119     if(pos > bucket.size()) {
00120         error("Index out of bounds(BrooseBucket).");
00121     }
00122 
00123     uint i = 0;
00124     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++){
00125         if (pos == i) {
00126             return bucketIter->first;
00127         }
00128         i++;
00129     }
00130     return OverlayKey::UNSPECIFIED_KEY;
00131 }

int BrooseBucket::getFailedResponses ( const BrooseHandle node  )  [virtual]

returns the number of failed responses to a specific broose handle

Parameters:
node broose handle to check
Returns:
number of failed responses
00265 {
00266     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00267         if (node == bucketIter->second)
00268             return bucketIter->second.failedResponses;
00269     }
00270     return -1;
00271 }

simtime_t BrooseBucket::getLastSeen ( BrooseHandle  node  )  [virtual]

returns the timestamp of a specific node

Parameters:
node broose handle to which the timestamp will be retrieved
Returns:
the retrieved timestamp
00317 {
00318     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00319         if (node == bucketIter->second)
00320             return bucketIter->second.lastSeen;
00321     }
00322     return -2;
00323 }

uint BrooseBucket::getMaxSize (  )  [virtual]

returns number of maximal entries

Returns:
number of maximal entries
00140 {
00141     return maxSize;
00142 }

simtime_t BrooseBucket::getRTT ( BrooseHandle  node  )  [virtual]

returns the round trip time to a specific broose handle

Parameters:
node broose handle to which the rtt will be retrieved
Returns:
rtt to the specific node
00300 {
00301     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00302         if (node == bucketIter->second)
00303             return bucketIter->second.rtt;
00304     }
00305     return -2;
00306 }

uint BrooseBucket::getSize (  )  [virtual]

returns number of current entries

Returns:
number of current entries
00135 {
00136     return bucket.size();
00137 }

void BrooseBucket::handleMessage ( cMessage *  msg  )  [virtual]

00042 {
00043     error("BrooseBucket::handleMessage() shouldn't be called!");
00044 }

void BrooseBucket::increaseFailedResponses ( const BrooseHandle node  )  [virtual]

increase the number of failed responses to a specific broose handle

Parameters:
node broose handle which counter will be increased
00274 {
00275     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00276         if (node == bucketIter->second)
00277             bucketIter->second.failedResponses++;
00278     }
00279 }

void BrooseBucket::initialize ( int  stage  )  [virtual]

00034 {
00035     // because of IPAddressResolver, we need to wait until interfaces
00036     // are registered, address auto-assignment takes place etc.
00037     if (stage != 5)
00038         return;
00039 }

void BrooseBucket::initializeBucket ( int  shiftingBits,
uint  prefix,
BrooseHandle  node,
int  size 
) [virtual]

initializes a bucket

Parameters:
shiftingBits specifies the kind of the bucket
prefix in case of a R bucket specifies the prefix
node broose handle to the node which owns this bucket
size maximal size of the bucket
00048 {
00049     maxSize = size;
00050     thisNode = node;
00051     bits = shiftingBits;
00052 
00053     if (shiftingBits < 0) {
00054         key = thisNode.key << -shiftingBits;
00055     } else {
00056         key = thisNode.key >> shiftingBits;
00057     }
00058 
00059     if (prefix != 0) {
00060         OverlayKey tmp(prefix); // constraint
00061         tmp = tmp << (thisNode.key.getLength() - shiftingBits);
00062         key = key + tmp;
00063     }
00064     bucket.clear();
00065 }

bool BrooseBucket::isEmpty (  )  [virtual]

checks if the bucket is empty

Returns:
true if the bucket is empty
00145 {
00146     return bucket.empty();
00147 }

bool BrooseBucket::keyInRange ( const OverlayKey key  )  [virtual]

checks if the key close to the owner's id

Parameters:
key key to check
Returns:
true if node is close
00233 {
00234     OverlayKey dist;
00235 
00236     if (bucket.size() == 0)
00237         return false;
00238 
00239     // check if the function was called to perform on a B bucket
00240     if (bits == 0) {
00241         if (bucket.size() <=  (maxSize / 7))
00242             dist = OverlayKey::max();
00243         else
00244             dist = getDist((maxSize / 7) - 1);
00245     } else
00246         dist = getDist(bucket.size()-1);
00247 
00248     if ((key ^ thisNode.key) <= dist)
00249         return true;
00250     else
00251         return false;
00252 
00253 }

int BrooseBucket::longestPrefix ( void   )  [virtual]

return the longest prefix of all entries

Returns:
the longest prefix
00175 {
00176     int bits = 0;
00177     int maxBits = MAXBITS;
00178     int tmp = 0;
00179     BrooseHandle node1, node2;
00180 
00181     if (bucket.size() <= 1)
00182         return 0;
00183 
00184     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); ++bucketIter){
00185         tmp = 0;
00186         node1 = bucketIter->second;
00187         ++bucketIter;
00188 
00189         if (bucketIter != bucket.end()) {
00190             node2 = bucketIter->second;
00191             --bucketIter;
00192 
00193             for (uint i = 1; i <= node1.key.getLength(); i++) {
00194                 if (node1.key.bitAtPlace(i) == node2.key.bitAtPlace(i))
00195                     tmp++;
00196                 else
00197                     break;
00198             }
00199 
00200             if (tmp < maxBits) {
00201                 bits = tmp;
00202                 maxBits = tmp;
00203             }
00204         } else {
00205             --bucketIter;
00206         }
00207     }
00208     return bits;
00209 }

bool BrooseBucket::nodeInBucket ( const BrooseHandle node  )  [virtual]

checks if a node is already in the bucket

Parameters:
node broose handle to check
Returns:
true if node is already in the bucket
00256 {
00257     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00258         if (node == bucketIter->second)
00259             return true;
00260     }
00261     return false;
00262 }

virtual int BrooseBucket::numInitStages (  )  const [inline, virtual]

00046     {
00047         return 6;
00048     }

void BrooseBucket::output ( int  maxEntries = 0  ) 

displays the content of the bucket on standard out

Parameters:
maxEntries the maximal number of entries which will be printed
00212 {
00213     EV << "(" << bucket.size() << "/" << maxSize <<")" << endl;
00214     BrooseHandle node;
00215     OverlayKey dist;
00216 
00217     int max;
00218     max = bucket.size();
00219     if (maxEntries != 0 && maxEntries < max) {
00220         max = maxEntries;
00221     }
00222     int i;
00223 
00224     for (bucketIter = bucket.begin(), i = 0; i < max; bucketIter++, i++) {
00225         dist = bucketIter->first;
00226         node = bucketIter->second;
00227         EV << dist << " " << node.key << " " << node.ip << " RTT: "
00228            << node.rtt << " LS: " << node.lastSeen << endl;
00229     }
00230 }

void BrooseBucket::remove ( BrooseHandle  node  )  [virtual]

removes a broose node handle from the bucket

Parameters:
node broose handle which will be removed
00090 {
00091     for (bucketIter = bucket.begin(); bucketIter != bucket.end();) {
00092         if (bucketIter->second == node)
00093             bucket.erase(bucketIter++);
00094         else
00095             ++bucketIter;
00096     }
00097 }

void BrooseBucket::resetFailedResponses ( const BrooseHandle node  )  [virtual]

resets the counter of failed responses to a specific broose handle

Parameters:
node broose handle which counter will be reset
00282 {
00283     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00284         if (node == bucketIter->second)
00285             bucketIter->second.failedResponses = 0;
00286     }
00287 }

void BrooseBucket::setLastSeen ( BrooseHandle  node,
simtime_t  lastSeen 
) [virtual]

updates the timestamp of a specific node

Parameters:
node broose handle to which the timestamp will be updated
lastSeen timestamp of the last message
00309 {
00310     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00311         if (node == bucketIter->second)
00312             bucketIter->second.lastSeen = time;
00313     }
00314 }

void BrooseBucket::setRTT ( BrooseHandle  node,
simtime_t  rpcRTT 
) [virtual]

sets the round trip time to a specific broose handle

Parameters:
node broose handle to which the rtt will be stored
rpcRTT rtt to the specific node
00291 {
00292     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00293         if (node == bucketIter->second) {
00294             bucketIter->second.rtt = rpcRTT;
00295         }
00296     }
00297 }

void BrooseBucket::test (  )  [protected]


Member Data Documentation

int BrooseBucket::bits [protected]

number of bits the node's key has to be shifted to fit the apropriate bucket

std::map<const OverlayKey, BrooseHandle> BrooseBucket::bucket [protected]

data structure representing the bucket

std::map<const OverlayKey, BrooseHandle>::iterator BrooseBucket::bucketIter [protected]

iterator to navigate through the bucket

OverlayKey BrooseBucket::key [protected]

the node's key shifted to fit the bucket and used to measure distance to other keys

unsigned int BrooseBucket::maxSize [protected]

maximal size of the bucket

BrooseHandle BrooseBucket::thisNode [protected]

node handle to the node managing this bucket


The documentation for this class was generated from the following files:
Generated on Fri May 11 14:52:39 2007 for ITM OverSim by  doxygen 1.4.7