smf.h 10.9 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
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
7
8
 * 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
 *
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
10
 *      http://www.openairinterface.org/?page_id=698
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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
 */

#ifndef FILE_SMF_SEEN
#define FILE_SMF_SEEN

25
26
27
28
#include "3gpp_29.274.h"
#include "3gpp_29.571.h"
#include "3gpp_24.501.h"
#include <nlohmann/json.hpp>
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
29
30

typedef uint64_t supi64_t;
31
#define SUPI_64_FMT "%" SCNu64
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
32
33
34
35
36
37
38
39

#define SUPI_DIGITS_MAX 15

typedef struct {
  uint32_t length;
  char data[SUPI_DIGITS_MAX + 1];
} supi_t;

40
41
static void smf_string_to_supi(supi_t* const supi, char const* const supi_str) {
  // strncpy(supi->data, supi_str, SUPI_DIGITS_MAX + 1);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
42
43
44
  memcpy((void*) supi->data, (void*) supi_str, SUPI_DIGITS_MAX + 1);
  supi->length = strlen(supi->data);
  return;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
45
46
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
47
48
49
50
static std::string smf_supi_to_string(supi_t const supi) {
  std::string supi_str;
  supi_str.assign(supi.data, SUPI_DIGITS_MAX + 1);
  return supi_str;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
51
}
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
52

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
53
static uint64_t smf_supi_to_u64(supi_t supi) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
54
55
56
57
58
  uint64_t uint_supi;
  sscanf(supi.data, "%" SCNu64, &uint_supi);
  return uint_supi;
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
59
typedef struct s_nssai  // section 28.4, TS23.003
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
60
{
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
61
  uint8_t sST;
62
  // uint32_t sD:24;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
63
  std::string sD;
64
65
66
67
68
  // s_nssai(const uint8_t& sst,  const uint32_t sd) : sST(sst), sD(sd) {}
  s_nssai(const uint8_t& sst, const std::string sd) : sST(sst), sD(sd) {}
  s_nssai() : sST(), sD() {}
  s_nssai(const s_nssai& p) : sST(p.sST), sD(p.sD) {}
  bool operator==(const struct s_nssai& s) const {
69
70
71
72
73
74
    if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) {
      return true;
    } else {
      return false;
    }
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
75
76
77
78
79

} snssai_t;

typedef uint8_t pdu_session_id;

80
// SMF + AMF + 3GPP TS 29.571 (Common data)
81
enum class http_response_codes_e {
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  HTTP_RESPONSE_CODE_OK                     = 200,
  HTTP_RESPONSE_CODE_CREATED                = 201,
  HTTP_RESPONSE_CODE_ACCEPTED               = 202,
  HTTP_RESPONSE_CODE_NO_CONTENT             = 204,
  HTTP_RESPONSE_CODE_BAD_REQUEST            = 400,
  HTTP_RESPONSE_CODE_UNAUTHORIZED           = 401,
  HTTP_RESPONSE_CODE_FORBIDDEN              = 403,
  HTTP_RESPONSE_CODE_NOT_FOUND              = 404,
  HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED     = 405,
  HTTP_RESPONSE_CODE_REQUEST_TIMEOUT        = 408,
  HTTP_RESPONSE_CODE_406_NOT_ACCEPTED       = 406,
  HTTP_RESPONSE_CODE_CONFLICT               = 409,
  HTTP_RESPONSE_CODE_GONE                   = 410,
  HTTP_RESPONSE_CODE_LENGTH_REQUIRED        = 411,
  HTTP_RESPONSE_CODE_PRECONDITION_FAILED    = 412,
  HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE      = 413,
  HTTP_RESPONSE_CODE_URI_TOO_LONG           = 414,
99
  HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
100
101
102
103
104
  HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS      = 429,
  HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR  = 500,
  HTTP_RESPONSE_CODE_NOT_IMPLEMENTED        = 501,
  HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE    = 503,
  HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT        = 504
105
106
107

};

108
// From 23.502
109
enum class session_management_procedures_type_e {
110
111
112
113
114
  PROCEDURE_TYPE_UNKNOWN                      = 0,
  PDU_SESSION_ESTABLISHMENT_UE_REQUESTED      = 1,
  SERVICE_REQUEST_UE_TRIGGERED_STEP1          = 2,
  SERVICE_REQUEST_UE_TRIGGERED_STEP2          = 3,
  SERVICE_REQUEST_NETWORK_TRIGGERED           = 4,
115
116
117
  PDU_SESSION_MODIFICATION_UE_INITIATED_STEP1 = 5,
  PDU_SESSION_MODIFICATION_UE_INITIATED_STEP2 = 6,
  PDU_SESSION_MODIFICATION_UE_INITIATED_STEP3 = 7,
118
119
120
121
122
123
124
125
  PDU_SESSION_MODIFICATION_SMF_REQUESTED      = 8,
  PDU_SESSION_MODIFICATION_AN_REQUESTED       = 9,
  PDU_SESSION_RELEASE_UE_REQUESTED_STEP1      = 10,
  PDU_SESSION_RELEASE_UE_REQUESTED_STEP2      = 11,
  PDU_SESSION_RELEASE_UE_REQUESTED_STEP3      = 12,
  PDU_SESSION_RELEASE_SMF_INITIATED           = 13,
  PDU_SESSION_RELEASE_AMF_INITIATED           = 14,
  PDU_SESSION_RELEASE_AN_INITIATED            = 15,
126
  HO_PATH_SWITCH_REQ                          = 16,
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
127
128
129
  N2_HO_PREPARATION_PHASE_STEP1               = 17,
  N2_HO_PREPARATION_PHASE_STEP2               = 18,
  N2_HO_EXECUTION_PHASE                       = 19,
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
130
131
  N2_HO_CANCELLATION_PHASE                    = 20,
  PDU_SESSION_TEST                            = 21
132
133
};

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
134
static const std::vector<std::string> session_management_procedures_type_e2str =
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
135
136
    {"PROCEDURE_TYPE_UNKNOWN",
     "PDU_SESSION_ESTABLISHMENT_UE_REQUESTED",
137
138
139
140
141
142
143
144
145
146
147
148
149
150
     "SERVICE_REQUEST_UE_TRIGGERED_STEP1",
     "SERVICE_REQUEST_UE_TRIGGERED_STEP2",
     "SERVICE_REQUEST_NETWORK_TRIGGERED",
     "PDU_SESSION_MODIFICATION_UE_INITIATED_STEP1",
     "PDU_SESSION_MODIFICATION_UE_INITIATED_STEP2",
     "PDU_SESSION_MODIFICATION_UE_INITIATED_STEP3",
     "PDU_SESSION_MODIFICATION_SMF_REQUESTED",
     "PDU_SESSION_MODIFICATION_AN_REQUESTED",
     "PDU_SESSION_RELEASE_UE_REQUESTED_STEP1",
     "PDU_SESSION_RELEASE_UE_REQUESTED_STEP2",
     "PDU_SESSION_RELEASE_UE_REQUESTED_STEP3",
     "PDU_SESSION_RELEASE_SMF_INITIATED",
     "PDU_SESSION_RELEASE_AMF_INITIATED",
     "PDU_SESSION_RELEASE_AN_INITIATED",
151
     "HO_PATH_SWITCH_REQ",
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
152
153
154
     "N2_HO_PREPARATION_PHASE_STEP1",
     "N2_HO_PREPARATION_PHASE_STEP2",
     "N2_HO_EXECUTION_PHASE",
155
156
157
     "PDU_SESSION_TEST"

};
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
158

159
enum class sm_context_status_e {
160
  SM_CONTEXT_STATUS_ACTIVE   = 0,
161
162
163
  SM_CONTEXT_STATUS_RELEASED = 1
};

164
165
static const std::vector<std::string> sm_context_status_e2str = {"ACTIVE",
                                                                 "RELEASED"};
166

167
typedef struct qos_profile_gbr_s {
168
  gfbr_t gfbr;  // Guaranteed Flow Bit Rate
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
169
  mfbr_t mfbr;  // Maximum Flow Bit Rate
170
171
172
173
  // Notification Control
  // Maximum Packet Loss Rate (UL/DL)
} qos_profile_gbr_t;

174
enum class qos_profile_type_e { NON_GBR = 0, GBR = 1 };
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
175

176
// See Section 5.7.2@3GPP TS 23.501
177
178
179
typedef struct qos_profile_s {
  uint8_t _5qi;
  arp_5gc_t arp;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
180
181
  uint8_t priority_level;
  qos_profile_type_e profile_type;
182
  union {
183
184
    reflective_qos_attribute_e rqa;     // Reflective QoS Attribute (RQA)
    qos_profile_gbr_t qos_profile_gbr;  // Attributes for GBR
185
  } parameter;
186
187
} qos_profile_t;

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// URL, N1, N2 (may get from configuration file)
#define NAMF_COMMUNICATION_BASE "/namf-comm/"
#define NAMF_COMMUNICATION_N1N2_MESSAGE_TRANSFER_URL                           \
  "/ue-contexts/{}/n1-n2-messages"  // context id
#define NUDM_SDM_BASE "/nudm-sdm/"
#define NUDM_SDM_GET_SM_DATA_URL "/{}/sm-data"  // ue Id
#define N1_SM_CONTENT_ID "n1SmMsg"
#define N1N2_MESSAGE_CLASS "SM"
#define N2_SM_CONTENT_ID "n2msg"
#define NSMF_PDU_SESSION_BASE "/nsmf-pdusession/"
#define NSMF_CALLBACK_N1N2_MESSAGE_TRANSFER_FAILURE                            \
  "/callback/N1N2MsgTxfrFailureNotification/{}"  // UE Id
#define NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL "/sm-contexts"
#define NSMF_PDU_SESSION_SM_CONTEXT_UPDATE_URL "/sm-contexts/"

// NRF
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_NF_REGISTER_URL "/nf-instances/"
206
#define NNRF_NF_STATUS_SUBSCRIBE_URL "/subscriptions"
207

208
// for CURL
209
210
#define NF_CURL_TIMEOUT_MS 100L
#define MAX_WAIT_MSECS 10000  // 1 second
211
#define AMF_NUMBER_RETRIES 3
212
#define UDM_NUMBER_RETRIES 3
213
214
constexpr auto CURL_MIME_BOUNDARY = "----Boundary";

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
215
// for N1N2
216
#define BUF_LEN 512
217

218
219
220
// FOR FUTURE PROMISE
#define FUTURE_STATUS_TIMEOUT_MS 100

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
221
// for PFCP
222
constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
223
// 8.22  Fully Qualified TEID (F-TEID) - 3GPP TS 29.274 V16.0.0
224
225
#define TEID_GRE_KEY_LENGTH 4

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
226
#define DEFAULT_QFI 6
227

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
228
229
230
typedef struct dnn_smf_info_item_s {
  std::string dnn;
} dnn_smf_info_item_t;
231

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
232
233
234
235
236
237
238
239
typedef struct snssai_smf_info_item_s {
  snssai_t snssai;
  std::vector<dnn_smf_info_item_t> dnn_smf_info_list;
} snssai_smf_info_item_t;

typedef struct smf_info_s {
  std::vector<snssai_smf_info_item_t> snssai_smf_info_list;
} smf_info_t;
240

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
241
242
243
244
typedef struct nf_service_version_s {
  std::string api_version_in_uri;  // apiVersionInUri
  std::string api_full_version;    // apiFullVersion

245
  nf_service_version_s& operator=(const nf_service_version_s& s) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
246
    api_version_in_uri = s.api_version_in_uri;
247
    api_full_version   = s.api_full_version;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
248
    return *this;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  }

  std::string to_string() const {
    std::string s = {};
    s.append(", Version (");
    s.append("apiVersionInUri: ");
    s.append(api_version_in_uri);
    s.append(", apiFullVersion: ");
    s.append(api_full_version);
    s.append(" )");
    return s;
  }
} nf_service_version_t;

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
263
typedef struct ip_endpoint_s {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
264
  // struct in6_addr  ipv6_address;
265
  struct in_addr ipv4_address;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
266
267
268
269
  std::string transport;  // TCP
  unsigned int port;
  std::string to_string() const {
    std::string s = {};
270
271
    s.append("Ipv4 Address: ");
    s.append(inet_ntoa(ipv4_address));
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
272
273
274
275
276
277
278
279
    s.append(", TransportProtocol: ");
    s.append(transport);
    s.append(", Port: ");
    s.append(std::to_string(port));
    return s;
  }
} ip_endpoint_t;

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
280
281
282
283
284
285
typedef struct nf_service_s {
  std::string service_instance_id;
  std::string service_name;
  std::vector<nf_service_version_t> versions;
  std::string scheme;
  std::string nf_service_status;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
286
  std::vector<ip_endpoint_t> ip_endpoints;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300

  std::string to_string() const {
    std::string s = {};
    s.append("Service Instance ID: ");
    s.append(service_instance_id);
    s.append(", Service name: ");
    s.append(service_name);
    for (auto v : versions) {
      s.append(v.to_string());
    }
    s.append(", Scheme: ");
    s.append(scheme);
    s.append(", Service status: ");
    s.append(nf_service_status);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
301
302
303
304
    s.append(",  IpEndPoints: ");
    for (auto endpoint : ip_endpoints) {
      s.append(endpoint.to_string());
    }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
305
306
307
308
    return s;
  }
} nf_service_t;

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
typedef struct dnn_upf_info_item_s {
  std::string dnn;
  // std::vector<std::string> dnai_list
  // std::vector<std::string> pdu_session_types
} dnn_upf_info_item_t;

typedef struct snssai_upf_info_item_s {
  snssai_t snssai;
  std::vector<dnn_upf_info_item_t> dnn_upf_info_list;
} snssai_upf_info_item_t;

typedef struct upf_info_s {
  std::vector<snssai_upf_info_item_t> snssai_upf_info_list;
} upf_info_t;

typedef struct patch_item_s {
  std::string op;
  std::string path;
  // std::string from;
  std::string value;

  nlohmann::json to_json() const {
    nlohmann::json json_data = {};
    json_data["op"]          = op;
    json_data["path"]        = path;
    json_data["value"]       = value;
    return json_data;
  }
} patch_item_t;

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
339
// TODO: move to 23.003
340
341
342
343
344
typedef struct guami_5g_s {
  plmn_t plmn;
  std::string amf_id;
} guami_5g_t;

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
345
#endif