s1ap_eNB_management_procedures.c 5.46 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
1
/*******************************************************************************
Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
Cedric Roux's avatar
 
Cedric Roux committed
4

Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier 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.
Cedric Roux's avatar
 
Cedric Roux committed
9 10


Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier 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.
Cedric Roux's avatar
 
Cedric Roux committed
15

Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier 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/>.
Cedric Roux's avatar
 
Cedric Roux committed
20 21

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

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.
Cedric Roux's avatar
 
Cedric Roux committed
27

Lionel Gauthier's avatar
GPLv3  
Lionel Gauthier committed
28
 *******************************************************************************/
Cedric Roux's avatar
 
Cedric Roux committed
29

30 31 32 33 34 35 36 37 38
/*! \file s1ap_eNB_management_procedures.c
 * \brief S1AP eNB task 
 * \author  S. Roux and Navid Nikaein 
 * \date 2010 - 2016
 * \email: navid.nikaein@eurecom.fr
 * \version 1.0
 * @ingroup _s1ap
 */

Cedric Roux's avatar
 
Cedric Roux committed
39 40 41 42
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

43 44 45
#include "intertask_interface.h"

#include "assertions.h"
Cedric Roux's avatar
Cedric Roux committed
46
#include "conversions.h"
Cedric Roux's avatar
 
Cedric Roux committed
47 48 49 50 51

#include "s1ap_common.h"
#include "s1ap_eNB_defs.h"
#include "s1ap_eNB.h"

Cedric Roux's avatar
Cedric Roux committed
52
s1ap_eNB_internal_data_t s1ap_eNB_internal_data;
Cedric Roux's avatar
 
Cedric Roux committed
53

Cedric Roux's avatar
Cedric Roux committed
54 55
RB_GENERATE(s1ap_mme_map, s1ap_eNB_mme_data_s, entry, s1ap_eNB_compare_assoc_id);

56
int s1ap_eNB_compare_assoc_id(
57
  struct s1ap_eNB_mme_data_s *p1, struct s1ap_eNB_mme_data_s *p2)
Cedric Roux's avatar
Cedric Roux committed
58
{
59 60 61
  if (p1->assoc_id == -1) {
    if (p1->cnx_id < p2->cnx_id) {
      return -1;
Cedric Roux's avatar
Cedric Roux committed
62 63
    }

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    if (p1->cnx_id > p2->cnx_id) {
      return 1;
    }
  } else {
    if (p1->assoc_id < p2->assoc_id) {
      return -1;
    }

    if (p1->assoc_id > p2->assoc_id) {
      return 1;
    }
  }

  /* Matching reference */
  return 0;
Cedric Roux's avatar
Cedric Roux committed
79 80 81 82
}

uint16_t s1ap_eNB_fetch_add_global_cnx_id(void)
{
83
  return ++s1ap_eNB_internal_data.global_cnx_id;
Cedric Roux's avatar
Cedric Roux committed
84 85 86 87
}

void s1ap_eNB_prepare_internal_data(void)
{
88 89
  memset(&s1ap_eNB_internal_data, 0, sizeof(s1ap_eNB_internal_data));
  STAILQ_INIT(&s1ap_eNB_internal_data.s1ap_eNB_instances_head);
Cedric Roux's avatar
Cedric Roux committed
90 91 92 93
}

void s1ap_eNB_insert_new_instance(s1ap_eNB_instance_t *new_instance_p)
{
94
  DevAssert(new_instance_p != NULL);
Cedric Roux's avatar
Cedric Roux committed
95

96 97
  STAILQ_INSERT_TAIL(&s1ap_eNB_internal_data.s1ap_eNB_instances_head,
                     new_instance_p, s1ap_eNB_entries);
Cedric Roux's avatar
Cedric Roux committed
98 99
}

100
struct s1ap_eNB_mme_data_s *s1ap_eNB_get_MME(
101 102
  s1ap_eNB_instance_t *instance_p,
  int32_t assoc_id, uint16_t cnx_id)
