Commit d61ee799 authored by Niuhaiwen's avatar Niuhaiwen

add amfiplist

parent 337d3a18
No preview for this file type
...@@ -17,12 +17,12 @@ PLUGIN = ...@@ -17,12 +17,12 @@ PLUGIN =
{ {
INTERFACE_NAME = "ens18"; # YOUR NETWORK CONFIG HERE INTERFACE_NAME = "ens18"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read"; IPV4_ADDRESS = "read";
PORT = 8383; # YOUR NETWORK CONFIG HERE PORT = 8282; # YOUR NETWORK CONFIG HERE
}; };
NRF: NRF:
{ {
INTERFACE_NAME = "NRF"; # YOUR NETWORK CONFIG HERE INTERFACE_NAME = "NRF"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "10.244.2.2";#amf地址 IPV4_ADDRESS = "10.244.1.12";#amf地址
PORT = 8282; # YOUR NETWORK CONFIG HERE PORT = 8282; # YOUR NETWORK CONFIG HERE
}; };
}; };
......
This diff is collapsed.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
using namespace config; using namespace config;
std::map<std::string,long> ip2len; std::map<std::string,long> ip2len;
std::map<std::string,bool> all_rp; std::map<std::string,bool> all_rp;
extern std::vector<std::string> amf_ip_list;
long msg_len[4]={0}; long msg_len[4]={0};
long pro_cap[4] = {0}; long pro_cap[4] = {0};
bool isall[4] = {0}; bool isall[4] = {0};
...@@ -55,6 +55,7 @@ void PluginApi::setupRoutes() { ...@@ -55,6 +55,7 @@ void PluginApi::setupRoutes() {
using namespace Pistache::Rest; using namespace Pistache::Rest;
Routes::Get(*router, base + "/modify/AMFIP/:AmfIp/:AmfPort", Routes::bind(&PluginApi::modify_AmfIP_handler, this)); Routes::Get(*router, base + "/modify/AMFIP/:AmfIp/:AmfPort", Routes::bind(&PluginApi::modify_AmfIP_handler, this));
Routes::Post(*router, base + "/create/AmfIpList", Routes::bind(&PluginApi::create_AmfIpList_handler, this));
// Routes::Delete(*router, base + "/:realmId/:storageId/records/:recordId", Routes::bind(&PluginApi::delete_record_handler, this)); // Routes::Delete(*router, base + "/:realmId/:storageId/records/:recordId", Routes::bind(&PluginApi::delete_record_handler, this));
// Routes::Get(*router, base + "/:realmId/:storageId/records/:recordId/meta", Routes::bind(&PluginApi::get_meta_handler, this)); // Routes::Get(*router, base + "/:realmId/:storageId/records/:recordId/meta", Routes::bind(&PluginApi::get_meta_handler, this));
// Routes::Get(*router, base + "/:realmId/:storageId/records/:recordId", Routes::bind(&PluginApi::get_record_handler, this)); // Routes::Get(*router, base + "/:realmId/:storageId/records/:recordId", Routes::bind(&PluginApi::get_record_handler, this));
...@@ -68,7 +69,7 @@ void PluginApi::algorithm_omf_handler(const Pistache::Rest::Request &request, Pi ...@@ -68,7 +69,7 @@ void PluginApi::algorithm_omf_handler(const Pistache::Rest::Request &request, Pi
auto amf_id = request.param(":amf-id").as<std::uint32_t>(); auto amf_id = request.param(":amf-id").as<std::uint32_t>();
Logger::plugin_server().debug("Receiving algorithm-omf info from amf-%d",amf_id); Logger::plugin_server().debug("Receiving algorithm-omf info from amf-%d",amf_id);
Logger::plugin_server().debug("%s",request.body().c_str()); Logger::plugin_server().debug("%s",request.body().c_str());
TransData transdata; TransData transdata;
try { try {
nlohmann::json::parse(request.body()).get_to(transdata); nlohmann::json::parse(request.body()).get_to(transdata);
Logger::plugin_server().debug("ip address : %s",transdata.ip_addr.c_str()); Logger::plugin_server().debug("ip address : %s",transdata.ip_addr.c_str());
...@@ -242,7 +243,7 @@ void PluginApi::N2_trans_handler(const Pistache::Rest::Request &request, Pistach ...@@ -242,7 +243,7 @@ void PluginApi::N2_trans_handler(const Pistache::Rest::Request &request, Pistach
auto assoc_id = request.param(":assoid").as<std::uint32_t>(); auto assoc_id = request.param(":assoid").as<std::uint32_t>();
auto stream = request.param(":stream").as<std::uint16_t>(); auto stream = request.param(":stream").as<std::uint16_t>();
Logger::plugin_server().info("--Put!--assoc_id = (%d), stream = (%d)",assoc_id,stream); Logger::plugin_server().info("-n2trans-handler-Put!--assoc_id = (%d), stream = (%d)",assoc_id,stream);
// SubscriptionData subscriptionData; // SubscriptionData subscriptionData;
...@@ -285,6 +286,33 @@ void PluginApi::modify_AmfIP_handler(const Pistache::Rest::Request &request, Pis ...@@ -285,6 +286,33 @@ void PluginApi::modify_AmfIP_handler(const Pistache::Rest::Request &request, Pis
return; return;
} }
} }
void PluginApi::create_AmfIpList_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
Logger::plugin_server().debug("%s",request.body().c_str());
TransData transdata;
try {
// response.send(Pistache::Http::Code::Ok, "Ok");
amf_ip_list.clear();
nlohmann::json::parse(request.body()).get_to(transdata);
// std::set<nlohmann::json>::iterator iterator;
// for(iterator = request.body().begin();iterator!=request.body().end();)
this->create_AmfIpList(transdata,response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
//send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
} }
} }
} }
......
...@@ -57,10 +57,14 @@ private: ...@@ -57,10 +57,14 @@ private:
// void update_meta_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); // void update_meta_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
// void record_crud_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); // void record_crud_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void modify_AmfIP_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void modify_AmfIP_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void create_AmfIpList_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router; std::shared_ptr<Pistache::Rest::Router> router;
virtual void n2_trans_to_gnb(const std::uint32_t &assoc_id, const uint16_t &stream, TransData &transdata, Pistache::Http::ResponseWriter &response) = 0; virtual void n2_trans_to_gnb(const std::uint32_t &assoc_id, const uint16_t &stream, TransData &transdata, Pistache::Http::ResponseWriter &response) = 0;
virtual void modify_AmfIP(const std::string &amfip, const unsigned int &amfport, Pistache::Http::ResponseWriter &response) = 0; virtual void modify_AmfIP(const std::string &amfip, const unsigned int &amfport, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_AmfIpList(TransData &transdata, Pistache::Http::ResponseWriter &response) = 0;
}; };
......
...@@ -56,6 +56,13 @@ void PluginApiImpl::modify_AmfIP(const std::string &amfip, const unsigned int &a ...@@ -56,6 +56,13 @@ void PluginApiImpl::modify_AmfIP(const std::string &amfip, const unsigned int &a
Logger::plugin_server().info("new amf_ip = (%s), amf_port = (%d)",amf_ip.c_str(),amf_port); Logger::plugin_server().info("new amf_ip = (%s), amf_port = (%d)",amf_ip.c_str(),amf_port);
response.send(Pistache::Http::Code::Ok); response.send(Pistache::Http::Code::Ok);
} }
void PluginApiImpl::create_AmfIpList(TransData &transdata, Pistache::Http::ResponseWriter &response)
{
response.send(Pistache::Http::Code::Ok);
}
} }
} }
} }
......
...@@ -58,6 +58,7 @@ public: ...@@ -58,6 +58,7 @@ public:
void n2_trans_to_gnb(const std::uint32_t &assoc_id, const uint16_t &stream, TransData &transdata,Pistache::Http::ResponseWriter &response); void n2_trans_to_gnb(const std::uint32_t &assoc_id, const uint16_t &stream, TransData &transdata,Pistache::Http::ResponseWriter &response);
void modify_AmfIP(const std::string &amfip, const unsigned int &amfport, Pistache::Http::ResponseWriter &response); void modify_AmfIP(const std::string &amfip, const unsigned int &amfport, Pistache::Http::ResponseWriter &response);
void create_AmfIpList(TransData &transdata, Pistache::Http::ResponseWriter &response);
// void get_meta(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response); // void get_meta(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
// void get_record(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response); // void get_record(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
// void search_record(const std::string &realmId, const std::string &storageId, const Pistache::Optional<int32_t> &limitRange, const Pistache::Optional<SearchExpression> &filter, const Pistache::Optional<bool> &countIndicator, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response); // void search_record(const std::string &realmId, const std::string &storageId, const Pistache::Optional<int32_t> &limitRange, const Pistache::Optional<SearchExpression> &filter, const Pistache::Optional<bool> &countIndicator, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "TransData.hpp" #include "TransData.hpp"
#include <iostream> #include <iostream>
extern std::vector<std::string> amf_ip_list;
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
...@@ -37,6 +40,17 @@ void to_json(nlohmann::json& j, const TransData& o) { ...@@ -37,6 +40,17 @@ void to_json(nlohmann::json& j, const TransData& o) {
void from_json(const nlohmann::json& j, TransData& o) { void from_json(const nlohmann::json& j, TransData& o) {
if(j.find("n2_data") != j.end()) if(j.find("n2_data") != j.end())
j.at("n2_data").get_to(o.m_transdata); j.at("n2_data").get_to(o.m_transdata);
else{
// add amf ip
std::string ipitem;
int i=0;
for (auto& el : j.items()) {
el.value().at("ip").get_to(ipitem);
amf_ip_list.push_back(ipitem);
std::cout << amf_ip_list[i]<<std::endl;
i++;
}
}
if(j.find("ip_address") != j.end()) if(j.find("ip_address") != j.end())
j.at("ip_address").get_to(o.ip_addr); j.at("ip_address").get_to(o.ip_addr);
if(j.find("current_message_queue_len") != j.end()) if(j.find("current_message_queue_len") != j.end())
...@@ -45,6 +59,9 @@ void from_json(const nlohmann::json& j, TransData& o) { ...@@ -45,6 +59,9 @@ void from_json(const nlohmann::json& j, TransData& o) {
j.at("capability").get_to(o.cap); j.at("capability").get_to(o.cap);
std::cout << "capability_dukl"<<std::endl; std::cout << "capability_dukl"<<std::endl;
} }
} }
......
...@@ -27,11 +27,14 @@ ...@@ -27,11 +27,14 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <iostream> #include <iostream>
extern std::vector<std::string> amf_ip_list;
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
namespace model { namespace model {
class TransData { class TransData {
public: public:
TransData(); TransData();
...@@ -45,6 +48,7 @@ class TransData { ...@@ -45,6 +48,7 @@ class TransData {
std::string ip_addr; std::string ip_addr;
long mq_len; long mq_len;
double cap; double cap;
}; };
} // namespace model } // namespace model
......
...@@ -16,6 +16,7 @@ using namespace amf_application; ...@@ -16,6 +16,7 @@ using namespace amf_application;
plugin_config plugin_cfg; plugin_config plugin_cfg;
plugin_app plugin_app_inst; plugin_app plugin_app_inst;
sctp_server * sctp_s_38412 = nullptr; sctp_server * sctp_s_38412 = nullptr;
std::vector<std::string> amf_ip_list;
std::string amf_ip; std::string amf_ip;
unsigned int amf_port; unsigned int amf_port;
......
...@@ -11,6 +11,7 @@ using namespace sctp; ...@@ -11,6 +11,7 @@ using namespace sctp;
using namespace config; using namespace config;
extern sctp_server* sctp_s_38412; extern sctp_server* sctp_s_38412;
extern plugin_config plugin_cfg; extern plugin_config plugin_cfg;
extern std::vector<std::string> amf_ip_list;
extern std::string amf_ip; extern std::string amf_ip;
...@@ -18,7 +19,7 @@ extern unsigned int amf_port; ...@@ -18,7 +19,7 @@ extern unsigned int amf_port;
extern std::map<std::string,long> ip2len; extern std::map<std::string,long> ip2len;
ofstream timestamp_plugin("/home/xgcore/plugin_timestamp.txt"); ofstream timestamp_plugin("/home/xgcore/plugin_timestamp.txt");
string amf_ip_list[15] = {"10.103.239.116","10.103.239.114","10.103.239.112","10.103.238.75","10.103.239.112","10.103.238.72","10.103.239.53","10.103.239.61","10.103.239.63","10.103.238.105","10.103.238.104","10.103.238.103","10.103.238.98","10.103.238.97","10.103.238.96"}; // string amf_ip_list[15] = {"10.103.239.116","10.103.239.114","10.103.239.112","10.103.238.75","10.103.239.112","10.103.238.72","10.103.239.53","10.103.239.61","10.103.239.63","10.103.238.105","10.103.238.104","10.103.238.103","10.103.238.98","10.103.238.97","10.103.238.96"};
int amf_ports[15] = {8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282}; int amf_ports[15] = {8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282};
int weight[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int weight[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
namespace amf_application{ namespace amf_application{
...@@ -41,9 +42,7 @@ static std::size_t callback( ...@@ -41,9 +42,7 @@ static std::size_t callback(
out->append(in, totalBytes); out->append(in, totalBytes);
return totalBytes; return totalBytes;
} }
//string amf_ip_list[15] = {"10.103.239.56","10.103.239.116","10.103.239.114","10.103.239.113","10.103.239.112","10.103.238.72","10.103.239.53","10.103.239.61","10.103.239.63","10.103.238.105","10.103.238.104","10.103.238.103","10.103.238.98","10.103.238.97","10.103.238.96"};
//int amf_ports[15] = {8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282,8282};
//int weight[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int index = -1; int index = -1;
int random_index = 0; int random_index = 0;
int choose = 0; int choose = 0;
...@@ -70,50 +69,50 @@ void plugin_app::handle_receive( ...@@ -70,50 +69,50 @@ void plugin_app::handle_receive(
json_data["n2_data"] = ngapmsg; json_data["n2_data"] = ngapmsg;
std::string url; std::string url;
if(plugin_cfg.is_wrr || plugin_cfg.is_omf){ // if(plugin_cfg.is_wrr || plugin_cfg.is_omf){
Logger::plugin_sbi().debug("Algorithm WRR or OMF"); // Logger::plugin_sbi().debug("Algorithm WRR or OMF");
Logger::plugin_sbi().debug("current weight weight[0]=%d, weight[0]=%d, weight[0]=%d, weight[0]=%d", weight[0],weight[1],weight[2],weight[3]); // Logger::plugin_sbi().debug("current weight weight[0]=%d, weight[0]=%d, weight[0]=%d, weight[0]=%d", weight[0],weight[1],weight[2],weight[3]);
int sum = 0; // int sum = 0;
int index_num = 0; // int index_num = 0;
for(int i=0; i < num_inst; i++) // for(int i=0; i < num_inst; i++)
index_num += weight[i]; // index_num += weight[i];
for(int i=0; i <= choose; i++) // for(int i=0; i <= choose; i++)
sum += weight[i]; // sum += weight[i];
if((index + 1) > sum) // if((index + 1) > sum)
choose = (choose + 1) % num_inst; // choose = (choose + 1) % num_inst;
if((index + 1) > index_num) // if((index + 1) > index_num)
index = 0; // index = 0;
Logger::sctp().debug("Choosing %d th AMF instance ", choose+1); // Logger::sctp().debug("Choosing %d th AMF instance ", choose+1);
url = // url =
"http://" + std::string(amf_ip_list[choose].c_str()) + // "http://" + std::string(amf_ip_list[choose].c_str()) +
":" + std::to_string(amf_ports[choose]) + "/namf-comm/v1/plugin_n2/" + // ":" + std::to_string(amf_ports[choose]) + "/namf-comm/v1/plugin_n2/" +
to_string (assoc_id ) + "/" + to_string (stream) ; // to_string (assoc_id ) + "/" + to_string (stream) ;
} // }
#if 0 // #if 0
srand(time(NULL)); // srand(time(NULL));
random_index = rand()%4; // random_index = rand()%4;
Logger::sctp().debug("Choosing %d th AMF instance ", random_index+1); // Logger::sctp().debug("Choosing %d th AMF instance ", random_index+1);
std::string url = // std::string url =
"http://" + std::string(amf_ip_list[random_index].c_str()) + // "http://" + std::string(amf_ip_list[random_index].c_str()) +
":" + std::to_string(amf_ports[random_index]) + "/namf-comm/v1/plugin_n2/" + // ":" + std::to_string(amf_ports[random_index]) + "/namf-comm/v1/plugin_n2/" +
to_string (assoc_id ) + "/" + to_string (stream) ; // to_string (assoc_id ) + "/" + to_string (stream) ;
#endif // #endif
if(plugin_cfg.is_rr){ // if(plugin_cfg.is_rr){
Logger::plugin_sbi().debug("Algorithm RR "); // Logger::plugin_sbi().debug("Algorithm RR ");
url = url =
"http://" + std::string(amf_ip_list[index % 4].c_str()) + "http://" + std::string(amf_ip_list[index % amf_ip_list.size()].c_str()) +
":" + std::to_string(amf_ports[index % 4]) + "/namf-comm/v1/plugin_n2/" + ":" + std::to_string(8282) + "/namf-comm/v1/plugin_n2/" +
to_string (assoc_id ) + "/" + to_string (stream) ; to_string (assoc_id ) + "/" + to_string (stream) ;
} // }
// #if 0
// url =
// "http://" + std::string(amf_ip_list[0].c_str()) +
// ":" + std::to_string(amf_ports[0]) + "/namf-comm/v1/plugin_n2/" +
// to_string (assoc_id ) + "/" + to_string (stream) ;
// #endif
#if 0 #if 0
url =
"http://" + std::string(amf_ip_list[0].c_str()) +
":" + std::to_string(amf_ports[0]) + "/namf-comm/v1/plugin_n2/" +
to_string (assoc_id ) + "/" + to_string (stream) ;
#endif
#if 1
url = url =
"http://" + std::string(amf_ip.c_str()) + "http://" + std::string(amf_ip.c_str()) +
":" + std::to_string(amf_port) + "/namf-comm/v1/plugin_n2/" + ":" + std::to_string(amf_port) + "/namf-comm/v1/plugin_n2/" +
......
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