Public Member Functions | Protected Member Functions | Protected Attributes

oversim::ChordSuccessorList Class Reference

Chord's successor list module. More...

#include <ChordSuccessorList.h>

List of all members.

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual void initializeList (uint32_t size, NodeHandle owner, Chord *overlay)
 Initializes the successor list.
virtual uint32_t getSize ()
 Returns number of neighbors in the successor list.
virtual bool isEmpty ()
 Checks if the successor list is empty.
virtual const NodeHandlegetSuccessor (uint32_t pos=0)
 Returns a particular successor.
virtual void addSuccessor (NodeHandle successor, bool resize=true)
 Adds new successor nodes to the successor list.
virtual void updateList (NotifyResponse *notify)
bool handleFailedNode (const TransportAddress &failed)
void display ()

Protected Member Functions

void removeOldSuccessors ()
void updateDisplayString ()
 Displays the current number of successors in the list.
void updateTooltip ()
 Displays the first 4 successor nodes as tooltip.

Protected Attributes

NodeHandle thisNode
 own node handle
std::map< OverlayKey,
SuccessorListEntry
successorMap
 internal representation of the successor list
uint32_t successorListSize
 maximum size of the successor list
Chordoverlay
 pointer to the main chord module

Detailed Description

Chord's successor list module.

This modul contains the successor list of the Chord implementation.

Author:
Markus Mauch, Ingmar Baumgart
See also:
Chord

Definition at line 58 of file ChordSuccessorList.h.


Member Function Documentation

void oversim::ChordSuccessorList::addSuccessor ( NodeHandle  successor,
bool  resize = true 
) [virtual]

Adds new successor nodes to the successor list.

Adds new successor nodes to the successor list and sorts the list using the corresponding chord keys. If the list size exceeds the maximum size nodes at the end of the list will be removed.

Parameters:
successor the node handle of the successor to be added
resize if true, shrink the list to successorListSize

Definition at line 122 of file ChordSuccessorList.cc.

Referenced by handleFailedNode(), oversim::Chord::handleNewSuccessorHint(), oversim::Chord::handleRpcJoinResponse(), oversim::Chord::handleRpcNotifyResponse(), oversim::Chord::handleRpcStabilizeResponse(), initializeList(), removeOldSuccessors(), oversim::Chord::rpcJoin(), oversim::Chord::rpcNotify(), and updateList().

{
    OverlayKey sum = successor.getKey() - (thisNode.getKey() + OverlayKey::ONE);

    std::map<OverlayKey, SuccessorListEntry>::iterator it =
        successorMap.find(sum);

    // Make a CommonAPI update() upcall to inform application
    // about our new neighbor in the successor list

    if (it == successorMap.end()) {
        // TODO: first add node and than call update()
        overlay->callUpdate(successor, true);
    } else {
        successorMap.erase(it);
    }

    SuccessorListEntry entry;
    entry.nodeHandle = successor;
    entry.newEntry = true;

    successorMap.insert(make_pair(sum, entry));

    if ((resize == true) && (successorMap.size() > (uint32_t)successorListSize)) {
        it = successorMap.end();
        it--;
        overlay->callUpdate(it->second.nodeHandle, false);
        successorMap.erase(it);
    }
}

void oversim::ChordSuccessorList::display (  ) 

Definition at line 233 of file ChordSuccessorList.cc.

{
    cout << "Content of ChordSuccessorList:" << endl;
    for (std::map<OverlayKey,SuccessorListEntry>::iterator it =
        successorMap.begin(); it != successorMap.end(); it++)
        cout << it->first << " with Node: " << it->second.nodeHandle << endl;
}

uint32_t oversim::ChordSuccessorList::getSize (  )  [virtual]
const NodeHandle & oversim::ChordSuccessorList::getSuccessor ( uint32_t  pos = 0  )  [virtual]
bool oversim::ChordSuccessorList::handleFailedNode ( const TransportAddress failed  ) 

Definition at line 153 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::handleFailedNode().

{
    assert(failed != thisNode);
    for (std::map<OverlayKey, SuccessorListEntry>::iterator iter =
         successorMap.begin(); iter != successorMap.end(); ++iter) {
        if (failed == iter->second.nodeHandle) {
            successorMap.erase(iter);
            overlay->callUpdate(failed, false);
            // ensure that thisNode is always in the successor list
            if (getSize() == 0)
                addSuccessor(thisNode);
            return true;
        }
    }
    return false;
}

void oversim::ChordSuccessorList::handleMessage ( cMessage *  msg  )  [virtual]

