route subscriber operation responses through endpoint peer traffic connections, remove the invalid metadata-port dependency, and update regression coverage;

r05a06_dev
Bryan Biedenkapp 2 days ago
parent 4f476e4789
commit a87be87d5b

@ -239,37 +239,6 @@ void MetadataNetwork::erasePacketBufferEntry(PacketBufferMap& pktMap, uint32_t p
pktMap.unlock();
}
/* Helper to send a metadata message to a peer's metadata port. */
bool MetadataNetwork::writePeerMetadata(FNEPeerConnection* connection, uint32_t ssrc, FrameQueue::OpcodePair opcode, const uint8_t* data,
uint32_t length, uint16_t pktSeq, uint32_t streamId) const
{
if (connection == nullptr)
return false;
#if defined(CATCH2_TEST_COMPILATION)
if (m_testPeerMetadataWriteHandler) {
m_testPeerMetadataWriteHandler(opcode, data, length);
return true;
}
#endif
if (m_status != NET_STAT_MST_RUNNING)
return false;
if (m_frameQueue == nullptr)
return false;
sockaddr_storage addr;
uint32_t addrLen = 0U;
uint16_t port = connection->port() + 1U;
if (udp::Socket::lookup(connection->address(), port, addr, addrLen) != 0) {
LogWarning(LOG_NET, "PEER %u (%s) failed to resolve metadata endpoint %s:%u", connection->id(),
connection->identWithQualifier().c_str(), connection->address().c_str(), port);
return false;
}
return m_frameQueue->write(data, length, streamId, connection->id(), ssrc, opcode, pktSeq, addr, addrLen);
}
/*
** Packet Processing
*/

@ -201,20 +201,6 @@ namespace network
*/
static void erasePacketBufferEntry(PacketBufferMap& pktMap, uint32_t peerId, const PacketBufferEntryPtr& pkt);
/**
* @brief Writes metadata for a peer connection.
* @param connection Pointer to the FNEPeerConnection instance.
* @param ssrc SSRC of the packet.
* @param opcode Opcode pair of the frame.
* @param data Pointer to the data buffer.
* @param length Length of the data buffer.
* @param pktSeq Packet sequence number.
* @param streamId Stream ID of the packet.
* @returns True if the metadata was successfully written, false otherwise.
*/
bool writePeerMetadata(FNEPeerConnection* connection, uint32_t ssrc, FrameQueue::OpcodePair opcode, const uint8_t* data,
uint32_t length, uint16_t pktSeq, uint32_t streamId) const;
/*
** Packet Processing
*/