Cedric Roux's avatar
Cedric Roux committed
103
{
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  struct s1ap_eNB_mme_data_s  temp;
  struct s1ap_eNB_mme_data_s *found;

  memset(&temp, 0, sizeof(struct s1ap_eNB_mme_data_s));

  temp.assoc_id = assoc_id;
  temp.cnx_id   = cnx_id;

  if (instance_p == NULL) {
    STAILQ_FOREACH(instance_p, &s1ap_eNB_internal_data.s1ap_eNB_instances_head,
                   s1ap_eNB_entries) {
      found = RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);

      if (found != NULL) {
        return found;
      }
Cedric Roux's avatar
Cedric Roux committed
120
    }
121 122 123
  } else {
    return RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);
  }
Cedric Roux's avatar
Cedric Roux committed
124

125
  return NULL;
Cedric Roux's avatar
Cedric Roux committed
126 127
}

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
struct s1ap_eNB_mme_data_s *s1ap_eNB_get_MME_from_instance(
  s1ap_eNB_instance_t *instance_p)
{
 
  struct s1ap_eNB_mme_data_s *mme = NULL;
  struct s1ap_eNB_mme_data_s *mme_next = NULL;

  for (mme = RB_MIN(s1ap_mme_map, &instance_p->s1ap_mme_head); mme!=NULL ; mme = mme_next) {
    mme_next = RB_NEXT(s1ap_mme_map, &instance_p->s1ap_mme_head, mme);
    if (mme->s1ap_eNB_instance == instance_p) {
      return mme;
    }
  }

  return NULL;
}

145
s1ap_eNB_instance_t *s1ap_eNB_get_instance(instance_t instance)
Cedric Roux's avatar
Cedric Roux committed
146
{
147 148 149 150 151 152 153
  s1ap_eNB_instance_t *temp = NULL;

  STAILQ_FOREACH(temp, &s1ap_eNB_internal_data.s1ap_eNB_instances_head,
                 s1ap_eNB_entries) {
    if (temp->instance == instance) {
      /* Matching occurence */
      return temp;
Cedric Roux's avatar
Cedric Roux committed
154
    }
155
  }
Cedric Roux's avatar
Cedric Roux committed
156

157
  return NULL;
Cedric Roux's avatar
Cedric Roux committed
158
}
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

void s1ap_eNB_remove_mme_desc(s1ap_eNB_instance_t * instance) 
{

    struct s1ap_eNB_mme_data_s *mme = NULL;
    struct s1ap_eNB_mme_data_s *mmeNext = NULL;
    struct plmn_identity_s* plmnInfo;
    struct served_group_id_s* groupInfo;
    struct served_gummei_s* gummeiInfo;
    struct mme_code_s* mmeCode;

    for (mme = RB_MIN(s1ap_mme_map, &instance->s1ap_mme_head); mme; mme = mmeNext) {
      mmeNext = RB_NEXT(s1ap_mme_map, &instance->s1ap_mme_head, mme);
      RB_REMOVE(s1ap_mme_map, &instance->s1ap_mme_head, mme);
      while (!STAILQ_EMPTY(&mme->served_gummei)) {
        gummeiInfo = STAILQ_FIRST(&mme->served_gummei);
        STAILQ_REMOVE_HEAD(&mme->served_gummei, next);
	
        while (!STAILQ_EMPTY(&gummeiInfo->served_plmns)) {
	  plmnInfo = STAILQ_FIRST(&gummeiInfo->served_plmns);
	  STAILQ_REMOVE_HEAD(&gummeiInfo->served_plmns, next);
	  free(plmnInfo);
        }
        while (!STAILQ_EMPTY(&gummeiInfo->served_group_ids)) {
	  groupInfo = STAILQ_FIRST(&gummeiInfo->served_group_ids);
	  STAILQ_REMOVE_HEAD(&gummeiInfo->served_group_ids, next);
	  free(groupInfo);
        }
        while (!STAILQ_EMPTY(&gummeiInfo->mme_codes)) {
	  mmeCode = STAILQ_FIRST(&gummeiInfo->mme_codes);
	  STAILQ_REMOVE_HEAD(&gummeiInfo->mme_codes, next);
	  free(mmeCode);
        }
        free(gummeiInfo);
      }
      free(mme);
    }
}