OneSimulator: NetworkLayer类

NetworkLayer没有子类;
NetworkLayer作为DTNHost的成员,维护 和 哪些Host存在Connection;
在World.update()时会被调用

1.NetworkLayer Init流程
在DTNHost.DTNHost()构造时候发生,
成员: Connection连接:private List connections; // connected hosts
通信范围 private double transmitRange; // transmission coverage
传输速度 private int transmitSpeed; // bandwidth of the transmission (Bps)
绑定来自SimScenario的ConnectionListeners this.cListeners = cListeners;

2.NetworkLayer.update()
DTNHost.update()时发生,
两端的NetworkLayer的成员 List connections删去响应的connection,
两端的Router 触发 changedConnection().
MessageRouter 和 ActiveRouter都不触发流程, EpidemicRouter和DirectDeliveryRouter也不响应,
只有ProphetRouter响应(但是只响应up事件)

   public void update() {
         for (int i=0; i<this.connections.size(); ) {                         //for each conn,
                Connection con = this.connections.get(i);
                DTNHost anotherNode = con.getOtherNode(this.host);
                // all connections should be up at this stage
                if (!isWithinRange(anotherNode)) {                                //若 对端 已经超出通信范围
                       con.setUpState(false);                                       //Connection.isUp赋值为false
                       notifyConnectionListeners(CON_DOWN, anotherNode);            //通知Report类 Host间Conn Down
                       // tear down bidirectional connection
                       if (!anotherNode.getConnections().remove(con)) {             //对端的NetworkLayer的connections删除
                             throw new SimError("No connection " + con + "  found in " + anotherNode);
                       }
                       this.host.changedConnection(con);                            //本端Router触发 changedConnection()
                       anotherNode.changedConnection(con);
                       connections.remove(i);                                       //本端的NetworkLayer的connections删除
                }
                else {
                       i++;
                }
         }
   }

3.connect()流程
由World.update() 中的 World.connectHosts()触发(存在conGrid机制,分成cell的connection优化计算方法)

     if (simulateConnections) {              //配置文件里 Scenario.simulateConnections = true
         connectHosts();            // make connections
     }

World.connectHosts() 相当于 对任何两个DTNHost尝试connect 即DTNHost.connect();

// the old way to do it (aka Algorithm no 1)
// try to connect every single node to all other nodes
for (int i=0, n = hosts.size();i < n; i++) {
    for (int j=0;j < n; j++) {
        if (isCancelled) {
            return;
        }
        hosts.get(i).connect(hosts.get(j));
    }
}

DTNHost.connect(anotherHost); (1)该DTNHost是Active; 且 该DTNHost !=anotherHost (2)DTNHost.NetworkLayer.connect(anotherHost)
NetworkLayer.connect(anotherHost) 流程:
(1)要求 对端DTNHost是Active, 两个DTNHost距离在通信范围内, 两个DTNHost间的connection不存在在 List NetworkLayer.connections
(2)得到最小ConSpeed, 建立Connection
(3)通知Listener Connection_UP事件
(4)两个DTNHost NetworkLayer 成员 connections, 添加新Connection
(5)Router类响应 Connection状态改变,比如ProphetRouter 改变delivery predictions

   public void connect(DTNHost anotherHost) {
         if (anotherHost.isActive() && isWithinRange(anotherHost) && !isConnected(anotherHost)) {
                // new contact within range
                // connection speed is the lower one of the two speeds
                ...
                Connection con = new Connection(this.host, anotherHost,  conSpeed);
                this.connections.add(con);
                notifyConnectionListeners(CON_UP, anotherHost);
                // set up bidirectional connection
                anotherHost.getConnections().add(con);
                // inform routers about the connection
                this.host.changedConnection(con);
                anotherHost.changedConnection(con);
         }
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值