BrooseBucket Class Reference

Broose bucket module. More...

#include <BrooseBucket.h>

List of all members.

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual bool add (const NodeHandle &node, bool isAlive=false, simtime_t rtt=MAXTIME)
 adds a broose node handle to the bucket
virtual void remove (const NodeHandle &node)
 removes a broose node handle from the bucket
virtual const BrooseHandleget (uint32_t pos=0)
 returns a specific broose handle
virtual const OverlayKeygetDist (uint32_t pos=0)
 returns distance of a specific broose handle
virtual void initializeBucket (int shiftingBits, uint32_t prefix, int size, Broose *overlay, bool isBBucket=false)
 initializes a bucket
virtual uint32_t getSize ()
 returns number of current entries
virtual uint32_t getMaxSize ()
 returns number of maximal entries
virtual void fillVector (NodeVector *result)
 Fills a NodeVector with all bucket entries.
virtual bool isEmpty ()
 checks if the bucket is empty
virtual void clear ()
 removes all entries from the bucket
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 int getPos (const NodeHandle &node)
 returns the position of a node in this bucket
virtual int getFailedResponses (const NodeHandle &node)
 returns the number of failed responses to a specific broose handle
virtual void increaseFailedResponses (const NodeHandle &node)
 increase the number of failed responses to a specific broose handle
virtual void resetFailedResponses (const NodeHandle &node)
 resets the counter of failed responses to a specific broose handle
virtual void setRTT (const NodeHandle &node, simtime_t rpcRTT)
 sets the round trip time to a specific broose handle
virtual simtime_t getRTT (const NodeHandle &node)
 returns the round trip time to a specific broose handle
virtual void setLastSeen (const NodeHandle &node, simtime_t lastSeen)
 updates the timestamp of a specific node
virtual simtime_t getLastSeen (const NodeHandle &node)
 returns the timestamp of a specific node
void output (int maxEntries=0)
 displays the content of the bucket on standard out

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
OverlayKey key
 the node's key shifted to fit the bucket and used to measure distance to other keys
Brooseoverlay
 pointer to the main Broose module
bool isBBucket
 true, if this bucket is the node's BBucket


Detailed Description

Broose bucket module.

This modul contains the bucket of the Broose implementation.

Author:
Jochen Schenk
See also:
Broose

Definition at line 43 of file BrooseBucket.h.


Member Function Documentation

bool BrooseBucket::add ( const NodeHandle node,
bool  isAlive = false,
simtime_t  rtt = MAXTIME 
) [virtual]

adds a broose node handle to the bucket

Parameters:
node the NodeHandle to add
isAlive true, if it is known that the node is alive
rtt measured round-trip-time to node
Returns:
true, if the node was known or has been added

Definition at line 70 of file BrooseBucket.cc.

Referenced by Broose::changeState(), and Broose::handleBucketTimerExpired().

00071 {
00072     OverlayKey tmp = key ^ node.getKey();
00073 
00074     bucketIter = bucket.find(tmp);
00075 
00076     if (bucketIter == bucket.end()) {
00077         // new node
00078         if (bucket.size() < maxSize) {
00079              bucketIter = bucket.insert(make_pair(tmp,node)).first;
00080         } else {
00081             std::map<OverlayKey, BrooseHandle>::iterator back = --bucket.end();
00082 
00083             // is the new node closer than the one farthest away,
00084             // remove the one and add the other
00085             if (back->first > tmp) {
00086                 bucket.erase(back);
00087                 bucketIter = bucket.insert(make_pair(tmp,node)).first;
00088             } else {
00089                 // doesn't fit into bucket
00090                 return false;
00091             }
00092         }
00093 
00094         if (isBBucket && (getPos(node) < (maxSize/7))) {
00095             // node is a new sibling
00096             if (bucket.size() > (maxSize/7)) {
00097                 // call update() for removed sibling
00098                 overlay->callUpdate(get(maxSize/7), false);
00099             }
00100 
00101             // call update() for new sibling
00102             overlay->callUpdate(node, true);
00103         }
00104     }
00105 
00106     if (isAlive) {
00107         bucketIter->second.failedResponses = 0;
00108         bucketIter->second.lastSeen = simTime();
00109     }
00110 
00111     if (rtt != MAXTIME) {
00112         bucketIter->second.rtt = rtt;
00113     }
00114 
00115     return true;
00116 }

void BrooseBucket::clear (  )  [virtual]

removes all entries from the bucket

Definition at line 186 of file BrooseBucket.cc.

00187 {
00188     bucket.clear();
00189 }

void BrooseBucket::fillVector ( NodeVector result  )  [virtual]

Fills a NodeVector with all bucket entries.

Parameters:
result a pointer to an existing NodeVector, which gets filled with all bucket entries

Definition at line 191 of file BrooseBucket.cc.

Referenced by Broose::findNode().

00192 {
00193     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00194         result->add(bucketIter->second);
00195     }
00196 }

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

returns a specific broose handle

Parameters:
pos position of the broose handle in the bucket

