OverSim
NeighborCache Class Reference

#include <NeighborCache.h>

Inheritance diagram for NeighborCache:
BaseApp BaseRpc BaseTcpSupport RpcListener

Classes

struct  NeighborCacheEntry
struct  WaitingContext

Public Member Functions

 ~NeighborCache ()
bool isEnabled ()
const TransportAddressgetBootstrapNode ()
bool piggybackOwnCoords ()
const AbstractNcsgetNcsAccess () const
const NodeHandlegetOverlayThisNode ()
uint16_t getNeighborCacheSize ()
bool isEntry (const TransportAddress &node)
simtime_t getNodeAge (const TransportAddress &handle)
const NodeHandlegetNodeHandle (const TransportAddress &add)
simtime_t getNodeTimeout (const NodeHandle &node)
 Caclulation of reasonable timout value.
TransportAddress getNearestNode (uint8_t maxLayer)
double getAvgAbsPredictionError ()
std::vector< TransportAddress > * getClosestNodes (uint8_t number)
std::vector< TransportAddress > * getSpreadedNodes (uint8_t number)
void updateNode (const NodeHandle &add, simtime_t rtt, const NodeHandle &srcRoute=NodeHandle::UNSPECIFIED_NODE, AbstractNcsNodeInfo *ncsInfo=NULL)
void updateNcsInfo (const TransportAddress &node, AbstractNcsNodeInfo *ncsInfo)
void setNodeTimeout (const TransportAddress &handle)
Prox getProx (const TransportAddress &node, NeighborCacheQueryType type=NEIGHBORCACHE_AVAILABLE, int rpcId=-1, ProxListener *listener=NULL, cPolymorphic *contextPointer=NULL)
 Gets the proximity of a node.
Prox estimateProx (const TransportAddress &node)
 Estimates a Prox value of node, in relation to this node, based on information collected by the overlay.
const AbstractNcsNodeInfogetNodeCoordsInfo (const TransportAddress &node)
 Returns the coordinate information of a node.
TreeManagementgetTreeManager ()
 Returns a pointer to the treeManager Module.
std::pair< simtime_t, simtime_t > getMeanVarRtt (const TransportAddress &node, bool returnVar)
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)

Protected Types

typedef UNORDERED_MAP
< TransportAddress,
NeighborCacheEntry >::iterator 
NeighborCacheIterator
typedef UNORDERED_MAP
< TransportAddress,
NeighborCacheEntry >
::const_iterator 
NeighborCacheConstIterator
typedef std::multimap
< simtime_t, TransportAddress >
::iterator 
neighborCacheExpireMapIterator

Protected Member Functions

void initializeApp (int stage)
 initializes derived class-attributes
void finishApp ()
 collects statistical data of derived app
virtual CompType getThisCompType ()
 Return the component type of this module.
void handleTimerEvent (cMessage *msg)
void queryProx (const TransportAddress &node, int rpcId, ProxListener *listener, cPolymorphic *contextPointer)
 Sends a pingNode call based on parameters from a getProx call.
bool handleRpcCall (BaseCallMessage *msg)
 Coord / RTT measuring rpc stuff goes here.
void handleReadyMessage (CompReadyMessage *msg)
 handle ready message - build tree topology
simtime_t getRttBasedTimeout (const NodeHandle &node)
simtime_t getNcsBasedTimeout (const NodeHandle &node)
void callbackDiscoveryFinished (const TransportAddress &nearNode)
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base class-attributes
void handleMessage (cMessage *msg)
 checks for message type and calls corresponding method
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
virtual void update (const NodeHandle &node, bool joined)
 Common API function: informs application about neighbors and own nodeID.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (int num)
 Common API function: produces a list of neighbor nodes.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
void sendReadyMessage (bool ready=true, const OverlayKey &nodeId=OverlayKey::UNSPECIFIED_KEY)
- Protected Member Functions inherited from BaseRpc
virtual void internalHandleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 Handles rpc timeouts internal in base classes

void initRpcs ()
 Initializes Remote-Procedure state.
void finishRpcs ()
 Deinitializes Remote-Procedure state.
virtual void internalHandleRpcMessage (BaseRpcMessage *msg)
 Handles incoming rpc messages and delegates them to the corresponding listeners or handlers.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message using the overlay's UDP port
