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

📄 ramimo_proc_multichannel2.pr.c

📁 用OPNET实现802.11MAC协议DCF协议
💻 C
📖 第 1 页 / 共 5 页
字号:
				    printf("Obtaining Information On The Receiver Group\n");
				    op_radio_txch_rxgroup_get(txch_id, &numreceivers, &receivers);
				    printf("Number of Receivers = %d\n", numreceivers);
				    for(i=0;i<numreceivers;i++)
					{
				        op_ima_obj_attr_get(op_topo_parent(op_topo_assoc(op_topo_parent(op_topo_parent(receivers[i])), OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_QUEUE, 0)), "user id", &tempint);
						printf("Receiver User ID = %d\n", tempint); 
					}
					for(i=0;i<numnodes;i++)
					{
					    printf("Routing Table Information\n");
						printf("Source Node %d\n", userid);
						printf(    "Dest NN  SD   DD\n");
						printf("%d    %d   %d   %d\n", i,r_table[i][0],r_table[i][1],r_table[i][2]);
					}
				
#endif
				
				if(userid == 0)
				op_prg_odb_bkpt("TEST");
				}
				FSM_PROFILE_SECTION_OUT (state0_exit_exec)


			/** state (INIT) transition processing **/
			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_multichannel2 [WAIT enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [WAIT enter execs]", state1_enter_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (state1_enter_exec)

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


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


			/** state (WAIT) transition processing **/
			FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [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_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_multichannel2 [END enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [END enter execs]", state2_enter_exec)
				{
				}
				FSM_PROFILE_SECTION_OUT (state2_enter_exec)

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


			/** state (END) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "END", "ramimo_proc_multichannel2 [END exit execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [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_multichannel2 [SRCARVL enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [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);
				
#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_multichannel2 [SRCARVL exit execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [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_multichannel2 [TX enter execs]")
				FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel2 [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*/

⌨️ 快捷键说明

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