mirror of
https://github.com/Telecominfraproject/wlan-cloud-owls.git
synced 2026-01-27 02:22:44 +00:00
Merge branch 'WIFI-12378' of https://github.com/telecominfraproject/wlan-cloud-owls into main
This commit is contained in:
@@ -26,6 +26,12 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
Runner->Reactor().removeEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*Client->Runner_, &SimulationRunner::OnSocketReadable));
|
||||
Runner->Reactor().removeEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*Client->Runner_, &SimulationRunner::OnSocketError));
|
||||
Runner->Reactor().removeEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*Client->Runner_, &SimulationRunner::OnSocketShutdown));
|
||||
(*Client->WS_).close();
|
||||
}
|
||||
Client->Connected_ = false;
|
||||
|
||||
@@ -73,6 +73,12 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
Runner->Reactor().addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketReadable));
|
||||
Runner->Reactor().addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketError));
|
||||
Runner->Reactor().addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketShutdown));
|
||||
Client->Connected_ = true;
|
||||
Runner->AddClientFd(Client->WS_->impl()->sockfd(), Client);
|
||||
Runner->Scheduler().in(std::chrono::seconds(1), Connect, Client, Runner);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
M["params"]["sanity"] = 100;
|
||||
M["params"]["data"] = P;
|
||||
|
||||
if (Client->Send(to_string(M))) {
|
||||
if (Client->SendObject(M)) {
|
||||
DEBUG_LINE("sent");
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->HealthInterval_),
|
||||
OWLSclientEvents::HealthCheck, Client, Runner);
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_wsping++;
|
||||
try {
|
||||
if (Client->SendWSPing()) {
|
||||
Runner->Scheduler().in(std::chrono::seconds(60 * 4),
|
||||
OWLSclientEvents::WSPing, Client, Runner);
|
||||
return;
|
||||
}
|
||||
Client->WS_->sendFrame(
|
||||
"", 0, Poco::Net::WebSocket::FRAME_OP_PING | Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
Runner->Scheduler().in(std::chrono::seconds(60 * 4),
|
||||
OWLSclientEvents::WSPing, Client, Runner);
|
||||
return;
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
|
||||
@@ -652,9 +652,9 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSclient::SendObject(nlohmann::json &O) {
|
||||
bool OWLSclient::SendObject(const nlohmann::json &O) {
|
||||
try {
|
||||
auto M = to_string(O);
|
||||
std::string M = to_string(O);
|
||||
uint32_t BytesSent = WS_->sendFrame(M.c_str(), M.size());
|
||||
if (BytesSent == M.size()) {
|
||||
DEBUG_LINE("sent");
|
||||
|
||||
@@ -33,10 +33,13 @@ namespace OpenWifi {
|
||||
public:
|
||||
OWLSclient(std::string SerialNumber,
|
||||
Poco::Logger &Logger, SimulationRunner *runner);
|
||||
~OWLSclient() {
|
||||
std::cout << SerialNumber_ << ": Deleting client" << std::endl;
|
||||
}
|
||||
|
||||
bool Send(const std::string &Cmd);
|
||||
bool SendWSPing();
|
||||
bool SendObject(nlohmann::json &O);
|
||||
bool SendObject(const nlohmann::json &O);
|
||||
|
||||
void SetFirmware(const std::string &S = "sim-firmware-1") { Firmware_ = S; }
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <Poco/Net/NetException.h>
|
||||
#include <Poco/Net/SSLException.h>
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
void SimulationRunner::Start() {
|
||||
@@ -62,6 +63,62 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void SimulationRunner::OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto socket = pNf->socket().impl()->sockfd();
|
||||
std::map<std::int64_t, std::shared_ptr<OWLSclient>>::iterator client_hint;
|
||||
std::shared_ptr<OWLSclient> client;
|
||||
|
||||
client_hint = Clients_fd_.find(socket);
|
||||
if (client_hint == end(Clients_fd_)) {
|
||||
poco_warning(Logger_, fmt::format("{}: Invalid socket", socket));
|
||||
return;
|
||||
}
|
||||
client = client_hint->second;
|
||||
Clients_fd_.erase(socket);
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*this, &SimulationRunner::OnSocketReadable));
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*this, &SimulationRunner::OnSocketError));
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*this, &SimulationRunner::OnSocketShutdown));
|
||||
client->fd_ = -1;
|
||||
if(Running_)
|
||||
OWLSclientEvents::Reconnect(client,this);
|
||||
}
|
||||
|
||||
void SimulationRunner::OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
auto socket = pNf->socket().impl()->sockfd();
|
||||
std::map<std::int64_t, std::shared_ptr<OWLSclient>>::iterator client_hint;
|
||||
std::shared_ptr<OWLSclient> client;
|
||||
|
||||
client_hint = Clients_fd_.find(socket);
|
||||
if (client_hint == end(Clients_fd_)) {
|
||||
poco_warning(Logger_, fmt::format("{}: Invalid socket", socket));
|
||||
return;
|
||||
}
|
||||
client = client_hint->second;
|
||||
Clients_fd_.erase(socket);
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*this, &SimulationRunner::OnSocketReadable));
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*this, &SimulationRunner::OnSocketError));
|
||||
Reactor_.removeEventHandler(
|
||||
*client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*this, &SimulationRunner::OnSocketShutdown));
|
||||
client->fd_ = -1;
|
||||
if(Running_)
|
||||
OWLSclientEvents::Reconnect(client,this);
|
||||
}
|
||||
|
||||
void SimulationRunner::OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf) {
|
||||
std::map<std::int64_t, std::shared_ptr<OWLSclient>>::iterator client_hint;
|
||||
std::shared_ptr<OWLSclient> client;
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace OpenWifi {
|
||||
CensusReport & Report() { return CensusReport_; }
|
||||
|
||||
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf);
|
||||
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf);
|
||||
void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf);
|
||||
|
||||
const std::string & Id() const { return Id_; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user