Commit c84bc571 authored by yangjian's avatar yangjian

Test the project of the university of information engineering

parent 558a4917
......@@ -118,6 +118,13 @@ void amf_app_task(void*) {
amf_app_inst->handle_itti_message(ref(*m));
} break;
case TEST_SIGNALLING_NETWORK_INITIATED_DEREGISTRAATION: {
Logger::amf_app().debug("Received TEST_SIGNALLING_NETWORK_INITIATED_DEREGISTRAATION");
itti_test_signalling_network_initiated_deregistration* m =
dynamic_cast<itti_test_signalling_network_initiated_deregistration*>(msg);
amf_app_inst->handle_itti_message(ref(*m));
} break;
case TIME_OUT:
if (itti_msg_timeout* to = dynamic_cast<itti_msg_timeout*>(msg)) {
switch (to->arg1_user) {
......@@ -208,6 +215,15 @@ void amf_app::handle_itti_message(
}
}
//------------------------------------------------------------------------------
void amf_app::handle_itti_message(
itti_test_signalling_network_initiated_deregistration& itti_msg) {
amf_n1_inst->network_initiate_de_registration_handle(itti_msg.ran_ue_ngap_id, itti_msg.amf_ue_ngap_id);
}
//------------------------------------------------------------------------------
void amf_app::handle_itti_message(
......
......@@ -56,6 +56,7 @@ class amf_app {
void handle_itti_message(itti_nas_signalling_establishment_request& itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request& itti_msg);
void handle_itti_message(itti_paging_n1n2_message_transfer& itti_msg);
void handle_itti_message(itti_test_signalling_network_initiated_deregistration& itti_msg);
// context management
std::map<long, std::shared_ptr<ue_context>> amf_ue_ngap_id2ue_ctx;
mutable std::shared_mutex m_amf_ue_ngap_id2ue_ctx;
......
This diff is collapsed.
......@@ -104,6 +104,11 @@ class amf_n1 {
void run_initial_registration_procedure();
void run_mobility_registration_update_procedure(
std::shared_ptr<nas_context> nc);
void run_periodic_registration_update_procedure(
std::shared_ptr<nas_context> nc,uint16_t);
void run_periodic_registration_update_procedure(
std::shared_ptr<nas_context> nc,bstring& nas_msg);
// authentication
bool auth_vectors_generator(std::shared_ptr<nas_context>& nc);
......@@ -159,6 +164,9 @@ class amf_n1 {
void set_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t state);
void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t& state);
void network_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
private: // nas message handlers
void ue_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
......
......@@ -42,7 +42,7 @@ nas_context::nas_context() {
is_common_procedure_for_security_mode_control_running = false;
is_common_procedure_for_nas_transport_running = false;
auts = NULL;
ueSecurityCaplen = 0;
ueSecurityCaplen = 2;
}
//------------------------------------------------------------------------------
......
......@@ -83,6 +83,7 @@ typedef enum {
UPLINKRANSTATUSTRANSFER,
PDU_SESS_RES_SET_RESP,
PAGING_N1N2_MESSAGE_TRANSFER,
TEST_SIGNALLING_NETWORK_INITIATED_DEREGISTRAATION,
PAGING,
TIME_OUT,
HEALTH_PING,
......
......@@ -72,5 +72,17 @@ class itti_paging_n1n2_message_transfer : public itti_msg_amf_app {
plmn_t plmn;
};
class itti_test_signalling_network_initiated_deregistration : public itti_msg_amf_app {
public:
itti_test_signalling_network_initiated_deregistration(const task_id_t origin, const task_id_t destination)
: itti_msg_amf_app(TEST_SIGNALLING_NETWORK_INITIATED_DEREGISTRAATION, origin, destination) {}
itti_test_signalling_network_initiated_deregistration(const itti_test_signalling_network_initiated_deregistration& i) : itti_msg_amf_app(i) {}
public:
uint32_t ran_ue_ngap_id;
long amf_ue_ngap_id;
};
#endif
......@@ -83,13 +83,15 @@ void _5GSDeregistrationType::get(uint8_t& type) {
//------------------------------------------------------------------------------
int _5GSDeregistrationType::encode2buffer(uint8_t* buf, int len) {
Logger::nas_mm().error("Encoding 5GSDeregistrationType IE");
Logger::nas_mm().debug("Encoding 5GSDeregistrationType (0x%x)",u1.b);
if (len < 1) {
Logger::nas_mm().error(
"encoding 5GSDeregistrationType error(len is less than one)");
return -1;
}
*buf = u1.b;
return 0;
}
//------------------------------------------------------------------------------
......
......@@ -51,6 +51,14 @@ void DeregistrationRequest::setHeader(uint8_t security_header_type) {
EPD_5GS_MM_MSG, security_header_type,
DEREGISTRATION_REQUEST_UE_ORIGINATING);
}
//------------------------------------------------------------------------------
void DeregistrationRequest::setHeader(uint8_t security_header_type,uint8_t msg_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type,
msg_type);
}
//------------------------------------------------------------------------------
void DeregistrationRequest::setDeregistrationType(uint8_t dereg_type) {
......@@ -161,11 +169,11 @@ int DeregistrationRequest::encode2buffer(uint8_t* buf, int len) {
Logger::nas_mm().error("Mandatory IE missing Deregistration Type");
return 0;
}
if (!ie_ngKSI) {
if ((!ie_ngKSI) && (plain_header->getMessageType() == DEREGISTRATION_REQUEST_UE_ORIGINATING)) {
Logger::nas_mm().error("Mandatory IE missing ie_ngKSI");
return 0;
}
if (!ie_5gs_mobility_id) {
if ((!ie_5gs_mobility_id) && (plain_header->getMessageType() == DEREGISTRATION_REQUEST_UE_ORIGINATING)) {
Logger::nas_mm().error("Mandatory IE missing ie_5gs_mobility_id");
return 0;
}
......@@ -173,16 +181,24 @@ int DeregistrationRequest::encode2buffer(uint8_t* buf, int len) {
encoded_size += 3;
if (!(ie_deregistrationtype->encode2buffer(
buf + encoded_size, len - encoded_size))) {
if (plain_header->getMessageType() == DEREGISTRATION_REQUEST_UE_ORIGINATING)
{
if (!(ie_ngKSI->encode2buffer(buf + encoded_size, len - encoded_size))) {
encoded_size += 1;
} else {
Logger::nas_mm().error("Encoding IE ie_ngKSI error");
return 0;
}
}
else {
encoded_size += 1;
}
} else {
Logger::nas_mm().error("Encoding IE Deregistrationt Type error");
return 0;
}
if (plain_header->getMessageType() == DEREGISTRATION_REQUEST_UE_ORIGINATING)
{
if (int size = ie_5gs_mobility_id->encode2buffer(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
......@@ -190,10 +206,16 @@ int DeregistrationRequest::encode2buffer(uint8_t* buf, int len) {
Logger::nas_mm().error("Encoding IE ie_5gs_mobility_id error");
return 0;
}
}
*(buf + encoded_size) = 0x58;
encoded_size += 1;
*(buf + encoded_size) = 74;
encoded_size += 1;
Logger::nas_mm().debug(
"Encoded DeregistrationRequest message len (%d)", encoded_size);
return 1;
return encoded_size;
}
//------------------------------------------------------------------------------
......
......@@ -41,6 +41,7 @@ class DeregistrationRequest {
int encode2buffer(uint8_t* buf, int len);
int decodefrombuffer(NasMmPlainHeader* header, uint8_t* buf, int len);
void setHeader(uint8_t security_header_type);
void setHeader(uint8_t security_header_type,uint8_t msg_type);
void setDeregistrationType(uint8_t dereg_type);
void setDeregistrationType(_5gs_deregistration_type_t type);
void setngKSI(uint8_t tsc, uint8_t key_set_id);
......
......@@ -231,8 +231,9 @@ bool RegistrationRequest::getUeSecurityCapability(uint8_t& ea, uint8_t& ia) {
ea = ie_ue_security_capability->getEASel();
ia = ie_ue_security_capability->getIASel();
} else {
return -1;
return false;
}
return true;
}
//------------------------------------------------------------------------------
......@@ -299,7 +300,7 @@ uint16_t RegistrationRequest::getPduSessionStatus() {
if (ie_PDU_session_status) {
return ie_PDU_session_status->getValue();
} else {
return -1;
return 0;
}
}
......@@ -386,9 +387,9 @@ void RegistrationRequest::setEPS_NAS_Message_Container(bstring value) {
bool RegistrationRequest::getEpsNasMessageContainer(bstring& epsNas) {
if (ie_eps_nas_message_container) {
ie_eps_nas_message_container->getValue(epsNas);
return 0;
return true;
} else {
return -1;
return false;
}
}
......@@ -486,9 +487,9 @@ void RegistrationRequest::setNAS_Message_Container(bstring value) {
bool RegistrationRequest::getNasMessageContainer(bstring& nas) {
if (ie_nas_message_container) {
ie_nas_message_container->getValue(nas);
return 0;
return true;
} else {
return -1;
return false;
}
}
......
......@@ -17,6 +17,8 @@ void AMFApiServer::init(size_t thr) {
m_nonUEN2MessagesCollectionDocumentApiImpl->init();
m_nonUEN2MessagesSubscriptionsCollectionDocumentApiImpl->init();
m_subscriptionsCollectionDocumentApiImpl->init();
m_testSignallingApiImpl->init();
Logger::amf_server().debug("Initiate AMF server endpoints done!");
}
......@@ -53,6 +55,11 @@ void AMFApiServer::start() {
if (m_subscriptionsCollectionDocumentApiImpl != nullptr)
Logger::amf_server().debug(
"AMF handler for SubscriptionsCollectionDocumentApiImpl");
if (m_testSignallingApiImpl != nullptr)
Logger::amf_server().debug(
"AMF handler for TestSignallingApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve();
}
......
......@@ -17,6 +17,8 @@
#include "NonUEN2MessagesSubscriptionsCollectionDocumentApiImpl.h"
#include "SubscriptionsCollectionDocumentApiImpl.h"
#include "TestSignallingApiImpl.h"
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_PAYLOAD 32768
......@@ -59,6 +61,10 @@ class AMFApiServer {
m_subscriptionsCollectionDocumentApiImpl =
std::make_shared<SubscriptionsCollectionDocumentApiImpl>(
m_router, amf_app_inst);
m_testSignallingApiImpl =
std::make_shared<TestSignallingApiImpl>(
m_router, amf_app_inst);
}
void init(size_t thr = 1);
......@@ -88,4 +94,7 @@ class AMFApiServer {
m_nonUEN2MessagesSubscriptionsCollectionDocumentApiImpl;
std::shared_ptr<SubscriptionsCollectionDocumentApiImpl>
m_subscriptionsCollectionDocumentApiImpl;
std::shared_ptr<TestSignallingApiImpl>
m_testSignallingApiImpl;
};
#include "TestSignallingApi.h"
namespace oai {
namespace amf {
namespace api {
TestSignallingApi::
TestSignallingApi(
std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void TestSignallingApi::init() {
setupRoutes();
}
void TestSignallingApi::
setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router,
base + "/test-signalling/network-initiated-deregistration/:subscriptionId",
Routes::bind(
&TestSignallingApi::
test_signalling_network_initiated_deregistration_handler,
this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(
&TestSignallingApi::
test_signalling_api_default_handler,
this));
}
void TestSignallingApi::
test_signalling_network_initiated_deregistration_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
// Getting the path params
auto subscriptionId =
request.param(":subscriptionId").as<std::string>();
try {
this->test_signalling_network_initiated_deregistration(subscriptionId, response);
} catch (nlohmann::detail::exception& e) {
// send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception& e) {
// send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void TestSignallingApi::
test_signalling_api_default_handler(
const Pistache::Rest::Request&,
Pistache::Http::ResponseWriter response) {
response.send(
Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace amf
} // namespace oai
#ifndef _TESTSIGNALLING_API_H_
#define _TESTSIGNALLING_API_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include <nlohmann/json.hpp>
#include "ProblemDetails.h"
#include <string>
namespace oai {
namespace amf {
namespace api {
class TestSignallingApi {
public:
TestSignallingApi(
std::shared_ptr<Pistache::Rest::Router>);
virtual ~TestSignallingApi() {}
void init();
const std::string base = "/namf-test/v1";
private:
void setupRoutes();
void test_signalling_network_initiated_deregistration_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void
test_signalling_api_default_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
virtual void test_signalling_network_initiated_deregistration(
const std::string& subscriptionId,
Pistache::Http::ResponseWriter& response) = 0;
};
} // namespace api
} // namespace amf
} // namespace oai
#endif
#include "TestSignallingApiImpl.h"
#include "itti.hpp"
#include "amf_n11.hpp"
#include "pdu_session_context.hpp"
using namespace amf_application;
//using namespace ngap;
extern itti_mw* itti_inst;
extern amf_n11* amf_n11_inst;
namespace oai {
namespace amf {
namespace api {
TestSignallingApiImpl::
TestSignallingApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr,
amf_application::amf_app* amf_app_inst)
: TestSignallingApi(rtr),
m_amf_app(amf_app_inst) {}
void TestSignallingApiImpl::
test_signalling_network_initiated_deregistration(
const std::string& subscriptionId,
Pistache::Http::ResponseWriter& response) {
response.send(
Pistache::Http::Code::Ok,
"test_signalling_network_initiated_deregistration ok!\n");
std::string supi = subscriptionId;
Logger::amf_server().debug(
"Key for PDU Session context: SUPI (%s)", supi.c_str());
std::shared_ptr<pdu_session_context> psc;
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi);
itti_test_signalling_network_initiated_deregistration* itti_msg =
new itti_test_signalling_network_initiated_deregistration(AMF_SERVER, TASK_AMF_APP);
itti_msg->ran_ue_ngap_id = psc.get()->ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = psc.get()->amf_ue_ngap_id;
std::shared_ptr<itti_test_signalling_network_initiated_deregistration> i =
std::shared_ptr<itti_test_signalling_network_initiated_deregistration>(itti_msg);
int ret = itti_inst->send_msg(i);
if (0 != ret) {
Logger::amf_server().error(
"Could not send ITTI message %s to task TASK_AMF_APP",
i->get_msg_name());
}
} else {
Logger::amf_server().error(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
}
}
} // namespace api
} // namespace amf
} // namespace oai
#ifndef _TESTSIGNALLING_API_IMPL_H_
#define _TESTSIGNALLING_API_IMPL_H_
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <TestSignallingApi.h>
#include <pistache/optional.h>
#include "ProblemDetails.h"
#include <string>
#include "amf_app.hpp"
namespace oai {
namespace amf {
namespace api {
class TestSignallingApiImpl
: public oai::amf::api::
TestSignallingApi {
public:
TestSignallingApiImpl(
std::shared_ptr<Pistache::Rest::Router>,
amf_application::amf_app* amf_app_inst);
~TestSignallingApiImpl() {}
void test_signalling_network_initiated_deregistration(
const std::string& subscriptionId,
Pistache::Http::ResponseWriter& response);
private:
amf_application::amf_app* m_amf_app;
};
} // namespace api
} // namespace amf
} // namespace oai
#endif
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