This replaces ROUTE_DIRECT calls!
uint32_t sendUdpRpcCall (const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message to the underlay

uint32_t sendInternalRpcCall (CompType destComp, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends an internal Remote-Procedure-Call between two tiers

void cancelRpcMessage (uint32_t nonce)
 Cancels a Remote-Procedure-Call.
void cancelAllRpcs ()
 Cancels all RPCs.
void sendRpcResponse (TransportType transportType, CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message and deletes call message.
void sendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message to UDP and deletes call message.
int pingNode (const TransportAddress &dest, simtime_t timeout=-1, int retries=0, cPolymorphic *context=NULL, const char *caption="PING", RpcListener *rpcListener=NULL, int rpcId=-1, TransportType transportType=INVALID_TRANSPORT)
 ping a node by its TransportAddress
virtual void pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt)
virtual void pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId)
bool internalHandleMessage (cMessage *msg)
- Protected Member Functions inherited from RpcListener
virtual void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcResponse (BaseResponseMessage *msg, const RpcState &rpcState, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
virtual void handleRpcTimeout (const RpcState &rpcState)
 This method is called if an RPC timeout has been reached.
- Protected Member Functions inherited from BaseTcpSupport
void handleTCPMessage (cMessage *msg)
 Member function to handle incoming TCP messages.
void bindAndListenTcp (int port)
 Member function to bind service to the specified port and listen afterwards.
bool isAlreadyConnected (TransportAddress address)
 Member function to check if the service is already connected.
void establishTcpConnection (TransportAddress address)
 Member function to establish a connection to the specified node.
void sendTcpData (cPacket *msg, TransportAddress address)
 Member function to send TCP data to the specified node.
virtual void handleConnectionEvent (EvCode code, TransportAddress address)
 Member function to handle passive connection events.
virtual void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
 Member function to handle incoming data.
virtual void handleIncomingConnection (TransportAddress address)
 Member function to handle newly opened connections.
void closeTcpConnection (TransportAddress address)
 Member function to close an established connection.
void setTcpOut (cGate *gate)
 Member function to set local gate towards the TCP module during init phase.
cGate * getTcpOut ()
 Member function to get local gate towards the TCP module.

Protected Attributes

GlobalStatisticsglobalStatistics
UNORDERED_MAP
< TransportAddress,
NeighborCacheEntry
neighborCache
std::multimap< simtime_t,
TransportAddress
neighborCacheExpireMap
ProxAddressVectorclosestNodes
- Protected Attributes inherited from BaseApp
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created
- Protected Attributes inherited from BaseRpc
NodeHandle thisNode
 NodeHandle to this node.
BaseOverlayoverlay
bool debugOutput
 debug output ?
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
CompType thisCompType
NeighborCacheneighborCache
 pointer to the neighbor cache
CryptoModulecryptoModule
 pointer to CryptoModule
int numPingSent
int bytesPingSent
int numPingResponseSent
int bytesPingResponseSent

Private Types

enum  NeighborCacheRttState { RTTSTATE_VALID, RTTSTATE_UNKNOWN, RTTSTATE_TIMEOUT, RTTSTATE_WAITING }
typedef std::vector
< WaitingContext
WaitingContexts
typedef std::pair< simtime_t,
NeighborCacheRttState
Rtt

Private Member Functions

bool cleanupCache ()
void updateEntry (const TransportAddress &address, simtime_t insertTime)
Prox getCoordinateBasedProx (const TransportAddress &node)
void recordNcsEstimationError (const NodeHandle &handle, simtime_t rtt)
bool insertNodeContext (const TransportAddress &handle, cPolymorphic *context, ProxListener *rpcListener, int rpcId)
NeighborCache::WaitingContexts getNodeContexts (const TransportAddress &handle)
Rtt getNodeRtt (const TransportAddress &add)
void pingResponse (PingResponse *response, cPolymorphic *context, int rpcId, simtime_t rtt)
void pingTimeout (PingCall *call, const TransportAddress &dest, cPolymorphic *context, int rpcId)
void prepareOverlay ()
void setCbrNodeId ()

Private Attributes

bool enableNeighborCache
uint8_t collectClosestNodes
simtime_t rttExpirationTime
uint32_t maxSize
bool discoveryFinished
uint32_t misses
uint32_t hits
AbstractNcsncs
TreeManagementtreeManager
GlobalViewBuilderglobalViewBuilder
bool capReqFinished
bool ncsPiggybackOwnCoords
bool useNcsForTimeout
StdProxComparatorproxComparator
DiscoveryModediscoveryMode
CoordBasedRoutingcoordBasedRouting
NeighborCacheQueryType defaultQueryType
NeighborCacheQueryType defaultQueryTypeI
NeighborCacheQueryType defaultQueryTypeQ
cMessage * landmarkTimer
cMessage * cbrTimer
std::map< TransportAddress,
std::vector< double > > 
lastAbsoluteErrorPerNode
uint32_t numMsg
double absoluteError
double relativeError
uint32_t numRttErrorToHigh
uint32_t numRttErrorToLow
uint32_t rttHistory
double timeoutAccuracyLimit

Static Private Attributes

static const std::vector< double > coordsDummy
static const double RTT_TIMEOUT_ADJUSTMENT = 1.3
static const double NCS_TIMEOUT_CONSTANT = 0.350

Friends

class Nps
class SimpleUnderlayNCS
class TreeManagement
class GlobalViewBuilder
class DiscoveryMode
std::ostream & operator<< (std::ostream &os, const NeighborCacheEntry &entry)

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}

Detailed Description

Definition at line 78 of file NeighborCache.h.

Member Typedef Documentation

Definition at line 214 of file NeighborCache.h.

typedef std::multimap<simtime_t, TransportAddress>::iterator NeighborCache::neighborCacheExpireMapIterator
protected

Definition at line 217 of file NeighborCache.h.

typedef std::pair<simtime_t, NeighborCacheRttState> NeighborCache::Rtt
private

Definition at line 169 of file NeighborCache.h.

typedef std::vector<WaitingContext> NeighborCache::WaitingContexts
private

Definition at line 152 of file NeighborCache.h.

Member Enumeration Documentation

Enumerator:
RTTSTATE_VALID 
RTTSTATE_UNKNOWN 
RTTSTATE_TIMEOUT 
RTTSTATE_WAITING 

Definition at line 162 of file NeighborCache.h.

Constructor & Destructor Documentation

NeighborCache::~NeighborCache ( )

Definition at line 222 of file NeighborCache.cc.

{
delete ncs;
delete treeManager;
delete discoveryMode;
delete closestNodes;
cancelAndDelete(cbrTimer);
}

Member Function Documentation

void NeighborCache::callbackDiscoveryFinished ( const TransportAddress nearNode)
protected
bool NeighborCache::cleanupCache ( )
private

Definition at line 501 of file NeighborCache.cc.

Referenced by insertNodeContext(), queryProx(), setNodeTimeout(), updateNcsInfo(), and updateNode().

{
bool result = false;
uint32_t size = neighborCache.size();
if (size > maxSize) {
for (uint32_t i = 0; i < (size - (maxSize / 2)); ++i) {
it = neighborCacheExpireMap.begin();
if ((neighborCache[it->second].rttState == RTTSTATE_WAITING) ||
(neighborCache[it->second].insertTime == simTime())) {
break;
}
neighborCache.erase(it->second);
result = true;
}
}
assert(neighborCache.size() == neighborCacheExpireMap.size());
return result;
}
Prox NeighborCache::estimateProx ( const TransportAddress node)

Estimates a Prox value of node, in relation to this node, based on information collected by the overlay.

Parameters
nodeThe node whose proximity will be requested.
Returns
The RTT value if one is found in the cache, or else a Prox estimate.

Definition at line 976 of file NeighborCache.cc.

Referenced by getProx().

{
Enter_Method("estimateProx()");
Rtt rtt = getNodeRtt(node);
if (rtt.second != RTTSTATE_UNKNOWN) return rtt.first;
if (ncs && neighborCache.count(node)) {
return getCoordinateBasedProx(node);
}
}
void NeighborCache::finishApp ( )
protectedvirtual

collects statistical data of derived app

Reimplemented from BaseApp.

Definition at line 194 of file NeighborCache.cc.

{
if ((misses + hits) != 0) {
->addStdDev("NeighborCache: Ping hit rate",
((double)hits / (double)(misses + hits)));
}
if (ncs && numMsg > 0) {
globalStatistics->addStdDev("NeighborCache: NCS absolute RTT error",
absoluteError / (double)numMsg);
globalStatistics->addStdDev("NeighborCache: NCS relative RTT error",
relativeError / (double)numMsg);
globalStatistics->addStdDev("NeighborCache: number of messages/s",
numMsg / SIMTIME_DBL(simTime() - creationTime));
globalStatistics->addStdDev("NeighborCache: NCS percentage of RTT errors to high",
(double)numRttErrorToHigh / (double)numMsg);
globalStatistics->addStdDev("NeighborCache: NCS percentage of RTT errors to low",
(double)numRttErrorToLow / (double)numMsg);
}
}
}
double NeighborCache::getAvgAbsPredictionError ( )

Definition at line 597 of file NeighborCache.cc.

Referenced by SVivaldi::calcError().

