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

📄 dymo_pkt_support.ex.c

📁 dymo是基于多径累计的ADHOC路由算法优化,并在OPNET11.0上实现.
💻 C
📖 第 1 页 / 共 2 页
字号:
			break;
			}
			
		case (DYMOC_ROUTE_ERROR):
			{
			/* This is a route error option	*/
			rerr_option_ptr = (DymoT_Rerr*) option_ptr->value_ptr;
			copy_unreachable_lptr = dymo_pkt_support_unreachable_nodes_copy (rerr_option_ptr->unreachable_dest_lptr);
			copy_option_ptr = dymo_pkt_support_rerr_option_create (rerr_option_ptr->ignore_flag, rerr_option_ptr->elem_ttl,
				rerr_option_ptr->elem_len, copy_unreachable_lptr);
			break;
			}
			
		case (DYMOC_HELLO):
			{
			/* This is an Hello option	*/
			hello_option_ptr = (DymoT_Hello*) option_ptr->value_ptr;
			copy_option_ptr = dymo_pkt_support_hello_option_create (hello_option_ptr->repair_flag,
				hello_option_ptr->ack_required_flag, hello_option_ptr->hop_count, hello_option_ptr->dest_addr, 
				hello_option_ptr->dest_seq_num, hello_option_ptr->src_addr, hello_option_ptr->lifetime, DYMOC_HELLO);
			
			break;
			}
		}
	
	FRET (copy_option_ptr);
	}


