add fne-stats; add reload peers and crypto;

r05a04_dev
Bryan Biedenkapp 2 months ago
parent 7d15834462
commit 230f6c5358

@ -226,6 +226,12 @@ namespace lookups
*/
void setReloadTime(uint32_t reloadTime) { m_reloadTime = reloadTime; }
/**
* @brief Returns the last load time of this lookup table.
* @return const uint64_t Last load time in milliseconds since epoch.
*/
const uint64_t lastLoadTime() const { return m_lastLoadTime; }
private:
std::string m_rulesFile;
uint32_t m_reloadTime;

@ -186,6 +186,12 @@ namespace lookups
*/
void setReloadTime(uint32_t reloadTime) { m_reloadTime = reloadTime; }
/**
* @brief Returns the last load time of this lookup table.
* @return const uint64_t Last load time in milliseconds since epoch.
*/
const uint64_t lastLoadTime() const { return m_lastLoadTime; }
protected:
std::string m_filename;
uint32_t m_reloadTime;

@ -636,6 +636,12 @@ namespace lookups
*/
void setReloadTime(uint32_t reloadTime) { m_reloadTime = reloadTime; }
/**
* @brief Returns the last load time of this lookup table.
* @return const uint64_t Last load time in milliseconds since epoch.
*/
const uint64_t lastLoadTime() const { return m_lastLoadTime; }
private:
std::string m_rulesFile;
uint32_t m_reloadTime;

@ -245,6 +245,12 @@ public:
*/
void setReloadTime(uint32_t reloadTime) { m_reloadTime = reloadTime; }
/**
* @brief Returns the last load time of this lookup table.
* @return const uint64_t Last load time in milliseconds since epoch.
*/
const uint64_t lastLoadTime() const { return m_lastLoadTime; }
private:
std::string m_file;
std::string m_password;

@ -521,7 +521,7 @@ bool HostFNE::initializeRESTAPI()
// initialize network remote command
if (restApiEnable) {
m_RESTAPI = new RESTAPI(restApiAddress, restApiPort, restApiPassword, restApiSSLKey, restApiSSLCert, restApiEnableSSL, this, restApiDebug);
m_RESTAPI->setLookups(m_ridLookup, m_tidLookup, m_peerListLookup, m_adjSiteMapLookup);
m_RESTAPI->setLookups(m_ridLookup, m_tidLookup, m_peerListLookup, m_adjSiteMapLookup, m_cryptoLookup);
bool ret = m_RESTAPI->open();
if (!ret) {
delete m_RESTAPI;

@ -143,6 +143,7 @@ FNENetwork::FNENetwork(HostFNE* host, const std::string& address, uint16_t port,
m_verbosePacketData(false),
m_sndcpStartAddr(__IP_FROM_STR("10.10.1.10")),
m_sndcpEndAddr(__IP_FROM_STR("10.10.1.254")),
m_totalCallsProcessed(0U),
m_logDenials(false),
m_logUpstreamCallStartEnd(true),
m_reportPeerPing(reportPeerPing),

@ -406,6 +406,8 @@ namespace network
uint32_t m_sndcpStartAddr;
uint32_t m_sndcpEndAddr;
uint64_t m_totalCallsProcessed;
bool m_logDenials;
bool m_logUpstreamCallStartEnd;
bool m_reportPeerPing;

@ -265,6 +265,8 @@ bool TagAnalogData::processFrame(const uint8_t* data, uint32_t len, uint32_t pee
m_status[dstId].activeCall = true;
m_status.unlock();
m_network->m_totalCallsProcessed++;
#define CALL_START_LOG "Analog, Call Start, peer = %u, ssrc = %u, srcId = %u, dstId = %u, streamId = %u, fromUpstream = %u", peerId, ssrc, srcId, dstId, streamId, fromUpstream
if (m_network->m_logUpstreamCallStartEnd && fromUpstream)
LogInfoEx(LOG_PEER, CALL_START_LOG);

@ -366,6 +366,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].activeCall = true;
m_status.unlock();
m_network->m_totalCallsProcessed++;
// is this a private call?
if (flco == FLCO::PRIVATE) {
m_statusPVCall.lock(false);

@ -402,6 +402,8 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
m_status[dstId].activeCall = true;
m_status.unlock();
m_network->m_totalCallsProcessed++;
// is this a private call?
if (!group) {
m_statusPVCall.lock(false);

@ -445,6 +445,8 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_status[dstId].activeCall = true;
m_status.unlock();
m_network->m_totalCallsProcessed++;
// is this a private call?
if (lco == LCO::PRIVATE) {
m_statusPVCall.lock(false);

@ -506,6 +506,7 @@ RESTAPI::RESTAPI(const std::string& address, uint16_t port, const std::string& p
m_tidLookup(nullptr),
m_peerListLookup(nullptr),
m_adjSiteMapLookup(nullptr),
m_cryptoLookup(nullptr),
m_authTokens()
{
assert(!address.empty());
@ -556,12 +557,14 @@ RESTAPI::~RESTAPI()
/* Sets the instances of the Radio ID and Talkgroup ID lookup tables. */
void RESTAPI::setLookups(lookups::RadioIdLookup* ridLookup, lookups::TalkgroupRulesLookup* tidLookup,
::lookups::PeerListLookup* peerListLookup, ::lookups::AdjSiteMapLookup* adjMapLookup)
::lookups::PeerListLookup* peerListLookup, ::lookups::AdjSiteMapLookup* adjMapLookup,
CryptoContainer* cryptoLookup)
{
m_ridLookup = ridLookup;
m_tidLookup = tidLookup;
m_peerListLookup = peerListLookup;
m_adjSiteMapLookup = adjMapLookup;
m_cryptoLookup = cryptoLookup;
}
/* Sets the instance of the FNE network. */
@ -664,7 +667,10 @@ void RESTAPI::initializeEndpoints()
m_dispatcher.match(FNE_GET_RELOAD_TGS).get(REST_API_BIND(RESTAPI::restAPI_GetReloadTGs, this));
m_dispatcher.match(FNE_GET_RELOAD_RIDS).get(REST_API_BIND(RESTAPI::restAPI_GetReloadRIDs, this));
m_dispatcher.match(FNE_GET_RELOAD_PEERLIST).get(REST_API_BIND(RESTAPI::restAPI_GetReloadPeerList, this));
m_dispatcher.match(FNE_GET_RELOAD_CRYPTO).get(REST_API_BIND(RESTAPI::restAPI_GetReloadCrypto, this));
m_dispatcher.match(FNE_GET_STATS).get(REST_API_BIND(RESTAPI::restAPI_GetStats, this));
m_dispatcher.match(FNE_GET_AFF_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetAffList, this));
m_dispatcher.match(FNE_GET_SPANNING_TREE).get(REST_API_BIND(RESTAPI::restAPI_GetSpanningTree, this));
@ -1615,6 +1621,211 @@ void RESTAPI::restAPI_GetReloadRIDs(const HTTPPayload& request, HTTPPayload& rep
reply.payload(response);
}
/* REST API endpoint; implements get reload peer list request. */
void RESTAPI::restAPI_GetReloadPeerList(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)
{
if (!validateAuth(request, reply)) {
return;
}
json::object response = json::object();
setResponseDefaultStatus(response);
if (m_network != nullptr) {
m_network->m_peerListLookup->reload();
}
reply.payload(response);
}
/* REST API endpoint; implements get reload crypto container request. */
void RESTAPI::restAPI_GetReloadCrypto(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)
{
if (!validateAuth(request, reply)) {
return;
}
json::object response = json::object();
setResponseDefaultStatus(response);
if (m_network != nullptr) {
m_network->m_cryptoLookup->reload();
}
reply.payload(response);
}
/* REST API endpoint; implements get statistics request. */
void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)
{
if (!validateAuth(request, reply)) {
return;
}
json::object response = json::object();
setResponseDefaultStatus(response);
if (m_network != nullptr) {
// peer statistics (right now this is just a list of connected peers)
json::array peerStats = json::array();
if (m_network->m_peers.size() > 0) {
for (auto entry : m_network->m_peers) {
uint32_t peerId = entry.first;
network::FNEPeerConnection* peer = entry.second;
if (peer != nullptr) {
json::object peerObj = json::object();
peerObj["peerId"].set<uint32_t>(peerId);
uint32_t masterId = peer->masterId();
peerObj["masterId"].set<uint32_t>(masterId);
peerObj["address"].set<std::string>(peer->address());
uint16_t port = peer->port();
peerObj["port"].set<uint16_t>(port);
// format last ping into human readable form
{
std::chrono::milliseconds lastPing(peer->lastPing());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastPing;
std::time_t lastPingTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastPingTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
peerObj["lastPing"].set<std::string>(timeStr);
}
uint32_t pingsReceived = peer->pingsReceived();
peerObj["pingsReceived"].set<uint32_t>(pingsReceived);
uint32_t missedMetadataUpdates = peer->missedMetadataUpdates();
peerObj["missedMetadataUpdates"].set<uint32_t>(missedMetadataUpdates);
bool isNeighbor = peer->isNeighborFNEPeer();
bool isReplica = peer->isReplica();
peerObj["isNeighbor"].set<bool>(isNeighbor);
peerObj["isReplica"].set<bool>(isReplica);
peerStats.push_back(json::value(peerObj));
}
}
}
response["peerStats"].set<json::array>(peerStats);
// table load statistics
json::object tableLastLoad = json::object();
// RID table load time
{
// format last load time into human readable form
std::chrono::milliseconds lastLoad(m_network->m_ridLookup->lastLoadTime());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastLoad;
std::time_t lastLoadTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastLoadTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
tableLastLoad["ridLastLoadTime"].set<std::string>(timeStr);
}
// talkgroup table load time
{
// format last load time into human readable form
std::chrono::milliseconds lastLoad(m_network->m_tidLookup->lastLoadTime());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastLoad;
std::time_t lastLoadTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastLoadTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
tableLastLoad["tgLastLoadTime"].set<std::string>(timeStr);
}
// peer list table load time
{
// format last load time into human readable form
std::chrono::milliseconds lastLoad(m_peerListLookup->lastLoadTime());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastLoad;
std::time_t lastLoadTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastLoadTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
tableLastLoad["peerListLastLoadTime"].set<std::string>(timeStr);
}
// adjacent site map table load time
{
// format last load time into human readable form
std::chrono::milliseconds lastLoad(m_adjSiteMapLookup->lastLoadTime());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastLoad;
std::time_t lastLoadTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastLoadTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
tableLastLoad["adjSiteMapLastLoadTime"].set<std::string>(timeStr);
}
// crypto key table load time
{
// format last load time into human readable form
std::chrono::milliseconds lastLoad(m_cryptoLookup->lastLoadTime());
std::chrono::system_clock::time_point tp = std::chrono::system_clock::time_point() + lastLoad;
std::time_t lastLoadTime = std::chrono::system_clock::to_time_t(tp);
char timeBuf[26];
::memset(timeBuf, 0x00U, 26);
::ctime_r(&lastLoadTime, timeBuf);
// remove newline character from ctime_r output
std::string timeStr = std::string(timeBuf);
timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end());
tableLastLoad["cryptoKeyLastLoadTime"].set<std::string>(timeStr);
}
response["tableLastLoad"].set<json::object>(tableLastLoad);
// total calls processed
uint32_t totalCallsProcessed = m_network->m_totalCallsProcessed;
response["totalCallsProcessed"].set<uint32_t>(totalCallsProcessed);
// table totals
uint32_t ridTotalEntries = m_network->m_ridLookup->table().size();
response["ridTotalEntries"].set<uint32_t>(ridTotalEntries);
uint32_t tgTotalEntries = m_network->m_tidLookup->groupVoice().size();
response["tgTotalEntries"].set<uint32_t>(tgTotalEntries);
uint32_t peerListTotalEntries = m_peerListLookup->table().size();
response["peerListTotalEntries"].set<uint32_t>(peerListTotalEntries);
uint32_t adjSiteMapTotalEntries = m_adjSiteMapLookup->adjPeerMap().size();
response["adjSiteMapTotalEntries"].set<uint32_t>(adjSiteMapTotalEntries);
uint32_t cryptoKeyTotalEntries = m_cryptoLookup->keys().size();
response["cryptoKeyTotalEntries"].set<uint32_t>(cryptoKeyTotalEntries);
}
reply.payload(response);
}
/* REST API endpoint; implements get affiliation list request. */
void RESTAPI::restAPI_GetAffList(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match)

@ -23,7 +23,9 @@
#include "common/lookups/AdjSiteMapLookup.h"
#include "common/lookups/RadioIdLookup.h"
#include "common/lookups/TalkgroupRulesLookup.h"
#include "common/lookups/PeerListLookup.h"
#include "common/Thread.h"
#include "fne/CryptoContainer.h"
#include "fne/restapi/RESTDefines.h"
#include <vector>
@ -71,9 +73,11 @@ public:
* @param tidLookup Talkgroup Rules Lookup Table Instance
* @param peerListLookup Peer List Lookup Table Instance
* @param adjPeerMapLookup Adjacent Site Map Lookup Table Instance
* @param cryptoLookup Crypto Container Instance
*/
void setLookups(::lookups::RadioIdLookup* ridLookup, ::lookups::TalkgroupRulesLookup* tidLookup,
::lookups::PeerListLookup* peerListLookup, ::lookups::AdjSiteMapLookup* adjPeerMapLookup);
::lookups::PeerListLookup* peerListLookup, ::lookups::AdjSiteMapLookup* adjPeerMapLookup,
CryptoContainer* cryptoLookup);
/**
* @brief Sets the instance of the FNE network.
* @param network Instance oft he FNENetwork class.
@ -114,6 +118,7 @@ private:
::lookups::TalkgroupRulesLookup* m_tidLookup;
::lookups::PeerListLookup* m_peerListLookup;
::lookups::AdjSiteMapLookup* m_adjSiteMapLookup;
CryptoContainer* m_cryptoLookup;
typedef std::unordered_map<std::string, uint64_t>::value_type AuthTokenValueType;
std::unordered_map<std::string, uint64_t> m_authTokens;
@ -333,6 +338,30 @@ private:
*/
void restAPI_GetReloadRIDs(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements get reload peer list request.
* @param request HTTP request.
* @param reply HTTP reply.
* @param match HTTP request matcher.
*/
void restAPI_GetReloadPeerList(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements get reload crypto container request.
* @param request HTTP request.
* @param reply HTTP reply.
* @param match HTTP request matcher.
*/
void restAPI_GetReloadCrypto(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements get statistics request.
* @param request HTTP request.
* @param reply HTTP reply.
* @param match HTTP request matcher.
*/
void restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, const restapi::RequestMatch& match);
/**
* @brief REST API endpoint; implements get affiliation list request.
* @param request HTTP request.

@ -54,7 +54,10 @@
#define FNE_GET_RELOAD_TGS "/reload-tgs"
#define FNE_GET_RELOAD_RIDS "/reload-rids"
#define FNE_GET_RELOAD_PEERLIST "/reload-peers"
#define FNE_GET_RELOAD_CRYPTO "/reload-crypto"
#define FNE_GET_STATS "/stats"
#define FNE_GET_AFF_LIST "/report-affiliations"
#define FNE_GET_SPANNING_TREE "/spanning-tree"

@ -44,6 +44,8 @@
#define RCD_FNE_GET_AFFLIST "fne-affs"
#define RCD_FNE_GET_RELOADTGS "fne-reload-tgs"
#define RCD_FNE_GET_RELOADRIDS "fne-reload-rids"
#define RCD_FNE_GET_RELOADPEERLIST "fne-reload-peerlist"
#define RCD_FNE_GET_RELOADCRYPTO "fne-reload-crypto"
#define RCD_FNE_PUT_RESETPEER "fne-reset-peer"
#define RCD_FNE_PUT_PEER_ACL_ADD "fne-peer-acl-add"
@ -54,6 +56,8 @@
#define RCD_FNE_SAVE_TGID_ACL "fne-tgid-commit"
#define RCD_FNE_SAVE_PEER_ACL "fne-peer-commit"
#define RCD_FNE_GET_STATS "fne-stats"
#define RCD_FNE_GET_SPANNINGTREE "fne-spanning-tree"
#define RCD_MODE "mdm-mode"
@ -214,6 +218,8 @@ void usage(const char* message, const char* arg)
reply += " fne-affs Retrieves the list of currently affiliated SUs (Converged FNE only)\r\n";
reply += " fne-reload-tgs Forces the FNE to reload its TGID list from disk (Converged FNE only)\r\n";
reply += " fne-reload-rids Forces the FNE to reload its RID list from disk (Converged FNE only)\r\n";
reply += " fne-reload-peerlist Forces the FNE to reload its peer list from disk (Converged FNE only)\r\n";
reply += " fne-reload-crypto Forces the FNE to reload its crypto containers from disk (Converged FNE only)\r\n";
reply += "\r\n";
reply += " fne-reset-peer <pid> Forces the FNE to reset the connection of the given peer ID (Converged FNE only)\r\n";
reply += " fne-peer-acl-add <pid> Adds the specified peer ID to the FNE ACL tables (Converged FNE only)\r\n";
@ -224,6 +230,8 @@ void usage(const char* message, const char* arg)
reply += " fne-tgid-commit Saves the current TGID ACL to permenant storage (Converged FNE only)\r\n";
reply += " fne-peer-commit Saves the current peer ACL to permenant storage (Converged FNE only)\r\n";
reply += "\r\n";
reply += " fne-stats Retrieves current FNE statistics (Converged FNE only)\r\n";
reply += "\r\n";
reply += " fne-spanning-tree Retrieves the current FNE spanning tree (Converged FNE only)\r\n";
reply += "\r\n";
reply += " mdm-mode <mode> Set current mode of host (idle, lockout, dmr, p25, nxdn)\r\n";
@ -892,6 +900,12 @@ int main(int argc, char** argv)
else if (rcom == RCD_FNE_GET_RELOADRIDS) {
retCode = client->send(HTTP_GET, FNE_GET_RELOAD_RIDS, json::object(), response);
}
else if (rcom == RCD_FNE_GET_RELOADPEERLIST) {
retCode = client->send(HTTP_GET, FNE_GET_RELOAD_PEERLIST, json::object(), response);
}
else if (rcom == RCD_FNE_GET_RELOADCRYPTO) {
retCode = client->send(HTTP_GET, FNE_GET_RELOAD_CRYPTO, json::object(), response);
}
else if (rcom == RCD_FNE_PUT_RESETPEER && argCnt >= 1U) {
uint32_t peerId = getArgUInt32(args, 0U);
json::object req = json::object();
@ -929,6 +943,9 @@ int main(int argc, char** argv)
else if (rcom == RCD_FNE_SAVE_PEER_ACL) {
retCode = client->send(HTTP_GET, FNE_GET_PEER_COMMIT, json::object(), response);
}
else if (rcom == RCD_FNE_GET_STATS) {
retCode = client->send(HTTP_GET, FNE_GET_STATS, json::object(), response);
}
else if (rcom == RCD_FNE_GET_SPANNINGTREE) {
retCode = client->send(HTTP_GET, FNE_GET_SPANNING_TREE, json::object(), response);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.