mirror of
https://github.com/Telecominfraproject/wlan-cloud-owls.git
synced 2026-01-11 22:45:12 +00:00
Compare commits
177 Commits
WIFI-12378
...
v2.9.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64ba6f4d67 | ||
|
|
3d83d6a80e | ||
|
|
43cae660de | ||
|
|
d71be33cc3 | ||
|
|
965ea73a13 | ||
|
|
faa678d4e7 | ||
|
|
3c2503bc79 | ||
|
|
e8d11c8631 | ||
|
|
c0eda00485 | ||
|
|
43ee46ea8a | ||
|
|
9584e1833c | ||
|
|
ba0ae691bf | ||
|
|
9dc9d11bce | ||
|
|
c9f692a067 | ||
|
|
b8f7e8528e | ||
|
|
3cf1013fcb | ||
|
|
69772aaef2 | ||
|
|
9382999719 | ||
|
|
06e69405c0 | ||
|
|
bcaee74193 | ||
|
|
260543096d | ||
|
|
c11de3598f | ||
|
|
1173e5b088 | ||
|
|
be893a0b08 | ||
|
|
eeec24cd11 | ||
|
|
bf8d73c947 | ||
|
|
06fffea197 | ||
|
|
39f012a429 | ||
|
|
4a1e4d9cba | ||
|
|
b8d5f9e2b4 | ||
|
|
033f67fac4 | ||
|
|
9c75e989b5 | ||
|
|
0d5c42fe9f | ||
|
|
adfbd2d52b | ||
|
|
93aa2e300f | ||
|
|
218da6d7d5 | ||
|
|
f0fea163e4 | ||
|
|
dc90ad1698 | ||
|
|
d13526606d | ||
|
|
45126be0dc | ||
|
|
cf0677910f | ||
|
|
475522d5dc | ||
|
|
7be435a27b | ||
|
|
487a038903 | ||
|
|
e4fd1c4f7e | ||
|
|
3c529dbba0 | ||
|
|
94636ea1dc | ||
|
|
b4b2b08336 | ||
|
|
fda78a1d8b | ||
|
|
f4e7c212fa | ||
|
|
77c46ad267 | ||
|
|
8b67aa61c0 | ||
|
|
f2fdf68130 | ||
|
|
9edba2c9c7 | ||
|
|
e427b4cd25 | ||
|
|
81c872151b | ||
|
|
18257c8247 | ||
|
|
a51746f396 | ||
|
|
0057483346 | ||
|
|
3163684eac | ||
|
|
1033985339 | ||
|
|
e07d472142 | ||
|
|
8e0a21fd9a | ||
|
|
26f49c254f | ||
|
|
d9ecc1aac7 | ||
|
|
b7ba377a0c | ||
|
|
91e27fe0c4 | ||
|
|
28f4ea5145 | ||
|
|
e98c8f2340 | ||
|
|
132bbfc597 | ||
|
|
03e0031429 | ||
|
|
a2d44f3d64 | ||
|
|
1de06904c6 | ||
|
|
8b570d8d62 | ||
|
|
d0106a9687 | ||
|
|
3bbe5e2d1b | ||
|
|
eff23f22d9 | ||
|
|
5bc6232a89 | ||
|
|
aefd6ccf37 | ||
|
|
eafe534aad | ||
|
|
50b8113d18 | ||
|
|
050ad3c3d3 | ||
|
|
6c8fa9dba7 | ||
|
|
d719d9b9ce | ||
|
|
6f52e8bf85 | ||
|
|
259d2722dc | ||
|
|
eedfce997d | ||
|
|
0dbe8e2c81 | ||
|
|
1899728e21 | ||
|
|
28e6362b32 | ||
|
|
7bd9fe147f | ||
|
|
c8002c55ea | ||
|
|
f978ff0f06 | ||
|
|
1d61ee6539 | ||
|
|
acdce83ef9 | ||
|
|
f44d135acf | ||
|
|
f199cbdaec | ||
|
|
0eef450565 | ||
|
|
1c4bd5835c | ||
|
|
2129861184 | ||
|
|
dbf8fd4a9d | ||
|
|
3b8efb40ef | ||
|
|
bb23cb22ad | ||
|
|
716cf134f1 | ||
|
|
0b8d7fdc5c | ||
|
|
01d099c586 | ||
|
|
21df075a8a | ||
|
|
6f710c0344 | ||
|
|
7eb9e0c6cd | ||
|
|
ffaf5428d1 | ||
|
|
ae508dcfd6 | ||
|
|
8fe56ded3a | ||
|
|
1f2c3f609c | ||
|
|
051612334d | ||
|
|
52225e355b | ||
|
|
a17a5ec74b | ||
|
|
856f868af9 | ||
|
|
d7dc336fa9 | ||
|
|
cf50a7125a | ||
|
|
0164794f50 | ||
|
|
389743a6d0 | ||
|
|
75a491d2dd | ||
|
|
3cd669f4a3 | ||
|
|
61b5f9bf3a | ||
|
|
656b32f1db | ||
|
|
55871aa07e | ||
|
|
ea8bdb1f65 | ||
|
|
b266e5f450 | ||
|
|
96e89ba0dd | ||
|
|
cbc7c8c564 | ||
|
|
a8963de508 | ||
|
|
bf10713b7f | ||
|
|
9a0156dea9 | ||
|
|
47092ac303 | ||
|
|
d7d487856d | ||
|
|
00f4be21ff | ||
|
|
2f57241432 | ||
|
|
7035049b7d | ||
|
|
d28056a43c | ||
|
|
d9c8274bee | ||
|
|
9ff09e8a13 | ||
|
|
987abb64ab | ||
|
|
265cd1ed5c | ||
|
|
dcad05dd85 | ||
|
|
0499fb51dc | ||
|
|
10a55031e4 | ||
|
|
fe23a777d0 | ||
|
|
1f0fa3ae6c | ||
|
|
7ae8498b18 | ||
|
|
5afac8092e | ||
|
|
2615d0113a | ||
|
|
641ab1ad50 | ||
|
|
8300d387f4 | ||
|
|
44efafa206 | ||
|
|
82e8f3373c | ||
|
|
2e59557b3e | ||
|
|
e39e58b09b | ||
|
|
0118650be6 | ||
|
|
85858d40b9 | ||
|
|
1e77c7a746 | ||
|
|
2493511ad6 | ||
|
|
1310865a70 | ||
|
|
9d77130c5d | ||
|
|
b0a59f97e5 | ||
|
|
d4e8b468e9 | ||
|
|
6cf96051bc | ||
|
|
e0bae5e975 | ||
|
|
4ed5cda4d0 | ||
|
|
6059927eea | ||
|
|
90738bcc29 | ||
|
|
f36ede98dc | ||
|
|
54079e014a | ||
|
|
39abb170dd | ||
|
|
bccbbf685d | ||
|
|
7fc9273484 | ||
|
|
43f3dff19b | ||
|
|
9d21987fd1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -37,6 +37,7 @@ git_rsa
|
||||
/cmake-build/
|
||||
/cmake-build-debug/
|
||||
/data/
|
||||
/owls.properties.good
|
||||
|
||||
# Helm
|
||||
*.swp
|
||||
|
||||
2
.idea/.name
generated
2
.idea/.name
generated
@@ -1 +1 @@
|
||||
ucentral_clnt
|
||||
owls
|
||||
@@ -108,6 +108,7 @@ add_executable( owls
|
||||
src/framework/RESTAPI_PartHandler.h
|
||||
src/framework/MicroService.cpp
|
||||
src/framework/MicroServiceExtra.h
|
||||
src/framework/default_device_types.h
|
||||
src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp
|
||||
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
|
||||
src/RESTObjects/RESTAPI_FMSObjects.h src/RESTObjects/RESTAPI_FMSObjects.cpp
|
||||
@@ -115,7 +116,6 @@ add_executable( owls
|
||||
src/RESTObjects/RESTAPI_OWLSobjects.cpp src/RESTObjects/RESTAPI_OWLSobjects.h
|
||||
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
|
||||
src/RESTObjects/RESTAPI_AnalyticsObjects.cpp src/RESTObjects/RESTAPI_AnalyticsObjects.h
|
||||
|
||||
src/RESTAPI/RESTAPI_routers.cpp
|
||||
src/Daemon.cpp src/Daemon.h
|
||||
src/Dashboard.cpp src/Dashboard.h
|
||||
|
||||
1450
cmake-build/Makefile
1450
cmake-build/Makefile
File diff suppressed because it is too large
Load Diff
@@ -146,12 +146,6 @@ components:
|
||||
- $ref: '#/components/schemas/StringList'
|
||||
- $ref: '#/components/schemas/TagValuePairList'
|
||||
|
||||
SystemCommandResults:
|
||||
type: object
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/StringList'
|
||||
- $ref: '#/components/schemas/TagValuePairList'
|
||||
|
||||
SystemInfoResults:
|
||||
type: object
|
||||
properties:
|
||||
@@ -180,6 +174,33 @@ components:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
SystemResources:
|
||||
type: object
|
||||
properties:
|
||||
numberOfFileDescriptors:
|
||||
type: integer
|
||||
format: int64
|
||||
currRealMem:
|
||||
type: integer
|
||||
format: int64
|
||||
peakRealMem:
|
||||
type: integer
|
||||
format: int64
|
||||
currVirtMem:
|
||||
type: integer
|
||||
format: int64
|
||||
peakVirtMem:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
SystemCommandResults:
|
||||
type: object
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/SystemResources'
|
||||
- $ref: '#/components/schemas/SystemInfoResults'
|
||||
- $ref: '#/components/schemas/StringList'
|
||||
- $ref: '#/components/schemas/TagValuePairList'
|
||||
|
||||
SystemCommandSetLogLevel:
|
||||
type: object
|
||||
properties:
|
||||
@@ -453,6 +474,7 @@ paths:
|
||||
type: string
|
||||
format: uuid
|
||||
required: true
|
||||
example: must be set to 0 to create a new simulation
|
||||
requestBody:
|
||||
description: Simulation details
|
||||
content:
|
||||
@@ -685,18 +707,12 @@ paths:
|
||||
type: string
|
||||
enum:
|
||||
- info
|
||||
- extraConfiguration
|
||||
- resources
|
||||
required: true
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: Successful command execution
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/SystemInfoResults'
|
||||
400:
|
||||
$ref: '#/components/responses/BadRequest'
|
||||
$ref: '#/components/schemas/SystemCommandResults'
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
404:
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
// Arilia Wireless Inc.
|
||||
//
|
||||
|
||||
#include <Poco/Net/SSLManager.h>
|
||||
#include <framework/UI_WebSocketClientServer.h>
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "SimStats.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
#include "Poco/Net/SSLManager.h"
|
||||
#include "UI_Owls_WebSocketNotifications.h"
|
||||
#include "framework/UI_WebSocketClientServer.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class Daemon *Daemon::instance_ = nullptr;
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <framework/MicroService.h>
|
||||
#include <framework/MicroServiceNames.h>
|
||||
|
||||
#include "Dashboard.h"
|
||||
#include "framework/MicroService.h"
|
||||
#include "framework/MicroServiceNames.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// Created by stephane bourque on 2021-07-21.
|
||||
//
|
||||
|
||||
#include "Dashboard.h"
|
||||
#include "framework/utils.h"
|
||||
#include <framework/utils.h>
|
||||
#include <Dashboard.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
void OWLSDashboard::Create() {
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// Created by stephane bourque on 2021-07-21.
|
||||
//
|
||||
|
||||
#ifndef UCENTRALGW_DASHBOARD_H
|
||||
#define UCENTRALGW_DASHBOARD_H
|
||||
#pragma once
|
||||
|
||||
#include "RESTObjects/RESTAPI_OWLSobjects.h"
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include <framework/OpenWifiTypes.h>
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
class OWLSDashboard {
|
||||
@@ -21,4 +20,3 @@ namespace OpenWifi {
|
||||
};
|
||||
} // namespace OpenWifi
|
||||
|
||||
#endif // UCENTRALGW_DASHBOARD_H
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <framework/MicroServiceFuncs.h>
|
||||
|
||||
#include "OWLS_utils.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -2,19 +2,24 @@
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
/*
|
||||
void Connect(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
|
||||
void Connect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
if(Client->Valid_) {
|
||||
try {
|
||||
Runner->Report().ev_connect++;
|
||||
@@ -36,22 +41,23 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
if (Client->SendObject(ConnectMessage)) {
|
||||
Client->Reset();
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->StatisticsInterval_),
|
||||
OWLSclientEvents::State, Client, Runner);
|
||||
OWLSClientEvents::State, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->HealthInterval_),
|
||||
OWLSclientEvents::HealthCheck, Client, Runner);
|
||||
OWLSClientEvents::HealthCheck, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(MicroServiceRandom(120, 200)),
|
||||
OWLSclientEvents::Log, Client, Runner, 1, "Device started");
|
||||
OWLSClientEvents::Log, Client, Runner, 1, "Device started");
|
||||
Runner->Scheduler().in(std::chrono::seconds(60 * 4),
|
||||
OWLSclientEvents::WSPing, Client, Runner);
|
||||
OWLSClientEvents::WSPing, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(30),
|
||||
OWLSclientEvents::Update, Client, Runner);
|
||||
OWLSClientEvents::Update, Client, Runner);
|
||||
Client->Logger_.information(fmt::format("connect({}): completed.", Client->SerialNumber_));
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client->Logger().log(E);
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error occurred during connection", true);
|
||||
OWLSClientEvents::Disconnect(ClientGuard,Client, Runner, "Error occurred during connection", true);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
#include "OWLSevent.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
|
||||
void CrashLog(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void CrashLog([[
|
||||
maybe_unused]] std::lock_guard<std::mutex> &ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
if(Client->Valid_) {
|
||||
Runner->Report().ev_crashlog++;
|
||||
}
|
||||
|
||||
@@ -1,32 +1,42 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
#include "OWLSevent.h"
|
||||
#include "OWLS_utils.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void Disconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, const std::string &Reason, bool Reconnect) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void Disconnect(const char *context, std::lock_guard<std::mutex> &ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner,
|
||||
const std::string &Reason, bool Reconnect) {
|
||||
|
||||
if(Client->Valid_) {
|
||||
Runner->Report().ev_disconnect++;
|
||||
Client->Disconnect();
|
||||
poco_debug(Client->Logger(),fmt::format("{}: disconnecting. Reason: {}", Client->SerialNumber_, Reason));
|
||||
if(Reconnect) {
|
||||
Runner->Scheduler().in(std::chrono::seconds(OWLSutils::local_random(3, 15)),
|
||||
OWLSclientEvents::EstablishConnection, Client, Runner);
|
||||
} else {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (Client->Valid_) {
|
||||
Client->Disconnect(context, ClientGuard);
|
||||
poco_debug(Client->Logger(),
|
||||
fmt::format("Disconnecting({}): Reason: {}", Client->SerialNumber_, Reason));
|
||||
if (Reconnect) {
|
||||
poco_debug(Client->Logger_, fmt::format( "Reconnecting({}): {}", context, Client->SerialNumber_ ));
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->Backoff()),
|
||||
OWLSClientEvents::EstablishConnection, Client, Runner);
|
||||
} else {
|
||||
// DEBUG_LINE("not reconnecting");
|
||||
}
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
poco_warning(Client->Logger_,fmt::format("Disconnect({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
poco_warning(Client->Logger_,fmt::format("Disconnect({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,22 @@
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void EstablishConnection( const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
void EstablishConnection(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
Poco::URI uri(Runner->Details().gateway);
|
||||
|
||||
Poco::Net::Context::Params P;
|
||||
@@ -47,8 +50,8 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
|
||||
SSL_CTX *SSLCtx = Context->sslContext();
|
||||
if (!SSL_CTX_check_private_key(SSLCtx)) {
|
||||
std::cout << "Wrong Certificate: " << SimulationCoordinator()->GetCertFileName()
|
||||
<< " for " << SimulationCoordinator()->GetKeyFileName() << std::endl;
|
||||
poco_error(Client->Logger_,fmt::format("Wrong Certificate: {} for {}",SimulationCoordinator()->GetCertFileName() ,
|
||||
SimulationCoordinator()->GetKeyFileName()));
|
||||
}
|
||||
|
||||
if (SimulationCoordinator()->GetLevel() == Poco::Net::Context::VERIFY_STRICT) {
|
||||
@@ -60,7 +63,9 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
Request.set("origin", "http://www.websocket.org");
|
||||
Poco::Net::HTTPResponse Response;
|
||||
|
||||
Client->Logger_.information(fmt::format("connecting({}): host={} port={}", Client->SerialNumber_,
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
|
||||
Client->Logger_.information(fmt::format("Connecting({}): host={} port={}", Client->SerialNumber_,
|
||||
uri.getHost(), uri.getPort()));
|
||||
|
||||
try {
|
||||
@@ -71,30 +76,78 @@ namespace OpenWifi::OWLSclientEvents {
|
||||
(*Client->WS_).setNoDelay(true);
|
||||
(*Client->WS_).setBlocking(false);
|
||||
(*Client->WS_).setMaxPayloadSize(128000);
|
||||
Runner->AddClientFd(Client->WS_->impl()->sockfd(), Client);
|
||||
Client->Connected_ = true;
|
||||
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));
|
||||
Runner->Scheduler().in(std::chrono::seconds(1), Connect, Client, Runner);
|
||||
SimStats()->Connect(Runner->Id());
|
||||
if(Connect(ClientGuard, Client, Runner)) {
|
||||
Client->fd_ = Client->WS_->impl()->sockfd();
|
||||
Runner->AddClientFd(Client->fd_, Client);
|
||||
Client->Reactor_.addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketReadable));
|
||||
Client->Reactor_.addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketError));
|
||||
Client->Reactor_.addEventHandler(
|
||||
*Client->WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*Runner, &SimulationRunner::OnSocketShutdown));
|
||||
Client->Connected_ = true;
|
||||
Client->Logger_.information(fmt::format("connecting({}): connected.", Client->SerialNumber_));
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client->Logger_.warning(
|
||||
fmt::format("connecting({}): exception. {}", Client->SerialNumber_, E.displayText()));
|
||||
Runner->Scheduler().in(std::chrono::seconds(60), Reconnect, Client, Runner);
|
||||
fmt::format("Connecting({}): exception. {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
Client->Logger_.warning(
|
||||
fmt::format("connecting({}): std::exception. {}", Client->SerialNumber_, E.what()));
|
||||
Runner->Scheduler().in(std::chrono::seconds(60), Reconnect, Client, Runner);
|
||||
fmt::format("Connecting({}): std::exception. {}", Client->SerialNumber_, E.what()));
|
||||
} catch (...) {
|
||||
Client->Logger_.warning(fmt::format("connecting({}): unknown exception. {}", Client->SerialNumber_));
|
||||
Runner->Scheduler().in(std::chrono::seconds(60), Reconnect, Client, Runner);
|
||||
Client->Logger_.warning(fmt::format("Connecting({}): unknown exception. {}", Client->SerialNumber_));
|
||||
}
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->Backoff()), Reconnect, Client, Runner);
|
||||
}
|
||||
}
|
||||
|
||||
bool Connect([[
|
||||
maybe_unused]] std::lock_guard<std::mutex> & ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
|
||||
try {
|
||||
Runner->Report().ev_connect++;
|
||||
|
||||
Poco::JSON::Object::Ptr ConnectMessage{new Poco::JSON::Object}, Params{new Poco::JSON::Object},
|
||||
TmpCapabilities{new Poco::JSON::Object}, Capabilities{new Poco::JSON::Object}, MacAddr{new Poco::JSON::Object};
|
||||
auto LabelMac = Utils::SerialNumberToInt(Client->SerialNumber_);
|
||||
Params->set("serial", Client->SerialNumber_);
|
||||
Params->set("uuid", Client->UUID_);
|
||||
Params->set("firmware", Client->Firmware_);
|
||||
MacAddr->set("wan", Client->SerialNumber_);
|
||||
MacAddr->set("lan", Utils::SerialToMAC(Utils::IntToSerialNumber(LabelMac + 1)));
|
||||
TmpCapabilities = SimulationCoordinator()->GetSimCapabilitiesPtr();
|
||||
TmpCapabilities->set("label_macaddr", Client->SerialNumber_);
|
||||
TmpCapabilities->set("macaddr", MacAddr);
|
||||
Params->set("capabilities", TmpCapabilities);
|
||||
|
||||
OWLSutils::MakeHeader(ConnectMessage,"connect",Params);
|
||||
|
||||
if (Client->SendObject(__func__, ConnectMessage)) {
|
||||
Client->Reset();
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->StatisticsInterval_ + MicroServiceRandom(5, 15)),
|
||||
OWLSClientEvents::State, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->HealthInterval_ + MicroServiceRandom(5, 15)),
|
||||
OWLSClientEvents::HealthCheck, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(MicroServiceRandom(120, 200)),
|
||||
OWLSClientEvents::Log, Client, Runner, 1, "Device started");
|
||||
Runner->Scheduler().in(std::chrono::seconds(60 * 4 + MicroServiceRandom(5, 15) ),
|
||||
OWLSClientEvents::WSPing, Client, Runner);
|
||||
/* Runner->Scheduler().in(std::chrono::seconds(30),
|
||||
OWLSClientEvents::Update, Client, Runner);
|
||||
*/
|
||||
Client->Logger_.information(fmt::format("connect({}): completed.", Client->SerialNumber_));
|
||||
Client->Backoff_=0;
|
||||
SimStats()->Connect(Runner->Id());
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client->Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,45 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void HealthCheck(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void HealthCheck(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
|
||||
// DEBUG_LINE("start");
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_healthcheck++;
|
||||
try {
|
||||
|
||||
Poco::JSON::Object Message, Params, Data, Memory;
|
||||
Memory.set("memory", 23);
|
||||
Data.set("data", Memory);
|
||||
Params.set(uCentralProtocol::SERIAL, Client->SerialNumber_);
|
||||
Params.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Params.set(uCentralProtocol::SANITY, 100);
|
||||
Params.set(uCentralProtocol::DATA, Data);
|
||||
Poco::JSON::Object::Ptr Message{new Poco::JSON::Object}, Params{new Poco::JSON::Object}, Data{new Poco::JSON::Object}, Memory{new Poco::JSON::Object};
|
||||
Memory->set("memory", 23);
|
||||
Data->set("data", Memory);
|
||||
Params->set(uCentralProtocol::SERIAL, Client->SerialNumber_);
|
||||
Params->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Params->set(uCentralProtocol::SANITY, 100);
|
||||
Params->set(uCentralProtocol::DATA, Data);
|
||||
OWLSutils::MakeHeader(Message, uCentralProtocol::HEALTHCHECK, Params);
|
||||
|
||||
std::cout << Client->SerialNumber_ << " H: " << Client->UUID_ << std::endl;
|
||||
|
||||
if (Client->SendObject(Message)) {
|
||||
if (Client->SendObject(__func__, Message)) {
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->HealthInterval_),
|
||||
OWLSclientEvents::HealthCheck, Client, Runner);
|
||||
OWLSClientEvents::HealthCheck, Client, Runner);
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("HealthCheck({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("HealthCheck({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error while sending HealthCheck", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Runner, "Error while sending HealthCheck", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
|
||||
void KeepAlive(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void KeepAlive(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_keepalive++;
|
||||
try {
|
||||
|
||||
Poco::JSON::Object Message, Params;
|
||||
Params.set("serial", Client->SerialNumber_);
|
||||
Params.set("uuid", Client->UUID_);
|
||||
Poco::JSON::Object::Ptr Message{new Poco::JSON::Object},
|
||||
Params{new Poco::JSON::Object};
|
||||
Params->set("serial", Client->SerialNumber_);
|
||||
Params->set("uuid", Client->UUID_);
|
||||
OWLSutils::MakeHeader(Message,"ping",Params);
|
||||
|
||||
if (Client->SendObject(Message)) {
|
||||
if (Client->SendObject(__func__, Message)) {
|
||||
Runner->Scheduler().in(std::chrono::seconds(Runner->Details().keepAlive),
|
||||
OWLSclientEvents::KeepAlive, Client, Runner);
|
||||
OWLSClientEvents::KeepAlive, Client, Runner);
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("KeepAlive({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("KeepAlive({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error while sending keepalive", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard,Client, Runner, "Error while sending keepalive", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void Log(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void Log(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
if(Client->Valid_ && Client->Connected_ ) {
|
||||
Runner->Report().ev_log++;
|
||||
try {
|
||||
Poco::JSON::Object Message, Params;
|
||||
Params.set("serial", Client->SerialNumber_);
|
||||
Params.set("uuid", Client->UUID_);
|
||||
Params.set("severity", Severity);
|
||||
Params.set("log", LogLine);
|
||||
Poco::JSON::Object::Ptr Message{new Poco::JSON::Object}, Params{new Poco::JSON::Object};
|
||||
Params->set("serial", Client->SerialNumber_);
|
||||
Params->set("uuid", Client->UUID_);
|
||||
Params->set("severity", Severity);
|
||||
Params->set("log", LogLine);
|
||||
OWLSutils::MakeHeader(Message,"log",Params);
|
||||
|
||||
if (Client->SendObject(Message)) {
|
||||
if (Client->SendObject(__func__,Message)) {
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("Log({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("KeLogepAlive({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error while sending a Log event", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard,Client, Runner, "Error while sending a Log event", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
#include "OWLSevent.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void PendingConfig(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void PendingConfig(std::lock_guard<std::mutex> &ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_configpendingchange++;
|
||||
try {
|
||||
Poco::JSON::Object Message, Params;
|
||||
Params.set("serial", Client->SerialNumber_);
|
||||
Params.set("uuid", Client->UUID_);
|
||||
Params.set("active", Client->Active_);
|
||||
Poco::JSON::Object::Ptr Message{new Poco::JSON::Object}, Params{new Poco::JSON::Object};
|
||||
Params->set("serial", Client->SerialNumber_);
|
||||
Params->set("uuid", Client->UUID_);
|
||||
Params->set("active", Client->Active_);
|
||||
OWLSutils::MakeHeader(Message,"cfgpending",Params);
|
||||
|
||||
if (Client->SendObject(Message)) {
|
||||
if (Client->SendObject(__func__,Message)) {
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("PendingConfig({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("PendingConfig({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error while sending ConfigPendingEvent", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Runner, "Error while sending ConfigPendingEvent", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,32 +2,32 @@
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
#include "OWLS_utils.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void Reconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void Reconnect(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
if(Client->Valid_) {
|
||||
Runner->Report().ev_reconnect++;
|
||||
Client->Connected_ = false;
|
||||
Runner->Scheduler().in(std::chrono::seconds(OWLSutils::local_random(3,15)), OWLSclientEvents::EstablishConnection, Client, Runner);
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->Backoff()), OWLSClientEvents::EstablishConnection, Client, Runner);
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("Reconnect({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("Reconnect({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,61 +2,58 @@
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
#include "OWLSdefinitions.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void State(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
void State(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
|
||||
Runner->Report().ev_state++;
|
||||
try {
|
||||
Poco::JSON::Object Message, TempParams, Params;
|
||||
Poco::JSON::Object::Ptr Message{new Poco::JSON::Object}, TempParams{new Poco::JSON::Object}, Params{new Poco::JSON::Object};
|
||||
|
||||
TempParams.set(uCentralProtocol::SERIAL, Client->SerialNumber_);
|
||||
TempParams.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
TempParams.set(uCentralProtocol::STATE, Client->CreateStatePtr());
|
||||
TempParams->set(uCentralProtocol::SERIAL, Client->SerialNumber_);
|
||||
TempParams->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
TempParams->set(uCentralProtocol::STATE, Client->CreateStatePtr());
|
||||
|
||||
std::ostringstream os;
|
||||
TempParams.stringify(os);
|
||||
|
||||
// std::cout << "State: " << os.str() << std::endl;
|
||||
TempParams->stringify(os);
|
||||
|
||||
unsigned long BufSize = os.str().size() + 4000;
|
||||
std::vector<Bytef> Buffer(BufSize);
|
||||
compress(&Buffer[0], &BufSize, (Bytef *)os.str().c_str(), os.str().size());
|
||||
auto CompressedBase64Encoded = OpenWifi::Utils::base64encode(&Buffer[0], BufSize);
|
||||
|
||||
Params.set("compress_64", CompressedBase64Encoded);
|
||||
Params.set("compress_sz", os.str().size());
|
||||
Params->set("compress_64", CompressedBase64Encoded);
|
||||
Params->set("compress_sz", os.str().size());
|
||||
|
||||
OWLSutils::MakeHeader(Message,uCentralProtocol::STATE,Params);
|
||||
|
||||
std::cout << Client->SerialNumber_ << " S: " << Client->UUID_ << std::endl;
|
||||
|
||||
if (Client->SendObject(Message)) {
|
||||
if (Client->SendObject(__func__, Message)) {
|
||||
Runner->Scheduler().in(std::chrono::seconds(Client->StatisticsInterval_),
|
||||
OWLSclientEvents::State, Client, Runner);
|
||||
OWLSClientEvents::State, Client, Runner);
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("State({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("State({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
DEBUG_LINE("failed");
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error sending stats event", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard,Client, Runner, "Error sending stats event", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void Update(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
void Update(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
|
||||
try {
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_update++;
|
||||
Client->Update();
|
||||
Runner->Scheduler().in(std::chrono::seconds(30),
|
||||
OWLSclientEvents::Update, Client, Runner);
|
||||
OWLSClientEvents::Update, Client, Runner);
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("Update({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("Update({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-12.
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimStats.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
|
||||
void WSPing(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner) {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
|
||||
void WSPing(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner) {
|
||||
if(!Runner->Running()) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> ClientGuard(Client->Mutex_);
|
||||
if(Client->Valid_ && Client->Connected_) {
|
||||
Runner->Report().ev_wsping++;
|
||||
try {
|
||||
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);
|
||||
Runner->Scheduler().in(std::chrono::seconds(60 * 3),
|
||||
OWLSClientEvents::WSPing, Client, Runner);
|
||||
return;
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Client->Logger().log(E);
|
||||
poco_warning(Client->Logger_,fmt::format("WSPing({}): exception {}", Client->SerialNumber_, E.displayText()));
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
poco_warning(Client->Logger_,fmt::format("WSPing({}): std::exception {}", Client->SerialNumber_, E.what()));
|
||||
}
|
||||
OWLSclientEvents::Disconnect(Client, Runner, "Error in WSPing", true);
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Runner, "Error in WSPing", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <random>
|
||||
|
||||
#include <framework/MicroServiceFuncs.h>
|
||||
#include <framework/ow_constants.h>
|
||||
|
||||
@@ -205,16 +206,16 @@ namespace OpenWifi {
|
||||
return Channels_2G[std::rand() % Channels_2G.size()];
|
||||
}
|
||||
|
||||
inline void MakeHeader(Poco::JSON::Object &Message, const char *method, const Poco::JSON::Object &Params) {
|
||||
Message.set(uCentralProtocol::JSONRPC, "2.0");
|
||||
Message.set(uCentralProtocol::METHOD, method);
|
||||
Message.set(uCentralProtocol::PARAMS, Params);
|
||||
inline void MakeHeader(Poco::JSON::Object::Ptr Message, const char *method, const Poco::JSON::Object::Ptr &Params) {
|
||||
Message->set(uCentralProtocol::JSONRPC, "2.0");
|
||||
Message->set(uCentralProtocol::METHOD, method);
|
||||
Message->set(uCentralProtocol::PARAMS, Params);
|
||||
}
|
||||
|
||||
inline void MakeRPCHeader(Poco::JSON::Object &Message, std::uint64_t Id, const Poco::JSON::Object &Result) {
|
||||
Message.set(uCentralProtocol::JSONRPC, "2.0");
|
||||
Message.set(uCentralProtocol::ID, Id);
|
||||
Message.set(uCentralProtocol::RESULT, Result);
|
||||
inline void MakeRPCHeader(Poco::JSON::Object::Ptr Message, std::uint64_t Id, const Poco::JSON::Object::Ptr &Result) {
|
||||
Message->set(uCentralProtocol::JSONRPC, "2.0");
|
||||
Message->set(uCentralProtocol::ID, Id);
|
||||
Message->set(uCentralProtocol::RESULT, Result);
|
||||
}
|
||||
|
||||
inline bool is_integer(const std::string &s) {
|
||||
|
||||
@@ -7,30 +7,32 @@
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
#include "OWLS_utils.h"
|
||||
#include <fmt/format.h>
|
||||
#include <Poco/NObserver.h>
|
||||
#include <Poco/Net/HTTPRequest.h>
|
||||
#include <Poco/URI.h>
|
||||
|
||||
#include "Poco/NObserver.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/URI.h"
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "OWLSdefinitions.h"
|
||||
#include "framework/MicroServiceFuncs.h"
|
||||
|
||||
#include "OWLS_utils.h"
|
||||
#include "OWLSclient.h"
|
||||
#include "OWLSdefinitions.h"
|
||||
#include "SimStats.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
OWLSclient::OWLSclient(std::string SerialNumber,
|
||||
Poco::Logger &Logger, SimulationRunner *runner)
|
||||
Poco::Logger &Logger, SimulationRunner *runner,
|
||||
Poco::Net::SocketReactor &R)
|
||||
: Logger_(Logger), SerialNumber_(std::move(SerialNumber)),
|
||||
Memory_(1),
|
||||
Load_(1),
|
||||
Runner_(runner) {
|
||||
Runner_(runner),
|
||||
Reactor_(R) {
|
||||
|
||||
AllInterfaceNames_[ap_interface_types::upstream] = "up0v0";
|
||||
AllInterfaceNames_[ap_interface_types::downstream] = "down0v0";
|
||||
@@ -245,64 +247,66 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
Poco::JSON::Object OWLSclient::CreateLinkStatePtr() {
|
||||
Poco::JSON::Object res;
|
||||
Poco::JSON::Object::Ptr OWLSclient::CreateLinkStatePtr() {
|
||||
Poco::JSON::Object::Ptr res{new Poco::JSON::Object};
|
||||
for (const auto &[interface_type, _] : AllCounters_) {
|
||||
Poco::JSON::Object InterfaceInfo, InterfacePort;
|
||||
InterfaceInfo.set("carrier",1);
|
||||
InterfaceInfo.set("duplex","full");
|
||||
InterfaceInfo.set("speed",1000);
|
||||
InterfacePort.set(AllPortNames_[interface_type],InterfaceInfo);
|
||||
res.set(AllInterfaceRoles_[interface_type], InterfacePort);
|
||||
res->set(AllInterfaceRoles_[interface_type], InterfacePort);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Poco::JSON::Object OWLSclient::CreateStatePtr() {
|
||||
Poco::JSON::Object State,Unit;
|
||||
Poco::JSON::Object::Ptr OWLSclient::CreateStatePtr() {
|
||||
Poco::JSON::Object::Ptr State{new Poco::JSON::Object},Unit{new Poco::JSON::Object};
|
||||
|
||||
auto now = Utils::Now();
|
||||
Memory_.to_json(Unit);
|
||||
Load_.to_json(Unit);
|
||||
Unit.set("localtime", now);
|
||||
Unit.set("uptime", now - StartTime_);
|
||||
Unit.set("temperature", std::vector<std::int64_t> { OWLSutils::local_random(48,58), OWLSutils::local_random(48,58)});
|
||||
Memory_.to_json(*Unit);
|
||||
Load_.to_json(*Unit);
|
||||
Unit->set("localtime", now);
|
||||
Unit->set("uptime", now - StartTime_);
|
||||
Unit->set("temperature", std::vector<std::int64_t> { OWLSutils::local_random(48,58), OWLSutils::local_random(48,58)});
|
||||
|
||||
Poco::JSON::Array RadioArray;
|
||||
Poco::JSON::Array::Ptr RadioArray{new Poco::JSON::Array};
|
||||
for (auto &[_, radio] : AllRadios_) {
|
||||
Poco::JSON::Object doc;
|
||||
radio.to_json(doc);
|
||||
RadioArray.add(doc);
|
||||
RadioArray->add(doc);
|
||||
}
|
||||
|
||||
Poco::JSON::Array all_interfaces;
|
||||
Poco::JSON::Array::Ptr all_interfaces{new Poco::JSON::Array};
|
||||
for (const auto &ap_interface_type :
|
||||
{ap_interface_types::upstream, ap_interface_types::downstream}) {
|
||||
if (AllCounters_.find(ap_interface_type) != AllCounters_.end()) {
|
||||
Poco::JSON::Object current_interface;
|
||||
Poco::JSON::Array ue_clients, up_ssids;
|
||||
Poco::JSON::Object::Ptr current_interface{new Poco::JSON::Object};
|
||||
Poco::JSON::Array::Ptr ue_clients{new Poco::JSON::Array}, up_ssids{new Poco::JSON::Array};
|
||||
uint64_t ssid_num = 0, interfaces = 0;
|
||||
|
||||
for (auto &[interface, associations] : AllAssociations_) {
|
||||
auto &[interface_type, ssid, band] = interface;
|
||||
if (interface_type == ap_interface_type) {
|
||||
Poco::JSON::Array association_list;
|
||||
Poco::JSON::Array::Ptr association_list{new Poco::JSON::Array};
|
||||
std::string bssid;
|
||||
for (auto &association : associations) {
|
||||
bssid = association.bssid;
|
||||
Poco::JSON::Object doc;
|
||||
association.to_json(doc);
|
||||
association_list.add(doc);
|
||||
association_list->add(doc);
|
||||
Poco::JSON::Object ue;
|
||||
ue.set("mac", association.station);
|
||||
ue.set("ipv4_addresses", std::vector<std::string>{association.ipaddr_v4});
|
||||
ue.set("ipv6_addresses", std::vector<std::string>{association.ipaddr_v6});
|
||||
if(interface_type==upstream)
|
||||
if(interface_type==upstream) {
|
||||
ue.set("ports", std::vector<std::string>{"wwan0"});
|
||||
else
|
||||
ue.set("ports", std::vector<std::string>{"wlan0"});
|
||||
}
|
||||
else {
|
||||
ue.set("ports", std::vector<std::string>{"wlan0"});
|
||||
}
|
||||
ue.set("last_seen", 0);
|
||||
ue_clients.add(ue);
|
||||
ue_clients->add(ue);
|
||||
}
|
||||
Poco::JSON::Object ssid_info;
|
||||
ssid_info.set("associations", association_list);
|
||||
@@ -323,13 +327,13 @@ namespace OpenWifi {
|
||||
R.set("$ref",
|
||||
"#/radios/" + std::to_string(AllRadios_[band].index));
|
||||
ssid_info.set("radio", R);
|
||||
up_ssids.add(ssid_info);
|
||||
up_ssids->add(ssid_info);
|
||||
}
|
||||
}
|
||||
current_interface.set("ssids", up_ssids);
|
||||
current_interface->set("ssids", up_ssids);
|
||||
Poco::JSON::Object C;
|
||||
AllCounters_[ap_interface_type].to_json(C);
|
||||
current_interface.set("counters", C);
|
||||
current_interface->set("counters", C);
|
||||
|
||||
// if we have 2 interfaces, then the clients go to the downstream interface
|
||||
// if we only have 1 interface then this is bridged and therefore clients go on the
|
||||
@@ -338,62 +342,69 @@ namespace OpenWifi {
|
||||
ap_interface_type == ap_interface_types::upstream) ||
|
||||
(AllCounters_.size() == 2 &&
|
||||
ap_interface_type == ap_interface_types::downstream)) {
|
||||
Poco::JSON::Array ip_clients;
|
||||
Poco::JSON::Array::Ptr ip_clients{new Poco::JSON::Array};
|
||||
for (const auto &lan_client : AllLanClients_) {
|
||||
Poco::JSON::Object d;
|
||||
lan_client.to_json(d);
|
||||
ip_clients.add(d);
|
||||
ip_clients->add(d);
|
||||
}
|
||||
for (const auto &ue_client : ue_clients) {
|
||||
ip_clients.add(ue_client);
|
||||
for (const auto &ue_client : *ue_clients) {
|
||||
ip_clients->add(ue_client);
|
||||
}
|
||||
current_interface.set("clients", ip_clients);
|
||||
current_interface->set("clients", ip_clients);
|
||||
}
|
||||
current_interface.set("name", AllInterfaceNames_[ap_interface_type]);
|
||||
all_interfaces.add(current_interface);
|
||||
current_interface->set("name", AllInterfaceNames_[ap_interface_type]);
|
||||
all_interfaces->add(current_interface);
|
||||
}
|
||||
}
|
||||
|
||||
State.set("version" , 1 );
|
||||
State.set("radios", RadioArray);
|
||||
State.set("link-state", CreateLinkStatePtr());
|
||||
State.set("unit", Unit);
|
||||
State.set("interfaces", all_interfaces);
|
||||
State->set("version" , 1 );
|
||||
State->set("radios", RadioArray);
|
||||
State->set("link-state", CreateLinkStatePtr());
|
||||
State->set("unit", Unit);
|
||||
State->set("interfaces", all_interfaces);
|
||||
|
||||
return State;
|
||||
}
|
||||
|
||||
void OWLSclient::DoConfigure([[maybe_unused]] std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params) {
|
||||
void OWLSclient::DoConfigure(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params) {
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if (Params->has(uCentralProtocol::SERIAL) &&
|
||||
Params->has(uCentralProtocol::CONFIG) &&
|
||||
Params->has(uCentralProtocol::UUID)) {
|
||||
|
||||
std::string Serial = Params->get(uCentralProtocol::SERIAL);
|
||||
std::uint64_t NewUUID = Params->get(uCentralProtocol::UUID);
|
||||
std::cout << Client->SerialNumber_ << " C: " << Client->UUID_ << " New: " << NewUUID << std::endl;
|
||||
auto Configuration = Params->getObject("config");
|
||||
Client->UUID_ = Client->Active_ = NewUUID;
|
||||
Client->CurrentConfig_ = Configuration;
|
||||
|
||||
auto Metrics = Configuration->getObject("metrics");
|
||||
auto Health = Metrics->getObject("health");
|
||||
Client->HealthInterval_ = Health->get("interval");
|
||||
auto Statistics = Metrics->getObject("statistics");
|
||||
Client->StatisticsInterval_ = Statistics->get("interval");
|
||||
if(Configuration->isObject("metrics")) {
|
||||
auto Metrics = Configuration->getObject("metrics");
|
||||
if(Metrics->isObject("health")) {
|
||||
auto Health = Metrics->getObject("health");
|
||||
Client->HealthInterval_ = Health->get("interval");
|
||||
}
|
||||
if(Metrics->isObject("statistics")) {
|
||||
auto Statistics = Metrics->getObject("statistics");
|
||||
Client->StatisticsInterval_ = Statistics->get("interval");
|
||||
}
|
||||
}
|
||||
|
||||
// prepare response...
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set(uCentralProtocol::ERROR, 0);
|
||||
Status.set(uCentralProtocol::TEXT, "Success");
|
||||
Result.set(uCentralProtocol::SERIAL, Serial);
|
||||
Result.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result.set(uCentralProtocol::STATUS, Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set(uCentralProtocol::ERROR, 0);
|
||||
Status->set(uCentralProtocol::TEXT, "Success");
|
||||
Result->set(uCentralProtocol::SERIAL, Serial);
|
||||
Result->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result->set(uCentralProtocol::STATUS, Status);
|
||||
OWLSutils::MakeRPCHeader(Answer, Id, Result);
|
||||
poco_information(Client->Logger_,fmt::format("configure({}): done.", Client->SerialNumber_));
|
||||
// std::this_thread::sleep_for(std::chrono::seconds(OWLSutils::local_random(10,30)));
|
||||
Client->SendObject(Answer);
|
||||
if(!Client->SendObject(__func__,Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: configure - failed.", true);
|
||||
}
|
||||
} else {
|
||||
poco_warning(Client->Logger_,fmt::format("configure({}): Illegal command.", Client->SerialNumber_));
|
||||
}
|
||||
@@ -406,47 +417,54 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void OWLSclient::Disconnect() {
|
||||
void OWLSclient::Disconnect(const char *context, [[maybe_unused]] std::lock_guard<std::mutex> &Guard) {
|
||||
if(fd_!=-1) {
|
||||
Runner_->RemoveClientFd(fd_);
|
||||
fd_ = -1;
|
||||
}
|
||||
if(Valid_) {
|
||||
Runner_->Report().ev_disconnect++;
|
||||
SimStats()->Disconnect(Runner_->Id());
|
||||
if (Connected_) {
|
||||
Runner_->RemoveClientFd(fd_);
|
||||
fd_ = -1;
|
||||
Runner_->Reactor().removeEventHandler(
|
||||
Reactor_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<SimulationRunner, Poco::Net::ReadableNotification>(
|
||||
*Runner_, &SimulationRunner::OnSocketReadable));
|
||||
Runner_->Reactor().removeEventHandler(
|
||||
Reactor_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<SimulationRunner, Poco::Net::ErrorNotification>(
|
||||
*Runner_, &SimulationRunner::OnSocketError));
|
||||
Runner_->Reactor().removeEventHandler(
|
||||
Reactor_.removeEventHandler(
|
||||
*WS_, Poco::NObserver<SimulationRunner, Poco::Net::ShutdownNotification>(
|
||||
*Runner_, &SimulationRunner::OnSocketShutdown));
|
||||
(*WS_).close();
|
||||
Connected_ = false;
|
||||
poco_debug(Logger_, fmt::format("Disconnecting a client({}){}: ", context, SerialNumber_));
|
||||
}
|
||||
Connected_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OWLSclient::DoReboot(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params) {
|
||||
void OWLSclient::DoReboot(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params) {
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if (Params->has("serial") && Params->has("when")) {
|
||||
std::string Serial = Params->get("serial");
|
||||
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set(uCentralProtocol::ERROR, 0);
|
||||
Status.set(uCentralProtocol::TEXT, "Success");
|
||||
Result.set(uCentralProtocol::SERIAL, Serial);
|
||||
Result.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result.set(uCentralProtocol::STATUS, Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set(uCentralProtocol::ERROR, 0);
|
||||
Status->set(uCentralProtocol::TEXT, "Success");
|
||||
Result->set(uCentralProtocol::SERIAL, Serial);
|
||||
Result->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result->set(uCentralProtocol::STATUS, Status);
|
||||
|
||||
OWLSutils::MakeRPCHeader(Answer,Id,Result);
|
||||
poco_information(Client->Logger_,fmt::format("reboot({}): done.", Client->SerialNumber_));
|
||||
Client->SendObject(Answer);
|
||||
Client->Disconnect();
|
||||
Client->Reset();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(20));
|
||||
OWLSclientEvents::Disconnect(Client, Client->Runner_, "Command: reboot", true);
|
||||
if(!Client->SendObject(__func__ ,Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: reboot failed", true);
|
||||
} else {
|
||||
Client->Disconnect(__func__, ClientGuard);
|
||||
Client->Reset();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(20));
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: reboot", true);
|
||||
}
|
||||
} else {
|
||||
Client->Logger_.warning(fmt::format("reboot({}): Illegal command.", Client->SerialNumber_));
|
||||
}
|
||||
@@ -473,28 +491,31 @@ namespace OpenWifi {
|
||||
return p;
|
||||
}
|
||||
|
||||
void OWLSclient::DoUpgrade(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params) {
|
||||
void OWLSclient::DoUpgrade(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params) {
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if (Params->has("serial") && Params->has("uri")) {
|
||||
std::string Serial = Params->get("serial");
|
||||
std::string URI = Params->get("uri");
|
||||
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set(uCentralProtocol::ERROR, 0);
|
||||
Status.set(uCentralProtocol::TEXT, "Success");
|
||||
Result.set(uCentralProtocol::SERIAL, Serial);
|
||||
Result.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result.set(uCentralProtocol::STATUS, Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set(uCentralProtocol::ERROR, 0);
|
||||
Status->set(uCentralProtocol::TEXT, "Success");
|
||||
Result->set(uCentralProtocol::SERIAL, Serial);
|
||||
Result->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result->set(uCentralProtocol::STATUS, Status);
|
||||
OWLSutils::MakeRPCHeader(Answer, Id, Result);
|
||||
poco_information(Client->Logger_,fmt::format("upgrade({}): from URI={}.", Client->SerialNumber_, URI));
|
||||
Client->SendObject(Answer);
|
||||
Client->Disconnect();
|
||||
Client->Version_++;
|
||||
Client->SetFirmware(GetFirmware(URI));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(30));
|
||||
Client->Reset();
|
||||
OWLSclientEvents::Disconnect(Client, Client->Runner_, "Command: upgrade", true);
|
||||
if(!Client->SendObject(__func__ , Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: upgrade failed", true);
|
||||
} else {
|
||||
Client->Disconnect(__func__,ClientGuard);
|
||||
Client->Version_++;
|
||||
Client->SetFirmware(GetFirmware(URI));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(30));
|
||||
Client->Reset();
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: upgrade", true);
|
||||
}
|
||||
} else {
|
||||
Client->Logger_.warning(fmt::format("upgrade({}): Illegal command.", Client->SerialNumber_));
|
||||
}
|
||||
@@ -504,30 +525,33 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void OWLSclient::DoFactory(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params) {
|
||||
void OWLSclient::DoFactory(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params) {
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if (Params->has("serial") && Params->has("when")) {
|
||||
std::string Serial = Params->get("serial");
|
||||
|
||||
Client->Version_ = 1;
|
||||
Client->SetFirmware();
|
||||
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set(uCentralProtocol::ERROR, 0);
|
||||
Status.set(uCentralProtocol::TEXT, "Success");
|
||||
Result.set(uCentralProtocol::SERIAL, Serial);
|
||||
Result.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result.set(uCentralProtocol::STATUS, Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set(uCentralProtocol::ERROR, 0);
|
||||
Status->set(uCentralProtocol::TEXT, "Success");
|
||||
Result->set(uCentralProtocol::SERIAL, Serial);
|
||||
Result->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result->set(uCentralProtocol::STATUS, Status);
|
||||
OWLSutils::MakeRPCHeader(Answer, Id, Result);
|
||||
poco_information(Client->Logger_, fmt::format("factory({}): done.", Client->SerialNumber_));
|
||||
Client->SendObject(Answer);
|
||||
Client->Disconnect();
|
||||
Client->CurrentConfig_ = SimulationCoordinator()->GetSimConfigurationPtr(Utils::Now());
|
||||
Client->UpdateConfiguration();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
Client->Reset();
|
||||
OWLSclientEvents::Disconnect(Client, Client->Runner_, "Command: upgrade", true);
|
||||
if(!Client->SendObject(__func__ , Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: factory failed", true);
|
||||
} else {
|
||||
Client->Disconnect(__func__, ClientGuard);
|
||||
Client->CurrentConfig_ = SimulationCoordinator()->GetSimConfigurationPtr(Utils::Now());
|
||||
Client->UpdateConfiguration();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
Client->Reset();
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: upgrade", true);
|
||||
}
|
||||
} else {
|
||||
Client->Logger_.warning(fmt::format("factory({}): Illegal command.", Client->SerialNumber_));
|
||||
}
|
||||
@@ -537,24 +561,26 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void OWLSclient::DoLEDs([[maybe_unused]] std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params) {
|
||||
void OWLSclient::DoLEDs(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params) {
|
||||
std::lock_guard ClientGuard(Client->Mutex_);
|
||||
try {
|
||||
std::lock_guard G(Client->Mutex_);
|
||||
if (Params->has("serial") && Params->has("pattern")) {
|
||||
std::string Serial = Params->get("serial");
|
||||
auto Pattern = Params->get("pattern").toString();
|
||||
uint64_t Duration = Params->has("when") ? (uint64_t)Params->get("durarion") : 10;
|
||||
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set(uCentralProtocol::ERROR, 0);
|
||||
Status.set(uCentralProtocol::TEXT, "Success");
|
||||
Result.set(uCentralProtocol::SERIAL, Serial);
|
||||
Result.set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result.set(uCentralProtocol::STATUS, Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set(uCentralProtocol::ERROR, 0);
|
||||
Status->set(uCentralProtocol::TEXT, "Success");
|
||||
Result->set(uCentralProtocol::SERIAL, Serial);
|
||||
Result->set(uCentralProtocol::UUID, Client->UUID_);
|
||||
Result->set(uCentralProtocol::STATUS, Status);
|
||||
OWLSutils::MakeRPCHeader(Answer, Id, Result);
|
||||
poco_information(Client->Logger_,fmt::format("LEDs({}): pattern set to: {} for {} ms.",
|
||||
Client->SerialNumber_, Duration, Pattern));
|
||||
Client->SendObject(Answer);
|
||||
if(!Client->SendObject(__func__ , Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: LEDs failed", true);
|
||||
}
|
||||
} else {
|
||||
Client->Logger_.warning(fmt::format("LEDs({}): Illegal command.", Client->SerialNumber_));
|
||||
}
|
||||
@@ -563,74 +589,43 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void OWLSclient::UNsupportedCommand(std::shared_ptr<OWLSclient> Client, uint64_t Id,
|
||||
void OWLSclient::UnSupportedCommand([[
|
||||
maybe_unused]] std::lock_guard<std::mutex> &ClientGuard,const std::shared_ptr<OWLSclient> &Client, uint64_t Id,
|
||||
const std::string & Method) {
|
||||
try {
|
||||
Poco::JSON::Object Answer, Result, Status;
|
||||
Status.set("error", 1);
|
||||
Status.set("text", "Command not supported");
|
||||
Result.set("serial", Client->SerialNumber_);
|
||||
Result.set("status", Status);
|
||||
Poco::JSON::Object::Ptr Answer{new Poco::JSON::Object}, Result{new Poco::JSON::Object}, Status{new Poco::JSON::Object};
|
||||
Status->set("error", 1);
|
||||
Status->set("text", "Command not supported");
|
||||
Result->set("serial", Client->SerialNumber_);
|
||||
Result->set("status", Status);
|
||||
OWLSutils::MakeRPCHeader(Answer, Id, Result);
|
||||
poco_information(Logger_,fmt::format("UNSUPPORTED({}): command {} not allowed for simulated devices.",
|
||||
SerialNumber_, Method));
|
||||
SendObject(Answer);
|
||||
if(!SendObject(__func__, Answer)) {
|
||||
OWLSClientEvents::Disconnect(__func__, ClientGuard, Client, Client->Runner_, "Command: unsupported failed", true);
|
||||
}
|
||||
} catch(const Poco::Exception &E) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool OWLSclient::Send(const std::string &Cmd) {
|
||||
|
||||
try {
|
||||
uint32_t BytesSent = WS_->sendFrame(Cmd.c_str(), Cmd.size());
|
||||
if (BytesSent == Cmd.size()) {
|
||||
SimStats()->AddOutMsg(Runner_->Id(),Cmd.size());
|
||||
return true;
|
||||
} else {
|
||||
DEBUG_LINE("fail to send");
|
||||
Logger_.warning(
|
||||
fmt::format("SEND({}): incomplete. Sent: {}", SerialNumber_, BytesSent));
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
Logger_.log(E);
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
bool OWLSclient::SendObject(const char *context, const Poco::JSON::Object::Ptr &Object) {
|
||||
if(!Runner_->Running()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSclient::SendWSPing() {
|
||||
try {
|
||||
WS_->sendFrame(
|
||||
"", 0, Poco::Net::WebSocket::FRAME_OP_PING | Poco::Net::WebSocket::FRAME_FLAG_FIN);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("failed");
|
||||
Logger_.log(E);
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSclient::SendObject(const Poco::JSON::Object &O) {
|
||||
auto os = std::make_unique<std::ostringstream>();
|
||||
try {
|
||||
std::ostringstream os;
|
||||
O.stringify(os);
|
||||
uint32_t BytesSent = WS_->sendFrame(os.str().c_str(), os.str().size());
|
||||
if (BytesSent == os.str().size()) {
|
||||
Object->stringify(*os);
|
||||
uint32_t BytesSent = WS_->sendFrame(os->str().c_str(), os->str().size());
|
||||
if (BytesSent == os->str().size()) {
|
||||
SimStats()->AddOutMsg(Runner_->Id(),BytesSent);
|
||||
return true;
|
||||
} else {
|
||||
DEBUG_LINE("failed");
|
||||
Logger_.warning(
|
||||
fmt::format("SEND({}): incomplete send. Sent: {}", SerialNumber_, BytesSent));
|
||||
std::cout << fmt::format("SendObject({},{}): size={} sent={}", context, SerialNumber_, os->str().size(), BytesSent) << std::endl;
|
||||
Logger_.warning(fmt::format("SendObject({},{}): size={} sent={}", context, SerialNumber_, os->str().size(), BytesSent));
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
DEBUG_LINE("exception1");
|
||||
std::cout << fmt::format("SendObject({},{}): size={} exception={}", context, SerialNumber_, os->str().size(), E.displayText()) << std::endl;
|
||||
Logger_.log(E);
|
||||
} catch (const std::exception &E) {
|
||||
DEBUG_LINE("exception2");
|
||||
|
||||
@@ -9,20 +9,21 @@
|
||||
#include <random>
|
||||
#include <tuple>
|
||||
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Net/SocketNotification.h"
|
||||
#include "Poco/Net/SocketReactor.h"
|
||||
#include "Poco/Net/WebSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <Poco/AutoPtr.h>
|
||||
#include <Poco/JSON/Object.h>
|
||||
#include <Poco/Logger.h>
|
||||
#include <Poco/Net/SocketNotification.h>
|
||||
#include <Poco/Net/SocketReactor.h>
|
||||
#include <Poco/Net/WebSocket.h>
|
||||
#include <Poco/Thread.h>
|
||||
|
||||
#include "framework/utils.h"
|
||||
#include "OWLSdefinitions.h"
|
||||
|
||||
#include "OWLSdefinitions.h"
|
||||
#include "MockElements.h"
|
||||
#include "OWLSclientEvents.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -31,14 +32,14 @@ namespace OpenWifi {
|
||||
class OWLSclient {
|
||||
public:
|
||||
OWLSclient(std::string SerialNumber,
|
||||
Poco::Logger &Logger, SimulationRunner *runner);
|
||||
Poco::Logger &Logger, SimulationRunner *runner, Poco::Net::SocketReactor &R);
|
||||
~OWLSclient() {
|
||||
poco_debug(Logger_,fmt::format("{} simulator client done.", SerialNumber_));
|
||||
}
|
||||
|
||||
bool Send(const std::string &Cmd);
|
||||
bool SendWSPing();
|
||||
bool SendObject(const Poco::JSON::Object &O);
|
||||
// bool Send(const std::string &Cmd);
|
||||
// bool SendWSPing();
|
||||
[[nodiscard]] bool SendObject(const char *context, const Poco::JSON::Object::Ptr &O);
|
||||
void SetFirmware(const std::string &S = "sim-firmware-1") { Firmware_ = S; }
|
||||
|
||||
[[nodiscard]] const std::string &Serial() const { return SerialNumber_; }
|
||||
@@ -48,24 +49,25 @@ namespace OpenWifi {
|
||||
[[nodiscard]] bool Connected() const { return Connected_; }
|
||||
[[nodiscard]] inline uint64_t GetStartTime() const { return StartTime_; }
|
||||
|
||||
static void DoConfigure(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params);
|
||||
static void DoReboot(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params);
|
||||
static void DoUpgrade(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params);
|
||||
static void DoFactory(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params);
|
||||
static void DoLEDs(std::shared_ptr<OWLSclient> Client, uint64_t Id, const Poco::JSON::Object::Ptr Params);
|
||||
void UNsupportedCommand(std::shared_ptr<OWLSclient> Client, uint64_t Id, const std::string &Method);
|
||||
static void DoConfigure(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params);
|
||||
static void DoReboot(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params);
|
||||
static void DoUpgrade(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params);
|
||||
static void DoFactory(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params);
|
||||
static void DoLEDs(const std::shared_ptr<OWLSclient> &Client, uint64_t Id, Poco::JSON::Object::Ptr Params);
|
||||
|
||||
void UnSupportedCommand(std::lock_guard<std::mutex> &G,const std::shared_ptr<OWLSclient> &Client, uint64_t Id, const std::string &Method);
|
||||
|
||||
using interface_location_t = std::tuple<ap_interface_types, std::string, radio_bands>;
|
||||
using associations_map_t = std::map<interface_location_t, MockAssociations>;
|
||||
|
||||
void Disconnect();
|
||||
void Disconnect(const char *context, std::lock_guard<std::mutex> &Guard);
|
||||
|
||||
void CreateAssociations(const interface_location_t &interface,const std::string &bssid, uint64_t min,
|
||||
uint64_t max);
|
||||
void CreateLanClients(uint64_t min, uint64_t max);
|
||||
|
||||
Poco::JSON::Object CreateStatePtr();
|
||||
Poco::JSON::Object CreateLinkStatePtr();
|
||||
Poco::JSON::Object::Ptr CreateStatePtr();
|
||||
Poco::JSON::Object::Ptr CreateLinkStatePtr();
|
||||
|
||||
Poco::Logger &Logger() { return Logger_; };
|
||||
|
||||
@@ -90,21 +92,30 @@ namespace OpenWifi {
|
||||
inline const auto & Load() { return Load_; }
|
||||
|
||||
void Update();
|
||||
[[nodiscard ]] inline auto Backoff() {
|
||||
if(Backoff_>300) {
|
||||
Backoff_ = 15;
|
||||
} else {
|
||||
Backoff_ *=2;
|
||||
}
|
||||
return Backoff_;
|
||||
}
|
||||
|
||||
friend class SimulationRunner;
|
||||
|
||||
friend void OWLSclientEvents::EstablishConnection(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::Reconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::Connect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::Log(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine);
|
||||
friend void OWLSclientEvents::State(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::HealthCheck(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::Update(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::WSPing(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::KeepAlive(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::Disconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, const std::string &Reason, bool Reconnect);
|
||||
friend void OWLSclientEvents::CrashLog(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSclientEvents::PendingConfig(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::EstablishConnection(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::Reconnect(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
// friend void OWLSClientEvents::Connect(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend bool OWLSClientEvents::Connect(std::lock_guard<std::mutex> & ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::Log(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine);
|
||||
friend void OWLSClientEvents::State(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::HealthCheck(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::Update(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::WSPing(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::KeepAlive(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::Disconnect(const char *context, std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner, const std::string &Reason, bool Reconnect);
|
||||
friend void OWLSClientEvents::CrashLog(std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
friend void OWLSClientEvents::PendingConfig(std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
|
||||
private:
|
||||
// std::recursive_mutex Mutex_;
|
||||
@@ -124,13 +135,16 @@ namespace OpenWifi {
|
||||
std::string mac_lan;
|
||||
std::uint64_t HealthInterval_ = 60;
|
||||
std::uint64_t StatisticsInterval_ = 60;
|
||||
uint64_t bssid_index = 1;
|
||||
std::int64_t fd_=-1;
|
||||
uint64_t bssid_index = 1;
|
||||
std::int64_t fd_=-1;
|
||||
|
||||
MockMemory Memory_;
|
||||
MockCPULoad Load_;
|
||||
MockMemory Memory_;
|
||||
MockCPULoad Load_;
|
||||
|
||||
SimulationRunner *Runner_ = nullptr;
|
||||
std::uint16_t Backoff_=0;
|
||||
|
||||
SimulationRunner *Runner_ = nullptr;
|
||||
Poco::Net::SocketReactor &Reactor_;
|
||||
|
||||
MockLanClients AllLanClients_;
|
||||
associations_map_t AllAssociations_;
|
||||
|
||||
@@ -11,17 +11,17 @@ namespace OpenWifi {
|
||||
class SimulationRunner;
|
||||
}
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
void EstablishConnection(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void Reconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void Connect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void State(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void HealthCheck(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void Log(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine);
|
||||
void WSPing(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void Update(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void KeepAlive(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void Disconnect(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner, const std::string &Reason, bool Reconnect);
|
||||
void CrashLog(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
void PendingConfig(std::shared_ptr<OWLSclient> Client, SimulationRunner *Runner);
|
||||
namespace OpenWifi::OWLSClientEvents {
|
||||
void EstablishConnection(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void Reconnect(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
bool Connect(std::lock_guard<std::mutex> & ClientGuard, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void State(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void HealthCheck(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void Log(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner, std::uint64_t Severity, const std::string & LogLine);
|
||||
void WSPing(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void Update(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void KeepAlive(const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void Disconnect(const char *context, std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner, const std::string &Reason, bool Reconnect);
|
||||
void CrashLog(std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
void PendingConfig(std::lock_guard<std::mutex> &g, const std::shared_ptr<OWLSclient> &Client, SimulationRunner *Runner);
|
||||
};
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-04-03.
|
||||
//
|
||||
#include <cstdlib>
|
||||
|
||||
#include "Poco/zlib.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "SimulationCoordinator.h"
|
||||
#include "OWLSevent.h"
|
||||
|
||||
#include "framework/MicroServiceFuncs.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
bool OWLSConnectEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M;
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "connect";
|
||||
M["params"]["serial"] = Client_->Serial();
|
||||
M["params"]["uuid"] = Client_->UUID();
|
||||
M["params"]["firmware"] = Client_->Firmware();
|
||||
auto TmpCapabilities = SimulationCoordinator()->GetSimCapabilities();
|
||||
auto LabelMac = Utils::SerialNumberToInt(Client_->Serial());
|
||||
auto LabelMacFormatted = Utils::SerialToMAC(Utils::IntToSerialNumber(LabelMac));
|
||||
auto LabelLanMacFormatted = Utils::SerialToMAC(Utils::IntToSerialNumber(LabelMac + 1));
|
||||
TmpCapabilities["label_macaddr"] = LabelMac;
|
||||
TmpCapabilities["macaddr"]["wan"] = LabelMac;
|
||||
TmpCapabilities["macaddr"]["lan"] = LabelLanMacFormatted;
|
||||
M["params"]["capabilities"] = TmpCapabilities;
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->Reset();
|
||||
Client_->AddEvent(ev_state,
|
||||
SimulationCoordinator()->GetSimulationInfo().stateInterval);
|
||||
Client_->AddEvent(ev_healthcheck,
|
||||
SimulationCoordinator()->GetSimulationInfo().healthCheckInterval);
|
||||
Client_->AddEvent(ev_log, MicroServiceRandom(120, 200));
|
||||
Client_->AddEvent(ev_wsping, 60 * 5);
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error occurred during connection", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSStateEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M;
|
||||
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "state";
|
||||
|
||||
nlohmann::json ParamsObj;
|
||||
ParamsObj["serial"] = Client_->Serial();
|
||||
ParamsObj["uuid"] = Client_->UUID();
|
||||
ParamsObj["state"] = Client_->CreateState();
|
||||
|
||||
auto ParamsStr = to_string(ParamsObj);
|
||||
|
||||
unsigned long BufSize = ParamsStr.size() + 4000;
|
||||
std::vector<Bytef> Buffer(BufSize);
|
||||
compress(&Buffer[0], &BufSize, (Bytef *)ParamsStr.c_str(), ParamsStr.size());
|
||||
|
||||
auto CompressedBase64Encoded = OpenWifi::Utils::base64encode(&Buffer[0], BufSize);
|
||||
|
||||
M["params"]["compress_64"] = CompressedBase64Encoded;
|
||||
M["params"]["compress_sz"] = ParamsStr.size();
|
||||
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->AddEvent(ev_state, Client_->GetStateInterval());
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error sending stats event", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSHealthCheckEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M, P;
|
||||
|
||||
|
||||
P["memory"] = 23;
|
||||
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "healthcheck";
|
||||
M["params"]["serial"] = Client_->Serial();
|
||||
M["params"]["uuid"] = Client_->UUID();
|
||||
M["params"]["sanity"] = 100;
|
||||
M["params"]["data"] = P;
|
||||
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->AddEvent(ev_healthcheck, Client_->GetHealthInterval());
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error while sending HealthCheck", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSLogEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M;
|
||||
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "log";
|
||||
M["params"]["serial"] = Client_->Serial();
|
||||
M["params"]["uuid"] = Client_->UUID();
|
||||
M["params"]["severity"] = Severity_;
|
||||
M["params"]["log"] = LogLine_;
|
||||
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->AddEvent(ev_log, MicroServiceRandom(300, 600));
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error while sending a Log event", true);
|
||||
return false;
|
||||
};
|
||||
|
||||
bool OWLSCrashLogEvent::Send() { return false; };
|
||||
|
||||
bool OWLSConfigChangePendingEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M;
|
||||
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "cfgpending";
|
||||
M["params"]["serial"] = Client_->Serial();
|
||||
M["params"]["uuid"] = Client_->UUID();
|
||||
M["params"]["active"] = Client_->Active();
|
||||
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->AddEvent(ev_configpendingchange,
|
||||
SimulationCoordinator()->GetSimulationInfo().clientInterval);
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error while sending ConfigPendingEvent", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSKeepAliveEvent::Send() {
|
||||
try {
|
||||
nlohmann::json M;
|
||||
|
||||
M["jsonrpc"] = "2.0";
|
||||
M["method"] = "ping";
|
||||
M["params"]["serial"] = Client_->Serial();
|
||||
M["params"]["uuid"] = Client_->UUID();
|
||||
|
||||
if (Client_->Send(to_string(M))) {
|
||||
Client_->AddEvent(ev_keepalive,
|
||||
SimulationCoordinator()->GetSimulationInfo().keepAlive);
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error while sending keepalive", true);
|
||||
return false;
|
||||
};
|
||||
|
||||
// This is just a fake event, reboot is handled somewhere else.
|
||||
bool OWLSRebootEvent::Send() { return true; }
|
||||
|
||||
// This is just a fake event, disconnect is handled somewhere else.
|
||||
bool OWLSDisconnectEvent::Send() { return true; }
|
||||
|
||||
bool OWLSWSPingEvent::Send() {
|
||||
try {
|
||||
if (Client_->SendWSPing()) {
|
||||
Client_->AddEvent(ev_wsping, 60 * 5);
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
Client_->Disconnect("Error in WSPing", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OWLSUpdate::Send() {
|
||||
try {
|
||||
Client_->Update();
|
||||
} catch (const Poco::Exception &E) {
|
||||
Client_->Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace OpenWifi
|
||||
130
src/OWLSevent.h
130
src/OWLSevent.h
@@ -1,130 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-04-03.
|
||||
//
|
||||
|
||||
#ifndef UCENTRAL_CLNT_OWLSEVENT_H
|
||||
#define UCENTRAL_CLNT_OWLSEVENT_H
|
||||
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "OWLSclient.h"
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "OWLSdefinitions.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class OWLSevent {
|
||||
public:
|
||||
explicit OWLSevent(std::shared_ptr<OWLSclient> Client)
|
||||
: Client_(std::move(Client)) {}
|
||||
virtual bool Send() = 0;
|
||||
|
||||
protected:
|
||||
bool SendObject(Poco::JSON::Object &Obj);
|
||||
std::shared_ptr<OWLSclient> Client_;
|
||||
};
|
||||
|
||||
class OWLSConnectEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSConnectEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSStateEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSStateEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSHealthCheckEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSHealthCheckEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSLogEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSLogEvent(std::shared_ptr<OWLSclient> Client, std::string LogLine,
|
||||
uint64_t Severity)
|
||||
: OWLSevent(std::move(Client)), LogLine_(std::move(LogLine)), Severity_(Severity){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
std::string LogLine_;
|
||||
uint64_t Severity_;
|
||||
};
|
||||
|
||||
class OWLSCrashLogEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSCrashLogEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSConfigChangePendingEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSConfigChangePendingEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSKeepAliveEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSKeepAliveEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSRebootEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSRebootEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSDisconnectEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSDisconnectEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSWSPingEvent : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSWSPingEvent(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class OWLSUpdate : public OWLSevent {
|
||||
public:
|
||||
explicit OWLSUpdate(std::shared_ptr<OWLSclient> Client)
|
||||
: OWLSevent(std::move(Client)){};
|
||||
bool Send() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace OpenWifi
|
||||
|
||||
#endif // UCENTRAL_CLNT_OWLSEVENT_H
|
||||
@@ -9,65 +9,16 @@
|
||||
#include "Poco/Net/HTTPCookie.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "framework/MicroServiceFuncs.h"
|
||||
#include <framework/default_device_types.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
static const std::vector<std::string> DefaultDeviceTypes{"actiontec_web7200",
|
||||
"cig_wf188n",
|
||||
"cig_wf194c",
|
||||
"cig_wf194c4",
|
||||
"cig_wf196",
|
||||
"cig_wf610d",
|
||||
"cig_wf808",
|
||||
"cybertan_eww622-a1",
|
||||
"edgecore_eap101",
|
||||
"edgecore_eap102",
|
||||
"edgecore_eap104",
|
||||
"edgecore_ecs4100-12ph",
|
||||
"edgecore_ecw5211",
|
||||
"edgecore_ecw5410",
|
||||
"edgecore_oap100",
|
||||
"edgecore_spw2ac1200",
|
||||
"edgecore_spw2ac1200-lan-poe",
|
||||
"edgecore_ssw2ac2600",
|
||||
"hfcl_ion4",
|
||||
"hfcl_ion4x",
|
||||
"hfcl_ion4x_2",
|
||||
"hfcl_ion4xe",
|
||||
"hfcl_ion4xi",
|
||||
"indio_um-305ac",
|
||||
"indio_um-305ax",
|
||||
"indio_um-310ax-v1",
|
||||
"indio_um-325ac",
|
||||
"indio_um-510ac-v3",
|
||||
"indio_um-510axm-v1",
|
||||
"indio_um-510axp-v1",
|
||||
"indio_um-550ac",
|
||||
"linksys_e8450-ubi",
|
||||
"linksys_ea6350-v4",
|
||||
"linksys_ea8300",
|
||||
"liteon_wpx8324",
|
||||
"meshpp_s618_cp01",
|
||||
"meshpp_s618_cp03",
|
||||
"tp-link_ec420-g1",
|
||||
"tplink_ex227",
|
||||
"tplink_ex228",
|
||||
"tplink_ex447",
|
||||
"udaya_a5-id2",
|
||||
"wallys_dr40x9",
|
||||
"wallys_dr6018",
|
||||
"wallys_dr6018_v4",
|
||||
"x64_vm",
|
||||
"yuncore_ax840",
|
||||
"yuncore_fap640",
|
||||
"yuncore_fap650"};
|
||||
|
||||
static bool GooDeviceType(const std::string &D) {
|
||||
for (const auto &i : DefaultDeviceTypes) {
|
||||
if (i == D)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
for(const auto &[name,_]:DefaultDeviceTypeList) {
|
||||
if(name==D) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RESTAPI_simulation_handler::DoGet() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#ifdef TIP_GATEWAY_SERVICE
|
||||
#include "AP_WS_Server.h"
|
||||
#include "CapabilitiesCache.h"
|
||||
#include "RADIUSSessionTracker.h"
|
||||
#endif
|
||||
|
||||
#include "RESTAPI_GWobjects.h"
|
||||
@@ -29,6 +30,7 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj, "serialNumber", SerialNumber);
|
||||
#ifdef TIP_GATEWAY_SERVICE
|
||||
field_to_json(Obj, "deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible));
|
||||
field_to_json(Obj, "hasRADIUSSessions", RADIUSSessionTracker()->HasSessions(SerialNumber));
|
||||
#endif
|
||||
field_to_json(Obj, "macAddress", MACAddress);
|
||||
field_to_json(Obj, "manufacturer", Manufacturer);
|
||||
@@ -54,6 +56,9 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj, "pendingConfiguration", pendingConfiguration);
|
||||
field_to_json(Obj, "pendingConfigurationCmd", pendingConfigurationCmd);
|
||||
field_to_json(Obj, "restrictionDetails", restrictionDetails);
|
||||
field_to_json(Obj, "pendingUUID", pendingUUID);
|
||||
field_to_json(Obj, "simulated", simulated);
|
||||
field_to_json(Obj, "lastRecordedContact", lastRecordedContact);
|
||||
}
|
||||
|
||||
void Device::to_json_with_status(Poco::JSON::Object &Obj) const {
|
||||
@@ -63,7 +68,7 @@ namespace OpenWifi::GWObjects {
|
||||
ConnectionState ConState;
|
||||
|
||||
if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
|
||||
ConState.to_json(Obj);
|
||||
ConState.to_json(SerialNumber,Obj);
|
||||
} else {
|
||||
field_to_json(Obj, "ipAddress", "");
|
||||
field_to_json(Obj, "txBytes", (uint64_t)0);
|
||||
@@ -75,6 +80,13 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj, "associations_2G", (uint64_t)0);
|
||||
field_to_json(Obj, "associations_5G", (uint64_t)0);
|
||||
field_to_json(Obj, "associations_6G", (uint64_t)0);
|
||||
field_to_json(Obj, "hasRADIUSSessions", false);
|
||||
field_to_json(Obj, "hasGPS", ConState.hasGPS);
|
||||
field_to_json(Obj, "sanity", ConState.sanity);
|
||||
field_to_json(Obj, "memoryUsed", ConState.memoryUsed);
|
||||
field_to_json(Obj, "sanity", ConState.sanity);
|
||||
field_to_json(Obj, "load", ConState.load);
|
||||
field_to_json(Obj, "temperature", ConState.temperature);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -84,20 +96,32 @@ namespace OpenWifi::GWObjects {
|
||||
field_from_json(Obj, "serialNumber", SerialNumber);
|
||||
field_from_json(Obj, "deviceType", DeviceType);
|
||||
field_from_json(Obj, "macAddress", MACAddress);
|
||||
field_from_json(Obj, "manufacturer", Manufacturer);
|
||||
field_from_json(Obj, "UUID", UUID);
|
||||
field_from_json(Obj, "configuration", Configuration);
|
||||
field_from_json(Obj, "notes", Notes);
|
||||
field_from_json(Obj, "manufacturer", Manufacturer);
|
||||
field_from_json(Obj, "createdTimestamp", CreationTimestamp);
|
||||
field_from_json(Obj, "lastConfigurationChange", LastConfigurationChange);
|
||||
field_from_json(Obj, "lastConfigurationDownload", LastConfigurationDownload);
|
||||
field_from_json(Obj, "lastFWUpdate", LastFWUpdate);
|
||||
field_from_json(Obj, "owner", Owner);
|
||||
field_from_json(Obj, "location", Location);
|
||||
field_from_json(Obj, "venue", Venue);
|
||||
field_from_json(Obj, "firmware", Firmware);
|
||||
field_from_json(Obj, "compatible", Compatible);
|
||||
field_from_json(Obj, "fwUpdatePolicy", FWUpdatePolicy);
|
||||
field_from_json(Obj, "devicePassword", DevicePassword);
|
||||
field_from_json(Obj, "subscriber", subscriber);
|
||||
field_from_json(Obj, "entity", entity);
|
||||
field_from_json(Obj, "modified", modified);
|
||||
field_from_json(Obj, "locale", locale);
|
||||
field_from_json(Obj, "restrictedDevice", restrictedDevice);
|
||||
field_from_json(Obj, "pendingConfiguration", pendingConfiguration);
|
||||
field_from_json(Obj, "pendingConfigurationCmd", pendingConfigurationCmd);
|
||||
field_from_json(Obj, "restrictionDetails", restrictionDetails);
|
||||
field_from_json(Obj, "pendingUUID", pendingUUID);
|
||||
field_from_json(Obj, "simulated", simulated);
|
||||
field_from_json(Obj, "lastRecordedContact", lastRecordedContact);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
}
|
||||
@@ -165,6 +189,8 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj, "waitingForFile", WaitingForFile);
|
||||
field_to_json(Obj, "attachFile", AttachDate);
|
||||
field_to_json(Obj, "executionTime", executionTime);
|
||||
field_to_json(Obj, "lastTry", lastTry);
|
||||
field_to_json(Obj, "deferred", deferred);
|
||||
}
|
||||
|
||||
bool DefaultConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -198,7 +224,7 @@ namespace OpenWifi::GWObjects {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConnectionState::to_json(Poco::JSON::Object &Obj) const {
|
||||
void ConnectionState::to_json([[maybe_unused]] const std::string &SerialNumber, Poco::JSON::Object &Obj) {
|
||||
field_to_json(Obj, "ipAddress", Address);
|
||||
field_to_json(Obj, "txBytes", TX);
|
||||
field_to_json(Obj, "rxBytes", RX);
|
||||
@@ -220,6 +246,22 @@ namespace OpenWifi::GWObjects {
|
||||
field_to_json(Obj, "connectionCompletionTime", connectionCompletionTime);
|
||||
field_to_json(Obj, "totalConnectionTime", Utils::Now() - started);
|
||||
field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate);
|
||||
field_to_json(Obj, "connectReason", connectReason);
|
||||
|
||||
#ifdef TIP_GATEWAY_SERVICE
|
||||
hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber);
|
||||
AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity,
|
||||
memoryUsed,
|
||||
load,
|
||||
temperature);
|
||||
#endif
|
||||
field_to_json(Obj, "hasRADIUSSessions", hasRADIUSSessions );
|
||||
field_to_json(Obj, "hasGPS", hasGPS);
|
||||
field_to_json(Obj, "sanity", sanity);
|
||||
field_to_json(Obj, "memoryUsed", memoryUsed);
|
||||
field_to_json(Obj, "sanity", sanity);
|
||||
field_to_json(Obj, "load", load);
|
||||
field_to_json(Obj, "temperature", temperature);
|
||||
|
||||
switch (VerifiedCertificate) {
|
||||
case NO_CERTIFICATE:
|
||||
@@ -234,6 +276,9 @@ namespace OpenWifi::GWObjects {
|
||||
case VERIFIED:
|
||||
field_to_json(Obj, "verifiedCertificate", "VERIFIED");
|
||||
break;
|
||||
case SIMULATED:
|
||||
field_to_json(Obj, "verifiedCertificate", "SIMULATED");
|
||||
break;
|
||||
default:
|
||||
field_to_json(Obj, "verifiedCertificate", "NO_CERTIFICATE");
|
||||
break;
|
||||
@@ -490,6 +535,29 @@ namespace OpenWifi::GWObjects {
|
||||
return false;
|
||||
}
|
||||
|
||||
void RangeOptions::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "NO_IR", NO_IR);
|
||||
field_to_json(Obj, "AUTO_BW", AUTO_BW);
|
||||
field_to_json(Obj, "DFS", DFS);
|
||||
field_to_json(Obj, "NO_OUTDOOR", NO_OUTDOOR);
|
||||
field_to_json(Obj, "wmmrule_ETSI", wmmrule_ETSI);
|
||||
field_to_json(Obj, "NO_OFDM", NO_OFDM);
|
||||
}
|
||||
|
||||
void FrequencyRange::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "from", from);
|
||||
field_to_json(Obj, "to", to);
|
||||
field_to_json(Obj, "channelWidth", channelWidth);
|
||||
field_to_json(Obj, "powerDb", powerDb);
|
||||
field_to_json(Obj, "options", options);
|
||||
}
|
||||
|
||||
void RegulatoryCountryInfo::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "country", country);
|
||||
field_to_json(Obj, "domain", domain);
|
||||
field_to_json(Obj, "ranges", ranges);
|
||||
}
|
||||
|
||||
void DeviceRestrictionsKeyInfo::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "vendor", vendor);
|
||||
field_to_json(Obj, "algo", algo);
|
||||
@@ -544,4 +612,43 @@ namespace OpenWifi::GWObjects {
|
||||
(T.commands != commands) || (T.developer != developer) || (T.ssh != ssh) ||
|
||||
(T.key_info != key_info) || (T.country != country));
|
||||
}
|
||||
|
||||
void RADIUSSession::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "started", started);
|
||||
field_to_json(Obj, "lastTransaction", lastTransaction);
|
||||
field_to_json(Obj, "destination", destination);
|
||||
field_to_json(Obj, "serialNumber", serialNumber);
|
||||
field_to_json(Obj, "userName", userName);
|
||||
field_to_json(Obj, "accountingSessionId", accountingSessionId);
|
||||
field_to_json(Obj, "accountingMultiSessionId", accountingMultiSessionId);
|
||||
field_to_json(Obj, "inputPackets", inputPackets);
|
||||
field_to_json(Obj, "outputPackets", outputPackets);
|
||||
field_to_json(Obj, "inputOctets", inputOctets);
|
||||
field_to_json(Obj, "outputOctets", outputOctets);
|
||||
field_to_json(Obj, "inputGigaWords", inputGigaWords);
|
||||
field_to_json(Obj, "outputGigaWords", outputGigaWords);
|
||||
field_to_json(Obj, "sessionTime", sessionTime);
|
||||
field_to_json(Obj, "callingStationId", callingStationId);
|
||||
field_to_json(Obj, "chargeableUserIdentity", chargeableUserIdentity);
|
||||
field_to_json(Obj, "interface", interface);
|
||||
field_to_json(Obj, "secret", secret);
|
||||
field_to_json(Obj, "nasId", nasId);
|
||||
}
|
||||
|
||||
void RADIUSSessionList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "sessions", sessions);
|
||||
}
|
||||
|
||||
bool RadiusCoADMParameters::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj, "accountingSessionId", accountingSessionId);
|
||||
field_from_json(Obj, "accountingMultiSessionId", accountingMultiSessionId);
|
||||
field_from_json(Obj, "callingStationId", callingStationId);
|
||||
field_from_json(Obj, "chargeableUserIdentity", chargeableUserIdentity);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace OpenWifi::GWObjects
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "RESTAPI_SecurityObjects.h"
|
||||
|
||||
#ifdef TIP_GATEWAY_SERVICE
|
||||
#include <RADIUS_helpers.h>
|
||||
#endif
|
||||
|
||||
namespace OpenWifi::GWObjects {
|
||||
|
||||
enum CertificateValidation { NO_CERTIFICATE, VALID_CERTIFICATE, MISMATCH_SERIAL, VERIFIED };
|
||||
enum CertificateValidation { NO_CERTIFICATE, VALID_CERTIFICATE, MISMATCH_SERIAL, VERIFIED, SIMULATED };
|
||||
|
||||
struct ConnectionState {
|
||||
uint64_t MessageCount = 0;
|
||||
@@ -38,8 +42,15 @@ namespace OpenWifi::GWObjects {
|
||||
uint64_t sessionId = 0;
|
||||
double connectionCompletionTime = 0.0;
|
||||
std::uint64_t certificateExpiryDate = 0;
|
||||
std::uint64_t hasRADIUSSessions = 0;
|
||||
bool hasGPS = false;
|
||||
std::uint64_t sanity=0;
|
||||
std::double_t memoryUsed=0.0;
|
||||
std::double_t load=0.0;
|
||||
std::double_t temperature=0.0;
|
||||
std::string connectReason;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ;
|
||||
};
|
||||
|
||||
struct DeviceRestrictionsKeyInfo {
|
||||
@@ -96,6 +107,9 @@ namespace OpenWifi::GWObjects {
|
||||
std::string pendingConfiguration;
|
||||
std::string pendingConfigurationCmd;
|
||||
DeviceRestrictions restrictionDetails;
|
||||
std::uint64_t pendingUUID = 0;
|
||||
bool simulated=false;
|
||||
std::uint64_t lastRecordedContact=0;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
void to_json_with_status(Poco::JSON::Object &Obj) const;
|
||||
@@ -188,7 +202,11 @@ namespace OpenWifi::GWObjects {
|
||||
uint64_t AttachSize = 0;
|
||||
std::string AttachType;
|
||||
double executionTime = 0.0;
|
||||
std::uint64_t lastTry = 0;
|
||||
bool deferred = false;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct BlackListedDevice {
|
||||
@@ -334,4 +352,77 @@ namespace OpenWifi::GWObjects {
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct RangeOptions {
|
||||
bool NO_IR=false;
|
||||
bool AUTO_BW=false;
|
||||
bool DFS=false;
|
||||
bool NO_OUTDOOR=false;
|
||||
bool wmmrule_ETSI=false;
|
||||
bool NO_OFDM=false;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
struct FrequencyRange {
|
||||
float from = 0.0;
|
||||
float to = 0.0;
|
||||
int channelWidth = 0;
|
||||
int powerDb = 0;
|
||||
RangeOptions options;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
struct RegulatoryCountryInfo {
|
||||
std::string country;
|
||||
std::string domain;
|
||||
std::vector<FrequencyRange> ranges;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
using RegulatoryInfoCountryMap = std::map<std::string,RegulatoryCountryInfo>;
|
||||
|
||||
struct RADIUSSession {
|
||||
std::uint64_t started=0,
|
||||
lastTransaction=0;
|
||||
std::string serialNumber,
|
||||
destination,
|
||||
userName,
|
||||
accountingSessionId,
|
||||
accountingMultiSessionId,
|
||||
callingStationId,
|
||||
chargeableUserIdentity,
|
||||
secret,
|
||||
interface,
|
||||
nasId;
|
||||
std::uint64_t inputPackets = 0,
|
||||
outputPackets = 0,
|
||||
inputOctets = 0,
|
||||
outputOctets = 0,
|
||||
inputGigaWords = 0,
|
||||
outputGigaWords = 0;
|
||||
std::uint32_t sessionTime = 0;
|
||||
|
||||
#ifdef TIP_GATEWAY_SERVICE
|
||||
RADIUS::RadiusPacket accountingPacket;
|
||||
#endif
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
struct RADIUSSessionList {
|
||||
std::vector<RADIUSSession> sessions;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
struct RadiusCoADMParameters {
|
||||
std::string accountingSessionId,
|
||||
accountingMultiSessionId,
|
||||
callingStationId,
|
||||
chargeableUserIdentity;
|
||||
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
} // namespace OpenWifi::GWObjects
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/SubSystemServer.h"
|
||||
#include "framework/utils.h"
|
||||
|
||||
#include <framework/SubSystemServer.h>
|
||||
#include <framework/utils.h>
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
#include <RESTObjects/RESTAPI_SecurityObjects.h>
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
// Created by stephane bourque on 2021-11-03.
|
||||
//
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <Poco/JSON/Parser.h>
|
||||
|
||||
#include <framework/MicroServiceFuncs.h>
|
||||
#include <framework/utils.h>
|
||||
|
||||
#include "SimulationCoordinator.h"
|
||||
#include "SimStats.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
#include "fmt/format.h"
|
||||
#include "framework/MicroServiceFuncs.h"
|
||||
#include "framework/utils.h"
|
||||
|
||||
#include <Poco/JSON/Parser.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
#include "RESTObjects/RESTAPI_OWLSobjects.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "framework/SubSystemServer.h"
|
||||
#include <framework/SubSystemServer.h>
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
#include <RESTObjects/RESTAPI_SecurityObjects.h>
|
||||
|
||||
#include "SimulationRunner.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
struct SimulationRecord {
|
||||
|
||||
@@ -5,20 +5,18 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "Poco/Logger.h"
|
||||
|
||||
#include "SimStats.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "OWLSevent.h"
|
||||
|
||||
#include "fmt/format.h"
|
||||
|
||||
#include "UI_Owls_WebSocketNotifications.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <Poco/Logger.h>
|
||||
#include <Poco/Net/NetException.h>
|
||||
#include <Poco/Net/SSLException.h>
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "SimStats.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "UI_Owls_WebSocketNotifications.h"
|
||||
|
||||
|
||||
namespace OpenWifi {
|
||||
void SimulationRunner::Start() {
|
||||
std::random_device rd;
|
||||
@@ -28,38 +26,77 @@ namespace OpenWifi {
|
||||
Running_ = true;
|
||||
std::lock_guard Lock(Mutex_);
|
||||
|
||||
SocketReactorThread_.start(Reactor_);
|
||||
NumberOfReactors_ = Poco::Environment::processorCount() * 2;
|
||||
for(std::uint64_t i=0;i<NumberOfReactors_;i++) {
|
||||
auto NewReactor = std::make_unique<Poco::Net::SocketReactor>();
|
||||
auto NewReactorThread = std::make_unique<Poco::Thread>();
|
||||
NewReactorThread->start(*NewReactor);
|
||||
SocketReactorPool_.push_back(std::move(NewReactor));
|
||||
SocketReactorThreadPool_.push_back(std::move(NewReactorThread));
|
||||
}
|
||||
|
||||
std::uint64_t ReactorIndex=0;
|
||||
for (uint64_t i = 0; i < Details_.devices; i++) {
|
||||
char Buffer[32];
|
||||
snprintf(Buffer, sizeof(Buffer), "%s%05x0", Details_.macPrefix.c_str(), (unsigned int)i);
|
||||
auto Client = std::make_shared<OWLSclient>(Buffer, Logger_, this);
|
||||
auto Client = std::make_shared<OWLSclient>(Buffer, Logger_, this, *SocketReactorPool_[ReactorIndex++ % NumberOfReactors_]);
|
||||
Client->SerialNumber_ = Buffer;
|
||||
Client->Valid_ = true;
|
||||
Scheduler_.in(std::chrono::seconds(distrib(gen)), OWLSclientEvents::EstablishConnection, Client, this);
|
||||
Scheduler_.in(std::chrono::seconds(distrib(gen)), OWLSClientEvents::EstablishConnection, Client, this);
|
||||
Clients_[Buffer] = Client;
|
||||
}
|
||||
Scheduler_.in(std::chrono::seconds(10), ProgressUpdate, this);
|
||||
|
||||
UpdateTimerCallback_ = std::make_unique<Poco::TimerCallback<SimulationRunner>>(
|
||||
*this, &SimulationRunner::onUpdateTimer);
|
||||
UpdateTimer_.setStartInterval(10000);
|
||||
UpdateTimer_.setPeriodicInterval(2 * 1000);
|
||||
UpdateTimer_.start(*UpdateTimerCallback_, MicroServiceTimerPool());
|
||||
}
|
||||
|
||||
void SimulationRunner::onUpdateTimer([[maybe_unused]] Poco::Timer &timer) {
|
||||
if(Running_) {
|
||||
|
||||
OWLSNotifications::SimulationUpdate_t Notification;
|
||||
SimStats()->GetCurrent(Id_, Notification.content, UInfo_);
|
||||
OWLSNotifications::SimulationUpdate(Notification);
|
||||
++StatsUpdates_;
|
||||
|
||||
if((StatsUpdates_ % 15) == 0) {
|
||||
std::lock_guard Lock(Mutex_);
|
||||
|
||||
for(auto &client:Clients_) {
|
||||
if(!Running_) {
|
||||
return;
|
||||
}
|
||||
if(client.second->Mutex_.try_lock()) {
|
||||
if (client.second->Connected_) {
|
||||
client.second->Update();
|
||||
}
|
||||
client.second->Mutex_.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimulationRunner::ProgressUpdate(SimulationRunner *sim) {
|
||||
if(sim->Running_) {
|
||||
OWLSNotifications::SimulationUpdate_t Notification;
|
||||
SimStats()->GetCurrent(sim->Id_, Notification.content, sim->UInfo_);
|
||||
OWLSNotifications::SimulationUpdate(Notification);
|
||||
sim->Scheduler_.in(std::chrono::seconds(10), ProgressUpdate, sim);
|
||||
// sim->Scheduler_.in(std::chrono::seconds(10), ProgressUpdate, sim);
|
||||
}
|
||||
}
|
||||
|
||||
void SimulationRunner::Stop() {
|
||||
if (Running_) {
|
||||
Running_ = false;
|
||||
for(auto &client:Clients_) {
|
||||
OWLSclientEvents::Disconnect(client.second, this, "Simulation shutting down", false);
|
||||
client.second->Valid_ = false;
|
||||
}
|
||||
Reactor_.stop();
|
||||
SocketReactorThread_.join();
|
||||
UpdateTimer_.stop();
|
||||
std::lock_guard Guard(Mutex_);
|
||||
std::for_each(SocketReactorPool_.begin(),SocketReactorPool_.end(),[](auto &reactor) { reactor->stop(); });
|
||||
std::for_each(SocketReactorThreadPool_.begin(),SocketReactorThreadPool_.end(),[](auto &t){ t->join(); });
|
||||
SocketReactorThreadPool_.clear();
|
||||
SocketReactorPool_.clear();
|
||||
Clients_.clear();
|
||||
}
|
||||
}
|
||||
@@ -67,59 +104,61 @@ namespace OpenWifi {
|
||||
void SimulationRunner::OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
std::cout << "SimulationRunner::OnSocketError" << std::endl;
|
||||
|
||||
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;
|
||||
{
|
||||
std::lock_guard GG(SocketFdMutex_);
|
||||
client_hint = Clients_fd_.find(socket);
|
||||
if (client_hint == end(Clients_fd_)) {
|
||||
pNf->socket().impl()->close();
|
||||
poco_warning(Logger_, fmt::format("{}: Invalid socket", socket));
|
||||
return;
|
||||
}
|
||||
client = client_hint->second;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard Guard(client->Mutex_);
|
||||
client->Disconnect(__func__, Guard);
|
||||
}
|
||||
if (Running_) {
|
||||
OWLSClientEvents::Reconnect(client, this);
|
||||
}
|
||||
client = client_hint->second;
|
||||
client->Disconnect();
|
||||
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;
|
||||
{
|
||||
std::lock_guard G(SocketFdMutex_);
|
||||
auto client_hint = Clients_fd_.find(socket);
|
||||
if (client_hint == end(Clients_fd_)) {
|
||||
pNf->socket().impl()->close();
|
||||
poco_warning(Logger_, fmt::format("{}: Invalid socket", socket));
|
||||
return;
|
||||
}
|
||||
client = client_hint->second;
|
||||
}
|
||||
{
|
||||
std::lock_guard Guard(client->Mutex_);
|
||||
client->Disconnect(__func__ , Guard);
|
||||
}
|
||||
client = client_hint->second;
|
||||
client->Disconnect();
|
||||
if(Running_)
|
||||
OWLSclientEvents::Reconnect(client,this);
|
||||
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;
|
||||
|
||||
int socket;
|
||||
{
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
std::lock_guard G(SocketFdMutex_);
|
||||
socket = pNf->socket().impl()->sockfd();
|
||||
client_hint = Clients_fd_.find(socket);
|
||||
auto client_hint = Clients_fd_.find(socket);
|
||||
if (client_hint == end(Clients_fd_)) {
|
||||
poco_warning(Logger_, fmt::format("{}: Invalid socket", socket));
|
||||
return;
|
||||
@@ -137,8 +176,7 @@ namespace OpenWifi {
|
||||
auto Op = Flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
|
||||
|
||||
if (MessageSize == 0 && Flags == 0 && Op == 0) {
|
||||
Clients_fd_.erase(socket);
|
||||
OWLSclientEvents::Disconnect(client, this, "Error while waiting for data in WebSocket", true);
|
||||
OWLSClientEvents::Disconnect(__func__, Guard, client, this, "Error while waiting for data in WebSocket", true);
|
||||
return;
|
||||
}
|
||||
IncomingFrame.append(0);
|
||||
@@ -161,7 +199,7 @@ namespace OpenWifi {
|
||||
|
||||
if (Frame->has("jsonrpc") && Frame->has("id") &&
|
||||
Frame->has("method") && Frame->has("params")) {
|
||||
ProcessCommand(client, Frame);
|
||||
ProcessCommand(Guard,client, Frame);
|
||||
} else {
|
||||
Logger_.warning(
|
||||
fmt::format("MESSAGE({}): invalid incoming message.", client->SerialNumber_));
|
||||
@@ -179,12 +217,10 @@ namespace OpenWifi {
|
||||
Logger_.warning(fmt::format("Exception({}): Generic exception: {}", client->SerialNumber_,
|
||||
E.displayText()));
|
||||
}
|
||||
|
||||
Clients_fd_.erase(socket);
|
||||
OWLSclientEvents::Disconnect(client, this, "Error while waiting for data in WebSocket", true);
|
||||
OWLSClientEvents::Disconnect(__func__, Guard,client, this, "Error while waiting for data in WebSocket", true);
|
||||
}
|
||||
|
||||
void SimulationRunner::ProcessCommand(std::shared_ptr<OWLSclient> Client, Poco::JSON::Object::Ptr Frame) {
|
||||
void SimulationRunner::ProcessCommand(std::lock_guard<std::mutex> &ClientGuard, const std::shared_ptr<OWLSclient> & Client, Poco::JSON::Object::Ptr Frame) {
|
||||
|
||||
std::string Method = Frame->get("method");
|
||||
std::uint64_t Id = Frame->get("id");
|
||||
@@ -212,7 +248,7 @@ namespace OpenWifi {
|
||||
t.detach();
|
||||
} else {
|
||||
Logger_.warning(fmt::format("COMMAND({}): unknown method '{}'", Client->SerialNumber_, Method));
|
||||
Client->UNsupportedCommand(Client, Id, Method);
|
||||
Client->UnSupportedCommand(ClientGuard,Client, Id, Method);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,15 @@
|
||||
|
||||
#include <Poco/Thread.h>
|
||||
#include <Poco/Environment.h>
|
||||
#include "OWLSclient.h"
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
#include <Poco/Timer.h>
|
||||
|
||||
#include "CensusReport.h"
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
#include <libs/Scheduler.h>
|
||||
#include <RESTObjects/RESTAPI_SecurityObjects.h>
|
||||
|
||||
#include "OWLSclient.h"
|
||||
#include "CensusReport.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class SimulationRunner {
|
||||
@@ -38,35 +40,44 @@ namespace OpenWifi {
|
||||
|
||||
const std::string & Id() const { return Id_; }
|
||||
|
||||
inline void AddClientFd(std::int64_t fd, std::shared_ptr<OWLSclient> c) {
|
||||
std::lock_guard G(Mutex_);
|
||||
inline void AddClientFd(std::int64_t fd, const std::shared_ptr<OWLSclient> &c) {
|
||||
std::lock_guard G(SocketFdMutex_);
|
||||
Clients_fd_[fd] = c;
|
||||
}
|
||||
|
||||
inline void RemoveClientFd(std::int64_t fd) {
|
||||
std::lock_guard G(Mutex_);
|
||||
std::lock_guard G(SocketFdMutex_);
|
||||
Clients_fd_.erase(fd);
|
||||
}
|
||||
|
||||
void ProcessCommand(std::shared_ptr<OWLSclient> Client, Poco::JSON::Object::Ptr Vars);
|
||||
Poco::Net::SocketReactor & Reactor() { return Reactor_; }
|
||||
void ProcessCommand(std::lock_guard<std::mutex> &G, const std::shared_ptr<OWLSclient> &Client, Poco::JSON::Object::Ptr Vars);
|
||||
|
||||
inline auto & Scheduler() { return Scheduler_; }
|
||||
inline bool Running() { return Running_; }
|
||||
|
||||
void onUpdateTimer(Poco::Timer &timer);
|
||||
|
||||
private:
|
||||
std::mutex SocketFdMutex_;
|
||||
my_mutex Mutex_;
|
||||
OWLSObjects::SimulationDetails Details_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::Net::SocketReactor Reactor_;
|
||||
std::vector<std::unique_ptr<Poco::Net::SocketReactor>> SocketReactorPool_;
|
||||
std::vector<std::unique_ptr<Poco::Thread>> SocketReactorThreadPool_;
|
||||
std::map<std::string, std::shared_ptr<OWLSclient>> Clients_;
|
||||
std::map<std::int64_t, std::shared_ptr<OWLSclient>> Clients_fd_;
|
||||
Poco::Thread SocketReactorThread_;
|
||||
std::atomic_bool Running_ = false;
|
||||
CensusReport CensusReport_;
|
||||
std::string State_{"stopped"};
|
||||
std::string Id_;
|
||||
Bosma::Scheduler Scheduler_;
|
||||
SecurityObjects::UserInfo UInfo_;
|
||||
std::uint64_t NumberOfReactors_=0;
|
||||
std::uint64_t StatsUpdates_=0;
|
||||
|
||||
Poco::Timer UpdateTimer_;
|
||||
std::unique_ptr<Poco::TimerCallback<SimulationRunner>> UpdateTimerCallback_;
|
||||
|
||||
|
||||
static void ProgressUpdate(SimulationRunner *s);
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/StorageClass.h"
|
||||
#include "storage/storage_results.h"
|
||||
#include "storage/storage_simulations.h"
|
||||
#include <framework/StorageClass.h>
|
||||
#include <storage/storage_results.h>
|
||||
#include <storage/storage_simulations.h>
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
// Created by stephane bourque on 2022-10-30.
|
||||
//
|
||||
|
||||
#include "UI_Owls_WebSocketNotifications.h"
|
||||
#include "framework/UI_WebSocketClientServer.h"
|
||||
#include <framework/UI_WebSocketClientServer.h>
|
||||
|
||||
#include <UI_Owls_WebSocketNotifications.h>
|
||||
|
||||
namespace OpenWifi::OWLSNotifications {
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RESTObjects/RESTAPI_OWLSobjects.h"
|
||||
#include "framework/UI_WebSocketClientNotifications.h"
|
||||
#include <framework/UI_WebSocketClientNotifications.h>
|
||||
#include <RESTObjects/RESTAPI_OWLSobjects.h>
|
||||
|
||||
namespace OpenWifi::OWLSNotifications {
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenWifi {
|
||||
Response.set("Connection", "keep-alive");
|
||||
Response.setVersion(Poco::Net::HTTPMessage::HTTP_1_1);
|
||||
std::ostream &Answer = Response.send();
|
||||
Answer << "process Alive and kicking!";
|
||||
Answer << ALBHealthCheckServer()->CallbackText();
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace OpenWifi {
|
||||
inline static std::atomic_uint64_t req_id_ = 1;
|
||||
};
|
||||
|
||||
typedef std::string ALBHealthMessageCallback();
|
||||
|
||||
class ALBHealthCheckServer : public SubSystemServer {
|
||||
public:
|
||||
ALBHealthCheckServer();
|
||||
@@ -48,10 +50,22 @@ namespace OpenWifi {
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
inline void RegisterExtendedHealthMessage(ALBHealthMessageCallback *F) {
|
||||
Callback_=F;
|
||||
};
|
||||
|
||||
inline std::string CallbackText() {
|
||||
if(Callback_== nullptr) {
|
||||
return "process Alive and kicking!";
|
||||
} else {
|
||||
return Callback_();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Poco::Net::HTTPServer> Server_;
|
||||
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
|
||||
ALBHealthMessageCallback *Callback_= nullptr;
|
||||
int Port_ = 0;
|
||||
mutable std::atomic_bool Running_ = false;
|
||||
};
|
||||
|
||||
@@ -37,6 +37,10 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"uuid": {
|
||||
"type": "integer"
|
||||
},
|
||||
"public_ip_lookup": {
|
||||
"type": "string",
|
||||
"format": "uc-fqdn"
|
||||
},
|
||||
"unit": {
|
||||
"$ref": "#/$defs/unit"
|
||||
},
|
||||
@@ -634,26 +638,6 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"type": "string",
|
||||
"format": "uc-timeout",
|
||||
"default": "6h"
|
||||
},
|
||||
"relay-server": {
|
||||
"type": "string",
|
||||
"format": "ipv4",
|
||||
"example": "192.168.2.1"
|
||||
},
|
||||
"circuit-id-format": {
|
||||
"type": "string",
|
||||
"example": [
|
||||
"\\{Interface\\}:\\{VLAN-Id\\}:\\{SSID\\}:\\{Model\\}:\\{Name\\}:\\{AP-MAC\\}:\\{Location\\}",
|
||||
"\\{AP-MAC\\};\\{SSID\\};\\{Crypto\\}",
|
||||
"\\{Name\\} \\{ESSID\\}"
|
||||
]
|
||||
},
|
||||
"remote-id-format": {
|
||||
"type": "string",
|
||||
"example": [
|
||||
"\\{Client-MAC-hex\\} \\{SSID\\}",
|
||||
"\\{AP-MAC-hex\\} \\{SSID\\}"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1232,6 +1216,32 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"secondary": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"examples": [
|
||||
1812
|
||||
]
|
||||
},
|
||||
"secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"request-attribute": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -1309,6 +1319,25 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"value": "Example Operator"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"maximum": 255,
|
||||
"minimum": 1
|
||||
},
|
||||
"hex-value": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"id": 32,
|
||||
"value": "0a0b0c0d"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1658,6 +1687,236 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.click": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "click-to-continue"
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.radius": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "radius"
|
||||
},
|
||||
"auth-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"auth-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"auth-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"acct-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"acct-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-interval": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.credentials": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "credentials"
|
||||
},
|
||||
"credentials": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.uam": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "uam"
|
||||
},
|
||||
"uam-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 3990
|
||||
},
|
||||
"uam-secret": {
|
||||
"type": "string"
|
||||
},
|
||||
"uam-server": {
|
||||
"type": "string"
|
||||
},
|
||||
"nasid": {
|
||||
"type": "string"
|
||||
},
|
||||
"nasmac": {
|
||||
"type": "string"
|
||||
},
|
||||
"auth-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"auth-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"auth-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"acct-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"acct-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-interval": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
},
|
||||
"ssid": {
|
||||
"type": "string"
|
||||
},
|
||||
"mac-format": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"aabbccddeeff",
|
||||
"aa-bb-cc-dd-ee-ff",
|
||||
"aa:bb:cc:dd:ee:ff",
|
||||
"AABBCCDDEEFF",
|
||||
"AA:BB:CC:DD:EE:FF",
|
||||
"AA-BB-CC-DD-EE-FF"
|
||||
]
|
||||
},
|
||||
"final-redirect-url": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"default",
|
||||
"uam"
|
||||
]
|
||||
},
|
||||
"mac-auth": {
|
||||
"type": "boolean",
|
||||
"default": "default"
|
||||
},
|
||||
"radius-gw-proxy": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive": {
|
||||
"allOf": [
|
||||
{
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.click"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.radius"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.credentials"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.uam"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"walled-garden-fqdn": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"walled-garden-ipaddr": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "uc-ip"
|
||||
}
|
||||
},
|
||||
"web-root": {
|
||||
"type": "string",
|
||||
"format": "uc-base64"
|
||||
},
|
||||
"idle-timeout": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
},
|
||||
"session-timeout": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"interface.ssid": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1710,6 +1969,10 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"isolate-clients": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"strict-forwarding": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"power-save": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1778,7 +2041,14 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"$ref": "#/$defs/interface.ssid.rate-limit"
|
||||
},
|
||||
"roaming": {
|
||||
"$ref": "#/$defs/interface.ssid.roaming"
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/$defs/interface.ssid.roaming"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
},
|
||||
"radius": {
|
||||
"$ref": "#/$defs/interface.ssid.radius"
|
||||
@@ -1795,6 +2065,9 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"access-control-list": {
|
||||
"$ref": "#/$defs/interface.ssid.acl"
|
||||
},
|
||||
"captive": {
|
||||
"$ref": "#/$defs/service.captive"
|
||||
},
|
||||
"hostapd-bss-raw": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -1962,6 +2235,17 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
]
|
||||
}
|
||||
},
|
||||
"vlan-awareness": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"first": {
|
||||
"type": "integer"
|
||||
},
|
||||
"last": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"vlan": {
|
||||
"$ref": "#/$defs/interface.vlan"
|
||||
},
|
||||
@@ -2084,6 +2368,10 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
"examples": [
|
||||
"01234567890123456789012345678901"
|
||||
]
|
||||
},
|
||||
"mutual-tls": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2693,236 +2981,6 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.click": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "click-to-continue"
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.radius": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "radius"
|
||||
},
|
||||
"auth-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"auth-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"auth-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"acct-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"acct-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-interval": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.credentials": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "credentials"
|
||||
},
|
||||
"credentials": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive.uam": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auth-mode": {
|
||||
"type": "string",
|
||||
"const": "uam"
|
||||
},
|
||||
"uam-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 3990
|
||||
},
|
||||
"uam-secret": {
|
||||
"type": "string"
|
||||
},
|
||||
"uam-server": {
|
||||
"type": "string"
|
||||
},
|
||||
"nasid": {
|
||||
"type": "string"
|
||||
},
|
||||
"nasmac": {
|
||||
"type": "string"
|
||||
},
|
||||
"auth-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"auth-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"auth-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-server": {
|
||||
"type": "string",
|
||||
"format": "uc-host",
|
||||
"examples": [
|
||||
"192.168.1.10"
|
||||
]
|
||||
},
|
||||
"acct-port": {
|
||||
"type": "integer",
|
||||
"maximum": 65535,
|
||||
"minimum": 1024,
|
||||
"default": 1812
|
||||
},
|
||||
"acct-secret": {
|
||||
"type": "string",
|
||||
"examples": [
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"acct-interval": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
},
|
||||
"ssid": {
|
||||
"type": "string"
|
||||
},
|
||||
"mac-format": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"aabbccddeeff",
|
||||
"aa-bb-cc-dd-ee-ff",
|
||||
"aa:bb:cc:dd:ee:ff",
|
||||
"AABBCCDDEEFF",
|
||||
"AA:BB:CC:DD:EE:FF",
|
||||
"AA-BB-CC-DD-EE-FF"
|
||||
]
|
||||
},
|
||||
"final-redirect-url": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"default",
|
||||
"uam"
|
||||
]
|
||||
},
|
||||
"mac-auth": {
|
||||
"type": "boolean",
|
||||
"default": "default"
|
||||
},
|
||||
"radius-gw-proxy": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.captive": {
|
||||
"allOf": [
|
||||
{
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.click"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.radius"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.credentials"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/service.captive.uam"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"walled-garden-fqdn": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"walled-garden-ipaddr": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "uc-ip"
|
||||
}
|
||||
},
|
||||
"web-root": {
|
||||
"type": "string",
|
||||
"format": "uc-base64"
|
||||
},
|
||||
"idle-timeout": {
|
||||
"type": "integer",
|
||||
"default": 600
|
||||
},
|
||||
"session-timeout": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"service.gps": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2941,6 +2999,32 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
}
|
||||
}
|
||||
},
|
||||
"service.dhcp-relay": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"select-ports": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"vlans": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"vlan": {
|
||||
"type": "number"
|
||||
},
|
||||
"relay-server": {
|
||||
"type": "string",
|
||||
"format": "uc-ip"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"service": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -3000,6 +3084,9 @@ static std::string DefaultUCentralSchema = R"foo(
|
||||
},
|
||||
"gps": {
|
||||
"$ref": "#/$defs/service.gps"
|
||||
},
|
||||
"dhcp-relay": {
|
||||
"$ref": "#/$defs/service.dhcp-relay"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,18 +14,18 @@ namespace OpenWifi {
|
||||
void EventBusManager::run() {
|
||||
Running_ = true;
|
||||
Utils::SetThreadName("fmwk:EventMgr");
|
||||
auto Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
|
||||
auto Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
||||
false);
|
||||
while (Running_) {
|
||||
Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer());
|
||||
if (!Running_)
|
||||
break;
|
||||
Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE);
|
||||
Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
|
||||
Msg, false);
|
||||
}
|
||||
Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE);
|
||||
Msg = std::make_shared<std::string>(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE));
|
||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
||||
false);
|
||||
};
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace OpenWifi {
|
||||
Consumer.async_commit(Msg);
|
||||
continue;
|
||||
}
|
||||
KafkaManager()->Dispatch(Msg.get_topic(), Msg.get_key(), Msg.get_payload());
|
||||
KafkaManager()->Dispatch(Msg.get_topic().c_str(), Msg.get_key(), std::make_shared<std::string>(Msg.get_payload()));
|
||||
if (!AutoCommit)
|
||||
Consumer.async_commit(Msg);
|
||||
}
|
||||
@@ -212,8 +212,8 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaProducer::Produce(const std::string &Topic, const std::string &Key,
|
||||
const std::string &Payload) {
|
||||
void KafkaProducer::Produce(const char *Topic, const std::string &Key,
|
||||
std::shared_ptr<std::string> Payload) {
|
||||
std::lock_guard G(Mutex_);
|
||||
Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload));
|
||||
}
|
||||
@@ -275,8 +275,8 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaDispatcher::Dispatch(const std::string &Topic, const std::string &Key,
|
||||
const std::string &Payload) {
|
||||
void KafkaDispatcher::Dispatch(const char *Topic, const std::string &Key,
|
||||
const std::shared_ptr<std::string> Payload) {
|
||||
std::lock_guard G(Mutex_);
|
||||
auto It = Notifiers_.find(Topic);
|
||||
if (It != Notifiers_.end()) {
|
||||
@@ -332,20 +332,21 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaManager::PostMessage(const std::string &topic, const std::string &key,
|
||||
const std::string &PayLoad, bool WrapMessage) {
|
||||
void KafkaManager::PostMessage(const char *topic, const std::string &key,
|
||||
const std::shared_ptr<std::string> PayLoad, bool WrapMessage) {
|
||||
if (KafkaEnabled_) {
|
||||
ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(PayLoad) : PayLoad);
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaManager::Dispatch(const std::string &Topic, const std::string &Key,
|
||||
const std::string &Payload) {
|
||||
void KafkaManager::Dispatch(const char *Topic, const std::string &Key,
|
||||
const std::shared_ptr<std::string> Payload) {
|
||||
Dispatcher_.Dispatch(Topic, Key, Payload);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string &PayLoad) {
|
||||
return SystemInfoWrapper_ + PayLoad + "}";
|
||||
[[nodiscard]] const std::shared_ptr<std::string> KafkaManager::WrapSystemId(const std::shared_ptr<std::string> PayLoad) {
|
||||
*PayLoad = SystemInfoWrapper_ + *PayLoad + "}";
|
||||
return PayLoad;
|
||||
}
|
||||
|
||||
uint64_t KafkaManager::RegisterTopicWatcher(const std::string &Topic,
|
||||
|
||||
@@ -18,17 +18,17 @@ namespace OpenWifi {
|
||||
|
||||
class KafkaMessage : public Poco::Notification {
|
||||
public:
|
||||
KafkaMessage(const std::string &Topic, const std::string &Key, const std::string &Payload)
|
||||
KafkaMessage(const char * Topic, const std::string &Key, std::shared_ptr<std::string> Payload)
|
||||
: Topic_(Topic), Key_(Key), Payload_(Payload) {}
|
||||
|
||||
inline const std::string &Topic() { return Topic_; }
|
||||
inline const char * Topic() { return Topic_; }
|
||||
inline const std::string &Key() { return Key_; }
|
||||
inline const std::string &Payload() { return Payload_; }
|
||||
inline const std::string &Payload() { return *Payload_; }
|
||||
|
||||
private:
|
||||
std::string Topic_;
|
||||
const char *Topic_;
|
||||
std::string Key_;
|
||||
std::string Payload_;
|
||||
std::shared_ptr<std::string> Payload_;
|
||||
};
|
||||
|
||||
class KafkaProducer : public Poco::Runnable {
|
||||
@@ -36,7 +36,7 @@ namespace OpenWifi {
|
||||
void run() override;
|
||||
void Start();
|
||||
void Stop();
|
||||
void Produce(const std::string &Topic, const std::string &Key, const std::string &Payload);
|
||||
void Produce(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
|
||||
|
||||
private:
|
||||
std::recursive_mutex Mutex_;
|
||||
@@ -63,7 +63,7 @@ namespace OpenWifi {
|
||||
void Stop();
|
||||
auto RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F);
|
||||
void UnregisterTopicWatcher(const std::string &Topic, int Id);
|
||||
void Dispatch(const std::string &Topic, const std::string &Key, const std::string &Payload);
|
||||
void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload);
|
||||
void run() override;
|
||||
void Topics(std::vector<std::string> &T);
|
||||
|
||||
@@ -91,10 +91,10 @@ namespace OpenWifi {
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
|
||||
void PostMessage(const std::string &topic, const std::string &key,
|
||||
const std::string &PayLoad, bool WrapMessage = true);
|
||||
void Dispatch(const std::string &Topic, const std::string &Key, const std::string &Payload);
|
||||
[[nodiscard]] std::string WrapSystemId(const std::string &PayLoad);
|
||||
void PostMessage(const char *topic, const std::string &key,
|
||||
std::shared_ptr<std::string> PayLoad, bool WrapMessage = true);
|
||||
void Dispatch(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
|
||||
[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(std::shared_ptr<std::string> PayLoad);
|
||||
[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; }
|
||||
uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F);
|
||||
void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id);
|
||||
|
||||
@@ -10,32 +10,32 @@
|
||||
|
||||
#include <string>
|
||||
namespace OpenWifi::KafkaTopics {
|
||||
static const std::string HEALTHCHECK{"healthcheck"};
|
||||
static const std::string STATE{"state"};
|
||||
static const std::string CONNECTION{"connection"};
|
||||
static const std::string WIFISCAN{"wifiscan"};
|
||||
static const std::string ALERTS{"alerts"};
|
||||
static const std::string COMMAND{"command"};
|
||||
static const std::string SERVICE_EVENTS{"service_events"};
|
||||
static const std::string DEVICE_EVENT_QUEUE{"device_event_queue"};
|
||||
static const std::string DEVICE_TELEMETRY{"device_telemetry"};
|
||||
static const std::string PROVISIONING_CHANGE{"provisioning_change"};
|
||||
inline const char * HEALTHCHECK = "healthcheck";
|
||||
inline const char * STATE = "state";
|
||||
inline const char * CONNECTION = "connection";
|
||||
inline const char * WIFISCAN = "wifiscan";
|
||||
inline const char * ALERTS = "alerts";
|
||||
inline const char * COMMAND = "command";
|
||||
inline const char * SERVICE_EVENTS = "service_events";
|
||||
inline const char * DEVICE_EVENT_QUEUE = "device_event_queue";
|
||||
inline const char * DEVICE_TELEMETRY = "device_telemetry";
|
||||
inline const char * PROVISIONING_CHANGE = "provisioning_change";
|
||||
|
||||
namespace ServiceEvents {
|
||||
static const std::string EVENT_JOIN{"join"};
|
||||
static const std::string EVENT_LEAVE{"leave"};
|
||||
static const std::string EVENT_KEEP_ALIVE{"keep-alive"};
|
||||
static const std::string EVENT_REMOVE_TOKEN{"remove-token"};
|
||||
inline const char * EVENT_JOIN = "join";
|
||||
inline const char * EVENT_LEAVE = "leave";
|
||||
inline const char * EVENT_KEEP_ALIVE = "keep-alive";
|
||||
inline const char * EVENT_REMOVE_TOKEN = "remove-token";
|
||||
|
||||
namespace Fields {
|
||||
static const std::string EVENT{"event"};
|
||||
static const std::string ID{"id"};
|
||||
static const std::string TYPE{"type"};
|
||||
static const std::string PUBLIC{"publicEndPoint"};
|
||||
static const std::string PRIVATE{"privateEndPoint"};
|
||||
static const std::string KEY{"key"};
|
||||
static const std::string VRSN{"version"};
|
||||
static const std::string TOKEN{"token"};
|
||||
inline const char * EVENT = "event";
|
||||
inline const char * ID = "id";
|
||||
inline const char * TYPE = "type";
|
||||
inline const char * PUBLIC = "publicEndPoint";
|
||||
inline const char * PRIVATE = "privateEndPoint";
|
||||
inline const char * KEY = "key";
|
||||
inline const char * VRSN = "version";
|
||||
inline const char * TOKEN = "token";
|
||||
} // namespace Fields
|
||||
} // namespace ServiceEvents
|
||||
} // namespace OpenWifi::KafkaTopics
|
||||
|
||||
@@ -129,6 +129,8 @@ namespace OpenWifi {
|
||||
}
|
||||
} else {
|
||||
poco_error(logger(), "Bad bus message.");
|
||||
std::ostringstream os;
|
||||
Object->stringify(std::cout);
|
||||
}
|
||||
|
||||
auto i = Services_.begin();
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "framework/MicroServiceFuncs.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
#include "framework/ALBserver.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); }
|
||||
|
||||
@@ -47,11 +49,11 @@ namespace OpenWifi {
|
||||
|
||||
void MicroServiceReload(const std::string &Type) { MicroService::instance().Reload(Type); }
|
||||
|
||||
const Types::StringVec MicroServiceGetLogLevelNames() {
|
||||
Types::StringVec MicroServiceGetLogLevelNames() {
|
||||
return MicroService::instance().GetLogLevelNames();
|
||||
}
|
||||
|
||||
const Types::StringVec MicroServiceGetSubSystems() {
|
||||
Types::StringVec MicroServiceGetSubSystems() {
|
||||
return MicroService::instance().GetSubSystems();
|
||||
}
|
||||
|
||||
@@ -79,7 +81,7 @@ namespace OpenWifi {
|
||||
|
||||
std::string MicroServiceGetUIURI() { return MicroService::instance().GetUIURI(); }
|
||||
|
||||
const SubSystemVec MicroServiceGetFullSubSystems() {
|
||||
SubSystemVec MicroServiceGetFullSubSystems() {
|
||||
return MicroService::instance().GetFullSubSystems();
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ namespace OpenWifi {
|
||||
|
||||
std::uint64_t MicroServiceDaemonBusTimer() { return MicroService::instance().DaemonBusTimer(); }
|
||||
|
||||
std::string MicroServiceMakeSystemEventMessage(const std::string &Type) {
|
||||
std::string MicroServiceMakeSystemEventMessage(const char *Type) {
|
||||
return MicroService::instance().MakeSystemEventMessage(Type);
|
||||
}
|
||||
|
||||
@@ -123,4 +125,8 @@ namespace OpenWifi {
|
||||
return MicroService::instance().AllowExternalMicroServices();
|
||||
}
|
||||
|
||||
void MicroServiceALBCallback( std::string Callback()) {
|
||||
return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback);
|
||||
}
|
||||
|
||||
} // namespace OpenWifi
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace OpenWifi {
|
||||
void MicroServiceLoadConfigurationFile();
|
||||
void MicroServiceReload();
|
||||
void MicroServiceReload(const std::string &Type);
|
||||
const Types::StringVec MicroServiceGetLogLevelNames();
|
||||
const Types::StringVec MicroServiceGetSubSystems();
|
||||
Types::StringVec MicroServiceGetLogLevelNames();
|
||||
Types::StringVec MicroServiceGetSubSystems();
|
||||
Types::StringPairVec MicroServiceGetLogLevels();
|
||||
bool MicroServiceSetSubsystemLogLevel(const std::string &SubSystem, const std::string &Level);
|
||||
void MicroServiceGetExtraConfiguration(Poco::JSON::Object &Answer);
|
||||
@@ -40,10 +40,10 @@ namespace OpenWifi {
|
||||
std::uint64_t MicroServiceUptimeTotalSeconds();
|
||||
std::uint64_t MicroServiceStartTimeEpochTime();
|
||||
std::string MicroServiceGetUIURI();
|
||||
const SubSystemVec MicroServiceGetFullSubSystems();
|
||||
SubSystemVec MicroServiceGetFullSubSystems();
|
||||
std::string MicroServiceCreateUUID();
|
||||
std::uint64_t MicroServiceDaemonBusTimer();
|
||||
std::string MicroServiceMakeSystemEventMessage(const std::string &Type);
|
||||
std::string MicroServiceMakeSystemEventMessage(const char *Type);
|
||||
Poco::ThreadPool &MicroServiceTimerPool();
|
||||
std::string MicroServiceConfigPath(const std::string &Key, const std::string &DefaultValue);
|
||||
std::string MicroServiceWWWAssetsDir();
|
||||
@@ -53,4 +53,5 @@ namespace OpenWifi {
|
||||
std::string MicroServiceGetPublicAPIEndPoint();
|
||||
void MicroServiceDeleteOverrideConfiguration();
|
||||
bool AllowExternalMicroServices();
|
||||
void MicroServiceALBCallback( std::string Callback());
|
||||
} // namespace OpenWifi
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace OpenWifi::Types {
|
||||
typedef std::string UUID_t;
|
||||
typedef std::vector<UUID_t> UUIDvec_t;
|
||||
typedef std::map<std::string, std::map<uint32_t, uint64_t>> Counted3DMapSII;
|
||||
typedef std::vector<int64_t> IntList;
|
||||
typedef std::vector<uint64_t> UIntList;
|
||||
typedef std::vector<double> DoubleList;
|
||||
|
||||
struct MicroServiceMeta {
|
||||
uint64_t Id = 0;
|
||||
|
||||
@@ -574,6 +574,16 @@ namespace OpenWifi {
|
||||
Poco::JSON::Stringifier::stringify(Object, Answer);
|
||||
}
|
||||
|
||||
inline void ReturnObject(const std::vector<std::string> &Strings) {
|
||||
Poco::JSON::Array Arr;
|
||||
for(const auto &String:Strings) {
|
||||
Arr.add(String);
|
||||
}
|
||||
std::ostringstream os;
|
||||
Arr.stringify(os);
|
||||
return ReturnRawJSON(os.str());
|
||||
}
|
||||
|
||||
inline void ReturnRawJSON(const std::string &json_doc) {
|
||||
PrepareResponse();
|
||||
if (Request != nullptr) {
|
||||
|
||||
@@ -24,50 +24,63 @@ namespace OpenWifi {
|
||||
Server, TransactionId, Internal) {}
|
||||
static auto PathName() { return std::list<std::string>{"/api/v1/system"}; }
|
||||
|
||||
inline void DoGet() {
|
||||
inline void DoGet() final {
|
||||
std::string Arg;
|
||||
if (HasParameter("command", Arg) && Arg == "info") {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(RESTAPI::Protocol::VERSION, MicroServiceVersion());
|
||||
Answer.set(RESTAPI::Protocol::UPTIME, MicroServiceUptimeTotalSeconds());
|
||||
Answer.set(RESTAPI::Protocol::START, MicroServiceStartTimeEpochTime());
|
||||
Answer.set(RESTAPI::Protocol::OS, Poco::Environment::osName());
|
||||
Answer.set(RESTAPI::Protocol::PROCESSORS, Poco::Environment::processorCount());
|
||||
Answer.set(RESTAPI::Protocol::HOSTNAME, Poco::Environment::nodeName());
|
||||
Answer.set(RESTAPI::Protocol::UI, MicroServiceGetUIURI());
|
||||
if (HasParameter("command", Arg)) {
|
||||
if (Arg == "info") {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(RESTAPI::Protocol::VERSION, MicroServiceVersion());
|
||||
Answer.set(RESTAPI::Protocol::UPTIME, MicroServiceUptimeTotalSeconds());
|
||||
Answer.set(RESTAPI::Protocol::START, MicroServiceStartTimeEpochTime());
|
||||
Answer.set(RESTAPI::Protocol::OS, Poco::Environment::osName());
|
||||
Answer.set(RESTAPI::Protocol::PROCESSORS, Poco::Environment::processorCount());
|
||||
Answer.set(RESTAPI::Protocol::HOSTNAME, Poco::Environment::nodeName());
|
||||
Answer.set(RESTAPI::Protocol::UI, MicroServiceGetUIURI());
|
||||
|
||||
Poco::JSON::Array Certificates;
|
||||
auto SubSystems = MicroServiceGetFullSubSystems();
|
||||
std::set<std::string> CertNames;
|
||||
Poco::JSON::Array Certificates;
|
||||
auto SubSystems = MicroServiceGetFullSubSystems();
|
||||
std::set<std::string> CertNames;
|
||||
|
||||
for (const auto &i : SubSystems) {
|
||||
auto Hosts = i->HostSize();
|
||||
for (uint64_t j = 0; j < Hosts; ++j) {
|
||||
auto CertFileName = i->Host(j).CertFile();
|
||||
if (!CertFileName.empty()) {
|
||||
Poco::File F1(CertFileName);
|
||||
if (F1.exists()) {
|
||||
auto InsertResult = CertNames.insert(CertFileName);
|
||||
if (InsertResult.second) {
|
||||
Poco::JSON::Object Inner;
|
||||
Poco::Path F(CertFileName);
|
||||
Inner.set("filename", F.getFileName());
|
||||
Poco::Crypto::X509Certificate C(CertFileName);
|
||||
auto ExpiresOn = C.expiresOn();
|
||||
Inner.set("expiresOn", ExpiresOn.timestamp().epochTime());
|
||||
Certificates.add(Inner);
|
||||
for (const auto &i : SubSystems) {
|
||||
auto Hosts = i->HostSize();
|
||||
for (uint64_t j = 0; j < Hosts; ++j) {
|
||||
auto CertFileName = i->Host(j).CertFile();
|
||||
if (!CertFileName.empty()) {
|
||||
Poco::File F1(CertFileName);
|
||||
if (F1.exists()) {
|
||||
auto InsertResult = CertNames.insert(CertFileName);
|
||||
if (InsertResult.second) {
|
||||
Poco::JSON::Object Inner;
|
||||
Poco::Path F(CertFileName);
|
||||
Inner.set("filename", F.getFileName());
|
||||
Poco::Crypto::X509Certificate C(CertFileName);
|
||||
auto ExpiresOn = C.expiresOn();
|
||||
Inner.set("expiresOn", ExpiresOn.timestamp().epochTime());
|
||||
Certificates.add(Inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Answer.set("certificates", Certificates);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
if (Arg == "extraConfiguration") {
|
||||
Poco::JSON::Object Answer;
|
||||
MicroServiceGetExtraConfiguration(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
if (Arg == "resources") {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("numberOfFileDescriptors", Utils::get_open_fds());
|
||||
std::uint64_t currRealMem, peakRealMem, currVirtMem, peakVirtMem;
|
||||
Utils::getMemory(currRealMem, peakRealMem, currVirtMem, peakVirtMem);
|
||||
Answer.set("currRealMem", currRealMem);
|
||||
Answer.set("peakRealMem", peakRealMem);
|
||||
Answer.set("currVirtMem", currVirtMem);
|
||||
Answer.set("peakVirtMem", peakVirtMem);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
Answer.set("certificates", Certificates);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
if (GetBoolParameter("extraConfiguration")) {
|
||||
Poco::JSON::Object Answer;
|
||||
MicroServiceGetExtraConfiguration(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
BadRequest(RESTAPI::Errors::InvalidCommand);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,15 @@
|
||||
#include "framework/OpenWifiTypes.h"
|
||||
#include "framework/utils.h"
|
||||
|
||||
#include <RESTObjects/RESTAPI_SecurityObjects.h>
|
||||
|
||||
namespace OpenWifi::RESTAPI_utils {
|
||||
|
||||
inline bool IsRootOrAdmin(const SecurityObjects::UserInfo &UI) {
|
||||
return UI.userRole==SecurityObjects::ROOT ||
|
||||
UI.userRole==SecurityObjects::ADMIN;
|
||||
}
|
||||
|
||||
inline void EmbedDocument(const std::string &ObjName, Poco::JSON::Object &Obj,
|
||||
const std::string &ObjStr) {
|
||||
std::string D = ObjStr.empty() ? "{}" : ObjStr;
|
||||
@@ -95,6 +102,20 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
Obj.set(Field, A);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::DoubleList &V) {
|
||||
Poco::JSON::Array A;
|
||||
for (const auto &i : V)
|
||||
A.add(i);
|
||||
Obj.set(Field, A);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::IntList &V) {
|
||||
Poco::JSON::Array A;
|
||||
for (const auto &i : V)
|
||||
A.add(i);
|
||||
Obj.set(Field, A);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::TagList &V) {
|
||||
Poco::JSON::Array A;
|
||||
for (const auto &i : V)
|
||||
@@ -277,6 +298,28 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
}
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
|
||||
Types::DoubleList &Value) {
|
||||
if (Obj->isArray(Field) && !Obj->isNull(Field)) {
|
||||
Value.clear();
|
||||
Poco::JSON::Array::Ptr A = Obj->getArray(Field);
|
||||
for (const auto &i : *A) {
|
||||
Value.push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
|
||||
Types::IntList &Value) {
|
||||
if (Obj->isArray(Field) && !Obj->isNull(Field)) {
|
||||
Value.clear();
|
||||
Poco::JSON::Array::Ptr A = Obj->getArray(Field);
|
||||
for (const auto &i : *A) {
|
||||
Value.push_back(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
|
||||
std::vector<T> &Value) {
|
||||
|
||||
@@ -22,9 +22,8 @@ namespace OpenWifi {
|
||||
|
||||
class StorageClass : public SubSystemServer {
|
||||
public:
|
||||
StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {}
|
||||
|
||||
int Start() override {
|
||||
inline int Start() override {
|
||||
std::lock_guard Guard(Mutex_);
|
||||
|
||||
Logger().notice("Starting.");
|
||||
@@ -40,17 +39,22 @@ namespace OpenWifi {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Stop() override { Pool_->shutdown(); }
|
||||
inline void Stop() override { Pool_->shutdown(); }
|
||||
|
||||
DBType Type() const { return dbType_; };
|
||||
|
||||
StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
inline int Setup_SQLite();
|
||||
inline int Setup_MySQL();
|
||||
inline int Setup_PostgreSQL();
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Poco::Data::SessionPool> Pool_;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Poco::Data::SessionPool> Pool_;
|
||||
Poco::Data::SQLite::Connector SQLiteConn_;
|
||||
Poco::Data::PostgreSQL::Connector PostgresConn_;
|
||||
Poco::Data::MySQL::Connector MySQLConn_;
|
||||
@@ -81,7 +85,7 @@ namespace OpenWifi {
|
||||
// Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 8,
|
||||
// (int)NumSessions,
|
||||
// (int)IdleTime));
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8,
|
||||
Pool_ = std::make_shared<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8,
|
||||
(int)NumSessions, (int)IdleTime);
|
||||
return 0;
|
||||
}
|
||||
@@ -102,7 +106,7 @@ namespace OpenWifi {
|
||||
";compress=true;auto-reconnect=true";
|
||||
|
||||
Poco::Data::MySQL::Connector::registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8,
|
||||
Pool_ = std::make_shared<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8,
|
||||
NumSessions, IdleTime);
|
||||
|
||||
return 0;
|
||||
@@ -126,7 +130,7 @@ namespace OpenWifi {
|
||||
" connect_timeout=" + ConnectionTimeout;
|
||||
|
||||
Poco::Data::PostgreSQL::Connector::registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8,
|
||||
Pool_ = std::make_shared<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8,
|
||||
NumSessions, IdleTime);
|
||||
|
||||
return 0;
|
||||
|
||||
63
src/framework/default_device_types.h
Normal file
63
src/framework/default_device_types.h
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by stephane bourque on 2023-04-19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace OpenWifi {
|
||||
inline const std::vector<std::pair<std::string, std::string>> DefaultDeviceTypeList{
|
||||
{"actiontec_web7200", "AP"},
|
||||
{"cig_wf186w", "AP"},
|
||||
{"cig_wf188n", "AP"},
|
||||
{"cig_wf194c4", "AP"},
|
||||
{"cig_wf196", "AP"},
|
||||
{"cig_wf196-ca", "AP"},
|
||||
{"cig_wf196-ca-ath12", "AP"},
|
||||
{"cig_wf196-us", "AP"},
|
||||
{"cig_wf610d", "AP"},
|
||||
{"cig_wf660a", "AP"},
|
||||
{"cig_wf808", "AP"},
|
||||
{"cybertan_eww622-a1", "AP"},
|
||||
{"edgecore_eap101", "AP"},
|
||||
{"edgecore_eap101-ath12", "AP"},
|
||||
{"edgecore_eap102", "AP"},
|
||||
{"edgecore_eap104", "AP"},
|
||||
{"edgecore_eap104-ath12", "AP"},
|
||||
{"edgecore_ecs4100-12ph", "AP"},
|
||||
{"edgecore_ecw5211", "AP"},
|
||||
{"edgecore_ecw5410", "AP"},
|
||||
{"edgecore_oap100", "AP"},
|
||||
{"edgecore_spw2ac1200", "SWITCH"},
|
||||
{"edgecore_spw2ac1200-lan-poe", "SWITCH"},
|
||||
{"edgecore_ssw2ac2600", "SWITCH"},
|
||||
{"hfcl_ion4", "AP"},
|
||||
{"hfcl_ion4x", "AP"},
|
||||
{"hfcl_ion4x_2", "AP"},
|
||||
{"hfcl_ion4xe", "AP"},
|
||||
{"hfcl_ion4xi", "AP"},
|
||||
{"indio_um-305ac", "AP"},
|
||||
{"indio_um-305ax", "AP"},
|
||||
{"indio_um-310ax-v1", "AP"},
|
||||
{"indio_um-325ac", "AP"},
|
||||
{"indio_um-510ac-v3", "AP"},
|
||||
{"indio_um-510axm-v1", "AP"},
|
||||
{"indio_um-510axp-v1", "AP"},
|
||||
{"indio_um-550ac", "AP"},
|
||||
{"linksys_e8450-ubi", "AP"},
|
||||
{"linksys_ea6350-v4", "AP"},
|
||||
{"linksys_ea8300", "AP"},
|
||||
{"liteon_wpx8324", "AP"},
|
||||
{"meshpp_s618_cp01", "AP"},
|
||||
{"meshpp_s618_cp03", "AP"},
|
||||
{"udaya_a5-id2", "AP"},
|
||||
{"wallys_dr40x9", "AP"},
|
||||
{"wallys_dr6018", "AP"},
|
||||
{"wallys_dr6018_v4", "AP"},
|
||||
{"x64_vm", "AP"},
|
||||
{"yuncore_ax840", "AP"},
|
||||
{"yuncore_fap640", "AP"},
|
||||
{"yuncore_fap650", "AP"}};
|
||||
}
|
||||
@@ -401,6 +401,12 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
1171, "Command not supported on simulated device."
|
||||
};
|
||||
|
||||
static const struct msg VenuesNameAlreadyExists {
|
||||
1172, "The venue name already exists."
|
||||
};
|
||||
|
||||
static const struct msg DefFirmwareNameExists { 1172, "Firmware name already exists." };
|
||||
|
||||
static const struct msg SimulationDoesNotExist {
|
||||
7000, "Simulation Instance ID does not exist."
|
||||
};
|
||||
@@ -566,6 +572,7 @@ namespace OpenWifi::uCentralProtocol {
|
||||
static const char *HEALTHCHECK = "healthcheck";
|
||||
static const char *LOG = "log";
|
||||
static const char *CRASHLOG = "crashlog";
|
||||
static const char *REBOOTLOG = "rebootLog";
|
||||
static const char *PING = "ping";
|
||||
static const char *CFGPENDING = "cfgpending";
|
||||
static const char *RECOVERY = "recovery";
|
||||
@@ -624,6 +631,8 @@ namespace OpenWifi::uCentralProtocol {
|
||||
static const char *DEVICEUPDATE = "deviceupdate";
|
||||
static const char *FWSIGNATURE = "FWsignature";
|
||||
static const char *SIGNATURE = "signature";
|
||||
static const char *INFO = "info";
|
||||
static const char *DATE = "date";
|
||||
|
||||
static const char *SERIALNUMBER = "serialNumber";
|
||||
static const char *COMPATIBLE = "compatible";
|
||||
@@ -654,6 +663,7 @@ namespace OpenWifi::uCentralProtocol::Events {
|
||||
static const char *HEALTHCHECK = "healthcheck";
|
||||
static const char *LOG = "log";
|
||||
static const char *CRASHLOG = "crashlog";
|
||||
static const char *REBOOTLOG = "rebootLog";
|
||||
static const char *PING = "ping";
|
||||
static const char *CFGPENDING = "cfgpending";
|
||||
static const char *RECOVERY = "recovery";
|
||||
@@ -677,7 +687,8 @@ namespace OpenWifi::uCentralProtocol::Events {
|
||||
ET_VENUEBROADCAST,
|
||||
ET_EVENT,
|
||||
ET_WIFISCAN,
|
||||
ET_ALARM
|
||||
ET_ALARM,
|
||||
ET_REBOOTLOG
|
||||
};
|
||||
|
||||
inline EVENT_MSG EventFromString(const std::string &Method) {
|
||||
@@ -708,8 +719,10 @@ namespace OpenWifi::uCentralProtocol::Events {
|
||||
else if (strcmp(WIFISCAN, Method.c_str()) == 0)
|
||||
return ET_WIFISCAN;
|
||||
else if (strcmp(ALARM, Method.c_str()) == 0)
|
||||
return ET_WIFISCAN;
|
||||
return ET_ALARM;
|
||||
return ET_ALARM;
|
||||
else if (strcmp(REBOOTLOG, Method.c_str()) == 0)
|
||||
return ET_REBOOTLOG;
|
||||
return ET_UNKNOWN;
|
||||
};
|
||||
} // namespace OpenWifi::uCentralProtocol::Events
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@ namespace OpenWifi::Utils {
|
||||
std::all_of(Serial.begin(), Serial.end(), [](auto i) { return std::isxdigit(i); }));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool ValidSerialNumbers(const std::vector<std::string> &numbers) {
|
||||
return std::all_of(numbers.begin(),numbers.end(),[](auto &number) {return ValidSerialNumber(number);});
|
||||
}
|
||||
|
||||
[[nodiscard]] bool ValidUUID(const std::string &UUID) {
|
||||
if (UUID.size() > 36)
|
||||
return false;
|
||||
@@ -128,6 +132,15 @@ namespace OpenWifi::Utils {
|
||||
return std::regex_match(Hostname, HostNameRegex);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool ValidNumber(const std::string &number, bool isSigned)
|
||||
{
|
||||
static std::regex IntRegex("^-?[0-9]\\d*(\\.\\d+)?$");
|
||||
if(!isSigned) {
|
||||
IntRegex = "^[0-9]\\d*(\\.\\d+)?$";
|
||||
}
|
||||
return std::regex_match(number, IntRegex);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string ToHex(const std::vector<unsigned char> &B) {
|
||||
std::string R;
|
||||
R.reserve(B.size() * 2);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#include "Poco/Base64Decoder.h"
|
||||
#include "Poco/Base64Encoder.h"
|
||||
#include "Poco/File.h"
|
||||
@@ -68,8 +70,10 @@ namespace OpenWifi::Utils {
|
||||
};
|
||||
|
||||
[[nodiscard]] bool ValidSerialNumber(const std::string &Serial);
|
||||
[[nodiscard]] bool ValidSerialNumbers(const std::vector<std::string> &Serial);
|
||||
[[nodiscard]] bool ValidUUID(const std::string &UUID);
|
||||
[[nodiscard]] bool ValidHostname(const std::string &hostname);
|
||||
[[nodiscard]] bool ValidNumber(const std::string &number, bool isSigned);
|
||||
|
||||
template <typename... Args> std::string ComputeHash(Args &&...args) {
|
||||
Poco::SHA2Engine E;
|
||||
@@ -146,4 +150,101 @@ namespace OpenWifi::Utils {
|
||||
|
||||
bool ExtractBase64CompressedData(const std::string &CompressedData,
|
||||
std::string &UnCompressedData, uint64_t compress_sz);
|
||||
|
||||
inline bool match(const char* first, const char* second)
|
||||
{
|
||||
// If we reach at the end of both strings, we are done
|
||||
if (*first == '\0' && *second == '\0')
|
||||
return true;
|
||||
|
||||
// Make sure to eliminate consecutive '*'
|
||||
if (*first == '*') {
|
||||
while (*(first + 1) == '*')
|
||||
first++;
|
||||
}
|
||||
|
||||
// Make sure that the characters after '*' are present
|
||||
// in second string. This function assumes that the
|
||||
// first string will not contain two consecutive '*'
|
||||
if (*first == '*' && *(first + 1) != '\0'
|
||||
&& *second == '\0')
|
||||
return false;
|
||||
|
||||
// If the first string contains '?', or current
|
||||
// characters of both strings match
|
||||
if (*first == '?' || *first == *second)
|
||||
return match(first + 1, second + 1);
|
||||
|
||||
// If there is *, then there are two possibilities
|
||||
// a) We consider current character of second string
|
||||
// b) We ignore current character of second string.
|
||||
if (*first == '*')
|
||||
return match(first + 1, second)
|
||||
|| match(first, second + 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline std::uint64_t GetValue(FILE *file) {
|
||||
unsigned long v=0;
|
||||
char factor[32];
|
||||
if(fscanf(file, " %lu %31s", &v, factor)==2) {
|
||||
switch (factor[0]) {
|
||||
case 'k':
|
||||
return v * 1000;
|
||||
case 'M':
|
||||
return v * 1000000;
|
||||
case 'G':
|
||||
return v * 1000000000;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
inline bool getMemory(
|
||||
std::uint64_t &currRealMem, std::uint64_t &peakRealMem,
|
||||
std::uint64_t &currVirtMem, std::uint64_t &peakVirtMem) {
|
||||
|
||||
// stores each word in status file
|
||||
char buffer[1024] = "";
|
||||
|
||||
currRealMem = peakRealMem = currVirtMem = peakVirtMem = 0;
|
||||
|
||||
// linux file contains this-process info
|
||||
FILE * file = std::fopen("/proc/self/status", "r");
|
||||
if (file == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// read the entire file, recording mems in kB
|
||||
while (fscanf(file, " %1023s", buffer) == 1) {
|
||||
|
||||
if (strcmp(buffer, "VmRSS:") == 0) {
|
||||
currRealMem= GetValue(file);
|
||||
} else if (strcmp(buffer, "VmHWM:") == 0) {
|
||||
peakRealMem= GetValue(file);
|
||||
} else if (strcmp(buffer, "VmSize:") == 0) {
|
||||
currVirtMem= GetValue(file);
|
||||
} else if (strcmp(buffer, "VmPeak:") == 0) {
|
||||
peakVirtMem= GetValue(file);
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline int get_open_fds() {
|
||||
DIR *dp = opendir("/proc/self/fd");
|
||||
struct dirent *de;
|
||||
int count = -3; // '.', '..', dp
|
||||
|
||||
if (dp == nullptr)
|
||||
return -1;
|
||||
while ((de = readdir(dp)) != nullptr)
|
||||
count++;
|
||||
(void)closedir(dp);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
} // namespace OpenWifi::Utils
|
||||
|
||||
@@ -135,7 +135,7 @@ createsim() {
|
||||
echo "Simulation file is not passed as an argument. Please pass the simulation. To get example simulation definition, run 'examplesim' command and check 'example-sim.json' file"
|
||||
exit 1
|
||||
else
|
||||
curl ${FLAGS} -X POST "https://${OWLS}/api/v1/simulation" \
|
||||
curl ${FLAGS} -X POST "https://${OWLS}/api/v1/simulation/0" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "accept: application/json" \
|
||||
@@ -145,7 +145,7 @@ createsim() {
|
||||
}
|
||||
|
||||
listsims() {
|
||||
testargcount 0 #$
|
||||
testargcount 0 $#
|
||||
curl ${FLAGS} -X GET "https://${OWLS}/api/v1/simulation/*" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -153,7 +153,7 @@ listsims() {
|
||||
}
|
||||
|
||||
getsim() {
|
||||
testargcount 1 #$
|
||||
testargcount 1 $#
|
||||
curl ${FLAGS} -X GET "https://${OWLS}/api/v1/simulation/$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -161,7 +161,7 @@ getsim() {
|
||||
}
|
||||
|
||||
deletesim() {
|
||||
testargcount 1 #$
|
||||
testargcount 1 $#
|
||||
curl ${FLAGS} -X DELETE "https://${OWLS}/api/v1/simulation?id=$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -169,7 +169,7 @@ deletesim() {
|
||||
}
|
||||
|
||||
startsim() {
|
||||
testargcount 1 #$
|
||||
testargcount 1 $#
|
||||
curl ${FLAGS} -X POST "https://${OWLS}/api/v1/operation/$1?operation=start" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -177,7 +177,7 @@ startsim() {
|
||||
}
|
||||
|
||||
stopsim() {
|
||||
testargcount 2 #$
|
||||
testargcount 2 $#
|
||||
curl ${FLAGS} -X POST "https://${OWLS}/api/v1/operation/$1?operation=stop&runningId=$2" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -185,7 +185,7 @@ stopsim() {
|
||||
}
|
||||
|
||||
cancelsim() {
|
||||
testargcount 2 #$
|
||||
testargcount 2 $#
|
||||
curl ${FLAGS} -X POST "https://${OWLS}/api/v1/operation/$1?operation=cancel" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -193,7 +193,7 @@ cancelsim() {
|
||||
}
|
||||
|
||||
getsimstats() {
|
||||
testargcount 1 #$
|
||||
testargcount 1 $#
|
||||
curl ${FLAGS} -X GET "https://${OWLS}/api/v1/status/$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -201,7 +201,7 @@ getsimstats() {
|
||||
}
|
||||
|
||||
liststatuses() {
|
||||
testargcount 0 #$
|
||||
testargcount 0 $#
|
||||
curl ${FLAGS} -X GET "https://${OWLS}/api/v1/status/*" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
@@ -209,7 +209,7 @@ liststatuses() {
|
||||
}
|
||||
|
||||
results() {
|
||||
testargcount 1 #$
|
||||
testargcount 1 $#
|
||||
curl ${FLAGS} -X GET "https://${OWLS}/api/v1/results/$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
|
||||
Reference in New Issue
Block a user