Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
9b550db0
Commit
9b550db0
authored
Nov 23, 2015
by
Nils Richerzhagen
Browse files
Worked on ChurnModel (Debug State)
parent
02dda393
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/churn/CSVBasedChurnModel.java
View file @
9b550db0
...
...
@@ -220,7 +220,7 @@ public class CSVBasedChurnModel implements ChurnModel {
if
(
parts
.
length
==
4
)
{
try
{
String
groupID
=
parts
[
0
].
replaceAll
(
"\\s+"
,
""
);
int
a
=
DefaultConfigurator
.
parseNumber
(
"20m"
,
Integer
.
class
);
//
int a = DefaultConfigurator.parseNumber("20m", Integer.class);
long
startTime
=
DefaultConfigurator
.
parseNumber
(
parts
[
1
].
replaceAll
(
"\\s+"
,
""
),
Long
.
class
);
long
endTime
=
DefaultConfigurator
.
parseNumber
(
parts
[
2
].
replaceAll
(
"\\s+"
,
""
),
Long
.
class
);
long
duration
=
DefaultConfigurator
.
parseNumber
(
parts
[
3
].
replaceAll
(
"\\s+"
,
""
),
Long
.
class
);
...
...
src/de/tud/kom/p2psim/impl/churn/FluctuatingPeerCountChurnModel.java
0 → 100644
View file @
9b550db0
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.churn
;
import
java.util.Comparator
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.PriorityQueue
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.churn.ChurnModel
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.network.SimNetInterface
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* random arrival/leaving rate during simulation for a prefixed interval
*
* Session length fix und nur arrival/leaving rate in lower und upper bound randoms
*
* @author Nils Richerzhagen
* @version 1.0, Feb 18, 2015
*/
public
class
FluctuatingPeerCountChurnModel
implements
ChurnModel
{
private
final
String
SEP
=
","
;
private
Map
<
Long
,
Long
>
churnInfos
;
private
double
upperFluctuationBound
;
/**
*
*/
private
double
lowerFluctuationBound
;
/**
* Maximum number of online clients for non-fluctuation phase.
*/
private
int
maxPeersOnline
;
/**
* Inter-arrival time as specified during configuration
*/
// private final long initialInterArrivalTime;
/*
* Parameters a and b of exponential distribution defining session lengths
*/
private
double
a
=
0.6378
;
private
double
b
=
-
0.05944
;
/**
* Minimum session length as specified during configuration
*/
private
long
minSessionLength
=
10
*
Time
.
SECOND
;
private
List
<
SimHost
>
hosts
;
private
final
Random
random
=
Randoms
.
getRandom
(
FluctuatingPeerCountChurnModel
.
class
);
private
long
lastJoin
=
-
1
;
private
Map
<
Long
,
ClientSessionInfo
>
clientSessionInfos
=
new
LinkedHashMap
<
Long
,
ClientSessionInfo
>();
private
PriorityQueue
<
ClientSessionInfo
>
clientsSortedByOfflineTime
;
@XMLConfigurableConstructor
({
"maxPeersOnline"
,
"upperFluctuationBound"
,
"lowerFluctuationBound"
})
public
FluctuatingPeerCountChurnModel
(
int
maxPeersOnline
,
double
upperFluctuationBound
,
double
lowerFluctuationBound
)
{
this
.
maxPeersOnline
=
maxPeersOnline
;
this
.
upperFluctuationBound
=
upperFluctuationBound
;
this
.
lowerFluctuationBound
=
lowerFluctuationBound
;
}
@Override
public
long
getNextUptime
(
SimHost
host
)
{
long
currentTime
=
Time
.
getCurrentTime
();
if
(!
hosts
.
remove
(
host
)){
/*
* FIXME: Avoiding reusing peer instances.
*/
return
1000
*
Time
.
HOUR
;
}
// TODO Current Fluctuation
if
(
clientsSortedByOfflineTime
.
size
()
<
maxPeersOnline
){
/*
* Initially, join peers until the peer threshold is reached.
*/
if
(
lastJoin
<
0
)
{
lastJoin
=
currentTime
;
}
// long currentJoin = lastJoin + initialInterArrivalTime;
// ClientSessionInfo info = new ClientSessionInfo(currentJoin);
// clientsSortedByOfflineTime.add(info);
// clientSessionInfos.put(host.getHostId(), info);
// if (hasFlashcrowd && !flashCrowdFinished
// && currentJoin > flashcrowdStart) {
// currentJoin = flashcrowdStart;
// inFlashcrowd = true;
// }
// lastJoin = currentJoin;
// return info.joiningAt - currentTime;
}
else
{
/*
* After reaching the peer threshold, only peers that went offline
* are replaced to keep the threshold.
*/
ClientSessionInfo
nextToGoOffline
=
clientsSortedByOfflineTime
.
poll
();
if
(
nextToGoOffline
==
null
)
{
throw
new
AssertionError
();
}
else
{
// Use the next time a peer goes offline as joining time.
long
currentJoin
=
nextToGoOffline
.
leavingAt
;
ClientSessionInfo
info
=
new
ClientSessionInfo
(
currentJoin
);
clientsSortedByOfflineTime
.
add
(
info
);
clientSessionInfos
.
put
(
host
.
getHostId
(),
info
);
// if (hasFlashcrowd && !flashCrowdFinished
// && currentJoin > flashcrowdStart) {
// currentJoin = flashcrowdStart;
// inFlashcrowd = true;
// }
lastJoin
=
currentJoin
;
return
info
.
joiningAt
-
currentTime
;
}
}
return
0
;
}
@Override
public
long
getNextDowntime
(
SimHost
host
)
{
return
0
;
}
@Override
public
void
prepare
(
List
<
SimHost
>
churnHosts
)
{
hosts
=
new
LinkedList
<
SimHost
>(
churnHosts
);
for
(
SimHost
host
:
churnHosts
)
{
for
(
SimNetInterface
netI
:
host
.
getNetworkComponent
()
.
getSimNetworkInterfaces
())
{
if
(
netI
.
isOnline
())
{
netI
.
goOffline
();
}
}
}
clientsSortedByOfflineTime
=
new
PriorityQueue
<
FluctuatingPeerCountChurnModel
.
ClientSessionInfo
>(
(
int
)
Math
.
ceil
(
hosts
.
size
()
/
10.0
),
COMP_OFFLINE_TIME
);
}
/**
* Comparator used to sort client infos by offline time
*/
private
static
final
Comparator
<
ClientSessionInfo
>
COMP_OFFLINE_TIME
=
new
Comparator
<
FluctuatingPeerCountChurnModel
.
ClientSessionInfo
>()
{
@Override
public
int
compare
(
ClientSessionInfo
o1
,
ClientSessionInfo
o2
)
{
return
((
Long
)
o1
.
leavingAt
).
compareTo
(
o2
.
leavingAt
);
}
};
protected
long
getSessionLength
(){
double
rnd
=
random
.
nextDouble
();
long
sessionLength
=
(
long
)
(
Math
.
log
(
rnd
/
a
)
/
b
)
*
Time
.
MINUTE
+
(
long
)
(
rnd
*
Time
.
MINUTE
);
/*
* The minimum session length is limited to avoid too short sessions
*/
return
Math
.
max
(
minSessionLength
+
(
long
)
(
rnd
*
Time
.
MINUTE
),
sessionLength
);
}
public
void
setMinSessionLength
(
long
minSessionLength
)
{
this
.
minSessionLength
=
minSessionLength
;
}
/**
* Client session information
*/
private
class
ClientSessionInfo
{
public
final
long
joiningAt
;
public
final
long
leavingAt
;
public
final
long
sessionLength
;
public
ClientSessionInfo
(
long
joiningAt
)
{
this
.
sessionLength
=
getSessionLength
();
this
.
joiningAt
=
joiningAt
;
this
.
leavingAt
=
joiningAt
+
sessionLength
;
}
}
}
src/de/tud/kom/p2psim/impl/churn/InteractiveChurnModel.java
0 → 100644
View file @
9b550db0
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.churn
;
import
java.util.List
;
import
de.tud.kom.p2psim.api.churn.ChurnModel
;
import
de.tud.kom.p2psim.api.common.SimHost
;
/**
* This {@link ChurnModel} is used for DEMO purposes in which the user can change the arrival/leaving rate in an interactive manner.
*
* TODO Based on visualization input! Include that here?
*
* @author Nils Richerzhagen
* @version 1.0, Nov 23, 2015
*/
public
class
InteractiveChurnModel
implements
ChurnModel
{
@Override
public
long
getNextUptime
(
SimHost
host
)
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
long
getNextDowntime
(
SimHost
host
)
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
void
prepare
(
List
<
SimHost
>
churnHosts
)
{
// TODO Auto-generated method stub
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment