forked from akeranen/the-one
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb0e088
commit aa06564
Showing
13 changed files
with
1,328 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package report; | ||
|
||
import java.util.List; | ||
|
||
import core.DTNHost; | ||
import core.Message; | ||
import core.MessageListener; | ||
|
||
public class EmDeliveredMessagesReport extends Report implements MessageListener { | ||
|
||
public static String HEADER = "# time ID size hopcount deliveryTime " + | ||
"fromHost toHost remainingTtl isResponse path"; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public EmDeliveredMessagesReport() { | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
write(HEADER); | ||
} | ||
|
||
/** | ||
* Returns the given messages hop path as a string | ||
* @param m The message | ||
* @return hop path as a string | ||
*/ | ||
private String getPathString(Message m) { | ||
|
||
if(m.getId().contains("EM")) { | ||
List<DTNHost> hops = m.getHops(); | ||
String str = m.getFrom().toString(); | ||
|
||
for (int i=1; i<hops.size(); i++) { | ||
str += "->" + hops.get(i); | ||
} | ||
|
||
return str; | ||
} | ||
return null; | ||
} | ||
|
||
public void messageTransferred(Message m, DTNHost from, DTNHost to, | ||
boolean firstDelivery) { | ||
|
||
if(m.getId().contains("EM")) { | ||
|
||
if (!isWarmupID(m.getId()) && firstDelivery) { | ||
int ttl = m.getTtl(); | ||
write(format(getSimTime()) + " " + m.getId() + " " + | ||
m.getSize() + " " + m.getHopCount() + " " + | ||
format(getSimTime() - m.getCreationTime()) + " " + | ||
m.getFrom() + " " + m.getTo() + " " + | ||
(ttl != Integer.MAX_VALUE ? ttl : "n/a") + | ||
(m.isResponse() ? " Y " : " N ") + getPathString(m)); | ||
} | ||
} | ||
} | ||
|
||
public void newMessage(Message m) { | ||
if (isWarmup()) { | ||
addWarmupID(m.getId()); | ||
} | ||
} | ||
|
||
// nothing to implement for the rest | ||
public void messageDeleted(Message m, DTNHost where, boolean dropped) {} | ||
public void messageTransferAborted(Message m, DTNHost from, DTNHost to) {} | ||
public void messageTransferStarted(Message m, DTNHost from, DTNHost to) {} | ||
|
||
@Override | ||
public void done() { | ||
super.done(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2010 Aalto University, ComNet | ||
* Released under GPLv3. See LICENSE.txt for details. | ||
*/ | ||
package report; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import core.DTNHost; | ||
import core.Message; | ||
import core.MessageListener; | ||
|
||
/** | ||
* Reports delivered messages' delays (one line per delivered message) | ||
* and cumulative delivery probability sorted by message delays. | ||
* Ignores the messages that were created during the warm up period. | ||
*/ | ||
public class EmMessageDelayReport extends Report implements MessageListener { | ||
public static final String HEADER = | ||
"# messageDelay cumulativeProbability"; | ||
/** all message delays */ | ||
private List<Double> delays; | ||
private int nrofCreated; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public EmMessageDelayReport() { | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
write(HEADER); | ||
this.delays = new ArrayList<Double>(); | ||
this.nrofCreated = 0; | ||
} | ||
|
||
public void newMessage(Message m) { | ||
if (isWarmup()) { | ||
addWarmupID(m.getId()); | ||
} | ||
else { | ||
if(m != null) { | ||
if(m.getAppID().contains("EM")) { | ||
this.nrofCreated++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void messageTransferred(Message m, DTNHost from, DTNHost to, | ||
boolean firstDelivery) { | ||
|
||
if(m.getAppID().contains("EM")) { | ||
if (firstDelivery && !isWarmupID(m.getId())) { | ||
this.delays.add(getSimTime() - m.getCreationTime()); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void done() { | ||
if (delays.size() == 0) { | ||
write("# no messages delivered in sim time "+format(getSimTime())); | ||
super.done(); | ||
return; | ||
} | ||
double cumProb = 0; // cumulative probability | ||
|
||
java.util.Collections.sort(delays); | ||
|
||
for (int i=0; i < delays.size(); i++) { | ||
cumProb += 1.0/nrofCreated; | ||
write(format(delays.get(i)) + " " + format(cumProb)); | ||
} | ||
super.done(); | ||
} | ||
|
||
// nothing to implement for the rest | ||
public void messageDeleted(Message m, DTNHost where, boolean dropped) {} | ||
public void messageTransferAborted(Message m, DTNHost from, DTNHost to) {} | ||
public void messageTransferStarted(Message m, DTNHost from, DTNHost to) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package report; | ||
|
||
import core.DTNHost; | ||
import core.Message; | ||
|
||
public class EmMessageDeliveryReport extends MessageDeliveryReport { | ||
|
||
public static String HEADER="# time created delivered delivered/created"; | ||
private int created; | ||
private int delivered; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public EmMessageDeliveryReport() { | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
created = 0; | ||
delivered = 0; | ||
write(HEADER); | ||
} | ||
|
||
public void messageTransferred(Message m, DTNHost from, DTNHost to, | ||
boolean firstDelivery) { | ||
|
||
if(m.getId().contains("EM")) { | ||
if (firstDelivery && !isWarmup() && !isWarmupID(m.getId())) { | ||
|
||
delivered++; | ||
reportValues(); | ||
} | ||
} | ||
} | ||
|
||
public void newMessage(Message m) { | ||
if (isWarmup()) { | ||
addWarmupID(m.getId()); | ||
return; | ||
} | ||
if(m.getId().contains("EM")) { | ||
created++; | ||
reportValues(); | ||
} | ||
} | ||
|
||
/** | ||
* Writes the current values to report file | ||
*/ | ||
private void reportValues() { | ||
double prob = (1.0 * delivered) / created; | ||
write(format(getSimTime()) + " " + created + " " + delivered + | ||
" " + format(prob)); | ||
} | ||
|
||
// nothing to implement for the rest | ||
public void messageDeleted(Message m, DTNHost where, boolean dropped) {} | ||
public void messageTransferAborted(Message m, DTNHost from, DTNHost to) {} | ||
public void messageTransferStarted(Message m, DTNHost from, DTNHost to) {} | ||
|
||
@Override | ||
public void done() { | ||
super.done(); | ||
} | ||
} |
Oops, something went wrong.