您的位置:首页 > 编程语言

report代码分析2——ConnectivityDtnsim2Report,ConnectivityONEReport

2015-11-13 16:25 447 查看
ConnectivityDtnsim2Report
DTNSim2输入,产生 连通性报告(

记录连接的信息,生成两个节点的连接情况 )

outline



public class ConnectivityDtnsim2Report extends Report implements ConnectionListener {

//构造方法,初始化报告输出

public ConnectivityDtnsim2Report() {
init();
}

在父类中:

protected void init() {
this.lastReportTime = getSimTime();

if (outputInterval > 0) {

createSuffixedOutput(outFileName);

}
else {

createOutput(outFileName);

}
}

//当两主机相连时

public void hostsConnected(DTNHost h1, DTNHost h2) {
if (isWarmup()) {
addWarmupID(connectionString(h1, h2));
return;
}

newEvent();
//调用父类方法,This method should be called before every new (complete) event the report logs

write(createTimeStamp() + " " + connectionString(h1, h2) + " up");

}

//当两主机断开连接时

public void hostsDisconnected(DTNHost h1, DTNHost h2) {
String conString = connectionString(h1, h2);

if (isWarmup() || isWarmupID(conString)) {
removeWarmupID(conString);
return;
}

newEvent();
write(createTimeStamp() + " " + conString + " down");

}

//生成并返回一个@前缀的当前模拟时间

private String createTimeStamp() {
return String.format("@%.2f", getSimTime());
}

//生成并返回一个表示两节点连接的字串,小的网络地址节点在前

private String connectionString(DTNHost h1, DTNHost h2) {
if (h1.getAddress() < h2.getAddress()) {
return h1 + " <-> " + h2;
}
else {
return h2 + " <-> " + h1;
}
}

}

ConnectivityONEReport

ONE StandardEventsReader输入,产生连通性报告
操作连接的时间(断开和请求),连接的两个节点和状态(up是连接,down是断开)类似于ConnectivityDtnsim2Report
outline



public class ConnectivityONEReport extends Report implements ConnectionListener {

//构造方法,初始化

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");
}

//获取当前时间

private String createTimeStamp() {
return String.format("%.2f", getSimTime());
}

//连接字符串

private String connectionString(DTNHost h1, DTNHost h2) {
if (h1.getAddress() < h2.getAddress()) {
return h1.getAddress() + " " + h2.getAddress();
}
else {
return h2.getAddress() + " " + h1.getAddress();
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: