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();
}
}
}
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();
}
}
}
相关文章推荐
- Pycharm 新手一进去全是小波浪的非重要报错(PEP8)
- JAVA I/O输入输出流详解
- Java SE__java代码注释规范
- MyEclipse注册
- 从头认识java-8.10 接口里面的类
- rvm实现一个系统同时运行多个ruby版本项目(用于解决一个服务器部署多个ruby版本项目的实现)
- python 函数参数
- report包中的类及代码分析
- C、C++中union用法总结
- C语言:使用冒泡排序,排序多个字符串(优化)。
- C、C++内存对齐
- 从Jni到Java增加一个系统服务SystemServer,并通过getSystemService调用
- Movement models代码分析3--WorkingDayMovement
- Java学习笔记--导航
- Java SE__关于Java的File.separator
- 关于PHP中类方法的重载问题
- movement包中的类及代码分析
- rvm 用于ruby版本的管理
- 写给系统管理员的25个PHP安全实践
- 《C语言入门经典》Ivor Horton第九章练习题