{
/*
//TODO retain and consider the last measured RTTs not the last error(s)
double absoluteDiff = 0.0;
uint32_t numNeighbors = 0;
for (std::map<TransportAddress, std::vector<double> >::iterator it =
lastAbsoluteErrorPerNode.begin(); it != lastAbsoluteErrorPerNode.end();
it++) {
double tempAbsoluteDiff = 0.0;
for (uint32_t i = 0; i < it->second.size(); i++) {
tempAbsoluteDiff += it->second.at(i);
}
absoluteDiff += (tempAbsoluteDiff / it->second.size());
numNeighbors++;
}
absoluteDiff /= numNeighbors;
return (absoluteDiff > 1.0) ? 1.0 : absoluteDiff;
*/
// old version
//if (neighborCache.size() < 2 || sampleSize == 0) return 1.0;
double absoluteDiff = 0;
uint32_t numNeighbors = 0;
uint32_t sampleSize = 10; //test
for (std::map<simtime_t, TransportAddress>::reverse_iterator it =
it != neighborCacheExpireMap.rend() &&
numNeighbors < sampleSize; ++it) {
NeighborCacheEntry& cacheEntry = neighborCache[it->second];
double dist = ncs->getOwnNcsInfo().getDistance(*cacheEntry.coordsInfo);
if (dist != 0 && cacheEntry.rttState == RTTSTATE_VALID) {
double predictionError = fabs(dist - SIMTIME_DBL(cacheEntry.rtt));
//test: error weighted
//if (it->second.coordErr < 1) {
// predictionError /= it->second.coordErr;
//}
//test: age weighted
//if ((simTime() - it->second.insertTime) > 1) {
// predictionError /= (simTime() - it->second.insertTime);
//}
numNeighbors++;
absoluteDiff += predictionError;
}
}
assert(numNeighbors != 0);
absoluteDiff /= numNeighbors;
return (absoluteDiff > 1.0) ? 1.0 : absoluteDiff;
}
const TransportAddress & NeighborCache::getBootstrapNode ( )

Definition at line 1172 of file NeighborCache.cc.

{
//TODO failed bootstrap nodes are only detected and removed from nc
// if rpcs are used for joining
// return close node (discovery mode)
if (closestNodes) {
for (uint16_t i = 0; i < closestNodes->size(); ++i) {
if (neighborCache.count((*closestNodes)[i]) > 0 &&
neighborCache[(*closestNodes)[i]].rttState == RTTSTATE_VALID) {
//std::cout << (*closestNodes)[i].getProx().proximity << "\n"<< std::endl;
return (*closestNodes)[i];
}
}
}
// return known alive node
if (neighborCache.size() > 0) {
while (it != neighborCache.end() &&
it->second.rttState != RTTSTATE_VALID) ++it;
if (it != neighborCache.end()) {
return neighborCache.begin()->first;
}
}
}
std::vector< TransportAddress > * NeighborCache::getClosestNodes ( uint8_t  number)

Definition at line 558 of file NeighborCache.cc.

Referenced by DiscoveryMode::handleRpcCall().

{
std::vector<TransportAddress>* nodes =
new std::vector<TransportAddress>();
for (uint8_t i = 0; (i < number && i < closestNodes->size()); ++i) {
nodes->push_back((*closestNodes)[i]);
}
return nodes;
}
Prox NeighborCache::getCoordinateBasedProx ( const TransportAddress node)
private

Definition at line 1016 of file NeighborCache.cc.

Referenced by estimateProx(), and recordNcsEstimationError().

{
if (ncs && isEntry(node)) {
if (temp) return ncs->getCoordinateBasedProx(*temp);
}
}
std::pair< simtime_t, simtime_t > NeighborCache::getMeanVarRtt ( const TransportAddress node,
bool  returnVar 
)

Definition at line 1076 of file NeighborCache.cc.

Referenced by getRttBasedTimeout().

{
if (neighborCache.count(node) == 0) {
throw cRuntimeError("NeighborCache.cc: getMeanVarRtt was asked for"
"a non-existent node reference.");
}
uint16_t size = neighborCache[node].lastRtts.size();
if (size == 0) return std::make_pair(-1.0,-1.0);
simtime_t rttSum = 0;
for (int i = 0; i < size; i++){
rttSum += neighborCache[node].lastRtts[i];
}
simtime_t meanRtt = rttSum / size;
if (!returnVar) {
return std::make_pair(meanRtt, -1.0);
}
if (size == 1) {
return std::make_pair(meanRtt, 0.0);
}
double sum = 0.0;
for (int i = 0; i < size; i++){
simtime_t tempRtt = neighborCache[node].lastRtts.at(i) - meanRtt;
sum += (SIMTIME_DBL(tempRtt) * SIMTIME_DBL(tempRtt));
}
return std::make_pair(meanRtt, (sum / size));
}
const AbstractNcs& NeighborCache::getNcsAccess ( ) const
inline
simtime_t NeighborCache::getNcsBasedTimeout ( const NodeHandle node)
protected

Definition at line 1145 of file NeighborCache.cc.

Referenced by getNodeTimeout().

{
double timeout = -1;
// check if an entry is available in NeighborCache
if (isEntry(node)) {
if (prox != Prox::PROX_UNKNOWN && prox != Prox::PROX_TIMEOUT &&
prox.proximity > 0 && prox.accuracy > timeoutAccuracyLimit) {
timeout = prox.proximity + (6 * (1 - prox.accuracy));
} else return -1;
if (/*timeout > SIMTIME_DBL(defaultTimeout) ||*/ timeout < 0)
return -1;
}
return timeout;
}
TransportAddress NeighborCache::getNearestNode ( uint8_t  maxLayer)

Definition at line 537 of file NeighborCache.cc.

{
simtime_t nearestNodeRtt = MAXTIME;
for(it = neighborCache.begin(); it != neighborCache.end(); it++ ) {
if (it->second.rtt < nearestNodeRtt &&
it->second.rtt > 0 /*&&
it->second.coordsInfo.npsLayer < maxLayer+1 &&
it->second.coordsInfo.npsLayer > 0*/) {
nearestNode.setIp(it->first.getIp());
nearestNodeRtt = it->second.rtt;
nearestNode.setPort(it->second.nodeRef.getPort());
}
}
return nearestNode;
}
uint16_t NeighborCache::getNeighborCacheSize ( )
inline

Definition at line 271 of file NeighborCache.h.

{ return neighborCache.size(); };
simtime_t NeighborCache::getNodeAge ( const TransportAddress handle)

Definition at line 492 of file NeighborCache.cc.

Referenced by getProx().

{
if (neighborCache.count(address) == 0) {
throw cRuntimeError("NeighborCache.cc: getNodeAge was asked for "
"a non-existent address.");
}
return neighborCache[address].insertTime;
}
NeighborCache::WaitingContexts NeighborCache::getNodeContexts ( const TransportAddress handle)
private

