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

📄 proc.pr.c

📁 802.11-MAC协议使用opnet仿真的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
					        printf("Packet DEST ID = %d\n", destid);
				            printf("Packet Duration Field = %lf\n", vcs_duration);
				    	#endif
								
						/*Instigate the next stage in the transmission process if the RTS packet is destined for this node*/
						/*and the channel is free, and the node is not currently involved in a transfer*/
						if( (destid == userid) && (pcs_state == 0) && (vcs_state == 0) && (inprogress == 0) )
						{ 
						    /*Schedule CTS Interrupt in SIFS seconds time*/
				 			nexttxevent = op_intrpt_schedule_self(op_sim_time() + sifs, CTS_INT);
							txreq = 2;
				        	txcode = CTS_INT;
							
						    /*Update the inprogress variable*/
				            inprogress = 1;
							
							#ifdef PRINT_RX_ARVL
				        	    printf("Packet is Destined for this node!\n");
				    	        printf("Scheduled a CTS transmission interrupt!\n");
				        	#endif
						}
					} 
				    /*If it is a CTS packet*/
				    else if(strcmp(pktname, "CTS_pkt") == 0)
				    {
				        /*Read the primary destination node user ID*/ 
						op_pk_nfd_get(pktptr, "DEST", &destid);
				
				 	    /*Determine the duration that the channel will be busy*/
				        op_pk_nfd_get(pktptr, "DURATION", &vcs_duration); 
						
						/*Schedule an interrupt to update the channel status*/
						op_intrpt_schedule_self(op_sim_time(), VCS_BUSY_INT);
						   			
						#ifdef PRINT_RX_ARVL
						    printf("CTS Packet Information:\n");
				            printf("Packet DEST ID = %d\n", destid);
				    		printf("Packet Duration Field = %lf\n", vcs_duration);
				    	#endif
								
						/*Instigate the next stage in the transmission process if the CTS packet is destined for this node*/
						/*and the channel is free*/
						if( (destid == userid) && (pcs_state == 0) && (vcs_state == 0) )
						{ 
						    /*Schedule DATA Interrupt in SIFS seconds time*/
				 			nexttxevent = op_intrpt_schedule_self(op_sim_time() + sifs, DATA_INT);
							txreq = 3;
				        	txcode = DATA_INT;
							
							#ifdef PRINT_RX_ARVL
				        	    printf("Packet is Destined for this node!\n");
				    	        printf("Scheduled a DATA transmission interrupt!\n");
				        	#endif
						}
					}
				    /*If it is a DATA packet*/
					else if(strcmp(pktname, "DATA_pkt") == 0)
				    {
					    /*Read the primary destination node user ID*/ 
						op_pk_nfd_get(pktptr, "DEST", &destid);
							
						#ifdef PRINT_RX_ARVL
						    printf("DATA Packet Information:\n");
				            printf("Packet DEST ID = %d\n", destid);
				    	#endif
								
						/*Instigate the next stage in the transmission process if the DATA packet is destined for this node*/
						/*and the channel is free*/
						if( (destid == userid) && (pcs_state == 0) && (vcs_state == 0) )
						{ 
						    /*Write out statistics if it is the final node*/
						
						    /*Schedule ACK Interrupt in SIFS seconds time*/
				 			nexttxevent = op_intrpt_schedule_self(op_sim_time() + sifs, ACK_INT);
							txreq = 4;
				        	txcode = ACK_INT;
								
						   	#ifdef PRINT_RX_ARVL
				        	    printf("Packet is Destined for this node!\n");
				    	        printf("Scheduled an ACK transmission interrupt!\n");
				        	#endif
						}
					}
				    /*If it is a DATA packet*/
					else if(strcmp(pktname, "ACK_pkt") == 0)
				    {	
				        /*Read the primary destination node user ID*/ 
						op_pk_nfd_get(pktptr, "DEST", &destid);
							
						#ifdef PRINT_RX_ARVL
						    printf("ACK Packet Information:\n");
				            printf("Packet DEST ID = %d\n", destid);
				    	#endif
								
						/*Instigate the next stage in the transmission process if the DATA packet is destined for this node*/
						/*and the channel is free*/
						if( (destid == userid) && (pcs_state == 0) && (vcs_state == 0) )
						{ 
				            /*Write out Statistics if it is the final node*/
						  		
						    /*Update the inprogress variable*/
				            inprogress = 0;
							
							#ifdef PRINT_RX_ARVL
				        	    printf("Packet is Destined for this node!\n");
				    	        printf("A transfer is complete!\n");
				        	#endif
							
						}
					}
				}
				else
				{
				    #ifdef PRINT_RX_ARVL
					    printf("Packet Cannot be Received\n");
				        printf("Packet Type = %s\n", pktname);
					#endif
				}
				
				/*Destroy the packet*/
				op_pk_destroy(pktptr);
				}

				FSM_PROFILE_SECTION_OUT ("Proc [RX_ARVL enter execs]", state6_enter_exec)

			/** state (RX_ARVL) exit executives **/
			FSM_STATE_EXIT_FORCED (6, "RX_ARVL", "Proc [RX_ARVL exit execs]")
				FSM_PROFILE_SECTION_IN ("Proc [RX_ARVL exit execs]", state6_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT ("Proc [RX_ARVL exit execs]", state6_exit_exec)


			/** state (RX_ARVL) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "RX_ARVL", "WAIT")
				/*---------------------------------------------------------*/



			/** state (ROB) enter executives **/
			FSM_STATE_ENTER_FORCED (7, state7_enter_exec, "ROB", "Proc [ROB enter execs]")
				FSM_PROFILE_SECTION_IN ("Proc [ROB enter execs]", state7_enter_exec)
				{
				/*Determine a suitable backoff time if not already calculated*/
				if(rob == -1.0)
				{
				    //TEMP BACKOFF STRATEGY FOR NOW
				    rob = op_dist_uniform(10);
				
				    #ifdef PRINT_ROB
				        printf("Calculating a Random Backoff Time!\n");
					    printf("Backofftime = %lf\n", rob);
				    #endif
				}
				
				/*Schedule the appropriate transmission interrupt on expiry of the backoff timer*/
				nexttxevent = op_intrpt_schedule_self(op_sim_time() + rob, txcode);
					
#ifdef PRINT_ROB
				    printf("Scheduled a Transmission Interrupt in ROB State\n");
#endif
				}

				FSM_PROFILE_SECTION_OUT ("Proc [ROB enter execs]", state7_enter_exec)

			/** state (ROB) exit executives **/
			FSM_STATE_EXIT_FORCED (7, "ROB", "Proc [ROB exit execs]")
				FSM_PROFILE_SECTION_IN ("Proc [ROB exit execs]", state7_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT ("Proc [ROB exit execs]", state7_exit_exec)


			/** state (ROB) transition processing **/
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "ROB", "WAIT")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,Proc)
		}
	}

