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

📄 dsr_pkt_support.ex.c

📁 opnet11.5 manet dsr和aodv协议
💻 C
📖 第 1 页 / 共 4 页
字号:
		FRET (src_addr);		}	else if (access_number > (num_hops - 1))		{		/* Return the destination address	*/		FRET (dest_addr);		}	else		{		next_hop_address_ptr = (InetT_Address*) op_prg_list_access (source_route_ptr->route_lptr, access_number);		FRET (*next_hop_address_ptr);		}	}/*****************************************************//************** TLV CREATION FUNCTIONS ***************//*****************************************************/DsrT_Packet_Option*dsr_pkt_support_route_request_tlv_create (long int request_id, InetT_Address dest_address)	{	DsrT_Route_Request_Option*			route_request_ptr = OPC_NIL;	DsrT_Packet_Option*					dsr_tlv_ptr = OPC_NIL;	int 								address_length;		/** Creates the route request option in the DSR packet	**/	FIN (dsr_pkt_support_route_request_tlv_create (<args>));		address_length = (inet_address_family_get (&dest_address) == InetC_Addr_Family_v4 ? IP_V4_ADDRESS_LENGTH : IP_V6_ADDRESS_LENGTH);	route_request_ptr = dsr_pkt_support_route_request_mem_alloc ();	route_request_ptr->identification = request_id;	route_request_ptr->target_address = inet_address_copy (dest_address);		dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_ROUTE_REQUEST;	dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS + address_length;	dsr_tlv_ptr->dsr_option_ptr = (void*) route_request_ptr;		FRET (dsr_tlv_ptr);	}DsrT_Packet_Option*dsr_pkt_support_route_reply_tlv_create (InetT_Address PRG_ARG_UNUSED (src_address), InetT_Address dest_address, 											List* intermediate_hops_lptr, Boolean last_hop_external)	{	DsrT_Route_Reply_Option*			route_reply_ptr = OPC_NIL;	DsrT_Packet_Option*					dsr_tlv_ptr = OPC_NIL;	int									count, num_hops;	int									address_length;	InetT_Address*						hop_address_ptr;	InetT_Address*						copy_address_ptr = OPC_NIL;		/** Creates the route reply TLV in the DSR packet	**/	FIN (dsr_pkt_support_route_reply_tlv_create (<args>));		route_reply_ptr = dsr_pkt_support_route_reply_mem_alloc ();	route_reply_ptr->last_hop_external = last_hop_external;	num_hops = op_prg_list_size (intermediate_hops_lptr);		for (count = 0; count < num_hops; count++)		{		hop_address_ptr = (InetT_Address*) op_prg_list_access (intermediate_hops_lptr, count);		copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);		op_prg_list_insert (route_reply_ptr->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		}		/* Insert the destination node address at the tail of the list	*/	copy_address_ptr = inet_address_create_dynamic (dest_address);	op_prg_list_insert (route_reply_ptr->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		/* Allocate the main DSR header	*/	dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_ROUTE_REPLY;		/* The number of addresses are the number of 	*/	/* intermediate hops and the source and			*/	/* destination addresses						*/	address_length = (inet_address_family_get (copy_address_ptr) == InetC_Addr_Family_v4 ? IP_V4_ADDRESS_LENGTH : IP_V6_ADDRESS_LENGTH);	dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS + address_length * (num_hops + 2);	dsr_tlv_ptr->dsr_option_ptr = (void*) route_reply_ptr;		FRET (dsr_tlv_ptr);	}DsrT_Packet_Option*dsr_pkt_support_route_error_tlv_create (int error_type, int salvage, InetT_Address src_address, InetT_Address dest_address,											InetT_Address unreachable_node_address)	{	DsrT_Route_Error_Option*		route_error_ptr = OPC_NIL;	DsrT_Packet_Option*				dsr_tlv_ptr = OPC_NIL;	int								address_length;		/** Creates the route error TLV in the DSR packet	**/	FIN (dsr_pkt_support_route_error_tlv_create (<args>));		/* Allocate the route error option	*/	route_error_ptr = dsr_pkt_support_route_error_mem_alloc ();	route_error_ptr->error_type = error_type;	route_error_ptr->salvage = salvage;		/* Copy the relavent IP addresses	*/	route_error_ptr->error_source_address = inet_address_copy (src_address);	route_error_ptr->error_dest_address = inet_address_copy (dest_address);	route_error_ptr->unreachable_node_address = inet_address_copy (unreachable_node_address);		/* Allocate the main DSR header	*/	dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_ROUTE_ERROR;		/* There are three IP addresses in this packet	*/	address_length = (inet_address_family_get (&src_address) == InetC_Addr_Family_v4 ? IP_V4_ADDRESS_LENGTH : IP_V6_ADDRESS_LENGTH);	dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS + address_length * 3;	dsr_tlv_ptr->dsr_option_ptr = (void*) route_error_ptr;		FRET (dsr_tlv_ptr);	}DsrT_Packet_Option*dsr_pkt_support_ack_request_tlv_create (int ack_request_id)	{	DsrT_Acknowledgement_Request*	ack_request_ptr = OPC_NIL;	DsrT_Packet_Option*				dsr_tlv_ptr = OPC_NIL;		/** Creates the acknowledgement request	**/	/** TLV in the DSR packet				**/	FIN (dsr_pkt_support_ack_request_tlv_create (<args>));		/* Allocate the acknowledgement request option	*/	ack_request_ptr = dsr_pkt_support_ack_request_mem_alloc ();	ack_request_ptr->identification = ack_request_id;		/* Allocate the main DSR header	*/	dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_ACK_REQUEST;	dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS;	dsr_tlv_ptr->dsr_option_ptr = (void*) ack_request_ptr;		FRET (dsr_tlv_ptr);	}DsrT_Packet_Option*dsr_pkt_support_acknowledgement_tlv_create (int ack_request_id, InetT_Address source_address, InetT_Address dest_address)	{	DsrT_Acknowledgement*		acknowledgement_ptr = OPC_NIL;	DsrT_Packet_Option*			dsr_tlv_ptr = OPC_NIL;	int							address_length;		/** Creates the acknowledgement TLV in the DSR packet **/	FIN (dsr_pkt_support_acknowledgement_tlv_create (<args>));		/* Allocate the acknowledgement option	*/	acknowledgement_ptr = dsr_pkt_support_acknowledgement_mem_alloc ();	acknowledgement_ptr->identification = ack_request_id;	acknowledgement_ptr->ack_source_address = inet_address_copy (source_address);	acknowledgement_ptr->ack_dest_address = inet_address_copy (dest_address);		/* Allocate the main DSR header	*/	dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_ACKNOWLEDGEMENT;		/* There are two IP addresses in the packet	*/	address_length = (inet_address_family_get (&source_address) == InetC_Addr_Family_v4 ? IP_V4_ADDRESS_LENGTH : IP_V6_ADDRESS_LENGTH);	dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS + address_length * 2;	dsr_tlv_ptr->dsr_option_ptr = (void*) acknowledgement_ptr;		FRET (dsr_tlv_ptr);	}DsrT_Packet_Option*dsr_pkt_support_source_route_tlv_create (List* route_lptr, Boolean first_hop_external, 							Boolean last_hop_external, Boolean route_export, Boolean packet_salvaging)	{	DsrT_Source_Route_Option*	source_route_ptr = OPC_NIL;	DsrT_Packet_Option*			dsr_tlv_ptr = OPC_NIL;	InetT_Address*				hop_address_ptr;	InetT_Address*				copy_address_ptr = OPC_NIL;	int							num_hops, count;	int							start_count;	int							address_length;		/** Creates the source route TLV in the DSR packet **/	FIN (dsr_pkt_support_source_route_tlv_create (<args>));		/* Allocate the source route option	*/	source_route_ptr = dsr_pkt_support_source_route_mem_alloc ();	source_route_ptr->first_hop_external = first_hop_external;	source_route_ptr->last_hop_external = last_hop_external;	source_route_ptr->export_route = route_export;		/* Initailize the salvage to zero	*/	source_route_ptr->salvage = 0;		/* Get the number of hops	*/	num_hops = op_prg_list_size (route_lptr);		/* The source node needs to be included for	*/	/* packet salvaging							*/	if (packet_salvaging == OPC_FALSE)		{		start_count = 1;		}	else		{		/* Packet salvaging	*/		start_count = 0;		}		/* Set the number of hops remaining	*/	source_route_ptr->segments_left = num_hops - 2;				/* Copy each hop except the first and last hop	*/	/* since the source route contains all the		*/	/* intermediate hops except the source and 		*/	/* destination address							*/	for (count = start_count; count < (num_hops - 1); count++)		{		hop_address_ptr = (InetT_Address*) op_prg_list_access (route_lptr, count);		copy_address_ptr = inet_address_copy_dynamic (hop_address_ptr);		op_prg_list_insert (source_route_ptr->route_lptr, copy_address_ptr, OPC_LISTPOS_TAIL);		}		/* Get the number of hops in the source route	*/	num_hops = op_prg_list_size (source_route_ptr->route_lptr);		/* Allocate the main DSR header	*/	dsr_tlv_ptr = dsr_pkt_support_option_mem_alloc ();	dsr_tlv_ptr->option_type = DSRC_SOURCE_ROUTE;		/* Set the option length based on the number	*/	/* of IP addresses present in the option		*/	if (copy_address_ptr != OPC_NIL)		address_length = (inet_address_family_get (copy_address_ptr) == InetC_Addr_Family_v4 ? IP_V4_ADDRESS_LENGTH : IP_V6_ADDRESS_LENGTH);	else		address_length = 0;		dsr_tlv_ptr->option_length = DSR_HEADER_OPTIONS + address_length * num_hops;	dsr_tlv_ptr->dsr_option_ptr = (void*) source_route_ptr;		FRET (dsr_tlv_ptr);	}		voiddsr_pkt_support_options_print (void* tlv_options_lptr1, VosT_Ll_Desc* output_list1)	{	char							temp_str [256];	char							ip_addr_str [INETC_ADDR_STR_LEN];	char*							alloc_str;	char*							route_str;	int								num_options, count;	DsrT_Packet_Option*				dsr_tlv_ptr;	DsrT_Route_Request_Option*		route_request_option_ptr;	DsrT_Route_Reply_Option*		route_reply_option_ptr;	DsrT_Route_Error_Option*		route_error_option_ptr;	DsrT_Acknowledgement_Request*	ack_request_option_ptr;	DsrT_Acknowledgement*			ack_option_ptr;	DsrT_Source_Route_Option*		source_route_option_ptr;	List* 							tlv_options_lptr;	Prg_List* 						output_list;		/** Prints the options set in the DSR packet	**/	/** to an output list which is passd into the	**/	/** print procedure for the packet print		**/	FIN (dsr_pkt_support_options_print (<args>));		/* Initialize the parameters. */	tlv_options_lptr = (List*) tlv_options_lptr1;	output_list = (Prg_List*) output_list1;		/* 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 print its contents	*/		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_ptr = (DsrT_Route_Request_Option*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      ROUTE REQUEST OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								sprintf (temp_str, "        Route Request ID                   %ld", route_request_option_ptr->identification);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								inet_address_print(ip_addr_str, route_request_option_ptr->target_address);				sprintf (temp_str, "        Route Request Target Address        %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								route_str = dsr_support_route_print (route_request_option_ptr->route_lptr);				strcpy (temp_str, "        Route Traversed");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);				DSR_PKPRINT_STRING_INSERT (alloc_str, route_str, output_list);								break;				}						case (DSRC_ROUTE_REPLY):				{				route_reply_option_ptr = (DsrT_Route_Reply_Option*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      ROUTE REPLY OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								route_str = dsr_support_route_print (route_reply_option_ptr->route_lptr);				strcpy (temp_str, "        Reply Packet Route");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);				DSR_PKPRINT_STRING_INSERT (alloc_str, route_str, output_list);								break;				}						case (DSRC_ROUTE_ERROR):				{				route_error_option_ptr = (DsrT_Route_Error_Option*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      ROUTE ERROR OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								if (route_error_option_ptr->error_type == 1)					{					strcpy (temp_str, "        Route Error Cause                   Unreachable Node");					DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);					}								inet_address_print(ip_addr_str, route_error_option_ptr->error_source_address);				sprintf (temp_str, "        Route Error Source Address        %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								inet_address_print(ip_addr_str, route_error_option_ptr->error_dest_address);				sprintf (temp_str, "        Route Error Destination Address   %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								inet_address_print(ip_addr_str, route_error_option_ptr->unreachable_node_address);				sprintf (temp_str, "        Unreachable Node Address          %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								sprintf (temp_str, "        Salvage Count                     %d", route_error_option_ptr->salvage);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								break;				}							case (DSRC_ACK_REQUEST):				{				ack_request_option_ptr = (DsrT_Acknowledgement_Request*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      ACKNOWLEDGEMENT REQUEST OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								sprintf (temp_str, "        Acknowledgement Request ID        %ld", ack_request_option_ptr->identification);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								break;				}						case (DSRC_ACKNOWLEDGEMENT):				{				ack_option_ptr = (DsrT_Acknowledgement*) dsr_tlv_ptr->dsr_option_ptr;								strcpy (temp_str, "      ACKNOWLEDGEMENT OPTION");				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								sprintf (temp_str, "        Acknowledgement ID                    %ld", ack_option_ptr->identification);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								inet_address_print(ip_addr_str, ack_option_ptr->ack_source_address);				sprintf (temp_str, "        Acknowledgement Source Address        %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);								inet_address_print(ip_addr_str, ack_option_ptr->ack_dest_address);				sprintf (temp_str, "        Acknowledgement Destination Address   %s", ip_addr_str);				DSR_PKPRINT_STRING_INSERT (alloc_str, temp_str, output_list);				

⌨️ 快捷键说明

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