Definition at line 278 of file NeighborCache.cc.

Referenced by setNodeTimeout(), and updateNode().

{
if (neighborCache.count(handle) == 0)
throw cRuntimeError("NeighborCache error!");
WaitingContexts temp = neighborCache[handle].waitingContexts;
neighborCache[handle].waitingContexts.clear();
return temp;
}
const AbstractNcsNodeInfo * NeighborCache::getNodeCoordsInfo ( const TransportAddress node)

Returns the coordinate information of a node.

Parameters
nodeThe node whose coordinate information will be requested.
Returns
The coordinate information.

Definition at line 1026 of file NeighborCache.cc.

Referenced by Nps::coordsReqRpcResponse(), and getCoordinateBasedProx().

{
if (neighborCache.count(node) == 0) {
throw cRuntimeError("NeighborCache.cc: getNodeCoords was asked for "
"a non-existent node reference.");
}
return neighborCache[node].coordsInfo;
}
const NodeHandle & NeighborCache::getNodeHandle ( const TransportAddress add)

Definition at line 483 of file NeighborCache.cc.

{
if (neighborCache.count(add) == 0) {
throw cRuntimeError("NeighborCache.cc: getNodeHandle was asked for "
"a non-existent node reference.");
}
return neighborCache[add].nodeRef;
}
NeighborCache::Rtt NeighborCache::getNodeRtt ( const TransportAddress add)
private

Definition at line 457 of file NeighborCache.cc.

Referenced by Nps::coordsReqRpcResponse(), estimateProx(), and getProx().

{
// cache disabled or entry not there
add.isUnspecified() ||
(neighborCache.count(add) == 0)) {
misses++;
return std::make_pair(0.0, RTTSTATE_UNKNOWN);
}
NeighborCacheEntry &entry = neighborCache[add];
if (entry.rttState == RTTSTATE_WAITING ||
entry.rttState == RTTSTATE_UNKNOWN)
return std::make_pair(entry.rtt, entry.rttState);
// entry expired
if ((simTime() - entry.insertTime) >= rttExpirationTime) {
entry.rttState = RTTSTATE_UNKNOWN;
return std::make_pair(entry.rtt, RTTSTATE_UNKNOWN);
}
hits++;
assert(!(entry.rtt == 0.0 && entry.rttState == RTTSTATE_VALID));
return std::make_pair(entry.rtt, entry.rttState);
}
simtime_t NeighborCache::getNodeTimeout ( const NodeHandle node)

Caclulation of reasonable timout value.

Parameters
nodethe node an RPC is sent to
Returns
recommended timeout value

Definition at line 1109 of file NeighborCache.cc.

Referenced by BaseRpc::sendRpcCall().

{
simtime_t timeout = getRttBasedTimeout(node);
if (timeout == -1 && useNcsForTimeout && ncs) return getNcsBasedTimeout(node);
return timeout;
}
const NodeHandle& NeighborCache::getOverlayThisNode ( )
inline

Definition at line 269 of file NeighborCache.h.

Referenced by SimpleNcs::init().

{ return overlay->getThisNode(); };
Prox NeighborCache::getProx ( const TransportAddress node,
NeighborCacheQueryType  type = NEIGHBORCACHE_AVAILABLE,
int  rpcId = -1,
ProxListener listener = NULL,
cPolymorphic *  contextPointer = NULL 
)

Gets the proximity of a node.

Parameters
nodeThe node whose proximity will be requested.
typeRequest type. NEIGHBORCACHE_EXACT looks in the cache, and if no value is found, sends an RTT query to the node. NEIGHBORCACHE_AVAILABLE looks in the cache, and if no value is found returns Prox::PROX_UNKNOWN. NEIGHBORCACHE_ESTIMATED looks in the cache, and if no value is found calculates an estimate based on information collected by the overlay. NEIGHBORCACHE_QUERY always sends an RTT query to the node and returns Prox::PROX_UNKNOWN.
rpcIdIdentifier sent to the RPC to identify the call.
listenerModule to be called back when an RTT response arrives.
contextPointerPointer sent to the RPC to identify the call. IMPORTANT: contextPointer gets deleted (only) if no Ping call is sent! So, *contextpointer may be undefined!
Returns
The proximity value of node.

Definition at line 853 of file NeighborCache.cc.

Referenced by BasePastry::determineAliveTable(), getNcsBasedTimeout(), DiscoveryMode::handleRpcResponse(), Bamboo::lookupFinished(), BasePastry::pingNodes(), BasePastry::prePing(), and Kademlia::routingAdd().

{
Enter_Method("getProx()");
queryProx(node, rpcId, listener, contextPointer);
}
if (node == overlay->getThisNode()) {
delete contextPointer;
}
if (node.isUnspecified()) {
throw cRuntimeError("Prox queried for undefined TransportAddress!");
delete contextPointer;
}
bool sendQuery = false;
Rtt rtt = getNodeRtt(node);
//countGetProxTotal++;
switch(type) {
if (rtt.second == RTTSTATE_TIMEOUT) {
if (getNodeAge(node) == simTime()) {
// right now, we got a time-out, so no new ping is sent
} else{
// if timeout, return unknown???, and send a query!
sendQuery = true;
}
} else if (rtt.second == RTTSTATE_WAITING) {
// if a query was sent, return WAITING
sendQuery = true; //just inserting a context, no real ping is sent
} else if (rtt.second == RTTSTATE_UNKNOWN) {
// if no entry known, send a query and return UNKNOWN
result = Prox::PROX_WAITING; //???
sendQuery = true;
} else {
// else, return whatever we have
result = rtt.first;
}
break;
if (rtt.second == RTTSTATE_TIMEOUT) {
// if timeout, return that
} else if (rtt.second == RTTSTATE_WAITING) {
// if a query was sent, return WAITING;
sendQuery = true; //just inserting a context, no real ping is sent
} else if (rtt.second == RTTSTATE_UNKNOWN) {
// if no entry known, send a query and return UNKNOWN
result = Prox::PROX_WAITING; //???
sendQuery = true;
} else {
// else, return whatever we have
result = rtt.first;
}
break;
if (rtt.second == RTTSTATE_TIMEOUT) {
// if timeout, return that
} else if (rtt.second == RTTSTATE_WAITING) {
// if a query was sent, return an estimate
result = estimateProx(node);
} else if (rtt.second == RTTSTATE_UNKNOWN) {
// if no entry known, return an estimate
result = estimateProx(node);
} else {
// else return whatever we have
result = rtt.first;
}
break;
if (rtt.second == RTTSTATE_TIMEOUT) {
// if timeout, return that.
} else if (rtt.second == RTTSTATE_WAITING) {
// if a query was sent return WAITING
} else if (rtt.second == RTTSTATE_UNKNOWN) {
// if a query was sent return WAITING
} else {
// else return what we have
result = rtt.first;
}
break;
// simply send a query and return WAITING
sendQuery = true;
break;
default:
throw cRuntimeError("Unknown query type!");
break;
}
if (sendQuery) {
if (!insertNodeContext(node, contextPointer, listener, rpcId)) {
queryProx(node, rpcId, listener, contextPointer);
}
} else delete contextPointer;
return result;
}
simtime_t NeighborCache::getRttBasedTimeout ( const NodeHandle node)
protected

