Skip to content

Commit

Permalink
Merge 064e2f5 into 70a7f7b
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Jul 3, 2023
2 parents 70a7f7b + 064e2f5 commit e0712cd
Show file tree
Hide file tree
Showing 79 changed files with 5,580 additions and 96 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ tools/e133/e133_monitor
tools/e133/e133_monitor.exe
tools/e133/e133_receiver
tools/e133/e133_receiver.exe
tools/e133/llrp_manager
tools/e133/llrp_manager.exe
tools/e133/llrp_target
tools/e133/llrp_target.exe
tools/e133/slp_locate
tools/e133/slp_locate.exe
tools/e133/slp_register
Expand Down
17 changes: 13 additions & 4 deletions common/network/HealthCheckedConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ namespace network {

HealthCheckedConnection::HealthCheckedConnection(
ola::thread::SchedulerInterface *scheduler,
const ola::TimeInterval heartbeat_interval,
const ola::TimeInterval timeout_interval)
: m_scheduler(scheduler),
m_heartbeat_interval(timeout_interval),
m_heartbeat_interval(heartbeat_interval),
m_timeout_interval(timeout_interval),
m_send_timeout_id(ola::thread::INVALID_TIMEOUT),
m_receive_timeout_id(ola::thread::INVALID_TIMEOUT) {
}


HealthCheckedConnection::HealthCheckedConnection(
ola::thread::SchedulerInterface *scheduler,
const ola::TimeInterval heartbeat_interval)
: HealthCheckedConnection(scheduler,
heartbeat_interval,
ola::TimeInterval(static_cast<int>(
2.5 * heartbeat_interval.AsInt()))) {
}

HealthCheckedConnection::~HealthCheckedConnection() {
if (m_send_timeout_id != ola::thread::INVALID_TIMEOUT)
m_scheduler->RemoveTimeout(m_send_timeout_id);
Expand Down Expand Up @@ -101,10 +112,8 @@ bool HealthCheckedConnection::SendNextHeartbeat() {


void HealthCheckedConnection::UpdateReceiveTimer() {
TimeInterval timeout_interval(static_cast<int>(
2.5 * m_heartbeat_interval.AsInt()));
m_receive_timeout_id = m_scheduler->RegisterSingleTimeout(
timeout_interval,
m_timeout_interval,
NewSingleCallback(
this, &HealthCheckedConnection::InternalHeartbeatTimeout));
}
Expand Down
83 changes: 80 additions & 3 deletions common/network/HealthCheckedConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,28 @@ class MockHealthCheckedConnection: public HealthCheckedConnection {

MockHealthCheckedConnection(ola::io::ConnectedDescriptor *descriptor,
SelectServer *scheduler,
const ola::TimeInterval heartbeat_interval,
const ola::TimeInterval timeout_interval,
const Options &options,
MockClock *clock)
: HealthCheckedConnection(scheduler, timeout_interval),
: HealthCheckedConnection(scheduler,
heartbeat_interval,
timeout_interval),
m_descriptor(descriptor),
m_ss(scheduler),
m_options(options),
m_next_heartbeat(0),
m_expected_heartbeat(0),
m_channel_ok(true),
m_clock(clock) {
}

MockHealthCheckedConnection(ola::io::ConnectedDescriptor *descriptor,
SelectServer *scheduler,
const ola::TimeInterval heartbeat_interval,
const Options &options,
MockClock *clock)
: HealthCheckedConnection(scheduler, heartbeat_interval),
m_descriptor(descriptor),
m_ss(scheduler),
m_options(options),
Expand All @@ -70,8 +88,10 @@ class MockHealthCheckedConnection: public HealthCheckedConnection {
}

void SendHeartbeat() {
OLA_DEBUG << "Maybe send heartbeat";
if (m_options.send_every == 0 ||
m_next_heartbeat % m_options.send_every == 0) {
OLA_DEBUG << "Sending heartbeat";
m_descriptor->Send(&m_next_heartbeat, sizeof(m_next_heartbeat));
}
m_clock->AdvanceTime(0, 180000);
Expand Down Expand Up @@ -115,13 +135,18 @@ class HealthCheckedConnectionTest: public CppUnit::TestFixture {
HealthCheckedConnectionTest()
: CppUnit::TestFixture(),
m_ss(NULL, &m_clock),
heartbeat_interval(0, 200000) {
heartbeat_interval(0, 200000),
// Allow a little bit of wiggle room so we don't hit timing issues
// when running the tests
timeout_interval(0, 650000) {
}

CPPUNIT_TEST_SUITE(HealthCheckedConnectionTest);
CPPUNIT_TEST(testSimpleChannel);
CPPUNIT_TEST(testChannelWithPacketLoss);
CPPUNIT_TEST(testChannelWithHeavyPacketLoss);
CPPUNIT_TEST(testChannelWithHeavyPacketLossLongerTimeout);
CPPUNIT_TEST(testChannelWithVeryHeavyPacketLossLongerTimeout);
CPPUNIT_TEST(testPauseAndResume);
CPPUNIT_TEST_SUITE_END();

Expand All @@ -131,6 +156,8 @@ class HealthCheckedConnectionTest: public CppUnit::TestFixture {
void testSimpleChannel();
void testChannelWithPacketLoss();
void testChannelWithHeavyPacketLoss();
void testChannelWithHeavyPacketLossLongerTimeout();
void testChannelWithVeryHeavyPacketLossLongerTimeout();
void testPauseAndResume();

void PauseReading(MockHealthCheckedConnection *connection) {
Expand All @@ -148,6 +175,7 @@ class HealthCheckedConnectionTest: public CppUnit::TestFixture {
SelectServer m_ss;
LoopbackDescriptor socket;
TimeInterval heartbeat_interval;
TimeInterval timeout_interval;
MockHealthCheckedConnection::Options options;
};

Expand Down Expand Up @@ -206,7 +234,7 @@ void HealthCheckedConnectionTest::testChannelWithPacketLoss() {


/**
* Check the channel works when every 2nd heartbeat is lost
* Check the channel fails when 2 of every 3 heartbeats are lost
*/
void HealthCheckedConnectionTest::testChannelWithHeavyPacketLoss() {
options.send_every = 3;
Expand All @@ -228,6 +256,55 @@ 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() {
options.send_every = 3;
MockHealthCheckedConnection connection(&socket,
&m_ss,
heartbeat_interval,
timeout_interval,
options,
&m_clock);

socket.SetOnData(
NewCallback(&connection, &MockHealthCheckedConnection::ReadData));
connection.Setup();
m_ss.AddReadDescriptor(&socket);
connection.Setup();

m_ss.Run();
OLA_ASSERT_TRUE(connection.ChannelOk());
}


/**
* Check the channel fails when 3 of every 4 heartbeats are lost even though
* the timeout interval is 3 * heartbeat_interval
*/
void HealthCheckedConnectionTest::testChannelWithVeryHeavyPacketLossLongerTimeout() {
options.send_every = 4;
options.abort_on_failure = false;
MockHealthCheckedConnection connection(&socket,
&m_ss,
heartbeat_interval,
timeout_interval,
options,
&m_clock);

socket.SetOnData(
NewCallback(&connection, &MockHealthCheckedConnection::ReadData));
connection.Setup();
m_ss.AddReadDescriptor(&socket);
connection.Setup();

m_ss.Run();
OLA_ASSERT_FALSE(connection.ChannelOk());
}


/**
* Check pausing doesn't mark the channel as bad.
*/
Expand Down
70 changes: 70 additions & 0 deletions include/ola/acn/ACNFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ACNFlags.h
* Flags used in ACN PDUs
* Copyright (C) 2020 Peter Newman
*/

#ifndef INCLUDE_OLA_ACN_ACNFLAGS_H_
#define INCLUDE_OLA_ACN_ACNFLAGS_H_

/**
* @addtogroup acn
* @{
* @file ACNFlags.h
* @brief ACN flag values.
* @}
*/

#include <stdint.h>

namespace ola {
namespace acn {

/**
* @addtogroup acn
* @{
*/

// masks for the flag fields
/**
* @brief This indicates a 20 bit length field (default is 12 bits)
*/
static const uint8_t LFLAG_MASK = 0x80;

/**
* @brief This indicates a vector is present
*/
static const uint8_t VFLAG_MASK = 0x40;

/**
* @brief This indicates a header field is present
*/
static const uint8_t HFLAG_MASK = 0x20;

/**
* @brief This indicates a data field is present
*/
static const uint8_t DFLAG_MASK = 0x10;

/**
* @}
*/

} // namespace acn
} // namespace ola

#endif // INCLUDE_OLA_ACN_ACNFLAGS_H_
5 changes: 5 additions & 0 deletions include/ola/acn/ACNPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const uint16_t ACN_PORT = 5568;
*/
const uint16_t E133_PORT = 5569;

/**
* @brief The port used for E1.33 LLRP communication.
*/
const uint16_t LLRP_PORT = 5569;

/**
* @}
*/
Expand Down
46 changes: 45 additions & 1 deletion include/ola/acn/ACNVectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ namespace acn {
enum RootVector {
VECTOR_ROOT_E131_REV2 = 3, /**< Draft E1.31, used by some old gear. */
VECTOR_ROOT_E131 = 4, /**< E1.31 (sACN) */
VECTOR_ROOT_E133 = 5, /**< E1.33 (RDNNet) */
VECTOR_ROOT_RPT = 5, /**< E1.33 (RPT) */
VECTOR_ROOT_NULL = 6, /**< NULL (empty) root */
VECTOR_ROOT_BROKER = 9, /**< E1.33 (Broker) */
VECTOR_ROOT_LLRP = 0x0A, /**< E1.33 (LLRP) */
VECTOR_ROOT_EPT = 0x0B, /**< E1.33 (EPT) */
};

/**
Expand Down Expand Up @@ -87,6 +90,47 @@ enum E133ControllerVector {
VECTOR_CONTROLLER_EXPECT_MASTER = 5, /**< Expect master message */
};

/**
* @brief Vectors used at the E1.33 LLRP layer.
*/
enum LLRPVector {
VECTOR_LLRP_PROBE_REQUEST = 1, /**< LLRP Probe Request */
VECTOR_LLRP_PROBE_REPLY = 2, /**< LLRP Probe Reply */
VECTOR_LLRP_RDM_CMD = 3, /**< LLRP RDM Command */
};

/**
* @brief Vectors used at the E1.33 Broker layer.
*/
enum BrokerVector {
VECTOR_BROKER_CONNECT = 0x0001, /**< Broker Client Connect */
VECTOR_BROKER_CONNECT_REPLY = 0x0002, /**< Broker Connect Reply */
VECTOR_BROKER_CLIENT_ENTRY_UPDATE = 0x0003, /**< Broker Client Entry Update */
VECTOR_BROKER_REDIRECT_V4 = 0x0004, /**< Broker Client Redirect IPv4 */
VECTOR_BROKER_REDIRECT_V6 = 0x0005, /**< Broker Client Redirect IPv6 */
VECTOR_BROKER_FETCH_CLIENT_LIST = 0x0006, /**< Broker Fetch Client List */
VECTOR_BROKER_CONNECTED_CLIENT_LIST = 0x0007, /**< Broker Connected Client List */
VECTOR_BROKER_CLIENT_ADD = 0x0008, /**< Broker Client Incremental Addition */
VECTOR_BROKER_CLIENT_REMOVE = 0x0009, /**< Broker Client Incremental Deletion */
VECTOR_BROKER_CLIENT_ENTRY_CHANGE = 0x000A, /**< Broker Client Entry Change */
VECTOR_BROKER_REQUEST_DYNAMIC_UIDS = 0x000B, /**< Broker Request Dynamic UID Assignment */
VECTOR_BROKER_ASSIGNED_DYNAMIC_UIDS = 0x000C, /**< Broker Dynamic UID Assignment List */
VECTOR_BROKER_FETCH_DYNAMIC_UID_LIST = 0x000D, /**< Broker Fetch Dynamic UID Assignment List */
VECTOR_BROKER_DISCONNECT = 0x000E, /**< Broker Client Disconnect */
VECTOR_BROKER_NULL = 0x000F, /**< Broker Client Null */
};

// Table A-21, Client Protocol Codes
// These aren't fully named as vectors in the standard, but are used as such so
// we put them in here
/**
* @brief Vectors used at the E1.33 Broker Client Entry layer.
*/
enum ClientProtocolCode {
CLIENT_PROTOCOL_RPT = 0x00000005, /**< Broker RPT Client Entry */
CLIENT_PROTOCOL_EPT = 0x0000000b, /**< Broker EPT Client Entry */
};

/**
* @}
*/
Expand Down
13 changes: 13 additions & 0 deletions include/ola/acn/CID.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ class CID {
*/
std::string ToString() const;

/**
* @brief A helper function to write a CID to an ostream.
* @param out the ostream
* @param cid the CID to write.
*/
friend std::ostream& operator<< (std::ostream &out, const CID &cid) {
return out << cid.ToString();
}

/**
* @brief Write the CID to an OutputBufferInterface
*/
Expand Down Expand Up @@ -132,6 +141,10 @@ class CID {
*/
static CID FromString(const std::string &cid);

static CID LLRPBroadcastCID() {
return FromString("FBAD822C-BD0C-4D4C-BDC8-7EABEBC85AFF");
}

private:
class CIDImpl *m_impl;

Expand Down
1 change: 1 addition & 0 deletions include/ola/acn/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ olaacninclude_HEADERS =

if INSTALL_ACN
olaacninclude_HEADERS += \
include/ola/acn/ACNFlags.h \
include/ola/acn/ACNPort.h \
include/ola/acn/ACNVectors.h \
include/ola/acn/CID.h
Expand Down
4 changes: 2 additions & 2 deletions include/ola/e133/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DeviceManager {
* @returns true if the data should be acknowledged, false otherwise.
*/
typedef ola::Callback3<bool, const IPV4Address&, uint16_t,
const string&> RDMMesssageCallback;
const string&> RDMMessageCallback;

// Run when we acquire designated controller status for a device.
typedef ola::Callback1<void, const IPV4Address&> AcquireDeviceCallback;
Expand All @@ -66,7 +66,7 @@ class DeviceManager {
~DeviceManager();

// Ownership of the callbacks is transferred.
void SetRDMMessageCallback(RDMMesssageCallback *callback);
void SetRDMMessageCallback(RDMMessageCallback *callback);
void SetAcquireDeviceCallback(AcquireDeviceCallback *callback);
void SetReleaseDeviceCallback(ReleaseDeviceCallback *callback);

Expand Down
Loading

0 comments on commit e0712cd

Please sign in to comment.