s1ap_eNB_nnsf.c 14.3 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Cedric Roux's avatar
 
Cedric Roux committed
22 23 24 25 26 27 28 29 30 31
/*! \file s1ap_eNB_nnsf.c
 * \brief s1ap NAS node selection functions
 * \author Sebastien ROUX <sebastien.roux@eurecom.fr>
 * \date 2012
 * \version 0.1
 */

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

32
#include "intertask_interface.h"
Cedric Roux's avatar
 
Cedric Roux committed
33

34 35 36
#include "s1ap_common.h"

#include "s1ap_eNB_defs.h"
Cedric Roux's avatar
 
Cedric Roux committed
37 38
#include "s1ap_eNB_nnsf.h"

winckel's avatar
RRC:  
winckel committed
39 40 41 42
struct s1ap_eNB_mme_data_s *
s1ap_eNB_nnsf_select_mme(s1ap_eNB_instance_t       *instance_p,
                         rrc_establishment_cause_t  cause)
{
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  struct s1ap_eNB_mme_data_s *mme_data_p = NULL;
  struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL;
  uint8_t current_capacity = 0;

  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
      /* The association between MME and eNB is not ready for the moment,
       * go to the next known MME.
       */
      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
        /* MME is overloaded. We have to check the RRC establishment
         * cause and take decision to the select this MME depending on
         * the overload state.
         */
        if ((cause == RRC_CAUSE_MO_DATA)
            && (mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_MO_DATA)) {
          continue;
        }

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_ALL_SIGNALLING)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA))) {
          continue;
winckel's avatar
RRC:  
winckel committed
65
        }
66 67 68 69 70

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA)
                || (cause == RRC_CAUSE_HIGH_PRIO_ACCESS))) {
          continue;
winckel's avatar
RRC:  
winckel committed
71
        }
72 73 74 75 76 77 78 79 80 81 82 83 84 85

        /* At this point, the RRC establishment can be handled by the MME
         * even if it is in overload state.
         */
      } else {
        /* The MME is not overloaded, association is simply not ready. */
        continue;
      }
    }

    if (current_capacity < mme_data_p->relative_mme_capacity) {
      /* We find a better MME, keep a reference to it */
      current_capacity = mme_data_p->relative_mme_capacity;
      mme_highest_capacity_p = mme_data_p;
winckel's avatar
RRC:  
winckel committed
86
    }
87
  }
winckel's avatar
RRC:  
winckel committed
88

89
  return mme_highest_capacity_p;
winckel's avatar
RRC:  
winckel committed
90 91
}

Cedric Roux's avatar
 
Cedric Roux committed
92
struct s1ap_eNB_mme_data_s *
93 94 95
s1ap_eNB_nnsf_select_mme_by_plmn_id(s1ap_eNB_instance_t       *instance_p,
                                    rrc_establishment_cause_t  cause,
                                    int                        selected_plmn_identity)
Cedric Roux's avatar
 
Cedric Roux committed
96
{
97 98 99 100 101 102
  struct s1ap_eNB_mme_data_s *mme_data_p = NULL;
  struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL;
  uint8_t current_capacity = 0;

  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
    struct served_gummei_s *gummei_p = NULL;
103
    struct plmn_identity_s *served_plmn_p = NULL;
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
      /* The association between MME and eNB is not ready for the moment,
       * go to the next known MME.
       */
      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
        /* MME is overloaded. We have to check the RRC establishment
         * cause and take decision to the select this MME depending on
         * the overload state.
         */
        if ((cause == RRC_CAUSE_MO_DATA)
            && (mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_MO_DATA)) {
          continue;
        }

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_ALL_SIGNALLING)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA))) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
121
        }
122 123 124 125 126

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA)
                || (cause == RRC_CAUSE_HIGH_PRIO_ACCESS))) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
127 128
        }

129 130 131 132 133 134 135 136 137
        /* At this point, the RRC establishment can be handled by the MME
         * even if it is in overload state.
         */
      } else {
        /* The MME is not overloaded, association is simply not ready. */
        continue;
      }
    }

138 139 140 141 142 143 144 145 146 147 148 149 150 151
    /* Looking for served GUMMEI PLMN Identity selected matching the one provided by the UE */
    STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) {
      STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) {
        if ((served_plmn_p->mcc == instance_p->mcc[selected_plmn_identity]) &&
            (served_plmn_p->mnc == instance_p->mnc[selected_plmn_identity])) {
          break;
        }
      }
      /* if found, we can stop the outer loop, too */
      if (served_plmn_p) break;
    }
    /* if we didn't find such a served PLMN, go on with the next MME */
    if (!served_plmn_p) continue;