Definition at line 1118 of file NeighborCache.cc.

Referenced by getNodeTimeout().

{
simtime_t timeout = -1;
// check if an entry is available in NeighborCache
if (isEntry(node)) {
std::pair<simtime_t, simtime_t> temp = getMeanVarRtt(node, true);
simtime_t meanRtt = temp.first;
simtime_t varRtt = temp.second;
// TODO return value even if node has timed out
if (meanRtt == -1) return -1;
if (varRtt > 0) {
// like TCP
timeout = meanRtt + 4 * varRtt;
} else {
// only one RTT is available
timeout = meanRtt * 1.2;
}
// adjustment
//if (timeout > SIMTIME_DBL(defaultTimeout)) return -1;
}
return timeout;
}
std::vector< TransportAddress > * NeighborCache::getSpreadedNodes ( uint8_t  number)

Definition at line 570 of file NeighborCache.cc.

Referenced by DiscoveryMode::handleRpcCall().

{
std::vector<TransportAddress>* nodes =
new std::vector<TransportAddress>;
for (uint8_t i = 0; (i < number && i < neighborCache.size()); ++i) {
nodes->push_back((it++)->first);
}
/*if (dynamic_cast<BasePastry*>(overlay)) {
BasePastry* pastry = static_cast<BasePastry*>(overlay);
std::vector<TransportAddress>* spreadedNodes = pastry->get
}*/
return nodes;
}
virtual CompType NeighborCache::getThisCompType ( )
inlineprotectedvirtual

Return the component type of this module.

This method is overloaded by BaseOverlay/BaseApp and returns the appropriate component type of this module.

Returns
the component type of this module

Reimplemented from BaseApp.

Definition at line 225 of file NeighborCache.h.

Referenced by TreeManagement::checkTreeChildNodes(), TreeManagement::handleRpcTimeout(), TreeManagement::registerAtParent(), TreeManagement::sendChildReleaseCall(), Nps::sendCoordsReqCall(), TreeManagement::sendMessageToChildren(), TreeManagement::sendMessageToParent(), DiscoveryMode::sendNewRequest(), and DiscoveryMode::start().

{ return NEIGHBORCACHE_COMP; };
TreeManagement * NeighborCache::getTreeManager ( )

Returns a pointer to the treeManager Module.

Returns
treeManager Module

Definition at line 1167 of file NeighborCache.cc.

Referenced by GlobalViewBuilder::handleCoordSendTimer(), and GlobalViewBuilder::initializeViewBuilder().

{
return treeManager;
}
void NeighborCache::handleReadyMessage ( CompReadyMessage msg)
protectedvirtual

handle ready message - build tree topology

Reimplemented from BaseApp.

Definition at line 658 of file NeighborCache.cc.

{
// bootstrap list is ready
if (readyMsg->getReady() && readyMsg->getComp() == BOOTSTRAPLIST_COMP) {
} else {
// inform overlay
}
} else if (readyMsg->getReady() && readyMsg->getComp() == OVERLAY_COMP) {
// overlay is ready, build up tree
//std::cout << thisNode << "treeManager->startTreeBuilding()" << std::endl;
}
}
} //else {
//TODO
//}
delete readyMsg;
}
bool NeighborCache::handleRpcCall ( BaseCallMessage msg)
protectedvirtual

Coord / RTT measuring rpc stuff goes here.

Reimplemented from BaseRpc.

Definition at line 814 of file NeighborCache.cc.

{
bool messageHandled = false;//TODO
if (ncs && !messageHandled) {
messageHandled = ncs->handleRpcCall(msg); //TODO
}
if (discoveryMode && !messageHandled) {
messageHandled = discoveryMode->handleRpcCall(msg);
}
if (treeManager && !messageHandled) {
messageHandled = treeManager->handleRpcCall(msg);
if(globalViewBuilder && !messageHandled) {
messageHandled = globalViewBuilder->handleRpcCall(msg);
}
}
return messageHandled;
}
void NeighborCache::handleTimerEvent ( cMessage *  msg)
protectedvirtual

Reimplemented from BaseRpc.

Definition at line 780 of file NeighborCache.cc.

{
if (msg == cbrTimer) {
// TODO duplicate code
(dynamic_cast<SimpleNcs*>(ncs) || (dynamic_cast<SVivaldi*>(ncs) &&
static_cast<SVivaldi*>(ncs)->getLoss() > 0.95 &&
static_cast<SVivaldi*>(ncs)->getOwnError() < 0.2))) { //TODO
//std::cout << thisNode.getIp() << " NeighborCache::handleTimerEvent(): setCbrNodeId(); overlay->join(thisNode.getKey())" << std::endl;
return;
} else {
//assert(false);
return;
//scheduleAt(simTime() + uniform(0, 5000), cbrTimer); //TODO
}
return;
}
if (ncs) {
}
if (treeManager) {
}
}
}
void NeighborCache::initializeApp ( int  stage)
protectedvirtual

initializes derived class-attributes

Parameters
stagethe init stage

Reimplemented from BaseApp.

Definition at line 73 of file NeighborCache.cc.

