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
BrooseHandle
get (uint pos=0)
 returns a specific broose handle
virtual const
OverlayKey
getDist (uint pos=0)
 returns distance of a specific broose handle
virtual void initializeBucket (int shiftingBits, uint prefix, BrooseHandle node, int size, Broose *overlay, bool isBBucket=false)
 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< OverlayKey,
BrooseHandle
bucket
 data structure representing the bucket
std::map< 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
Brooseoverlay
 pointer to the main Broose module
bool isBBucket
 true, if this bucket is the node's BBucket

Member Function Documentation

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

00048     {
00049         return 6;
00050     }

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 
00040     WATCH_MAP(bucket);
00041 
00042 }

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

00045 {
00046     error("BrooseBucket::handleMessage() shouldn't be called!");
00047 }

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

adds a broose node handle to the bucket

Parameters:
node broose handle which will be added
00074 {
00075     OverlayKey tmp = key ^ node.key;
00076     if (bucket.size() < maxSize) {
00077         if (bucket.insert(make_pair(tmp,node)).second) {
00078             if (isBBucket) {
00079                 overlay->callUpdate(node, true);
00080             }
00081         }
00082     } else {
00083         if (bucket.find(tmp) == bucket.end()) {
00084             bucketIter = bucket.end();
00085             bucketIter--;
00086 
00087             // is the new node closer than the one farthest away,
00088             // remove the one and add the other
00089 
00090             if (bucketIter->first > tmp) {
00091                 if (isBBucket) {
00092                     overlay->callUpdate(bucketIter->second, false);
00093                 }
00094                 bucket.erase(bucketIter);
00095                 if (bucket.insert(make_pair(tmp,node)).second) {
00096                     if (isBBucket) {
00097                         overlay->callUpdate(node, true);
00098                     }
00099                 }
00100             }
00101         }
00102     }
00103 
00104 }

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

removes a broose node handle from the bucket

Parameters:
node broose handle which will be removed
00107 {
00108     for (bucketIter = bucket.begin(); bucketIter != bucket.end();) {
00109         if (bucketIter->second.ip == node.ip) {
00110             if (isBBucket) {
00111                 overlay->callUpdate(node, false);
00112             }
00113             bucket.erase(bucketIter++);
00114         } else {
00115             ++bucketIter;
00116         }
00117     }
00118 }

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

returns a specific broose handle

Parameters:
pos position of the broose handle in the bucket
00123 {
00124     if (pos > bucket.size()) {
00125         error("Index out of bounds(BrooseBucket).");
00126     }
00127 
00128     uint i = 0;
00129     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++) {
00130         if (pos == i) {
00131             return bucketIter->second;
00132         }
00133         i++;
00134     }
00135     return BrooseHandle::UNSPECIFIED_NODE;
00136 }

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
00139 {
00140     if(pos > bucket.size()) {
00141         error("Index out of bounds(BrooseBucket).");
00142     }
00143 
00144     uint i = 0;
00145     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++) {
00146         if (pos == i) {
00147             return bucketIter->first;
00148         }
00149         i++;
00150     }
00151     return OverlayKey::UNSPECIFIED_KEY;
00152 }

void BrooseBucket::initializeBucket ( int  shiftingBits,
uint  prefix,
BrooseHandle  node,
int  size,
Broose overlay,
bool  isBBucket = false 
) [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
overlay pointer to the main Broose module
isBBucket true, is this bucket is the node's BBucket
00052 {
00053     maxSize = size;
00054     thisNode = node;
00055     bits = shiftingBits;
00056     this->overlay = overlay;
00057     this->isBBucket = isBBucket;
00058 
00059     if (shiftingBits < 0) {
00060         key = thisNode.key << -shiftingBits;
00061     } else {
00062         key = thisNode.key >> shiftingBits;
00063     }
00064 
00065     if (prefix != 0) {
00066         OverlayKey tmp(prefix); // constraint
00067         tmp = tmp << (thisNode.key.getLength() - shiftingBits);
00068         key = key + tmp;
00069     }
00070     bucket.clear();
00071 }

uint BrooseBucket::getSize (  )  [virtual]

returns number of current entries

Returns:
number of current entries
00156 {
00157     return bucket.size();
00158 }

uint BrooseBucket::getMaxSize (  )  [virtual]

returns number of maximal entries

Returns:
number of maximal entries
00161 {
00162     return maxSize;
00163 }

bool BrooseBucket::isEmpty (  )  [virtual]

checks if the bucket is empty

Returns:
true if the bucket is empty
00166 {
00167     return bucket.empty();
00168 }

void BrooseBucket::clear (  )  [virtual]

removes all entries from the bucket

00171 {
00172     bucket.clear();
00173 }

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
00176 {
00177     BrooseHandle closestNode;
00178     OverlayKey lastDist = OverlayKey::max();
00179     OverlayKey dist;
00180 
00181     if (bucket.empty()) {
00182         EV << "[BrooseBucket::getClosestNode() @ " << thisNode.ip
00183         << " (" << thisNode.key.toString(16) << ")]\n"
00184         << "    BUCKET EMPTY"
00185         << endl;
00186     }
00187 
00188     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00189         dist = bucketIter->second.key ^ destKey;
00190         if (dist < lastDist) {
00191             closestNode = bucketIter->second;
00192             lastDist = dist;
00193         }
00194     }
00195     return closestNode;
00196 }

