⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aodv_waypoint_mob.pr.c

📁 opnet ad hoc adov routing
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: aodv_waypoint_mob.pr.c *//* Portions of this file copyright 1992-2001 by OPNET Technologies, Inc. *//* This variable carries the header into the object file */static const char aodv_waypoint_mob_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3C064A77 3C064A77 1 manet.antd.nist.gov lmiller 0 0 none none 0 0 none 0 0 0 0 0 0                                                                                                                                                                                                                                                                                                                                                                                                        ";#include <string.h>/* OPNET system definitions */#include <opnet.h>#if defined (__cplusplus)extern "C" {#endifFSM_EXT_DECS#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Header Block *//* Include directives */#include <math.h>#include "Aodv_Utils.h"/* PI constant      */#define PI	 3.141592654/* Transition codes */#define MOVE_CODE        0#define START_PAUSE_CODE 1#define END_PAUSE_CODE   2#define STAT_CODE        3/* Transition macro */#define MOVE          (op_intrpt_type () == OPC_INTRPT_SELF && op_intrpt_code() == MOVE_CODE)#define START_PAUSE   (PAUSE == 1)#define KEEP_MOVING   (PAUSE == 0)#define END_PAUSE     (op_intrpt_type () == OPC_INTRPT_SELF && op_intrpt_code() == END_PAUSE_CODE)#define STATS         (op_intrpt_type () == OPC_INTRPT_SELF && op_intrpt_code() == STAT_CODE)#define FIX           (MOBILE == 0) #define MOBIL         (MOBILE == 1)/* Mobility status */#define Disabled 0#define Enabled  1#define N_MAX 55#define TRACE_LEV_1 1/* Declare global vars */double avg_speed;typedef struct{	double x;	double y;	}Position;Position position_map[N_MAX];Position last_position_map[N_MAX];double   avg_dist_from_nodes[N_MAX];double   last_avg_dist_from_nodes[N_MAX];double   total_relative_deplacement[N_MAX];int      connectivity_map[N_MAX][N_MAX];void     aodv_mob_print_conn_map();int      nb_links;/* End of Header Block */#if !defined (VOSD_NO_FIN)#undef	BIN#undef	BOUT#define	BIN		FIN_LOCAL_FIELD(last_line_passed) = __LINE__ - _block_origin;#define	BOUT	BIN#define	BINIT	FIN_LOCAL_FIELD(last_line_passed) = 0; _block_origin = __LINE__;#else#define	BINIT#endif /* #if !defined (VOSD_NO_FIN) *//* State variable definitions */typedef struct	{	/* Internal state tracking for FSM */	FSM_SYS_STATE	/* State Variables */	Distribution *	         		one;	Objid	                  		node_id;	Objid	                  		process_id;	Objid	                  		net_id;	int	                    		MOBILE;	double	                 		XMAX;	double	                 		XMIN;	double	                 		YMAX;	double	                 		YMIN;	int	                    		DEBUG;	int	                    		node_addr;	double	                 		TRANSMISSION_RANGE;	int	                    		num_nodes;	double	                 		my_avg_speed;	double	                 		distance_to_cover;	double	                 		PAUSE_TIME;	double	                 		MVT_STEP;	double	                 		SPEED_LIMIT;	double	                 		direction_angle;	double	                 		step_range;	double	                 		DISTANCE_LIMIT;	Distribution *	         		uniform_double_x;	Distribution *	         		uniform_double_y;	int	                    		PAUSE;	double	                 		x_target;	double	                 		y_target;	} aodv_waypoint_mob_state;#define pr_state_ptr            		((aodv_waypoint_mob_state*) SimI_Mod_State_Ptr)#define one                     		pr_state_ptr->one#define node_id                 		pr_state_ptr->node_id#define process_id              		pr_state_ptr->process_id#define net_id                  		pr_state_ptr->net_id#define MOBILE                  		pr_state_ptr->MOBILE#define XMAX                    		pr_state_ptr->XMAX#define XMIN                    		pr_state_ptr->XMIN#define YMAX                    		pr_state_ptr->YMAX#define YMIN                    		pr_state_ptr->YMIN#define DEBUG                   		pr_state_ptr->DEBUG#define node_addr               		pr_state_ptr->node_addr#define TRANSMISSION_RANGE      		pr_state_ptr->TRANSMISSION_RANGE#define num_nodes               		pr_state_ptr->num_nodes#define my_avg_speed            		pr_state_ptr->my_avg_speed#define distance_to_cover       		pr_state_ptr->distance_to_cover#define PAUSE_TIME              		pr_state_ptr->PAUSE_TIME#define MVT_STEP                		pr_state_ptr->MVT_STEP#define SPEED_LIMIT             		pr_state_ptr->SPEED_LIMIT#define direction_angle         		pr_state_ptr->direction_angle#define step_range              		pr_state_ptr->step_range#define DISTANCE_LIMIT          		pr_state_ptr->DISTANCE_LIMIT#define uniform_double_x        		pr_state_ptr->uniform_double_x#define uniform_double_y        		pr_state_ptr->uniform_double_y#define PAUSE                   		pr_state_ptr->PAUSE#define x_target                		pr_state_ptr->x_target#define y_target                		pr_state_ptr->y_target/* This macro definition will define a local variable called	*//* "op_sv_ptr" in each function containing a FIN statement.	*//* This variable points to the state variable data structure,	*//* and can be used from a C debugger to display their values.	*/#undef FIN_PREAMBLE#define FIN_PREAMBLE	aodv_waypoint_mob_state *op_sv_ptr = pr_state_ptr;/* Function Block */enum { _block_origin = __LINE__ };/*************************/* Prints a major message *************************/void aodv_mob_print_major(char * msg, int trace_level)	{	char msg1[64];	char msg2[64];	if(DEBUG >= trace_level)		{		printf("\n\n|------------------------------------------------------------------------------|\n");		sprintf(msg1,"|====]  Node %d  [====|  @  Mobility", node_addr);		printf("%s",msg1);		sprintf(msg2,"Time: %f |", op_sim_time());				aodv_justify(strlen(msg1),msg2,80);		printf("|------------------------------------------------------------------------------|");				printf("\n\t\t- %s\n",msg);		}	}/****************************/* Prints a minor message *****************************/void aodv_mob_print_minor(char * msg, int trace_level)	{	if(DEBUG >= trace_level)		{		printf("\t\t> %s\n", msg);			   		}	}/*****************************Init connectivity map*******************************/void aodv_mob_init_conn_map()	{		double distance_i_j;	int i,j;	double xi,xj,yi,yj;		// Init to zero	for(i = 0; i < num_nodes; i++)		{		// init total relative deplacement table		total_relative_deplacement[i] = 0;		// init conn map		for(j = 0; j < num_nodes; j++)			connectivity_map[i][j] = 0;			}		//aodv_mob_print_major("Connectivity Map:",TRACE_LEV_1);	// Update connectivity	for(i = 1; i < num_nodes; i++)		{			xi = position_map[i].x;		yi = position_map[i].y;							for(j=0; j < i; j++)			{			xj = position_map[j].x;			yj = position_map[j].y;										distance_i_j= sqrt((xi-xj)*(xi-xj) + (yi-yj)*(yi-yj));			if(distance_i_j <= TRANSMISSION_RANGE)				{				nb_links++;				connectivity_map[i][j] = 1;				}			}		}		}/*******************************Update connectivity map********************************/void aodv_mob_update_conn_map()	{	double distance_i_j;	int i,j;	double xi,xj,yi,yj;		i = node_addr;	xi = position_map[i].x;	yi = position_map[i].y;				//printf("\t\t> New neighbors: ");	for(j=0; j < num_nodes; j++)		{		if(j != i)			{			xj = position_map[j].x;			yj = position_map[j].y;									distance_i_j= sqrt((xi-xj)*(xi-xj) + (yi-yj)*(yi-yj));			if(distance_i_j > TRANSMISSION_RANGE)				{				if(i>j)					{					if(connectivity_map[i][j] == 1)						{						nb_links--;						if(DEBUG) printf("\t\t>> Link toward [%d] has broken.\n",j);						}					connectivity_map[i][j] = 0;					}				else					{					if(connectivity_map[j][i] == 1)						{						nb_links--;						if(DEBUG) printf("\t\t>> Link toward [%d] has broken.\n",j);						}										connectivity_map[j][i] = 0;					}				}			else				{				//printf("[%d]  ",j);				if(i>j)					{					if(connectivity_map[i][j] == 0)						{						nb_links++;						if(DEBUG) printf("\t\t>> Link toward [%d] has formed.\n",j);											}					connectivity_map[i][j] = 1;					}				else					{					if(connectivity_map[j][i] == 0)						{						nb_links++;						if(DEBUG) printf("\t\t>> Link toward [%d] has formed.\n",j);											}					connectivity_map[j][i] = 1;					}				}			}		}	//printf("\n");	}/*Print connectivity map*/void aodv_mob_print_conn_map()	{	int i,j;	int conn_i_j;	int neighbor;		for(i = 0; i < num_nodes; i++)		{			if(DEBUG > 3) printf("\t\t> Node [%d] Neighbors: ",i);		for(j=0; j < num_nodes; j++)			{			if(j != i)				{				neighbor = j;				if(i>j)					conn_i_j = connectivity_map[i][j];				else					conn_i_j = connectivity_map[j][i];				if(conn_i_j)					if(DEBUG > 3) printf("[%d]  ",neighbor);				}			}		if(DEBUG > 3) printf("\n");		}	}/********************************/* Compute relative distances/* for a given node********************************/doubleaodv_mob_compute_relative_dist(int current_node, Position position_table[N_MAX])	{	double distance_i_j = 0;	int i,j;	double xi,xj,yi,yj;		i = current_node;	xi = position_table[i].x;	yi = position_table[i].y;				for(j=0; j < num_nodes; j++)		{		if(j != i)			{			xj = position_table[j].x;			yj = position_table[j].y;									distance_i_j+= sqrt((xi-xj)*(xi-xj) + (yi-yj)*(yi-yj));			}		}	return (double) distance_i_j/(num_nodes-1.0);	}/*****************************/* Collect stats******************************/voidaodv_mob_collect_stats()	{	int i;	aodv_mob_print_major("Collecting stats",TRACE_LEV_1);	// For each node in the network	for(i = 0; i < num_nodes; i++)		{		// Compute the current avg distance		avg_dist_from_nodes[i] = aodv_mob_compute_relative_dist(i, position_map);		// Compute the last avg distance		last_avg_dist_from_nodes[i] = aodv_mob_compute_relative_dist(i, last_position_map);			// Record the total relative deplacement		total_relative_deplacement[i]+= sqrt((avg_dist_from_nodes[i] - last_avg_dist_from_nodes[i])*(avg_dist_from_nodes[i] - last_avg_dist_from_nodes[i]));		}	// Schedule inerrupt to update mobility	op_intrpt_schedule_self(op_sim_time()+ MVT_STEP,STAT_CODE);	}/* End of Function Block *//* Undefine optional tracing in FIN/FOUT/FRET *//* The FSM has its own tracing code and the other *//* functions should not have any tracing.		  */#undef FIN_TRACING#define FIN_TRACING#undef FOUTRET_TRACING#define FOUTRET_TRACING#if defined (__cplusplus)extern "C" {#endif	void aodv_waypoint_mob (void);	Compcode aodv_waypoint_mob_init (void **);	void aodv_waypoint_mob_diag (void);	void aodv_waypoint_mob_terminate (void);	void aodv_waypoint_mob_svar (void *, const char *, char **);#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Process model interrupt handling procedure */voidaodv_waypoint_mob (void)	{	int _block_origin = 0;	FIN (aodv_waypoint_mob ());	if (1)		{		Objid	       params_comp_attr_objid;		Objid          params_attr_objid;		double	       rand, prev_angle,x,y,z,x_pos,y_pos,z_pos;		double         first_interval;		char           msg[64];		int            i;		double         pause_time;		FSM_ENTER (aodv_waypoint_mob)		FSM_BLOCK_SWITCH			{			/*---------------------------------------------------------*/			/** state (init) enter executives **/			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "aodv_waypoint_mob () [init enter execs]")				{				// init Objids				process_id = op_id_self();				node_id = op_topo_parent (process_id);				op_ima_obj_attr_get(node_id,"wlan_mac.station_address",&node_addr);				op_ima_obj_attr_get(node_id, "DEBUG", &DEBUG);				// Disable DEBUG				DEBUG = 0;				net_id = op_topo_parent(node_id);				// Load Mobility parameters				op_ima_obj_attr_get (process_id, "Mobility Parameters", &params_comp_attr_objid);				params_attr_objid = op_topo_child (params_comp_attr_objid, OPC_OBJTYPE_GENERIC, 0);				op_ima_obj_attr_get(params_attr_objid, "MOBILITY"   , &MOBILE);				op_ima_obj_attr_get(params_attr_objid, "PAUSE_TIME" , &PAUSE_TIME);				op_ima_obj_attr_get(params_attr_objid, "MVT_STEP"   , &MVT_STEP);				op_ima_obj_attr_get(params_attr_objid, "SPEED_LIMIT", &SPEED_LIMIT);				op_ima_obj_attr_get(params_attr_objid, "X_MIN"      , &XMIN);				op_ima_obj_attr_get(params_attr_objid, "X_MAX"      , &XMAX);				op_ima_obj_attr_get(params_attr_objid, "Y_MIN"      , &YMIN);				op_ima_obj_attr_get(params_attr_objid, "Y_MAX"      , &YMAX);				op_ima_sim_attr_get(OPC_IMA_DOUBLE,"Wireless LAN Range (meters)",&TRANSMISSION_RANGE);				/* Read the number of nodes in the network */				num_nodes = op_topo_object_count (OPC_OBJTYPE_NDMOB);				if(num_nodes > N_MAX)					{					op_sim_end("Network contains more than N_MAX nodes","Change N_MAX value in all files and restart all over again","","");					}				// Pick a random init position				uniform_double_x = op_dist_load ("uniform", XMIN, XMAX);				x_pos = op_dist_outcome(uniform_double_x);				uniform_double_y = op_dist_load ("uniform", YMIN, YMAX);				y_pos = op_dist_outcome(uniform_double_y);								// Set the current position of the node				op_ima_obj_attr_set(node_id,"x position",x_pos);				op_ima_obj_attr_set(node_id,"y position",y_pos);								// Register its position in the connectivity map				position_map[node_addr].x = x_pos;				position_map[node_addr].y = y_pos;				// Register its last position in the connectivity map				last_position_map[node_addr].x = x_pos;				last_position_map[node_addr].y = y_pos;				// Compute DISTANCE_LIMIT				DISTANCE_LIMIT = sqrt((XMAX - XMIN)*(XMAX - XMIN)+(YMAX - YMIN)*(YMAX - YMIN));				// initialize distributions for random movement				one = op_dist_load ("uniform", -1, 1);								// Begin				// If MOBILITY attribute is set to Enabled, then node is 				// really entitled to travel through the network.				// In this case, transit to "Init_Mvt" state. Otherwise, go to "Idle" state.				// The number of established links is initially set to 0				nb_links = 0;				// Init avg speed				avg_speed = PAUSE_TIME;				// The last node updates the connectivity map.				if(node_addr == (num_nodes -1))					{					aodv_mob_init_conn_map();					aodv_mob_print_conn_map();					op_intrpt_schedule_self(op_sim_time()+ 0.5*MVT_STEP,STAT_CODE);					}				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -