在做拓扑控制协议仿真时,需要使用wlan_tx和wlan_rx这一对收发机,并对节点通信半径进行动态调整,但如果使用较低版本的OPNET,源程序中可能没有对通信半径做明确限制。此时我们可以修改无线收发机的pipeline -> wlan_propdel管道程序,达到动态调整通信半径的目的。
第一步,在wlan_mac进程模型中,添加Simulation Attributes -> Wireless LAN Range (meters) 属性,类型为integer,缺省值为300。
第二步,改动wlan_propdel管道程序。以某一版本的该程序为例:
之前的:
#include <opnet.h>
/**//***** constants *****/
/**//* propagation velocity of radio signal (m/s) */
#define PROP_VELOCITY 3.0E+08
/**//* The variable defining a maximum range across which the station can communicate (meters) */
static double wlan_max_distance = OPC_DBL_INFINITY;
/**//***** pipeline procedure *****/
#if defined (__cplusplus)
extern "C"
#endif
void
Zhou_wlan_propdel (pkptr)
Packet* pkptr;
{
double start_prop_delay, end_prop_delay;
double start_prop_distance, end_prop_distance;
// Compute the propagation delay separating the
// radio transmitter from the radio receiver.
FIN (wlan_propdel (pkptr));
// Get the start distance between transmitter and receiver.
start_prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_START_DIST);
// Get the end distance between transmitter and receiver.
end_prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_END_DIST);
// 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;
// If the maximum transmission range of the station is not already set
// then extract it from the user defined simulation attribute.
if (wlan_max_distance == OPC_DBL_INFINITY)
{
if (op_ima_sim_attr_exists ("Wireless LAN Range (meters)") == OPC_TRUE)
{
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "Wireless LAN Range (meters)", &wlan_max_distance);
}
//printf ("wlan_max_distance is %f \n", wlan_max_distance);
}
// If the starting and ending propagation distance is more than the maximum transmission
// range then discard the packet in the pipeline stage. This will model the physical
// transmission boundary of a wireless station.
if (end_prop_distance > wlan_max_distance || start_prop_distance > wlan_max_distance)
{
// Discard the packet if the destination is more than the specified range
op_td_set_int (pkptr, OPC_TDA_RA_MATCH_STATUS, OPC_TDA_RA_MATCH_IGNORE);
}
// Place both propagation delays in packet transmission 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;
}
修改之后的,注意 "
if (wlan_max_distance == OPC_DBL_INFINITY)"那部分为添加语句:
#include <opnet.h>
/**//***** constants *****/
/**//* propagation velocity of radio signal (m/s) */
#define PROP_VELOCITY 3.0E+08
/**//* The variable defining a maximum range across which the station can communicate (meters) */
static double wlan_max_distance = OPC_DBL_INFINITY;
/**//***** pipeline procedure *****/
#if defined (__cplusplus)
extern "C"
#endif
void
wlan_propdel (pkptr)
Packet* pkptr;
{
double start_prop_delay, end_prop_delay;
double start_prop_distance, end_prop_distance;
// Compute the propagation delay separating the
// radio transmitter from the radio receiver.
FIN (wlan_propdel (pkptr));
// Get the start distance between transmitter and receiver.
start_prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_START_DIST);
// Get the end distance between transmitter and receiver.
end_prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_END_DIST);
// 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;
// If the maximum transmission range of the station is not already set
// then extract it from the user defined simulation attribute.
if (wlan_max_distance == OPC_DBL_INFINITY)
{
if (op_ima_sim_attr_exists ("Wireless LAN Range (meters)") == OPC_TRUE)
{
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "Wireless LAN Range (meters)", &wlan_max_distance);
}
//printf ("wlan_max_distance is %f \n", wlan_max_distance);
}
// If the starting and ending propagation distance is more than the maximum transmission
// range then discard the packet in the pipeline stage. This will model the physical
// transmission boundary of a wireless station.
if (end_prop_distance > wlan_max_distance || start_prop_distance > wlan_max_distance)
{
// Discard the packet if the destination is more than the specified range
op_td_set_int (pkptr, OPC_TDA_RA_MATCH_STATUS, OPC_TDA_RA_MATCH_IGNORE);
}
// Place both propagation delays in packet transmission 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;
}
第三步,选择file -> Compile,编译该程序。需要注意的是,如果将wlan_propdel改名为其他名字,如***_wlan_propdel,那么需要将函数名也修改为相应的***_wlan_propdel。