int BrooseBucket::longestPrefix ( void   )  [virtual]

return the longest prefix of all entries

Returns:
the longest prefix
00199 {
00200     int bits = 0;
00201     int maxBits = MAXBITS;
00202     int tmp = 0;
00203     BrooseHandle node1, node2;
00204 
00205     if (bucket.size() <= 1)
00206         return 0;
00207 
00208     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); ++bucketIter) {
00209         tmp = 0;
00210         node1 = bucketIter->second;
00211         ++bucketIter;
00212 
00213         if (bucketIter != bucket.end()) {
00214             node2 = bucketIter->second;
00215             --bucketIter;
00216 
00217             for (uint i = 1; i <= node1.key.getLength(); i++) {
00218 //                 if (node1.key.bitAtPlace(i) == node2.key.bitAtPlace(i))
00219                 if (node1.key.get(node1.key.getLength() - i, 1) == node2.key.get(node1.key.getLength() - i, 1))
00220                     tmp++;
00221                 else
00222                     break;
00223             }
00224 
00225             if (tmp < maxBits) {
00226                 bits = tmp;
00227                 maxBits = tmp;
00228             }
00229         } else {
00230             --bucketIter;
00231         }
00232     }
00233     return bits;
00234 }

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
00262 {
00263     OverlayKey dist;
00264 
00265     if (bucket.size() == 0)
00266         return false;
00267 
00268     // check if the function was called to perform on a B bucket
00269     if (bits == 0) {
00270         if (bucket.size() <=  (maxSize / 7))
00271             dist = OverlayKey::max();
00272         else
00273             dist = getDist((maxSize / 7) - 1);
00274     } else
00275         dist = getDist(bucket.size()-1);
00276 
00277     if ((key ^ thisNode.key) <= dist)
00278         return true;
00279     else
00280         return false;
00281 
00282 }

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
00285 {
00286     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00287         if (node.ip == bucketIter->second.ip)
00288             return true;
00289     }
00290     return false;
00291 }

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
00294 {
00295     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00296         if (node.ip == bucketIter->second.ip)
00297             return bucketIter->second.failedResponses;
00298     }
00299     return -1;
00300 }

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
00303 {
00304     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00305         if (node.ip == bucketIter->second.ip)
00306             bucketIter->second.failedResponses++;
00307     }
00308 }

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
00311 {
00312     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00313         if (node.ip == bucketIter->second.ip)
00314             bucketIter->second.failedResponses = 0;
00315     }
00316 }

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
00320 {
00321     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00322         if (node.ip == bucketIter->second.ip) {
00323             bucketIter->second.rtt = rpcRTT;
00324         }
00325     }
00326 }

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
00329 {
00330     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00331         if (node.ip == bucketIter->second.ip)
00332             return bucketIter->second.rtt;
00333     }
00334     return -2;
00335 }

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
00338 {
00339     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00340         if (node.ip == bucketIter->second.ip)
00341             bucketIter->second.lastSeen = time;
00342     }
00343 }

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
00346 {
00347     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00348         if (node.ip == bucketIter->second.ip)
00349             return bucketIter->second.lastSeen;
00350     }
00351     return -2;
00352 }

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
00237 {
00238     EV << "[BrooseBucket::output() @ " << thisNode.ip
00239     << " (" << thisNode.key.toString(16) << ")]\n"
00240     << "    BucketSize/MaxSize: " << bucket.size() << "/" << maxSize
00241     << endl;
00242     BrooseHandle node;
00243     OverlayKey dist;
00244 
00245     int max;
00246     max = bucket.size();
00247     if (maxEntries != 0 && maxEntries < max) {
00248         max = maxEntries;
00249     }
00250     int i;
00251 
00252     for (bucketIter = bucket.begin(), i = 0; i < max; bucketIter++, i++) {
00253         dist = bucketIter->first;
00254         node = bucketIter->second;
00255         EV << "    " << dist << " " << node.key << " " << node.ip << " RTT: "
00256         << node.rtt << " LS: " << node.lastSeen
00257         << endl;
00258     }
00259 }

void BrooseBucket::binaryOutput ( const OverlayKey key  ) 

displays a key in binary form

Parameters:
key key which is displayed
00355 {
00356     if(key.isUnspecified())
00357         cout << "<unspec>";
00358     else {
00359         for (unsigned int i = 1; i <= key.getLength(); i++)
00360 //             cout << key.bitAtPlace(i);
00361             cout << key.get(key.getLength() - i, 1);
00362     }
00363 }

void BrooseBucket::test (  )  [protected]


Member Data Documentation

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

data structure representing the bucket

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

iterator to navigate through the bucket

unsigned int BrooseBucket::maxSize [protected]

maximal size of the bucket

BrooseHandle BrooseBucket::thisNode [protected]

node handle to the node managing this bucket

OverlayKey BrooseBucket::key [protected]

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

int BrooseBucket::bits [protected]

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

Broose* BrooseBucket::overlay [protected]

pointer to the main Broose module

bool BrooseBucket::isBBucket [protected]

true, if this bucket is the node's BBucket


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:28 2008 for ITM OverSim by  doxygen 1.5.3