ngap_gNB_defs.h 8.72 KB
Newer Older
zhenghuangkun's avatar
zhenghuangkun committed
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 32 33 34 35 36
/*
 * 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
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * 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
 */

#include <stdint.h>

#include "queue.h"
#include "tree.h"

#include "sctp_gNB_defs.h"

#ifndef NGAP_GNB_DEFS_H_
#define NGAP_GNB_DEFS_H_

#define NGAP_GNB_NAME_LENGTH_MAX    (150)

typedef enum {
  /* Disconnected state: initial state for any association. */
  NGAP_GNB_STATE_DISCONNECTED = 0x0,
zhenghuangkun's avatar
zhenghuangkun committed
37 38
  /* State waiting for S1 Setup response message if gNB is AMF accepted or
   * S1 Setup failure if AMF rejects the gNB.
zhenghuangkun's avatar
zhenghuangkun committed
39 40
   */
  NGAP_GNB_STATE_WAITING     = 0x1,
zhenghuangkun's avatar
zhenghuangkun committed
41
  /* The gNB is successfully connected to AMF, UE contexts can be created. */
zhenghuangkun's avatar
zhenghuangkun committed
42
  NGAP_GNB_STATE_CONNECTED   = 0x2,
zhenghuangkun's avatar
zhenghuangkun committed
43
  /* The AMF has sent an overload start message. Once the AMF disables the
zhenghuangkun's avatar
zhenghuangkun committed
44 45 46 47 48 49 50 51 52 53
   * OVERLOAD marker, the state of the association will be
   * NGAP_GNB_STATE_CONNECTED.
   */
  NGAP_GNB_OVERLOAD          = 0x3,
  /* Max number of states available */
  NGAP_GNB_STATE_MAX,
} ngap_gNB_state_t;

/* If the Overload Action IE in the OVERLOAD START message is set to
 * - “reject all RRC connection establishments for non-emergency mobile
zhenghuangkun's avatar
zhenghuangkun committed
54 55 56
 *    originated data transfer  E(i.e. reject traffic corresponding to RRC cause
 *    “mo-data  E(TS 36.331 [16])), or
 * - “reject all RRC connection establishments for signalling  E(i.e. reject
zhenghuangkun's avatar
zhenghuangkun committed
57
 *    traffic corresponding to RRC cause “modata Eand “mo-signalling E *    (TS 38.331 [16])),or
zhenghuangkun's avatar
zhenghuangkun committed
58
 * - “only permit RRC connection establishments for emergency sessions and
zhenghuangkun's avatar
zhenghuangkun committed
59 60
 *    mobile terminated services E(i.e. only permit traffic corresponding to RRC
 *    cause “emergency Eand “mt-Access E(TS 36.331 [16])).
zhenghuangkun's avatar
zhenghuangkun committed
61 62
 *
 * NOTE: When the Overload Action IE is set to “only permit RRC connection
zhenghuangkun's avatar
zhenghuangkun committed
63 64
 * establishments for emergency sessions and mobile terminated services E
 * emergency calls with RRC cause “highPriorityAcess Efrom high priority users
zhenghuangkun's avatar
zhenghuangkun committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
 * are rejected (TS 24.301 [24]).
 */
typedef enum {
  NGAP_OVERLOAD_REJECT_MO_DATA        = 0x0,
  NGAP_OVERLOAD_REJECT_ALL_SIGNALLING = 0x1,
  NGAP_OVERLOAD_ONLY_EMERGENCY_AND_MT = 0x2,
  NGAP_NO_OVERLOAD                    = 0x3,
  NGAP_OVERLOAD_MAX,
} ngap_overload_state_t;

/* Served PLMN identity element */
struct plmn_identity_s {
  uint16_t mcc;
  uint16_t mnc;
  uint8_t  mnc_digit_length;
  STAILQ_ENTRY(plmn_identity_s) next;
};

