Skip to content

Commit

Permalink
Merge ac11a22 into f87e79d
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Apr 5, 2024
2 parents f87e79d + ac11a22 commit 7f5e83e
Show file tree
Hide file tree
Showing 26 changed files with 1,478 additions and 16 deletions.
11 changes: 11 additions & 0 deletions include/ola/e133/MessageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ola/e133/E133Enums.h>
#include <ola/io/IOStack.h>
#include <ola/io/MemoryBlockPool.h>
#include <ola/rdm/RDMCommand.h>
#include <string>

namespace ola {
Expand All @@ -46,8 +47,18 @@ class MessageBuilder {

void PrependRDMHeader(IOStack *packet);

void BuildTCPRDMCommandPDU(IOStack *packet,
ola::rdm::RDMRequest *request,
uint16_t source_endpoint_id,
uint16_t destination_endpoint_id,
uint32_t sequence_number);

void BuildNullTCPPacket(IOStack *packet);

void BuildBrokerFetchClientListTCPPacket(IOStack *packet);

void BuildBrokerNullTCPPacket(IOStack *packet);

void BuildTCPE133StatusPDU(IOStack *packet,
uint32_t sequence_number, uint16_t endpoint_id,
ola::e133::E133StatusCode status_code,
Expand Down
38 changes: 38 additions & 0 deletions libs/acn/BrokerFetchClientListPDU.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*
* BrokerFetchClientListPDU.cpp
* The BrokerFetchClientListPDU
* Copyright (C) 2023 Peter Newman
*/

#include "libs/acn/BrokerFetchClientListPDU.h"

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

namespace ola {
namespace acn {

using ola::network::HostToNetwork;

void BrokerFetchClientListPDU::PrependPDU(ola::io::IOStack *stack) {
uint16_t vector = HostToNetwork(static_cast<uint16_t>(
VECTOR_BROKER_FETCH_CLIENT_LIST));
stack->Write(reinterpret_cast<uint8_t*>(&vector), sizeof(vector));
PrependFlagsAndLength(stack, VFLAG_MASK | HFLAG_MASK | DFLAG_MASK, true);
}
} // namespace acn
} // namespace ola
56 changes: 56 additions & 0 deletions libs/acn/BrokerFetchClientListPDU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.
*
* BrokerFetchClientListPDU.h
* The BrokerFetchClientListPDU class
* Copyright (C) 2023 Peter Newman
*/

#ifndef LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_
#define LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_

#include <ola/io/IOStack.h>

#include "libs/acn/PDU.h"

namespace ola {
namespace acn {

class BrokerFetchClientListPDU : public PDU {
public:
explicit BrokerFetchClientListPDU(unsigned int vector):
PDU(vector, TWO_BYTES, true) {}

unsigned int HeaderSize() const { return 0; }
bool PackHeader(OLA_UNUSED uint8_t *data,
unsigned int *length) const {
*length = 0;
return true;
}
void PackHeader(OLA_UNUSED ola::io::OutputStream *stream) const {}

unsigned int DataSize() const { return 0; }
bool PackData(OLA_UNUSED uint8_t *data,
unsigned int *length) const {
*length = 0;
return true;
}
void PackData(OLA_UNUSED ola::io::OutputStream *stream) const {}

static void PrependPDU(ola::io::IOStack *stack);
};
} // namespace acn
} // namespace ola
#endif // LIBS_ACN_BROKERFETCHCLIENTLISTPDU_H_
148 changes: 148 additions & 0 deletions libs/acn/BrokerFetchClientListPDUTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* 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.
*
* BrokerFetchClientListPDUTest.cpp
* Test fixture for the BrokerFetchClientListPDU class
* Copyright (C) 2023 Peter Newman
*/

#include <cppunit/extensions/HelperMacros.h>

#include "ola/Logging.h"
#include "ola/io/IOQueue.h"
#include "ola/io/IOStack.h"
#include "ola/io/OutputStream.h"
#include "ola/network/NetworkUtils.h"
#include "ola/testing/TestUtils.h"
#include "libs/acn/PDUTestCommon.h"
#include "libs/acn/BrokerFetchClientListPDU.h"

namespace ola {
namespace acn {

using ola::acn::BrokerFetchClientListPDU;
using ola::io::IOQueue;
using ola::io::IOStack;
using ola::io::OutputStream;
using ola::network::HostToNetwork;

class BrokerFetchClientListPDUTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(BrokerFetchClientListPDUTest);
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDU);
CPPUNIT_TEST(testSimpleBrokerFetchClientListPDUToOutputStream);
CPPUNIT_TEST(testPrepend);
CPPUNIT_TEST_SUITE_END();

public:
void testSimpleBrokerFetchClientListPDU();
void testSimpleBrokerFetchClientListPDUToOutputStream();
void testPrepend();

void setUp() {
ola::InitLogging(ola::OLA_LOG_DEBUG, ola::OLA_LOG_STDERR);
}

private:
static const uint16_t TEST_VECTOR;
};

CPPUNIT_TEST_SUITE_REGISTRATION(BrokerFetchClientListPDUTest);

const uint16_t BrokerFetchClientListPDUTest::TEST_VECTOR = 39;


/*
* Test that packing a BrokerFetchClientListPDU works.
*/
void BrokerFetchClientListPDUTest::testSimpleBrokerFetchClientListPDU() {
BrokerFetchClientListPDU pdu(TEST_VECTOR);

OLA_ASSERT_EQ(0u, pdu.HeaderSize());
OLA_ASSERT_EQ(0u, pdu.DataSize());
OLA_ASSERT_EQ(5u, pdu.Size());

unsigned int size = pdu.Size();
uint8_t *data = new uint8_t[size];
unsigned int bytes_used = size;
OLA_ASSERT(pdu.Pack(data, &bytes_used));
OLA_ASSERT_EQ(size, bytes_used);

// spot check the data
OLA_ASSERT_EQ((uint8_t) 0xf0, data[0]);
// bytes_used is technically data[1] and data[2] if > 255
OLA_ASSERT_EQ((uint8_t) bytes_used, data[2]);
uint16_t actual_value;
memcpy(&actual_value, data + 3, sizeof(actual_value));
OLA_ASSERT_EQ(HostToNetwork(TEST_VECTOR), actual_value);

// test undersized buffer
bytes_used = size - 1;
OLA_ASSERT_FALSE(pdu.Pack(data, &bytes_used));
OLA_ASSERT_EQ(0u, bytes_used);

// test oversized buffer
bytes_used = size + 1;
OLA_ASSERT(pdu.Pack(data, &bytes_used));
OLA_ASSERT_EQ(size, bytes_used);
delete[] data;
}

/*
* Test that writing to an output stream works.
*/
void BrokerFetchClientListPDUTest::
testSimpleBrokerFetchClientListPDUToOutputStream() {
BrokerFetchClientListPDU pdu(TEST_VECTOR);

OLA_ASSERT_EQ(0u, pdu.HeaderSize());
OLA_ASSERT_EQ(0u, pdu.DataSize());
OLA_ASSERT_EQ(5u, pdu.Size());

IOQueue output;
OutputStream stream(&output);
pdu.Write(&stream);
OLA_ASSERT_EQ(5u, output.Size());

uint8_t *pdu_data = new uint8_t[output.Size()];
unsigned int pdu_size = output.Peek(pdu_data, output.Size());
OLA_ASSERT_EQ(output.Size(), pdu_size);

uint8_t EXPECTED[] = {
0xf0, 0x00, 0x05,
0, 39
};
OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size);
output.Pop(output.Size());
delete[] pdu_data;
}


void BrokerFetchClientListPDUTest::testPrepend() {
IOStack stack;
BrokerFetchClientListPDU::PrependPDU(&stack);

unsigned int length = stack.Size();
uint8_t *buffer = new uint8_t[length];
OLA_ASSERT(stack.Read(buffer, length));

const uint8_t expected_data[] = {
0xf0, 0x00, 0x05,
0, 0x06
};
OLA_ASSERT_DATA_EQUALS(expected_data, sizeof(expected_data), buffer, length);
delete[] buffer;
}
} // namespace acn
} // namespace ola
8 changes: 7 additions & 1 deletion libs/acn/HeaderSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libs/acn/E133Header.h"
#include "libs/acn/LLRPHeader.h"
#include "libs/acn/RootHeader.h"
#include "libs/acn/RPTHeader.h"
#include "libs/acn/TransportHeader.h"

namespace ola {
Expand Down Expand Up @@ -60,14 +61,18 @@ class HeaderSet {
const LLRPHeader &GetLLRPHeader() const { return m_llrp_header; }
void SetLLRPHeader(const LLRPHeader &header) { m_llrp_header = header; }

const RPTHeader &GetRPTHeader() const { return m_rpt_header; }
void SetRPTHeader(const RPTHeader &header) { m_rpt_header = header; }

bool operator==(const HeaderSet &other) const {
return (
m_transport_header == other.m_transport_header &&
m_root_header == other.m_root_header &&
m_e131_header == other.m_e131_header &&
m_e133_header == other.m_e133_header &&
m_dmp_header == other.m_dmp_header &&
m_llrp_header == other.m_llrp_header);
m_llrp_header == other.m_llrp_header &&
m_rpt_header == other.m_rpt_header);
}

private:
Expand All @@ -77,6 +82,7 @@ class HeaderSet {
E133Header m_e133_header;
DMPHeader m_dmp_header;
LLRPHeader m_llrp_header;
RPTHeader m_rpt_header;
};
} // namespace acn
} // namespace ola
Expand Down
Loading

0 comments on commit 7f5e83e

Please sign in to comment.