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

📄 ramimo_proc.pr.c

📁 用OPNET实现802.11MAC协议DCF协议
💻 C
📖 第 1 页 / 共 5 页
字号:
			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_LOGIC ("WAIT")
			FSM_PROFILE_SECTION_OUT (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")
				}
				/*---------------------------------------------------------*/



			/** state (END) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, "END", state2_enter_exec, "ramimo_proc [END enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc [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 (state2_enter_exec)

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


			/** state (END) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "END", "ramimo_proc [END exit execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc [END exit execs]", state2_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (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 [SRCARVL enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc [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               */
				/**********************************************************************************/
				
				/*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]++;
				
#ifdef PRINT_SRC_ARVL
				    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 an RTS transmission if the channel is free and the node is not busy*/
				if( (pcs_state == 0) && (vcs_state == 0) && (busy == 0) )
				{
				    /*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("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
				}
				
				/*Place it in the queue ready for transmission*/
				op_subq_pk_insert(SRC_QUEUE, pktptr, OPC_QPOS_TAIL);
				
				op_prg_odb_bkpt("SRCARVL");
				//op_prg_odb_bkpt("TEST");
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (SRCARVL) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "SRCARVL", "ramimo_proc [SRCARVL exit execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc [SRCARVL exit execs]", state3_exit_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (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 [TX enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc [TX enter execs]", state4_enter_exec)
				{
#ifdef PRINT_TX
				    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("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));
				
					/*Work out the propagation delay between the source to destination node*/
				    propdelay = distance/300000000.0;
					
					/*Determine the expected duration of the subsequent exchange of data*/
					/*This is the sum of the packet durations less RTS, two SIFS and 3 propdelays*/
				    tempdouble = ((ctspktsize+datapktsize+ackpktsize)/datarate) + (2.0*sifs) + (3.0*propdelay); 
					
					/*Set the fields of the CTS 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);
					
					#ifdef PRINT_TX
				    	printf("Transmitting a CTS 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);	
				    #endif
				}
				/*If transmission of a DATA packet*/
				else if(DATA)
				{
				    /*Access the packet at the head of the SRC subqueue*/
				    origpktptr = op_subq_pk_access(SRC_QUEUE, OPC_QPOS_HEAD);
				    
					/*Create a copy of the packet for transmission*/
				    pktptr = op_pk_copy(origpktptr);
				
				  	/*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 * ((datapktsize/datarate) + (2.0*propdelay) + (ackpktsize/datarate) + sifs);
					timeout = op_intrpt_schedule_self(op_sim_time() + tempdouble, TX_TIMEOUT_INT);
				
				 	/*Record statistics if from node 0 to 3*/
				    /*BOTH THESE STATISTICS ARE CONTRIVED FOR SPECIFIC SCENARIO*/
					if( (userid == 0) && (commnodeid == 9) )
				        op_stat_write_t(txstat, 3, op_sim_time());
					
					op_stat_write_t(linkstat, commnodeid, op_sim_time());
					
					//printf("NODE ID = %d\n", userid);
					//printf("Transmitting Data Packet at %lf time\n", op_sim_time());
					//op_prg_odb_bkpt("WIN");
					
					#ifdef PRINT_TX
				    	printf("Transmitting a copy of a DATA 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);
					    op_pk_nfd_get(pktptr, "number", &tempdouble);
					    printf("Packet Sequence Number = %lf\n", tempdouble);
					    printf("Scheduled a DATA Timeout Interrupt for %lfs\n", op_ev_time(timeout));
				    #endif
					
				    #ifdef PACKET
					    printf("Transmitting a Data Packet from Node %d!\n", userid);
					    op_pk_nfd_get(pktptr, "SRC", &tempint);
					 	printf("SRC Node = %d\n", tempint);
					    op_pk_nfd_get(pktptr, "DEST", &tempint);
					 	printf("DEST Node = %d\n", tempint);
					    op_prg_odb_bkpt("PACKET");
				    #endif

⌨️ 快捷键说明

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