#if defined (__cplusplus)
	extern "C" { 
#endif
	extern VosT_Fun_Status Vos_Catmem_Register (const char * , int , VosT_Void_Null_Proc, VosT_Address *);
	extern VosT_Address Vos_Catmem_Alloc (VosT_Address, size_t);
	extern VosT_Fun_Status Vos_Catmem_Dealloc (VosT_Address);
#if defined (__cplusplus)
	}
#endif


Compcode
Proc_init (void ** gen_state_pptr)
	{
	int _block_origin = 0;
	static VosT_Address	obtype = OPC_NIL;

	FIN (Proc_init (gen_state_pptr))

	if (obtype == OPC_NIL)
		{
		/* Initialize memory management */
		if (Vos_Catmem_Register ("proc state vars (Proc)",
			sizeof (Proc_state), Vos_Vnop, &obtype) == VOSC_FAILURE)
			{
			FRET (OPC_COMPCODE_FAILURE)
			}
		}

	*gen_state_pptr = Vos_Catmem_Alloc (obtype, 1);
	if (*gen_state_pptr == OPC_NIL)
		{
		FRET (OPC_COMPCODE_FAILURE)
		}
	else
		{
		/* Initialize FSM handling */
		((Proc_state *)(*gen_state_pptr))->current_block = 0;

		FRET (OPC_COMPCODE_SUCCESS)
		}
	}



