aodv_pkt_support.ex.c

来自「opnet11.5 manet dsr和aodv协议」· C语言 代码 · 共 517 行 · 第 1/2 页

C
517
字号
			copy_option_ptr = aodv_pkt_support_rrep_option_create (rrep_option_ptr->repair_flag,				rrep_option_ptr->ack_required_flag, rrep_option_ptr->hop_count, rrep_option_ptr->dest_addr, 				rrep_option_ptr->dest_seq_num, rrep_option_ptr->src_addr, rrep_option_ptr->lifetime, AODVC_HELLO);						break;			}		}		FRET (copy_option_ptr);	}static voidaodv_pkt_support_option_mem_free (AodvT_Packet_Option* option_ptr)	{	AodvT_Rreq*					rreq_option_ptr;	AodvT_Rrep*					rrep_option_ptr;	AodvT_Rerr*					rerr_option_ptr;		/** Free the memory for the packet option	*/	FIN (aodv_pkt_support_option_mem_free (<args>));		/* Based on the type of option free it	*/	switch (option_ptr->type)		{		case (AODVC_ROUTE_REQUEST):			{			/* This is a route request option	*/			rreq_option_ptr = (AodvT_Rreq*) option_ptr->value_ptr;			aodv_pkt_support_rreq_option_mem_free (rreq_option_ptr);						break;			}					case (AODVC_ROUTE_REPLY):		case (AODVC_HELLO):			{			/* This is a route reply option	*/			rrep_option_ptr = (AodvT_Rrep*) option_ptr->value_ptr;			aodv_pkt_support_rrep_option_mem_free (rrep_option_ptr);						break;			}					case (AODVC_ROUTE_ERROR):			{			/* This is a route error option	*/			rerr_option_ptr = (AodvT_Rerr*) option_ptr->value_ptr;			aodv_pkt_support_rerr_option_mem_free (rerr_option_ptr);						break;			}		}					/* Free the memory allocated for the TLV	*/	op_prg_mem_free (option_ptr);		FOUT;	}static List*aodv_pkt_support_unreachable_nodes_copy (List* unreachable_nodes_lptr)	{	List*						copy_lptr;	int							num_nodes, count;	AodvT_Unreachable_Node*		unreachable_node_ptr;	AodvT_Unreachable_Node*		copy_unreachable_ptr;		/** Makes a copy of the unreachable nodes list	**/	FIN (aodv_pkt_support_unreachable_nodes_copy (<args>));		/* Create a list for the copy	*/	copy_lptr = op_prg_list_create ();			/* Get the number of unreachable nodes	*/	num_nodes = op_prg_list_size (unreachable_nodes_lptr);		for (count = 0; count < num_nodes; count++)		{		/* Get each unreachable node	*/		unreachable_node_ptr = (AodvT_Unreachable_Node*) op_prg_list_access (unreachable_nodes_lptr, count);				/* Make a copy of the node	*/		copy_unreachable_ptr = aodv_pkt_support_unreachable_nodes_mem_alloc ();		copy_unreachable_ptr->unreachable_dest = inet_address_copy (unreachable_node_ptr->unreachable_dest);		copy_unreachable_ptr->unreachable_dest_seq_num = unreachable_node_ptr->unreachable_dest_seq_num;				/* Insert into the list of unreachable nodes	*/		op_prg_list_insert (copy_lptr, copy_unreachable_ptr, OPC_LISTPOS_TAIL);		}		FRET (copy_lptr);	}static AodvT_Packet_Option*aodv_pkt_support_option_mem_alloc (void)	{	static Pmohandle		aodv_option_pmh;	AodvT_Packet_Option*	aodv_option_ptr = OPC_NIL;	static Boolean			aodv_option_pmh_defined = OPC_FALSE;		/** Allocates memory for the TLV in the option	**/	FIN (aodv_pkt_support_option_mem_alloc (void));		if (aodv_option_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route request option	*/		aodv_option_pmh = op_prg_pmo_define ("AODV Option TLV", sizeof (AodvT_Packet_Option), 32);		aodv_option_pmh_defined = OPC_TRUE;		}		/* Allocate the route request option from the pooled memory	*/	aodv_option_ptr = (AodvT_Packet_Option*) op_prg_pmo_alloc (aodv_option_pmh);		FRET (aodv_option_ptr);	}	static AodvT_Rreq*aodv_pkt_support_rreq_option_mem_alloc (void)	{	static Pmohandle		rreq_option_pmh;	AodvT_Rreq*				rreq_ptr = OPC_NIL;	static Boolean			rreq_option_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for the route request option	**/	FIN (aodv_pkt_support_rreq_option_mem_alloc (void));		if (rreq_option_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route request option	*/		rreq_option_pmh = op_prg_pmo_define ("AODV Route Request Option", sizeof (AodvT_Rreq), 32);		rreq_option_pmh_defined = OPC_TRUE;		}		/* Allocate the route request option from the pooled memory	*/	rreq_ptr = (AodvT_Rreq*) op_prg_pmo_alloc (rreq_option_pmh);		FRET (rreq_ptr);	}static AodvT_Rrep*aodv_pkt_support_rrep_option_mem_alloc (void)	{	static Pmohandle		rrep_option_pmh;	AodvT_Rrep*				rrep_ptr = OPC_NIL;	static Boolean			rrep_option_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for the route reply option	**/	FIN (aodv_pkt_support_rrep_option_mem_alloc (void));		if (rrep_option_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route reply option	*/		rrep_option_pmh = op_prg_pmo_define ("AODV Route Reply Option", sizeof (AodvT_Rrep), 32);		rrep_option_pmh_defined = OPC_TRUE;		}		/* Allocate the route reply option from the pooled memory	*/	rrep_ptr = (AodvT_Rrep*) op_prg_pmo_alloc (rrep_option_pmh);		FRET (rrep_ptr);	}static AodvT_Rerr*aodv_pkt_support_rerr_option_mem_alloc (void)	{	static Pmohandle		rerr_option_pmh;	AodvT_Rerr*				rerr_ptr = OPC_NIL;	static Boolean			rerr_option_pmh_defined = OPC_FALSE;		/** Allocates pooled memory for the route error option	**/	FIN (aodv_pkt_support_rerr_option_mem_alloc (void));		if (rerr_option_pmh_defined == OPC_FALSE)		{		/* Define the pool memory handle for route erroroption	*/		rerr_option_pmh = op_prg_pmo_define ("AODV Route Error Option", sizeof (AodvT_Rerr), 32);		rerr_option_pmh_defined = OPC_TRUE;		}		/* Allocate the route error option from the pooled memory	*/	rerr_ptr = (AodvT_Rerr*) op_prg_pmo_alloc (rerr_option_pmh);		FRET (rerr_ptr);	}static voidaodv_pkt_support_rreq_option_mem_free (AodvT_Rreq* rreq_option_ptr)	{	/** Frees the memory allocated to the route request option	**/	FIN (aodv_pkt_support_rreq_option_mem_free (<args>));		/* Destroy the IP addresses	*/	inet_address_destroy (rreq_option_ptr->dest_addr);	inet_address_destroy (rreq_option_ptr->src_addr);		/* Free the option	*/	op_prg_mem_free (rreq_option_ptr);		FOUT;	}static voidaodv_pkt_support_rrep_option_mem_free (AodvT_Rrep* rrep_option_ptr)	{	FIN (aodv_pkt_support_rrep_option_mem_free (<args>));		/* Destroy the IP addresses	*/	inet_address_destroy (rrep_option_ptr->dest_addr);	inet_address_destroy (rrep_option_ptr->src_addr);		/* Free the option	*/	op_prg_mem_free (rrep_option_ptr);		FOUT;	}static voidaodv_pkt_support_rerr_option_mem_free (AodvT_Rerr* rerr_option_ptr)	{	AodvT_Unreachable_Node*		unreachable_dest_ptr;	int							num_dest;		/** Frees the memory allocated for the route error option	**/	FIN (aodv_pkt_support_rerr_option_mem_free (<args>));		/* Get the number of unreachable destinations	*/	num_dest = op_prg_list_size (rerr_option_ptr->unreachable_dest_lptr);		while (num_dest > 0)		{		/* Access each unreachable destination	*/		unreachable_dest_ptr = (AodvT_Unreachable_Node*) op_prg_list_remove (rerr_option_ptr->unreachable_dest_lptr, OPC_LISTPOS_HEAD);				/* Free the memory	*/		inet_address_destroy (unreachable_dest_ptr->unreachable_dest);		op_prg_mem_free (unreachable_dest_ptr);				num_dest--;		}		/* Free the list	*/	op_prg_mem_free (rerr_option_ptr->unreachable_dest_lptr);		/* Free the route error option	*/	op_prg_mem_free (rerr_option_ptr);		FOUT;	}

⌨️ 快捷键说明

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