N1N2MessageCollectionDocumentApiImpl.cpp 4.89 KB
Newer Older
dukl's avatar
dukl committed
1
/**
2 3 4 5 6 7 8 9 10 11 12
 * Namf_Communication
 * AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS,
 * CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 1.1.0.alpha-1
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */
dukl's avatar
dukl committed
13 14

#include "N1N2MessageCollectionDocumentApiImpl.h"
dukl's avatar
dukl committed
15 16
#include "itti.hpp"

17
#include "amf_app.hpp"
18
#include "amf_sbi.hpp"
dukl's avatar
dukl committed
19
#include "pdu_session_context.hpp"
20 21 22
#include "conversions.hpp"
#include "comUt.hpp"

dukl's avatar
dukl committed
23 24
using namespace amf_application;

25 26
extern itti_mw* itti_inst;
extern amf_app* amf_app_inst;
dukl's avatar
dukl committed
27 28 29 30 31 32 33

namespace oai {
namespace amf {
namespace api {

using namespace oai::amf::model;

34 35 36 37
N1N2MessageCollectionDocumentApiImpl::N1N2MessageCollectionDocumentApiImpl(
    std::shared_ptr<Pistache::Rest::Router> rtr,
    amf_application::amf_app* amf_app_inst)
    : N1N2MessageCollectionDocumentApi(rtr), m_amf_app(amf_app_inst) {}
dukl's avatar
dukl committed
38

39 40 41 42
void N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer(
    const std::string& ueContextId,
    const N1N2MessageTransferReqData& n1N2MessageTransferReqData,
    Pistache::Http::ResponseWriter& response) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
43
  Logger::amf_server().debug("Response OK");
44 45 46 47
  response.send(
      Pistache::Http::Code::Ok,
      "N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer API has "
      "not been implemented yet!");
dukl's avatar
dukl committed
48 49
}

50 51 52 53 54 55
void N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer(
    const std::string& ueContextId,
    const N1N2MessageTransferReqData& n1N2MessageTransferReqData,
    std::string& n1sm_str, Pistache::Http::ResponseWriter& response) {
  Logger::amf_server().debug(
      "Receive N1N2MessageTransfer Request, handling...");
dukl's avatar
dukl committed
56 57

  bstring n1sm;
58 59
  conv::msg_str_2_msg_hex(n1sm_str, n1sm);
  comUt::print_buffer(
60 61 62 63 64
      "amf_server", "Received N1 SM", (uint8_t*) bdata(n1sm), blength(n1sm));
  response.send(
      Pistache::Http::Code::Ok,
      "N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer API has "
      "not been implemented yet!");
dukl's avatar
dukl committed
65 66
}

67 68 69 70 71 72 73
void N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer(
    const std::string& ueContextId,
    const N1N2MessageTransferReqData& n1N2MessageTransferReqData,
    std::string& n1sm_str, std::string& n2sm_str,
    Pistache::Http::ResponseWriter& response) {
  Logger::amf_server().debug(
      "Receive N1N2MessageTransfer Request, handling...");
74 75 76 77 78

  nlohmann::json response_json = {};
  response_json["cause"] =
      n1_n2_message_transfer_cause_e2str[N1_N2_TRANSFER_INITIATED];
  Pistache::Http::Code code = Pistache::Http::Code::Ok;
dukl's avatar
dukl committed
79

80
  std::string supi = ueContextId;
81 82
  Logger::amf_server().debug(
      "Key for PDU Session context: SUPI (%s)", supi.c_str());
dukl's avatar
dukl committed
83
  std::shared_ptr<pdu_session_context> psc;
84

85 86 87 88
  if (!amf_app_inst->find_pdu_session_context(
          supi, (uint8_t) n1N2MessageTransferReqData.getPduSessionId(), psc)) {
    Logger::amf_server().error(
        "Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
dukl's avatar
dukl committed
89
  }
90

dukl's avatar
dukl committed
91
  bstring n1sm;
92
  conv::msg_str_2_msg_hex(
93 94
      n1sm_str.substr(0, n1sm_str.length()), n1sm);  // TODO: verify n1sm_length

dukl's avatar
dukl committed
95
  bstring n2sm;
96
  conv::msg_str_2_msg_hex(n2sm_str, n2sm);
97 98

  psc.get()->n1sm             = n1sm;
99
  psc.get()->isn1sm_avaliable = true;
100
  psc.get()->n2sm             = n2sm;
101
  psc.get()->isn2sm_avaliable = true;
102 103
  Logger::amf_server().debug(
      "n2sm size in amf_server(%d)", blength(psc.get()->n2sm));
dukl's avatar
dukl committed
104

105 106 107 108
  itti_n1n2_message_transfer_request* itti_msg =
      new itti_n1n2_message_transfer_request(AMF_SERVER, TASK_AMF_APP);
  itti_msg->supi        = ueContextId;
  itti_msg->n1sm        = n1sm;
dukl's avatar
dukl committed
109
  itti_msg->is_n1sm_set = true;
110
  itti_msg->n2sm        = n2sm;
dukl's avatar
dukl committed
111
  itti_msg->is_n2sm_set = true;
112 113
  itti_msg->pdu_session_id =
      (uint8_t) n1N2MessageTransferReqData.getPduSessionId();
114 115 116 117 118
  itti_msg->n2sm_info_type = n1N2MessageTransferReqData.getN2InfoContainer()
                                 .getSmInfo()
                                 .getN2InfoContent()
                                 .getNgapIeType()
                                 .get_value();
119 120 121 122 123 124 125 126

  // For Paging
  if (n1N2MessageTransferReqData.ppiIsSet()) {
    itti_msg->is_ppi_set = true;
    itti_msg->ppi        = n1N2MessageTransferReqData.getPpi();
    response_json["cause"] =
        n1_n2_message_transfer_cause_e2str[ATTEMPTING_TO_REACH_UE];
    code = Pistache::Http::Code::Accepted;
127 128
  } else {
    itti_msg->is_ppi_set = false;
129 130 131 132 133 134
  }

  // Send response to the NF Service Consumer (e.g., SMF)
  response.send(code, response_json.dump().c_str());

  // Process N1N2 Message Transfer Request
135 136
  std::shared_ptr<itti_n1n2_message_transfer_request> i =
      std::shared_ptr<itti_n1n2_message_transfer_request>(itti_msg);
dukl's avatar
dukl committed
137 138
  int ret = itti_inst->send_msg(i);
  if (0 != ret) {
139 140 141
    Logger::amf_server().error(
        "Could not send ITTI message %s to task TASK_AMF_N2",
        i->get_msg_name());
dukl's avatar
dukl committed
142
  }
dukl's avatar
dukl committed
143 144
}

145 146 147
}  // namespace api
}  // namespace amf
}  // namespace oai