amf_config.cpp 43.7 KB
Newer Older
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
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 7 8
 * 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
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 *      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
 */

dukl's avatar
dukl committed
22
#include "amf_config.hpp"
23

24 25 26
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
27 28
#include <iostream>
#include <libconfig.h++>
29

30
#include "3gpp_29.502.h"
31
#include "3gpp_ts24501.hpp"
dukl's avatar
dukl committed
32
#include "amf_app.hpp"
33 34
#include "conversions.hpp"
#include "fqdn.hpp"
dukl's avatar
dukl committed
35
#include "if.hpp"
36
#include "logger.hpp"
37 38
#include "string.hpp"
#include "thread_sched.hpp"
39

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
40 41 42 43 44
extern "C" {
#include <arpa/inet.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
45

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
46
#include "common_defs.h"
dukl's avatar
dukl committed
47 48 49
}

using namespace libconfig;
dukl's avatar
dukl committed
50
using namespace amf_application;
dukl's avatar
dukl committed
51

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
52
namespace config {
dukl's avatar
dukl committed
53

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
54 55
//------------------------------------------------------------------------------
amf_config::amf_config() {
56 57 58 59 60 61
  nrf_addr.ipv4_addr.s_addr               = INADDR_ANY;
  nrf_addr.port                           = 80;
  nrf_addr.api_version                    = "v1";
  ausf_addr.ipv4_addr.s_addr              = INADDR_ANY;
  ausf_addr.port                          = 80;
  ausf_addr.api_version                   = "v1";
62 63 64 65 66 67
  udm_addr.ipv4_addr.s_addr               = INADDR_ANY;
  udm_addr.port                           = 80;
  udm_addr.api_version                    = "v1";
  nssf_addr.ipv4_addr.s_addr              = INADDR_ANY;
  nssf_addr.port                          = 80;
  nssf_addr.api_version                   = "v1";
68 69
  instance                                = 0;
  n2                                      = {};
70
  sbi                                     = {};
71 72 73 74 75
  sbi_api_version                         = "v1";
  sbi_http2_port                          = 8080;
  statistics_interval                     = 0;
  guami                                   = {};
  guami_list                              = {};
76
  relative_amf_capacity                   = 0;
77
  plmn_list                               = {};
78
  auth_para                               = {};
79 80 81
  nas_cfg                                 = {};
  smf_pool                                = {};
  support_features.enable_nf_registration = false;
82
  support_features.enable_nrf_selection   = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
83
  support_features.enable_external_nrf    = false;
84 85 86
  support_features.enable_smf_selection   = false;
  support_features.enable_external_ausf   = false;
  support_features.enable_external_udm    = false;
87
  support_features.enable_external_nssf   = false;
88 89
  support_features.use_fqdn_dns           = false;
  support_features.use_http2              = false;
90
  // TODO:
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
91 92 93
}

//------------------------------------------------------------------------------
94
amf_config::~amf_config() {}
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
95 96

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
97 98 99
int amf_config::load(const std::string& config_file) {
  Logger::amf_app().debug(
      "\nLoad AMF system configuration file(%s)", config_file.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
100 101
  Config cfg;
  unsigned char buf_in6_addr[sizeof(struct in6_addr)];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
102 103

  // Config file
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
104 105
  try {
    cfg.readFile(config_file.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
106 107 108 109
  } catch (const FileIOException& fioex) {
    Logger::amf_app().error(
        "I/O error while reading file %s - %s", config_file.c_str(),
        fioex.what());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
110
    throw;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
111 112 113 114
  } catch (const ParseException& pex) {
    Logger::amf_app().error(
        "Parse error at %s:%d - %s", pex.getFile(), pex.getLine(),
        pex.getError());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
115
    throw;
dukl's avatar
dukl committed
116
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
117

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
118
  const Setting& root = cfg.getRoot();
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
119 120

  // AMF config
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
121
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
122 123
    const Setting& amf_cfg = root[AMF_CONFIG_STRING_AMF_CONFIG];
  } catch (const SettingNotFoundException& nfex) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
124
    Logger::amf_app().error("%s : %s", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
125
    return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
126
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
127 128

  // Instance
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
129
  const Setting& amf_cfg = root[AMF_CONFIG_STRING_AMF_CONFIG];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
130 131
  try {
    amf_cfg.lookupValue(AMF_CONFIG_STRING_INSTANCE_ID, instance);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
132 133 134
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
135
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
136 137

  // Statistic Timer interval
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
138
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
139 140 141 142 143
    amf_cfg.lookupValue(
        AMF_CONFIG_STRING_STATISTICS_TIMER_INTERVAL, statistics_interval);
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
144
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
145 146

  // PID Dir
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
147 148
  try {
    amf_cfg.lookupValue(AMF_CONFIG_STRING_PID_DIRECTORY, pid_dir);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
149 150 151
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
152
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
153 154

  // AMF Name
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
155
  try {
156
    amf_cfg.lookupValue(AMF_CONFIG_STRING_AMF_NAME, amf_name);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
157 158 159
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
160
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
161 162

  // GUAMI
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
163
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
164
    const Setting& guami_cfg = amf_cfg[AMF_CONFIG_STRING_GUAMI];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
165 166 167 168 169
    guami_cfg.lookupValue(AMF_CONFIG_STRING_MCC, guami.mcc);
    guami_cfg.lookupValue(AMF_CONFIG_STRING_MNC, guami.mnc);
    guami_cfg.lookupValue(AMF_CONFIG_STRING_RegionID, guami.regionID);
    guami_cfg.lookupValue(AMF_CONFIG_STRING_AMFSetID, guami.AmfSetID);
    guami_cfg.lookupValue(AMF_CONFIG_STRING_AMFPointer, guami.AmfPointer);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
170 171 172
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
173
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
174 175

  // GUAMI List
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
176
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
177
    const Setting& guami_list_cfg =
178
        amf_cfg[AMF_CONFIG_STRING_SERVED_GUAMI_LIST];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
179 180 181
    int count = guami_list_cfg.getLength();
    for (int i = 0; i < count; i++) {
      guami_t guami;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
182
      const Setting& guami_item = guami_list_cfg[i];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
183 184 185 186 187 188
      guami_item.lookupValue(AMF_CONFIG_STRING_MCC, guami.mcc);
      guami_item.lookupValue(AMF_CONFIG_STRING_MNC, guami.mnc);
      guami_item.lookupValue(AMF_CONFIG_STRING_RegionID, guami.regionID);
      guami_item.lookupValue(AMF_CONFIG_STRING_AMFSetID, guami.AmfSetID);
      guami_item.lookupValue(AMF_CONFIG_STRING_AMFPointer, guami.AmfPointer);
      guami_list.push_back(guami);
dukl's avatar
dukl committed
189
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
190 191 192
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
193
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
194 195

  // AMF Capacity
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
196
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
197
    amf_cfg.lookupValue(
198
        AMF_CONFIG_STRING_RELATIVE_AMF_CAPACITY, relative_amf_capacity);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
199 200 201
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
202
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
203 204

  // PLMN List
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
205
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
206 207
    const Setting& plmn_list_cfg = amf_cfg[AMF_CONFIG_STRING_PLMN_SUPPORT_LIST];
    int count                    = plmn_list_cfg.getLength();
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
208 209
    for (int i = 0; i < count; i++) {
      plmn_item_t plmn_item;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
210
      const Setting& item = plmn_list_cfg[i];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
211 212 213
      item.lookupValue(AMF_CONFIG_STRING_MCC, plmn_item.mcc);
      item.lookupValue(AMF_CONFIG_STRING_MNC, plmn_item.mnc);
      item.lookupValue(AMF_CONFIG_STRING_TAC, plmn_item.tac);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
214
      const Setting& slice_list_cfg =
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
215
          plmn_list_cfg[i][AMF_CONFIG_STRING_SLICE_SUPPORT_LIST];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
216 217 218
      int numOfSlice = slice_list_cfg.getLength();
      for (int j = 0; j < numOfSlice; j++) {
        slice_t slice;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
219
        const Setting& slice_item = slice_list_cfg[j];
220 221 222 223
        std::string sst           = {};
        std::string sd            = {};
        slice_item.lookupValue(AMF_CONFIG_STRING_SST, sst);
        slice_item.lookupValue(AMF_CONFIG_STRING_SD, sd);
224
        slice.sd = SD_NO_VALUE;  // Default value
225 226
        try {
          slice.sst = std::stoi(sst);
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
227
          conv::sd_string_to_int(sd, slice.sd);
228 229 230
        } catch (const std::exception& err) {
          Logger::amf_app().error("Invalid SST/SD");
        }
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
231

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
232
        plmn_item.slice_list.push_back(slice);
dukl's avatar
dukl committed
233
      }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
234
      plmn_list.push_back(plmn_item);
dukl's avatar
dukl committed
235
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
236 237 238
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
239
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
240

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
241
  // Supported features
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
242
  try {
243
    const Setting& support_features_cfg =
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
244 245
        amf_cfg[AMF_CONFIG_STRING_SUPPORT_FEATURES];
    string opt;
246
    support_features_cfg.lookupValue(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
247 248
        AMF_CONFIG_STRING_SUPPORT_FEATURES_NF_REGISTRATION, opt);
    if (boost::iequals(opt, "yes")) {
249
      support_features.enable_nf_registration = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
250
    } else {
251
      support_features.enable_nf_registration = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
252 253
    }

254 255 256 257 258 259 260 261
    support_features_cfg.lookupValue(
        AMF_CONFIG_STRING_SUPPORT_FEATURES_NRF_SELECTION, opt);
    if (boost::iequals(opt, "yes")) {
      support_features.enable_nrf_selection = true;
    } else {
      support_features.enable_nrf_selection = false;
    }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
262 263 264 265 266 267 268
    support_features_cfg.lookupValue(
        AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_NRF, opt);
    if (boost::iequals(opt, "yes")) {
      support_features.enable_external_nrf = true;
    } else {
      support_features.enable_external_nrf = false;
    }
269 270
    // TODO: should be removed
    support_features.enable_external_nrf = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
271

272
    support_features_cfg.lookupValue(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
273 274
        AMF_CONFIG_STRING_SUPPORT_FEATURES_SMF_SELECTION, opt);
    if (boost::iequals(opt, "yes")) {
275
      support_features.enable_smf_selection = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
276
    } else {
277
      support_features.enable_smf_selection = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
278 279
    }

280
    support_features_cfg.lookupValue(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
281 282
        AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF, opt);
    if (boost::iequals(opt, "yes")) {
283
      support_features.enable_external_ausf = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
284
    } else {
285
      support_features.enable_external_ausf = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
286 287
    }

288
    support_features_cfg.lookupValue(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
289 290
        AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_UDM, opt);
    if (boost::iequals(opt, "yes")) {
291
      support_features.enable_external_udm = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
292
    } else {
293
      support_features.enable_external_udm = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
294
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
295

296 297 298 299 300 301 302 303
    support_features_cfg.lookupValue(
        AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_NSSF, opt);
    if (boost::iequals(opt, "yes")) {
      support_features.enable_external_nssf = true;
    } else {
      support_features.enable_external_nssf = false;
    }

304 305 306 307
    // TODO: should be removed
    support_features.enable_external_nssf =
        support_features.enable_nrf_selection;

308
    support_features_cfg.lookupValue(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
309 310
        AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS, opt);
    if (boost::iequals(opt, "yes")) {
311
      support_features.use_fqdn_dns = true;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
312
    } else {
313 314 315 316 317 318 319 320 321
      support_features.use_fqdn_dns = false;
    }

    support_features_cfg.lookupValue(
        AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_HTTP2, opt);
    if (boost::iequals(opt, "yes")) {
      support_features.use_http2 = true;
    } else {
      support_features.use_http2 = false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
322 323 324 325 326
    }

  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
327
    return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
328 329
  }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
330 331
  // Network interfaces
  // TODO: should move SMF/NRF/AUSF out of this section
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
332
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
333
    const Setting& new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
334 335

    // N2
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
336
    const Setting& n2_amf_cfg =
337
        new_if_cfg[AMF_CONFIG_STRING_INTERFACE_NGAP_AMF];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
338
    load_interface(n2_amf_cfg, n2);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
339

340 341 342
    // SBI
    const Setting& sbi_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_SBI];
    load_interface(sbi_cfg, sbi);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
343

344
    // SBI API VERSION
345
    if (!(sbi_cfg.lookupValue(
346 347 348 349 350
            AMF_CONFIG_STRING_API_VERSION, sbi_api_version))) {
      Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
      throw(AMF_CONFIG_STRING_API_VERSION "failed");
    }

351
    // HTTP2 port
352
    if (!(sbi_cfg.lookupValue(
353 354 355 356 357
            AMF_CONFIG_STRING_SBI_HTTP2_PORT, sbi_http2_port))) {
      Logger::amf_app().error(AMF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
      throw(AMF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
    }

358 359 360 361 362 363 364 365 366 367 368 369 370
    if (!support_features.enable_smf_selection) {
      // SMF
      const Setting& smf_addr_pool =
          sbi_cfg[AMF_CONFIG_STRING_SMF_INSTANCES_POOL];
      int count = smf_addr_pool.getLength();
      for (int i = 0; i < count; i++) {
        const Setting& smf_addr_item = smf_addr_pool[i];
        smf_inst_t smf_inst          = {};
        struct in_addr smf_ipv4_addr = {};
        unsigned int smf_port        = {};
        uint32_t smf_http2_port      = {};
        std::string smf_api_version  = {};
        std::string selected         = {};
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
371

372 373
        // Store FQDN
        smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_inst.fqdn);
374

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
375
        smf_addr_item.lookupValue(
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
            AMF_CONFIG_STRING_SMF_INSTANCE_ID, smf_inst.id);
        if (!support_features.use_fqdn_dns) {
          smf_addr_item.lookupValue(
              AMF_CONFIG_STRING_IPV4_ADDRESS, smf_inst.ipv4);
          IPV4_STR_ADDR_TO_INADDR(
              util::trim(smf_inst.ipv4).c_str(), smf_ipv4_addr,
              "BAD IPv4 ADDRESS FORMAT FOR SMF !");
          if (!(smf_addr_item.lookupValue(
                  AMF_CONFIG_STRING_SMF_INSTANCE_PORT, smf_inst.port))) {
            Logger::amf_app().error(AMF_CONFIG_STRING_SMF_INSTANCE_PORT
                                    "failed");
            throw(AMF_CONFIG_STRING_SMF_INSTANCE_PORT "failed");
          }
          if (!(smf_addr_item.lookupValue(
                  AMF_CONFIG_STRING_SBI_HTTP2_PORT, smf_inst.http2_port))) {
            Logger::amf_app().error(AMF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
            throw(AMF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
          }
          smf_addr_item.lookupValue(
              AMF_CONFIG_STRING_SMF_INSTANCE_VERSION, smf_inst.version);
          if (!(smf_addr_item.lookupValue(
                  AMF_CONFIG_STRING_SMF_INSTANCE_VERSION, smf_inst.version))) {
            Logger::amf_app().error(AMF_CONFIG_STRING_SMF_INSTANCE_VERSION
                                    "failed");
            throw(AMF_CONFIG_STRING_SMF_INSTANCE_VERSION "failed");
          }
        } else {
          smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_inst.fqdn);
404
        }
405

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
406
        smf_addr_item.lookupValue(
407 408 409 410 411 412
            AMF_CONFIG_STRING_SMF_INSTANCE_SELECTED, selected);
        if (boost::iequals(selected, "true"))
          smf_inst.selected = true;
        else
          smf_inst.selected = false;
        smf_pool.push_back(smf_inst);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
413
      }
dukl's avatar
dukl committed
414
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
415 416

    // NRF
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
417 418 419 420 421 422
    const Setting& nrf_cfg       = new_if_cfg[AMF_CONFIG_STRING_NRF];
    struct in_addr nrf_ipv4_addr = {};
    unsigned int nrf_port        = 0;
    std::string nrf_api_version  = {};
    string address               = {};

423
    if (!support_features.use_fqdn_dns) {
424 425 426
      // Store FQDN
      nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_addr.fqdn);

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
      nrf_cfg.lookupValue(AMF_CONFIG_STRING_NRF_IPV4_ADDRESS, address);
      IPV4_STR_ADDR_TO_INADDR(
          util::trim(address).c_str(), nrf_ipv4_addr,
          "BAD IPv4 ADDRESS FORMAT FOR NRF !");
      nrf_addr.ipv4_addr = nrf_ipv4_addr;
      if (!(nrf_cfg.lookupValue(AMF_CONFIG_STRING_NRF_PORT, nrf_port))) {
        Logger::amf_app().error(AMF_CONFIG_STRING_NRF_PORT "failed");
        throw(AMF_CONFIG_STRING_NRF_PORT "failed");
      }
      nrf_addr.port = nrf_port;
      if (!(nrf_cfg.lookupValue(
              AMF_CONFIG_STRING_API_VERSION, nrf_api_version))) {
        Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
        throw(AMF_CONFIG_STRING_API_VERSION "failed");
      }
      nrf_addr.api_version = nrf_api_version;
    } else {
444
      nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_addr.fqdn);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
445
      uint8_t addr_type = {};
446
      fqdn::resolve(nrf_addr.fqdn, address, nrf_port, addr_type);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
447 448 449
      if (addr_type != 0) {  // IPv6: TODO
        throw("DO NOT SUPPORT IPV6 ADDR FOR NRF!");
      } else {  // IPv4
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
450 451 452
        IPV4_STR_ADDR_TO_INADDR(
            util::trim(address).c_str(), nrf_ipv4_addr,
            "BAD IPv4 ADDRESS FORMAT FOR NRF !");
453 454 455 456 457 458 459 460 461 462
        nrf_addr.ipv4_addr = nrf_ipv4_addr;
        // nrf_addr.port        = nrf_port;

        // We hardcode nrf port from config for the moment
        if (!(nrf_cfg.lookupValue(AMF_CONFIG_STRING_NRF_PORT, nrf_port))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_NRF_PORT "failed");
          throw(AMF_CONFIG_STRING_NRF_PORT "failed");
        }
        nrf_addr.port = nrf_port;
        //
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
463
        nrf_addr.api_version = "v1";  // TODO: get API version
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
464
      }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
465
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
466

467
    // AUSF
468
    if (support_features.enable_external_ausf) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
469 470 471 472
      const Setting& ausf_cfg       = new_if_cfg[AMF_CONFIG_STRING_AUSF];
      struct in_addr ausf_ipv4_addr = {};
      unsigned int ausf_port        = {};
      std::string ausf_api_version  = {};
473

474
      if (!support_features.use_fqdn_dns) {
475 476 477
        // Store FQDN
        ausf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, ausf_addr.fqdn);

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
        ausf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
        IPV4_STR_ADDR_TO_INADDR(
            util::trim(address).c_str(), ausf_ipv4_addr,
            "BAD IPv4 ADDRESS FORMAT FOR AUSF !");
        ausf_addr.ipv4_addr = ausf_ipv4_addr;
        if (!(ausf_cfg.lookupValue(AMF_CONFIG_STRING_PORT, ausf_port))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_PORT "failed");
          throw(AMF_CONFIG_STRING_PORT "failed");
        }
        ausf_addr.port = ausf_port;

        if (!(ausf_cfg.lookupValue(
                AMF_CONFIG_STRING_API_VERSION, ausf_api_version))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
          throw(AMF_CONFIG_STRING_API_VERSION "failed");
        }
        ausf_addr.api_version = ausf_api_version;
      } else {
496
        ausf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, ausf_addr.fqdn);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
497
        uint8_t addr_type = {};
498
        fqdn::resolve(ausf_addr.fqdn, address, ausf_port, addr_type);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
499 500 501 502 503 504
        if (addr_type != 0) {  // IPv6: TODO
          throw("DO NOT SUPPORT IPV6 ADDR FOR AUSF!");
        } else {  // IPv4
          IPV4_STR_ADDR_TO_INADDR(
              util::trim(address).c_str(), ausf_ipv4_addr,
              "BAD IPv4 ADDRESS FORMAT FOR AUSF !");
505 506 507 508 509 510
          ausf_addr.ipv4_addr = ausf_ipv4_addr;
          // We hardcode nrf port from config for the moment
          if (!(ausf_cfg.lookupValue(AMF_CONFIG_STRING_PORT, ausf_port))) {
            Logger::amf_app().error(AMF_CONFIG_STRING_PORT "failed");
            throw(AMF_CONFIG_STRING_PORT "failed");
          }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
511 512 513 514
          ausf_addr.port        = ausf_port;
          ausf_addr.api_version = "v1";  // TODO: get API version
        }
      }
515 516
    }

517 518 519 520 521 522 523 524
    // UDM
    if (support_features.enable_external_udm) {
      const Setting& udm_cfg       = new_if_cfg[AMF_CONFIG_STRING_UDM];
      struct in_addr udm_ipv4_addr = {};
      unsigned int udm_port        = {};
      std::string udm_api_version  = {};

      if (!support_features.use_fqdn_dns) {
525 526 527
        // Store FQDN
        udm_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, udm_addr.fqdn);

528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
        udm_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
        IPV4_STR_ADDR_TO_INADDR(
            util::trim(address).c_str(), udm_ipv4_addr,
            "BAD IPv4 ADDRESS FORMAT FOR UDM !");
        udm_addr.ipv4_addr = udm_ipv4_addr;
        if (!(udm_cfg.lookupValue(AMF_CONFIG_STRING_PORT, udm_port))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_PORT "failed");
          throw(AMF_CONFIG_STRING_PORT "failed");
        }
        udm_addr.port = udm_port;

        if (!(udm_cfg.lookupValue(
                AMF_CONFIG_STRING_API_VERSION, udm_api_version))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
          throw(AMF_CONFIG_STRING_API_VERSION "failed");
        }
        udm_addr.api_version = udm_api_version;
      } else {
546
        udm_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, udm_addr.fqdn);
547
        uint8_t addr_type = {};
548
        fqdn::resolve(udm_addr.fqdn, address, udm_port, addr_type);
549 550 551 552 553 554 555 556 557 558 559 560 561
        if (addr_type != 0) {  // IPv6: TODO
          throw("DO NOT SUPPORT IPV6 ADDR FOR UDM!");
        } else {  // IPv4
          IPV4_STR_ADDR_TO_INADDR(
              util::trim(address).c_str(), udm_ipv4_addr,
              "BAD IPv4 ADDRESS FORMAT FOR UDM !");
          udm_addr.ipv4_addr   = udm_ipv4_addr;
          udm_addr.port        = udm_port;
          udm_addr.api_version = "v1";  // TODO: get API version
        }
      }
    }

562
    // NSSF
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
563
    if (support_features.enable_external_nssf) {
564 565 566 567 568 569
      const Setting& nssf_cfg       = new_if_cfg[AMF_CONFIG_STRING_NSSF];
      struct in_addr nssf_ipv4_addr = {};
      unsigned int nssf_port        = {};
      std::string nssf_api_version  = {};

      if (!support_features.use_fqdn_dns) {
570 571
        // Store FQDN
        nssf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nssf_addr.fqdn);
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
        nssf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
        IPV4_STR_ADDR_TO_INADDR(
            util::trim(address).c_str(), nssf_ipv4_addr,
            "BAD IPv4 ADDRESS FORMAT FOR NSSF !");
        nssf_addr.ipv4_addr = nssf_ipv4_addr;
        if (!(nssf_cfg.lookupValue(AMF_CONFIG_STRING_PORT, nssf_port))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_PORT "failed");
          throw(AMF_CONFIG_STRING_PORT "failed");
        }
        nssf_addr.port = nssf_port;

        if (!(nssf_cfg.lookupValue(
                AMF_CONFIG_STRING_API_VERSION, nssf_api_version))) {
          Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
          throw(AMF_CONFIG_STRING_API_VERSION "failed");
        }
        nssf_addr.api_version = nssf_api_version;
      } else {
590
        nssf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nssf_addr.fqdn);
591
        uint8_t addr_type = {};
592
        fqdn::resolve(nssf_addr.fqdn, address, nssf_port, addr_type);
593 594 595 596 597 598 599 600 601 602 603 604
        if (addr_type != 0) {  // IPv6: TODO
          throw("DO NOT SUPPORT IPV6 ADDR FOR NSSF!");
        } else {  // IPv4
          IPV4_STR_ADDR_TO_INADDR(
              util::trim(address).c_str(), nssf_ipv4_addr,
              "BAD IPv4 ADDRESS FORMAT FOR NSSF !");
          nssf_addr.ipv4_addr   = nssf_ipv4_addr;
          nssf_addr.port        = nssf_port;
          nssf_addr.api_version = "v1";  // TODO: get API version
        }
      }
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
605 606 607
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
608
    return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
609
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
610 611

  // Emergency support
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
612
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
613 614 615 616 617 618
    const Setting& core_config = amf_cfg[AMF_CONFIG_STRING_CORE_CONFIGURATION];
    core_config.lookupValue(
        AMF_CONFIG_STRING_EMERGENCY_SUPPORT, is_emergency_support);
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
619
    return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
620
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
621 622

  // Authentication Info
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
623
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
624 625 626
    const Setting& auth = amf_cfg[AMF_CONFIG_STRING_AUTHENTICATION];
    auth.lookupValue(
        AMF_CONFIG_STRING_AUTH_MYSQL_SERVER, auth_para.mysql_server);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
627 628 629 630
    auth.lookupValue(AMF_CONFIG_STRING_AUTH_MYSQL_USER, auth_para.mysql_user);
    auth.lookupValue(AMF_CONFIG_STRING_AUTH_MYSQL_PASS, auth_para.mysql_pass);
    auth.lookupValue(AMF_CONFIG_STRING_AUTH_MYSQL_DB, auth_para.mysql_db);
    auth.lookupValue(AMF_CONFIG_STRING_AUTH_RANDOM, auth_para.random);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
631 632 633
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
634
    return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
635
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
636 637

  // Integrity/Ciphering algorithms (NAS)
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
638
  try {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
639 640
    const Setting& nas = amf_cfg[AMF_CONFIG_STRING_NAS];
    const Setting& intAlg =
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
641
        nas[AMF_CONFIG_STRING_NAS_SUPPORTED_INTEGRITY_ALGORITHM_LIST];
dukl's avatar
dukl committed
642

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
643 644
    int intCount = intAlg.getLength();
    for (int i = 0; i < intCount; i++) {
645
      std::string intAlgStr = intAlg[i];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
646
      if (!intAlgStr.compare("NIA0"))
dukl's avatar
dukl committed
647
        nas_cfg.prefered_integrity_algorithm[i] = IA0_5G;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
648 649 650 651 652 653 654 655
      if (!intAlgStr.compare("NIA1"))
        nas_cfg.prefered_integrity_algorithm[i] = IA1_128_5G;
      if (!intAlgStr.compare("NIA2"))
        nas_cfg.prefered_integrity_algorithm[i] = IA2_128_5G;
    }
    for (int i = intCount; i < 8; i++) {
      nas_cfg.prefered_integrity_algorithm[i] = IA0_5G;
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
656
    const Setting& encAlg =
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
657
        nas[AMF_CONFIG_STRING_NAS_SUPPORTED_CIPHERING_ALGORITHM_LIST];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
658 659
    int encCount = encAlg.getLength();
    for (int i = 0; i < encCount; i++) {
660
      std::string encAlgStr = encAlg[i];
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
661
      if (!encAlgStr.compare("NEA0"))
dukl's avatar
dukl committed
662
        nas_cfg.prefered_ciphering_algorithm[i] = EA0_5G;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
663 664 665 666 667 668 669
      if (!encAlgStr.compare("NEA1"))
        nas_cfg.prefered_ciphering_algorithm[i] = EA1_128_5G;
      if (!encAlgStr.compare("NEA2"))
        nas_cfg.prefered_ciphering_algorithm[i] = EA2_128_5G;
    }
    for (int i = encCount; i < 8; i++) {
      nas_cfg.prefered_ciphering_algorithm[i] = EA0_5G;
dukl's avatar
dukl committed
670
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
671

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
672 673 674
  } catch (const SettingNotFoundException& nfex) {
    Logger::amf_app().error(
        "%s : %s, using defaults", nfex.what(), nfex.getPath());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
675
    return RETURNerror;
dukl's avatar
dukl committed
676
  }
677

678
  return 1;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
679
}
dukl's avatar
dukl committed
680

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
681 682
//------------------------------------------------------------------------------
void amf_config::display() {
683 684
  Logger::config().info(
      "==== OAI-CN5G %s v%s ====", PACKAGE_NAME, PACKAGE_VERSION);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
685 686
  Logger::config().info(
      "======================    AMF   =====================");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
687
  Logger::config().info("Configuration AMF:");
688 689
  Logger::config().info("- Instance ................: %d", instance);
  Logger::config().info("- PID dir .................: %s", pid_dir.c_str());
690
  Logger::config().info("- AMF NAME.................: %s", amf_name.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
691 692
  Logger::config().info(
      "- GUAMI (MCC, MNC, Region ID, AMF Set ID, AMF pointer): ");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
693
  Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
694
      "    (%s, %s, %s, %s, %s)", guami.mcc.c_str(), guami.mnc.c_str(),
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
695
      guami.regionID.c_str(), guami.AmfSetID.c_str(), guami.AmfPointer.c_str());
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
696
  Logger::config().info("- Served Guami List:");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
697
  for (int i = 0; i < guami_list.size(); i++) {
698
    Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
699
        "    (%s, %s, %s , %s, %s)", guami_list[i].mcc.c_str(),
700 701
        guami_list[i].mnc.c_str(), guami_list[i].regionID.c_str(),
        guami_list[i].AmfSetID.c_str(), guami_list[i].AmfPointer.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
702
  }
703 704
  Logger::config().info(
      "- Relative Capacity .......: %d", relative_amf_capacity);
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
705
  Logger::config().info("- PLMN Support: ");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
706
  for (int i = 0; i < plmn_list.size(); i++) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
707
    Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
708
        "    MCC, MNC ..............: %s, %s", plmn_list[i].mcc.c_str(),
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
709
        plmn_list[i].mnc.c_str());
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
710 711
    Logger::config().info("    TAC ...................: %d", plmn_list[i].tac);
    Logger::config().info("    Slice Support .........:");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
712
    for (int j = 0; j < plmn_list[i].slice_list.size(); j++) {
713 714 715 716 717 718 719 720 721
      if (plmn_list[i].slice_list[j].sd != SD_NO_VALUE) {
        Logger::config().info(
            "        SST, SD ...........: %d, %ld (0x%x)",
            plmn_list[i].slice_list[j].sst, plmn_list[i].slice_list[j].sd,
            plmn_list[i].slice_list[j].sd);
      } else {
        Logger::config().info(
            "        SST ...............: %d", plmn_list[i].slice_list[j].sst);
      }
dukl's avatar
dukl committed
722
    }
dukl's avatar
dukl committed
723
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
724
  Logger::config().info(
725
      "- Emergency Support .......: %s", is_emergency_support.c_str());
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
726

727
  Logger::config().info("- Database: ");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
728
  Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
729
      "    MySQL Server Addr .....: %s", auth_para.mysql_server.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
730
  Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
731
      "    MySQL user ............: %s", auth_para.mysql_user.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
732
  Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
733
      "    MySQL pass ............: %s", auth_para.mysql_pass.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
734
  Logger::config().info(
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
735
      "    MySQL DB ..............: %s", auth_para.mysql_db.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
736

737 738 739 740 741 742 743 744 745 746 747 748 749
  // TODO:
  /*
    Logger::config().info("- Supported NAS Algorithm: ");
    Logger::config().info(
        "    Integrity Algorithm ...: %s","");
    Logger::config().info(
        "    Ciphering Algorithm ...: %s", "");

    st::string nas_itegrity_algorithm_list = {};
    for(auto s: nas_cfg.prefered_integrity_algorithm){
    }
  */

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
750
  Logger::config().info("- N2 Networking:");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
751 752 753
  Logger::config().info("    Iface .................: %s", n2.if_name.c_str());
  Logger::config().info("    IP Addr ...............: %s", inet_ntoa(n2.addr4));
  Logger::config().info("    Port ..................: %d", n2.port);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
754

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
755
  Logger::config().info("- SBI Networking:");
756
  Logger::config().info("    Iface .................: %s", sbi.if_name.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
757
  Logger::config().info(
758 759
      "    IP Addr ...............: %s", inet_ntoa(sbi.addr4));
  Logger::config().info("    Port ..................: %d", sbi.port);
760
  Logger::config().info("    HTTP2 port ............: %d", sbi_http2_port);
761 762
  Logger::config().info(
      "    API version............: %s", sbi_api_version.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
763

764
  if (support_features.enable_external_nrf) {
765 766
    Logger::config().info("- NRF:");
    Logger::config().info(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
767
        "    IP Addr ...............: %s", inet_ntoa(nrf_addr.ipv4_addr));
768
    Logger::config().info("    Port ..................: %d", nrf_addr.port);
769
    Logger::config().info(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
770
        "    API version ...........: %s", nrf_addr.api_version.c_str());
771 772
  }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
773
  if (support_features.enable_external_nssf) {
774 775 776 777 778 779 780 781
    Logger::config().info("- NSSF:");
    Logger::config().info(
        "    IP Addr ...............: %s", inet_ntoa(nssf_addr.ipv4_addr));
    Logger::config().info("    Port ..................: %d", nssf_addr.port);
    Logger::config().info(
        "    API version ...........: %s", nssf_addr.api_version.c_str());
  }

782
  if (support_features.enable_external_ausf) {
783 784
    Logger::config().info("- AUSF:");
    Logger::config().info(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
785
        "    IP Addr ...............: %s", inet_ntoa(ausf_addr.ipv4_addr));
786
    Logger::config().info("    Port ..................: %d", ausf_addr.port);
787
    Logger::config().info(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
788
        "    API version ...........: %s", ausf_addr.api_version.c_str());
789 790
  }

791 792 793 794 795 796 797 798 799
  if (support_features.enable_external_udm) {
    Logger::config().info("- UDM:");
    Logger::config().info(
        "    IP Addr ...............: %s", inet_ntoa(udm_addr.ipv4_addr));
    Logger::config().info("    Port ..................: %d", udm_addr.port);
    Logger::config().info(
        "    API version ...........: %s", udm_addr.api_version.c_str());
  }

800
  if (!support_features.enable_smf_selection) {
Tien Thinh NGUYEN's avatar
Tien Thinh NGUYEN committed
801
    Logger::config().info("- SMF Pool: ");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
802
    for (int i = 0; i < smf_pool.size(); i++) {
803
      std::string selected = smf_pool[i].selected ? "true" : "false";
804 805 806
      std::string smf_info = support_features.use_fqdn_dns ?
                                 smf_pool[i].fqdn :
                                 smf_pool[i].ipv4.c_str();
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
807 808
      Logger::config().info(
          "    SMF_INSTANCE_ID %d (%s:%s, version %s) is selected: %s",
809
          smf_pool[i].id, smf_info.c_str(), smf_pool[i].port.c_str(),
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
810 811
          smf_pool[i].version.c_str(), selected.c_str());
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
812
  }
813 814

  Logger::config().info("- Supported Features:");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
815
  Logger::config().info(
816 817
      "    NF Registration .......: %s",
      support_features.enable_nf_registration ? "Yes" : "No");
818 819 820
  Logger::config().info(
      "    NRF Selection .........: %s",
      support_features.enable_nrf_selection ? "Yes" : "No");
821 822 823
  Logger::config().info(
      "    SMF Selection .........: %s",
      support_features.enable_smf_selection ? "Yes" : "No");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
824 825 826
  Logger::config().info(
      "    External NRF ..........: %s",
      support_features.enable_external_nrf ? "Yes" : "No");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
827
  Logger::config().info(
828 829
      "    External AUSF .........: %s",
      support_features.enable_external_ausf ? "Yes" : "No");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
830
  Logger::config().info(
831 832
      "    External UDM ..........: %s",
      support_features.enable_external_udm ? "Yes" : "No");
833 834 835
  Logger::config().info(
      "    External NSSF .........: %s",
      support_features.enable_external_nssf ? "Yes" : "No");
836
  Logger::config().info(
837 838
      "    Use FQDN ..............: %s",
      support_features.use_fqdn_dns ? "Yes" : "No");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
839
  Logger::config().info(
840 841
      "    Use HTTP2..............: %s",
      support_features.use_http2 ? "Yes" : "No");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
842
}
dukl's avatar
dukl committed
843

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
844
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
845 846
int amf_config::load_interface(
    const libconfig::Setting& if_cfg, interface_cfg_t& cfg) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
847 848 849
  if_cfg.lookupValue(AMF_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
  util::trim(cfg.if_name);
  if (not boost::iequals(cfg.if_name, "none")) {
850
    std::string address = {};
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
851 852 853
    if_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
    util::trim(address);
    if (boost::iequals(address, "read")) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
854 855
      if (get_inet_addr_infos_from_iface(
              cfg.if_name, cfg.addr4, cfg.network4, cfg.mtu)) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
856 857
        Logger::amf_app().error(
            "Could not read %s network interface configuration", cfg.if_name);
858
        return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
859 860
      }
    } else {
861
      std::vector<std::string> words;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
862 863
      boost::split(
          words, address, boost::is_any_of("/"), boost::token_compress_on);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
864
      if (words.size() != 2) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
865 866 867
        Logger::amf_app().error(
            "Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file",
            address.c_str());
868
        return RETURNerror;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
869 870
      }
      unsigned char buf_in_addr[sizeof(struct in6_addr)];  // you never know...
871 872
      if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr) ==
          1) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
873
        memcpy(&cfg.addr4, buf_in_addr, sizeof(struct in_addr));
dukl's avatar
dukl committed
874
      } else {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
875
        Logger::amf_app().error(
876 877
            "In conversion: Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS
            " = %s in config file",
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
878
            util::trim(words.at(0)).c_str());
879
        return RETURNerror;
dukl's avatar
dukl committed
880
      }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
881 882 883
      cfg.network4.s_addr = htons(
          ntohs(cfg.addr4.s_addr) &
          0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
884
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
885
    if_cfg.lookupValue(AMF_CONFIG_STRING_PORT, cfg.port);
dukl's avatar
dukl committed
886
  }
887
  return RETURNok;
dukl's avatar
dukl committed
888 889
}

890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
//------------------------------------------------------------------------------
bool amf_config::resolve_fqdn(
    const std::string& fqdn, struct in_addr& ipv4_addr) {
  uint8_t addr_type = {};
  unsigned int port = 0;
  string address    = {};

  fqdn::resolve(fqdn, address, port, addr_type);
  if (addr_type != 0) {  // IPv6: TODO
    Logger::amf_app().error("DO NOT SUPPORT IPV6 ADDR FOR THIS NF");
    return false;
  } else {  // IPv4
    if (inet_aton(util::trim(address).c_str(), &ipv4_addr) <= 0) return false;
    //    IPV4_STR_ADDR_TO_INADDR(
    //        util::trim(address).c_str(), ipv4_addr,
    //        "BAD IPv4 ADDRESS FORMAT FOR NF !");
  }
  return true;
}

910 911 912 913 914 915 916
//------------------------------------------------------------------------------
std::string amf_config::get_amf_n1n2_message_subscribe_uri(
    const std::string& ue_cxt_id) {
  unsigned int sbi_port = 80;
  if (support_features.use_http2) {
    sbi_port = sbi_http2_port;
  } else {
917
    sbi_port = sbi.port;
918
  }
919
  return std::string(inet_ntoa(*((struct in_addr*) &sbi.addr4))) + ":" +
920 921 922 923
         std::to_string(sbi_port) + NAMF_COMMUNICATION_BASE + sbi_api_version +
         "/ue-contexts/" + ue_cxt_id + "/n1-n2-messages/subscriptions";
}

924 925 926 927 928 929 930
//------------------------------------------------------------------------------
std::string amf_config::get_nrf_nf_discovery_service_uri() {
  return std::string(inet_ntoa(*((struct in_addr*) &nrf_addr.ipv4_addr))) +
         ":" + std::to_string(nrf_addr.port) + "/nnrf-disc/" +
         nrf_addr.api_version + "/nf-instances";
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
931 932 933 934 935 936 937 938
//------------------------------------------------------------------------------
std::string amf_config::get_nrf_nf_registration_uri(
    const std::string& nf_instance_id) {
  return std::string(inet_ntoa(*((struct in_addr*) &nrf_addr.ipv4_addr))) +
         ":" + std::to_string(nrf_addr.port) + "/nnrf-nfm/" +
         nrf_addr.api_version + "/nf-instances/" + nf_instance_id;
}

939 940 941 942 943 944 945
//------------------------------------------------------------------------------
std::string amf_config::get_udm_slice_selection_subscription_data_retrieval_uri(
    const std::string& supi) {
  return std::string(inet_ntoa(*((struct in_addr*) &udm_addr.ipv4_addr))) +
         ":" + std::to_string(udm_addr.port) + "/nudm-sdm/" +
         udm_addr.api_version + "/" + supi + "/nssai";
}
946 947 948 949 950 951 952

//------------------------------------------------------------------------------
std::string amf_config::get_nssf_network_slice_selection_information_uri() {
  return std::string(inet_ntoa(*((struct in_addr*) &nssf_addr.ipv4_addr))) +
         ":" + std::to_string(nssf_addr.port) + "/nnssf-nsselection/" +
         nssf_addr.api_version + "/network-slice-information";
}
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
953

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
954 955 956 957 958 959 960
//------------------------------------------------------------------------------
std::string amf_config::get_ausf_ue_authentications_uri() {
  return std::string(inet_ntoa(*((struct in_addr*) &ausf_addr.ipv4_addr))) +
         ":" + std::to_string(ausf_addr.port) + "/nausf-auth/" +
         ausf_addr.api_version + "/ue-authentications";
}

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
//------------------------------------------------------------------------------
bool amf_config::get_smf_pdu_session_context_uri(
    const std::shared_ptr<pdu_session_context>& psc, std::string& smf_uri) {
  if (!psc) return false;

  if (!psc.get()->smf_info.info_available) {
    Logger::amf_sbi().error("No SMF is available for this PDU session");
    return false;
  }

  std::string smf_addr    = {};
  std::string smf_port    = {};
  std::string smf_ip_addr = {};

  smf_addr = psc->smf_info.addr;
  smf_port = psc->smf_info.port;

  // remove http port from the URI if existed
  std::size_t found_port = smf_addr.find(":");
  if (found_port != std::string::npos)
    smf_ip_addr = smf_addr.substr(0, found_port - 1);
  else
    smf_ip_addr = smf_addr;

  std::size_t found = psc.get()->smf_info.context_location.find(smf_ip_addr);
  if (found != std::string::npos)
    smf_uri = psc.get()->smf_info.context_location;
  else
    smf_uri = smf_addr + ":" + smf_port + psc.get()->smf_info.context_location;
  return true;
}

//------------------------------------------------------------------------------
std::string amf_config::get_smf_pdu_session_base_uri(
    const std::string& smf_addr, const std::string& smf_port,
    const std::string& smf_api_version) {
  // Remove http port from the URI if existed
  std::string smf_ip_addr = {};
  std::size_t found_port  = smf_addr.find(":");
  if (found_port != std::string::npos)
    smf_ip_addr = smf_addr.substr(0, found_port);
  else
    smf_ip_addr = smf_addr;

  return smf_ip_addr + ":" + smf_port + "/nsmf-pdusession/" + smf_api_version +
         NSMF_PDU_SESSION_CREATE;
}

1009 1010 1011 1012
//------------------------------------------------------------------------------
void amf_config::to_json(nlohmann::json& json_data) const {
  json_data["instance"]   = instance;
  json_data["pid_dir"]    = pid_dir;
1013
  json_data["amf_name"]   = amf_name;
1014 1015 1016 1017 1018 1019
  json_data["guami"]      = guami.to_json();
  json_data["guami_list"] = nlohmann::json::array();
  for (auto s : guami_list) {
    json_data["guami_list"].push_back(s.to_json());
  }

1020
  json_data["relative_amf_capacity"] = relative_amf_capacity;
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

  json_data["plmn_list"] = nlohmann::json::array();
  for (auto s : plmn_list) {
    json_data["plmn_list"].push_back(s.to_json());
  }
  json_data["is_emergency_support"] = is_emergency_support;

  json_data["auth_para"] = auth_para.to_json();

  json_data["n2"]                    = n2.to_json();
1031 1032
  json_data["sbi"]                   = sbi.to_json();
  json_data["sbi"]["sbi_http2_port"] = sbi_http2_port;
1033 1034 1035 1036 1037 1038 1039 1040

  json_data["support_features"] = support_features.to_json();

  if (support_features.enable_external_nrf) {
    json_data["nrf"] = nrf_addr.to_json();
  }

  if (support_features.enable_external_nssf) {
1041
    json_data["nssf"] = nssf_addr.to_json();
1042 1043 1044
  }

  if (support_features.enable_external_ausf) {
1045
    json_data["ausf"] = ausf_addr.to_json();
1046 1047 1048
  }

  if (support_features.enable_external_udm) {
1049
    json_data["udm"] = udm_addr.to_json();
1050 1051 1052 1053 1054 1055 1056
  }

  json_data["smf_pool"] = nlohmann::json::array();
  for (auto s : smf_pool) {
    json_data["smf_pool"].push_back(s.to_json());
  }
}
1057

1058
//------------------------------------------------------------------------------
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
bool amf_config::from_json(nlohmann::json& json_data) {
  try {
    if (json_data.find("instance") != json_data.end()) {
      instance = json_data["instance"].get<int>();
    }

    if (json_data.find("pid_dir") != json_data.end()) {
      pid_dir = json_data["pid_dir"].get<std::string>();
    }
    if (json_data.find("amf_name") != json_data.end()) {
1069
      amf_name = json_data["amf_name"].get<std::string>();
1070 1071 1072 1073 1074 1075
    }
    if (json_data.find("guami") != json_data.end()) {
      guami.from_json(json_data["guami"]);
    }

    if (json_data.find("guami_list") != json_data.end()) {
1076
      guami_list.clear();
1077 1078 1079 1080 1081 1082 1083
      for (auto s : json_data["guami_list"]) {
        guami_t g = {};
        g.from_json(s);
        guami_list.push_back(g);
      }
    }

1084 1085
    if (json_data.find("relative_amf_capacity") != json_data.end()) {
      relative_amf_capacity = json_data["relative_amf_capacity"].get<int>();
1086 1087 1088
    }

    if (json_data.find("plmn_list") != json_data.end()) {
1089
      plmn_list.clear();
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
      for (auto s : json_data["plmn_list"]) {
        plmn_item_t p = {};
        p.from_json(s);
        plmn_list.push_back(p);
      }
    }

    if (json_data.find("is_emergency_support") != json_data.end()) {
      is_emergency_support =
          json_data["is_emergency_support"].get<std::string>();
    }

1102
    if (json_data.find("auth_para") != json_data.end()) {
1103 1104 1105 1106 1107 1108
      auth_para.from_json(json_data["auth_para"]);
    }

    if (json_data.find("n2") != json_data.end()) {
      n2.from_json(json_data["n2"]);
    }
1109 1110
    if (json_data.find("sbi") != json_data.end()) {
      sbi.from_json(json_data["sbi"]);
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
    }

    if (json_data.find("sbi_http2_port") != json_data.end()) {
      sbi_http2_port = json_data["sbi_http2_port"].get<int>();
    }

    if (json_data.find("support_features") != json_data.end()) {
      support_features.from_json(json_data["support_features"]);
    }

    if (support_features.enable_external_nrf) {
      if (json_data.find("nrf") != json_data.end()) {
        nrf_addr.from_json(json_data["nrf"]);
1124 1125 1126 1127
        // if use FQDN -> update IP addr accordingly
        if (support_features.use_fqdn_dns) {
          resolve_fqdn(nrf_addr.fqdn, nrf_addr.ipv4_addr);
        }
1128 1129 1130 1131 1132 1133
      }
    }

    if (support_features.enable_external_nssf) {
      if (json_data.find("nssf") != json_data.end()) {
        nssf_addr.from_json(json_data["nssf"]);
1134 1135 1136 1137
        // if use FQDN -> update IP addr accordingly
        if (support_features.use_fqdn_dns) {
          resolve_fqdn(nssf_addr.fqdn, nssf_addr.ipv4_addr);
        }
1138 1139 1140 1141 1142 1143
      }
    }

    if (support_features.enable_external_ausf) {
      if (json_data.find("ausf") != json_data.end()) {
        ausf_addr.from_json(json_data["ausf"]);
1144 1145 1146 1147
        // if use FQDN -> update IP addr accordingly
        if (support_features.use_fqdn_dns) {
          resolve_fqdn(ausf_addr.fqdn, ausf_addr.ipv4_addr);
        }
1148 1149 1150 1151 1152 1153
      }
    }

    if (support_features.enable_external_udm) {
      if (json_data.find("udm") != json_data.end()) {
        udm_addr.from_json(json_data["udm"]);
1154 1155 1156 1157
        // if use FQDN -> update IP addr accordingly
        if (support_features.use_fqdn_dns) {
          resolve_fqdn(udm_addr.fqdn, udm_addr.ipv4_addr);
        }
1158 1159 1160 1161
      }
    }

    if (json_data.find("smf_pool") != json_data.end()) {
1162
      smf_pool.clear();
1163
      for (auto s : json_data["smf_pool"]) {
1164 1165
        smf_inst_t smf_item      = {};
        struct in_addr ipv4_addr = {};
1166
        smf_item.from_json(s);
1167 1168 1169 1170 1171
        // if use FQDN -> update IP addr accordingly
        if (support_features.use_fqdn_dns) {
          resolve_fqdn(smf_item.fqdn, ipv4_addr);
          smf_item.ipv4 = inet_ntoa(ipv4_addr);
        }
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
        smf_pool.push_back(smf_item);
      }
    }

  } catch (nlohmann::detail::exception& e) {
    Logger::amf_app().error(
        "Exception when reading configuration from json %s", e.what());
    return false;
  } catch (std::exception& e) {
    Logger::amf_app().error(
        "Exception when reading configuration from json %s", e.what());
    return false;
  }

  return true;
}
1188
}  // namespace config