{
if (stage == MAX_STAGE_COMPONENTS) {
neighborCache.clear();
enableNeighborCache = par("enableNeighborCache");
rttExpirationTime = par("rttExpirationTime");
maxSize = par("maxSize");
//doDiscovery = par("doDiscovery");
collectClosestNodes = par("collectClosestNodes");
ncsPiggybackOwnCoords = par("ncsPiggybackOwnCoords");
useNcsForTimeout = par("useNcsForTimeout");
// set default query types
std::string temp = par("defaultQueryType").stdstringValue();
if (temp == "exact")
else if (temp == "exact_timeout")
else if (temp == "available")
else if (temp == "estimated")
else throw cRuntimeError((std::string("Wrong query type: ")
+ temp).c_str());
temp = par("defaultQueryTypeI").stdstringValue();
if (temp == "available")
else if (temp == "estimated")
else throw cRuntimeError((std::string("Wrong query type (I): ")
+ temp).c_str());
temp = par("defaultQueryTypeQ").stdstringValue();
if (temp == "exact")
else if (temp == "exact_timeout")
else if (temp == "query")
else throw cRuntimeError((std::string("Wrong query type (Q): ")
+ temp).c_str());
temp = par("ncsType").stdstringValue();
if (temp == "none") ncs = NULL;
else if (temp == "vivaldi") ncs = new Vivaldi();
else if (temp == "svivaldi") ncs = new SVivaldi();
else if (temp == "gnp") ncs = new Nps(); //TODO
else if (temp == "nps") ncs = new Nps();
else if (temp == "simple") ncs = new SimpleNcs();
else if (temp == "simpleunderlayncs") ncs = new SimpleUnderlayNCS(); //TODO
else throw cRuntimeError((std::string("Wrong NCS type: ")
+ temp).c_str());
if (par("doDiscovery")) {
if (collectClosestNodes == 0) {
throw cRuntimeError("Discovery Mode with collectClosestNodes = 0");
}
} else {
discoveryMode = NULL;
}
WATCH_VECTOR(*closestNodes);
} else {
closestNodes = NULL;
}
treeManager = NULL;
if(par("treeMgmtEnableTreeManagement")) {
treeManager->init(this);
if(par("gvbEnableGlobalViewBuilder")) {
capReqFinished = false;
}
}
cbrTimer = new cMessage("cbrTimer");
misses = 0;
hits = 0;
rttHistory = par("rttHistory");
timeoutAccuracyLimit = par("timeoutAccuracyLimit");
numMsg = 0;
WATCH(absoluteError);
WATCH(relativeError);
WATCH(numMsg);
} else if (stage == MIN_STAGE_TIER_1) {
if (ncs) ncs->init(this);
}
}
bool NeighborCache::insertNodeContext ( const TransportAddress handle,
cPolymorphic *  context,
ProxListener rpcListener,
int  rpcId 
)
private

Definition at line 233 of file NeighborCache.cc.

Referenced by getProx().

{
if (!enableNeighborCache) return false;
if (neighborCache.count(handle) == 0) {
NeighborCacheEntry& entry = neighborCache[handle];
entry.insertTime = simTime();
entry.rttState = RTTSTATE_WAITING;
neighborCacheExpireMap.insert(std::make_pair(entry.insertTime,
handle));
assert(neighborCache.size() == neighborCacheExpireMap.size());
return false;
} else {
NeighborCacheEntry& entry = neighborCache[handle];
// waiting?
if (entry.rttState == RTTSTATE_WAITING) {
WaitingContext temp(rpcListener, context, rpcId);
entry.waitingContexts.push_back(temp);
return true;
} else {
if (entry.waitingContexts.size() > 0) {
throw cRuntimeError("not waiting for response,"
" but additional contexts found!");
}
updateEntry(handle, entry.insertTime);
entry.rttState = RTTSTATE_WAITING;
entry.insertTime = simTime();
return false;
}
}
}
bool NeighborCache::isEnabled ( )
inline

Definition at line 258 of file NeighborCache.h.

Referenced by BasePastry::baseInit().

{ return enableNeighborCache; };
bool NeighborCache::isEntry ( const TransportAddress node)

Definition at line 589 of file NeighborCache.cc.

Referenced by getCoordinateBasedProx(), getNcsBasedTimeout(), and getRttBasedTimeout().

{
if (neighborCache.count(node) > 0) return true;
return false;
}
bool NeighborCache::piggybackOwnCoords ( )
inline

Definition at line 262 of file NeighborCache.h.

Referenced by BaseRpc::sendRpcResponse().

{ return (ncsPiggybackOwnCoords && ncs != NULL); };
void NeighborCache::pingResponse ( PingResponse response,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)
private

Definition at line 836 of file NeighborCache.cc.

{
//treeManager->pingResponse(response, context, rpcId, rtt);
}
}
void NeighborCache::pingTimeout ( PingCall call,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId 
)
private

Definition at line 844 of file NeighborCache.cc.

{
//treeManager->pingTimeout(call, dest, context, rpcId);
}
}
void NeighborCache::prepareOverlay ( )
private

Definition at line 705 of file NeighborCache.cc.

Referenced by Nps::coordsReqRpcResponse(), handleReadyMessage(), GlobalViewBuilder::handleRpcResponse(), and DiscoveryMode::stop().

{
(!ncs || ncs->isReady())) {
((dynamic_cast<Nps*>(ncs) || dynamic_cast<SimpleNcs*>(ncs) ||
(dynamic_cast<SVivaldi*>(ncs) &&
static_cast<SVivaldi*>(ncs)->getLoss() > 0.95)))) { //TODO
return;
} else {
scheduleAt(uniform(coordBasedRouting->getChangeIdStart(),
cbrTimer); //TODO
}
}
}
return;
}
//std::cout << "nc" << std::endl;
(ncs && ncs->isReady())) {
const TransportAddress& bootstrapNode =
if (globalViewBuilder && !bootstrapNode.isUnspecified() && true) { //TODO
return;
}
// first node
scheduleAt(uniform(coordBasedRouting->getChangeIdStart(),
cbrTimer); //TODO
}
}
}
void NeighborCache::queryProx ( const TransportAddress node,
int  rpcId,
ProxListener listener,
cPolymorphic *  contextPointer 
)
protected

Sends a pingNode call based on parameters from a getProx call.

Parameters
nodeThe node to which the pingNode call will be sent.
rpcIdThe rpcId that was passed to getProx.
listenerThe listener that was passed to getProx.
contextPointerThe pointer that was passed to getProx.

Definition at line 991 of file NeighborCache.cc.

Referenced by getProx().

{
Enter_Method("queryProx()");
WaitingContext temp(listener, contextPointer, rpcId);
if (neighborCache.count(node) == 0) {
NeighborCacheEntry& entry = neighborCache[node];
entry.waitingContexts.push_back(temp);
neighborCacheExpireMap.insert(std::make_pair(entry.insertTime, node));
} else {
NeighborCacheEntry& entry = neighborCache[node];
entry.waitingContexts.push_back(temp);
}
assert(neighborCache.size() == neighborCacheExpireMap.size());
// TODO: this ping traffic is accounted application data traffic!
pingNode(node, -1, 0, NULL, "PING");
}
void NeighborCache::recordNcsEstimationError ( const NodeHandle handle,
simtime_t  rtt 
)
private

Definition at line 1036 of file NeighborCache.cc.

Referenced by updateNode().

{
if (!ncs) return;
// Check if data collection can start
if (!globalStatistics->isMeasuring()) return;
Prox prox = getCoordinateBasedProx(handle);
if (prox == Prox::PROX_UNKNOWN) return;
//calculate absolute rtt error of the last message
double tempRttError = prox.proximity - SIMTIME_DBL(rtt);
/*
std::cout << "prox.proximity = " << prox.proximity
<< ", SIMTIME_DBL(rtt) = " << SIMTIME_DBL(rtt)
<< ", error = " << tempRttError
<< ", relativeError = " << (tempRttError / SIMTIME_DBL(rtt))
<< std::endl;
*/
if (tempRttError < 0){
tempRttError *= -1;
numMsg++;
absoluteError += tempRttError;
relativeError += (tempRttError / SIMTIME_DBL(rtt));
globalStatistics->recordOutVector("NCS: measured RTTs",
SIMTIME_DBL(rtt));
globalStatistics->recordOutVector("NCS: absolute Rtt Error",
tempRttError);
globalStatistics->recordOutVector("NCS: relative Rtt Error",
(tempRttError / SIMTIME_DBL(rtt)));
}
void NeighborCache::setCbrNodeId ( )
private

Definition at line 753 of file NeighborCache.cc.

Referenced by handleTimerEvent(), and prepareOverlay().

{
const std::vector<double>& coords = ncs->getOwnNcsInfo().getCoords();
const AP* cap = (globalViewBuilder ? globalViewBuilder->getCAP() : NULL);
cap));
EV << "[NeighborCache::setCbrNodeId() @ "
<< " (" << thisNode.getKey().toString(16) << ")]"
<< "\n -> nodeID ( 2): "
<< "\n -> nodeID (16): "
<< thisNode.getKey().toString(16) << endl;
/*
std::cout << "[NeighborCache::setCbrNodeId() @ "
<< thisNode.getIp()
<< " (" << thisNode.getKey().toString(16) << ")]"
<< "\n -> nodeID ( 2): "
<< thisNode.getKey().toString(2)
<< "\n -> nodeID (16): "
<< thisNode.getKey().toString(16) << std::endl;*/
}
void NeighborCache::setNodeTimeout ( const TransportAddress handle)

Definition at line 289 of file NeighborCache.cc.

Referenced by BaseRpc::internalHandleRpcMessage().