zhenghuangkun's avatar
zhenghuangkun committed
83 84 85 86
/* Served amf region id for a particular AMF */
struct served_region_id_s {
  uint8_t amf_region_id;
  STAILQ_ENTRY(served_region_id_s) next;
zhenghuangkun's avatar
zhenghuangkun committed
87 88
};

zhenghuangkun's avatar
zhenghuangkun committed
89 90 91 92
/* Served amf set id for a particular AMF */
struct amf_set_id_s {
  uint16_t amf_set_id;
  STAILQ_ENTRY(amf_set_id_s) next;
zhenghuangkun's avatar
zhenghuangkun committed
93 94
};

zhenghuangkun's avatar
zhenghuangkun committed
95 96 97 98 99 100 101 102 103 104
/* Served amf pointer for a particular AMF */
struct amf_pointer_s {
  uint8_t amf_pointer;
  STAILQ_ENTRY(amf_pointer_s) next;
};


/* Served guami element */
struct served_guami_s {
  /* Number of AMF served PLMNs */
zhenghuangkun's avatar
zhenghuangkun committed
105
  uint8_t nb_served_plmns;
zhenghuangkun's avatar
zhenghuangkun committed
106
  /* List of served PLMNs by AMF */
zhenghuangkun's avatar
zhenghuangkun committed
107 108
  STAILQ_HEAD(served_plmns_s, plmn_identity_s) served_plmns;

zhenghuangkun's avatar
zhenghuangkun committed
109 110
  /* Number of region id in list */
  uint8_t nb_region_id;
zhenghuangkun's avatar
zhenghuangkun committed
111
  /* Served group id list */
zhenghuangkun's avatar
zhenghuangkun committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  STAILQ_HEAD(served_region_ids_s, served_region_id_s) served_region_ids;

  /* Number of AMF set id */
  uint8_t nb_amf_set_id;
  /* AMF Set id to uniquely identify an AMF within an AMF pool area */
  STAILQ_HEAD(amf_set_ids_s, amf_set_id_s) amf_set_ids;

  /* Number of AMF pointer */
  uint8_t nb_amf_pointer;
  /* AMF pointer to uniquely identify an AMF within an AMF pool area */
  STAILQ_HEAD(amf_pointers_s, amf_pointer_s) amf_pointers;
    
  /* Next GUAMI element */
  STAILQ_ENTRY(served_guami_s) next;
};

zhenghuangkun's avatar
zhenghuangkun committed
128 129
/* NSSAI element */
typedef struct ngap_gNB_NSSAI_s{
zhenghuangkun's avatar
zhenghuangkun committed
130 131 132
  uint8_t sST;
  uint8_t sD_flag;
  uint8_t sD[3];
zhenghuangkun's avatar
zhenghuangkun committed
133 134
}ngap_gNB_NSSAI_t, slice_support_s;

zhenghuangkun's avatar
zhenghuangkun committed
135 136 137 138

/* plmn support element */
struct plmn_support_s {
  plmn_identity_s plmn_identity;
zhenghuangkun's avatar
zhenghuangkun committed
139

zhenghuangkun's avatar
zhenghuangkun committed
140 141 142 143
  /* Number of slice support in list */
  uint8_t nb_slice_s;
  /* Served group id list */
  STAILQ_HEAD(slice_supports_s, slice_support_s) slice_supports;
zhenghuangkun's avatar
zhenghuangkun committed
144

zhenghuangkun's avatar
zhenghuangkun committed
145 146
  /* Next plmn support element */
  STAILQ_ENTRY(plmn_support_s) next;
zhenghuangkun's avatar
zhenghuangkun committed
147 148
};

zhenghuangkun's avatar
zhenghuangkun committed
149

zhenghuangkun's avatar
zhenghuangkun committed
150 151
struct ngap_gNB_instance_s;

