Commit 0ba67b9f authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

First version to support NG Reset procedure

parent a9bccc48
......@@ -61,6 +61,7 @@ typedef enum {
ASYNC_SHELL_CMD = ITTI_MSG_TYPE_FIRST,
NEW_SCTP_ASSOCIATION,
NG_SETUP_REQ,
NG_RESET,
INITIAL_UE_MSG,
ITTI_UL_NAS_TRANSPORT,
ITTI_DL_NAS_TRANSPORT,
......
......@@ -24,6 +24,7 @@
#include "itti_msg.hpp"
#include "NGSetupRequest.hpp"
#include "NGReset.hpp"
#include "InitialUEMessage.hpp"
#include "UplinkNASTransport.hpp"
#include "UEContextReleaseRequest.hpp"
......@@ -66,6 +67,16 @@ class itti_ng_setup_request : public itti_msg_n2 {
NGSetupRequestMsg* ngSetupReq;
};
class itti_ng_reset : public itti_msg_n2 {
public:
itti_ng_reset(const task_id_t origin, const task_id_t destination)
: itti_msg_n2(NG_RESET, origin, destination) {}
itti_ng_reset(const itti_ng_reset& i) : itti_msg_n2(i) {}
public:
NGResetMsg* ngReset;
};
class itti_initial_ue_message : public itti_msg_n2 {
public:
itti_initial_ue_message(const task_id_t origin, const task_id_t destination)
......
/*
* 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
*/
/*! \file
\brief
\author
\date 2021
\email: contact@openairinterface.org
*/
#include "NGReset.hpp"
extern "C" {
#include "constr_TYPE.h"
#include "Ngap_NGAP-PDU.h"
#include "asn_codecs.h"
#include "per_encoder.h"
#include "per_decoder.h"
#include "constraints.h"
#include "dynamic_memory_check.h"
}
#include <iostream>
#include <vector>
using namespace std;
namespace ngap {
//------------------------------------------------------------------------------
NGResetMsg::NGResetMsg() {
ngResetPdu = NULL;
ngResetIEs = NULL;
cause = {};
resetType = {};
}
//------------------------------------------------------------------------------
NGResetMsg::~NGResetMsg() {}
//------------------------------------------------------------------------------
void NGResetMsg::setMessageType() {
if (!ngResetPdu)
ngResetPdu = (Ngap_NGAP_PDU_t*) calloc(1, sizeof(Ngap_NGAP_PDU_t));
MessageType NgResetMessageTypeIE;
NgResetMessageTypeIE.setProcedureCode(Ngap_ProcedureCode_id_NGReset);
NgResetMessageTypeIE.setTypeOfMessage(Ngap_NGAP_PDU_PR_initiatingMessage);
NgResetMessageTypeIE.setValuePresent(
Ngap_InitiatingMessage__value_PR_NGReset);
if (NgResetMessageTypeIE.getProcedureCode() ==
Ngap_ProcedureCode_id_NGReset &&
NgResetMessageTypeIE.getTypeOfMessage() ==
Ngap_NGAP_PDU_PR_initiatingMessage) {
NgResetMessageTypeIE.encode2pdu(ngResetPdu);
ngResetIEs = &(ngResetPdu->choice.initiatingMessage->value.choice.NGReset);
} else {
cout << "[warning] This information doesn't refer to NGReset "
"Message!!!"
<< endl;
}
}
//------------------------------------------------------------------------------
void NGResetMsg::setCause(Ngap_Cause_t cause) {
this->cause = cause;
}
//------------------------------------------------------------------------------
void NGResetMsg::setResetType(Ngap_ResetType_t resetType) {
this->resetType = resetType;
}
void NGResetMsg::getCause(Ngap_Cause_t& cause) {
cause = this->cause;
}
void NGResetMsg::getResetType(Ngap_ResetType_t& resetType) {
resetType = this->resetType;
}
//------------------------------------------------------------------------------
int NGResetMsg::encode2buffer(uint8_t* buf, int buf_size) {
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, ngResetPdu);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_NGAP_PDU, NULL, ngResetPdu, buf, buf_size);
printf("er.encoded(%ld)\n", er.encoded);
return er.encoded;
}
//------------------------------------------------------------------------------
bool NGResetMsg::decodefrompdu(Ngap_NGAP_PDU_t* ngap_msg_pdu) {
ngResetPdu = ngap_msg_pdu;
if (ngResetPdu->present == Ngap_NGAP_PDU_PR_initiatingMessage) {
if (ngResetPdu->choice.initiatingMessage &&
ngResetPdu->choice.initiatingMessage->procedureCode ==
Ngap_ProcedureCode_id_NGReset &&
ngResetPdu->choice.initiatingMessage->criticality ==
Ngap_Criticality_reject &&
ngResetPdu->choice.initiatingMessage->value.present ==
Ngap_InitiatingMessage__value_PR_NGReset) {
ngResetIEs = &ngResetPdu->choice.initiatingMessage->value.choice.NGReset;
for (int i = 0; i < ngResetIEs->protocolIEs.list.count; i++) {
switch (ngResetIEs->protocolIEs.list.array[i]->id) {
case Ngap_ProtocolIE_ID_id_Cause: {
if (ngResetIEs->protocolIEs.list.array[i]->criticality ==
Ngap_Criticality_reject &&
ngResetIEs->protocolIEs.list.array[i]->value.present ==
Ngap_NGResetIEs__value_PR_Cause) {
cause = ngResetIEs->protocolIEs.list.array[i]->value.choice.Cause;
} else {
cout << "Decoded NGAP Cause IE error" << endl;
return false;
}
} break;
case Ngap_ProtocolIE_ID_id_ResetType: {
if (ngResetIEs->protocolIEs.list.array[i]->criticality ==
Ngap_Criticality_ignore &&
ngResetIEs->protocolIEs.list.array[i]->value.present ==
Ngap_NGResetIEs__value_PR_ResetType) {
resetType =
ngResetIEs->protocolIEs.list.array[i]->value.choice.ResetType;
} else {
cout << "Decoded NGAP ResetType IE error" << endl;
return false;
}
} break;
default: {
cout << "Decoded NGAP message PDU error" << endl;
return false;
}
}
}
} else {
cout << "Check NGReset message error!!!";
return false;
}
} else {
cout << "Check NGReset message error!!!";
return false;
}
return true;
}
} // namespace ngap
/*
* 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
*/
/*! \file
\brief
\author
\date 2021
\email: contact@openairinterface.org
*/
#ifndef _NG_RESET_H_
#define _NG_RESET_H_
#include "NgapIEsStruct.hpp"
#include "MessageType.hpp"
#include "GlobalRanNodeId.hpp"
#include "RanNodeName.hpp"
#include "DefaultPagingDRX.hpp"
#include "SupportedTAList.hpp"
extern "C" {
#include "Ngap_NGAP-PDU.h"
#include "Ngap_ProtocolIE-Field.h"
#include "Ngap_NGSetupRequest.h"
}
namespace ngap {
class NGResetMsg {
public:
NGResetMsg();
virtual ~NGResetMsg();
void setMessageType(); // Initialize the PDU and populate the MessageType;
void setCause(Ngap_Cause_t);
void setResetType(Ngap_ResetType_t);
int encode2buffer(uint8_t* buf, int buf_size);
bool decodefrompdu(Ngap_NGAP_PDU_t* ngap_msg_pdu);
void getCause(Ngap_Cause_t&);
void getResetType(Ngap_ResetType_t&);
private:
Ngap_NGAP_PDU_t* ngResetPdu;
Ngap_NGReset_t* ngResetIEs;
Ngap_Cause_t cause;
Ngap_ResetType_t resetType;
// Cause *cause;
// ResetType resetType;
};
} // namespace ngap
#endif
......@@ -53,13 +53,11 @@ ngap_app::ngap_app(const std::string& address, const uint16_t port_num)
ngap_app::~ngap_app() {}
//------------------------------------------------------------------------------
// received sctp payload and decode it to NGAP message and send itti message to
// TASK_AMF_N2
void ngap_app::handle_receive(
bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,
sctp_stream_id_t instreams, sctp_stream_id_t outstreams) {
Logger::ngap().debug(
"Handling SCTP payload from sctp_server on assoc_id (%d), stream_id "
"Handling SCTP payload from SCTP Server on assoc_id (%d), stream_id "
"(%d), instreams (%d), outstreams (%d)",
assoc_id, stream, instreams, outstreams);
Ngap_NGAP_PDU_t* ngap_msg_pdu =
......@@ -71,14 +69,13 @@ void ngap_app::handle_receive(
"Decoded NGAP message, procedure code %d, present %d",
ngap_msg_pdu->choice.initiatingMessage->procedureCode,
ngap_msg_pdu->present);
// Handle the message
(*messages_callback[ngap_msg_pdu->choice.initiatingMessage->procedureCode]
[ngap_msg_pdu->present - 1])(
assoc_id, stream, ngap_msg_pdu);
}
//------------------------------------------------------------------------------
// handle new sctp association
// TNL association(clause 8.7.1.1, 3gpp ts38.413)
void ngap_app::handle_sctp_new_association(
sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams,
sctp_stream_id_t outstreams) {
......@@ -119,7 +116,6 @@ uint32_t ngap_app::getPpid() {
return ppid_;
}
// gnb context management
//------------------------------------------------------------------------------
bool ngap_app::is_assoc_id_2_gnb_context(
const sctp_assoc_id_t& assoc_id) const {
......
......@@ -48,13 +48,31 @@ class ngap_app : public sctp_application {
~ngap_app();
uint32_t getPpid();
/*
* Handle SCTP payload (decode it and send ITTI msg to N2)
* @param [bstring] payload: payload
* @param [sctp_assoc_id_t] assoc_id: gNB association ID
* @param [sctp_stream_id_t] stream: stream
* @param [sctp_stream_id_t] instreams: instreams
* @param [sctp_stream_id_t] outstreams: outstreams
* @return void:
*/
void handle_receive(
bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,
sctp_stream_id_t instreams, sctp_stream_id_t outstreams);
/*
* Handle new SCTP TNL Association (clause 8.7.1.1, 3gpp ts38.413)
* @param [sctp_assoc_id_t] assoc_id: gNB association ID
* @param [sctp_stream_id_t] instreams: instreams
* @param [sctp_stream_id_t] outstreams: outstreams
* @return void:
*/
void handle_sctp_new_association(
sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams,
sctp_stream_id_t outstreams);
// gnb context management
bool is_assoc_id_2_gnb_context(const sctp_assoc_id_t& assoc_id) const;
void set_assoc_id_2_gnb_context(
const sctp_assoc_id_t& assoc_id, std::shared_ptr<gnb_context> gc);
......
......@@ -39,6 +39,7 @@
#include "itti_msg_n11.hpp"
#include "itti.hpp"
#include "NGSetupRequest.hpp"
#include "NGReset.hpp"
#include "PduSessionResourceSetupResponse.hpp"
#include "PduSessionResourceReleaseResponse.hpp"
#include "InitialContextSetupResponse.hpp"
......@@ -646,7 +647,27 @@ int nas_non_delivery_indication(
int ng_reset(
const sctp_assoc_id_t assoc_id, const sctp_stream_id_t stream,
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending itti ng reset to TASK_AMF_N2");
Logger::ngap().debug("Sending ITTI NG Reset to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
NGResetMsg* ngReset = new NGResetMsg();
if (!ngReset->decodefrompdu(message_p)) {
Logger::ngap().error("Decoding NGReset message error");
return -1;
}
itti_ng_reset* itti_msg = new itti_ng_reset(TASK_NGAP, TASK_AMF_N2);
itti_msg->assoc_id = assoc_id;
itti_msg->stream = stream;
itti_msg->ngReset = ngReset;
std::shared_ptr<itti_ng_reset> i = std::shared_ptr<itti_ng_reset>(itti_msg);
int ret = itti_inst->send_msg(i);
if (0 != ret) {
Logger::ngap().error(
"Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name());
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment