Public Member Functions | Private Types | Private Attributes

NiceCluster Class Reference

#include <NiceCluster.h>

List of all members.

Public Member Functions

 NiceCluster ()
void add (const TransportAddress &member)
 Adds address to cluster.
void clear ()
 Removes all addresses from cluster, sets leader to unspecified address and sets last lt to 0.
bool contains (const TransportAddress &member)
 Tests if given address is in cluster.
int getSize ()
 Returns number of addresses in cluster.
const TransportAddressget (int i)
 Returns i-th address in cluster, counting by order.
void remove (const TransportAddress &member)
 Removes address from cluster.
void setLeader (const TransportAddress &leader)
 Set leader to given address.
const TransportAddressgetLeader ()
 Returns leader address.
std::set< TransportAddress >
::const_iterator 
begin () const
 Returns const iterator to first address.
std::set< TransportAddress >
::const_iterator 
end () const
 Returns const iterator to end of cluster.
simtime_t getLastLT ()
void setLastLT ()
bool isLeaderConfirmed ()
 The leader is "confirmed", when we can say reasonably sure that all the nodes in the cluster think of the leader as the leader.
void confirmLeader ()
 Confirm that we're sure that our leader information is correct.
int getLeaderHeartbeatsSent ()
void setLeaderHeartbeatsSent (int heartbeats)

Private Types

typedef std::set
< TransportAddress >
::const_iterator 
ConstClusterIterator
typedef std::set
< TransportAddress >::iterator 
ClusterIterator

Private Attributes

std::set< TransportAddresscluster
TransportAddress leader
simtime_t lastLT
bool leaderConfirmed
int leaderHeartbeatsSent

Detailed Description

Definition at line 30 of file NiceCluster.h.


Member Typedef Documentation

typedef std::set<TransportAddress>::iterator NiceCluster::ClusterIterator [private]

Definition at line 51 of file NiceCluster.h.

typedef std::set<TransportAddress>::const_iterator NiceCluster::ConstClusterIterator [private]

Definition at line 50 of file NiceCluster.h.


Constructor & Destructor Documentation

NiceCluster::NiceCluster (  ) 

Definition at line 28 of file NiceCluster.cc.

{
    leaderConfirmed = false;
    setLeader(TransportAddress::UNSPECIFIED_NODE);
    lastLT = 0.0;
    leaderHeartbeatsSent = 0;

    WATCH_SET(cluster);
    WATCH(leader);
    WATCH(leaderConfirmed);

} // NICECluster


Member Function Documentation

void NiceCluster::add ( const TransportAddress member  ) 
std::set< TransportAddress >::const_iterator NiceCluster::begin (  )  const

Returns const iterator to first address.

Definition at line 123 of file NiceCluster.cc.

Referenced by oversim::Nice::findCenter().

{
    return cluster.begin();
}

void NiceCluster::clear (  ) 

Removes all addresses from cluster, sets leader to unspecified address and sets last lt to 0.

Definition at line 50 of file NiceCluster.cc.

Referenced by oversim::Nice::ClusterSplit(), oversim::Nice::initializeOverlay(), and oversim::Nice::maintenance().

void NiceCluster::confirmLeader (  ) 

Confirm that we're sure that our leader information is correct.

Definition at line 152 of file NiceCluster.cc.

Referenced by oversim::Nice::ClusterMerge(), oversim::Nice::ClusterSplit(), and oversim::Nice::sendHeartbeats().

{
    leaderConfirmed = true;
}

bool NiceCluster::contains ( const TransportAddress member  ) 

Tests if given address is in cluster.

Definition at line 61 of file NiceCluster.cc.

Referenced by setLeader(), and oversim::Nice::updateVisualization().

{
    if (member.isUnspecified())
        return false;

    return cluster.find(member) != cluster.end();
} // contains

std::set< TransportAddress >::const_iterator NiceCluster::end (  )  const

Returns const iterator to end of cluster.

Definition at line 128 of file NiceCluster.cc.

Referenced by oversim::Nice::ClusterSplit(), oversim::Nice::findCenter(), oversim::Nice::gracefulLeave(), oversim::Nice::initializeOverlay(), and oversim::Nice::maintenance().

{
    return cluster.end();
}

const TransportAddress & NiceCluster::get ( int  i  ) 
simtime_t NiceCluster::getLastLT (  ) 

Definition at line 133 of file NiceCluster.cc.

{

    return lastLT;

}

const TransportAddress & NiceCluster::getLeader (  ) 

Returns leader address.

Definition at line 116 of file NiceCluster.cc.

Referenced by oversim::Nice::ClusterSplit(), oversim::Nice::maintenance(), and oversim::Nice::sendHeartbeats().

{

    return leader;

} // getLeader

int NiceCluster::getLeaderHeartbeatsSent (  ) 

Definition at line 157 of file NiceCluster.cc.

int NiceCluster::getSize (  ) 
bool NiceCluster::isLeaderConfirmed (  ) 

The leader is "confirmed", when we can say reasonably sure that all the nodes in the cluster think of the leader as the leader.

Definition at line 147 of file NiceCluster.cc.

Referenced by oversim::Nice::maintenance().

{
    return leaderConfirmed;
}

void NiceCluster::remove ( const TransportAddress member  ) 

Removes address from cluster.

If address is leader, sets leader to unspecified address.

Definition at line 90 of file NiceCluster.cc.

Referenced by oversim::Nice::gracefulLeave(), and oversim::Nice::Remove().

{

    cluster.erase(member);
    if (!leader.isUnspecified() && !member.isUnspecified() && leader == member) {
        setLeader(TransportAddress::UNSPECIFIED_NODE);
    }

} // remove

void NiceCluster::setLastLT (  ) 

Definition at line 140 of file NiceCluster.cc.

{

    lastLT = simTime();

}

void NiceCluster::setLeader ( const TransportAddress leader  ) 

Set leader to given address.

If leader is not in cluster, throws a cRuntimeError. The new leader is unconfirmed, call confirmLeader(), when we are sure that the leader info is correct.

Definition at line 101 of file NiceCluster.cc.

Referenced by oversim::Nice::changeState(), clear(), oversim::Nice::ClusterMerge(), oversim::Nice::ClusterSplit(), oversim::Nice::gracefulLeave(), oversim::Nice::handleNiceQuery(), oversim::Nice::maintenance(), NiceCluster(), and remove().

{

    if (!leader.isUnspecified() && !contains(leader)) {
        throw cRuntimeError("Leader not member of cluster");
    }
    this->leader = leader;

    leaderConfirmed = false;

//      //cout << "Leader set to " << leader << endl;

} // setLeader

void NiceCluster::setLeaderHeartbeatsSent ( int  heartbeats  ) 

Definition at line 162 of file NiceCluster.cc.

{
    leaderHeartbeatsSent = heartbeats;
}


Member Data Documentation

Definition at line 36 of file NiceCluster.h.

Referenced by add(), begin(), clear(), contains(), end(), get(), getSize(), NiceCluster(), and remove().

simtime_t NiceCluster::lastLT [private]

Definition at line 42 of file NiceCluster.h.

Referenced by clear(), getLastLT(), NiceCluster(), and setLastLT().

Definition at line 39 of file NiceCluster.h.

Referenced by getLeader(), NiceCluster(), and remove().

Definition at line 45 of file NiceCluster.h.

Referenced by confirmLeader(), isLeaderConfirmed(), NiceCluster(), and setLeader().

Definition at line 48 of file NiceCluster.h.

Referenced by getLeaderHeartbeatsSent(), NiceCluster(), and setLeaderHeartbeatsSent().


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