Commit 565f84e1 authored by liuyu's avatar liuyu

add plugin service,gnb test is ok, ue without test

parent 8341c820
{
"files.associations": {
"string": "cpp",
"*.h++": "cpp",
"ostream": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"*.ipp": "cpp"
}
}
\ No newline at end of file
......@@ -11,3 +11,4 @@ set (BUILD_TOP_DIR ${OPENAIRCN_DIR}/build)
set (SRC_TOP_DIR $ENV{OPENAIRCN_DIR}/src)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../src/oai-amf/CMakeLists.txt)
......@@ -37,17 +37,17 @@ AMF =
GUAMI:
{
MCC = "208"; MNC = "95"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "1" # YOUR GUAMI CONFIG HERE
MCC = "460"; MNC = "11"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "1" # YOUR GUAMI CONFIG HERE
}
SERVED_GUAMI_LIST = (
{MCC = "208"; MNC = "95"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "0"}, #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
{MCC = "460"; MNC = "11"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "0"}, #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
{MCC = "460"; MNC = "11"; RegionID = "10"; AMFSetID = "1"; AMFPointer = "1"} #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
);
PLMN_SUPPORT_LIST = (
{
MCC = "208"; MNC = "95"; TAC = 0xa000; # YOUR PLMN CONFIG HERE
MCC = "460"; MNC = "11"; TAC = 0xa000; # YOUR PLMN CONFIG HERE
SLICE_SUPPORT_LIST = (
{SST = "222"; SD = "123"}, # YOUR NSSAI CONFIG HERE
{SST = "1"; SD = "12"} # YOUR NSSAI CONFIG HERE
......@@ -60,7 +60,7 @@ AMF =
# AMF binded interface for N1/N2 interface (NGAP)
NGAP_AMF:
{
INTERFACE_NAME = "ens3"; # YOUR NETWORK CONFIG HERE
INTERFACE_NAME = "wlp58s0"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 38412; # YOUR NETWORK CONFIG HERE
PPID = 60; # YOUR NETWORK CONFIG HERE
......@@ -69,7 +69,7 @@ AMF =
# AMF binded interface for N11
N11:
{
INTERFACE_NAME = "ens3"; # YOUR NETWORK CONFIG HERE
INTERFACE_NAME = "ens33"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 80; # YOUR NETWORK CONFIG HERE
......
################################################################################
# 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
################################################################################
AMF =
{
INSTANCE_ID = 10; # 0 is the default
PID_DIRECTORY = "/var/run"; # /var/run is the default
AMF_NAME = "OAI-AMF";
RELATIVE_CAPACITY = 30;
# Display statistics about whole system (in seconds)
STATISTICS_TIMER_INTERVAL = 20; # YOUR CONFIG HERE
CORE_CONFIGURATION:
{
EMERGENCY_SUPPORT = "false";
};
GUAMI:
{
MCC = "460"; MNC = "11"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "1" # YOUR GUAMI CONFIG HERE
}
SERVED_GUAMI_LIST = (
{MCC = "460"; MNC = "11"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "0"} #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
#{MCC = "110"; MNC = "11"; RegionID = "10"; AMFSetID = "1"; AMFPointer = "1"} #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
);
PLMN_SUPPORT_LIST = (
{
MCC = "460"; MNC = "11"; TAC = 100; # YOUR PLMN CONFIG HERE
SLICE_SUPPORT_LIST = (
{SST = "1"; SD = "none"}, # YOUR NSSAI CONFIG HERE
{SST = "1"; SD = "12"} # YOUR NSSAI CONFIG HERE
)
}
);
INTERFACES:
{
# AMF binded interface for N1/N2 interface (NGAP)
NGAP_AMF:
{
INTERFACE_NAME = "wlp58s0"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 38412; # YOUR NETWORK CONFIG HERE
PPID = 60; # YOUR NETWORK CONFIG HERE
};
# AMF binded interface for N11
N11:
{
INTERFACE_NAME = "wlp58s0"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 8282; # YOUR NETWORK CONFIG HERE
SMF_INSTANCES_POOL = (
{SMF_INSTANCE_ID = 1; IPV4_ADDRESS = "192.168.122.197"; PORT = "8889"; VERSION = "v2"; SELECTED = "true"}, # YOUR SMF CONFIG HERE
{SMF_INSTANCE_ID = 2; IPV4_ADDRESS = "192.168.122.2"; PORT = "80"; VERSION = "v1"; SELECTED = "false"} # YOUR SMF CONFIG HERE
);
};
};
AUTHENTICATION:
{
## MySQL mandatory options
MYSQL_server = "127.0.0.1"; # MySQL Server address
MYSQL_user = "root"; # Database server login
MYSQL_pass = "linux"; # Database server password
MYSQL_db = "OPENXG_DB"; # Your database name
## OP
OPERATOR_key = "63bfa50ee6523365ff14c1f45f88737d"; # OP key matching your database
RANDOM = "true";
};
NAS:
{
ORDERED_SUPPORTED_INTEGRITY_ALGORITHM_LIST = [ "NIA1" , "NIA1" , "NIA1" ];
ORDERED_SUPPORTED_CIPHERING_ALGORITHM_LIST = [ "NEA0" , "NEA1" , "NEA2" ];
};
};
MODULES =
{
NGAP_MESSAGE = (
{MSG_NAME = "NGSetupRequest"; ProcedureCode = 21; TypeOfMessage = "initialMessage"}
);
};
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"*.ipp": "cpp"
}
}
\ No newline at end of file
......@@ -47,6 +47,7 @@
#include "Ngap_Cause.h"
#include "Ngap_CauseRadioNetwork.h"
#include "Ngap_TimeToWait.h"
#include <nlohmann/json.hpp>
extern "C" {
#include "dynamic_memory_check.h"
......@@ -222,7 +223,8 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
ngSetupFailure.setCauseRadioNetwork(Ngap_CauseRadioNetwork_unspecified, Ngap_TimeToWait_v5s);
int encoded = ngSetupFailure.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
//sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
sctp_s_38412.curl_http_client(itti_msg.assoc_id, itti_msg.stream, b);
Logger::amf_n2().error("No common PLMN, encoding NG_SETUP_FAILURE with cause (Unknown PLMN)");
return;
} else {
......@@ -269,7 +271,12 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
ngSetupResp.setPlmnSupportList(plmn_list);
int encoded = ngSetupResp.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
//sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
sctp_s_38412.curl_http_client(itti_msg.assoc_id, itti_msg.stream,b);
Logger::amf_n2().debug("Sending NG_SETUP_RESPONSE Ok");
gc.get()->ng_state = NGAP_READY;
Logger::amf_n2().debug("gNB with gNB_id 0x%x, assoc_id %d has been attached to AMF", gc.get()->globalRanNodeId, itti_msg.assoc_id);
......@@ -460,7 +467,8 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) {
uint8_t buffer[1024];
int encoded_size = ngap_msg->encode2buffer(buffer, 1024);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
//sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
sctp_s_38412.curl_http_client(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, b);
}
//------------------------------------------------------------------------------
......@@ -520,7 +528,8 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
uint8_t buffer[10000];
int encoded_size = msg->encode2buffer(buffer, 10000);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
//sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
sctp_s_38412.curl_http_client(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, b);
}
//------------------------------------------------------------------------------
......@@ -590,7 +599,8 @@ void amf_n2::handle_itti_message(itti_pdu_session_resource_setup_request &itti_m
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
//sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
sctp_s_38412.curl_http_client(gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, b);
//free memory
free_wrapper((void**) &buffer);
}
......@@ -609,7 +619,8 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request &itti_msg) {
uint8_t buffer[200];
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
//sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
sctp_s_38412.curl_http_client(itti_msg.assoc_id, itti_msg.stream, b);
}
//------------------------------------------------------------------------------
......
......@@ -68,6 +68,7 @@ typedef struct s_nssai // section 28.4, TS23.003
//SMF + AMF + 3GPP TS 29.571 (Common data)
enum class http_response_codes_e {
HTTP_RESPONSE_CODE_0 = 0,
HTTP_RESPONSE_CODE_200_OK = 200,
HTTP_RESPONSE_CODE_201_CREATED = 201,
HTTP_RESPONSE_CODE_202_ACCEPTED = 202,
......
......@@ -341,6 +341,7 @@ add_executable(amf
${SRC_TOP_DIR}/oai-amf/options.cpp
${SRC_TOP_DIR}/itti/itti.cpp
${SRC_TOP_DIR}/itti/itti_msg.cpp
${SRC_TOP_DIR}/ngap/ngap_app/ngap_app.cpp
)
IF(STATIC_LINKING)
......
......@@ -30,11 +30,14 @@ include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/contexts)
include_directories(${SRC_TOP_DIR}/nas/common)
include_directories(${SRC_TOP_DIR}/ngap/libngap)
include_directories(${SRC_TOP_DIR}/ngap/ngap_app)
include_directories(${SRC_TOP_DIR}/ngap/ngapIEs)
include_directories(${SRC_TOP_DIR}/ngap/ngapMsgs)
include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/sctp)
include_directories(${SRC_TOP_DIR}/sbi/amf_server)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/api)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/impl)
......
......@@ -12,6 +12,7 @@
#include "IndividualSubscriptionDocumentApi.h"
#include "Helpers.h"
#include "TransData.hpp"
namespace oai {
namespace amf {
......@@ -34,10 +35,36 @@ void IndividualSubscriptionDocumentApi::setupRoutes() {
Routes::Put(*router, base + "/subscriptions/:subscriptionId", Routes::bind(&IndividualSubscriptionDocumentApi::a_mf_status_change_subscribe_modfy_handler, this));
Routes::Delete(*router, base + "/subscriptions/:subscriptionId", Routes::bind(&IndividualSubscriptionDocumentApi::a_mf_status_change_un_subscribe_handler, this));
Routes::Put(*router, base + "/plugin_n2/:assoc_id/:stream", Routes::bind(&IndividualSubscriptionDocumentApi::gnb_message_from_plugin_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&IndividualSubscriptionDocumentApi::individual_subscription_document_api_default_handler, this));
}
void IndividualSubscriptionDocumentApi::gnb_message_from_plugin_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto assoc_id = request.param(":assoc_id").as<std::uint32_t>();
auto stream = request.param(":stream").as<std::uint32_t>();
// Getting the body param
printf("-------------------------------------------plugin http request\n-----------");
//SubscriptionData subscriptionData;
TransData transdata;
std::cout<<request.body()<<std::endl;
try {
nlohmann::json::parse(request.body()).get_to(transdata);
this->gnb_message_from_plugin(assoc_id, stream,transdata, 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 IndividualSubscriptionDocumentApi::a_mf_status_change_subscribe_modfy_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto subscriptionId = request.param(":subscriptionId").as<std::string>();
......
......@@ -23,6 +23,7 @@
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "TransData.hpp"
#include "ProblemDetails.h"
......@@ -50,6 +51,7 @@ private:
void a_mf_status_change_un_subscribe_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void individual_subscription_document_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void gnb_message_from_plugin_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
......@@ -71,6 +73,7 @@ private:
/// <param name="subscriptionId">AMF Status Change Subscription Identifier</param>
virtual void a_mf_status_change_un_subscribe(const std::string &subscriptionId, Pistache::Http::ResponseWriter &response) = 0;
virtual void gnb_message_from_plugin(const std::uint32_t &assoc_id, const std::uint16_t &stream , TransData transdata,Pistache::Http::ResponseWriter &response) =0;
};
}
......
......@@ -11,13 +11,25 @@
*/
#include "IndividualSubscriptionDocumentApiImpl.h"
//#include "ngap_app.hpp"/
#include "bstrlib.h"
#include "amf_n2.hpp"
#include <shared_mutex>
using namespace amf_application;
using namespace ngap;
extern amf_n2 *amf_n2_inst;
extern unsigned char* format_string_as_hex(std::string str);
extern char* bstring2charString(bstring b);
extern void msg_str_2_msg_hex(std::string msg, bstring &b);
extern void convert_string_2_hex(std::string &input, std::string &output);
namespace oai {
namespace amf {
namespace api {
using namespace oai::amf::model;
IndividualSubscriptionDocumentApiImpl::IndividualSubscriptionDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr, amf_application::amf_app *amf_app_inst)
: IndividualSubscriptionDocumentApi(rtr), m_amf_app(amf_app_inst)
{ }
......@@ -25,6 +37,20 @@ IndividualSubscriptionDocumentApiImpl::IndividualSubscriptionDocumentApiImpl(std
void IndividualSubscriptionDocumentApiImpl::a_mf_status_change_subscribe_modfy(const std::string &subscriptionId, const SubscriptionData &subscriptionData, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "IndividualSubscriptionDocumentApiImpl::a_mf_status_change_subscribe_modfy API has not been implemented yet!\n");
}
void IndividualSubscriptionDocumentApiImpl::gnb_message_from_plugin(const std::uint32_t &assoc_id, const std::uint16_t &stream , TransData transdata,Pistache::Http::ResponseWriter &response) {
printf("receive n2 message from plugin, sent to ngap task\n");
printf("transdata = %s\n",transdata.get_amf_data().c_str());
uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
std::memcpy(buffer, format_string_as_hex(transdata.get_amf_data()),transdata.get_amf_data().length()/2+1);
bstring payload = blk2bstr(buffer, transdata.get_amf_data().length()/2+1);
printf("%s\n,length %d",bdata(payload),blength(payload));
if (!amf_n2_inst->is_assoc_id_2_gnb_context(assoc_id)) {
amf_n2_inst->handle_sctp_new_association(assoc_id,10,8);
}
amf_n2_inst->handle_receive(payload,assoc_id,stream,10,8);
response.send(Pistache::Http::Code::Ok, "plugin message\n");
}
void IndividualSubscriptionDocumentApiImpl::a_mf_status_change_un_subscribe(const std::string &subscriptionId, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "IndividualSubscriptionDocumentApiImpl::a_mf_status_change_un_subscribe API has not been implemented yet!\n");
}
......
......@@ -32,7 +32,7 @@
#include "ProblemDetails.h"
#include "SubscriptionData.h"
#include <string>
#include "TransData.hpp"
#include "amf_app.hpp"
namespace oai {
......@@ -48,6 +48,7 @@ public:
void a_mf_status_change_subscribe_modfy(const std::string &subscriptionId, const SubscriptionData &subscriptionData, Pistache::Http::ResponseWriter &response);
void a_mf_status_change_un_subscribe(const std::string &subscriptionId, Pistache::Http::ResponseWriter &response);
void gnb_message_from_plugin(const std::uint32_t &assoc_id, const std::uint16_t &stream ,TransData transdata, Pistache::Http::ResponseWriter &response);
private:
amf_application::amf_app *m_amf_app;
};
......
/**
* 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.
*/
#include "TransData.hpp"
#include <iostream>
namespace oai {
namespace amf {
namespace model {
TransData::TransData() {
m_transdata = "";
}
TransData::~TransData() {}
std::string TransData::get_amf_data()
{
return m_transdata;
}
void to_json(nlohmann::json& j, const TransData& o) {
j = nlohmann::json();
j["n2_data"] = o.m_transdata;
}
void from_json(const nlohmann::json& j, TransData& o) {
j.at("n2_data").get_to(o.m_transdata);
}
} // namespace model
} // namespace amf
} // namespace oai
/**
* 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.
*/
/*
* TransData.h
*
*
*/
#ifndef _TRANSDATA_H_
#define _TRANSDATA_H_
#include <string>
#include <vector>
#include <stdlib.h>
#include <nlohmann/json.hpp>
#include <iostream>
namespace oai {
namespace amf {
namespace model {
class TransData {
public:
TransData();
virtual ~TransData();
friend void to_json(nlohmann::json& j, const TransData& o);
friend void from_json(const nlohmann::json& j, TransData& o);
std::string get_amf_data();
protected:
std::string m_transdata;
};
} // namespace model
} // namespace
} // namespace oai
#endif /* TransData_H_ */
......@@ -20,6 +20,7 @@
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/amf-app)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/unicode)
include_directories(${SRC_TOP_DIR}/nas/common)
......
......@@ -28,6 +28,10 @@
#include "sctp_server.hpp"
#include "logger.hpp"
#include <nlohmann/json.hpp>
#include "amf.hpp"
extern "C" {
#include <netinet/in.h>
#include <netinet/sctp.h>
......@@ -42,12 +46,13 @@ extern "C" {
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <curl/curl.h>
#include "bstrlib.h"
}
#include <iostream>
using namespace std;
namespace sctp {
//------------------------------------------------------------------------------
......@@ -148,12 +153,15 @@ int sctp_server::sctp_read_from_socket(int sd, uint32_t ppid) {
struct sctp_sndrcvinfo sinfo = { 0 };
struct sockaddr_in6 addr = { 0 };
uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
// char buffer[SCTP_RECV_BUFFER_SIZE];
if (sd < 0)
return -1;
memset((void*) &addr, 0, sizeof(struct sockaddr_in6));
from_len = (socklen_t) sizeof(struct sockaddr_in6);
memset((void*) &sinfo, 0, sizeof(struct sctp_sndrcvinfo));
int n = sctp_recvmsg(sd, (void*) buffer, SCTP_RECV_BUFFER_SIZE, (struct sockaddr*) &addr, &from_len, &sinfo, &flags);
// printf("buffer = %s\n",buffer);
// std::cout<<buffer<<std::endl;
if (n < 0) {
Logger::sctp().error("sctp_recvmsg error:: %s:%d", strerror(errno), errno);
return SCTP_RC_ERROR;
......@@ -185,9 +193,13 @@ int sctp_server::sctp_read_from_socket(int sd, uint32_t ppid) {
Logger::sctp().error("Received data from peer with unsolicited PPID (%d), expecting (%d)", ntohl(sinfo.sinfo_ppid), association->ppid);
return SCTP_RC_ERROR;
}
Logger::sctp().info("****[Assoc_id %d, Socket %d] Received a msg (length %d) from port %d, on stream %d, PPID %d ****", sinfo.sinfo_assoc_id, sd, n, ntohs(addr.sin6_port), sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
bstring payload = blk2bstr(buffer, n);
//handle payload
Logger::sctp().info("%s\n,length %d",bdata(payload),blength(payload));
app_->handle_receive(payload, (sctp_assoc_id_t) sinfo.sinfo_assoc_id, sinfo.sinfo_stream, association->instreams, association->outstreams);
}
}
......@@ -362,5 +374,97 @@ int sctp_server::sctp_send_msg(sctp_assoc_id_t sctp_assoc_id, sctp_stream_id_t s
assoc_desc->messages_sent++;
return 0;
}
void octet_stream_2_hex_stream(uint8_t* buf, int len, std::string& out) {
out = "";
char* tmp = (char*) calloc(1, 2 * len * sizeof(uint8_t) + 1);
for (int i = 0; i < len; i++) {
sprintf(tmp + 2 * i, "%02x", buf[i]);
}
tmp[2 * len] = '\0';
out = tmp;
printf("n1sm buffer: %s\n", out.c_str());
}
static std::size_t callback(
const char* in, std::size_t size, std::size_t num, std::string* out) {
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
}
void sctp_server::curl_http_client(sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,bstring payload)
{
printf("使用http发送到pluginf\n");
std::string ngapmsg;
octet_stream_2_hex_stream((uint8_t*) bdata(payload), blength(payload), ngapmsg);
Logger::sctp().debug(
"[Assoc ID %d] Sending buffer %p of %d bytes on stream %d,ngapmsg length %d ",
assoc_id, bdata(payload), blength(payload), stream,ngapmsg.length());
nlohmann::json json_data = {};
json_data["n2_data"] = ngapmsg;
std::string url =
"http://" + std::string("10.112.202.24") +
":" + std::to_string(38414) + "/nplugin-dr/v1/" +
to_string (assoc_id ) + "/" + to_string (stream) ;
Logger::sctp().debug(
"Send N2 message to PLUGIN , PLUGIN URL %s", url.c_str());
std::string body = json_data.dump();
Logger::sctp().debug(
"Send N2 message to PLUGIN , msg body: \n %s", body.c_str());
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl = curl_easy_init();
if (curl) {
CURLcode res = {};
struct curl_slist* headers = nullptr;
// std::string content_type = "content-type: multipart/related; boundary=" +
// std::string(CURL_MIME_BOUNDARY);
// headers = curl_slist_append(headers, content_type.c_str());
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, PLUGIN_CURL_TIMEOUT_MS);
// Response information.
long httpCode = {0};
std::unique_ptr<std::string> httpData(new std::string());
//std::unique_ptr<std::string> httpHeaderData(new std::string());
// Hook up data handling function.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
// curl_easy_setopt(curl, CURLOPT_HEADERDATA, httpHeaderData.get());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length());
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
Logger::sctp().debug("Send NGAP message to PLUGIN, response from PLUGIN, HTTP Code: %d", httpCode);
if (static_cast<http_response_codes_e>(httpCode) ==http_response_codes_e::HTTP_RESPONSE_CODE_0) {
Logger::sctp().info( "Cannot get response when calling %s", url.c_str());
// free curl before returning
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return;
}
if (static_cast<http_response_codes_e>(httpCode) ==http_response_codes_e::HTTP_RESPONSE_CODE_200_OK) {
Logger::sctp().info("sending successful when calling %s", url.c_str());
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return;
}
curl_global_cleanup();
}
}
}
\ No newline at end of file
......@@ -44,6 +44,8 @@ extern "C" {
#define SCTP_RC_NORMAL_READ 0
#define SCTP_RC_DISCONNECT 1
#define PLUGIN_CURL_TIMEOUT_MS 100L
namespace sctp {
typedef uint16_t sctp_stream_id_t;
......@@ -87,6 +89,7 @@ class sctp_server {
int create_socket(const char *address, const uint16_t port_num);
void start_receive(sctp_application *app);
int sctp_send_msg(sctp_assoc_id_t sctp_assoc_id, sctp_stream_id_t stream, bstring *payload);
void curl_http_client(sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,bstring payload);
private:
static void* sctp_receiver_thread(void *arg);
int getSocket();
......
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