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

📄 ramimo_proc_par.pr.c

📁 用OPNET实现802.11MAC协议DCF协议
💻 C
📖 第 1 页 / 共 5 页
字号:
			FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "INIT", "WAIT")
				/*---------------------------------------------------------*/



			/** state (WAIT) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, "WAIT", state1_enter_exec, "ramimo_proc_par [WAIT enter execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [WAIT enter execs], state1_enter_exec)
				{
				}

				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [WAIT enter execs], state1_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,"ramimo_proc_par")


			/** state (WAIT) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "WAIT", "ramimo_proc_par [WAIT exit execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [WAIT exit execs], state1_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [WAIT exit execs], state1_exit_exec)


			/** state (WAIT) transition processing **/
			FSM_PROFILE_SECTION_IN (ramimo_proc_par [WAIT trans conditions], state1_trans_conds)
			FSM_INIT_COND (END)
			FSM_TEST_COND (SRC_ARVL)
			FSM_TEST_COND (CTS)
			FSM_TEST_COND (RTS)
			FSM_TEST_COND (DATA)
			FSM_TEST_COND (ACK)
			FSM_TEST_COND (PCS)
			FSM_TEST_COND (RX_ARVL)
			FSM_TEST_COND (VCS_busy)
			FSM_TEST_COND (VCS_free)
			FSM_TEST_COND (ROB)
			FSM_TEST_COND (TX_TIMEOUT)
			FSM_TEST_COND (RX_TIMEOUT)
			FSM_TEST_COND (PKT_ARVL)
			FSM_TEST_LOGIC ("WAIT")
			FSM_PROFILE_SECTION_OUT (ramimo_proc_par [WAIT trans conditions], state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "END", "", "WAIT", "END")
				FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "SRC_ARVL", "", "WAIT", "SRCARVL")
				FSM_CASE_TRANSIT (2, 4, state4_enter_exec, ;, "CTS", "", "WAIT", "TX")
				FSM_CASE_TRANSIT (3, 4, state4_enter_exec, ;, "RTS", "", "WAIT", "TX")
				FSM_CASE_TRANSIT (4, 4, state4_enter_exec, ;, "DATA", "", "WAIT", "TX")
				FSM_CASE_TRANSIT (5, 4, state4_enter_exec, ;, "ACK", "", "WAIT", "TX")
				FSM_CASE_TRANSIT (6, 5, state5_enter_exec, ;, "PCS", "", "WAIT", "SENSE")
				FSM_CASE_TRANSIT (7, 6, state6_enter_exec, ;, "RX_ARVL", "", "WAIT", "RXARVL")
				FSM_CASE_TRANSIT (8, 5, state5_enter_exec, ;, "VCS_busy", "", "WAIT", "SENSE")
				FSM_CASE_TRANSIT (9, 5, state5_enter_exec, ;, "VCS_free", "", "WAIT", "SENSE")
				FSM_CASE_TRANSIT (10, 7, state7_enter_exec, ;, "ROB", "", "WAIT", "ROB")
				FSM_CASE_TRANSIT (11, 8, state8_enter_exec, ;, "TX_TIMEOUT", "", "WAIT", "TIMEOUT")
				FSM_CASE_TRANSIT (12, 8, state8_enter_exec, ;, "RX_TIMEOUT", "", "WAIT", "TIMEOUT")
				FSM_CASE_TRANSIT (13, 3, state3_enter_exec, ;, "PKT_ARVL", "", "WAIT", "SRCARVL")
				}
				/*---------------------------------------------------------*/



			/** state (END) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, "END", state2_enter_exec, "ramimo_proc_par [END enter execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [END enter execs], state2_enter_exec)
				{
				/*Only want one node to write out these statistics*/
				if(userid == 0)
				{	
				    /*Write out the scalar statistics*/
				    op_stat_scalar_write("USER_LOAD", userload);
				    op_stat_scalar_write("NUMGENPKTS", numgenpkts);
				    op_stat_scalar_write("NUMDISCPKTS", numdiscpkts);
				    op_stat_scalar_write("NUMRXPKTS", numrxpkts);
					
					for(i=0;i<numnodes;i++)
					{
					    for(j=0;j<numnodes;j++)
						{	
					        printf("Number of Packets Generated at Node %d for Node %d = %d\n", i, j, pktar[i][j]);
				    		printf("Number of Packets Discarded at Node %d for Node %d = %d\n", i, j, pktdi[i][j]);
				        	printf("Number of Packets Queued at Node %d for Node %d = %d\n", i, j, pktqu[i][j]);
				            printf("Number of Packets Received at Node %d from Node %d = %d\n\n", j, i, pktrx[i][j]);
				          }
						op_prg_odb_bkpt("END");
				    }
				    
				}
				}

				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [END enter execs], state2_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (5,"ramimo_proc_par")


			/** state (END) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "END", "ramimo_proc_par [END exit execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [END exit execs], state2_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [END exit execs], state2_exit_exec)


			/** state (END) transition processing **/
			FSM_TRANSIT_MISSING ("END")
				/*---------------------------------------------------------*/



			/** state (SRCARVL) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "SRCARVL", state3_enter_exec, "ramimo_proc_par [SRCARVL enter execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [SRCARVL enter execs], state3_enter_exec)
				{
				/**********************************************************************************/
				/*Queue the packet from the traffic generator ready for transmission              */
				/*Schedule an RTS transmission interrupt to start the transmission process if the */
				/*channel is free and the node is not currently processing anything               */
				/**********************************************************************************/
				
				if(SRC_ARVL)
				{
				    /*Get the packet from the incoming stream*/
				    pktptr = op_pk_get(SRC_STRM);
				
				    /*Calculate and store the next and previous (current) hop for this packet*/
				    op_pk_nfd_get(pktptr, "SRC", &srcid);
				    op_pk_nfd_get(pktptr, "DEST", &destid);
				    op_pk_nfd_set(pktptr, "nexthop", r_table[destid][0]);
				    op_pk_nfd_set(pktptr, "prevhop", userid);
				    op_pk_nfd_get(pktptr, "number", &seqnum);
				
				    /*Increment the number of generated packets*/
				    numgenpkts++;
				
				    /*Increment a variable to count the number of packet arrivals destined for specific nodes*/
				    pktar[srcid][destid]++;
				    pktqu[srcid][destid]++;
				
				    /*Place it in the queue ready for transmission*/
				    op_subq_pk_insert(SRC_QUEUE, pktptr, OPC_QPOS_TAIL);
				
				    #ifdef PRINT_SRC_ARVL
					    printf("PARENT PROC\n");
				        printf("SRCARVL STATE\n");
				        printf("Node %d\n", userid);
				        printf("Packet Source = %d\n", srcid);
				        printf("Packet Destination = %d\n", destid);
				        printf("Packet Next Hop = %d\n", r_table[destid][0]);
				        printf("Packet Prev Hop = %d\n", srcid);
				        printf("Packet Sequence Number = %lf\n", seqnum);
				        printf("Packet Inserted Into SRC Queue\n");
				    #endif
					
					/*Schedule a SRC_ARVL interrupt for the child process*/
				    op_intrpt_schedule_process(childproc, op_sim_time(), 0);
				}
				
				