{
//if (!enableNeighborCache) return;
if (neighborCache.count(handle) == 0) {
NeighborCacheEntry& entry = neighborCache[handle];
entry.insertTime = simTime();
entry.rttState = RTTSTATE_TIMEOUT;
neighborCacheExpireMap.insert(std::make_pair(entry.insertTime,
handle));
} else {
NeighborCacheEntry& entry = neighborCache[handle];
updateEntry(handle, entry.insertTime);
entry.insertTime = simTime();
entry.rttState = RTTSTATE_TIMEOUT;
WaitingContexts waitingContexts = getNodeContexts(handle);
for (uint32_t i = 0; i < waitingContexts.size(); ++i) {
assert(waitingContexts[i].proxListener || !waitingContexts[i].proxContext);
if (waitingContexts[i].proxListener) {
waitingContexts[i].proxListener->proxCallback(handle,
waitingContexts[i].id,
waitingContexts[i].proxContext,
}
}
}
assert(neighborCache.size() == neighborCacheExpireMap.size());
}
void NeighborCache::updateEntry ( const TransportAddress address,
simtime_t  insertTime 
)
private

Definition at line 524 of file NeighborCache.cc.

Referenced by insertNodeContext(), setNodeTimeout(), updateNcsInfo(), and updateNode().

{
neighborCacheExpireMap.lower_bound(insertTime);
while (it->second != address) ++it;
neighborCacheExpireMap.insert(std::make_pair(simTime(),
address));
assert(neighborCache.size() == neighborCacheExpireMap.size());
}
void NeighborCache::updateNcsInfo ( const TransportAddress node,
AbstractNcsNodeInfo ncsInfo 
)

Definition at line 421 of file NeighborCache.cc.

{
Enter_Method_Silent();
EV << "[NeighborCache::updateNcsInfo() @ " << thisNode.getIp()
<< " (" << thisNode.getKey().toString(16) << ")]\n"
<< " inserting new NcsInfo of node " << node.getIp()
<< endl;
if (neighborCache.count(node) == 0) {
NeighborCacheEntry& entry = neighborCache[node];
entry.insertTime = simTime();
entry.coordsInfo = ncsInfo;
neighborCacheExpireMap.insert(std::make_pair(entry.insertTime, node));
} else {
updateEntry(node, neighborCache[node].insertTime);
NeighborCacheEntry& entry = neighborCache[node];
if (ncsInfo) {
if (entry.coordsInfo) {
entry.coordsInfo->update(*ncsInfo);
delete ncsInfo;
} else {
entry.coordsInfo = ncsInfo;
}
}
}
}
void NeighborCache::updateNode ( const NodeHandle add,
simtime_t  rtt,
const NodeHandle srcRoute = NodeHandle::UNSPECIFIED_NODE,
AbstractNcsNodeInfo ncsInfo = NULL 
)

Definition at line 326 of file NeighborCache.cc.

Referenced by Nps::coordsReqRpcResponse(), and BaseRpc::internalHandleRpcMessage().

{
Enter_Method_Silent();
thisNode = overlay->getThisNode(); // Daniel TODO
EV << "[NeighborCache::updateNode() @ " << thisNode.getIp()
<< " (" << thisNode.getKey().toString(16) << ")]\n"
<< " inserting rtt(" << SIMTIME_DBL(rtt) << ") of node " << add.getIp()
<< endl;
if (rtt <= 0) {
delete ncsInfo;
return; //TODO broose
}
bool deleteInfo = false;
//if (enableNeighborCache) {
if (neighborCache.count(add) == 0) {
NeighborCacheEntry& entry = neighborCache[add];
if (closestNodes) {
//std::cout << "closestNodes->add(ProxTransportAddress(" << add << ", rtt));" << std::endl;
}
entry.insertTime = simTime();
entry.rtt = rtt;
entry.rttState = RTTSTATE_VALID;
entry.nodeRef = add;
entry.coordsInfo = ncsInfo;
entry.lastRtts.push_back(rtt);
neighborCacheExpireMap.insert(std::make_pair(entry.insertTime, add));
} else {
updateEntry(add, neighborCache[add].insertTime);
NeighborCacheEntry& entry = neighborCache[add];
if (closestNodes) {
//std::cout << "closestNodes->add(ProxTransportAddress(" << add << ", rtt));" << std::endl;
}
entry.insertTime = simTime();
if (entry.rttState != RTTSTATE_VALID || entry.rtt > rtt)
entry.rtt = rtt;
entry.rttState = RTTSTATE_VALID;
entry.nodeRef = add;
entry.lastRtts.push_back(rtt);
if (entry.lastRtts.size() > rttHistory) {
entry.lastRtts.pop_front();
}
if (ncsInfo) {
if (entry.coordsInfo) {
entry.coordsInfo->update(*ncsInfo);
deleteInfo = true;
} else {
entry.coordsInfo = ncsInfo;
}
}
WaitingContexts waitingContexts = getNodeContexts(add);
for (uint32_t i = 0; i < waitingContexts.size(); ++i) {
if (waitingContexts[i].proxListener) {
waitingContexts[i].proxListener
->proxCallback(add,
waitingContexts[i].id,
waitingContexts[i].proxContext,
Prox(rtt, 1));
}
}
}
assert(neighborCache.size() == neighborCacheExpireMap.size());
if (ncs) ncs->processCoordinates(rtt, *ncsInfo);
// delete ncsInfo if old info is used
if (deleteInfo) delete ncsInfo;
}

Friends And Related Function Documentation

friend class DiscoveryMode
friend

Definition at line 84 of file NeighborCache.h.

Referenced by initializeApp().

friend class GlobalViewBuilder
friend

Definition at line 83 of file NeighborCache.h.

Referenced by initializeApp().

friend class Nps
friend

Definition at line 80 of file NeighborCache.h.

Referenced by initializeApp().

std::ostream& operator<< ( std::ostream &  os,
const NeighborCacheEntry entry 
)
friend

Definition at line 45 of file NeighborCache.cc.

{
if (entry.rttState == NeighborCache::RTTSTATE_VALID) {
os << entry.rtt;
} else {
if (entry.rttState == NeighborCache::RTTSTATE_TIMEOUT) os << "TIMEOUT";
else if (entry.rttState == NeighborCache::RTTSTATE_UNKNOWN) os << "UNKNOWN";
else if (entry.rttState == NeighborCache::RTTSTATE_WAITING) os << "WAITING";
}
os << " (inserted: " << entry.insertTime;
os << ", #contexts: "
<< entry.waitingContexts.size();
if (!entry.nodeRef.isUnspecified()) os << ", <KEY>";
//TODO entry.coordsInfo
os << ")";
return os;
}
friend class SimpleUnderlayNCS
friend

Definition at line 81 of file NeighborCache.h.

Referenced by initializeApp().

friend class TreeManagement
friend

Definition at line 82 of file NeighborCache.h.

Referenced by initializeApp().

Member Data Documentation

double NeighborCache::absoluteError
private

Definition at line 132 of file NeighborCache.h.

Referenced by finishApp(), initializeApp(), and recordNcsEstimationError().

bool NeighborCache::capReqFinished
private

Definition at line 106 of file NeighborCache.h.

Referenced by initializeApp().

cMessage* NeighborCache::cbrTimer
private

Definition at line 124 of file NeighborCache.h.

Referenced by handleTimerEvent(), initializeApp(), prepareOverlay(), and ~NeighborCache().

ProxAddressVector* NeighborCache::closestNodes
protected
uint8_t NeighborCache::collectClosestNodes
private

Definition at line 90 of file NeighborCache.h.

Referenced by initializeApp().

CoordBasedRouting* NeighborCache::coordBasedRouting
private

Definition at line 115 of file NeighborCache.h.

Referenced by initializeApp(), prepareOverlay(), and setCbrNodeId().

const std::vector< double > NeighborCache::coordsDummy
staticprivate

Definition at line 126 of file NeighborCache.h.

NeighborCacheQueryType NeighborCache::defaultQueryType
private

Definition at line 117 of file NeighborCache.h.

Referenced by getProx(), and initializeApp().

NeighborCacheQueryType NeighborCache::defaultQueryTypeI
private

Definition at line 118 of file NeighborCache.h.

Referenced by getProx(), and initializeApp().

NeighborCacheQueryType NeighborCache::defaultQueryTypeQ
private

Definition at line 119 of file NeighborCache.h.

Referenced by getProx(), and initializeApp().

bool NeighborCache::discoveryFinished
private

Definition at line 93 of file NeighborCache.h.

Referenced by initializeApp().

DiscoveryMode* NeighborCache::discoveryMode
private
bool NeighborCache::enableNeighborCache
private

Definition at line 88 of file NeighborCache.h.

Referenced by getNodeRtt(), getProx(), initializeApp(), insertNodeContext(), and isEnabled().

GlobalViewBuilder* NeighborCache::globalViewBuilder
private
uint32_t NeighborCache::hits
private

Definition at line 96 of file NeighborCache.h.

Referenced by finishApp(), getNodeRtt(), and initializeApp().

cMessage* NeighborCache::landmarkTimer
private

Definition at line 123 of file NeighborCache.h.

std::map<TransportAddress, std::vector<double> > NeighborCache::lastAbsoluteErrorPerNode
private

Definition at line 130 of file NeighborCache.h.

Referenced by initializeApp().

uint32_t NeighborCache::maxSize
private

Definition at line 92 of file NeighborCache.h.

Referenced by cleanupCache(), and initializeApp().

uint32_t NeighborCache::misses
private

Definition at line 95 of file NeighborCache.h.

Referenced by finishApp(), getNodeRtt(), and initializeApp().

const double NeighborCache::NCS_TIMEOUT_CONSTANT = 0.350
staticprivate

Definition at line 180 of file NeighborCache.h.

Referenced by getNcsBasedTimeout().

bool NeighborCache::ncsPiggybackOwnCoords
private

Definition at line 108 of file NeighborCache.h.

Referenced by initializeApp(), and piggybackOwnCoords().

std::multimap<simtime_t, TransportAddress> NeighborCache::neighborCacheExpireMap
protected
uint32_t NeighborCache::numMsg
private

Definition at line 131 of file NeighborCache.h.

Referenced by finishApp(), initializeApp(), and recordNcsEstimationError().

uint32_t NeighborCache::numRttErrorToHigh
private

Definition at line 134 of file NeighborCache.h.

Referenced by finishApp(), initializeApp(), and recordNcsEstimationError().

uint32_t NeighborCache::numRttErrorToLow
private

Definition at line 135 of file NeighborCache.h.

Referenced by finishApp(), initializeApp(), and recordNcsEstimationError().

StdProxComparator* NeighborCache::proxComparator
private

Definition at line 112 of file NeighborCache.h.

Referenced by initializeApp(), and ~NeighborCache().

double NeighborCache::relativeError
private

Definition at line 133 of file NeighborCache.h.

Referenced by finishApp(), initializeApp(), and recordNcsEstimationError().

const double NeighborCache::RTT_TIMEOUT_ADJUSTMENT = 1.3
staticprivate

Definition at line 179 of file NeighborCache.h.

Referenced by getRttBasedTimeout().

simtime_t NeighborCache::rttExpirationTime
private

Definition at line 91 of file NeighborCache.h.

Referenced by getNodeRtt(), and initializeApp().

uint32_t NeighborCache::rttHistory
private

Definition at line 136 of file NeighborCache.h.

Referenced by initializeApp(), and updateNode().

double NeighborCache::timeoutAccuracyLimit
private

Definition at line 137 of file NeighborCache.h.

Referenced by getNcsBasedTimeout(), and initializeApp().

bool NeighborCache::useNcsForTimeout
private

Definition at line 110 of file NeighborCache.h.

Referenced by getNodeTimeout(), and initializeApp().


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