otg.c 4.52 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


nikaeinn's avatar
nikaeinn committed
11 12 13 14
    OpenAirInterface is distributed in the hope that 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.
15

nikaeinn's avatar
nikaeinn committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
nikaeinn's avatar
nikaeinn committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27 28 29 30

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

/*! \file otg.c
31
* \brief common function for otc tx and rx
32 33 34 35
* \author N. Nikaein and A. Hafsaoui
* \date 2011
* \version 0.1
* \company Eurecom
nikaeinn's avatar
nikaeinn committed
36
* \email: navid.nikaein@eurecom.fr
37 38 39 40 41 42 43 44 45 46
* \note
* \warning
*/



#include "otg.h"
#include "otg_vars.h"


47 48 49 50
// Defining initial and default values of OTG structures

void init_all_otg(int max_nb_frames)
{
51 52 53

  //set otg params to 0
  g_otg = calloc(1, sizeof(otg_t));
54

55 56 57
  if (g_otg == NULL)
    /* Memory could not be allocated */
    LOG_E(OTG,"Couldn't allocate memory for otg_t\n");
58 59 60

  memset(g_otg, 0, sizeof(otg_t));

61
  g_otg_multicast = calloc(1, sizeof(otg_multicast_t));
62

63 64 65
  if (g_otg_multicast == NULL)
    /* Memory could not be allocated */
    LOG_E(OTG,"Couldn't allocate memory for otg_multicast_t\n");
66

67
  memset(g_otg_multicast, 0, sizeof(otg_multicast_t));
68

69 70
  //set otg infos to 0
  otg_info = calloc(1, sizeof(otg_info_t));
71

72 73 74
  if (otg_info == NULL)
    /* Memory could not be allocated */
    LOG_E(OTG,"Couldn't allocate memory for otg_info_t\n");
75

76
  memset(otg_info, 0, sizeof(otg_info_t));
77

78 79
  //set otg multicast infos to 0
  otg_multicast_info = calloc(1, sizeof(otg_multicast_info_t));
80

81 82 83
  if (otg_multicast_info == NULL)
    /* Memory could not be allocated */
    LOG_E(OTG,"Couldn't allocate memory for otg_multicast_info_t\n");
84

85 86 87 88
  memset(otg_multicast_info, 0, sizeof(otg_multicast_info_t));

  //set otg forms infos to 0
  otg_forms_info=calloc(1, sizeof(otg_forms_info_t));
89

90 91 92
  if (otg_forms_info == NULL)
    /* Memory could not be allocated */
    LOG_E(OTG,"Couldn't allocate memory for otg_forms_info_t\n");
93

94
  memset(otg_forms_info, 0, sizeof(otg_forms_info_t));
95

96
  g_otg->max_nb_frames=max_nb_frames;
97

98
  LOG_I(OTG,"init done: init_all_otg\n");
99

100 101
}

102 103 104
char *str_sub (const char *s, unsigned int start, unsigned int end)
{

105 106
  char *new_s = NULL;
  int i;
107

108 109
  if (s != NULL && start < end)   {
    new_s = malloc (sizeof (*new_s) * (end - start + 2));
110

111 112
    if (new_s != NULL) {
      for (i = start; i <= end; i++) {
113
        new_s[i-start] = s[i];
114
      }
115

116
      new_s[i-start] = '\0';
117 118 119
    } else {
      LOG_E(OTG,"Insufficient memory \n");
      exit (-1);
120 121
    }
  }
122

123 124 125 126
  return new_s;
}

// set the simulation time
127 128
void set_ctime(int ctime)
{
129
  otg_info->ctime=ctime;
130 131
  //  otg_muticast_info->ctime=ctime;

132 133 134 135
}



136 137 138
// get the simulation time
int get_ctime(void)
{
139
  return otg_info->ctime;
140 141 142
}


143 144 145 146
void free_otg()
{
  int i,j,k;

147 148 149
  for (i=0; i<g_otg->num_nodes; i++)
    for (j=0; j<g_otg->num_nodes; j++)
      free( g_otg->dst_ip[i][j] );
150

151 152
  free( g_otg );
  g_otg = 0;
153 154

  LOG_D(OTG,"DEBUG TARMA: free_otg() called \n");
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

  for(i=0; i<NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) {
    for(j=0; j<NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; j++) {
      for(k=0; k<MAX_NUM_APPLICATION; k++) {
        if(otg_info->tarma_stream[i][j][k]) {
          free(otg_info->tarma_stream[i][j][k]);
          LOG_D(OTG,"DEBUG TARMA: freed tarma_stream[%d][%d][%d]\n",i,j,k);
        }

        if(otg_info->tarma_video[i][j][k]) {
          free(otg_info->tarma_video[i][j][k]);
          LOG_D(OTG,"DEBUG TARMA: freed tarma_video[%d][%d][%d]\n",i,j,k);
        }

        if(otg_info->background_stream[i][j][k]) {
          free(otg_info->background_stream[i][j][k]);
          LOG_D(OTG,"DEBUG TARMA: freed background_stream[%d][%d][%d]\n",i,j,k);
        }
      }
    }
175 176
  }

177
  free(otg_info);
178 179
}