void
Proc_diag (void)
	{
	/* No Diagnostic Block */
	}




void
Proc_terminate (void)
	{
	int _block_origin = __LINE__;

	FIN (Proc_terminate (void))

	Vos_Catmem_Dealloc (pr_state_ptr);

	FOUT
	}


/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in Proc_svar function. */
#undef tx_range
#undef rx_range
#undef proc_id
#undef node_id
#undef nodename
#undef userid
#undef subnet_id
#undef xpos
#undef ypos
#undef numnodes
#undef tx_id
#undef txcomp_id
#undef txch_id
#undef difs
#undef sifs
#undef rx_id
#undef rxcomp_id
#undef rxch_id
#undef pcs_state
#undef vcs_state
#undef inprogress
#undef vcs_duration
#undef chfreeint
#undef nexttxevent
#undef txcode
#undef robevent
#undef txreq
#undef rob
#undef srcobjid
#undef srcprohandle



void
Proc_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
	{
	Proc_state		*prs_ptr;

	FIN (Proc_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (char *)OPC_NIL;
		FOUT
		}
	prs_ptr = (Proc_state *)gen_ptr;

	if (strcmp ("tx_range" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->tx_range);
		FOUT
		}
	if (strcmp ("rx_range" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rx_range);
		FOUT
		}
	if (strcmp ("proc_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->proc_id);
		FOUT
		}
	if (strcmp ("node_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->node_id);
		FOUT
		}
	if (strcmp ("nodename" , var_name) == 0)
		{
		*var_p_ptr = (char *) (prs_ptr->nodename);
		FOUT
		}
	if (strcmp ("userid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->userid);
		FOUT
		}
	if (strcmp ("subnet_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->subnet_id);
		FOUT
		}
	if (strcmp ("xpos" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->xpos);
		FOUT
		}
	if (strcmp ("ypos" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->ypos);
		FOUT
		}
	if (strcmp ("numnodes" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->numnodes);
		FOUT
		}
	if (strcmp ("tx_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->tx_id);
		FOUT
		}
	if (strcmp ("txcomp_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->txcomp_id);
		FOUT
		}
	if (strcmp ("txch_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->txch_id);
		FOUT
		}
	if (strcmp ("difs" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->difs);
		FOUT
		}
	if (strcmp ("sifs" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->sifs);
		FOUT
		}
	if (strcmp ("rx_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rx_id);
		FOUT
		}
	if (strcmp ("rxcomp_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rxcomp_id);
		FOUT
		}
	if (strcmp ("rxch_id" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rxch_id);
		FOUT
		}
	if (strcmp ("pcs_state" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->pcs_state);
		FOUT
		}
	if (strcmp ("vcs_state" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->vcs_state);
		FOUT
		}
	if (strcmp ("inprogress" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->inprogress);
		FOUT
		}
	if (strcmp ("vcs_duration" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->vcs_duration);
		FOUT
		}
	if (strcmp ("chfreeint" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->chfreeint);
		FOUT
		}
	if (strcmp ("nexttxevent" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->nexttxevent);
		FOUT
		}
	if (strcmp ("txcode" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->txcode);
		FOUT
		}
	if (strcmp ("robevent" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->robevent);
		FOUT
		}
	if (strcmp ("txreq" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->txreq);
		FOUT
		}
	if (strcmp ("rob" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->rob);
		FOUT
		}
	if (strcmp ("srcobjid" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->srcobjid);
		FOUT
		}
	if (strcmp ("srcprohandle" , var_name) == 0)
		{
		*var_p_ptr = (char *) (&prs_ptr->srcprohandle);
		FOUT
		}
	*var_p_ptr = (char *)OPC_NIL;

	FOUT
	}

⌨️ 快捷键说明

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