ONE中,在对DTN更新时,会对router进行更新,本次是对router中个部分的更新进行一次梳理
//DTNHost
public void update(boolean simulateConnections, int[][] conPossible) {
if (!isRadioActive()) {
// Make sure inactive nodes don't have connections
tearDownAllConnections();
return;
}
if (simulateConnections) {
for (NetworkInterface i : net) {
i.update(conPossible);
}
}
this.router.update();
this.computeModel.update(this);
}
//DirectDeliveryRouter
@Override
public void update() {
super.update();
if (isTransferring() || !canStartTransfer()) {
return; // can't start a new transfer
}
// Try only the messages that can be delivered to final recipient
if (exchangeDeliverableMessages() != null) {
return; // started a transfer
}
}
//ActiveRouter
@Override
public void update() {
super.update();
/* in theory we can have multiple sending connections even though
currently all routers allow only one concurrent sending connection */
for (int i=0; i<this.sendingConnections.size(); ) {
boolean removeCurrent = false;
Connection con = sendingConnections.get(i);
/* finalize ready transfers */
if (con.isMessageTransferred()) {
if (con.getMessage() != null) {
transferDone(con);
con.finalizeTransfer();
} /* else: some other entity aborted transfer */
removeCurrent = true;
}
/* remove connections that have gone down */
else if (!con.isUp()) {
if (con.getMessage() != null) {
transferAborted(con);
con.abortTransfer();
}
removeCurrent = true;
}
if (removeCurrent) {
// if the message being sent was holding excess buffer, free it
if (this.getFreeBufferSize() < 0) {
this.makeRoomForMessage(0);
}
sendingConnections.remove(i);
}
else {
/* index increase needed only if nothing was removed */
i++;
}
}
/* time to do a TTL check and drop old messages? Only if not sending */
if (SimClock.getTime() - lastTtlCheck >= TTL_CHECK_INTERVAL &&
sendingConnections.size() == 0) {
dropExpiredMessages();
lastTtlCheck = SimClock.getTime();
}
if (energy != null) {
/* TODO: add support for other interfaces */
NetworkInterface iface = getHost().getInterface(1);
energy.update(iface, getHost().getComBus());
//System.out.println("Time: "+SimClock.getTime()+ " HostID: " + getHost().getAddress() + ", currentEnergy: " + energy.getEnergy());
}
}
1.执行顺序。
在执行router.update()时,需要执行DirectDeliveryRouter(以DirectDeliveryRouter为例)中的update(),于是执行其super.update(),即ActiveRouter的update()。于是执行ActiveRouter的update()中的super.update()。所以整体的执行顺序为:DTNHost的update()router.update()
DirectDeliveryRouter.update()
ActiveRouter.update()
MessageRouter.update()
2.更新的内容和顺序。
路由更新主要更新的内容:(1).判断是否传输结束 / 移除过期连接等;(2).丢弃TTL过期的消息;(3).更新能量;(4). 判断是否可以开始新消息传输;(5). 判断之前无法建立的连接是否可以建立,并进行消息传输
踩的坑:目前在能量更新的时候,基于当前的msgOnFly进行了能耗的更新操作。但是出现了某个主机节点在当前时间点执行了(5)操作,建立了与序号靠前的消息传输。但是当下一轮更新开始时,序号靠前的主机节点,执行(1)操作后,之前建立的消息传输直接结束,因此该消息根本没有经过(3)阶段,因此无法对该消息执行能耗信息的更新。