zhenghuangkun's avatar
zhenghuangkun committed
152 153 154 155
/* This structure describes association of a gNB to a AMF */
typedef struct ngap_gNB_amf_data_s {
  /* AMF descriptors tree, ordered by sctp assoc id */
  RB_ENTRY(ngap_gNB_amf_data_s) entry;
zhenghuangkun's avatar
zhenghuangkun committed
156

zhenghuangkun's avatar
zhenghuangkun committed
157 158
  /* This is the optional name provided by the AMF */
  char *amf_name;
zhenghuangkun's avatar
zhenghuangkun committed
159

zhenghuangkun's avatar
zhenghuangkun committed
160 161
  /* AMF NGAP IP address */
  net_ip_address_t amf_s1_ip;
zhenghuangkun's avatar
zhenghuangkun committed
162

zhenghuangkun's avatar
zhenghuangkun committed
163
  /* List of served GUAMI per AMF. There is one GUAMI per RAT with a max
zhenghuangkun's avatar
zhenghuangkun committed
164 165 166
   * number of 8 RATs but in our case only one is used. The LTE related pool
   * configuration is included on the first place in the list.
   */
zhenghuangkun's avatar
zhenghuangkun committed
167
  STAILQ_HEAD(served_guamis_s, served_guami_s) served_guami;
zhenghuangkun's avatar
zhenghuangkun committed
168

zhenghuangkun's avatar
zhenghuangkun committed
169 170
  /* Relative processing capacity of an AMF with respect to the other AMFs
   * in the pool in order to load-balance AMFs within a pool as defined
zhenghuangkun's avatar
zhenghuangkun committed
171 172
   * in TS 23.401.
   */
zhenghuangkun's avatar
zhenghuangkun committed
173 174 175 176 177 178 179
  uint8_t relative_amf_capacity;

  /*
   * List of PLMN Support per AMF.
   *
   */
  STAILQ_HEAD(plmn_supports_s, plmn_support_s) plmn_supports;
zhenghuangkun's avatar
zhenghuangkun committed
180

zhenghuangkun's avatar
zhenghuangkun committed
181
  /* Current AMF overload information (if any). */
zhenghuangkun's avatar
zhenghuangkun committed
182
  ngap_overload_state_t overload_state;
zhenghuangkun's avatar
zhenghuangkun committed
183
  /* Current gNB->AMF NGAP association state */
zhenghuangkun's avatar
zhenghuangkun committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
  ngap_gNB_state_t state;

  /* Next usable stream for UE signalling */
  int32_t nextstream;

  /* Number of input/ouput streams */
  uint16_t in_streams;
  uint16_t out_streams;

  /* Connexion id used between SCTP/NGAP */
  uint16_t cnx_id;

  /* SCTP association id */
  int32_t  assoc_id;

zhenghuangkun's avatar
zhenghuangkun committed
199
  /* This is served PLMN IDs communicated to the AMF via an index over the
zhenghuangkun's avatar
zhenghuangkun committed
200 201 202 203
   * MCC/MNC array in ngap_gNB_instance */
  uint8_t  broadcast_plmn_num;
  uint8_t  broadcast_plmn_index[PLMN_LIST_MAX_SIZE];

zhenghuangkun's avatar
zhenghuangkun committed
204

zhenghuangkun's avatar
zhenghuangkun committed
205 206
  /* Only meaningfull in virtual mode */
  struct ngap_gNB_instance_s *ngap_gNB_instance;
zhenghuangkun's avatar
zhenghuangkun committed
207 208
} ngap_gNB_amf_data_t;

