直接操作位置属性
如果为移动站点指定了轨迹,那么该站点的路径在整个仿真期间都是预先确定的。但如果没有指定轨迹,则该站点的位置可以在仿真期间由任意进程直接更新。移动站点的 x position 和 y position 属性规定它在父子网中的位置。移动站点的 altitude 属性规定它相对于海平面、下垫地形或父子网的高度(取决于该站点的 altitude modeling 属性设置)。修改其中某个属性会导致移动站点的位置立即发生变化。
通常采用以下两种技术之一来动态改变移动站点的位置。两种情况下,都由用户定义的进程负责修改移动站点的位置属性。第一种是集中式方法,由一个进程负责更新网络模型中所有移动站点的位置;该进程通常位于某个被特别指定为中央控制站点的站点内。第二种是分散式方法,即每个移动站点内部都有一个进程在运行,只更新它自己的位置。下面的示例给出了实现这两种技术的示例进程模型的代码片段。
注意: 在这些示例中,node_position_compute() 函数是用户提供的例程,它根据某些准则计算节点的位置。
图 16:实现分散管理父子移动节点位置属性的示例进程模型状态
/* Obtain the parent node’s object ID. */
parent_node_objid = op_topo_parent (op_id_self ());
/* Obtain the new subnet-relative coordinates for the parent node. */
node_position_compute (parent_node_objid, &x_pos, &y_pos, &alt);
/* Set the parent node’s position attributes to the new values. */
op_ima_obj_attr_set_dbl (parent_node_objid, “x position”, x_pos);
op_ima_obj_attr_set_dbl (parent_node_objid, “y position”, y_pos);
op_ima_obj_attr_set_dbl (parent_node_objid, “altitude”, alt);
图 17:实现集中管理所有移动节点位置属性的示例进程模型片段
/* Determine number of mobile nodes in the system. */
num_nodes = op_topo_object_count (OPC_OBJTYPE_NDMOB);
/* For each mobile node, obtain its object ID, system ID */
/* and new location. Set the new values in the position */
/* attributes of the node. */
for (i = 0; i < num_nodes; i++)
{
/* Obtain the i_th mobile node’s object ID. */
node_objid = op_topo_object (OPC_OBJTYPE_NDMOB, i);
/* Obtain the new subnet-relative coordinates for the mobile node. */
node_position_compute (node_objid, &x_pos, &y_pos, &alt);
/* Set the parent node’s position attributes to the new values. */
op_ima_obj_attr_set_dbl (node_objid, “x position”, x_pos);
op_ima_obj_attr_set_dbl (node_objid, “y position”, y_pos);
op_ima_obj_attr_set_dbl (node_objid, “altitude”, alt);
}
与轨迹不同(轨迹允许仿真内核模拟连续运动),直接操作移动站点的位置属性会迫使位置发生离散变化。移动站点的离散位置变化可能使默认无线电收发器管道出现意外行为。具体来说,可能涉及默认信号锁定机制、数据包干扰计算以及无线电接收信道的 busy 统计量等方面的问题。这些机制依赖于这样一个事实:当两个数据包从同一个无线电发射信道背靠背发送时,第一个数据包的接收完成时间与第二个数据包的到达起始时间相同。这基于两次传播时延计算:第一个数据包在其传输结束时的传播时延,以及第二个数据包在其传输开始时的传播时延。如果这两个传播时延不相同,那么两个背靠背的数据包将被错误地显示为相互重叠或之间存在间隙。
当两个站点在传输过程中相互靠近或远离时,无线电信号的传播时延会相应变化。因此,在一个数据包传输的开始和结束时刻,从移动站点发出的数据包的起始与结束传播时延可能不同。如果不考虑这种传播时延差异,背靠背数据包就会出现重叠或间隙行为。
在位置离散变化的情况下,默认无线电收发器管道并不能防止这种重叠或间隙行为。这是因为仿真内核在没有轨迹的情况下无法预测移动站点的未来位置。此时,仿真内核会把数据包 TDA 中传输结束时的传播距离 OPC_TDA_RA_END_DIST 设置为与传输开始时的传播距离(位于数据包的 TDA OPC_TDA_RA_START_DIST 中)相同的值。计算传播时延的默认无线电管道阶段 dra_propdel.ps.c 使用这些值,因此对两个时延返回相同的结果。
一种解决方案是用另一个管道阶段替换默认无线电管道阶段,使其能够正确计算传输结束时的传播时延。下面的代码是一个正确计算该时延的示例管道阶段。这里假定 node_distance_calculate() 过程返回指定站点在指定时刻之间以米为单位的距离。如果无法实现这样的过程,则应当改用能够处理默认信号锁定机制、数据包干扰计算以及无线电接收信道 busy 统计量问题的其他解决方案。
图 18:传播时延无线电管道阶段示例
/* mobile_propdel.ps.c */
/* Propagation delay model for radio link Transceiver Pipeline */
#include <opnet.h>
/* propagation velocity of radio signal (m/s) */
define PROP_VELOCITY 3.0E+08
#if defined (__cplusplus)
extern “c”
#endif
void
mobile_propdel (Packet *pkptr)
{
double start_prop_delay, end_prop_delay;
double start_prop_distance, end_prop_distance;
Objid source_node_objid, destination_node_objid;
double end_rx_time;
/** Compute the propagation delays separating the **/
/** radio transmitter from the radio receiver. **/
FIN (mobile_propdel (pkptr))
/* Obtain source node’s object ID. */
source_node_objid = op_topo_parent (op_td_get_int (pkptr,OPC_TDA_RA_TX_OBJID));
/* Obtain destination node’s object ID. */
destination_node_objid = op_topo_parent (op_td_get_int (pkptr,
OPC_TDA_RA_RX_OBJID));
/* Obtain the end of reception time. */
end_rx_time = op_td_get_dbl (pkptr, OPC_TDA_RA_END_RX);
/* Get the start distance between transmitter and receiver. */
start_prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_START_DIST);
/* Compute the end distance between transmitter and receiver, based */
/* on information that specifies where the nodes will be at the */
/* time when the packet has been completely received. This is */
/* necessary because, the end distance stored in the packet’s TDA */
/* is invalid if either node moves during the transmission. */
end_prop_distance = node_distance_calculate (source_node_objid,
destination_node_objid, end_rx_time);
/* Compute propagation delay to start of reception. */
start_prop_delay = start_prop_distance / PROP_VELOCITY;
/* Compute propagation delay to end of reception. */
end_prop_delay = end_prop_distance / PROP_VELOCITY;
/* Place both propagation delays in packet trans. data attributes. */
op_td_set_dbl (pkptr, OPC_TDA_RA_START_PROPDEL, start_prop_delay);
op_td_set_dbl (pkptr, OPC_TDA_RA_END_PROPDEL, end_prop_delay);
FOUT
}