在做拓撲控制協議仿真時,需要使用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。