152 153 154 155 156 157
    if (current_capacity < mme_data_p->relative_mme_capacity) {
      /* We find a better MME, keep a reference to it */
      current_capacity = mme_data_p->relative_mme_capacity;
      mme_highest_capacity_p = mme_data_p;
    }
  }
winckel's avatar
RRC:  
winckel committed
158

159
  return mme_highest_capacity_p;
winckel's avatar
RRC:  
winckel committed
160 161
}

Cedric Roux's avatar
 
Cedric Roux committed
162
struct s1ap_eNB_mme_data_s *
163
s1ap_eNB_nnsf_select_mme_by_mme_code(s1ap_eNB_instance_t       *instance_p,
Cedric Roux's avatar
 
Cedric Roux committed
164
                                     rrc_establishment_cause_t  cause,
165
                                     int                        selected_plmn_identity,
Cedric Roux's avatar
 
Cedric Roux committed
166 167
                                     uint8_t                    mme_code)
{
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  struct s1ap_eNB_mme_data_s *mme_data_p = NULL;

  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
    struct served_gummei_s *gummei_p = NULL;

    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
      /* The association between MME and eNB is not ready for the moment,
       * go to the next known MME.
       */
      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
        /* MME is overloaded. We have to check the RRC establishment
         * cause and take decision to the select this MME depending on
         * the overload state.
         */
        if ((cause == RRC_CAUSE_MO_DATA)
            && (mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_MO_DATA)) {
          continue;
        }

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_ALL_SIGNALLING)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA))) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
190
        }
191 192 193 194 195

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA)
                || (cause == RRC_CAUSE_HIGH_PRIO_ACCESS))) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
196 197
        }

198 199 200 201 202 203 204 205
        /* At this point, the RRC establishment can be handled by the MME
         * even if it is in overload state.
         */
      } else {
        /* The MME is not overloaded, association is simply not ready. */
        continue;
      }
    }
Cedric Roux's avatar
 
Cedric Roux committed
206

207 208 209
    /* Looking for MME code matching the one provided by NAS */
    STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) {
      struct mme_code_s *mme_code_p = NULL;
210
      struct plmn_identity_s   *served_plmn_p = NULL;
211

212 213 214 215 216 217
      STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) {
        if ((served_plmn_p->mcc == instance_p->mcc[selected_plmn_identity]) &&
            (served_plmn_p->mnc == instance_p->mnc[selected_plmn_identity])) {
          break;
        }
      }
218 219
      STAILQ_FOREACH(mme_code_p, &gummei_p->mme_codes, next) {
        if (mme_code_p->mme_code == mme_code) {
220
          break;
Cedric Roux's avatar
 
Cedric Roux committed
221
        }
222
      }
223 224 225 226 227 228 229 230

      /* The MME matches the parameters provided by the NAS layer ->
      * the MME is knwown and the association is ready.
      * Return the reference to the MME to use it for this UE.
      */
      if (mme_code_p && served_plmn_p) {
        return mme_data_p;
      }
Cedric Roux's avatar
 
Cedric Roux committed
231
    }
232
  }
Cedric Roux's avatar
 
Cedric Roux committed
233

234 235 236 237
  /* At this point no MME matches the selected PLMN and MME code. In this case,
   * return NULL. That way the RRC layer should know about it and reject RRC
   * connectivity. */
  return NULL;
Cedric Roux's avatar
 
Cedric Roux committed
238 239 240
}

struct s1ap_eNB_mme_data_s *
241
s1ap_eNB_nnsf_select_mme_by_gummei(s1ap_eNB_instance_t       *instance_p,
Cedric Roux's avatar
 
Cedric Roux committed
242
                                   rrc_establishment_cause_t  cause,
winckel's avatar
RRC:  
winckel committed
243
                                   s1ap_gummei_t                   gummei)
Cedric Roux's avatar
 
Cedric Roux committed
244
{
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
  struct s1ap_eNB_mme_data_s *mme_data_p             = NULL;

  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
    struct served_gummei_s *gummei_p = NULL;

    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
      /* The association between MME and eNB is not ready for the moment,
       * go to the next known MME.
       */
      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
        /* MME is overloaded. We have to check the RRC establishment
         * cause and take decision to the select this MME depending on
         * the overload state.
         */
        if ((cause == RRC_CAUSE_MO_DATA)
            && (mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_MO_DATA)) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
262
        }