zhenghuangkun's avatar
zhenghuangkun committed
209 210 211 212 213 214
typedef struct ngap_gNB_instance_s {
  /* Next ngap gNB association.
   * Only used for virtual mode.
   */
  STAILQ_ENTRY(ngap_gNB_instance_s) ngap_gNB_entries;

zhenghuangkun's avatar
zhenghuangkun committed
215 216 217 218 219 220 221 222
  /* Number of AMF requested by gNB (tree size) */
  uint32_t ngap_amf_nb;
  /* Number of AMF for which association is pending */
  uint32_t ngap_amf_pending_nb;
  /* Number of AMF successfully associated to gNB */
  uint32_t ngap_amf_associated_nb;
  /* Tree of NGAP AMF associations ordered by association ID */
  RB_HEAD(ngap_amf_map, ngap_gNB_amf_data_s) ngap_amf_head;
zhenghuangkun's avatar
zhenghuangkun committed
223

zhenghuangkun's avatar
zhenghuangkun committed
224
  /* TODO: add a map ordered by relative AMF capacity */
zhenghuangkun's avatar
zhenghuangkun committed
225 226 227 228 229 230 231 232 233 234 235 236

  /* Tree of UE ordered by gNB_ue_ngap_id's */
  RB_HEAD(ngap_ue_map, ngap_gNB_ue_context_s) ngap_ue_head;

  /* For virtual mode, mod_id as defined in the rest of the L1/L2 stack */
  instance_t instance;

  /* Displayable name of gNB */
  char *gNB_name;

  /* Unique gNB_id to identify the gNB within EPC.
   * In our case the gNB is a macro gNB so the id will be 20 bits long.
zhenghuangkun's avatar
zhenghuangkun committed
237
   * For Home gNB id, this field should be 36 bits long.
zhenghuangkun's avatar
zhenghuangkun committed
238
   */
zhenghuangkun's avatar
zhenghuangkun committed
239
  uint64_t gNB_id;
zhenghuangkun's avatar
zhenghuangkun committed
240 241 242 243
  /* The type of the cell */
  enum cell_type_e cell_type;

  /* Tracking area code */
zhenghuangkun's avatar
zhenghuangkun committed
244
  uint32_t tac;
zhenghuangkun's avatar
zhenghuangkun committed
245 246

  /* gNB NGAP IP address */
zhenghuangkun's avatar
zhenghuangkun committed
247
  net_ip_address_t gNB_ng_ip;
zhenghuangkun's avatar
zhenghuangkun committed
248 249 250 251 252 253 254 255 256
  
  /* Mobile Country Code
   * Mobile Network Code
   */
  uint16_t  mcc[PLMN_LIST_MAX_SIZE];
  uint16_t  mnc[PLMN_LIST_MAX_SIZE];
  uint8_t   mnc_digit_length[PLMN_LIST_MAX_SIZE];
  uint8_t   num_plmn;

zhenghuangkun's avatar
zhenghuangkun committed
257 258 259
  uint16_t   num_nssai[PLMN_LIST_MAX_SIZE];
  ngap_gNB_NSSAI_t s_nssai[PLMN_LIST_MAX_SIZE][1024];
  
zhenghuangkun's avatar
zhenghuangkun committed
260
  /* Default Paging DRX of the gNB as defined in TS 36.304 */
zhenghuangkun's avatar
zhenghuangkun committed
261
  ngap_paging_drx_t default_drx;
zhenghuangkun's avatar
zhenghuangkun committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
} ngap_gNB_instance_t;

typedef struct {
  /* List of served gNBs
   * Only used for virtual mode
   */
  STAILQ_HEAD(ngap_gNB_instances_head_s, ngap_gNB_instance_s) ngap_gNB_instances_head;
  /* Nb of registered gNBs */
  uint8_t nb_registered_gNBs;

  /* Generate a unique connexion id used between NGAP and SCTP */
  uint16_t global_cnx_id;
} ngap_gNB_internal_data_t;

int ngap_gNB_compare_assoc_id(
zhenghuangkun's avatar
zhenghuangkun committed
277
  struct ngap_gNB_amf_data_s *p1, struct ngap_gNB_amf_data_s *p2);
zhenghuangkun's avatar
zhenghuangkun committed
278 279

/* Generate the tree management functions */
zhenghuangkun's avatar
zhenghuangkun committed
280
RB_PROTOTYPE(ngap_amf_map, ngap_gNB_amf_data_s, entry,
zhenghuangkun's avatar
zhenghuangkun committed
281 282 283
             ngap_gNB_compare_assoc_id);

#endif /* NGAP_GNB_DEFS_H_ */