From f96a9502be9248b5db081efdc7982c8871556607 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Fri, 18 Mar 2022 11:49:40 -0700 Subject: [PATCH] Adding time point recording. --- src/APStats.cpp | 13 +- src/APStats.h | 98 +--------- src/RESTObjects/RESTAPI_AnalyticsObjects.cpp | 63 +++++++ src/RESTObjects/RESTAPI_AnalyticsObjects.h | 180 +++++++++++++++---- src/framework/MicroService.h | 9 + 5 files changed, 225 insertions(+), 138 deletions(-) diff --git a/src/APStats.cpp b/src/APStats.cpp index 4fab754..4811326 100644 --- a/src/APStats.cpp +++ b/src/APStats.cpp @@ -19,7 +19,7 @@ namespace OpenWifi { DI_.states++; DI_.connected =true; - DeviceTimePoint DTP; + AnalyticsObjects::DeviceTimePoint DTP; // find radios first to get associations. try { @@ -48,7 +48,7 @@ namespace OpenWifi { uint radio_index = 0; for (const auto &radio: radios) { if (radio.contains("channel")) { - RadioTimePoint RTP; + AnalyticsObjects::RadioTimePoint RTP; RTP.band = radio["channel"] <= 16 ? 2 : 5; radio_band[radio_index++] = radio["channel"] <= 16 ? 2 : 5; GetJSON("busy_ms", radio, RTP.busy_ms, (uint64_t) 0); @@ -86,7 +86,7 @@ namespace OpenWifi { if(interface.contains("ssids")) { auto ssids = interface["ssids"]; for (const auto &ssid: ssids) { - SSIDTimePoint SSIDTP; + AnalyticsObjects::SSIDTimePoint SSIDTP; uint radio_location = 2; if(ssid.contains("radio")) { auto radio = ssid["radio"]; @@ -101,7 +101,7 @@ namespace OpenWifi { GetJSON("bssid",ssid,bssid, std::string{""}); SSIDTP.bssid = Utils::MACToInt(bssid); GetJSON("mode",ssid,mode, std::string{""} ); - SSIDTP.mode = SSID_Mode(mode); + SSIDTP.mode = AnalyticsObjects::SSID_Mode(mode); GetJSON("ssid",ssid,ssid_name, std::string{""} ); SSIDTP.ssid = SSID_DICT()->Add(ssid_name); if (ssid.contains("associations") && ssid["associations"].is_array()) { @@ -117,7 +117,7 @@ namespace OpenWifi { DI_.associations_6g += associations.size(); } for(const auto &association:associations) { - UETimePoint TP; + AnalyticsObjects::UETimePoint TP; std::string association_bssid,station; GetJSON("bssid",association,association_bssid, std::string{""} ); GetJSON("station",association,station, std::string{} ); @@ -137,7 +137,7 @@ namespace OpenWifi { if(association.contains("msdu") && association["msdu"].is_array()) { auto msdus = association["msdu"]; for(const auto &msdu:msdus) { - msdu_entry E; + AnalyticsObjects::msdu_entry E; GetJSON("rx_msdu",msdu,E.rx_msdu, (uint64_t)0 ); GetJSON("tx_msdu",msdu,E.tx_msdu, (uint64_t)0 ); GetJSON("tx_msdu_failed",msdu,E.tx_msdu_failed, (uint64_t)0 ); @@ -230,5 +230,4 @@ namespace OpenWifi { std::cout << Utils::IntToSerialNumber(mac_) << ": health failed parsing." << std::endl; } } - } \ No newline at end of file diff --git a/src/APStats.h b/src/APStats.h index 793d6b0..fc61455 100644 --- a/src/APStats.h +++ b/src/APStats.h @@ -16,102 +16,6 @@ namespace OpenWifi { const uint32_t ap_buffer_size = ap_length / interval; const uint32_t ue_buffer_size = ue_length / interval; - - enum wifi_band { - band_2g=0, band_5g=1, band_6g=2 - }; - - struct msdu_entry { - uint64_t rx_msdu=0, - tx_msdu=0, - tx_msdu_failed=0, - tx_msdu_retries=0; - }; - - struct UETimePoint { - uint64_t association_bssid=0,station=0; - int64_t rssi=0; - uint64_t tx_bytes=0, - rx_bytes=0, - tx_duration=0, - rx_packets=0, - tx_packets=0, - tx_retries=0, - tx_failed=0, - connected=0, - inactive=0; - std::vector msdus; - }; - - enum SSID_MODES { - unknown=0, - ap, - mesh, - sta, - wds_ap, - wds_sta, - wds_repeater - }; - - inline SSID_MODES SSID_Mode(const std::string &m) { - if(m=="ap") - return ap; - if(m=="sta") - return sta; - if(m=="mesh") - return mesh; - if(m=="wds-ap") - return wds_ap; - if(m=="wds-sta") - return wds_sta; - if(m=="wds-repeater") - return wds_repeater; - return unknown; - } - - struct SSIDTimePoint { - uint64_t bssid=0, - mode=0, - ssid=0; - std::vector associations; - }; - - - struct APTimePoint { - uint64_t collisions=0, - multicast=0, - rx_bytes=0, - rx_dropped=0, - rx_errors=0, - rx_packets=0, - tx_bytes=0, - tx_dropped=0, - tx_errors=0, - tx_packets=0; - }; - - struct RadioTimePoint { - uint band=0, - radio_channel=0; - uint64_t active_ms=0, - busy_ms=0, - receive_ms=0, - transmit_ms=0, - tx_power=0, - channel=0; - int64_t temperature=0, - noise=0; - }; - - - struct DeviceTimePoint { - uint64_t timestamp=0; - APTimePoint ap_data; - std::vector ssid_data; - std::vector radio_data; - AnalyticsObjects::DeviceInfo device_info; - }; - class AP { public: explicit AP(uint64_t mac) : mac_(mac) { @@ -126,6 +30,6 @@ namespace OpenWifi { private: uint64_t mac_=0; AnalyticsObjects::DeviceInfo DI_; - std::vector DTP_; + std::vector DTP_; }; } diff --git a/src/RESTObjects/RESTAPI_AnalyticsObjects.cpp b/src/RESTObjects/RESTAPI_AnalyticsObjects.cpp index ccc1676..afadf6f 100644 --- a/src/RESTObjects/RESTAPI_AnalyticsObjects.cpp +++ b/src/RESTObjects/RESTAPI_AnalyticsObjects.cpp @@ -129,4 +129,67 @@ namespace OpenWifi::AnalyticsObjects { return false; } + void UETimePoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"association_bssid",association_bssid); + field_to_json(Obj,"station",station); + field_to_json(Obj,"rssi",rssi); + field_to_json(Obj,"tx_bytes",tx_bytes); + field_to_json(Obj,"rx_bytes",rx_bytes); + field_to_json(Obj,"tx_duration",tx_duration); + field_to_json(Obj,"rx_packets",rx_packets); + field_to_json(Obj,"tx_packets",tx_packets); + field_to_json(Obj,"tx_retries",tx_retries); + field_to_json(Obj,"tx_failed",tx_failed); + field_to_json(Obj,"connected",connected); + field_to_json(Obj,"inactive",inactive); + } + + void APTimePoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"collisions",collisions); + field_to_json(Obj,"multicast",multicast); + field_to_json(Obj,"rx_bytes",rx_bytes); + field_to_json(Obj,"rx_dropped",rx_dropped); + field_to_json(Obj,"rx_errors",rx_errors); + field_to_json(Obj,"rx_packets",rx_packets); + field_to_json(Obj,"tx_bytes",tx_bytes); + field_to_json(Obj,"tx_packets",tx_packets); + field_to_json(Obj,"tx_dropped",tx_dropped); + field_to_json(Obj,"tx_errors",tx_errors); + field_to_json(Obj,"tx_packets",tx_packets); + } + + void msdu_entry::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"rx_msdu",rx_msdu); + field_to_json(Obj,"tx_msdu",tx_msdu); + field_to_json(Obj,"tx_msdu_failed",tx_msdu_failed); + field_to_json(Obj,"tx_msdu_retries",tx_msdu_retries); + } + + void RadioTimePoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"band",band); + field_to_json(Obj,"radio_channel",radio_channel); + field_to_json(Obj,"active_ms",active_ms); + field_to_json(Obj,"busy_ms",busy_ms); + field_to_json(Obj,"receive_ms",receive_ms); + field_to_json(Obj,"transmit_ms",transmit_ms); + field_to_json(Obj,"tx_power",tx_power); + field_to_json(Obj,"channel",channel); + field_to_json(Obj,"temperature",temperature); + field_to_json(Obj,"noise",noise); + } + + void SSIDTimePoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"bssid",bssid); + field_to_json(Obj,"mode",mode); + field_to_json(Obj,"ssid",ssid); + field_to_json(Obj,"associations",associations); + } + + void DeviceTimePoint::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj,"timestamp",timestamp); + field_to_json(Obj,"ap_data",ap_data); + field_to_json(Obj,"ssid_data",ssid_data); + field_to_json(Obj,"radio_data",radio_data); + field_to_json(Obj,"device_info",device_info); + } } \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_AnalyticsObjects.h b/src/RESTObjects/RESTAPI_AnalyticsObjects.h index 8ac6c70..a066dbe 100644 --- a/src/RESTObjects/RESTAPI_AnalyticsObjects.h +++ b/src/RESTObjects/RESTAPI_AnalyticsObjects.h @@ -12,29 +12,32 @@ namespace OpenWifi { namespace AnalyticsObjects { struct Report { - uint64_t snapShot=0; + uint64_t snapShot = 0; void reset(); + void to_json(Poco::JSON::Object &Obj) const; }; struct VenueInfo { - OpenWifi::Types::UUID_t id; - std::string name; - std::string description; - uint64_t retention=0; - uint64_t interval=0; - bool monitorSubVenues=false; + OpenWifi::Types::UUID_t id; + std::string name; + std::string description; + uint64_t retention = 0; + uint64_t interval = 0; + bool monitorSubVenues = false; void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); }; struct BoardInfo { - ProvObjects::ObjectInfo info; - std::vector venueList; + ProvObjects::ObjectInfo info; + std::vector venueList; void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); inline bool operator<(const BoardInfo &bb) const { @@ -47,40 +50,149 @@ namespace OpenWifi { }; struct DeviceInfo { - std::string boardId; - std::string type; - std::string serialNumber; - std::string deviceType; - uint64_t lastContact; - uint64_t lastPing; - uint64_t lastState; - std::string lastFirmware; - uint64_t lastFirmwareUpdate; - uint64_t lastConnection; - uint64_t lastDisconnection; - uint64_t pings; - uint64_t states; - bool connected; - std::string connectionIp; - uint64_t associations_2g; - uint64_t associations_5g; - uint64_t associations_6g; - uint64_t health; - uint64_t lastHealth; - std::string locale; - uint64_t uptime; - double memory; + std::string boardId; + std::string type; + std::string serialNumber; + std::string deviceType; + uint64_t lastContact; + uint64_t lastPing; + uint64_t lastState; + std::string lastFirmware; + uint64_t lastFirmwareUpdate; + uint64_t lastConnection; + uint64_t lastDisconnection; + uint64_t pings; + uint64_t states; + bool connected; + std::string connectionIp; + uint64_t associations_2g; + uint64_t associations_5g; + uint64_t associations_6g; + uint64_t health; + uint64_t lastHealth; + std::string locale; + uint64_t uptime; + double memory; void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); }; struct DeviceInfoList { - std::vector devices; + std::vector devices; void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); }; - } + enum wifi_band { + band_2g = 0, band_5g = 1, band_6g = 2 + }; + + struct msdu_entry { + uint64_t rx_msdu = 0, + tx_msdu = 0, + tx_msdu_failed = 0, + tx_msdu_retries = 0; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct UETimePoint { + uint64_t association_bssid = 0, + station = 0; + int64_t rssi = 0; + uint64_t tx_bytes = 0, + rx_bytes = 0, + tx_duration = 0, + rx_packets = 0, + tx_packets = 0, + tx_retries = 0, + tx_failed = 0, + connected = 0, + inactive = 0; + std::vector msdus; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + enum SSID_MODES { + unknown = 0, + ap, + mesh, + sta, + wds_ap, + wds_sta, + wds_repeater + }; + + inline SSID_MODES SSID_Mode(const std::string &m) { + if (m == "ap") + return ap; + if (m == "sta") + return sta; + if (m == "mesh") + return mesh; + if (m == "wds-ap") + return wds_ap; + if (m == "wds-sta") + return wds_sta; + if (m == "wds-repeater") + return wds_repeater; + return unknown; + } + + struct SSIDTimePoint { + uint64_t bssid = 0, + mode = 0, + ssid = 0; + std::vector associations; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + + struct APTimePoint { + uint64_t collisions = 0, + multicast = 0, + rx_bytes = 0, + rx_dropped = 0, + rx_errors = 0, + rx_packets = 0, + tx_bytes = 0, + tx_dropped = 0, + tx_errors = 0, + tx_packets = 0; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + struct RadioTimePoint { + uint band = 0, + radio_channel = 0; + uint64_t active_ms = 0, + busy_ms = 0, + receive_ms = 0, + transmit_ms = 0, + tx_power = 0, + channel = 0; + int64_t temperature = 0, + noise = 0; + + void to_json(Poco::JSON::Object &Obj) const; + }; + + + struct DeviceTimePoint { + uint64_t timestamp = 0; + APTimePoint ap_data; + std::vector ssid_data; + std::vector radio_data; + AnalyticsObjects::DeviceInfo device_info; + + void to_json(Poco::JSON::Object &Obj) const; + }; + } } \ No newline at end of file diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index b329070..969382f 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -346,6 +346,15 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field, Value); } + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int64_t Value) { + Obj.set(Field, Value); + } + + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint Value) { + Obj.set(Field, Value); + } + + template void field_to_json(Poco::JSON::Object &Obj, const char *Field, const T &Value) { Poco::JSON::Object Answer; Value.to_json(Answer);