#ifdef PRINT_SRC_ARVL
				    printf("PARENT PROC\n");
				    printf("Attempting to schedule an RTS transmission\n");
				    printf("Channel busy status = %d\n", busy);
					printf("Channel PCS State = %d\n", pcs_state);
				    printf("Channel VCS State = %d\n", vcs_state);
#endif
				
				/*Schedule an RTS transmission if the channel is free and the node is not busy*/
				if( (pcs_state == 0) && (vcs_state == 0) && (busy == 0) )
				{
				    /*Initilise a flag variable*/
				    flag = 0;
				
				    /*Search through the packet queue to identify an appropriate one to transmit*/
				    for(i=0;i<op_subq_stat(SRC_QUEUE, OPC_QSTAT_PKSIZE);i++)
					{
					    /*Access the packet at the appropriate position*/
					    pktptr = op_subq_pk_access(SRC_QUEUE, i);
				
						/*Determine the ID of the corresponding source node*/
						op_pk_nfd_get(pktptr, "SRC", &srcid);
				
						#ifdef PRINT_SRC_ARVL
						    printf("PARENT PROC\n");
				            printf("Packet SRC ID = %d\n", srcid);
				            printf("Child TX SRC ID = %d\n", sharedptr->chitxsrcid);
				        #endif
						
						/*If a packet is found from a different source than the one being handled by the other channel, schedule an RTS for it*/
						if((srcid != sharedptr->chitxsrcid) && (flag == 0))
						{
						    flag = 1;
				
							/*Set the variable to indicate the ID of the source*/
							sharedptr->partxsrcid = srcid;
							
							/*Set the destination node ID to be associated with the tx interrupt*/
							op_pk_nfd_get(pktptr, "nexthop", &commnodeid);
				         	op_pk_nfd_get(pktptr, "number", &sequencenum);
					
				            /*Schedule RTS Interrupt in DIFS seconds time*/
				            nexttxevent = op_intrpt_schedule_self(op_sim_time() + difs, RTS_INT);
				        	txreq = 1;
				        	txstate = RTS_INT;
				        	busy = 1;
					
				         	/*Reset the random backoff interval if this is a new transmission*/
				         	rob = -1.0;
						
				            #ifdef PRINT_SRC_ARVL
							    printf("PARENT PROC\n");
				        	    printf("Scheduled an RTS transmission interrupt in DIFS seconds!\n");
				          	    printf("Will be communicating with node %d\n", commnodeid);
				         	    printf("Packet Sequence Number = %lf\n", sequencenum);
				            #endif
						}
					}
				}
				
				
				op_prg_odb_bkpt("SRCARVL");
				}

				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [SRCARVL enter execs], state3_enter_exec)

			/** state (SRCARVL) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "SRCARVL", "ramimo_proc_par [SRCARVL exit execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [SRCARVL exit execs], state3_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (ramimo_proc_par [SRCARVL exit execs], state3_exit_exec)


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



			/** state (TX) enter executives **/
			FSM_STATE_ENTER_FORCED (4, "TX", state4_enter_exec, "ramimo_proc_par [TX enter execs]")
				FSM_PROFILE_SECTION_IN (ramimo_proc_par [TX enter execs], state4_enter_exec)
				{
#ifdef PRINT_TX
					    printf("PARENT PROC\n");
				    printf("TX STATE\n");    
					printf("Node %d\n", userid);
#endif
					
				/*If transmission of an RTS packet*/
				if(RTS)
				{
				    /*Create an RTS packet*/
				    pktptr = op_pk_create_fmt("RTS_pkt");
					 	
					/*set the appropriate size of the packet - An RTS packet is 20 bytes*/
					op_pk_total_size_set(pktptr, rtspktsize);
						
					/*Determine the location of the destination node*/
				    other_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, commnodeid); 
					
					op_ima_obj_attr_get(other_node_id, "x position", &other_xpos);
				    op_ima_obj_attr_get(other_node_id, "y position", &other_ypos);
				
					/*Work out the distance between nodes*/
				    distance = sqrt((other_xpos - xpos)*(other_xpos - xpos) + (other_ypos - ypos)*(other_ypos - ypos));
				
					/*Work out the propagation delay between the source to destination node*/
				    propdelay = distance/300000000.0;
					
					/*Schedule an interrupt for timeout if a CTS packet is not received*/
					tempdouble = 1.1 * ((rtspktsize/datarate) + (2.0*propdelay) + (ctspktsize/datarate) + sifs);
					timeout = op_intrpt_schedule_self(op_sim_time() + tempdouble, TX_TIMEOUT_INT);
					
					/*Determine the expected duration of the subsequent exchange of data*/
					/*This is the sum of the packet durations, three SIFS and 4 propdelays*/
				    tempdouble = ((rtspktsize+ctspktsize+datapktsize+ackpktsize)/datarate) + (3.0*sifs) + (4.0*propdelay); 
						
					/*Set the fields of the RTS packet*/
					op_pk_nfd_set(pktptr, "SRC", userid);
					op_pk_nfd_set(pktptr, "DEST", commnodeid);
					op_pk_nfd_set(pktptr, "DURATION", tempdouble);
					op_pk_nfd_set(pktptr, "number", sequencenum);
				
				    //printf("NODE ID = %d\n", userid);
					//printf("Transmitting an RTS Packet at %lf time\n", op_sim_time());
					//op_prg_odb_bkpt("WIN");
						
				    #ifdef PRINT_TX
						    printf("PARENT PROC\n");
				    	printf("Transmitting an RTS Packet\n");
					    printf("Packet Size = %d\n", op_pk_total_size_get(pktptr));
					    op_pk_nfd_get(pktptr, "SRC", &srcid);
					    printf("Packet Source = %d\n", srcid);
					    op_pk_nfd_get(pktptr, "DEST", &destid);
					    printf("Packet Destination = %d\n", destid);
					    printf("Distance Between Nodes = %lf\n", distance);
					    printf("Propagation Delay Between Nodes = %1.10lf\n", propdelay);
					 	op_pk_nfd_get(pktptr, "DURATION", &tempdouble);
					    printf("Packet Duration Field = %lf\n", tempdouble);	
					 	op_pk_nfd_get(pktptr, "number", &tempdouble);
					    printf("Packet Sequence Number = %lf\n", tempdouble);	
					    printf("Scheduled an RTS Timeout Interrupt for %lfs\n", op_ev_time(timeout));
						printf("A transfer is commencing!\n");
				    #endif
					
				}
				/*If transmission of a CTS packet*/
				else if(CTS)
				{
				    /*Create an CTS packet*/
				    pktptr = op_pk_create_fmt("CTS_pkt");
				    
					/*set the appropriate size of the packet - A CTS packet is 14 bytes*/
					op_pk_total_size_set(pktptr, ctspktsize);
					
					/*Determine the location of the destination node*/
				    other_node_id = op_id_from_userid(subnet_id, OPC_OBJTYPE_NDMOB, commnodeid); 
					
					op_ima_obj_attr_get(other_node_id, "x position", &other_xpos);
				    op_ima_obj_attr_get(other_node_id, "y position", &other_ypos);
				
					/*Work out the distance between nodes*/
				    distance = sqrt((other_xpos - xpos)*(other_xpos - xpos) + (other_ypos - ypos)*(other_ypos - ypos));
				

⌨️ 快捷键说明

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