Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openlightingproject/ola i…
Browse files Browse the repository at this point in the history
…nto e1.33-controller
  • Loading branch information
peternewman committed Mar 27, 2024
2 parents 998475d + a05acc2 commit 1054c29
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 94 deletions.
6 changes: 4 additions & 2 deletions common/network/HealthCheckedConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ void HealthCheckedConnectionTest::testChannelWithHeavyPacketLoss() {
* Check the channel works when 2 of every 3 heartbeats are lost but the
* timeout interval is 3 * heartbeat_interval rather than the default
*/
void HealthCheckedConnectionTest::testChannelWithHeavyPacketLossLongerTimeout() {
void HealthCheckedConnectionTest::
testChannelWithHeavyPacketLossLongerTimeout() {
options.send_every = 3;
MockHealthCheckedConnection connection(&socket,
&m_ss,
Expand All @@ -284,7 +285,8 @@ void HealthCheckedConnectionTest::testChannelWithHeavyPacketLossLongerTimeout()
* Check the channel fails when 3 of every 4 heartbeats are lost even though
* the timeout interval is 3 * heartbeat_interval
*/
void HealthCheckedConnectionTest::testChannelWithVeryHeavyPacketLossLongerTimeout() {
void HealthCheckedConnectionTest::
testChannelWithVeryHeavyPacketLossLongerTimeout() {
options.send_every = 4;
options.abort_on_failure = false;
MockHealthCheckedConnection connection(&socket,
Expand Down
2 changes: 1 addition & 1 deletion include/ola/e133/E133Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ enum {
MAX_E133_STATUS_STRING_SIZE = 64
};

// The E1.33 version..
// The E1.33 version.
enum {
E133_VERSION = 1
};
Expand Down
31 changes: 16 additions & 15 deletions libs/acn/BrokerClientEntryHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,28 @@ namespace acn {
*/
class BrokerClientEntryHeader {
public:
BrokerClientEntryHeader() {}
BrokerClientEntryHeader() {}

BrokerClientEntryHeader(const ola::acn::CID &client_cid)
: m_client_cid(client_cid) {
}
~BrokerClientEntryHeader() {}
explicit BrokerClientEntryHeader(const ola::acn::CID &client_cid)
: m_client_cid(client_cid) {
}
~BrokerClientEntryHeader() {}

const ola::acn::CID ClientCid() const { return m_client_cid; }
const ola::acn::CID ClientCid() const { return m_client_cid; }

bool operator==(const BrokerClientEntryHeader &other) const {
return m_client_cid == other.m_client_cid;
}
bool operator==(const BrokerClientEntryHeader &other) const {
return m_client_cid == other.m_client_cid;
}

PACK(
struct broker_client_entry_pdu_header_s {
uint8_t client_cid[CID::CID_LENGTH];
});
typedef struct broker_client_entry_pdu_header_s broker_client_entry_pdu_header;
PACK(
struct broker_client_entry_pdu_header_s {
uint8_t client_cid[CID::CID_LENGTH];
});
typedef struct broker_client_entry_pdu_header_s
broker_client_entry_pdu_header;

private:
ola::acn::CID m_client_cid;
ola::acn::CID m_client_cid;
};
} // namespace acn
} // namespace ola
Expand Down
20 changes: 12 additions & 8 deletions libs/acn/BrokerClientEntryPDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ unsigned int BrokerClientEntryPDU::DataSize() const {
/*
* Pack the header portion.
*/
bool BrokerClientEntryPDU::PackHeader(uint8_t *data, unsigned int *length) const {
bool BrokerClientEntryPDU::PackHeader(uint8_t *data,
unsigned int *length) const {
unsigned int header_size = HeaderSize();

if (*length < header_size) {
OLA_WARN << "BrokerClientEntryPDU::PackHeader: buffer too small, got " << *length
<< " required " << header_size;
OLA_WARN << "BrokerClientEntryPDU::PackHeader: buffer too small, got "
<< *length << " required " << header_size;
*length = 0;
return false;
}
Expand All @@ -70,7 +71,8 @@ bool BrokerClientEntryPDU::PackHeader(uint8_t *data, unsigned int *length) const
/*
* Pack the data portion.
*/
bool BrokerClientEntryPDU::PackData(uint8_t *data, unsigned int *length) const {
bool BrokerClientEntryPDU::PackData(uint8_t *data,
unsigned int *length) const {
if (m_pdu)
return m_pdu->Pack(data, length);
*length = 0;
Expand All @@ -84,8 +86,9 @@ bool BrokerClientEntryPDU::PackData(uint8_t *data, unsigned int *length) const {
void BrokerClientEntryPDU::PackHeader(OutputStream *stream) const {
BrokerClientEntryHeader::broker_client_entry_pdu_header header;
m_header.ClientCid().Pack(header.client_cid);
stream->Write(reinterpret_cast<uint8_t*>(&header),
sizeof(BrokerClientEntryHeader::broker_client_entry_pdu_header));
stream->Write(
reinterpret_cast<uint8_t*>(&header),
sizeof(BrokerClientEntryHeader::broker_client_entry_pdu_header));
}


Expand All @@ -103,8 +106,9 @@ void BrokerClientEntryPDU::PrependPDU(ola::io::IOStack *stack,
const ola::acn::CID &client_cid) {
BrokerClientEntryHeader::broker_client_entry_pdu_header header;
client_cid.Pack(header.client_cid);
stack->Write(reinterpret_cast<uint8_t*>(&header),
sizeof(BrokerClientEntryHeader::broker_client_entry_pdu_header));
stack->Write(
reinterpret_cast<uint8_t*>(&header),
sizeof(BrokerClientEntryHeader::broker_client_entry_pdu_header));

vector = HostToNetwork(vector);
stack->Write(reinterpret_cast<uint8_t*>(&vector), sizeof(vector));
Expand Down
3 changes: 2 additions & 1 deletion libs/acn/BrokerClientEntryPDUTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class BrokerClientEntryPDUTest: public CppUnit::TestFixture {
static const uint8_t TEST_DATA[];
};

const uint8_t BrokerClientEntryPDUTest::TEST_DATA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
const uint8_t BrokerClientEntryPDUTest::TEST_DATA[] = {0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11,
12, 13, 14, 15};

CPPUNIT_TEST_SUITE_REGISTRATION(BrokerClientEntryPDUTest);
Expand Down
40 changes: 25 additions & 15 deletions libs/acn/BrokerConnectPDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
* Copyright (C) 2023 Peter Newman
*/

#include <algorithm>

#include "libs/acn/BrokerConnectPDU.h"

#include <ola/network/NetworkUtils.h>
#include <ola/acn/ACNVectors.h>
#include <algorithm>
#include <string>

#include "ola/acn/ACNVectors.h"
#include "ola/network/NetworkUtils.h"

namespace ola {
namespace acn {
Expand All @@ -34,22 +35,24 @@ using std::min;
using std::string;

unsigned int BrokerConnectPDU::DataSize() const {
//broker_connect_pdu_data data;
return static_cast<unsigned int>(sizeof(broker_connect_pdu_data));
}

bool BrokerConnectPDU::PackData(uint8_t *data, unsigned int *length) const {
broker_connect_pdu_data pdu_data;

size_t client_scope_str_len = min(m_client_scope.size(), sizeof(pdu_data.client_scope));
size_t client_scope_str_len = min(m_client_scope.size(),
sizeof(pdu_data.client_scope));
strncpy(pdu_data.client_scope, m_client_scope.c_str(), client_scope_str_len);
memset(pdu_data.client_scope + client_scope_str_len, 0,
(sizeof(pdu_data.client_scope) - client_scope_str_len));

pdu_data.e133_version = HostToNetwork(m_e133_version);

size_t search_domain_str_len = min(m_search_domain.size(), sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, m_search_domain.c_str(), search_domain_str_len);
size_t search_domain_str_len = min(m_search_domain.size(),
sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, m_search_domain.c_str(),
search_domain_str_len);
memset(pdu_data.search_domain + search_domain_str_len, 0,
(sizeof(pdu_data.search_domain) - search_domain_str_len));

Expand All @@ -67,15 +70,18 @@ bool BrokerConnectPDU::PackData(uint8_t *data, unsigned int *length) const {
void BrokerConnectPDU::PackData(ola::io::OutputStream *stream) const {
broker_connect_pdu_data pdu_data;

size_t client_scope_str_len = min(m_client_scope.size(), sizeof(pdu_data.client_scope));
size_t client_scope_str_len = min(m_client_scope.size(),
sizeof(pdu_data.client_scope));
strncpy(pdu_data.client_scope, m_client_scope.c_str(), client_scope_str_len);
memset(pdu_data.client_scope + client_scope_str_len, 0,
(sizeof(pdu_data.client_scope) - client_scope_str_len));

pdu_data.e133_version = HostToNetwork(m_e133_version);

size_t search_domain_str_len = min(m_search_domain.size(), sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, m_search_domain.c_str(), search_domain_str_len);
size_t search_domain_str_len = min(m_search_domain.size(),
sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, m_search_domain.c_str(),
search_domain_str_len);
memset(pdu_data.search_domain + search_domain_str_len, 0,
(sizeof(pdu_data.search_domain) - search_domain_str_len));

Expand All @@ -96,15 +102,18 @@ void BrokerConnectPDU::PrependPDU(ola::io::IOStack *stack,
bool incremental_updates) {
broker_connect_pdu_data pdu_data;

size_t client_scope_str_len = min(client_scope.size(), sizeof(pdu_data.client_scope));
size_t client_scope_str_len = min(client_scope.size(),
sizeof(pdu_data.client_scope));
strncpy(pdu_data.client_scope, client_scope.c_str(), client_scope_str_len);
memset(pdu_data.client_scope + client_scope_str_len, 0,
(sizeof(pdu_data.client_scope) - client_scope_str_len));

pdu_data.e133_version = HostToNetwork(e133_version);

size_t search_domain_str_len = min(search_domain.size(), sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, search_domain.c_str(), search_domain_str_len);
size_t search_domain_str_len = min(search_domain.size(),
sizeof(pdu_data.search_domain));
strncpy(pdu_data.search_domain, search_domain.c_str(),
search_domain_str_len);
memset(pdu_data.search_domain + search_domain_str_len, 0,
(sizeof(pdu_data.search_domain) - search_domain_str_len));

Expand All @@ -115,7 +124,8 @@ void BrokerConnectPDU::PrependPDU(ola::io::IOStack *stack,
pdu_data.connection = HostToNetwork(connection);
stack->Write(reinterpret_cast<uint8_t*>(&pdu_data),
static_cast<unsigned int>(sizeof(broker_connect_pdu_data)));
uint16_t vector = HostToNetwork(static_cast<uint16_t>(VECTOR_BROKER_CONNECT));
uint16_t vector = HostToNetwork(
static_cast<uint16_t>(VECTOR_BROKER_CONNECT));
stack->Write(reinterpret_cast<uint8_t*>(&vector), sizeof(vector));
PrependFlagsAndLength(stack, VFLAG_MASK | HFLAG_MASK | DFLAG_MASK, true);
}
Expand Down
5 changes: 3 additions & 2 deletions libs/acn/BrokerConnectPDU.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#ifndef LIBS_ACN_BROKERCONNECTPDU_H_
#define LIBS_ACN_BROKERCONNECTPDU_H_

#include <ola/io/IOStack.h>
#include <ola/rdm/RDMEnums.h>
#include <string>

#include "libs/acn/PDU.h"
#include "ola/io/IOStack.h"
#include "ola/rdm/RDMEnums.h"

namespace ola {
namespace acn {
Expand Down
2 changes: 1 addition & 1 deletion libs/acn/BrokerNullPDU.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BrokerNullPDU : public PDU {
*length = 0;
return true;
}
void PackData(OLA_UNUSED ola::io::OutputStream *stream) const {};
void PackData(OLA_UNUSED ola::io::OutputStream *stream) const {}

static void PrependPDU(ola::io::IOStack *stack);
};
Expand Down
6 changes: 4 additions & 2 deletions libs/acn/BrokerPDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ unsigned int BrokerPDU::DataSize() const {
* Pack the data portion.
*/
bool BrokerPDU::PackData(uint8_t *data, unsigned int *length) const {
if (m_pdu)
if (m_pdu) {
return m_pdu->Pack(data, length);
}
*length = 0;
return true;
}
Expand All @@ -53,8 +54,9 @@ bool BrokerPDU::PackData(uint8_t *data, unsigned int *length) const {
* Pack the data into a buffer
*/
void BrokerPDU::PackData(OutputStream *stream) const {
if (m_pdu)
if (m_pdu) {
m_pdu->Write(stream);
}
}


Expand Down
2 changes: 1 addition & 1 deletion libs/acn/LLRPProbeReplyInflator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LLRPProbeReplyInflator: public BaseInflator {

public:
struct LLRPProbeReply {
LLRPProbeReply(const ola::rdm::UID &_uid)
explicit LLRPProbeReply(const ola::rdm::UID &_uid)
: uid(_uid) {
}
ola::rdm::UID uid;
Expand Down
13 changes: 9 additions & 4 deletions libs/acn/LLRPProbeRequestInflator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,22 @@ bool LLRPProbeRequestInflator::HandlePDUData(uint32_t vector,
pdu_len - (sizeof(pdu_data) -
sizeof(pdu_data.known_uids)));
if (known_uids_size % UID::UID_SIZE != 0) {
OLA_WARN << "Got a partial known UID, received " << known_uids_size << " bytes";
OLA_WARN << "Got a partial known UID, received " << known_uids_size
<< " bytes";
return false;
}

memcpy(reinterpret_cast<uint8_t*>(&pdu_data), data, sizeof(pdu_data));

OLA_DEBUG << "Probe from " << UID(pdu_data.lower_uid) << " to " << UID(pdu_data.upper_uid);
OLA_DEBUG << "Probe from " << UID(pdu_data.lower_uid) << " to "
<< UID(pdu_data.upper_uid);

LLRPProbeRequest request(UID(pdu_data.lower_uid), UID(pdu_data.upper_uid));
request.client_tcp_connection_inactive = (pdu_data.filter & LLRPProbeRequestPDU::FILTER_CLIENT_TCP_CONNECTION_INACTIVE);
request.brokers_only = (pdu_data.filter & LLRPProbeRequestPDU::FILTER_BROKERS_ONLY);
request.client_tcp_connection_inactive =
(pdu_data.filter &
LLRPProbeRequestPDU::FILTER_CLIENT_TCP_CONNECTION_INACTIVE);
request.brokers_only = (pdu_data.filter &
LLRPProbeRequestPDU::FILTER_BROKERS_ONLY);
unsigned int known_uids_used_size = known_uids_size;
request.known_uids = UIDSet(pdu_data.known_uids, &known_uids_used_size);

Expand Down
49 changes: 49 additions & 0 deletions libs/acn/LLRPProbeRequestPDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,55 @@ void LLRPProbeRequestPDU::PackData(ola::io::OutputStream *stream) const {
(m_known_uids.Size() * UID::LENGTH)));
}

unsigned int LLRPProbeRequestPDU::DataSize() const {
llrp_probe_request_pdu_data data;
return static_cast<unsigned int>(sizeof(llrp_probe_request_pdu_data) -
sizeof(data.known_uids) +
(m_known_uids.Size() * UID::LENGTH));
}

bool LLRPProbeRequestPDU::PackData(uint8_t *data, unsigned int *length) const {
llrp_probe_request_pdu_data pdu_data;
m_lower_uid.Pack(pdu_data.lower_uid, sizeof(pdu_data.lower_uid));
m_upper_uid.Pack(pdu_data.upper_uid, sizeof(pdu_data.upper_uid));
uint16_t filter = 0;
if (m_client_tcp_connection_inactive) {
filter |= FILTER_CLIENT_TCP_CONNECTION_INACTIVE;
}
if (m_brokers_only) {
filter |= FILTER_BROKERS_ONLY;
}
pdu_data.filter = HostToNetwork(filter);
// TODO(Peter): We need to check we've got <= 200 UIDs here
m_known_uids.Pack(pdu_data.known_uids, sizeof(pdu_data.known_uids));
*length = static_cast<unsigned int>(sizeof(llrp_probe_request_pdu_data) -
sizeof(pdu_data.known_uids) +
(m_known_uids.Size() * UID::LENGTH));

memcpy(data, &pdu_data, *length);
return true;
}

void LLRPProbeRequestPDU::PackData(ola::io::OutputStream *stream) const {
llrp_probe_request_pdu_data data;
m_lower_uid.Pack(data.lower_uid, sizeof(data.lower_uid));
m_upper_uid.Pack(data.upper_uid, sizeof(data.upper_uid));
uint16_t filter = 0;
if (m_client_tcp_connection_inactive) {
filter |= FILTER_CLIENT_TCP_CONNECTION_INACTIVE;
}
if (m_brokers_only) {
filter |= FILTER_BROKERS_ONLY;
}
data.filter = HostToNetwork(filter);
// TODO(Peter): We need to check we've got <= 200 UIDs here
m_known_uids.Pack(data.known_uids, sizeof(data.known_uids));
stream->Write(reinterpret_cast<uint8_t*>(&data),
static_cast<unsigned int>(sizeof(llrp_probe_request_pdu_data) -
sizeof(data.known_uids) +
(m_known_uids.Size() * UID::LENGTH)));
}

void LLRPProbeRequestPDU::PrependPDU(ola::io::IOStack *stack,
const UID &lower_uid,
const UID &upper_uid,
Expand Down
14 changes: 14 additions & 0 deletions libs/acn/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ noinst_LTLIBRARIES += libs/acn/libolae131core.la
libs_acn_libolae131core_la_SOURCES = \
libs/acn/BaseInflator.cpp \
libs/acn/BaseInflator.h \
libs/acn/BrokerClientAddInflator.h \
libs/acn/BrokerClientEntryChangeInflator.h \
libs/acn/BrokerClientEntryHeader.h \
libs/acn/BrokerClientEntryPDU.cpp \
libs/acn/BrokerClientEntryPDU.h \
libs/acn/BrokerClientRemoveInflator.h \
libs/acn/BrokerConnectPDU.cpp \
libs/acn/BrokerConnectPDU.h \
libs/acn/BrokerInflator.h \
libs/acn/BrokerNullInflator.h \
libs/acn/BrokerNullPDU.cpp \
libs/acn/BrokerNullPDU.h \
libs/acn/BrokerPDU.cpp \
libs/acn/BrokerPDU.h \
libs/acn/DMPAddress.cpp \
libs/acn/DMPAddress.h \
libs/acn/DMPE131Inflator.cpp \
Expand Down
Loading

0 comments on commit 1054c29

Please sign in to comment.