Example #1
0
File: rwalk.c Project: a4a881d4/oai
void update_rwalk_nodes(double cur_time) {// need to implement an out-of-area check as well as a rebound function to stay in the area
   LOG_D(OMG, "--------UPDATE--------\n");
   Job_list tmp = Job_Vector;
   int done = 0; //
   while ((tmp != NULL) && (done == 0)){
      //if 	(tmp->pair == NULL){LOG_E(OMG, "UPDATE RWALK : tmp->pair ==NULL\n" );}
      //if 	(tmp->pair != NULL){LOG_E(OMG, "UPDATE RWALK : tmp->pair !=NULL\n" );}
	   LOG_D(OMG, "cur_time %f\n", cur_time );
		LOG_D(OMG, "tmp->pair->a  %f\n", tmp->pair->a  );

      if((tmp->pair !=NULL) && ( (double)tmp->pair->a >= cur_time - eps) && ( (double)tmp->pair->a <= cur_time + eps) ) { 
		   if (tmp->pair->b->generator == RWALK){
				LOG_D(OMG, " (first_job_time) %.2f == %.2f (cur_time) \n ",tmp->pair->a, cur_time );
 				LOG_D(OMG, " UPDATE RWALK \n ");
				NodePtr my_node = (NodePtr)tmp->pair->b;
				/*if(my_node->mobile == 1) {
 					LOG_D(OMG, " stop node and let it sleep \n" );
					my_node->mobile = 0;
					Pair pair = malloc(sizeof(Pair));
					pair = sleep_rwalk_node(my_node, cur_time);
					tmp->pair = pair;
					tmp = tmp->next;
				}*/
				if ((my_node->mobile ==0) || (my_node->mobile == 1)) {
					LOG_D(OMG, " node %d...let's move again \n",  my_node->ID);
					my_node->mobile = 1;
					Pair pair = malloc(sizeof(Pair));
					pair = move_rwalk_node(my_node, cur_time);
					tmp->pair = pair;
					tmp = tmp->next;
				}
				else{
			  		LOG_E(OMG, "update_generator: unsupported node state - mobile : %d \n", my_node->mobile);
					//exit(-1);
				}
         }
         else {
            LOG_D(OMG, " (first_job_time) %.2f == %.2f(cur_time) but (generator=%d) != (RWALK=%d)\n ",tmp->pair->a, cur_time, tmp->pair->b->generator, RWALK );
            tmp = tmp->next;
         }
      }
		else if ( (tmp->pair != NULL) && (cur_time < tmp->pair->a ) ){  //&& (tmp->pair->b->generator == RWALK)
		    LOG_D(OMG, " %.2f < %.2f \n",cur_time, tmp->pair->a);
		    LOG_D(OMG, "Nothing to do\n");
			 done = 1;  //quit the loop
		}
      else {
			LOG_E(OMG, "\n %.2f > %.2f", cur_time,tmp->pair->a   );   //LOG_D(OMG, " (generator=%d) != (RWALK=%d) \n", tmp->pair->b->generator,  RWALK );
		   done = 1;  //quit the loop
         exit(-1);
		}	
 }
			//sorting the new entries
			LOG_D(OMG, "--------DISPLAY JOB LIST--------\n"); //LOG_T
  			display_job_list(Job_Vector);
 			Job_Vector = quick_sort (Job_Vector);///////////
  			LOG_D(OMG, "--------DISPLAY JOB LIST AFTER SORTING--------\n"); 
 			display_job_list(Job_Vector);
}
Example #2
0
int
main (int argc, char *argv[])
{
  int i, node_type;
  double cur_time = 0.0;
  double ms = 0.0;
  node_list *current_positions = NULL;
  node_struct *my_node = NULL;
  int my_id = 0, time_s;
  double emu_info_time;
  char full_name[200];
  int pfd[2];     // fd for omv : fixme: this could be a local var
  char fdstr[10];
  char frames[10];
  char num_enb[10];
  char num_ue[10];
  //area_x, area_y and area_z for omv
  char x_area[20];
  char y_area[20];
  char z_area[20];
  char fname[64], vname[64];
  Data_Flow_Unit omv_data;

  //default parameters
  for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) {


    if (node_type == UE)
      omg_param_list[node_type].nodes = 5;
    else
      omg_param_list[node_type].nodes = 0;

    omg_param_list[node_type].min_x = 0;
    omg_param_list[node_type].max_x = 100;
    omg_param_list[node_type].min_y = 0;
    omg_param_list[node_type].max_y = 100;
    omg_param_list[node_type].min_speed = 0.1;
    omg_param_list[node_type].max_speed = 20.0;
    omg_param_list[node_type].min_journey_time = 0.1;
    omg_param_list[node_type].max_journey_time = 20.0;
    omg_param_list[node_type].min_azimuth = 0;
    omg_param_list[node_type].max_azimuth = 360;
    omg_param_list[node_type].min_sleep = 0.1;
    omg_param_list[node_type].max_sleep = 5.0;
    omg_param_list[node_type].mobility_file = "TRACE/mobility_3ues.tr";
    omg_param_list[node_type].mobility_type = STATIC;
    omg_param_list[node_type].nodes_type = node_type;
    //omg_param_list.sumo_config = "SUMO/SCENARIOS/traci.koln.sumo.cfg";
    omg_param_list[node_type].sumo_command = "sumo-gui";
    omg_param_list[node_type].sumo_config =
      "SUMO/SCENARIOS/traci.scen.sumo.cfg";
    omg_param_list[node_type].sumo_start = 0; //25900;
    omg_param_list[node_type].sumo_end = 200; //26200;
    omg_param_list[node_type].sumo_step = 1;
    omg_param_list[node_type].sumo_host = "localhost";
    omg_param_list[node_type].sumo_port = 8890;
  }


  init_omg_global_params ();  //initialize global paramaters

  get_options (argc, argv); // overwrite the default params if any input parameter

  for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) {
    omg_param_list[node_type].max_vertices =
      max_vertices_ongrid (omg_param_list[node_type]);

    omg_param_list[node_type].max_block_num =
      max_connecteddomains_ongrid (omg_param_list[node_type]);

  }



  init_mobility_generator (omg_param_list); //initialize choosen mobility generator

  // ****************init omv********************
  if (omv_enabled == 1) {
    if (pipe (pfd) == -1)
      perror ("pipe error \n");

    sprintf (full_name, "%s/UTIL/OMV/OMV", getenv ("OPENAIR2_DIR"));
    LOG_I (EMU, "Stating the OMV path %s pfd[0] %d pfd[1] %d \n", full_name,
           pfd[0], pfd[1]);





    switch (fork ()) {
    case -1:
      perror ("fork failed \n");
      break;

    case 0:
      if (close (pfd[1]) == -1)
        perror ("close on write\n");

      sprintf (fdstr, "%d", pfd[0]);
      sprintf (num_enb, "%d", 1);
      sprintf (num_ue, "%d", omg_param_list[UE].nodes);
      sprintf (x_area, "%f", omg_param_list[UE].max_x);
      sprintf (y_area, "%f", omg_param_list[UE].max_y);
      sprintf (z_area, "%f", 200.0);
      sprintf (frames, "%d", (int) n_frames);

      execl (full_name, "OMV", fdstr, frames, num_enb, num_ue, x_area,
             y_area, z_area, NULL);
      perror ("error in execl the OMV");
    }

    //parent
    if (close (pfd[0]) == -1)
      perror ("close on read\n");
  }

  //******************************

  for (emu_info_time = 0.0; emu_info_time <= n_frames; emu_info_time += 0.1) {

    update_nodes (emu_info_time);
    time_s = round (emu_info_time * 1000.0);

    //printf("%d \n",time_s);
    for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) {
      current_positions =
        get_current_positions (omg_param_list[node_type].mobility_type,
                               node_type, emu_info_time);

      if (current_positions != NULL)

        display_job_list (emu_info_time,
                          job_vector[omg_param_list
                                     [node_type].mobility_type]);

      /*if(current_positions!= NULL && time_s %1000==0)
         LOG_D(OMG, "%.2f  %d\n",emu_info_time,
         nodes_avgspeed(job_vector[omg_param_list [node_type].mobility_type])); */
    }


    //display current postion of nodes
    if (omv_enabled == 1)
      omv_write (pfd[1], node_vector[SUMO], omv_data);


  }

  /*LOG_I(OMG,"#-----event average-----\n");
     for (i=0;i<100;i++)
     {
     if(events[i]!=0)
     LOG_D(OMG,"%d %d \n",i,event_sum[i]/events[i]);
     } */

  stop_mobility_generator (omg_param_list);

  if (omv_enabled == 1)
    omv_end (pfd[1], omv_data);

  //clear_mem();

  return 0;
}