OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
MyOverlay.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3
//
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License
6
// as published by the Free Software Foundation; either version 2
7
// of the License, or (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
//
18
23
#ifndef _MYOVERLAY_
24
#define _MYOVERLAY_
25
26
#include "
BaseOverlay.h
"
27
28
class
MyOverlay
:
public
BaseOverlay
29
{
30
private
:
31
// RPC timer
32
cMessage *
rpcTimer
;
33
34
// Routing parameters
35
int
myKey
;
// our overlay key
36
NodeHandle
prevNode
;
// next node in chain
37
NodeHandle
nextNode
;
// previous node in chain
38
39
//module parameters
40
double
dropChance
;
// we'll store the "dropChance" parameter here
41
42
// statistics
43
int
numDropped
;
// how many packets have we dropped?
44
45
// routine for RPC timer
46
void
handleTimerEvent
(cMessage *msg);
47
48
// overlay routines
49
void
initializeOverlay
(
int
stage);
// called when the overlay is being initialized
50
void
setOwnNodeID
();
// (optional) called to set the key of this node (random otherwise)
51
void
joinOverlay
();
// called when the node is ready to join the overlay
52
void
finishOverlay
();
// called when the module is about to be destroyed
53
54
// obligatory: called when we need the next hop to route a packet to the given key
55
NodeVector
*
findNode
(
const
OverlayKey
& key,
// key to route to
56
int
numRedundantNodes,
// how many candidates for next hop we want (see getMaxNumSiblings)
57
int
numSiblings,
// how many siblings we'll return (?) (see getMaxRedundantNodes)
58
BaseOverlayMessage
* msg);
// message being routed
59
60
// obligatory: In general, called when we need to know whether node is amongst numSiblings closest nodes to key.
61
// But normally it is called with node set to thisNode, and asking whether this node is responsible for key.
62
bool
isSiblingFor
(
const
NodeHandle
& node,
// which node (usually thisNode) we're referring to
63
const
OverlayKey
& key,
// key in question
64
int
numSiblings,
// how many siblings we're querying about
65
bool
* err);
// set to false when we couldn't determine the range
66
67
// obligatory: Set the maximum number of siblings that can be queried about (usually 1)
68
int
getMaxNumSiblings
();
69
70
// obligatory: Set the maximum number of redundant nodes that can be queried about (usually 1)
71
int
getMaxNumRedundantNodes
();
72
73
// Our RPC interface
74
// asynchronously request the neighbors of neighborKey
75
void
getNeighbors
(
const
OverlayKey
& neighborKey);
76
// function to call to respond about the queried neighbors
77
virtual
void
callbackNeighbors
(
const
NodeHandle
& neighborKey,
78
const
NodeHandle
& prevNeighbor,
79
const
NodeHandle
& nextNeighbor);
80
// function to call if the query times out
81
virtual
void
callbackTimeout
(
const
OverlayKey
&neighborKey);
82
83
// internal handling of RPCs
84
bool
handleRpcCall
(
BaseCallMessage
*msg);
// called when we receive an RPC from another node
85
void
handleRpcResponse
(
BaseResponseMessage
* msg,
// called when we receive an RPC response from another node
86
cPolymorphic* context,
87
int
rpcId,
88
simtime_t rtt);
89
void
handleRpcTimeout
(
BaseCallMessage
* msg,
// called when an RPC times out
90
const
TransportAddress
& dest,
91
cPolymorphic* context,
int
rpcId,
92
const
OverlayKey
&);
93
94
public
:
95
MyOverlay
() {
rpcTimer
= NULL; };
96
~MyOverlay
() { cancelAndDelete(
rpcTimer
); };
97
};
98
99
#endif
src
overlay
myoverlay
MyOverlay.h
Generated on Fri Dec 7 2012 13:37:52 for OverSim by
1.8.1.2