static void
dymo_pkt_support_option_mem_free (DymoT_Packet_Option* option_ptr)
	{
	DymoT_Route_Ele*			re_option_ptr;
	DymoT_Hello*				hello_option_ptr;
	DymoT_Rerr*					rerr_option_ptr;
	
	/** Free the memory for the packet option	*/
	FIN (dymo_pkt_support_option_mem_free (<args>));
	
	/* Based on the element type of option free it	*/
	switch (option_ptr->elem_type)
		{
		case (DYMOC_ROUTE_ELEMENT):
			{
			/* This is a route element option	*/
			re_option_ptr = (DymoT_Route_Ele*) option_ptr->value_ptr;
			dymo_pkt_support_re_option_mem_free (re_option_ptr);
			
			break;
			}
			
		case (DYMOC_HELLO):
			{
			/* This is a hello option	*/
			hello_option_ptr = (DymoT_Hello*) option_ptr->value_ptr;
			dymo_pkt_support_hello_option_mem_free (hello_option_ptr);
			
			break;
			}
			
		case (DYMOC_ROUTE_ERROR):
			{
			/* This is a route error option	*/
			rerr_option_ptr = (DymoT_Rerr*) option_ptr->value_ptr;
			dymo_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*
dymo_pkt_support_unreachable_nodes_copy (List* unreachable_nodes_lptr)
	{
	List*						copy_lptr;
	int							num_nodes, count;
	DymoT_Unreachable_Node*		unreachable_node_ptr;
	DymoT_Unreachable_Node*		copy_unreachable_ptr;
	
	/** Makes a copy of the unreachable nodes list	**/
	FIN (dymo_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 = (DymoT_Unreachable_Node*) op_prg_list_access (unreachable_nodes_lptr, count);
		
		/* Make a copy of the node	*/
		copy_unreachable_ptr = dymo_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 DymoT_Packet_Option*
dymo_pkt_support_option_mem_alloc (void)
	{
	static Pmohandle		dymo_option_pmh;
	DymoT_Packet_Option*	dymo_option_ptr = OPC_NIL;
	static Boolean			dymo_option_pmh_defined = OPC_FALSE;
	
	/** Allocates memory for the TLV in the option	**/
	FIN (dymo_pkt_support_option_mem_alloc (void));
	
	if (dymo_option_pmh_defined == OPC_FALSE)
		{
		/* Define the pool memory handle for route request option	*/
		dymo_option_pmh = op_prg_pmo_define ("DYMO Option TLV", sizeof (DymoT_Packet_Option), 32);
		dymo_option_pmh_defined = OPC_TRUE;
		}
	
	/* Allocate the route request option from the pooled memory	*/
	dymo_option_ptr = (DymoT_Packet_Option*) op_prg_pmo_alloc (dymo_option_pmh);
	
	FRET (dymo_option_ptr);
	}
	

static DymoT_Route_Ele*
dymo_pkt_support_re_option_mem_alloc (void)
	{
	static Pmohandle		re_option_pmh;
	DymoT_Route_Ele*		re_ptr = OPC_NIL;
	static Boolean			re_option_pmh_defined = OPC_FALSE;
	
	/** Allocates pooled memory for the route request option	**/
	FIN (dymo_pkt_support_re_option_mem_alloc (void));
	
	if (re_option_pmh_defined == OPC_FALSE)
		{
		/* Define the pool memory handle for route element option	*/
		re_option_pmh = op_prg_pmo_define ("DYMO Route Element Option", sizeof (DymoT_Route_Ele), 32);
		re_option_pmh_defined = OPC_TRUE;
		}
	
	/* Allocate the route element option from the pooled memory	*/
	re_ptr = (DymoT_Route_Ele*) op_prg_pmo_alloc (re_option_pmh);
	
	FRET (re_ptr);
	}


static DymoT_Hello*
dymo_pkt_support_hello_option_mem_alloc (void)
	{
	static Pmohandle		hello_option_pmh;
	DymoT_Hello*			hello_ptr = OPC_NIL;
	static Boolean			hello_option_pmh_defined = OPC_FALSE;
	
	/** Allocates pooled memory for the hello option	**/
	FIN (dymo_pkt_support_hello_option_mem_alloc (void));
	
	if (hello_option_pmh_defined == OPC_FALSE)
		{
		/* Define the pool memory handle for hello option	*/
		hello_option_pmh = op_prg_pmo_define ("DYMO Hello Option", sizeof (DymoT_Hello), 32);
		hello_option_pmh_defined = OPC_TRUE;
		}
	
	/* Allocate the hello option from the pooled memory	*/
	hello_ptr = (DymoT_Hello*) op_prg_pmo_alloc (hello_option_pmh);
	
	FRET (hello_ptr);
	}


static DymoT_Rerr*
dymo_pkt_support_rerr_option_mem_alloc (void)
	{
	static Pmohandle		rerr_option_pmh;
	DymoT_Rerr*				rerr_ptr = OPC_NIL;
	static Boolean			rerr_option_pmh_defined = OPC_FALSE;
	
	/** Allocates pooled memory for the route error option	**/
	FIN (dymo_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 ("DYMO Route Error Option", sizeof (DymoT_Rerr), 32);
		rerr_option_pmh_defined = OPC_TRUE;
		}
	
	/* Allocate the route error option from the pooled memory	*/
	rerr_ptr = (DymoT_Rerr*) op_prg_pmo_alloc (rerr_option_pmh);
	
	FRET (rerr_ptr);
	}


static void
dymo_pkt_support_re_option_mem_free (DymoT_Route_Ele* re_option_ptr)
	{

	/** Frees the memory allocated to the route element option	**/
	FIN (dymo_pkt_support_re_option_mem_free (<args>));
	
	/* Destroy the IP addresses	*/
	inet_address_destroy (re_option_ptr->elem_target_addr);
	
	while(op_prg_list_size(re_option_ptr->reblock_lptr) > 0)
		{
		dymo_pkt_support_re_block_entry_mem_free (re_option_ptr, OPC_LISTPOS_TAIL);
		}

	op_prg_mem_free(re_option_ptr->reblock_lptr);
	/* Free the option	*/
	op_prg_mem_free (re_option_ptr);
	
	FOUT;
	}


static void
dymo_pkt_support_hello_option_mem_free (DymoT_Hello* hello_option_ptr)
	{
	FIN (dymo_pkt_support_hello_option_mem_free (<args>));
	
	/* Destroy the IP addresses	*/
	inet_address_destroy (hello_option_ptr->dest_addr);
	inet_address_destroy (hello_option_ptr->src_addr);
	
	/* Free the option	*/
	op_prg_mem_free (hello_option_ptr);
	
	FOUT;
	}


static void
dymo_pkt_support_rerr_option_mem_free (DymoT_Rerr* rerr_option_ptr)
	{
	DymoT_Unreachable_Node*		unreachable_dest_ptr;
	int							num_dest;
	
	/** Frees the memory allocated for the route error option	**/
	FIN (dymo_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 = (DymoT_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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -