本文介绍DTNHost都有些什么东西,想理解这一点,想想一台PC通常会包含哪些东西。本文先给出与DTNHost相关类的UML类图,接着介绍一个节点DTNHost包含些什么,即身份识别信息+移动模型+网卡+协议栈。
1. 概述
1.1 UML类图
以DTNHost为中心的类图如下。可见,DTNHost与MovementModel
、MessageRouter
是一一对应的,与NetworkInterface
是一对多的关系。
1.2 DTNHost成员变量
//DTNHost
private static int nextAddress = 0;
private String name;
private int address;
private MessageRouter router;
/*** 移动相关 ***/
private MovementModel movement;
private Coord location; // where is the host (2D coordinates)
private Coord destination; // where is it going (2D coordinates)
private Path path; //the Path this node is currently traveling
private double speed;
private double nextTimeToMove;
private List<MessageListener> msgListeners;
private List<MovementListener> movListeners;
private List<NetworkInterface> net; //Network interface of a DTNHost. Takes care of connectivity among hosts.
private ModuleCommunicationBus comBus; //Intermodule communication bus
2. 身份识别信息
DTNHost身份识别信息,用一个静态整型变量标识系统的DTNHost id
,源代码如下:
private String name;
private int address; //唯一标识DTNHost,类似于ip地址
private static int nextAddress = 0; //静态成员变量
3. 移动模型MovementModel
DTN下的节点是移动的,需要描述起始位置,移动路径;如何移动,移动速度,下次移动时间。每个节点只有一种移动方式,即DTNHost与移动模型一一对应。相关源代码如下:
private Coord location; //平面坐标下的位置(x,y)
private Coord destination; //平面坐标下的位置(x,y)
private Path path; //包含一系列坐标点, private List<Coord> coords
private MovementModel movement; //移动模型,节点如何移动
private double speed; //移动速度
private double nextTimeToMove; //下次移动时间
4. 网卡NetworkInterface
一台PC可以装多个网卡(有线与无线),同理,DTN的节点也可以装多个网卡(一对多的关系),用于管理节点间的连接。
private List<NetworkInterface> net; //Network interface of a DTNHost. Takes care of connectivity among hosts.
private ModuleCommunicationBus comBus; //总线? Intermodule communication bus
NetworkInterface
管理一系列连接,还包含一些传输属性的信息(理解成物理层,传输距离、传输速度等),相关源代码如下:
//NetworkInterface.java
protected DTNHost host = null; //每个NetworkInterface关联一个DTNHost
private int address; //network interface address
protected String interfacetype; //在设置文件设置,如Group4.interface1 = btInterface(bluetooth interface) 或 highspeedInterface
protected List<Connection> connections; //一个NetworkInterface有多具连接
private List<ConnectionListener> cListeners = null; //list of listeners
protected double transmitRange; //传输范围
protected double oldTransmitRange;
protected int transmitSpeed;
protected ConnectivityOptimizer optimizer = null; //optimizing the location of possible contacts with network interfaces of a specific range
private double scanInterval;
private double lastScanTime;
private ActivenessHandler ah; //activeness handler for the node group
private int activenessJitterMax; //maximum activeness jitter value for the node group
private int activenessJitterValue; //this interface's activeness jitter value
NetworkInterface
是超类,目前只有SimpleBroadcastInterface
(provides a constant bit-rate service, where one transmission can be on at a time)继承该类,NetworkInterface
管理一系列连接(一对多)。对于一个连接,需要刻画其连接两端的DTNHost
和NetworkInterface
,类似于IP地址+端口号。其UML类图如下:
5. 协议栈
有了网卡NetworkInterface
,还需要在其上面安装协议栈,方可通信。The ONE没有MAC层(被抽象了),网络层的路由层次关系如下:MyRouter
继承 ActiveRouter
继承 MessageRouter
。以EpidemicRouter
为例,其层次类图如下:
6. 监听器Listeners
监听器用于统计仿真结果,当节点变化时(如:节点移动或消息创建、转发、丢弃、删除),会触发相应的监听器更新仿真结果,详情可参考博文《消息监听器MessageListener》。DTNHost有两个监听器列表,如下:
private List<MessageListener> msgListeners; //消息监听器
private List<MovementListener> movListeners;//移动监听器