From a062ff084e4e078052d655a30c76f24dbfdcd896 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Wed, 26 Oct 2022 21:56:39 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-11280 Signed-off-by: stephb9959 --- CMakeLists.txt | 6 +- build | 2 +- src/RESTObjects/RESTAPI_OWLSobjects.cpp | 110 ++++++++++++++++++ src/RESTObjects/RESTAPI_OWLSobjects.h | 77 +++++++++++++ src/RESTObjects/RESTAPI_ProvObjects.cpp | 35 ++++++ src/RESTObjects/RESTAPI_ProvObjects.h | 18 ++- src/RESTObjects/RESTAPI_SecurityObjects.h | 3 +- src/framework/MicroServiceFuncs.cpp | 134 +++++++++++++--------- src/framework/MicroServiceFuncs.h | 6 + 9 files changed, 329 insertions(+), 62 deletions(-) create mode 100644 src/RESTObjects/RESTAPI_OWLSobjects.cpp create mode 100644 src/RESTObjects/RESTAPI_OWLSobjects.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 740f2620..d4269b47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,9 +120,13 @@ add_executable( owgw src/framework/MicroService.cpp src/framework/MicroServiceExtra.h src/RESTObjects/RESTAPI_SecurityObjects.h src/RESTObjects/RESTAPI_SecurityObjects.cpp - src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp src/RESTObjects/RESTAPI_FMSObjects.h src/RESTObjects/RESTAPI_FMSObjects.cpp + src/RESTObjects/RESTAPI_CertObjects.cpp src/RESTObjects/RESTAPI_CertObjects.h + 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/RESTObjects/RESTAPI_SubObjects.cpp src/RESTObjects/RESTAPI_SubObjects.h src/RESTAPI/RESTAPI_devices_handler.cpp src/RESTAPI/RESTAPI_devices_handler.h src/RESTAPI/RESTAPI_device_handler.cpp src/RESTAPI/RESTAPI_device_handler.h src/RESTAPI/RESTAPI_device_commandHandler.cpp src/RESTAPI/RESTAPI_device_commandHandler.h diff --git a/build b/build index 8580e7b6..1758dddc 100644 --- a/build +++ b/build @@ -1 +1 @@ -30 \ No newline at end of file +32 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_OWLSobjects.cpp b/src/RESTObjects/RESTAPI_OWLSobjects.cpp new file mode 100644 index 00000000..15e5f0a0 --- /dev/null +++ b/src/RESTObjects/RESTAPI_OWLSobjects.cpp @@ -0,0 +1,110 @@ +// +// Created by stephane bourque on 2021-08-31. +// + +#include "framework/RESTAPI_utils.h" + +using OpenWifi::RESTAPI_utils::field_to_json; +using OpenWifi::RESTAPI_utils::field_from_json; +using OpenWifi::RESTAPI_utils::EmbedDocument; + +#include "RESTAPI_OWLSobjects.h" + +// SIM -> 0x53/0x073, 0x49/0x69, 0x4d/0x6d + +namespace OpenWifi::OWLSObjects { + + void SimulationDetails::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"id", id); + field_to_json(Obj,"name", name); + field_to_json(Obj,"gateway", gateway); + field_to_json(Obj,"certificate", certificate); + field_to_json(Obj,"key", key); + field_to_json(Obj,"macPrefix", macPrefix); + field_to_json(Obj,"deviceType", deviceType); + field_to_json(Obj,"devices", devices); + field_to_json(Obj,"healthCheckInterval", healthCheckInterval); + field_to_json(Obj,"stateInterval", stateInterval); + field_to_json(Obj,"minAssociations", minAssociations); + field_to_json(Obj,"maxAssociations", maxAssociations); + field_to_json(Obj,"minClients", minClients); + field_to_json(Obj,"maxClients", maxClients); + field_to_json(Obj,"simulationLength", simulationLength); + field_to_json(Obj,"threads", threads); + field_to_json(Obj,"clientInterval", clientInterval); + field_to_json(Obj,"keepAlive", keepAlive); + field_to_json(Obj,"reconnectInterval", reconnectInterval); + field_to_json(Obj,"concurrentDevices", concurrentDevices); + } + + bool SimulationDetails::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"id", id); + field_from_json(Obj,"name", name); + field_from_json(Obj,"gateway", gateway); + field_from_json(Obj,"certificate", certificate); + field_from_json(Obj,"key", key); + field_from_json(Obj,"macPrefix", macPrefix); + field_from_json(Obj,"deviceType", deviceType); + field_from_json(Obj,"devices", devices); + field_from_json(Obj,"healthCheckInterval", healthCheckInterval); + field_from_json(Obj,"stateInterval", stateInterval); + field_from_json(Obj,"minAssociations", minAssociations); + field_from_json(Obj,"maxAssociations", maxAssociations); + field_from_json(Obj,"minClients", minClients); + field_from_json(Obj,"maxClients", maxClients); + field_from_json(Obj,"simulationLength", simulationLength); + field_from_json(Obj,"threads", threads); + field_from_json(Obj,"clientInterval", clientInterval); + field_from_json(Obj,"keepAlive", keepAlive); + field_from_json(Obj,"reconnectInterval", reconnectInterval); + field_from_json(Obj,"concurrentDevices", concurrentDevices); + return true; + } catch(...) { + + } + return false; + } + + void SimulationDetailsList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"list", list); + } + + bool SimulationDetailsList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"list", list); + return true; + } catch(...) { + + } + return false; + } + + void SimulationStatus::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"id", id); + field_to_json(Obj,"simulationId", simulationId); + field_to_json(Obj,"state", state); + field_to_json(Obj,"tx", tx); + field_to_json(Obj,"rx", rx); + field_to_json(Obj,"msgsTx", msgsTx); + field_to_json(Obj,"msgsRx", msgsRx); + field_to_json(Obj,"liveDevices", liveDevices); + field_to_json(Obj,"timeToFullDevices", timeToFullDevices); + field_to_json(Obj,"startTime", startTime); + field_to_json(Obj,"endTime", endTime); + field_to_json(Obj,"errorDevices", errorDevices); + field_to_json(Obj,"owner", owner); + } + + void Dashboard::to_json([[maybe_unused]] Poco::JSON::Object &Obj) const { + + } + + bool Dashboard::from_json([[maybe_unused]] const Poco::JSON::Object::Ptr &Obj) { + return true; + } + + void Dashboard::reset() { + + } +} diff --git a/src/RESTObjects/RESTAPI_OWLSobjects.h b/src/RESTObjects/RESTAPI_OWLSobjects.h new file mode 100644 index 00000000..4dadcb62 --- /dev/null +++ b/src/RESTObjects/RESTAPI_OWLSobjects.h @@ -0,0 +1,77 @@ +// +// Created by stephane bourque on 2021-08-31. +// + +#ifndef UCENTRALSIM_RESTAPI_OWLSOBJECTS_H +#define UCENTRALSIM_RESTAPI_OWLSOBJECTS_H + +#include +#include "Poco/JSON/Object.h" + +namespace OpenWifi::OWLSObjects { + + struct SimulationDetails { + std::string id; + std::string name; + std::string gateway; + std::string certificate; + std::string key; + std::string macPrefix; + std::string deviceType; + uint64_t devices = 5; + uint64_t healthCheckInterval = 60; + uint64_t stateInterval = 60 ; + uint64_t minAssociations = 1; + uint64_t maxAssociations = 3; + uint64_t minClients = 1 ; + uint64_t maxClients = 3; + uint64_t simulationLength = 60 * 60; + uint64_t threads = 16; + uint64_t clientInterval = 1; + uint64_t keepAlive = 300; + uint64_t reconnectInterval = 30 ; + uint64_t concurrentDevices = 5; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct SimulationDetailsList { + std::vector list; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct SimulationStatus { + std::string id; + std::string simulationId; + std::string state; + uint64_t tx; + uint64_t rx; + uint64_t msgsTx; + uint64_t msgsRx; + uint64_t liveDevices; + uint64_t timeToFullDevices; + uint64_t startTime; + uint64_t endTime; + uint64_t errorDevices; + std::string owner; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + + struct Dashboard { + int O; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + void reset(); + + }; + +} + + +#endif //UCENTRALSIM_RESTAPI_OWLSOBJECTS_H diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index e03b1f12..636fd171 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -1160,5 +1160,40 @@ namespace OpenWifi::ProvObjects { return false; } + void RRMAlgorithmDetails::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"name",name); + field_to_json(Obj,"parameters",parameters); + } + + bool RRMAlgorithmDetails::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"name",name); + field_from_json(Obj,"parameters",parameters); + return true; + } catch(...) { + + } + return false; + } + + void RRMDetails::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"vendor",vendor); + field_to_json(Obj,"schedule",schedule); + field_to_json(Obj,"algorithms",algorithms); + } + + bool RRMDetails::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj,"vendor",vendor); + field_from_json(Obj,"schedule",schedule); + field_from_json(Obj,"algorithms",algorithms); + return true; + } catch(...) { + + } + return false; + } + } + diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 4452af9d..59f59ed7 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -8,8 +8,7 @@ #pragma once -#include -#include "RESTAPI_SecurityObjects.h" +#include "RESTObjects/RESTAPI_SecurityObjects.h" namespace OpenWifi::ProvObjects { @@ -62,6 +61,21 @@ namespace OpenWifi::ProvObjects { }; typedef std::vector ManagementPolicyVec; + struct RRMAlgorithmDetails { + std::string name; + std::string parameters; + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct RRMDetails { + std::string vendor; + std::string schedule; + std::vector algorithms; + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + struct DeviceRules { std::string rcOnly{"inherit"}; std::string rrm{"inherit"}; diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.h b/src/RESTObjects/RESTAPI_SecurityObjects.h index a3f06e8b..ef74bc47 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.h +++ b/src/RESTObjects/RESTAPI_SecurityObjects.h @@ -251,7 +251,8 @@ namespace OpenWifi { VERIFY_EMAIL, SUB_FORGOT_PASSWORD, SUB_VERIFY_EMAIL, - SUB_SIGNUP + SUB_SIGNUP, + EMAIL_INVITATION }; struct ActionLink { diff --git a/src/framework/MicroServiceFuncs.cpp b/src/framework/MicroServiceFuncs.cpp index a715b494..33b9f552 100644 --- a/src/framework/MicroServiceFuncs.cpp +++ b/src/framework/MicroServiceFuncs.cpp @@ -6,88 +6,108 @@ #include "framework/MicroServiceFuncs.h" namespace OpenWifi { - const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); } + const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); } - Types::MicroServiceMetaVec MicroServiceGetServices(const std::string &Type) { - return MicroService::instance().GetServices(Type); - } + Types::MicroServiceMetaVec MicroServiceGetServices(const std::string &Type) { + return MicroService::instance().GetServices(Type); + } - std::string MicroServicePublicEndPoint() { return MicroService::instance().PublicEndPoint(); } + Types::MicroServiceMetaVec MicroServiceGetServices() { + return MicroService::instance().GetServices(); + } - std::string MicroServiceConfigGetString(const std::string &Key, const std::string &DefaultValue) { - return MicroService::instance().ConfigGetString(Key, DefaultValue); - } + std::string MicroServicePublicEndPoint() { return MicroService::instance().PublicEndPoint(); } - bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue) { - return MicroService::instance().ConfigGetBool(Key, DefaultValue); - } + std::string MicroServiceConfigGetString(const std::string &Key, const std::string &DefaultValue) { + return MicroService::instance().ConfigGetString(Key, DefaultValue); + } - std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue) { - return MicroService::instance().ConfigGetInt(Key, DefaultValue); - } + bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue) { + return MicroService::instance().ConfigGetBool(Key, DefaultValue); + } - std::string MicroServicePrivateEndPoint() { return MicroService::instance().PrivateEndPoint(); } + std::uint64_t MicroServiceConfigGetInt(const std::string &Key, std::uint64_t DefaultValue) { + return MicroService::instance().ConfigGetInt(Key, DefaultValue); + } - std::uint64_t MicroServiceID() { return MicroService::instance().ID(); } + std::string MicroServicePrivateEndPoint() { return MicroService::instance().PrivateEndPoint(); } - bool MicroServiceIsValidAPIKEY(const Poco::Net::HTTPServerRequest &Request) { - return MicroService::instance().IsValidAPIKEY(Request); - } + std::uint64_t MicroServiceID() { return MicroService::instance().ID(); } - bool MicroServiceNoAPISecurity() { return MicroService::instance().NoAPISecurity(); } + bool MicroServiceIsValidAPIKEY(const Poco::Net::HTTPServerRequest &Request) { + return MicroService::instance().IsValidAPIKEY(Request); + } - void MicroServiceLoadConfigurationFile() { MicroService::instance().LoadConfigurationFile(); } + bool MicroServiceNoAPISecurity() { return MicroService::instance().NoAPISecurity(); } - void MicroServiceReload() { MicroService::instance().Reload(); } + void MicroServiceLoadConfigurationFile() { MicroService::instance().LoadConfigurationFile(); } - void MicroServiceReload(const std::string &Type) { MicroService::instance().Reload(Type); } + void MicroServiceReload() { MicroService::instance().Reload(); } - const Types::StringVec MicroServiceGetLogLevelNames() { - return MicroService::instance().GetLogLevelNames(); - } + void MicroServiceReload(const std::string &Type) { MicroService::instance().Reload(Type); } - const Types::StringVec MicroServiceGetSubSystems() { - return MicroService::instance().GetSubSystems(); - } + const Types::StringVec MicroServiceGetLogLevelNames() { + return MicroService::instance().GetLogLevelNames(); + } - Types::StringPairVec MicroServiceGetLogLevels() { return MicroService::instance().GetLogLevels(); } + const Types::StringVec MicroServiceGetSubSystems() { + return MicroService::instance().GetSubSystems(); + } - bool MicroServiceSetSubsystemLogLevel(const std::string &SubSystem, const std::string &Level) { - return MicroService::instance().SetSubsystemLogLevel(SubSystem, Level); - } + Types::StringPairVec MicroServiceGetLogLevels() { return MicroService::instance().GetLogLevels(); } - void MicroServiceGetExtraConfiguration(Poco::JSON::Object &Answer) { - MicroService::instance().GetExtraConfiguration(Answer); - } + bool MicroServiceSetSubsystemLogLevel(const std::string &SubSystem, const std::string &Level) { + return MicroService::instance().SetSubsystemLogLevel(SubSystem, Level); + } - std::string MicroServiceVersion() { return MicroService::instance().Version(); } + void MicroServiceGetExtraConfiguration(Poco::JSON::Object &Answer) { + MicroService::instance().GetExtraConfiguration(Answer); + } - std::uint64_t MicroServiceUptimeTotalSeconds() { - return MicroService::instance().uptime().totalSeconds(); - } + std::string MicroServiceVersion() { return MicroService::instance().Version(); } - std::uint64_t MicroServiceStartTimeEpochTime() { - return MicroService::instance().startTime().epochTime(); - } + std::uint64_t MicroServiceUptimeTotalSeconds() { + return MicroService::instance().uptime().totalSeconds(); + } - std::string MicroServiceGetUIURI() { return MicroService::instance().GetUIURI(); } + std::uint64_t MicroServiceStartTimeEpochTime() { + return MicroService::instance().startTime().epochTime(); + } - const SubSystemVec MicroServiceGetFullSubSystems() { - return MicroService::instance().GetFullSubSystems(); - } + std::string MicroServiceGetUIURI() { return MicroService::instance().GetUIURI(); } - std::string MicroServiceCreateUUID() { return MicroService::CreateUUID(); } + const SubSystemVec MicroServiceGetFullSubSystems() { + return MicroService::instance().GetFullSubSystems(); + } - std::uint64_t MicroServiceDaemonBusTimer() { return MicroService::instance().DaemonBusTimer(); } + std::string MicroServiceCreateUUID() { return MicroService::CreateUUID(); } - std::string MicroServiceMakeSystemEventMessage(const std::string &Type) { - return MicroService::instance().MakeSystemEventMessage(Type); - } + std::uint64_t MicroServiceDaemonBusTimer() { return MicroService::instance().DaemonBusTimer(); } - Poco::ThreadPool &MicroServiceTimerPool() { return MicroService::instance().TimerPool(); } + std::string MicroServiceMakeSystemEventMessage(const std::string &Type) { + return MicroService::instance().MakeSystemEventMessage(Type); + } - std::string MicroServiceConfigPath(const std::string &Key, - const std::string &DefaultValue) { - return MicroService::instance().ConfigPath(Key, DefaultValue); - } + Poco::ThreadPool &MicroServiceTimerPool() { return MicroService::instance().TimerPool(); } + + std::string MicroServiceConfigPath(const std::string &Key, + const std::string &DefaultValue) { + return MicroService::instance().ConfigPath(Key, DefaultValue); + } + + std::string MicroServiceWWWAssetsDir() { + return MicroService::instance().WWWAssetsDir(); + } + + std::uint64_t MicroServiceRandom(std::uint64_t Start,std::uint64_t End) { + return MicroService::instance().Random(Start, End); + } + + std::string MicroServiceSign(Poco::JWT::Token &T, const std::string &Algo) { + return MicroService::instance().Sign(T, Algo); + } + + std::string MicroServiceGetPublicAPIEndPoint() { + return MicroService::instance().GetPublicAPIEndPoint(); + } } diff --git a/src/framework/MicroServiceFuncs.h b/src/framework/MicroServiceFuncs.h index 8244b32a..e0f9551e 100644 --- a/src/framework/MicroServiceFuncs.h +++ b/src/framework/MicroServiceFuncs.h @@ -11,6 +11,7 @@ #include "Poco/Net/HTTPServerRequest.h" #include "Poco/JSON/Object.h" #include "Poco/ThreadPool.h" +#include "Poco/JWT/Token.h" namespace OpenWifi { @@ -18,6 +19,7 @@ namespace OpenWifi { using SubSystemVec=std::vector; const std::string & MicroServiceDataDirectory(); Types::MicroServiceMetaVec MicroServiceGetServices(const std::string & Type); + Types::MicroServiceMetaVec MicroServiceGetServices(); std::string MicroServicePublicEndPoint(); std::string MicroServiceConfigGetString(const std::string &Key, const std::string &DefaultValue); bool MicroServiceConfigGetBool(const std::string &Key, bool DefaultValue); @@ -45,4 +47,8 @@ namespace OpenWifi { Poco::ThreadPool & MicroServiceTimerPool(); std::string MicroServiceConfigPath(const std::string &Key, const std::string &DefaultValue); + std::string MicroServiceWWWAssetsDir(); + std::uint64_t MicroServiceRandom(std::uint64_t Start,std::uint64_t End); + std::string MicroServiceSign(Poco::JWT::Token &T, const std::string &Algo); + std::string MicroServiceGetPublicAPIEndPoint(); }