Definition at line 138 of file BrooseBucket.cc.

Referenced by Broose::changeState(), Broose::handleBucketRequestRpc(), and Broose::handleBucketTimerExpired().

00139 {
00140     if (pos > bucket.size()) {
00141         error("Index out of bounds(BrooseBucket).");
00142     }
00143 
00144     uint32_t i = 0;
00145     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++) {
00146         if (pos == i) {
00147             return bucketIter->second;
00148         }
00149         i++;
00150     }
00151     return BrooseHandle::unspecifiedNode();
00152 }

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

returns distance of a specific broose handle

Parameters:
pos position of the broose handle in the bucket

Definition at line 154 of file BrooseBucket.cc.

Referenced by keyInRange().

00155 {
00156     if(pos > bucket.size()) {
00157         error("Index out of bounds(BrooseBucket).");
00158     }
00159 
00160     uint32_t i = 0;
00161     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); bucketIter++) {
00162         if (pos == i) {
00163             return bucketIter->first;
00164         }
00165         i++;
00166     }
00167     return OverlayKey::UNSPECIFIED_KEY;
00168 }

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

returns the number of failed responses to a specific broose handle

Parameters:
node broose handle to check
Returns:
number of failed responses

Definition at line 269 of file BrooseBucket.cc.

00270 {
00271     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00272         if (node.getAddress() == bucketIter->second.getAddress())
00273             return bucketIter->second.failedResponses;
00274     }
00275     return -1;
00276 }

simtime_t BrooseBucket::getLastSeen ( const NodeHandle node  )  [virtual]

returns the timestamp of a specific node

Parameters:
node broose handle to which the timestamp will be retrieved
Returns:
the retrieved timestamp

Definition at line 321 of file BrooseBucket.cc.

00322 {
00323     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00324         if (node.getAddress() == bucketIter->second.getAddress())
00325             return bucketIter->second.lastSeen;
00326     }
00327     return -2;
00328 }

uint32_t BrooseBucket::getMaxSize (  )  [virtual]

returns number of maximal entries

Returns:
number of maximal entries

Definition at line 176 of file BrooseBucket.cc.

00177 {
00178     return maxSize;
00179 }

int BrooseBucket::getPos ( const NodeHandle node  )  [virtual]

returns the position of a node in this bucket

Parameters:
node broose handle to check
Returns:
the position of the node (0 = first node, -1 = node not in bucket)

Definition at line 259 of file BrooseBucket.cc.

Referenced by add().

00260 {
00261     int i = -1;
00262     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++, i++) {
00263         if (node.getAddress() == bucketIter->second.getAddress())
00264             return i;
00265     }
00266     return i;
00267 }

simtime_t BrooseBucket::getRTT ( const NodeHandle 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

Definition at line 304 of file BrooseBucket.cc.

00305 {
00306     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00307         if (node.getAddress() == bucketIter->second.getAddress())
00308             return bucketIter->second.rtt;
00309     }
00310     return -2;
00311 }

uint32_t BrooseBucket::getSize (  )  [virtual]

returns number of current entries

Returns:
number of current entries

Definition at line 171 of file BrooseBucket.cc.

Referenced by Broose::changeState(), Broose::handleBucketRequestRpc(), and Broose::handleBucketTimerExpired().

00172 {
00173     return bucket.size();
00174 }

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

Definition at line 44 of file BrooseBucket.cc.

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

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

increase the number of failed responses to a specific broose handle

Parameters:
node broose handle which counter will be increased

Definition at line 278 of file BrooseBucket.cc.

00279 {
00280     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00281         if (node.getAddress() == bucketIter->second.getAddress())
00282             bucketIter->second.failedResponses++;
00283     }
00284 }

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

Definition at line 36 of file BrooseBucket.cc.

00037 {
00038     if(stage != MIN_STAGE_OVERLAY)
00039         return;
00040 
00041     WATCH_MAP(bucket);
00042 }