263 264 265 266

        if ((mme_data_p->overload_state == S1AP_OVERLOAD_REJECT_ALL_SIGNALLING)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA))) {
          continue;
Cedric Roux's avatar
 
Cedric Roux committed
267 268
        }

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
        if ((mme_data_p->overload_state == S1AP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
            && ((cause == RRC_CAUSE_MO_SIGNALLING) || (cause == RRC_CAUSE_MO_DATA)
                || (cause == RRC_CAUSE_HIGH_PRIO_ACCESS))) {
          continue;
        }

        /* At this point, the RRC establishment can be handled by the MME
         * even if it is in overload state.
         */
      } else {
        /* The MME is not overloaded, association is simply not ready. */
        continue;
      }
    }

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
    /* Looking for MME gummei matching the one provided by NAS */
    STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) {
      struct served_group_id_s *group_id_p = NULL;
      struct mme_code_s        *mme_code_p = NULL;
      struct plmn_identity_s   *served_plmn_p = NULL;

      STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) {
        if ((served_plmn_p->mcc == gummei.mcc) &&
            (served_plmn_p->mnc == gummei.mnc)) {
          break;
        }
      }
      STAILQ_FOREACH(mme_code_p, &gummei_p->mme_codes, next) {
        if (mme_code_p->mme_code == gummei.mme_code) {
          break;
        }
      }
      STAILQ_FOREACH(group_id_p, &gummei_p->served_group_ids, next) {
        if (group_id_p->mme_group_id == gummei.mme_group_id) {
          break;
        }
      }

      /* The MME matches the parameters provided by the NAS layer ->
      * the MME is knwown and the association is ready.
      * Return the reference to the MME to use it for this UE.
      */
      if ((group_id_p != NULL) &&
          (mme_code_p != NULL) &&
          (served_plmn_p != NULL)) {
        return mme_data_p;
      }
    }
  }

319 320 321 322
  /* At this point no MME matches the provided GUMMEI. In this case, return
   * NULL. That way the RRC layer should know about it and reject RRC
   * connectivity. */
  return NULL;
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
}


struct s1ap_eNB_mme_data_s *
s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_t       *instance_p,
                                            s1ap_gummei_t                   gummei)
{
  struct s1ap_eNB_mme_data_s *mme_data_p             = NULL;
  struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL;
  uint8_t                     current_capacity       = 0;

  RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
    struct served_gummei_s *gummei_p = NULL;

    if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
      /* The association between MME and eNB is not ready for the moment,
       * go to the next known MME.
       */
      if (mme_data_p->state == S1AP_ENB_OVERLOAD) {
        /* MME is overloaded. We have to check the RRC establishment
         * cause and take decision to the select this MME depending on
         * the overload state.
         */
    } else {
        /* The MME is not overloaded, association is simply not ready. */
        continue;
      }
    }

    if (current_capacity < mme_data_p->relative_mme_capacity) {
      /* We find a better MME, keep a reference to it */
      current_capacity = mme_data_p->relative_mme_capacity;
      mme_highest_capacity_p = mme_data_p;
    }

358 359 360 361 362 363 364 365 366 367
    /* Looking for MME gummei matching the one provided by NAS */
    STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) {
      struct served_group_id_s *group_id_p = NULL;
      struct mme_code_s        *mme_code_p = NULL;
      struct plmn_identity_s   *served_plmn_p = NULL;

      STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) {
        if ((served_plmn_p->mcc == gummei.mcc) &&
            (served_plmn_p->mnc == gummei.mnc)) {
          break;
Cedric Roux's avatar
 
Cedric Roux committed
368
        }
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
      }
      STAILQ_FOREACH(mme_code_p, &gummei_p->mme_codes, next) {
        if (mme_code_p->mme_code == gummei.mme_code) {
          break;
        }
      }
      STAILQ_FOREACH(group_id_p, &gummei_p->served_group_ids, next) {
        if (group_id_p->mme_group_id == gummei.mme_group_id) {
          break;
        }
      }

      /* The MME matches the parameters provided by the NAS layer ->
      * the MME is knwown and the association is ready.
      * Return the reference to the MME to use it for this UE.
      */
      if ((group_id_p != NULL) &&
          (mme_code_p != NULL) &&
          (served_plmn_p != NULL)) {
        return mme_data_p;
      }
Cedric Roux's avatar
 
Cedric Roux committed
390
    }
391
  }
Cedric Roux's avatar
 
Cedric Roux committed
392

393 394 395 396 397 398
  /* At this point no MME matches the provided GUMMEI. Select the one with the
   * highest relative capacity.
   * In case the list of known MME is empty, simply return NULL, that way the RRC
   * layer should know about it and reject RRC connectivity.
   */
  return mme_highest_capacity_p;
Cedric Roux's avatar
 
Cedric Roux committed
399
}