OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
GiaTokenFactory.cc
Go to the documentation of this file.
1
//
2
// Copyright (C) 2006 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 <assert.h>
25
26
#include "
GiaTokenFactory.h
"
27
#include "
Gia.h
"
28
29
30
Define_Module
(
GiaTokenFactory
);
31
32
33
void
GiaTokenFactory::initialize
(
int
stage )
34
{
35
// wait until IPAddressResolver finished his initialization
36
if
(stage !=
MIN_STAGE_OVERLAY
)
37
return
;
38
39
gia
= check_and_cast<
Gia
*>(getParentModule()->getSubmodule(
"gia"
));
40
41
stat_sentTokens
= 0;
42
43
WATCH(stat_sentTokens);
44
WATCH_VECTOR(
tokenQueueVector
);
45
}
46
47
void
GiaTokenFactory::handleMessages
( cMessage* msg )
48
{
49
error
(
"this module doesn't handle messages, it runs only in initialize()"
);
50
}
51
52
void
GiaTokenFactory::setNeighbors
(
GiaNeighbors
* nghbors )
53
{
54
neighbors
= nghbors;
55
}
56
57
void
GiaTokenFactory::setMaxHopCount
( uint32_t maxHopCount)
58
{
59
this->maxHopCount =
maxHopCount
;
60
}
61
62
void
GiaTokenFactory::grantToken
()
63
{
64
if
(
neighbors
->
getSize
() == 0)
return
;
65
66
// create priority queue
67
createPriorityQueue
();
68
69
// update sentTokenCount at node on top of priority queue
70
updateSentTokens
();
71
72
// send token to top of queue
73
assert(
tokenQueue
.size() );
74
assert( !
tokenQueue
.top().node.isUnspecified() );
75
gia
->
sendToken
(
tokenQueue
.top().node);
76
77
// increse statistic variable
78
stat_sentTokens
++;
79
80
updateQueueVector
();
81
}
82
83
void
GiaTokenFactory::createPriorityQueue
()
84
{
85
clearTokenQueue
();
86
for
(uint32_t i = 0; i <
neighbors
->
getSize
(); i++ ) {
87
FullGiaNodeInfo
temp;
88
temp.
node
=
neighbors
->
get
(i);
89
temp.
info
=
neighbors
->
get
(temp.
node
);
90
//temp.setCapacity(tempInfo->capacity);
91
//temp.setSentTokens(tempInfo->sentTokens);
92
93
tokenQueue
.push(temp);
94
}
95
}
96
97
void
GiaTokenFactory::clearTokenQueue
()
98
{
99
while
( !
tokenQueue
.empty() )
100
tokenQueue
.pop();
101
}
102
103
void
GiaTokenFactory::updateQueueVector
()
104
{
105
// fill tokenQueueVector
106
tokenQueueVector
.clear();
107
while
(!
tokenQueue
.empty()) {
108
tokenQueueVector
.push_back(
tokenQueue
.top().node);
109
tokenQueue
.pop();
110
}
111
}
112
113
void
GiaTokenFactory::updateSentTokens
()
114
{
115
if
(
tokenQueue
.empty())
return
;
116
117
tokenQueue
.top().info->sentTokens++;
118
}
119
120
bool
GiaTokenFactory::tokenCompareGiaNode::operator()
(
const
FullGiaNodeInfo
& x,
121
const
FullGiaNodeInfo
& y)
122
{
123
if
(x.
info
->
sentTokens
> y.
info
->
sentTokens
)
124
return
true
;
125
if
(x.
info
->
sentTokens
== y.
info
->
sentTokens
)
126
if
(x.
node
.
getCapacity
() < y.
node
.
getCapacity
())
//???
127
return
true
;
128
return
false
;
129
}
src
overlay
gia
GiaTokenFactory.cc
Generated on Fri Dec 7 2012 13:37:52 for OverSim by
1.8.1.2