📄 ramimo_proc_multichannel.pr.c
字号:
char pktname[20];
int srcid;
int destid;
double seqnum;
double propdelay;
Packet *rtspktptr;
listentry* listentryptr;
int lowpos;
int highpos;
int array[100];
int x;
int flag;
int retry;
double max_distance;
double min_distance;
Objid dest_node_id;
double dest_xpos;
double dest_ypos;
double d_source;
double d_destination;
int nexthop;
int prevhop;
double etoedelay;
double variancedelay;
FSM_ENTER ("ramimo_proc_multichannel")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (INIT) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "INIT", "ramimo_proc_multichannel [INIT enter execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [INIT enter execs]", state0_enter_exec)
{
/*Initialise Variables*/
userid = 0;
numnodes = 0;
pcs_state = 0;
vcs_state = 0;
txstate = 0;
busy = 0;
txreq = 0;
ssrc = 0;
slrc = 0;
numretries = 0;
tx_range = 0.0;
rx_range = 0.0;
xpos = 0.0;
ypos = 0.0;
difs = 0.0;
sifs = 0.0;
vcs_duration = 0.0;
rob = -1.0;
sequencenum = -1.0;
lastdelay = 0.0;
/*Determine the number of mobile nodes*/
numnodes = op_topo_object_count(OPC_OBJTYPE_NDMOB);
/*Read in the simulation attributes*/
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "SIFS", &sifs);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "tx_range", &tx_range);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "rx_range", &rx_range);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "DATA_pktsize", &datapktsize);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "ACK_pktsize", &ackpktsize);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "RTS_pktsize", &rtspktsize);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "CTS_pktsize", &ctspktsize);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "aSlotTime", &aSlotTime);
op_ima_sim_attr_get(OPC_IMA_INTEGER, "retrylimit", &retrylimit);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "USER_LOAD", &userload);
op_ima_sim_attr_get(OPC_IMA_STRING, "scenario", &scenario);
op_ima_sim_attr_get(OPC_IMA_DOUBLE, "resulttime", &resulttime);
/*Register Statistics*/
etoedelaystat = op_stat_reg("ENDTOENDDLY", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
variancedlystat = op_stat_reg("VARIANCEDLY", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
txstat = op_stat_reg("TXSTAT", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
rxstat = op_stat_reg("RXSTAT", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
discstat = op_stat_reg("DISCSTAT", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
linkstat = op_stat_reg("LINKSTAT", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
/*Initialise Variables*/
for(i=0;i<7;i++)
cw_vals[i] = pow(2,(i+4)) - 1.0;
cw_current = cw_vals[0];
if(userid == 0)
for(i=0;i<numnodes;i++)
for(j=0;j<numnodes;j++)
{
pktar[i][j] = 0;
pktdi[i][j] = 0;
pktqu[i][j] = 0;
pktrx[i][j] = 0;
}
/*Create a list to keep a record of received packets*/
listptr = op_prg_list_create();
/*Determine the corresponding DIFS period*/
difs = sifs + (2.0*aSlotTime);
/*Obtain the required object ID's for this node*/
proc_id = op_id_self();
node_id = op_topo_parent(proc_id);
subnet_id = op_topo_parent(node_id);
tx_id = op_topo_assoc(proc_id, OPC_TOPO_ASSOC_OUT, OPC_OBJTYPE_RATX, 0);
txcomp_id = op_topo_child(tx_id, OPC_OBJTYPE_COMP, 0);
txch_id = op_topo_child(txcomp_id, OPC_OBJTYPE_RATXCH, 0);
rx_id = op_topo_assoc(proc_id, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);
rxcomp_id = op_topo_child(rx_id, OPC_OBJTYPE_COMP, 0);
rxch_id = op_topo_child(rxcomp_id, OPC_OBJTYPE_RARXCH, 0);
/*Obtain the datarate of the transmitter channel*/
op_ima_obj_attr_get(txch_id, "data rate", &datarate);
/****************************************************************************************/
/*Derive the appropriate user ID from the node name and set the user ID object attribute*/
/****************************************************************************************/
/*Read the node name into a string*/
op_ima_obj_attr_get(node_id, "name", &nodename);
/*Extract the numerical part of the node name*/
namelength = strlen(nodename);
for(i=12; i<=namelength; i++)
{
i_temp = nodename[i];
i_temp = i_temp - '0';
if(i_temp >=0)
nodenum = 10*nodenum + i_temp;
}
/*Set the user ID object attribute*/
userid = nodenum;
op_ima_obj_attr_set(node_id, "user id", userid);
/*Set the appropriate frequencies of the transmitter and receiver channels*/
//if((userid == 0)||(userid == 2)||(userid == 4)||(userid == 6)||(userid == 8)||(userid == 10))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5180.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5180.0);
//}
//else
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5200.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5200.0);
//}
/*Set the appropriate frequencies of the transmitter and receiver channels*/
//if((userid == 0)||(userid == 4)||(userid == 8))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5200.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5200.0);
//}
//else if((userid == 1)||(userid == 5)||(userid == 9))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5220.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5220.0);
//}
//else if((userid == 2)||(userid == 6)||(userid == 10))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5240.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5240.0);
//}
//else if((userid == 3)||(userid == 7))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5180.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5180.0);
//}
/*Set the appropriate frequencies of the transmitter and receiver channels*/
//if((userid == 0)||(userid == 8))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5200.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5200.0);
//}
//else if((userid == 2)||(userid == 10))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5220.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5220.0);
//}
//else if((userid == 4))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5240.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5240.0);
//}
//else if((userid == 6))
//{
// op_ima_obj_attr_set(txch_id, "min frequency", 5180.0);
// op_ima_obj_attr_set(rxch_id, "min frequency", 5180.0);
//}
if((userid == 0))
{
op_ima_obj_attr_set(txch_id, "min frequency", 5200.0);
op_ima_obj_attr_set(rxch_id, "min frequency", 5200.0);
}
else if((userid == 5))
{
op_ima_obj_attr_set(txch_id, "min frequency", 5220.0);
op_ima_obj_attr_set(rxch_id, "min frequency", 5220.0);
}
else if((userid == 10))
{
op_ima_obj_attr_set(txch_id, "min frequency", 5240.0);
op_ima_obj_attr_set(rxch_id, "min frequency", 5240.0);
}
#ifdef PRINT_INIT
printf("INIT STATE - ENTER EXECS\n");
printf("Scenario = %s\n", scenario);
printf("Sifs = %lf\n", sifs);
printf("Transmission Range = %lf\n", tx_range);
printf("Receiving Range = %lf\n", rx_range);
printf("Data Packet Size = %lf\n", datapktsize);
printf("ACK Packet Size = %lf\n", ackpktsize);
printf("RTS Packet Size = %lf\n", rtspktsize);
printf("CTS Packet Size = %lf\n", ctspktsize);
printf("aSlotTime = %lf\n", aSlotTime);
printf("retry limit = %d\n", retrylimit);
for(i=0;i<7;i++)
printf("cw_vals[%d] = %lf\n", i, cw_vals[i]);
printf("cw_current = %lf\n", cw_current);
printf("Difs = %lf\n", difs);
printf("TX Channel Data Rate = %lf\n", datarate);
printf("Node Name = %s\n", nodename);
op_ima_obj_attr_get(node_id, "user id", &tempint);
printf("Object Attribute User ID = %d\n", tempint);
op_ima_obj_attr_get(txch_id, "min frequency", &tempdouble);
printf("Transmitter Channel Freq = %lf\n", tempdouble);
op_ima_obj_attr_get(rxch_id, "min frequency", &tempdouble);
printf("Receiver Channel Freq = %lf\n", tempdouble);
#endif
/*Schedule an interrupt to carry out the rest of the initialisation once all user IDs have been set*/
op_intrpt_schedule_self(op_sim_time(), 0);
/*Get a handle to the root process model of the packet generator*/
srcobjid = op_id_from_name(node_id, OPC_OBJTYPE_PROC, "SRC");
srcprohandle = op_pro_root(srcobjid);
/*Schedule an interrupt to carry out the initialisation of the packet generator for the appropriate nodes once all user IDs have been set*/
if((strcmp(scenario, "singleline") == 0) && (userid == 0))
op_intrpt_schedule_process(srcprohandle, op_sim_time(), PROC_INT);
if((strcmp(scenario, "dualline") == 0) && ((userid == 0) || (userid == 11)))
op_intrpt_schedule_process(srcprohandle, op_sim_time(), PROC_INT);
if((strcmp(scenario, "squaregrid") == 0) || (strcmp(scenario, "hexgrid") == 0))
op_intrpt_schedule_process(srcprohandle, op_sim_time(), PROC_INT);
op_prg_odb_bkpt("INIT");
op_prg_odb_bkpt("TEST");
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,"ramimo_proc_multichannel")
/** state (INIT) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, "INIT", "ramimo_proc_multichannel [INIT exit execs]")
FSM_PROFILE_SECTION_IN ("ramimo_proc_multichannel [INIT exit execs]", state0_exit_exec)
{
/*********************************************************************************************/
/*Determine the receiving range of the nodes and hence determine which nodes are within */
/*communications range. Set the receiver group as appropriate. */
/*********************************************************************************************/
/*Determine the location of this node*/
op_ima_obj_attr_get(node_id, "x position", &xpos);
op_ima_obj_attr_get(node_id, "y position", &ypos);
for(i=0;i<numnodes;i++)
{
/*Get the object ID of a node in the subnet*/
other_node_id = op_topo_child(subnet_id, OPC_OBJTYPE_NDMOB, i);
/*Determine the location of the another node*/
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));
/*Add them to the receiver group if they are within receiving range*/
if(distance < rx_range)
{
/*Get the object ID of the other nodes receiver channel*/
other_proc_id = op_topo_child(other_node_id, OPC_OBJTYPE_QUEUE, 0);
other_rx_id = op_topo_assoc(other_proc_id, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);
other_rxcomp_id = op_topo_child(other_rx_id, OPC_OBJTYPE_COMP, 0);
other_rxch_id = op_topo_child(other_rxcomp_id, OPC_OBJTYPE_RARXCH, 0);
/*Add the node to the receiver group of this transmitter*/
op_radio_txch_rxch_add(txch_id, other_rxch_id);
/*Get the object ID of the other nodes receiver channel*/
other_proc_id = op_topo_child(other_node_id, OPC_OBJTYPE_QUEUE, 1);
other_rx_id = op_topo_assoc(other_proc_id, OPC_TOPO_ASSOC_IN, OPC_OBJTYPE_RARX, 0);
other_rxcomp_id = op_topo_child(other_rx_id, OPC_OBJTYPE_COMP, 0);
other_rxch_id = op_topo_child(other_rxcomp_id, OPC_OBJTYPE_RARXCH, 0);
/*Add the node to the receiver group of this transmitter*/
op_radio_txch_rxch_add(txch_id, other_rxch_id);
}
}
/***************************************/
/*Set up the routing table information */
/***************************************/
for(i=0;i<numnodes;i++)
{
max_distance = 0; //max distance from source to intermediate hop
min_distance = 1e10; //min distance from intermediate hop to destination
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -