enb.c 31.9 KB
Newer Older
1 2 3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
4
#include <unistd.h>
5
#include <pthread.h>
6
#include <signal.h>
7 8 9 10 11 12
#include "database.h"
#include "event.h"
#include "handler.h"
#include "logger/logger.h"
#include "view/view.h"
#include "gui/gui.h"
13
#include "filter/filter.h"
14 15 16
#include "utils.h"
#include "../T_defs.h"
#include "event_selector.h"
Cedric Roux's avatar
Cedric Roux committed
17
#include "openair_logo.h"
18
#include "config.h"
19

Cedric Roux's avatar
Cedric Roux committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33
/****************************************************************************/
/* conversion from rnti to "ue_id" (which does not really exists)           */
/* the idea is to assign an ue_id to an rnti as soon as we get an event     */
/* for the rnti                                                             */
/****************************************************************************/

int ue_id[65536];
int next_ue_id;

void reset_ue_ids(void)
{
  int i;
  printf("resetting known UEs\n");
  for (i = 0; i < 65536; i++) ue_id[i] = -1;
34 35 36 37
  ue_id[65535] = 0;
  ue_id[65534] = 1;     /* HACK: to be removed */
  ue_id[2]     = 2;     /* this supposes RA RNTI = 2, very openair specific */
  next_ue_id = 3;
Cedric Roux's avatar
Cedric Roux committed
38 39 40 41
}

int ue_id_from_rnti(void *_priv, int rnti)
{
Cedric Roux's avatar
Cedric Roux committed
42 43
  if (rnti < 0) rnti = 65534; /* HACK, to be removed */

Cedric Roux's avatar
Cedric Roux committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57
  if (rnti < 0 || rnti > 65535) { printf("bad rnti %d\n", rnti); exit(1); }
  /* rnti not seen yet? give it a new ue_id */
  if (ue_id[rnti] == -1) {
    ue_id[rnti] = next_ue_id;
    next_ue_id++;
  }
  return ue_id[rnti];
}

/****************************************************************************/
/* end of rnti->ue_id conversion                                            */
/****************************************************************************/


Cedric Roux's avatar
Cedric Roux committed
58
typedef struct {
59
  view *phyview;
Cedric Roux's avatar
Cedric Roux committed
60 61 62
  view *macview;
  view *rlcview;
  view *pdcpview;
Cedric Roux's avatar
Cedric Roux committed
63
  view *rrcview;
Cedric Roux's avatar
Cedric Roux committed
64
  view *legacy;
Cedric Roux's avatar
Cedric Roux committed
65
  widget *current_ue_label;
Cedric Roux's avatar
Cedric Roux committed
66
  widget *current_ue_button;
Cedric Roux's avatar
Cedric Roux committed
67 68 69 70 71 72 73
  widget *prev_ue_button;
  widget *next_ue_button;
  widget *pusch_iq_ue_xy_plot;
  widget *ul_estimate_ue_xy_plot;
  widget *pucch1_energy_ue_xy_plot;
  widget *pucch_iq_ue_xy_plot;
  widget *dl_ul_harq_ue_label;
74 75
  widget *dl_mcs_xy_plot;
  widget *ul_mcs_xy_plot;
Cedric Roux's avatar
Cedric Roux committed
76 77 78 79 80 81 82 83 84 85 86 87
  logger *pusch_iq_ue_logger;
  logger *ul_estimate_ue_logger;
  logger *pucch1_energy_ue_threshold_logger;
  logger *pucch1_energy_ue_energy_logger;
  logger *pucch_iq_ue_logger;
  logger *dl_dci_logger[8];
  logger *dl_ack_logger[8];
  logger *dl_nack_logger[8];
  logger *ul_dci_logger[8];
  logger *ul_dci_retransmission_logger[8];
  logger *ul_ack_logger[8];
  logger *ul_nack_logger[8];
88 89
  logger *dl_mcs_logger;
  logger *ul_mcs_logger;
Cedric Roux's avatar
Cedric Roux committed
90 91
} enb_gui;

92 93 94 95 96
typedef struct {
  int socket;
  int *is_on;
  int nevents;
  pthread_mutex_t lock;
Cedric Roux's avatar
Cedric Roux committed
97 98 99
  enb_gui *e;
  int ue;                /* what UE is displayed in the UE specific views */
  void *database;
100
  int nb_rb;
101 102 103 104 105 106 107 108 109 110 111 112
} enb_data;

void is_on_changed(void *_d)
{
  enb_data *d = _d;
  char t;

  if (pthread_mutex_lock(&d->lock)) abort();

  if (d->socket == -1) goto no_connection;

  t = 1;
113 114 115
  if (socket_send(d->socket, &t, 1) == -1 ||
      socket_send(d->socket, &d->nevents, sizeof(int)) == -1 ||
      socket_send(d->socket, d->is_on, d->nevents * sizeof(int)) == -1)
116
    goto connection_dies;
117 118 119

no_connection:
  if (pthread_mutex_unlock(&d->lock)) abort();
120 121 122 123 124 125
  return;

connection_dies:
  close(d->socket);
  d->socket = -1;
  if (pthread_mutex_unlock(&d->lock)) abort();
126 127
}

128 129 130 131 132 133 134
static void *gui_thread(void *_g)
{
  gui *g = _g;
  gui_loop(g);
  return NULL;
}

Cedric Roux's avatar
Cedric Roux committed
135
static filter *ticktime_filter(void *database, char *event, int i, int ue)
136
{
Cedric Roux's avatar
Cedric Roux committed
137
  /* filter is "harq_pid == i && UE_id == 0 && eNB_id == 0" */
Cedric Roux's avatar
Cedric Roux committed
138
  /* we get the UE_id from the rnti */
139 140 141 142
  return
    filter_and(
      filter_eq(filter_evarg(database, event, "harq_pid"), filter_int(i)),
      filter_and(
Cedric Roux's avatar
Cedric Roux committed
143 144 145 146
        filter_eq(
          filter_evfun(database, ue_id_from_rnti, NULL,
            filter_evarg(database, event, "rnti")),
          filter_int(ue)),
147 148 149
        filter_eq(filter_evarg(database, event, "eNB_ID"), filter_int(0))));
}

Cedric Roux's avatar
Cedric Roux committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
static void set_current_ue(gui *g, enb_data *e, int ue)
{
  int i;
  char s[256];

  sprintf(s, "[UE %d]  ", ue);
  label_set_text(g, e->e->current_ue_label, s);
  sprintf(s, "PUSCH IQ [UE %d]", ue);
  xy_plot_set_title(g, e->e->pusch_iq_ue_xy_plot, s);
  sprintf(s, "UL estimated channel [UE %d]", ue);
  xy_plot_set_title(g, e->e->ul_estimate_ue_xy_plot, s);
  sprintf(s, "PUCCH1 energy (SR) [UE %d]", ue);
  xy_plot_set_title(g, e->e->pucch1_energy_ue_xy_plot, s);
  sprintf(s, "PUCCH IQ [UE %d]", ue);
  xy_plot_set_title(g, e->e->pucch_iq_ue_xy_plot, s);
  sprintf(s, "DL/UL HARQ (x8) [UE %d]", ue);
  label_set_text(g, e->e->dl_ul_harq_ue_label, s);
167 168 169 170
  sprintf(s, "DL MCS [UE %d]", ue);
  xy_plot_set_title(g, e->e->dl_mcs_xy_plot, s);
  sprintf(s, "UL MCS [UE %d]", ue);
  xy_plot_set_title(g, e->e->ul_mcs_xy_plot, s);
Cedric Roux's avatar
Cedric Roux committed
171 172 173

  logger_set_filter(e->e->pusch_iq_ue_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
174 175
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_PUSCH_IQ", "rnti")),
Cedric Roux's avatar
Cedric Roux committed
176 177 178
        filter_int(ue)));
  logger_set_filter(e->e->ul_estimate_ue_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
179 180
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_UL_CHANNEL_ESTIMATE", "rnti")),
Cedric Roux's avatar
Cedric Roux committed
181 182 183
        filter_int(ue)));
  logger_set_filter(e->e->pucch1_energy_ue_threshold_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
184 185
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_PUCCH_1_ENERGY", "rnti")),
Cedric Roux's avatar
Cedric Roux committed
186 187 188
        filter_int(ue)));
  logger_set_filter(e->e->pucch1_energy_ue_energy_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
189 190
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_PUCCH_1_ENERGY", "rnti")),
Cedric Roux's avatar
Cedric Roux committed
191 192 193
        filter_int(ue)));
  logger_set_filter(e->e->pucch_iq_ue_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
194 195
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_PUCCH_1AB_IQ", "rnti")),
Cedric Roux's avatar
Cedric Roux committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
        filter_int(ue)));
  for (i = 0; i < 8; i++) {
    logger_set_filter(e->e->dl_dci_logger[i],
        ticktime_filter(e->database, "ENB_PHY_DLSCH_UE_DCI", i, ue));
    logger_set_filter(e->e->dl_ack_logger[i],
        ticktime_filter(e->database, "ENB_PHY_DLSCH_UE_ACK", i, ue));
    logger_set_filter(e->e->dl_nack_logger[i],
        ticktime_filter(e->database, "ENB_PHY_DLSCH_UE_NACK", i, ue));
    logger_set_filter(e->e->ul_dci_logger[i],
        ticktime_filter(e->database, "ENB_PHY_ULSCH_UE_DCI", i, ue));
    logger_set_filter(e->e->ul_dci_retransmission_logger[i],
        ticktime_filter(e->database,
            "ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION", i, ue));
    logger_set_filter(e->e->ul_ack_logger[i],
        ticktime_filter(e->database, "ENB_PHY_ULSCH_UE_ACK", i, ue));
    logger_set_filter(e->e->ul_nack_logger[i],
        ticktime_filter(e->database, "ENB_PHY_ULSCH_UE_NACK", i, ue));
  }
214 215
  logger_set_filter(e->e->dl_mcs_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
216 217
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_DLSCH_UE_DCI", "rnti")),
218 219 220
        filter_int(ue)));
  logger_set_filter(e->e->ul_mcs_logger,
      filter_eq(
Cedric Roux's avatar
Cedric Roux committed
221 222
        filter_evfun(e->database, ue_id_from_rnti, NULL,
          filter_evarg(e->database, "ENB_PHY_ULSCH_UE_DCI", "rnti")),
223
        filter_int(ue)));
Cedric Roux's avatar
Cedric Roux committed
224 225 226 227 228 229 230 231 232 233
}

static void click(void *private, gui *g,
    char *notification, widget *w, void *notification_data)
{
  int *d = notification_data;
  int button = d[0];
  enb_data *ed = private;
  enb_gui *e = ed->e;
  int ue = ed->ue;
234
  int do_reset = 0;
Cedric Roux's avatar
Cedric Roux committed
235 236 237 238

  if (button != 1) return;
  if (w == e->prev_ue_button) { ue--; if (ue < 0) ue = 0; }
  if (w == e->next_ue_button) ue++;
239
  if (w == e->current_ue_button) do_reset = 1;
Cedric Roux's avatar
Cedric Roux committed
240

Cedric Roux's avatar
Cedric Roux committed
241
  if (pthread_mutex_lock(&ed->lock)) abort();
242
  if (do_reset) reset_ue_ids();
Cedric Roux's avatar
Cedric Roux committed
243 244 245 246 247
  if (ue != ed->ue) {
    set_current_ue(g, ed, ue);
    ed->ue = ue;
  }
  if (pthread_mutex_unlock(&ed->lock)) abort();
Cedric Roux's avatar
Cedric Roux committed
248 249 250 251
}

static void enb_main_gui(enb_gui *e, gui *g, event_handler *h, void *database,
    enb_data *ed)
252 253 254
{
  widget *main_window;
  widget *top_container;
Cedric Roux's avatar
Cedric Roux committed
255
  widget *line, *col;
Cedric Roux's avatar
Cedric Roux committed
256
  widget *logo;
257 258 259
  widget *input_signal_plot;
  logger *input_signal_log;
  view *input_signal_view;
Cedric Roux's avatar
Cedric Roux committed
260
  widget *timeline_plot;
261 262 263
  logger *timelog;
  view *timeview;
  view *subview;
Cedric Roux's avatar
Cedric Roux committed
264 265
  widget *text;
  view *textview;
Cedric Roux's avatar
Cedric Roux committed
266
  int i;
Cedric Roux's avatar
Cedric Roux committed
267
  widget *w, *w2;
268 269
  view *v;
  logger *l;
270

271
  main_window = new_toplevel_window(g, 1200, 900, "eNB tracer");
272 273 274 275 276
  top_container = new_container(g, VERTICAL);
  widget_add_child(g, main_window, top_container, -1);

  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
Cedric Roux's avatar
Cedric Roux committed
277
  logo = new_image(g, openair_logo_png, openair_logo_png_len);
Cedric Roux's avatar
Cedric Roux committed
278 279 280 281 282 283

  /* logo + prev/next UE buttons */
  col = new_container(g, VERTICAL);
  widget_add_child(g, col, logo, -1);
  w = new_container(g, HORIZONTAL);
  widget_add_child(g, col, w, -1);
Cedric Roux's avatar
Cedric Roux committed
284
  /* TODO: use button widget, not label widget */
Cedric Roux's avatar
Cedric Roux committed
285 286
  w2 = new_label(g, "");
  widget_add_child(g, w, w2, -1);
Cedric Roux's avatar
Cedric Roux committed
287 288
  label_set_clickable(g, w2, 1);
  e->current_ue_button = w2;
Cedric Roux's avatar
Cedric Roux committed
289 290 291 292 293 294 295 296 297 298 299
  e->current_ue_label = w2;
  w2 = new_label(g, "  [prev UE]  ");
  widget_add_child(g, w, w2, -1);
  label_set_clickable(g, w2, 1);
  e->prev_ue_button = w2;
  w2 = new_label(g, "  [next UE]  ");
  widget_add_child(g, w, w2, -1);
  label_set_clickable(g, w2, 1);
  e->next_ue_button = w2;
  widget_add_child(g, line, col, -1);

300 301
  input_signal_plot = new_xy_plot(g, 256, 55, "input signal", 20);
  widget_add_child(g, line, input_signal_plot, -1);
302
  xy_plot_set_range(g, input_signal_plot, 0, 7680*10 * ed->nb_rb/25, 20, 70);
303
  input_signal_log = new_framelog(h, database,
304
      "ENB_PHY_INPUT_SIGNAL", "subframe", "rxdata");
305 306 307 308
  /* a skip value of 10 means to process 1 frame over 10, that is
   * more or less 10 frames per second
   */
  framelog_set_skip(input_signal_log, 10);
309
  input_signal_view = new_view_xy(7680*10 * ed->nb_rb/25, 10,
310
      g, input_signal_plot, new_color(g, "#0c0c72"), XY_LOOP_MODE);
311
  logger_add_view(input_signal_log, input_signal_view);
Cedric Roux's avatar
Cedric Roux committed
312

Cedric Roux's avatar
Cedric Roux committed
313 314 315
  /* UE x PUSCH IQ data */
  w = new_xy_plot(g, 55, 55, "", 50);
  e->pusch_iq_ue_xy_plot = w;
316 317 318 319 320 321
  widget_add_child(g, line, w, -1);
  xy_plot_set_range(g, w, -1000, 1000, -1000, 1000);
  l = new_iqlog(h, database, "ENB_PHY_PUSCH_IQ", "nb_rb",
      "N_RB_UL", "symbols_per_tti", "pusch_comp");
  v = new_view_xy(100*12*14,10,g,w,new_color(g,"#000"),XY_FORCED_MODE);
  logger_add_view(l, v);
Cedric Roux's avatar
Cedric Roux committed
322
  e->pusch_iq_ue_logger = l;
323

Cedric Roux's avatar
Cedric Roux committed
324 325 326
  /* UE x estimated UL channel */
  w = new_xy_plot(g, 280, 55, "", 50);
  e->ul_estimate_ue_xy_plot = w;
327 328 329 330 331 332 333 334
  widget_add_child(g, line, w, -1);
  xy_plot_set_range(g, w, 0, 512*10, -10, 80);
  l = new_framelog(h, database,
      "ENB_PHY_UL_CHANNEL_ESTIMATE", "subframe", "chest_t");
  //framelog_set_skip(input_signal_log, 10);
  framelog_set_update_only_at_sf9(l, 0);
  v = new_view_xy(512*10, 10, g, w, new_color(g, "#0c0c72"), XY_LOOP_MODE);
  logger_add_view(l, v);
Cedric Roux's avatar
Cedric Roux committed
335
  e->ul_estimate_ue_logger = l;
336

Cedric Roux's avatar
Cedric Roux committed
337 338 339
  /* UE x PUCCH energy */
  w = new_xy_plot(g, 128, 55, "", 50);
  e->pucch1_energy_ue_xy_plot = w;
Cedric Roux's avatar
Cedric Roux committed
340 341 342 343 344 345
  widget_add_child(g, line, w, -1);
  xy_plot_set_range(g, w, 0, 1024*10, -10, 80);
  l = new_ttilog(h, database,
      "ENB_PHY_PUCCH_1_ENERGY", "frame", "subframe", "threshold", 0);
  v = new_view_tti(10, g, w, new_color(g, "#ff0000"));
  logger_add_view(l, v);
Cedric Roux's avatar
Cedric Roux committed
346
  e->pucch1_energy_ue_threshold_logger = l;
Cedric Roux's avatar
Cedric Roux committed
347 348 349 350
  l = new_ttilog(h, database,
      "ENB_PHY_PUCCH_1_ENERGY", "frame", "subframe", "energy", 1);
  v = new_view_tti(10, g, w, new_color(g, "#0c0c72"));
  logger_add_view(l, v);
Cedric Roux's avatar
Cedric Roux committed
351
  e->pucch1_energy_ue_energy_logger = l;
Cedric Roux's avatar
Cedric Roux committed
352

Cedric Roux's avatar
Cedric Roux committed
353 354 355
  /* UE x PUCCH IQ data */
  w = new_xy_plot(g, 55, 55, "", 50);
  e->pucch_iq_ue_xy_plot = w;
Cedric Roux's avatar
Cedric Roux committed
356
  widget_add_child(g, line, w, -1);
Cedric Roux's avatar
Cedric Roux committed
357
  xy_plot_set_range(g, w, -2000, 2000, -2000, 2000);
Cedric Roux's avatar
Cedric Roux committed
358 359 360
  l = new_iqdotlog(h, database, "ENB_PHY_PUCCH_1AB_IQ", "I", "Q");
  v = new_view_xy(500, 10, g, w, new_color(g,"#000"), XY_LOOP_MODE);
  logger_add_view(l, v);
Cedric Roux's avatar
Cedric Roux committed
361
  e->pucch_iq_ue_logger = l;
Cedric Roux's avatar
Cedric Roux committed
362

363 364 365 366
  /* UE x DL mcs */
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
  w = new_xy_plot(g, 128, 55, "", 20);
367
  xy_plot_set_range(g, w, 0, 1024*10, -2, 30);
368 369 370 371 372 373 374 375 376 377
  e->dl_mcs_xy_plot = w;
  widget_add_child(g, line, w, -1);
  l = new_ticked_ttilog(h, database, "ENB_PHY_DL_TICK", "frame", "subframe",
      "ENB_PHY_DLSCH_UE_DCI", "mcs", 0, -1);
  v = new_view_tti(10, g, w, new_color(g, "#0c0c72"));
  logger_add_view(l, v);
  e->dl_mcs_logger = l;

  /* UE x UL mcs */
  w = new_xy_plot(g, 128, 55, "", 20);
378
  xy_plot_set_range(g, w, 0, 1024*10, -2, 30);
379 380 381 382 383 384 385 386
  e->ul_mcs_xy_plot = w;
  widget_add_child(g, line, w, -1);
  l = new_ticked_ttilog(h, database, "ENB_PHY_DL_TICK", "frame", "subframe",
      "ENB_PHY_ULSCH_UE_DCI", "mcs", 0, -1);
  v = new_view_tti(10, g, w, new_color(g, "#0c0c72"));
  logger_add_view(l, v);
  e->ul_mcs_logger = l;

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
  /* UE x DL PHY (truly: DCI) throughput */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  w = new_xy_plot(g, 70, 10, "DL PHY [0]", 35);
  w2 = new_textarea(g, 70, 11, 64);
  xy_plot_set_range(g, w, 0, 1000, 0, 100000);
  xy_plot_set_tick_type(g, w, XY_PLOT_SCROLL_TICK);
  widget_add_child(g, col, w2, -1);
  widget_add_child(g, col, w, -1);
  container_set_child_growable(g, col, w, 1);
  l = new_throughputlog(h, database, "ENB_PHY_DL_TICK", "frame", "subframe",
      "ENB_PHY_DLSCH_UE_DCI", "TBS");
  v = new_view_scrolltti(10, g, w, new_color(g, "#0c0c72"), w2);
  logger_add_view(l, v);

  /* UE x UL PHY (truly: DCI) throughput */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  w = new_xy_plot(g, 70, 10, "UL PHY [0]", 35);
  w2 = new_textarea(g, 70, 11, 64);
  xy_plot_set_range(g, w, 0, 1000, 0, 100000);
  xy_plot_set_tick_type(g, w, XY_PLOT_SCROLL_TICK);
  widget_add_child(g, col, w2, -1);
  widget_add_child(g, col, w, -1);
  container_set_child_growable(g, col, w, 1);
  l = new_throughputlog(h, database, "ENB_PHY_DL_TICK", "frame", "subframe",
      "ENB_PHY_ULSCH_UE_DCI", "TBS");
  v = new_view_scrolltti(10, g, w, new_color(g, "#0c0c72"), w2);
  logger_add_view(l, v);

417
  /* downlink/uplink UE DCIs */
Cedric Roux's avatar
Cedric Roux committed
418
  widget_add_child(g, top_container,
Cedric Roux's avatar
Cedric Roux committed
419
      new_label(g,"DL/UL TICK/DCI/ACK/NACK [all UEs]"), -1);
Cedric Roux's avatar
Cedric Roux committed
420 421
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
Cedric Roux's avatar
Cedric Roux committed
422
  timeline_plot = new_timeline(g, 512, 8, 5);
Cedric Roux's avatar
Cedric Roux committed
423 424
  widget_add_child(g, line, timeline_plot, -1);
  container_set_child_growable(g, line, timeline_plot, 1);
Cedric Roux's avatar
Cedric Roux committed
425
  for (i = 0; i < 8; i++)
Cedric Roux's avatar
Cedric Roux committed
426
    timeline_set_subline_background_color(g, timeline_plot, i,
Cedric Roux's avatar
Cedric Roux committed
427
        new_color(g, i==0 || i==4 ? "#aaf" : "#eee"));
428
  timeview = new_view_time(3600, 10, g, timeline_plot);
429
  /* DL tick logging */
430
  timelog = new_timelog(h, database, "ENB_PHY_DL_TICK");
Cedric Roux's avatar
Cedric Roux committed
431
  subview = new_subview_time(timeview, 0, new_color(g, "#77c"), 3600*1000);
432
  logger_add_view(timelog, subview);
433
  /* DL DCI logging */
434
  timelog = new_timelog(h, database, "ENB_PHY_DLSCH_UE_DCI");
435
  subview = new_subview_time(timeview, 1, new_color(g, "#228"), 3600*1000);
Cedric Roux's avatar
Cedric Roux committed
436
  logger_add_view(timelog, subview);
437
  /* DL ACK */
438
  timelog = new_timelog(h, database, "ENB_PHY_DLSCH_UE_ACK");
439
  subview = new_subview_time(timeview, 2, new_color(g, "#282"), 3600*1000);
440
  logger_add_view(timelog, subview);
441
  /* DL NACK */
442
  timelog = new_timelog(h, database, "ENB_PHY_DLSCH_UE_NACK");
443
  subview = new_subview_time(timeview, 3, new_color(g, "#f22"), 3600*1000);
444
  logger_add_view(timelog, subview);
445

446
  /* UL tick logging */
447
  timelog = new_timelog(h, database, "ENB_PHY_UL_TICK");
Cedric Roux's avatar
Cedric Roux committed
448
  subview = new_subview_time(timeview, 4, new_color(g, "#77c"), 3600*1000);
449
  logger_add_view(timelog, subview);
450
  /* UL DCI logging */
451
  timelog = new_timelog(h, database, "ENB_PHY_ULSCH_UE_DCI");
452 453 454
  subview = new_subview_time(timeview, 5, new_color(g, "#228"), 3600*1000);
  logger_add_view(timelog, subview);
  /* UL retransmission without DCI logging */
455
  timelog = new_timelog(h,database,"ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION");
456 457 458
  subview = new_subview_time(timeview, 5, new_color(g, "#f22"), 3600*1000);
  logger_add_view(timelog, subview);
  /* UL ACK */
459
  timelog = new_timelog(h, database, "ENB_PHY_ULSCH_UE_ACK");
460 461 462
  subview = new_subview_time(timeview, 6, new_color(g, "#282"), 3600*1000);
  logger_add_view(timelog, subview);
  /* UL NACK */
463
  timelog = new_timelog(h, database, "ENB_PHY_ULSCH_UE_NACK");
464 465
  subview = new_subview_time(timeview, 7, new_color(g, "#f22"), 3600*1000);
  logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
466

467
  /* harq processes' ticktime view */
Cedric Roux's avatar
Cedric Roux committed
468 469
  e->dl_ul_harq_ue_label = new_label(g, "");
  widget_add_child(g, top_container, e->dl_ul_harq_ue_label, -1);
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
  timeline_plot = new_timeline(g, 512, 2*8+2, 3);
  widget_add_child(g, line, timeline_plot, -1);
  container_set_child_growable(g, line, timeline_plot, 1);
  for (i = 0; i < 2*8+2; i++)
    timeline_set_subline_background_color(g, timeline_plot, i,
        new_color(g, i==0 || i==9 ? "#ddd" : (i%9)&1 ? "#e6e6e6" : "#eee"));
  timeview = new_view_ticktime(10, g, timeline_plot);
  ticktime_set_tick(timeview,
      new_ticklog(h, database, "ENB_MASTER_TICK", "frame", "subframe"));
  /* tick */
  timelog = new_ticklog(h, database, "ENB_MASTER_TICK", "frame", "subframe");
  /* tick on DL view */
  subview = new_subview_ticktime(timeview, 0, new_color(g,"#bbb"), 3600*1000);
  logger_add_view(timelog, subview);
  /* tick on UL view */
  subview = new_subview_ticktime(timeview, 9, new_color(g,"#bbb"), 3600*1000);
  logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
489
  /* DL DCI */
490
  for (i = 0; i < 8; i++) {
491
    timelog = new_ticklog(h, database, "ENB_PHY_DLSCH_UE_DCI",
492 493 494 495
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+1,
        new_color(g,"#55f"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
496
    e->dl_dci_logger[i] = timelog;
497 498 499
  }
  /* DL ACK */
  for (i = 0; i < 8; i++) {
500
    timelog = new_ticklog(h, database, "ENB_PHY_DLSCH_UE_ACK",
501 502 503 504
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+1,
        new_color(g,"#282"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
505
    e->dl_ack_logger[i] = timelog;
506 507 508
  }
  /* DL NACK */
  for (i = 0; i < 8; i++) {
509
    timelog = new_ticklog(h, database, "ENB_PHY_DLSCH_UE_NACK",
510 511 512 513
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+1,
        new_color(g,"#f22"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
514
    e->dl_nack_logger[i] = timelog;
515
  }
Cedric Roux's avatar
Cedric Roux committed
516
  /* UL DCI/retransmission without DCI */
517 518
  for (i = 0; i < 8; i++) {
    /* first transmission */
519
    timelog = new_ticklog(h, database, "ENB_PHY_ULSCH_UE_DCI",
520 521 522 523
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+9+1,
        new_color(g,"#55f"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
524
    e->ul_dci_logger[i] = timelog;
525
    /* retransmission */
526 527
    timelog = new_ticklog(h, database,
        "ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION", "frame", "subframe");
528 529 530
    subview = new_subview_ticktime(timeview, i+9+1,
        new_color(g,"#99f"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
531
    e->ul_dci_retransmission_logger[i] = timelog;
532 533 534
  }
  /* UL ACK */
  for (i = 0; i < 8; i++) {
535
    timelog = new_ticklog(h, database, "ENB_PHY_ULSCH_UE_ACK",
536 537 538 539
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+9+1,
        new_color(g,"#282"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
540
    e->ul_ack_logger[i] = timelog;
541 542 543
  }
  /* UL NACK */
  for (i = 0; i < 8; i++) {
544
    timelog = new_ticklog(h, database, "ENB_PHY_ULSCH_UE_NACK",
545 546 547 548
        "frame", "subframe");
    subview = new_subview_ticktime(timeview, i+9+1,
        new_color(g,"#f22"), 3600*1000);
    logger_add_view(timelog, subview);
Cedric Roux's avatar
Cedric Roux committed
549
    e->ul_nack_logger[i] = timelog;
550 551
  }

Cedric Roux's avatar
Cedric Roux committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565
  /* phy/mac/rlc/pdcp/rrc textlog */
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
  container_set_child_growable(g, top_container, line, 1);

  /* phy */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  container_set_child_growable(g, line, col, 1);
  widget_add_child(g, col, new_label(g, "PHY"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#afa"));
  widget_add_child(g, col, text, -1);
  container_set_child_growable(g, col, text, 1);
  textview = new_view_textlist(10000, 10, g, text);
566
  e->phyview = textview;
Cedric Roux's avatar
Cedric Roux committed
567 568 569 570 571 572 573 574 575 576

  /* mac */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  container_set_child_growable(g, line, col, 1);
  widget_add_child(g, col, new_label(g, "MAC"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#adf"));
  widget_add_child(g, col, text, -1);
  container_set_child_growable(g, col, text, 1);
  textview = new_view_textlist(10000, 10, g, text);
Cedric Roux's avatar
Cedric Roux committed
577
  e->macview = textview;
Cedric Roux's avatar
Cedric Roux committed
578

579 580 581 582
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
  container_set_child_growable(g, top_container, line, 1);

Cedric Roux's avatar
Cedric Roux committed
583 584 585 586 587 588 589 590 591
  /* rlc */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  container_set_child_growable(g, line, col, 1);
  widget_add_child(g, col, new_label(g, "RLC"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#aff"));
  widget_add_child(g, col, text, -1);
  container_set_child_growable(g, col, text, 1);
  textview = new_view_textlist(10000, 10, g, text);
Cedric Roux's avatar
Cedric Roux committed
592
  e->rlcview = textview;
Cedric Roux's avatar
Cedric Roux committed
593 594 595 596 597 598 599 600 601 602

  /* pdcp */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  container_set_child_growable(g, line, col, 1);
  widget_add_child(g, col, new_label(g, "PDCP"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#ed9"));
  widget_add_child(g, col, text, -1);
  container_set_child_growable(g, col, text, 1);
  textview = new_view_textlist(10000, 10, g, text);
Cedric Roux's avatar
Cedric Roux committed
603
  e->pdcpview = textview;
Cedric Roux's avatar
Cedric Roux committed
604

605 606 607 608
  line = new_container(g, HORIZONTAL);
  widget_add_child(g, top_container, line, -1);
  container_set_child_growable(g, top_container, line, 1);

Cedric Roux's avatar
Cedric Roux committed
609 610 611 612 613 614 615 616 617 618
  /* rrc */
  col = new_container(g, VERTICAL);
  widget_add_child(g, line, col, -1);
  container_set_child_growable(g, line, col, 1);
  widget_add_child(g, col, new_label(g, "RRC"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#fdb"));
  widget_add_child(g, col, text, -1);
  container_set_child_growable(g, col, text, 1);
  textview = new_view_textlist(10000, 10, g, text);
  e->rrcview = textview;
Cedric Roux's avatar
Cedric Roux committed
619 620 621 622 623 624 625

  /* legacy logs (LOG_I, LOG_D, ...) */
  widget_add_child(g, top_container, new_label(g, "LEGACY"), -1);
  text = new_textlist(g, 100, 10, new_color(g, "#eeb"));
  widget_add_child(g, top_container, text, -1);
  container_set_child_growable(g, top_container, text, 1);
  e->legacy = new_view_textlist(10000, 10, g, text);
Cedric Roux's avatar
Cedric Roux committed
626

627
  set_current_ue(g, ed, ed->ue);
Cedric Roux's avatar
Cedric Roux committed
628
  register_notifier(g, "click", e->current_ue_button, click, ed);
Cedric Roux's avatar
Cedric Roux committed
629 630
  register_notifier(g, "click", e->prev_ue_button, click, ed);
  register_notifier(g, "click", e->next_ue_button, click, ed);
Cedric Roux's avatar
Cedric Roux committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
}

void view_add_log(view *v, char *log, event_handler *h, void *database,
    int *is_on)
{
  logger *textlog;
  char *name, *desc;

  database_get_generic_description(database,
      event_id_from_name(database, log), &name, &desc);
  textlog = new_textlog(h, database, name, desc);
  logger_add_view(textlog, v);
  free(name);
  free(desc);

  on_off(database, log, is_on, 1);
647 648
}

649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
void usage(void)
{
  printf(
"options:\n"
"    -d   <database file>      this option is mandatory\n"
"    -rb  <RBs>                setup for this number of RBs (default 25)\n"
"    -on  <GROUP or ID>        turn log ON for given GROUP or ID\n"
"    -off <GROUP or ID>        turn log OFF for given GROUP or ID\n"
"    -ON                       turn all logs ON\n"
"    -OFF                      turn all logs OFF\n"
"                              note: you may pass several -on/-off/-ON/-OFF,\n"
"                                    they will be processed in order\n"
"                                    by default, all is off\n"
"    -ip <host>                connect to given IP address (default %s)\n"
"    -p  <port>                connect to given port (default %d)\n"
"    -debug-gui                activate GUI debug logs\n",
  DEFAULT_REMOTE_IP,
  DEFAULT_REMOTE_PORT
  );
  exit(1);
}

671 672 673 674 675
int main(int n, char **v)
{
  extern int volatile gui_logd;
  char *database_filename = NULL;
  void *database;
676
  char *ip = DEFAULT_REMOTE_IP;
677 678 679 680 681 682 683 684 685
  int port = DEFAULT_REMOTE_PORT;
  char **on_off_name;
  int *on_off_action;
  int on_off_n = 0;
  int *is_on;
  int number_of_events;
  int i;
  event_handler *h;
  gui *g;
Cedric Roux's avatar
Cedric Roux committed
686
  enb_gui eg;
687
  enb_data enb_data;
688

Cedric Roux's avatar
Cedric Roux committed
689 690
  reset_ue_ids();

691 692
  enb_data.nb_rb = 25;

693 694 695
  /* write on a socket fails if the other end is closed and we get SIGPIPE */
  if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort();

696 697 698 699 700 701 702
  on_off_name = malloc(n * sizeof(char *)); if (on_off_name == NULL) abort();
  on_off_action = malloc(n * sizeof(int)); if (on_off_action == NULL) abort();

  for (i = 1; i < n; i++) {
    if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
    if (!strcmp(v[i], "-d"))
      { if (i > n-2) usage(); database_filename = v[++i]; continue; }
703 704
    if (!strcmp(v[i], "-rb"))
      { if (i > n-2) usage(); enb_data.nb_rb = atoi(v[++i]); continue; }
705
    if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
706 707 708 709 710 711 712 713 714 715 716 717 718 719
    if (!strcmp(v[i], "-p"))
      { if (i > n-2) usage(); port = atoi(v[++i]); continue; }
    if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
      on_off_name[on_off_n]=v[++i]; on_off_action[on_off_n++]=1; continue; }
    if (!strcmp(v[i], "-off")) { if (i > n-2) usage();
      on_off_name[on_off_n]=v[++i]; on_off_action[on_off_n++]=0; continue; }
    if (!strcmp(v[i], "-ON"))
      { on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=1; continue; }
    if (!strcmp(v[i], "-OFF"))
      { on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=0; continue; }
    if (!strcmp(v[i], "-debug-gui")) { gui_logd = 1; continue; }
    usage();
  }

720 721 722 723 724
  switch (enb_data.nb_rb) {
  case 25: case 50: case 100: break;
  default: printf("ERROR, bad value for -rb (%d)\n", enb_data.nb_rb); exit(1);
  }

725 726 727 728 729 730 731
  if (database_filename == NULL) {
    printf("ERROR: provide a database file (-d)\n");
    exit(1);
  }

  database = parse_database(database_filename);

732
  load_config_file(database_filename);
733

734 735 736 737 738 739 740 741 742
  number_of_events = number_of_ids(database);
  is_on = calloc(number_of_events, sizeof(int));
  if (is_on == NULL) abort();

  h = new_handler(database);

  g = gui_init();
  new_thread(gui_thread, g);

743
  enb_data.ue = 3;
Cedric Roux's avatar
Cedric Roux committed
744 745 746 747
  enb_data.e = &eg;
  enb_data.database = database;

  enb_main_gui(&eg, g, h, database, &enb_data);
748

Cedric Roux's avatar
Cedric Roux committed
749 750 751 752
  for (i = 0; i < number_of_events; i++) {
    logger *textlog;
    char *name, *desc;
    database_get_generic_description(database, i, &name, &desc);
Cedric Roux's avatar
Cedric Roux committed
753 754 755 756
    if (!strncmp(name, "LEGACY_", 7)) {
      textlog = new_textlog(h, database, name, desc);
      logger_add_view(textlog, eg.legacy);
    }
Cedric Roux's avatar
Cedric Roux committed
757 758 759 760
    free(name);
    free(desc);
  }

761
  on_off(database, "ENB_PHY_INPUT_SIGNAL", is_on, 1);
762
  on_off(database, "ENB_PHY_UL_CHANNEL_ESTIMATE", is_on, 1);
763 764 765 766 767 768 769 770 771
  on_off(database, "ENB_PHY_DL_TICK", is_on, 1);
  on_off(database, "ENB_PHY_DLSCH_UE_DCI", is_on, 1);
  on_off(database, "ENB_PHY_DLSCH_UE_ACK", is_on, 1);
  on_off(database, "ENB_PHY_DLSCH_UE_NACK", is_on, 1);
  on_off(database, "ENB_PHY_UL_TICK", is_on, 1);
  on_off(database, "ENB_PHY_ULSCH_UE_DCI", is_on, 1);
  on_off(database, "ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION", is_on, 1);
  on_off(database, "ENB_PHY_ULSCH_UE_ACK", is_on, 1);
  on_off(database, "ENB_PHY_ULSCH_UE_NACK", is_on, 1);
772
  on_off(database, "ENB_MASTER_TICK", is_on, 1);
773
  on_off(database, "ENB_PHY_PUSCH_IQ", is_on, 1);
Cedric Roux's avatar
Cedric Roux committed
774 775
  on_off(database, "ENB_PHY_PUCCH_1_ENERGY", is_on, 1);
  on_off(database, "ENB_PHY_PUCCH_1AB_IQ", is_on, 1);
776

777 778 779
  on_off(database, "LEGACY_GROUP_INFO", is_on, 1);
  on_off(database, "LEGACY_GROUP_ERROR", is_on, 1);
  on_off(database, "LEGACY_GROUP_WARNING", is_on, 1);
780

781 782 783 784 785
  view_add_log(eg.phyview, "ENB_PHY_DLSCH_UE_DCI", h, database, is_on);
  view_add_log(eg.phyview, "ENB_PHY_DLSCH_UE_ACK", h, database, is_on);
  view_add_log(eg.phyview, "ENB_PHY_DLSCH_UE_NACK", h, database, is_on);
  view_add_log(eg.phyview, "ENB_PHY_ULSCH_UE_DCI", h, database, is_on);
  view_add_log(eg.phyview, "ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION",
786
      h, database, is_on);
787 788
  view_add_log(eg.phyview, "ENB_PHY_ULSCH_UE_ACK", h, database, is_on);
  view_add_log(eg.phyview, "ENB_PHY_ULSCH_UE_NACK", h, database, is_on);
789

Cedric Roux's avatar
Cedric Roux committed
790 791 792 793 794
  view_add_log(eg.macview, "ENB_MAC_UE_DL_SDU", h, database, is_on);
  view_add_log(eg.macview, "ENB_MAC_UE_UL_SCHEDULE", h, database, is_on);
  view_add_log(eg.macview, "ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION",
      h, database, is_on);
  view_add_log(eg.macview, "ENB_MAC_UE_UL_PDU", h, database, is_on);
795
  view_add_log(eg.macview, "ENB_MAC_UE_UL_PDU_WITH_DATA", h, database, is_on);
Cedric Roux's avatar
Cedric Roux committed
796
  view_add_log(eg.macview, "ENB_MAC_UE_UL_SDU", h, database, is_on);
797
  view_add_log(eg.macview, "ENB_MAC_UE_UL_SDU_WITH_DATA", h, database, is_on);
Cedric Roux's avatar
Cedric Roux committed
798 799 800 801 802 803 804 805 806 807
  view_add_log(eg.macview, "ENB_MAC_UE_UL_CE", h, database, is_on);

  view_add_log(eg.rlcview, "ENB_RLC_DL", h, database, is_on);
  view_add_log(eg.rlcview, "ENB_RLC_UL", h, database, is_on);
  view_add_log(eg.rlcview, "ENB_RLC_MAC_DL", h, database, is_on);
  view_add_log(eg.rlcview, "ENB_RLC_MAC_UL", h, database, is_on);

  view_add_log(eg.pdcpview, "ENB_PDCP_UL", h, database, is_on);
  view_add_log(eg.pdcpview, "ENB_PDCP_DL", h, database, is_on);

Cedric Roux's avatar
Cedric Roux committed
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_SETUP_COMPLETE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_SECURITY_MODE_COMMAND",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UE_CAPABILITY_ENQUIRY",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_REJECT",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_REESTABLISHMENT_REJECT",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_RELEASE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_RECONFIGURATION",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_MEASUREMENT_REPORT",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_HANDOVER_PREPARATION_INFORMATION",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_SETUP",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UL_CCCH_DATA_IN",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UL_DCCH_DATA_IN",
      h, database, is_on);
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
  view_add_log(eg.rrcview, "ENB_RRC_SECURITY_MODE_COMPLETE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_SECURITY_MODE_FAILURE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UE_CAPABILITY_INFORMATION",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_REQUEST",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UL_HANDOVER_PREPARATION_TRANSFER",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UL_INFORMATION_TRANSFER",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_COUNTER_CHECK_RESPONSE",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UE_INFORMATION_RESPONSE_R9",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_PROXIMITY_INDICATION_R9",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_RECONFIGURATION_COMPLETE_R10",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_MBMS_COUNTING_RESPONSE_R10",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_INTER_FREQ_RSTD_MEASUREMENT_INDICATION",
      h, database, is_on);
  view_add_log(eg.rrcview, "ENB_RRC_UNKNOW_MESSAGE",
      h, database, is_on);
Cedric Roux's avatar
Cedric Roux committed
864

865 866 867 868
  /* deactivate those two by default, they are a bit heavy */
  on_off(database, "ENB_MAC_UE_UL_SDU_WITH_DATA", is_on, 0);
  on_off(database, "ENB_MAC_UE_UL_PDU_WITH_DATA", is_on, 0);

869 870 871
  for (i = 0; i < on_off_n; i++)
    on_off(database, on_off_name[i], is_on, on_off_action[i]);

872 873 874 875 876
  enb_data.socket = -1;
  enb_data.is_on = is_on;
  enb_data.nevents = number_of_events;
  if (pthread_mutex_init(&enb_data.lock, NULL)) abort();
  setup_event_selector(g, database, is_on, is_on_changed, &enb_data);
877

878 879
restart:
  clear_remote_config();
880
  enb_data.socket = connect_to(ip, port);
881

882 883
  /* send the first message - activate selected traces */
  is_on_changed(&enb_data);
884 885 886 887 888

  /* read messages */
  while (1) {
    char v[T_BUFFER_MAX];
    event e;
889
    e = get_event(enb_data.socket, v, database);
890
    if (e.type == -1) goto restart;
Cedric Roux's avatar
Cedric Roux committed
891
    if (pthread_mutex_lock(&enb_data.lock)) abort();
892
    handle_event(h, e);
Cedric Roux's avatar
Cedric Roux committed
893
    if (pthread_mutex_unlock(&enb_data.lock)) abort();
894 895 896 897
  }

  return 0;
}