-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectivityONEReport.java
69 lines (59 loc) · 1.72 KB
/
ConnectivityONEReport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2010 Aalto University, ComNet
* Released under GPLv3. See LICENSE.txt for details.
*/
package report;
import core.ConnectionListener;
import core.DTNHost;
/**
* Link connectivity report generator for ONE StandardEventsReader input.
* Connections that start during the warm up period are ignored.
*/
public class ConnectivityONEReport extends Report
implements ConnectionListener {
/**
* Constructor.
*/
public ConnectivityONEReport() {
init();
}
public void hostsConnected(DTNHost h1, DTNHost h2) {
if (isWarmup()) {
addWarmupID(connectionString(h1, h2));
return;
}
newEvent();
write(createTimeStamp() + " CONN " + connectionString(h1, h2) + " up");
}
public void hostsDisconnected(DTNHost h1, DTNHost h2) {
String conString = connectionString(h1, h2);
if (isWarmup() || isWarmupID(conString)) {
removeWarmupID(conString);
return;
}
write(createTimeStamp() + " CONN " + conString + " down");
}
/**
* Creates and returns a "@" prefixed time stamp of the current simulation
* time
* @return time stamp of the current simulation time
*/
private String createTimeStamp() {
return String.format("%.2f", getSimTime());
}
/**
* Creates and returns a String presentation of the connection where the
* node with the lower network address is first
* @param h1 The other node of the connection
* @param h2 The other node of the connection
* @return String presentation of the connection
*/
private String connectionString(DTNHost h1, DTNHost h2) {
if (h1.getAddress() < h2.getAddress()) {
return h1.getAddress() + " " + h2.getAddress();
}
else {
return h2.getAddress() + " " + h1.getAddress();
}
}
}