在做拓?fù)淇刂茀f(xié)議仿真時(shí),需要使用wlan_tx和wlan_rx這一對(duì)收發(fā)機(jī),并對(duì)節(jié)點(diǎn)通信半徑進(jìn)行動(dòng)態(tài)調(diào)整,但如果使用較低版本的OPNET,源程序中可能沒(méi)有對(duì)通信半徑做明確限制。此時(shí)我們可以修改無(wú)線收發(fā)機(jī)的pipeline -> wlan_propdel管道程序,達(dá)到動(dòng)態(tài)調(diào)整通信半徑的目的。
第一步,在wlan_mac進(jìn)程模型中,添加Simulation Attributes -> Wireless LAN Range (meters) 屬性,類(lèi)型為integer,缺省值為300。
第二步,改動(dòng)wlan_propdel管道程序。以某一版本的該程序?yàn)槔?br>之前的:
#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)"那部分為添加語(yǔ)句:
#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,那么需要將函數(shù)名也修改為相應(yīng)的***_wlan_propdel。