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

📄 dsr_pkt_support.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 4 页
字号:
				break;				}							case (DSRC_SOURCE_ROUTE):				{				source_route_option_ptr = (DsrT_Source_Route_Option*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      SOURCE ROUTE OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								route_str = dsr_support_route_print (source_route_option_ptr->route_lptr);				strcpy (temp_str, "        Source Route");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);				DSR_PKPRINT_STRING_INSERT (alloc_str, route_str, output_list);								sprintf (temp_str, "        Number of Segments Left           %d", source_route_option_ptr->segments_left);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								sprintf (temp_str, "        Salvage Count                     %d", source_route_option_ptr->salvage);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								break;				}			}		}		FOUT;	}								/*****************************************************//*** MEMORY ALLOCATION AND DEALLOCATION FUNCTIONS ****//*****************************************************/static List*dsr_pkt_support_tlv_options_mem_copy (List* tlv_options_lptr)	{	List*					copy_tlv_options_lptr = OPC_NIL;	DsrT_Packet_Option*		dsr_tlv_ptr = OPC_NIL;	DsrT_Packet_Option*		copy_dsr_tlv_ptr = OPC_NIL;	int						num_options, count;		/** Copies the list of options in the DSR packet	**/	FIN (dsr_pkt_support_tlv_options_mem_copy (<args>));		/* Create a new list to place the copies of the options	*/	copy_tlv_options_lptr = op_prg_list_create ();		/* Get the number of options	*/	num_options = op_prg_list_size (tlv_options_lptr);		for (count = 0; count < num_options; count++)		{		/* Get each option and copy the option	*/		/* based on its option type				*/		dsr_tlv_ptr = (DsrT_Packet_Option*) op_prg_list_access (tlv_options_lptr, count);				switch (dsr_tlv_ptr->option_type)			{			case (DSRC_ROUTE_REQUEST):				{				/* Route Request Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_route_request_mem_copy (dsr_tlv_ptr);				break;				}						case (DSRC_ROUTE_REPLY):				{				/* Route Reply Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_route_reply_mem_copy (dsr_tlv_ptr);				break;				}							case (DSRC_ROUTE_ERROR):				{				/* Route Error Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_route_error_mem_copy (dsr_tlv_ptr);				break;				}							case (DSRC_ACK_REQUEST):				{				/* Ack Request Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_ack_request_mem_copy (dsr_tlv_ptr);				break;				}							case (DSRC_ACKNOWLEDGEMENT):				{				/* Acknowledgement Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_acknowledgement_mem_copy (dsr_tlv_ptr);				break;				}							case (DSRC_SOURCE_ROUTE):				{				/* DSR Source Route Option	*/				copy_dsr_tlv_ptr = dsr_pkt_support_source_route_mem_copy (dsr_tlv_ptr);				break;				}						default:				{				/* Invalid option type	*/				op_sim_end ("Invalid Option Type in DSR packet", OPC_NIL, OPC_NIL, OPC_NIL);				break;				}			}				/* Insert the option into the options list	*/		op_prg_list_insert (copy_tlv_options_lptr, copy_dsr_tlv_ptr, OPC_LISTPOS_TAIL);		}		FRET (copy_tlv_options_lptr);	}static DsrT_Packet_Option*dsr_pkt_support_route_request_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Route_Request_Option*		route_request_ptr = OPC_NIL;	DsrT_Route_Request_Option*		copy_route_request_ptr = OPC_NIL;	int								num_hops, count;	InetT_Address*					hop_address_ptr;	InetT_Address*					copy_address_ptr;	DsrT_Packet_Option*				copy_dsr_tlv_ptr = OPC_NIL;		/** Makes a copy of the route request options	**/	FIN (dsr_pkt_support_route_request_mem_copy (<args>));		/* Get the original route request options	*/	route_request_ptr = (DsrT_Route_Request_Option*) dsr_tlv_ptr->dsr_option_ptr;			/* Allocate memory for the copy of the route request options	*/	copy_route_request_ptr = dsr_pkt_support_route_request_mem_alloc ();	copy_route_request_ptr->identification = route_request_ptr->identification;	copy_route_request_ptr->target_address = inet_address_copy (route_request_ptr->target_address);		/* Insert each hop that has already been traversed	*/	/* into the route request option copy				*/	if (route_request_ptr->route_lptr != OPC_NIL)		{		num_hops = op_prg_list_size (route_request_ptr->route_lptr);		for (count = 0; count < num_hops; count++)			{			hop_address_ptr = (InetT_Address*) op_prg_list_access (route_request_ptr->route_lptr, count);			copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);			op_prg_list_insert (copy_route_request_ptr->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);			}		}		/* Allocate memory for the copy of the DSR option header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_route_request_ptr;		FRET (copy_dsr_tlv_ptr);	}static DsrT_Packet_Option*dsr_pkt_support_route_reply_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Route_Reply_Option*		route_reply_option = OPC_NIL;	DsrT_Route_Reply_Option*		copy_route_reply_option = OPC_NIL;	int								num_hops, count;	InetT_Address*					hop_address_ptr;	InetT_Address*					copy_address_ptr;	DsrT_Packet_Option*				copy_dsr_tlv_ptr = OPC_NIL;		/** Makes a copy of the route reply TLV field	**/	FIN (dsr_pkt_support_route_reply_mem_copy (<args>));		/* Get the original route reply option	*/	route_reply_option = (DsrT_Route_Reply_Option*) dsr_tlv_ptr->dsr_option_ptr;		/* Allocate memory for the copy of the route reply option	*/	copy_route_reply_option = dsr_pkt_support_route_reply_mem_alloc ();	copy_route_reply_option->last_hop_external = route_reply_option->last_hop_external;		/* Get the number of hops which includes	*/	/* the source and destination hops 			*/	num_hops = op_prg_list_size (route_reply_option->route_lptr);		for (count = 0; count < num_hops; count++)		{		hop_address_ptr = (InetT_Address*) op_prg_list_access (route_reply_option->route_lptr, count);		copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);		op_prg_list_insert (copy_route_reply_option->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		}		/* Allocate the main DSR header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_route_reply_option;		FRET (copy_dsr_tlv_ptr);	}static DsrT_Packet_Option*dsr_pkt_support_route_error_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Route_Error_Option*		route_error_option = OPC_NIL;	DsrT_Route_Error_Option*		copy_route_error_option = OPC_NIL;	DsrT_Packet_Option*				copy_dsr_tlv_ptr = OPC_NIL;		/** Makes a copy of the route error TLV field	**/	FIN (dsr_pkt_support_route_error_mem_copy (<args>));		/* Get the original route error option	*/	route_error_option = (DsrT_Route_Error_Option*) dsr_tlv_ptr->dsr_option_ptr;		/* Allocate memory for the copy	of the route error option */	copy_route_error_option = dsr_pkt_support_route_error_mem_alloc ();	copy_route_error_option->error_type = route_error_option->error_type;	copy_route_error_option->salvage = route_error_option->salvage;		/* Copy the relavent IP addresses	*/	copy_route_error_option->error_source_address = inet_address_copy (route_error_option->error_source_address);	copy_route_error_option->error_dest_address = inet_address_copy (route_error_option->error_dest_address);	copy_route_error_option->unreachable_node_address = inet_address_copy (route_error_option->unreachable_node_address);		/* Allocate the main DSR header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_route_error_option;		FRET (copy_dsr_tlv_ptr);	}static DsrT_Packet_Option*dsr_pkt_support_ack_request_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Acknowledgement_Request*	ack_request_option = OPC_NIL;	DsrT_Acknowledgement_Request*	copy_ack_request_option = OPC_NIL;	DsrT_Packet_Option*				copy_dsr_tlv_ptr = OPC_NIL;		/** Makes a copy of the acknowledgement request TLV field	**/	FIN (dsr_pkt_support_ack_request_mem_copy (<args>));		/* Get the original ack request option	*/	ack_request_option = (DsrT_Acknowledgement_Request*) dsr_tlv_ptr->dsr_option_ptr;		/* Allocate memory for the copy of the ack request option	*/	copy_ack_request_option = dsr_pkt_support_ack_request_mem_alloc ();	copy_ack_request_option->identification = ack_request_option->identification;		/* Allocate the main DSR header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_ack_request_option;		FRET (copy_dsr_tlv_ptr);	}static DsrT_Packet_Option*dsr_pkt_support_acknowledgement_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Acknowledgement*		acknowledgement_option = OPC_NIL;	DsrT_Acknowledgement*		copy_acknowledgement_option = OPC_NIL;	DsrT_Packet_Option*			copy_dsr_tlv_ptr = OPC_NIL;		/** Makes a copy of the acknowledgement TLV field	**/	FIN (dsr_pkt_support_acknowledgement_mem_copy (<args>));		/* Get the original acknowledgement option	*/	acknowledgement_option = (DsrT_Acknowledgement*) dsr_tlv_ptr->dsr_option_ptr;		/* Allocate memory for the copy of the acknowledgement option	*/	copy_acknowledgement_option = dsr_pkt_support_acknowledgement_mem_alloc ();	copy_acknowledgement_option->identification = acknowledgement_option->identification;	copy_acknowledgement_option->ack_source_address = inet_address_copy (acknowledgement_option->ack_source_address);	copy_acknowledgement_option->ack_dest_address = inet_address_copy (acknowledgement_option->ack_dest_address);		/* Allocate the main DSR header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_acknowledgement_option;		FRET (copy_dsr_tlv_ptr);	}static DsrT_Packet_Option*dsr_pkt_support_source_route_mem_copy (DsrT_Packet_Option* dsr_tlv_ptr)	{	DsrT_Source_Route_Option*	source_route_option = OPC_NIL;	DsrT_Source_Route_Option*	copy_source_route_option = OPC_NIL;	DsrT_Packet_Option*			copy_dsr_tlv_ptr = OPC_NIL;	int							count, num_hops;	InetT_Address*				hop_address_ptr;	InetT_Address*				copy_address_ptr;		/** Makes a copy of the DSR Source Route TLV field	**/	FIN (dsr_pkt_support_source_route_mem_copy (<args>));		/* Get the original source route option	*/	source_route_option = (DsrT_Source_Route_Option*) dsr_tlv_ptr->dsr_option_ptr;		/* Allocate memory for the copy of the acknowledgement option	*/	copy_source_route_option = dsr_pkt_support_source_route_mem_alloc ();	copy_source_route_option->first_hop_external = source_route_option->first_hop_external;	copy_source_route_option->last_hop_external = source_route_option->last_hop_external;	copy_source_route_option->export_route = source_route_option->export_route;	copy_source_route_option->salvage = source_route_option->salvage;	copy_source_route_option->segments_left = source_route_option->segments_left;		/* Copy all the hops	*/	num_hops = op_prg_list_size (source_route_option->route_lptr);		for (count = 0; count < num_hops; count++)		{		hop_address_ptr = (InetT_Address*) op_prg_list_access (source_route_option->route_lptr, count);		copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);		op_prg_list_insert (copy_source_route_option->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		}		/* Allocate the main DSR header	*/	copy_dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	copy_dsr_tlv_ptr->option_type = dsr_tlv_ptr->option_type;	copy_dsr_tlv_ptr->option_length = dsr_tlv_ptr->option_length;	copy_dsr_tlv_ptr->dsr_option_ptr = (void*) copy_source_route_option;		FRET (copy_dsr_tlv_ptr);	}static voiddsr_pkt_support_tlv_options_mem_free (List* tlv_options_lptr)	{	DsrT_Packet_Option*		dsr_tlv_ptr = OPC_NIL;	int						num_options, count;		/** Frees the list of options in the DSR packet	**/	FIN (dsr_pkt_support_tlv_options_mem_free (<args>));		/* Get the number of options	*/	num_options = op_prg_list_size (tlv_options_lptr);		for (count = 0; count < num_options; count++)		{		/* Get each option and free the option	*/		/* based on its option type				*/		dsr_tlv_ptr = (DsrT_Packet_Option*) op_prg_list_remove (tlv_options_lptr, OPC_LISTPOS_HEAD);				switch (dsr_tlv_ptr->option_type)			{			case (DSRC_ROUTE_REQUEST):				{				/* Route Request Option	*/				dsr_pkt_support_route_request_mem_free (dsr_tlv_ptr);				break;				}						case (DSRC_ROUTE_REPLY):				{				/* Route Reply Option	*/				dsr_pkt_support_route_reply_mem_free (dsr_tlv_ptr);				break;				}							case (DSRC_ROUTE_ERROR):				{				/* Route Error Option	*/				dsr_pkt_support_route_error_mem_free (dsr_tlv_ptr);				break;				}							case (DSRC_ACK_REQUEST):				{				/* Ack Request Option	*/				dsr_pkt_support_ack_request_mem_free (dsr_tlv_ptr);				break;				}

⌨️ 快捷键说明

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