properly queue FNE peer messages (these are distinct from peers connected *to* the FNE, FNE peer messages are messages sent to FNE masters that are "ISSI"ed); better handle logging activity logging;

pull/48/head
Bryan Biedenkapp 2 years ago
parent c60b69b54e
commit abbe6cd41c

@ -252,9 +252,12 @@ uint32_t BaseNetwork::getDMRStreamId(uint32_t slotNo) const
/// <param name="length">Length of buffer to write.</param> /// <param name="length">Length of buffer to write.</param>
/// <param name="pktSeq"></param> /// <param name="pktSeq"></param>
/// <param name="streamId"></param> /// <param name="streamId"></param>
bool BaseNetwork::writeMaster(FrameQueue::OpcodePair opcode, const uint8_t* data, uint32_t length, uint16_t pktSeq, uint32_t streamId) /// <param name="queueOnly"></param>
bool BaseNetwork::writeMaster(FrameQueue::OpcodePair opcode, const uint8_t* data, uint32_t length, uint16_t pktSeq, uint32_t streamId, bool queueOnly)
{ {
m_frameQueue->enqueueMessage(data, length, streamId, m_peerId, opcode, pktSeq, m_addr, m_addrLen); m_frameQueue->enqueueMessage(data, length, streamId, m_peerId, opcode, pktSeq, m_addr, m_addrLen);
if (queueOnly)
return true;
return m_frameQueue->flushQueue(); return m_frameQueue->flushQueue();
} }

@ -192,7 +192,7 @@ namespace network
/// <summary>Helper to send a data message to the master.</summary> /// <summary>Helper to send a data message to the master.</summary>
bool writeMaster(FrameQueue::OpcodePair opcode, const uint8_t* data, uint32_t length, bool writeMaster(FrameQueue::OpcodePair opcode, const uint8_t* data, uint32_t length,
uint16_t pktSeq, uint32_t streamId); uint16_t pktSeq, uint32_t streamId, bool queueOnly = false);
/** Digital Mobile Radio */ /** Digital Mobile Radio */
/// <summary>Reads DMR raw frame data from the DMR ring buffer.</summary> /// <summary>Reads DMR raw frame data from the DMR ring buffer.</summary>

@ -0,0 +1,161 @@
/**
* Digital Voice Modem - Conference FNE Software
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Conference FNE Software
*
*/
/*
* Copyright (C) 2024 by Bryan Biedenkapp N2PLL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ActivityLog.h"
#include "common/network/BaseNetwork.h"
#include "common/Log.h" // for CurrentLogFileLevel() and LogGetNetwork()
#include <sys/time.h>
#if defined(CATCH2_TEST_COMPILATION)
#include <catch2/catch_test_macros.hpp>
#endif
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <ctime>
#include <cassert>
#include <cstring>
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#define EOL "\r\n"
const uint32_t ACT_LOG_BUFFER_LEN = 501U;
// ---------------------------------------------------------------------------
// Global Variables
// ---------------------------------------------------------------------------
static std::string m_actFilePath;
static std::string m_actFileRoot;
static FILE* m_actFpLog = nullptr;
static struct tm m_actTm;
// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
/// <summary>
/// Helper to open the activity log file, file handle.
/// </summary>
/// <returns>True, if log file is opened, otherwise false.
static bool ActivityLogOpen()
{
if (CurrentLogFileLevel() == 0U)
return true;
time_t now;
::time(&now);
struct tm* tm = ::gmtime(&now);
if (tm->tm_mday == m_actTm.tm_mday && tm->tm_mon == m_actTm.tm_mon && tm->tm_year == m_actTm.tm_year) {
if (m_actFpLog != nullptr)
return true;
}
else {
if (m_actFpLog != nullptr)
::fclose(m_actFpLog);
}
char filename[200U];
::sprintf(filename, "%s/%s-%04d-%02d-%02d.activity.log", LogGetFilePath().c_str(), LogGetFileRoot().c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
m_actFpLog = ::fopen(filename, "a+t");
m_actTm = *tm;
return m_actFpLog != nullptr;
}
/// <summary>
/// Initializes the activity log.
/// </summary>
/// <param name="filePath">Full-path to the activity log file.</param>
/// <param name="fileRoot">Prefix of the activity log file name.</param>
bool ActivityLogInitialise(const std::string& filePath, const std::string& fileRoot)
{
#if defined(CATCH2_TEST_COMPILATION)
return true;
#endif
m_actFilePath = filePath;
m_actFileRoot = fileRoot;
return ::ActivityLogOpen();
}
/// <summary>
/// Finalizes the activity log.
/// </summary>
void ActivityLogFinalise()
{
#if defined(CATCH2_TEST_COMPILATION)
return;
#endif
if (m_actFpLog != nullptr)
::fclose(m_actFpLog);
}
/// <summary>
/// Writes a new entry to the activity log.
/// </summary>
/// <remarks>This is a variable argument function.</remarks>
/// <param name="msg">Formatted string to write to activity log.</param>
void ActivityLog(const char* msg, ...)
{
#if defined(CATCH2_TEST_COMPILATION)
return;
#endif
assert(msg != nullptr);
char buffer[ACT_LOG_BUFFER_LEN];
va_list vl;
va_start(vl, msg);
::vsnprintf(buffer, ACT_LOG_BUFFER_LEN - 1U, msg, vl);
va_end(vl);
bool ret = ::ActivityLogOpen();
if (!ret)
return;
if (CurrentLogFileLevel() == 0U)
return;
::fprintf(m_actFpLog, "%s\n", buffer);
::fflush(m_actFpLog);
if (2U >= g_logDisplayLevel && g_logDisplayLevel != 0U) {
::fprintf(stdout, "%s" EOL, buffer);
::fflush(stdout);
}
}

@ -0,0 +1,44 @@
/**
* Digital Voice Modem - Conference FNE Software
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Conference FNE Software
*
*/
/*
* Copyright (C) 2024 by Bryan Biedenkapp N2PLL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(__ACTIVITY_LOG_H__)
#define __ACTIVITY_LOG_H__
#include "Defines.h"
#include <string>
// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
/// <summary>Initializes the activity log.</summary>
extern HOST_SW_API bool ActivityLogInitialise(const std::string& filePath, const std::string& fileRoot);
/// <summary>Finalizes the activity log.</summary>
extern HOST_SW_API void ActivityLogFinalise();
/// <summary>Writes a new entry to the activity log.</summary>
extern HOST_SW_API void ActivityLog(const char* msg, ...);
#endif // __ACTIVITY_LOG_H__

@ -30,6 +30,7 @@
*/ */
#include "Defines.h" #include "Defines.h"
#include "common/Log.h" #include "common/Log.h"
#include "ActivityLog.h"
#include "FNEMain.h" #include "FNEMain.h"
#include "HostFNE.h" #include "HostFNE.h"
@ -248,6 +249,7 @@ int main(int argc, char** argv)
} while (g_signal == 1); } while (g_signal == 1);
::LogFinalise(); ::LogFinalise();
::ActivityLogFinalise();
return ret; return ret;
} }