Definition at line 52 of file ChordSuccessorList.cc.

{
    error("this module doesn't handle messages, it runs only in initialize()");
}

void oversim::ChordSuccessorList::initialize ( int  stage  )  [virtual]

Definition at line 42 of file ChordSuccessorList.cc.

{
    // because of IPAddressResolver, we need to wait until interfaces
    // are registered, address auto-assignment takes place etc.
    if (stage != MIN_STAGE_OVERLAY)
        return;

    WATCH_MAP(successorMap);
}

void oversim::ChordSuccessorList::initializeList ( uint32_t  size,
NodeHandle  owner,
Chord overlay 
) [virtual]

Initializes the successor list.

This should be called on startup

Parameters:
size maximum number of neighbors in the successor list
owner the node owner is added to the successor list
overlay pointer to the main chord module

Definition at line 57 of file ChordSuccessorList.cc.

Referenced by oversim::Koorde::initializeFriendModules(), and oversim::Chord::initializeFriendModules().

{
    successorMap.clear();
    successorListSize = size;
    thisNode = owner;
    this->overlay = overlay;
    addSuccessor(thisNode);
}

bool oversim::ChordSuccessorList::isEmpty (  )  [virtual]
virtual int oversim::ChordSuccessorList::numInitStages (  )  const [inline, virtual]

Definition at line 61 of file ChordSuccessorList.h.

    {
        return MAX_STAGE_OVERLAY + 1;
    }

void oversim::ChordSuccessorList::removeOldSuccessors (  )  [protected]

Definition at line 170 of file ChordSuccessorList.cc.

Referenced by updateList().

{
    std::map<OverlayKey,SuccessorListEntry>::iterator it;

    for (it = successorMap.begin(); it != successorMap.end();) {

        if (it->second.newEntry == false) {
            overlay->callUpdate(it->second.nodeHandle, false);
            successorMap.erase(it++);
        } else {
            it->second.newEntry = false;
            it++;
        }
    }

    it = successorMap.end();
    it--;

    while (successorMap.size() > successorListSize) {
        successorMap.erase(it--);
    }

    if (getSize() == 0)
        addSuccessor(thisNode);
}

void oversim::ChordSuccessorList::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

Definition at line 197 of file ChordSuccessorList.cc.

{
    // FIXME: doesn't work without tcl/tk
    //          if (ev.isGUI()) {
    if (1) {
        char buf[80];

        if (successorMap.size() == 1) {
            sprintf(buf, "1 successor");
        } else {
            sprintf(buf, "%zi successors", successorMap.size());
        }

        getDisplayString().setTagArg("t", 0, buf);
        getDisplayString().setTagArg("t", 2, "blue");
    }

}

void oversim::ChordSuccessorList::updateList ( NotifyResponse notify  )  [virtual]

Definition at line 101 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::handleRpcNotifyResponse().

{
    addSuccessor(notifyResponse->getSrcNode(), false);

    for (uint32_t k = 0; ((k < static_cast<uint32_t>(notifyResponse->getSucNum()))
                     && (k < (successorListSize - 1))); k++) {
        NodeHandle successor = notifyResponse->getSucNode(k);

        // don't add nodes, if this would change our successor
        if (successor.getKey().isBetweenLR(thisNode.getKey(),
                                      notifyResponse->getSrcNode().getKey()))
            continue;

        addSuccessor(successor, false);
    }

    removeOldSuccessors();
    assert(!isEmpty());
}

void oversim::ChordSuccessorList::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

Definition at line 216 of file ChordSuccessorList.cc.

{
    if (ev.isGUI()) {
        std::stringstream str;
        for (uint32_t i = 0; i < successorMap.size(); i++)      {
            str << getSuccessor(i);
            if ( i != successorMap.size() - 1 )
                str << endl;
        }


        char buf[1024];
        sprintf(buf, "%s", str.str().c_str());
        getDisplayString().setTagArg("tt", 0, buf);
    }
}


Member Data Documentation

pointer to the main chord module

Definition at line 126 of file ChordSuccessorList.h.

Referenced by addSuccessor(), handleFailedNode(), and removeOldSuccessors().

maximum size of the successor list

Definition at line 124 of file ChordSuccessorList.h.

Referenced by addSuccessor(), initializeList(), removeOldSuccessors(), and updateList().

own node handle

Definition at line 121 of file ChordSuccessorList.h.

Referenced by addSuccessor(), handleFailedNode(), initializeList(), isEmpty(), removeOldSuccessors(), and updateList().


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