@ -153,7 +153,6 @@ namespace network
* @ingroup fne_network
*/
struct SubscriberOperationProxyPending {
MetadataNetwork* metadata; //!< Metadata network for a local console response.
uint32_t downstreamPeerId; //!< Console or downstream FNE peer ID.
uint32_t downstreamStreamId; //!< Original downstream stream ID.
uint32_t downstreamTransactionId; //!< Downstream proxy transaction ID, or zero for a console.
@ -281,7 +280,6 @@ namespace network
/**
* @brief Proxies a subscriber operation result query to the upstream replica parent.
* @param metadata Metadata network used to return a locally originated console response.
* @param downstreamPeerId Console or downstream FNE peer ID awaiting the response.
* @param downstreamStreamId Stream ID supplied by the downstream requestor.
* @param downstreamTransactionId Proxy transaction ID supplied by a downstream FNE, or zero for a console.
@ -289,7 +287,7 @@ namespace network
* @param hopLimit Number of additional upstream hops permitted.
* @returns True if the request was forwarded, otherwise false.
*/
bool proxySubscriberOperation(MetadataNetwork* metadata, uint32_t downstreamPeerId, uint32_t downstreamStreamId, uint32_t downstreamTransactionId,
bool proxySubscriberOperation(uint32_t downstreamPeerId, uint32_t downstreamStreamId, uint32_t downstreamTransactionId,
uint64_t operationId, uint8_t hopLimit);
/**
* @brief Processes a packed subscriber operation proxy response received from an upstream parent.

@ -78,8 +78,8 @@ static void encodeProxyResponse(uint8_t* buffer, uint8_t result, uint32_t transa
/* Proxies a subscriber operation result query to the upstream replica parent. */
bool TrafficNetwork::proxySubscriberOperation(MetadataNetwork* metadata, uint32_t downstreamPeerId,
uint32_t downstreamStreamId, uint32_t downstreamTransactionId, uint64_t operationId, uint8_t hopLimit)
bool TrafficNetwork::proxySubscriberOperation(uint32_t downstreamPeerId, uint32_t downstreamStreamId, uint32_t downstreamTransactionId,
uint64_t operationId, uint8_t hopLimit)
{
if (operationId == 0U || hopLimit == 0U || m_host == nullptr)
return false;
@ -117,7 +117,7 @@ bool TrafficNetwork::proxySubscriberOperation(MetadataNetwork* metadata, uint32_
} while (transactionId == 0U || m_subscriberOperationProxyPending.find(transactionId) != m_subscriberOperationProxyPending.end());
m_subscriberOperationProxyPending[transactionId] = {
metadata, downstreamPeerId, downstreamStreamId, downstreamTransactionId,
downstreamPeerId, downstreamStreamId, downstreamTransactionId,
operationId, now + SUBSCRIBER_OPERATION_PROXY_TIMEOUT_MS
};
}
@ -134,9 +134,7 @@ bool TrafficNetwork::proxySubscriberOperation(MetadataNetwork* metadata, uint32_
bool written = false;
#if defined(CATCH2_TEST_COMPILATION)
if (m_testSubscriberOperationProxyWriteHandler) {
written = m_testSubscriberOperationProxyWriteHandler(
{ NET_FUNC::SUBSCRIBER_OP, NET_SUBFUNC::SUBSCRIBER_OP_PROXY_REQUEST },
buffer, sizeof(buffer));
written = m_testSubscriberOperationProxyWriteHandler({ NET_FUNC::SUBSCRIBER_OP, NET_SUBFUNC::SUBSCRIBER_OP_PROXY_REQUEST }, buffer, sizeof(buffer));
} else
#endif
{
@ -209,8 +207,7 @@ void TrafficNetwork::processSubscriberOperationProxyResponse(PeerNetwork* peer,
// send the response to the downstream console when no downstream transaction is pending
PeerConnectionPtr connection = findPeer(pending.downstreamPeerId);
if (pending.metadata == nullptr || connection == nullptr || !connection->connected() ||
connection->peerClass() != PEER_CONN_CLASS_CONSOLE) {
if (connection == nullptr || !connection->connected() || connection->peerClass() != PEER_CONN_CLASS_CONSOLE) {
return;
}
@ -262,8 +259,9 @@ void TrafficNetwork::processSubscriberOperationProxyResponse(PeerNetwork* peer,
uint8_t buffer[DATA_PACKET_LENGTH];
::memset(buffer, 0x00U, sizeof(buffer));
::memcpy(buffer + SUBSCRIBER_OPERATION_HEADER_LENGTH, payload.data(), payload.length());
pending.metadata->writePeerMetadata(connection.get(), m_peerId, { NET_FUNC::SUBSCRIBER_OP, NET_SUBFUNC::SUBSCRIBER_OP_OPERATION }, buffer,
static_cast<uint32_t>(payload.length()) + SUBSCRIBER_OPERATION_HEADER_LENGTH, RTP_END_OF_CALL_SEQ, pending.downstreamStreamId);
writePeerCommand(connection->id(), { NET_FUNC::SUBSCRIBER_OP, NET_SUBFUNC::SUBSCRIBER_OP_OPERATION },
buffer, static_cast<uint32_t>(payload.length()) + SUBSCRIBER_OPERATION_HEADER_LENGTH, pending.downstreamStreamId, false);
}
// ---------------------------------------------------------------------------
@ -315,8 +313,8 @@ void MetadataNetwork::PacketHandler::subscriberOperation(TrafficNetwork* network
::memset(buffer, 0x00U, DATA_PACKET_LENGTH);
::memcpy(buffer + SUBSCRIBER_OPERATION_HEADER_LENGTH, responsePayload.data(), responseLength);
return mdNetwork->writePeerMetadata(connection.get(), network->m_peerId, { NET_FUNC::SUBSCRIBER_OP, subFunction }, buffer,
responseLength + SUBSCRIBER_OPERATION_HEADER_LENGTH, RTP_END_OF_CALL_SEQ, streamId);
return network->writePeerCommand(connection->id(), { NET_FUNC::SUBSCRIBER_OP, subFunction },
buffer, responseLength + SUBSCRIBER_OPERATION_HEADER_LENGTH, streamId, false);
};
// handle proxy requests by checking the local store before forwarding to another peer
@ -357,7 +355,7 @@ void MetadataNetwork::PacketHandler::subscriberOperation(TrafficNetwork* network
return;
}
if (hopLimit > 1U && network->proxySubscriberOperation(nullptr, peerId, streamId, transactionId, operationId, hopLimit - 1U)) {
if (hopLimit > 1U && network->proxySubscriberOperation(peerId, streamId, transactionId, operationId, hopLimit - 1U)) {
return;
}
@ -556,8 +554,7 @@ void MetadataNetwork::PacketHandler::subscriberOperation(TrafficNetwork* network
SubscriberOperationStore::Operation operation;
const bool found = operationId != 0U && network->subscriberOperations().get(operationId, operation);
if (!found && operationId != 0U && network->proxySubscriberOperation(mdNetwork,
peerId, streamId, 0U, operationId, SUBSCRIBER_OPERATION_PROXY_HOP_LIMIT)) {
if (!found && operationId != 0U && network->proxySubscriberOperation(peerId, streamId, 0U, operationId, SUBSCRIBER_OPERATION_PROXY_HOP_LIMIT)) {
return;
}
response["found"].set<bool>(found);

@ -34,6 +34,13 @@
#include <unordered_map>
#include <vector>
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
/** @brief Length in bytes of the command prefix added by TrafficNetwork::writePeerCommand(). */
constexpr uint32_t FNE_COMMAND_PREFIX_LENGTH = 6U;
// ---------------------------------------------------------------------------
// Class Declaration
// ---------------------------------------------------------------------------
@ -100,7 +107,7 @@ TEST_CASE("FNE metadata returns subscriber operation and P25 status results",
std::vector<uint8_t> responsePayload;
uint8_t responseFunction = network::NET_FUNC::ILLEGAL;
uint8_t responseSubFunction = network::NET_SUBFUNC::NOP;
FNETestHooks::captureMetadataWrite(harness.metadata, responsePayload,
FNETestHooks::capturePeerPayloadWrite(harness.traffic, responsePayload,
responseFunction, responseSubFunction);
json::object operationRequest = json::object();
@ -113,13 +120,13 @@ TEST_CASE("FNE metadata returns subscriber operation and P25 status results",
network::NET_FUNC::SUBSCRIBER_OP, network::NET_SUBFUNC::SUBSCRIBER_OP_OPERATION,
CONSOLE_PEER_ID, requestPayload);
REQUIRE(responsePayload.size() > 11U);
REQUIRE(responsePayload.size() > FNE_COMMAND_PREFIX_LENGTH + 11U);
CHECK(responseFunction == network::NET_FUNC::SUBSCRIBER_OP);
CHECK(responseSubFunction == network::NET_SUBFUNC::SUBSCRIBER_OP_OPERATION);
json::value operationResponseValue;
REQUIRE(json::parse(operationResponseValue,
std::string(reinterpret_cast<const char*>(responsePayload.data() + 11U),
responsePayload.size() - 11U))
std::string(reinterpret_cast<const char*>(responsePayload.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
responsePayload.size() - FNE_COMMAND_PREFIX_LENGTH - 11U))
.empty());
REQUIRE(operationResponseValue.is<json::object>());
json::object& operationResponse = operationResponseValue.get<json::object>();
@ -146,8 +153,8 @@ TEST_CASE("FNE metadata returns subscriber operation and P25 status results",
REQUIRE(responsePayload.size() > 11U);
json::value historyResponseValue;
REQUIRE(json::parse(historyResponseValue,
std::string(reinterpret_cast<const char*>(responsePayload.data() + 11U),
responsePayload.size() - 11U))
std::string(reinterpret_cast<const char*>(responsePayload.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
responsePayload.size() - FNE_COMMAND_PREFIX_LENGTH - 11U))
.empty());
REQUIRE(historyResponseValue.is<json::object>());
json::object& historyResponse = historyResponseValue.get<json::object>();
@ -170,8 +177,8 @@ TEST_CASE("FNE metadata returns subscriber operation and P25 status results",
CHECK(responseSubFunction == network::NET_SUBFUNC::SUBSCRIBER_OP_P25_STATUS);
json::value statusResponseValue;
REQUIRE(json::parse(statusResponseValue,
std::string(reinterpret_cast<const char*>(responsePayload.data() + 11U),
responsePayload.size() - 11U))
std::string(reinterpret_cast<const char*>(responsePayload.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
responsePayload.size() - FNE_COMMAND_PREFIX_LENGTH - 11U))
.empty());
REQUIRE(statusResponseValue.is<json::object>());
json::object& statusResponse = statusResponseValue.get<json::object>();
@ -199,7 +206,7 @@ TEST_CASE("FNE metadata proxies subscriber operation queries and correlates resp
uint8_t responseFunction = network::NET_FUNC::ILLEGAL;
uint8_t responseSubFunction = network::NET_SUBFUNC::NOP;
FNETestHooks::captureSubscriberOperationProxyWrite(harness.traffic, proxyRequest);
FNETestHooks::captureMetadataWrite(harness.metadata, consoleResponse,
FNETestHooks::capturePeerPayloadWrite(harness.traffic, consoleResponse,
responseFunction, responseSubFunction);
json::object request = json::object();
@ -248,13 +255,13 @@ TEST_CASE("FNE metadata proxies subscriber operation queries and correlates resp
FNETestHooks::enableReplicaPeer(upstream);
FNETestHooks::deliverSubscriberOperationProxyResponse(harness.traffic, upstream, proxyResponse);
REQUIRE(consoleResponse.size() > 11U);
REQUIRE(consoleResponse.size() > FNE_COMMAND_PREFIX_LENGTH + 11U);
CHECK(responseFunction == network::NET_FUNC::SUBSCRIBER_OP);
CHECK(responseSubFunction == network::NET_SUBFUNC::SUBSCRIBER_OP_OPERATION);
json::value responseValue;
REQUIRE(json::parse(responseValue,
std::string(reinterpret_cast<const char*>(consoleResponse.data() + 11U),
consoleResponse.size() - 11U)).empty());
std::string(reinterpret_cast<const char*>(consoleResponse.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
consoleResponse.size() - FNE_COMMAND_PREFIX_LENGTH - 11U)).empty());
REQUIRE(responseValue.is<json::object>());
json::object& response = responseValue.get<json::object>();
CHECK(response["found"].get<bool>());
@ -336,10 +343,9 @@ TEST_CASE("FNE metadata starts subscriber operations before transmission",
std::vector<uint8_t> responsePayload;
uint8_t responseFunction = network::NET_FUNC::ILLEGAL;
uint8_t responseSubFunction = network::NET_SUBFUNC::NOP;
FNETestHooks::captureMetadataWrite(harness.metadata, responsePayload,
responseFunction, responseSubFunction);
std::vector<uint32_t> peerWrites;
FNETestHooks::capturePeerWrites(harness.traffic, peerWrites);
FNETestHooks::capturePeerPayloadWrite(harness.traffic, responsePayload,
responseFunction, responseSubFunction, &peerWrites);
json::object request = json::object();
request["protocol"].set<std::string>("p25");
@ -354,16 +360,17 @@ TEST_CASE("FNE metadata starts subscriber operations before transmission",
network::NET_FUNC::SUBSCRIBER_OP, network::NET_SUBFUNC::SUBSCRIBER_OP_START,
CONSOLE_PEER_ID, requestPayload);
REQUIRE(responsePayload.size() > 11U);
REQUIRE(responsePayload.size() > FNE_COMMAND_PREFIX_LENGTH + 11U);
CHECK(responseFunction == network::NET_FUNC::SUBSCRIBER_OP);
CHECK(responseSubFunction == network::NET_SUBFUNC::SUBSCRIBER_OP_START);
REQUIRE(peerWrites.size() == 1U);
REQUIRE(peerWrites.size() == 2U);
CHECK(peerWrites.front() == RADIO_PEER_ID);
CHECK(peerWrites.back() == CONSOLE_PEER_ID);
json::value responseValue;
REQUIRE(json::parse(responseValue,
std::string(reinterpret_cast<const char*>(responsePayload.data() + 11U),
responsePayload.size() - 11U))
std::string(reinterpret_cast<const char*>(responsePayload.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
responsePayload.size() - FNE_COMMAND_PREFIX_LENGTH - 11U))
.empty());
REQUIRE(responseValue.is<json::object>());
json::object& response = responseValue.get<json::object>();
@ -390,12 +397,13 @@ TEST_CASE("FNE metadata starts subscriber operations before transmission",
network::NET_FUNC::SUBSCRIBER_OP, network::NET_SUBFUNC::SUBSCRIBER_OP_START,
CONSOLE_PEER_ID, requestPayload);
REQUIRE(responsePayload.size() > 11U);
REQUIRE(peerWrites.size() == 1U);
REQUIRE(responsePayload.size() > FNE_COMMAND_PREFIX_LENGTH + 11U);
REQUIRE(peerWrites.size() == 2U);
CHECK(peerWrites.front() == RADIO_PEER_ID);
CHECK(peerWrites.back() == CONSOLE_PEER_ID);
REQUIRE(json::parse(responseValue,
std::string(reinterpret_cast<const char*>(responsePayload.data() + 11U),
responsePayload.size() - 11U))
std::string(reinterpret_cast<const char*>(responsePayload.data() + FNE_COMMAND_PREFIX_LENGTH + 11U),
responsePayload.size() - FNE_COMMAND_PREFIX_LENGTH - 11U))
.empty());
REQUIRE(responseValue.is<json::object>());
json::object& dmrResponse = responseValue.get<json::object>();

@ -110,11 +110,14 @@ void FNETestHooks::clearPeerWriteCapture(TrafficNetwork& network)
/* Captures complete payloads selected by subsequent peer writes. */
void FNETestHooks::capturePeerPayloadWrite(TrafficNetwork& network,
std::vector<uint8_t>& payload, uint8_t& function, uint8_t& subFunction)
std::vector<uint8_t>& payload, uint8_t& function, uint8_t& subFunction,
std::vector<uint32_t>* peerIds)
{
network.m_testPeerPayloadWriteHandler = [&payload, &function, &subFunction](uint32_t,
network.m_testPeerPayloadWriteHandler = [&payload, &function, &subFunction, peerIds](uint32_t peerId,
FrameQueue::OpcodePair opcode,
const uint8_t* data, uint32_t length) {
if (peerIds != nullptr)
peerIds->push_back(peerId);
function = opcode.first;
subFunction = opcode.second;
payload.assign(data, data + length);

@ -142,9 +142,11 @@ public:
* @param[out] payload Complete peer payload.
* @param[out] function Function opcode.
* @param[out] subFunction Sub-function opcode.
* @param[out] peerIds Optional destination peer IDs selected for writes.
*/
static void capturePeerPayloadWrite(network::TrafficNetwork& network,
std::vector<uint8_t>& payload, uint8_t& function, uint8_t& subFunction);
std::vector<uint8_t>& payload, uint8_t& function, uint8_t& subFunction,
std::vector<uint32_t>* peerIds = nullptr);
/**
* @brief Clears the peer payload write capture callback.
* @param network Traffic network instance.

Loading…
Cancel
Save

Powered by TurnKey Linux.