void BrooseBucket::initializeBucket ( int  shiftingBits,
uint32_t  prefix,
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
size maximal size of the bucket
overlay pointer to the main Broose module
isBBucket true, is this bucket is the node's BBucket

Definition at line 49 of file BrooseBucket.cc.

Referenced by Broose::changeState(), and Broose::handleBucketTimerExpired().

00051 {
00052     maxSize = size;
00053     this->overlay = overlay;
00054     this->isBBucket = isBBucket;
00055 
00056     if (shiftingBits < 0) {
00057         key = overlay->getThisNode().getKey() << -shiftingBits;
00058     } else {
00059         key = overlay->getThisNode().getKey() >> shiftingBits;
00060     }
00061 
00062     if (prefix != 0) {
00063         OverlayKey tmp(prefix); // constraint
00064         tmp = tmp << (overlay->getThisNode().getKey().getLength() - shiftingBits);
00065         key = key + tmp;
00066     }
00067     bucket.clear();
00068 }

bool BrooseBucket::isEmpty (  )  [virtual]

checks if the bucket is empty

Returns:
true if the bucket is empty

Definition at line 181 of file BrooseBucket.cc.

00182 {
00183     return bucket.empty();
00184 }

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

Definition at line 236 of file BrooseBucket.cc.

Referenced by Broose::isSiblingFor().

00237 {
00238     OverlayKey dist;
00239 
00240     if (bucket.size() == 0)
00241         return false;
00242 
00243     // check if the function was called to perform on a B bucket
00244     if (isBBucket) {
00245         if (bucket.size() <=  (maxSize / 7))
00246             return true;
00247         else
00248             dist = getDist((maxSize / 7) - 1);
00249     } else
00250         dist = getDist(bucket.size()-1);
00251 
00252     if ((key ^ overlay->getThisNode().getKey()) <= dist)
00253         return true;
00254     else
00255         return false;
00256 
00257 }

int BrooseBucket::longestPrefix ( void   )  [virtual]

return the longest prefix of all entries

Returns:
the longest prefix

Definition at line 199 of file BrooseBucket.cc.

00200 {
00201     if (bucket.size() < 2)
00202         return 0;
00203 
00204     return bucket.begin()->second.getKey().sharedPrefixLength(
00205                                              (--bucket.end())->second.getKey());
00206 }

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

Definition at line 46 of file BrooseBucket.h.

00047     {
00048         return MAX_STAGE_OVERLAY + 1;
00049     }

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

Definition at line 208 of file BrooseBucket.cc.

Referenced by Broose::displayBucketState().

00209 {
00210     BrooseHandle node;
00211     OverlayKey dist;
00212 
00213     EV << "[BrooseBucket::output() @ " << overlay->getThisNode().getAddress()
00214        << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
00215        << "    BucketSize/MaxSize: " << bucket.size() << "/" << maxSize
00216        << endl;
00217 
00218     int max;
00219     max = bucket.size();
00220 
00221     if (maxEntries != 0 && maxEntries < max) {
00222         max = maxEntries;
00223     }
00224 
00225     int i;
00226 
00227     for (bucketIter = bucket.begin(), i = 0; i < max; bucketIter++, i++) {
00228         dist = bucketIter->first;
00229         node = bucketIter->second;
00230         EV << "    " << dist << " " << node.getKey() << " " << node.getAddress() << " RTT: "
00231            << node.rtt << " LS: " << node.lastSeen
00232            << endl;
00233     }
00234 }

void BrooseBucket::remove ( const NodeHandle node  )  [virtual]

removes a broose node handle from the bucket

Parameters:
node broose handle which will be removed

Definition at line 118 of file BrooseBucket.cc.

00119 {
00120     int i = 0;
00121     for (bucketIter = bucket.begin(); bucketIter != bucket.end(); i++) {
00122         if (bucketIter->second.getAddress() == node.getAddress()) {
00123             if (isBBucket && (i < (maxSize/7))) {
00124                 // call update() for removed sibling
00125                 overlay->callUpdate(node, false);
00126                 if (bucket.size() > (maxSize/7)) {
00127                     // new replacement sibling
00128                     overlay->callUpdate(get(maxSize/7), true);
00129                 }
00130             }
00131             bucket.erase(bucketIter++);
00132         } else {
00133             ++bucketIter;
00134         }
00135     }
00136 }

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

resets the counter of failed responses to a specific broose handle

Parameters:
node broose handle which counter will be reset

Definition at line 286 of file BrooseBucket.cc.

00287 {
00288     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00289         if (node.getAddress() == bucketIter->second.getAddress())
00290             bucketIter->second.failedResponses = 0;
00291     }
00292 }

void BrooseBucket::setLastSeen ( const NodeHandle 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

Definition at line 313 of file BrooseBucket.cc.

00314 {
00315     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00316         if (node.getAddress() == bucketIter->second.getAddress())
00317             bucketIter->second.lastSeen = time;
00318     }
00319 }

void BrooseBucket::setRTT ( const NodeHandle 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

Definition at line 295 of file BrooseBucket.cc.

00296 {
00297     for (bucketIter = bucket.begin(); bucketIter!=bucket.end(); bucketIter++) {
00298         if (node.getAddress() == bucketIter->second.getAddress()) {
00299             bucketIter->second.rtt = rpcRTT;
00300         }
00301     }
00302 }


Member Data Documentation

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

bool BrooseBucket::isBBucket [protected]

true, if this bucket is the node's BBucket

Definition at line 227 of file BrooseBucket.h.

Referenced by add(), keyInRange(), and remove().

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

Definition at line 225 of file BrooseBucket.h.

Referenced by add(), and initializeBucket().

unsigned int BrooseBucket::maxSize [protected]

maximal size of the bucket

Definition at line 224 of file BrooseBucket.h.

Referenced by add(), getMaxSize(), initializeBucket(), keyInRange(), output(), and remove().

pointer to the main Broose module

Definition at line 226 of file BrooseBucket.h.

Referenced by add(), keyInRange(), output(), and remove().


The documentation for this class was generated from the following files:

Generated on Tue Sep 8 17:26:57 2009 for OverSim by  doxygen 1.5.8