@ -32,6 +32,7 @@
#include "network/fne/TagDMRData.h" #include "network/fne/TagDMRData.h"
#include "network/fne/TagP25Data.h" #include "network/fne/TagP25Data.h"
#include "network/fne/TagNXDNData.h" #include "network/fne/TagNXDNData.h"
#include "ActivityLog.h"
#include "HostFNE.h" #include "HostFNE.h"
#include "FNEMain.h" #include "FNEMain.h"
@ -121,6 +122,11 @@ int HostFNE::run()
::fatal("unable to open the log file\n"); ::fatal("unable to open the log file\n");
} }
ret = ::ActivityLogInitialise(logConf["activityFilePath"].as<std::string>(), logConf["fileRoot"].as<std::string>());
if (!ret) {
::fatal("unable to open the activity log file\n");
}
// handle POSIX process forking // handle POSIX process forking
if (m_daemon) { if (m_daemon) {
// create new process // create new process

@ -7,7 +7,7 @@
* *
*/ */
/* /*
* Copyright (C) 2023 by Bryan Biedenkapp N2PLL * Copyright (C) 2023-2024 by Bryan Biedenkapp N2PLL
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -33,6 +33,7 @@
#include "network/fne/TagDMRData.h" #include "network/fne/TagDMRData.h"
#include "network/fne/TagP25Data.h" #include "network/fne/TagP25Data.h"
#include "network/fne/TagNXDNData.h" #include "network/fne/TagNXDNData.h"
#include "fne/ActivityLog.h"
#include "HostFNE.h" #include "HostFNE.h"
using namespace network; using namespace network;
@ -539,10 +540,7 @@ void FNENetwork::clock(uint32_t ms)
::memcpy(rawPayload, buffer.get() + 11U, length - 11U); ::memcpy(rawPayload, buffer.get() + 11U, length - 11U);
std::string payload(rawPayload, rawPayload + (length - 11U)); std::string payload(rawPayload, rawPayload + (length - 11U));
std::stringstream ss; ::ActivityLog("%u %s", peerId, payload.c_str());
ss << peerId << " " << payload;
::Log(9999U, nullptr, "%s", ss.str().c_str());
} }
else { else {
writePeerNAK(peerId, TAG_TRANSFER_ACT_LOG); writePeerNAK(peerId, TAG_TRANSFER_ACT_LOG);

@ -239,6 +239,7 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_network->m_callInProgress = true; m_network->m_callInProgress = true;
} }
} }
m_network->m_frameQueue->flushQueue();
// repeat traffic to upstream peers // repeat traffic to upstream peers
if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) { if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) {
@ -257,11 +258,11 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
// perform TGID route rewrites if configured // perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peerId, dmrData, dataType, dstId, slotNo); routeRewrite(outboundPeerBuffer, peerId, dmrData, dataType, dstId, slotNo);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, outboundPeerBuffer, len, pktSeq, streamId, true);
} }
} }
m_network->m_frameQueue->flushQueue(); m_network->m_frameQueue->flushQueue();
return true; return true;
} }

@ -209,6 +209,7 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
m_network->m_callInProgress = true; m_network->m_callInProgress = true;
} }
} }
m_network->m_frameQueue->flushQueue();
// repeat traffic to upstream peers // repeat traffic to upstream peers
if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) { if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) {
@ -227,11 +228,11 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
// perform TGID route rewrites if configured // perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peerId, messageType, dstId); routeRewrite(outboundPeerBuffer, peerId, messageType, dstId);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, outboundPeerBuffer, len, pktSeq, streamId, true);
} }
} }
m_network->m_frameQueue->flushQueue(); m_network->m_frameQueue->flushQueue();
return true; return true;
} }

@ -252,6 +252,7 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
m_network->m_callInProgress = true; m_network->m_callInProgress = true;
} }
} }
m_network->m_frameQueue->flushQueue();
// repeat traffic to upstream peers // repeat traffic to upstream peers
if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) { if (m_network->m_host->m_peerNetworks.size() > 0 && !tg.config().parrot()) {
@ -270,11 +271,11 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
// perform TGID route rewrites if configured // perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peerId, duid, dstId); routeRewrite(outboundPeerBuffer, peerId, duid, dstId);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, outboundPeerBuffer, len, pktSeq, streamId, true);
} }
} }
m_network->m_frameQueue->flushQueue(); m_network->m_frameQueue->flushQueue();
return true; return true;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.