job.c 4.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************

  Eurecom OpenAirInterface
  Copyright(c) 1999 - 2011 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fsr/openairinterface
  Address      : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France

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

/*! \file job.c
* \brief handle jobs for future nodes' update
32
33
* \author  S. Gashaw, M. Mahersi,  J. Harri, N. Nikaein,
* \date 2014
34
35
36
37
38
39
40
41
42
43
44
45
46
* \version 0.1
* \company Eurecom
* \email: 
* \note
* \warning
*/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#include "omg.h"

47
48
49
50
51
52
53
54
55
56
57
58
59
60
job_list *
add_job (pair_struct * job, job_list * job_vector)
{

  job_list *tmp;
  job_list *entry = (job_list *) malloc (sizeof (struct job_list_struct));
  entry->pair = job;
  entry->next = NULL;

  if (job_vector != NULL)
    {

      tmp = job_vector;
      tmp->next = entry;
61
    }
62
63
64

  return entry;

65
66
}

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//add_job2

job_list *
addjob (pair_struct * job, job_list * job_vector)
{

  job_list *tmp;
  job_list *entry = (job_list *) malloc (sizeof (struct job_list_struct));
  entry->pair = job;
  entry->next = NULL;

  if (job_vector == NULL)
    {
      return entry;
    }
  else
    {
      tmp = job_vector;
      while (tmp->next != NULL)
	{
	  tmp = tmp->next;
	}

      tmp->next = entry;
    }

  return job_vector;


}
97
98

// display list of jobs
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
void
display_job_list (double curr_t, job_list * job_vector)
{

  job_list *tmp = job_vector;
  if (tmp == NULL)
    {
      LOG_D (OMG, "Empty Job_list\n");
    }
  else
    {
      //LOG_D(OMG, "first_Job_time in Job_Vector %f\n", Job_Vector->pair->a);
      while (tmp != NULL)
	{
	  if ((tmp->pair != NULL) /*&& tmp->pair->b->id==0 */ )
	    //LOG_D(OMG, "%.2f %.2f \n",tmp->pair->b->x_pos, tmp->pair->b->y_pos);
	    LOG_D (OMG, "%.2f  %d %d %.2f %.2f  %.2f\n", curr_t, tmp->pair->b->id,tmp->pair->b->gid,
		   tmp->pair->b->x_pos, tmp->pair->b->y_pos,
		   tmp->pair->b->mob->speed);
118
119


120
	  tmp = tmp->next;
121

122
	}
123
    }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
}

//average nodes speed for each mobility type
unsigned int
nodes_avgspeed (job_list * job_vector)
{
  job_list *tmp = job_vector;
  unsigned int avg = 0, cnt = 0;
  if (tmp == NULL)
    {
      LOG_D (OMG, "Empty Job_list\n");
      return 0;
    }
  else
    {
      while (tmp != NULL)
	{
	  if ((tmp->pair != NULL))
	    {
	      avg += tmp->pair->b->mob->speed;
	      cnt++;
	    }
	  tmp = tmp->next;
	}
    }
  return avg / cnt;
150
151
152
}

// quick sort of the linked list
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
job_list *
job_list_sort (job_list * list, job_list * end)
{

  job_list *pivot, *tmp, *next, *before, *after;
  if (list != end && list->next != end)
    {

      pivot = list;
      before = pivot;
      after = end;
      for (tmp = list->next; tmp != end; tmp = next)
	{
	  next = tmp->next;
	  if (tmp->pair->next_event_t > pivot->pair->next_event_t)
	    tmp->next = after, after = tmp;
	  else
	    tmp->next = before, before = tmp;
	}

      before = job_list_sort (before, pivot);
      after = job_list_sort (after, end);

      pivot->next = after;
      return before;
178
    }
179
  return list;
180
181
}

182
183
job_list *
quick_sort (job_list * list)
184
{
185
  return job_list_sort (list, NULL);
186
187
188
}


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
job_list *
remove_job (job_list * list, int nid, int node_type)
{

  job_list *current, *previous;

  current = list;
  previous = NULL;
  while (current != NULL)
    {
      if (current->pair->b->id == nid && current->pair->b->type == node_type)
	{
	  if (current == list || previous == NULL)
	    list = current->next;
	  else
	    previous->next = current->next;

	  free (current);
	  break;

	}
      previous = current;
211
212
      current = current->next;
    }
213
  return list;
214

215
}