Commit 6f4baad5 authored by Fang-WANG's avatar Fang-WANG

notify ip ok, but can't support 2 nofity in a short time

parent 4455c072
build/* build/smf/build
build/log
src/minimal-ws-server/build/* src/minimal-ws-server/build/*
.vscode
json @ 350ff4f7
Subproject commit 350ff4f7ced7c4117eae2fb93df02823c8021fcb
nghttp2 @ 43ba3125
Subproject commit 43ba3125932c1d56addaeded2b7f62637af255cd
pistache @ e18ed9ba
Subproject commit e18ed9baeb2145af6f9ea41246cf48054ffd9907
spdlog @ a51b4856
Subproject commit a51b4856377a71f81b6d74b9af459305c4c644f8
...@@ -415,13 +415,12 @@ void xgpp_conv::data_notification_from_openapi( ...@@ -415,13 +415,12 @@ void xgpp_conv::data_notification_from_openapi(
// Only support UPF for now // Only support UPF for now
// if (nd.getNfProfile().getNfType() == "UPF") // if (nd.getNfProfile().getNfType() == "UPF")
p = std::make_shared<smf::upf_profile>(); p = std::make_shared<smf::upf_profile>();
nlohmann::json pj = {};
to_json(pj, nd.getNfProfile());
p.get()->from_json(pj);
// nlohmann::json pj = {};
// to_json(pj, nd.getNfProfile());
// p.get()->from_json(pj);
p.get()->set_nf_type(nd.getNfProfile().getNfType());
p.get()->set_nf_status(nd.getNfProfile().getNfStatus());
dn_msg.set_profile(p); dn_msg.set_profile(p);
} }
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
Chat is sent to all browsers open on this page. Chat is sent to all browsers open on this page.
<br> <br>
<br> <br>
<textarea id=r readonly cols=40 rows=10></textarea><br> <textarea id=r readonly cols=200 rows=10></textarea><br>
<input type="text" id=m cols=40 rows=1> <input type="text" id=m cols=200 rows=1>
<button id=b>Send</button> <button id=b>Send</button>
</body> </body>
</html> </html>
......
...@@ -59,26 +59,29 @@ __minimal_destroy_message(void *_msg) ...@@ -59,26 +59,29 @@ __minimal_destroy_message(void *_msg)
msg->len = 0; msg->len = 0;
} }
struct per_vhost_data__minimal *first_vhd = NULL; static int notifying = 0;
struct lws *wsi_client = NULL;
int update_client(int len, const char* payload) int update_client(int len, const char* payload)
{ {
lwsl_user("update_client %d. \n",len); char sendArr[1000];
first_vhd->amsg.len = len; if (notifying != 0)
/* notice we over-allocate by LWS_PRE */ return 0;
first_vhd->amsg.payload = malloc(LWS_PRE + len); if (len > 1000)
if (!first_vhd->amsg.payload) { return 0;
lwsl_user("OOM: dropping\n"); if (wsi_client == NULL)
return; return 0;
notifying = 1;
lwsl_user("update_client size %d. %s.\n",len,payload);
memcpy(sendArr + LWS_PRE, payload, len);
/* notice we allowed for LWS_PRE in the payload already */
int m = lws_write(wsi_client, sendArr + LWS_PRE, len, LWS_WRITE_TEXT);
if (m < len) {
lwsl_err("ERROR %d writing to ws\n", m);
} }
notifying = 0;
int client_num = 0; return (m-len);
memcpy((char *)first_vhd->amsg.payload + LWS_PRE, payload, len);
lws_start_foreach_llp(struct per_session_data__minimal **,
ppss, first_vhd->pss_list) {
lws_callback_on_writable((*ppss)->wsi);
lwsl_user("lws_callback_on_writable client %d. \n",client_num++);
} lws_end_foreach_llp(ppss, pss_list);
} }
static int static int
...@@ -95,30 +98,34 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, ...@@ -95,30 +98,34 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
switch (reason) { switch (reason) {
case LWS_CALLBACK_PROTOCOL_INIT: case LWS_CALLBACK_PROTOCOL_INIT:
lwsl_user("LWS_CALLBACK_PROTOCOL_INIT \n");
vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),
lws_get_protocol(wsi), lws_get_protocol(wsi),
sizeof(struct per_vhost_data__minimal)); sizeof(struct per_vhost_data__minimal));
vhd->context = lws_get_context(wsi); vhd->context = lws_get_context(wsi);
vhd->protocol = lws_get_protocol(wsi); vhd->protocol = lws_get_protocol(wsi);
vhd->vhost = lws_get_vhost(wsi); vhd->vhost = lws_get_vhost(wsi);
first_vhd = vhd;
break; break;
case LWS_CALLBACK_ESTABLISHED: case LWS_CALLBACK_ESTABLISHED:
lwsl_user("LWS_CALLBACK_ESTABLISHED \n");
/* add ourselves to the list of live pss held in the vhd */ /* add ourselves to the list of live pss held in the vhd */
lws_ll_fwd_insert(pss, pss_list, vhd->pss_list); lws_ll_fwd_insert(pss, pss_list, vhd->pss_list);
pss->wsi = wsi; pss->wsi = wsi;
pss->last = vhd->current; pss->last = vhd->current;
wsi_client = wsi;
break; break;
case LWS_CALLBACK_CLOSED: case LWS_CALLBACK_CLOSED:
lwsl_user("LWS_CALLBACK_CLOSED \n");
/* remove our closing pss from the list of live pss */ /* remove our closing pss from the list of live pss */
lws_ll_fwd_remove(struct per_session_data__minimal, pss_list, lws_ll_fwd_remove(struct per_session_data__minimal, pss_list,
pss, vhd->pss_list); pss, vhd->pss_list);
wsi_client = NULL;
break; break;
case LWS_CALLBACK_SERVER_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE:
lwsl_user("LWS_CALLBACK_SERVER_WRITEABLE len %d",vhd->amsg.len); lwsl_user("LWS_CALLBACK_SERVER_WRITEABLE len %d %p \n",vhd->amsg.len,vhd->amsg.payload);
if (!vhd->amsg.payload) if (!vhd->amsg.payload)
break; break;
...@@ -137,6 +144,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, ...@@ -137,6 +144,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
break; break;
case LWS_CALLBACK_RECEIVE: case LWS_CALLBACK_RECEIVE:
lwsl_user("LWS_CALLBACK_RECEIVE len %d \n",vhd->amsg.len);
if (vhd->amsg.payload) if (vhd->amsg.payload)
__minimal_destroy_message(&vhd->amsg); __minimal_destroy_message(&vhd->amsg);
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "smf_n4.hpp" #include "smf_n4.hpp"
#include "smf_paa_dynamic.hpp" #include "smf_paa_dynamic.hpp"
#include "string.hpp" #include "string.hpp"
#include "../../build/ext/json/test/thirdparty/fifo_map/fifo_map.hpp"
extern "C" { extern "C" {
#include "dynamic_memory_check.h" #include "dynamic_memory_check.h"
...@@ -68,6 +69,12 @@ extern "C" { ...@@ -68,6 +69,12 @@ extern "C" {
} }
using namespace smf; using namespace smf;
using namespace nlohmann;
template<class K, class V, class dummy_compare, class A>
// A workaround to give to use fifo_map as map, we are just ignoring the 'less' compare
using my_workaround_fifo_map = fifo_map<K, V, fifo_map_compare<K>, A>;
using my_json = basic_json<my_workaround_fifo_map>;
extern util::async_shell_cmd* async_shell_cmd_inst; extern util::async_shell_cmd* async_shell_cmd_inst;
extern smf_app* smf_app_inst; extern smf_app* smf_app_inst;
...@@ -1292,12 +1299,21 @@ bool smf_app::handle_nf_status_notification( ...@@ -1292,12 +1299,21 @@ bool smf_app::handle_nf_status_notification(
std::shared_ptr<nf_profile> profile = {}; std::shared_ptr<nf_profile> profile = {};
notification_msg.get_profile(profile); notification_msg.get_profile(profile);
Logger::smf_app().debug( my_json json_data = {};
"handle_nf_status_notification NF %s is %s !", profile.get()->get_nf_type().c_str(), event_type.c_str()); json_data["nfInstanceName"] = profile.get()->get_nf_instance_name().c_str();
json_data["nfEvent"] = event_type.c_str();
nlohmann::json json_data = {}; json_data["nfStatus"] = profile.get()->get_nf_status().c_str();
json_data["nfStatus"] = event_type.c_str(); json_data["nfInstanceId"] = profile.get()->get_nf_instance_id().c_str();
json_data["nfType"] = profile.get()->get_nf_type().c_str(); json_data["nfType"] = profile.get()->get_nf_type().c_str();
json_data["ipv4Addresses"] = nlohmann::json::array();
std::vector<struct in_addr> nfIpv4Addresses;
profile.get()->get_nf_ipv4_addresses(nfIpv4Addresses);
for (auto address : nfIpv4Addresses) {
json_data["ipv4Addresses"].push_back(inet_ntoa(address));
}
Logger::smf_app().error(
"json_data %s \n",json_data.dump().c_str());
update_client(json_data.dump().length(),json_data.dump().c_str()); update_client(json_data.dump().length(),json_data.dump().c_str());
return true; return true;
} }
......
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