OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
RecursiveLookup.cc
Go to the documentation of this file.
1
//
2
// Copyright (C) 2008 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
24
#include <
CommonMessages_m.h
>
25
26
#include <
BaseOverlay.h
>
27
#include <
LookupListener.h
>
28
29
#include <
RecursiveLookup.h
>
30
31
RecursiveLookup::RecursiveLookup
(
BaseOverlay
* overlay,
32
RoutingType
routingType,
33
const
RecursiveLookupConfiguration
& config,
34
bool
appLookup) :
35
overlay(overlay),
36
routingType(routingType),
37
redundantNodes(config.redundantNodes),
38
numRetries(config.numRetries),
39
appLookup(appLookup)
40
{
41
valid
=
false
;
42
}
43
44
RecursiveLookup::~RecursiveLookup
()
45
{
46
if
(
listener
!= NULL) {
47
delete
listener
;
48
listener
= NULL;
49
}
50
51
overlay
->
removeLookup
(
this
);
52
}
53
54
void
RecursiveLookup::lookup
(
const
OverlayKey
& key,
int
numSiblings,
55
int
hopCountMax,
int
retries,
56
LookupListener
* listener)
57
{
58
this->listener =
listener
;
59
60
FindNodeCall
* call =
new
FindNodeCall
(
"FindNodeCall"
);
61
if
(
appLookup
) call->
setStatType
(
APP_LOOKUP_STAT
);
62
else
call->
setStatType
(
MAINTENANCE_STAT
);
63
call->
setLookupKey
(key);
64
call->
setNumRedundantNodes
(
redundantNodes
);
65
call->
setNumSiblings
(numSiblings);
66
call->setBitLength(
FINDNODECALL_L
(call));
67
68
nonce
=
overlay
->
sendRouteRpcCall
(
OVERLAY_COMP
, key, call, NULL,
69
routingType
, -1, retries, -1,
this
);
70
}
71
72
const
NodeVector
&
RecursiveLookup::getResult
()
const
73
{
74
return
siblings
;
75
}
76
77
bool
RecursiveLookup::isValid
()
const
78
{
79
return
valid
;
80
}
81
82
void
RecursiveLookup::abortLookup
()
83
{
84
overlay
->
cancelRpcMessage
(
nonce
);
85
86
delete
this
;
87
}
88
89
uint32_t
RecursiveLookup::getAccumulatedHops
()
const
90
{
91
//throw new cRuntimeError("RecursiveLookup is asked for # accumulated hops!");
92
return
0;
//TODO hopCount in findNodeCall/Response ?
93
}
94
95
void
RecursiveLookup::handleRpcTimeout
(
BaseCallMessage
* msg,
96
const
TransportAddress
& dest,
97
cPolymorphic* context,
int
rpcId,
98
const
OverlayKey
& destKey)
99
{
100
//TODO retry
101
valid
=
false
;
102
103
// inform listener
104
if
(
listener
!= NULL) {
105
listener
->
lookupFinished
(
this
);
106
listener
= NULL;
107
}
108
109
delete
this
;
110
}
111
112
void
RecursiveLookup::handleRpcResponse
(
BaseResponseMessage
* msg,
113
cPolymorphic* context,
int
rpcId,
114
simtime_t rtt)
115
{
116
FindNodeResponse
* findNodeResponse = check_and_cast<
FindNodeResponse
*>(msg);
117
118
if
(findNodeResponse->
getSiblings
() &&
119
findNodeResponse->
getClosestNodesArraySize
() > 0) {
120
valid
=
true
;
121
for
(uint32_t i = 0; i < findNodeResponse->
getClosestNodesArraySize
();
122
i++) {
123
siblings
.push_back(findNodeResponse->
getClosestNodes
(i));
124
}
125
}
126
127
// std::cout << "RecursiveLookup::handleRpcResponse() "
128
// << findNodeResponse->getClosestNodesArraySize() << std::endl;
129
130
// inform listener
131
if
(
listener
!= NULL) {
132
listener
->
lookupFinished
(
this
);
133
listener
= NULL;
134
}
135
delete
this
;
136
}
src
common
RecursiveLookup.cc
Generated on Fri Dec 7 2012 13:37:53 for OverSim by
1.8.1.2