Skip to content

Commit d72f35e

Browse files
authored
Merge pull request #1959 from peternewman/e1.33-cherry-pick
E1.33 cherry pick number 6
2 parents 0fff671 + 016f0cd commit d72f35e

File tree

4 files changed

+166
-2
lines changed

4 files changed

+166
-2
lines changed

libs/acn/LLRPProbeReplyPDU.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ using ola::network::HostToNetwork;
3232
using ola::network::MACAddress;
3333
using ola::rdm::UID;
3434

35+
bool LLRPProbeReplyPDU::PackData(uint8_t *data, unsigned int *length) const {
36+
llrp_probe_reply_pdu_data pdu_data;
37+
m_target_uid.Pack(pdu_data.target_uid, sizeof(pdu_data.target_uid));
38+
m_hardware_address.Pack(pdu_data.hardware_address,
39+
sizeof(pdu_data.hardware_address));
40+
pdu_data.type = HostToNetwork(static_cast<uint8_t>(m_type));
41+
42+
*length = sizeof(llrp_probe_reply_pdu_data);
43+
memcpy(data, &pdu_data, *length);
44+
return true;
45+
}
46+
47+
void LLRPProbeReplyPDU::PackData(ola::io::OutputStream *stream) const {
48+
llrp_probe_reply_pdu_data data;
49+
m_target_uid.Pack(data.target_uid, sizeof(data.target_uid));
50+
m_hardware_address.Pack(data.hardware_address, sizeof(data.hardware_address));
51+
data.type = HostToNetwork(static_cast<uint8_t>(m_type));
52+
stream->Write(reinterpret_cast<uint8_t*>(&data),
53+
static_cast<unsigned int>(sizeof(llrp_probe_reply_pdu_data)));
54+
}
55+
3556
void LLRPProbeReplyPDU::PrependPDU(ola::io::IOStack *stack,
3657
const UID &target_uid,
3758
const MACAddress &hardware_address,

libs/acn/LLRPProbeReplyPDU.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
namespace ola {
3131
namespace acn {
3232

33-
class LLRPProbeReplyPDU : private PDU {
33+
class LLRPProbeReplyPDU : public PDU {
3434
public:
3535
typedef enum {
3636
LLRP_COMPONENT_TYPE_RPT_DEVICE = 0, /**< Device */
@@ -39,6 +39,27 @@ class LLRPProbeReplyPDU : private PDU {
3939
LLRP_COMPONENT_TYPE_NON_RDMNET = 0xff, /**< Non-RDMnet */
4040
} LLRPComponentType;
4141

42+
explicit LLRPProbeReplyPDU(unsigned int vector,
43+
const ola::rdm::UID &target_uid,
44+
const ola::network::MACAddress &hardware_address,
45+
const LLRPComponentType type):
46+
PDU(vector, ONE_BYTE, true),
47+
m_target_uid(target_uid),
48+
m_hardware_address(hardware_address),
49+
m_type(type) {}
50+
51+
unsigned int HeaderSize() const { return 0; }
52+
bool PackHeader(OLA_UNUSED uint8_t *data,
53+
unsigned int *length) const {
54+
*length = 0;
55+
return true;
56+
}
57+
void PackHeader(OLA_UNUSED ola::io::OutputStream *stream) const {}
58+
59+
unsigned int DataSize() const { return sizeof(llrp_probe_reply_pdu_data); }
60+
bool PackData(uint8_t *data, unsigned int *length) const;
61+
void PackData(ola::io::OutputStream *stream) const;
62+
4263
static void PrependPDU(ola::io::IOStack *stack,
4364
const ola::rdm::UID &target_uid,
4465
const ola::network::MACAddress &hardware_address,
@@ -53,6 +74,11 @@ class LLRPProbeReplyPDU : private PDU {
5374
uint8_t type;
5475
});
5576
typedef struct llrp_probe_reply_pdu_data_s llrp_probe_reply_pdu_data;
77+
78+
private:
79+
const ola::rdm::UID m_target_uid;
80+
const ola::network::MACAddress m_hardware_address;
81+
const LLRPComponentType m_type;
5682
};
5783
} // namespace acn
5884
} // namespace ola

libs/acn/LLRPProbeReplyPDUTest.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#include <string>
2424

2525
#include "ola/Logging.h"
26+
#include "ola/io/IOQueue.h"
2627
#include "ola/io/IOStack.h"
28+
#include "ola/io/OutputStream.h"
2729
#include "ola/network/NetworkUtils.h"
2830
#include "ola/rdm/UID.h"
2931
#include "ola/rdm/UIDSet.h"
@@ -35,16 +37,23 @@ namespace ola {
3537
namespace acn {
3638

3739
using ola::acn::LLRPProbeReplyPDU;
40+
using ola::io::IOQueue;
3841
using ola::io::IOStack;
42+
using ola::io::OutputStream;
43+
using ola::network::HostToNetwork;
3944
using ola::network::MACAddress;
4045
using ola::rdm::UID;
4146

4247
class LLRPProbeReplyPDUTest: public CppUnit::TestFixture {
4348
CPPUNIT_TEST_SUITE(LLRPProbeReplyPDUTest);
49+
CPPUNIT_TEST(testSimpleLLRPProbeReplyPDU);
50+
CPPUNIT_TEST(testSimpleLLRPProbeReplyPDUToOutputStream);
4451
CPPUNIT_TEST(testPrepend);
4552
CPPUNIT_TEST_SUITE_END();
4653

4754
public:
55+
void testSimpleLLRPProbeReplyPDU();
56+
void testSimpleLLRPProbeReplyPDUToOutputStream();
4857
void testPrepend();
4958

5059
private:
@@ -53,6 +62,98 @@ class LLRPProbeReplyPDUTest: public CppUnit::TestFixture {
5362

5463
CPPUNIT_TEST_SUITE_REGISTRATION(LLRPProbeReplyPDUTest);
5564

65+
const unsigned int LLRPProbeReplyPDUTest::TEST_VECTOR = 39;
66+
67+
68+
/*
69+
* Test that packing a LLRPProbeReplyPDU works.
70+
*/
71+
void LLRPProbeReplyPDUTest::testSimpleLLRPProbeReplyPDU() {
72+
UID target_uid = UID(0x4321, 0x12345678);
73+
MACAddress hardware_address;
74+
MACAddress::FromString("01:23:45:67:89:ab", &hardware_address);
75+
LLRPProbeReplyPDU pdu(
76+
TEST_VECTOR,
77+
target_uid,
78+
hardware_address,
79+
LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);
80+
81+
OLA_ASSERT_EQ(0u, pdu.HeaderSize());
82+
OLA_ASSERT_EQ(13u, pdu.DataSize());
83+
OLA_ASSERT_EQ(17u, pdu.Size());
84+
85+
unsigned int size = pdu.Size();
86+
uint8_t *data = new uint8_t[size];
87+
unsigned int bytes_used = size;
88+
OLA_ASSERT(pdu.Pack(data, &bytes_used));
89+
OLA_ASSERT_EQ(size, bytes_used);
90+
91+
// spot check the data
92+
OLA_ASSERT_EQ((uint8_t) 0xf0, data[0]);
93+
// bytes_used is technically data[1] and data[2] if > 255
94+
OLA_ASSERT_EQ((uint8_t) bytes_used, data[2]);
95+
OLA_ASSERT_EQ(HostToNetwork((uint8_t) TEST_VECTOR), data[3]);
96+
97+
uint8_t buffer[UID::LENGTH];
98+
target_uid.Pack(buffer, sizeof(buffer));
99+
OLA_ASSERT_DATA_EQUALS(&data[4], UID::LENGTH, buffer, sizeof(buffer));
100+
uint8_t buffer2[MACAddress::LENGTH];
101+
hardware_address.Pack(buffer2, sizeof(buffer2));
102+
OLA_ASSERT_DATA_EQUALS(&data[10], MACAddress::LENGTH,
103+
buffer2, sizeof(buffer2));
104+
105+
// test undersized buffer
106+
bytes_used = size - 1;
107+
OLA_ASSERT_FALSE(pdu.Pack(data, &bytes_used));
108+
OLA_ASSERT_EQ(0u, bytes_used);
109+
110+
// test oversized buffer
111+
bytes_used = size + 1;
112+
OLA_ASSERT(pdu.Pack(data, &bytes_used));
113+
OLA_ASSERT_EQ(size, bytes_used);
114+
delete[] data;
115+
}
116+
117+
118+
/*
119+
* Test that writing to an output stream works.
120+
*/
121+
void LLRPProbeReplyPDUTest::testSimpleLLRPProbeReplyPDUToOutputStream() {
122+
UID target_uid = UID(0x4321, 0x12345678);
123+
MACAddress hardware_address;
124+
MACAddress::FromString("01:23:45:67:89:ab", &hardware_address);
125+
LLRPProbeReplyPDU pdu(
126+
TEST_VECTOR,
127+
target_uid,
128+
hardware_address,
129+
LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);
130+
131+
OLA_ASSERT_EQ(0u, pdu.HeaderSize());
132+
OLA_ASSERT_EQ(13u, pdu.DataSize());
133+
OLA_ASSERT_EQ(17u, pdu.Size());
134+
135+
IOQueue output;
136+
OutputStream stream(&output);
137+
pdu.Write(&stream);
138+
OLA_ASSERT_EQ(17u, output.Size());
139+
140+
uint8_t *pdu_data = new uint8_t[output.Size()];
141+
unsigned int pdu_size = output.Peek(pdu_data, output.Size());
142+
OLA_ASSERT_EQ(output.Size(), pdu_size);
143+
144+
uint8_t EXPECTED[] = {
145+
0xf0, 0x00, 0x11,
146+
39,
147+
0x43, 0x21, 0x12, 0x34, 0x56, 0x78,
148+
0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
149+
0xff
150+
};
151+
OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size);
152+
output.Pop(output.Size());
153+
delete[] pdu_data;
154+
}
155+
156+
56157
void LLRPProbeReplyPDUTest::testPrepend() {
57158
IOStack stack;
58159
UID target_uid = UID(0x4321, 0x12345678);

libs/acn/MessageBuilder.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ola/e133/MessageBuilder.h"
2626
#include "ola/io/IOStack.h"
2727
#include "ola/rdm/RDMCommandSerializer.h"
28+
#include "ola/rdm/UID.h"
2829

2930
#include "libs/acn/BrokerPDU.h"
3031
#include "libs/acn/E133PDU.h"
@@ -72,12 +73,27 @@ void MessageBuilder::BuildTCPRDMCommandPDU(IOStack *packet,
7273
uint16_t source_endpoint_id,
7374
uint16_t destination_endpoint_id,
7475
uint32_t sequence_number) {
76+
// TODO(Peter): Potentially need some future way to handle controller
77+
// messages here
78+
ola::rdm::UID rpt_destination_uid = request->DestinationUID();
79+
if (rpt_destination_uid.IsBroadcast()) {
80+
if (rpt_destination_uid.IsVendorcast()) {
81+
rpt_destination_uid = ola::rdm::UID::RPTVendorcastAddressDevices(
82+
rpt_destination_uid);
83+
} else {
84+
rpt_destination_uid = ola::rdm::UID::RPTAllDevices();
85+
}
86+
if (destination_endpoint_id != NULL_ENDPOINT) {
87+
// TODO(Peter): Should we handle the reserved endpoints now?
88+
destination_endpoint_id = BROADCAST_ENDPOINT;
89+
}
90+
}
7591
ola::rdm::RDMCommandSerializer::Write(*request, packet);
7692
ola::acn::RDMPDU::PrependPDU(packet);
7793
ola::acn::RPTRequestPDU::PrependPDU(packet);
7894
RPTPDU::PrependPDU(packet, ola::acn::VECTOR_RPT_REQUEST,
7995
request->SourceUID(), source_endpoint_id,
80-
request->DestinationUID(), destination_endpoint_id,
96+
rpt_destination_uid, destination_endpoint_id,
8197
sequence_number);
8298
RootPDU::PrependPDU(packet, ola::acn::VECTOR_ROOT_RPT, m_cid, true);
8399
PreamblePacker::AddTCPPreamble(packet);

0 commit comments

Comments
 (0)