Skip to content

Commit

Permalink
Add support for the IPv6 data type to the RDM messaging and the addit…
Browse files Browse the repository at this point in the history
…ional E1.33 and E1.37-7 PIDs that enables
  • Loading branch information
peternewman committed Dec 3, 2023
1 parent 1a68747 commit 2a2ab67
Show file tree
Hide file tree
Showing 33 changed files with 461 additions and 35 deletions.
8 changes: 8 additions & 0 deletions common/messaging/DescriptorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using ola::messaging::BoolFieldDescriptor;
using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV6FieldDescriptor;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::StringFieldDescriptor;
using ola::messaging::UIDFieldDescriptor;
Expand Down Expand Up @@ -77,6 +78,13 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_TRUE(ipv4_descriptor.LimitedSize());
OLA_ASSERT_EQ(4u, ipv4_descriptor.MaxSize());

// IPv6 address
IPV6FieldDescriptor ipv6_descriptor("ipv6");
OLA_ASSERT_EQ(string("ipv6"), ipv6_descriptor.Name());
OLA_ASSERT_TRUE(ipv6_descriptor.FixedSize());
OLA_ASSERT_TRUE(ipv6_descriptor.LimitedSize());
OLA_ASSERT_EQ(16u, ipv6_descriptor.MaxSize());

// MAC address
MACFieldDescriptor mac_descriptor("mac");
OLA_ASSERT_EQ(string("mac"), mac_descriptor.Name());
Expand Down
7 changes: 7 additions & 0 deletions common/messaging/MessagePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ void GenericMessagePrinter::Visit(const IPV4MessageField *message) {
}


void GenericMessagePrinter::Visit(const IPV6MessageField *message) {
Stream() << string(m_indent, ' ') <<
TransformLabel(message->GetDescriptor()->Name()) << ": "
<< message->Value() << endl;
}


void GenericMessagePrinter::Visit(const MACMessageField *message) {
Stream() << string(m_indent, ' ') <<
TransformLabel(message->GetDescriptor()->Name()) << ": "
Expand Down
23 changes: 15 additions & 8 deletions common/messaging/MessagePrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@

using std::string;
using std::vector;
using ola::rdm::UID;
using ola::network::IPV6Address;
using ola::network::MACAddress;
using ola::rdm::UID;


using ola::messaging::BoolFieldDescriptor;
Expand All @@ -42,14 +43,16 @@ using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::GenericMessagePrinter;
using ola::messaging::GroupMessageField;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int16MessageField;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::Int8MessageField;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV4MessageField;
using ola::messaging::IPV6FieldDescriptor;
using ola::messaging::IPV6MessageField;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::MACMessageField;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int16MessageField;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::Int8MessageField;
using ola::messaging::Message;
using ola::messaging::MessageFieldInterface;
using ola::messaging::StringFieldDescriptor;
Expand Down Expand Up @@ -90,6 +93,7 @@ void GenericMessagePrinterTest::testSimplePrinter() {
// setup some fields
BoolFieldDescriptor bool_descriptor("On/Off");
IPV4FieldDescriptor ipv4_descriptor("ip");
IPV6FieldDescriptor ipv6_descriptor("ipv6");
MACFieldDescriptor mac_descriptor("mac");
UIDFieldDescriptor uid_descriptor("uid");
StringFieldDescriptor string_descriptor("Name", 0, 32);
Expand All @@ -104,6 +108,9 @@ void GenericMessagePrinterTest::testSimplePrinter() {
fields.push_back(
new IPV4MessageField(&ipv4_descriptor,
ola::network::HostToNetwork(0x0a000001)));
fields.push_back(
new IPV6MessageField(&ipv6_descriptor,
IPV6Address::FromStringOrDie("::ffff:192.168.0.1")));
fields.push_back(
new MACMessageField(&mac_descriptor,
MACAddress::FromStringOrDie("01:23:45:67:89:ab")));
Expand All @@ -116,9 +123,9 @@ void GenericMessagePrinterTest::testSimplePrinter() {

Message message(fields);
string expected = (
"On/Off: false\nip: 10.0.0.1\nmac: 01:23:45:67:89:ab\n"
"uid: 7a70:00000001\nName: foobar\nId: 42\nCount: 4 x 10 ^ -3\n"
"Delta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n");
"On/Off: false\nip: 10.0.0.1\nipv6: ::ffff:192.168.0.1\n"
"mac: 01:23:45:67:89:ab\nuid: 7a70:00000001\nName: foobar\nId: 42\n"
"Count: 4 x 10 ^ -3\nDelta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n");
OLA_ASSERT_EQ(expected, m_printer.AsString(&message));
}

Expand Down
6 changes: 6 additions & 0 deletions common/messaging/SchemaPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ void SchemaPrinter::Visit(const IPV4FieldDescriptor *descriptor) {
}


void SchemaPrinter::Visit(const IPV6FieldDescriptor *descriptor) {
m_str << string(m_indent, ' ') << descriptor->Name() << ": IPv6 address"
<< endl;
}


void SchemaPrinter::Visit(const MACFieldDescriptor *descriptor) {
m_str << string(m_indent, ' ') << descriptor->Name() << ": MAC" << endl;
}
Expand Down
6 changes: 5 additions & 1 deletion common/messaging/SchemaPrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using std::vector;

using ola::messaging::BoolFieldDescriptor;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV6FieldDescriptor;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::Descriptor;
using ola::messaging::FieldDescriptor;
Expand Down Expand Up @@ -85,6 +86,8 @@ void SchemaPrinterTest::testPrinter() {
"Count", false, 10);
IPV4FieldDescriptor *ipv4_descriptor = new IPV4FieldDescriptor(
"Address");
IPV6FieldDescriptor *ipv6_descriptor = new IPV6FieldDescriptor(
"v6 Address");
MACFieldDescriptor *mac_descriptor = new MACFieldDescriptor(
"MAC Address");
UIDFieldDescriptor *uid_descriptor = new UIDFieldDescriptor("Device");
Expand All @@ -95,6 +98,7 @@ void SchemaPrinterTest::testPrinter() {
fields.push_back(string_descriptor);
fields.push_back(uint8_descriptor);
fields.push_back(ipv4_descriptor);
fields.push_back(ipv6_descriptor);
fields.push_back(mac_descriptor);
fields.push_back(uid_descriptor);

Expand All @@ -104,7 +108,7 @@ void SchemaPrinterTest::testPrinter() {

string expected = (
"On/Off: bool\nName: string [0, 32]\nCount: uint8\n"
"Address: IPv4 address\nMAC Address: MAC\nDevice: UID\n");
"Address: IPv4 address\nv6 Address: IPv6 address\nMAC Address: MAC\nDevice: UID\n");

Check failure on line 111 in common/messaging/SchemaPrinterTest.cpp

View workflow job for this annotation

GitHub Actions / cpplint

Lines should be <= 80 characters long [whitespace/line_length] [2]
OLA_ASSERT_EQ(expected, printer.AsString());
}

Expand Down
5 changes: 5 additions & 0 deletions common/rdm/DescriptorConsistencyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ void DescriptorConsistencyChecker::Visit(
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::IPV6FieldDescriptor*) {
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::MACFieldDescriptor*) {
}
Expand Down
1 change: 1 addition & 0 deletions common/rdm/DescriptorConsistencyChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DescriptorConsistencyChecker

void Visit(const ola::messaging::BoolFieldDescriptor*);
void Visit(const ola::messaging::IPV4FieldDescriptor*);
void Visit(const ola::messaging::IPV6FieldDescriptor*);
void Visit(const ola::messaging::MACFieldDescriptor*);
void Visit(const ola::messaging::UIDFieldDescriptor*);
void Visit(const ola::messaging::StringFieldDescriptor*);
Expand Down
12 changes: 12 additions & 0 deletions common/rdm/GroupSizeCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ void GroupSizeCalculator::Visit(
}


void GroupSizeCalculator::Visit(
const ola::messaging::IPV6FieldDescriptor *descriptor) {
m_non_groups.push_back(descriptor);
}


void GroupSizeCalculator::Visit(
const ola::messaging::MACFieldDescriptor *descriptor) {
m_non_groups.push_back(descriptor);
Expand Down Expand Up @@ -246,6 +252,12 @@ void StaticGroupTokenCalculator::Visit(
}


void StaticGroupTokenCalculator::Visit(
OLA_UNUSED const ola::messaging::IPV6FieldDescriptor *descriptor) {
m_token_count.top()++;
}


void StaticGroupTokenCalculator::Visit(
OLA_UNUSED const ola::messaging::MACFieldDescriptor *descriptor) {
m_token_count.top()++;
Expand Down
2 changes: 2 additions & 0 deletions common/rdm/GroupSizeCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class StaticGroupTokenCalculator

void Visit(const ola::messaging::BoolFieldDescriptor*);
void Visit(const ola::messaging::IPV4FieldDescriptor*);
void Visit(const ola::messaging::IPV6FieldDescriptor*);
void Visit(const ola::messaging::MACFieldDescriptor*);
void Visit(const ola::messaging::UIDFieldDescriptor*);
void Visit(const ola::messaging::StringFieldDescriptor*);
Expand Down Expand Up @@ -98,6 +99,7 @@ class GroupSizeCalculator: public ola::messaging::FieldDescriptorVisitor {

void Visit(const ola::messaging::BoolFieldDescriptor*);
void Visit(const ola::messaging::IPV4FieldDescriptor*);
void Visit(const ola::messaging::IPV6FieldDescriptor*);
void Visit(const ola::messaging::MACFieldDescriptor*);
void Visit(const ola::messaging::UIDFieldDescriptor*);
void Visit(const ola::messaging::StringFieldDescriptor*);
Expand Down
12 changes: 7 additions & 5 deletions common/rdm/GroupSizeCalculatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using ola::messaging::Descriptor;
using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV6FieldDescriptor;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int32FieldDescriptor;
using ola::messaging::Int8FieldDescriptor;
Expand Down Expand Up @@ -84,16 +85,17 @@ void GroupSizeCalculatorTest::testSimpleCases() {
fields.push_back(new Int8FieldDescriptor("int8"));
fields.push_back(new Int16FieldDescriptor("int16"));
fields.push_back(new Int32FieldDescriptor("int32"));
fields.push_back(new MACFieldDescriptor("mac"));
fields.push_back(new StringFieldDescriptor("string", 0, 32));
fields.push_back(new IPV4FieldDescriptor("address"));
fields.push_back(new IPV6FieldDescriptor("addressv6"));
fields.push_back(new MACFieldDescriptor("mac"));
fields.push_back(new UIDFieldDescriptor("uid"));
Descriptor descriptor("Test Descriptor", fields);

unsigned int token_count, group_repeat_count;
OLA_ASSERT_TRUE(
m_static_calculator.CalculateTokensRequired(&descriptor, &token_count));
OLA_ASSERT_EQ(11u, token_count); // Actual token count
OLA_ASSERT_EQ(12u, token_count); // Actual token count


OLA_ASSERT_EQ(
Expand All @@ -106,21 +108,21 @@ void GroupSizeCalculatorTest::testSimpleCases() {
OLA_ASSERT_EQ(
GroupSizeCalculator::INSUFFICIENT_TOKENS,
m_calculator.CalculateGroupSize(
10, // Actual token count - 1
11, // Actual token count - 1
&descriptor,
&group_repeat_count));

OLA_ASSERT_EQ(
GroupSizeCalculator::NO_VARIABLE_GROUPS,
m_calculator.CalculateGroupSize(
11, // Actual token count
12, // Actual token count
&descriptor,
&group_repeat_count));

OLA_ASSERT_EQ(
GroupSizeCalculator::EXTRA_TOKENS,
m_calculator.CalculateGroupSize(
12, // Actual token count + 1
13, // Actual token count + 1
&descriptor,
&group_repeat_count));
}
Expand Down
31 changes: 22 additions & 9 deletions common/rdm/MessageDeserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void MessageDeserializer::Visit(
}

m_message_stack.top().push_back(
new ola::messaging::BoolMessageField(descriptor, m_data[m_offset++]));
new ola::messaging::BoolMessageField(descriptor, m_data[m_offset++]));
}


Expand All @@ -128,9 +128,22 @@ void MessageDeserializer::Visit(
memcpy(&data, m_data + m_offset, sizeof(data));
m_offset += sizeof(data);
m_message_stack.top().push_back(
new ola::messaging::IPV4MessageField(
descriptor,
ola::network::IPV4Address(data)));
new ola::messaging::IPV4MessageField(
descriptor,
ola::network::IPV4Address(data)));
}


void MessageDeserializer::Visit(
const ola::messaging::IPV6FieldDescriptor *descriptor) {
if (!CheckForData(descriptor->MaxSize())) {
return;
}

ola::network::IPV6Address ipv6_address(m_data + m_offset);
m_offset += descriptor->MaxSize();
m_message_stack.top().push_back(
new ola::messaging::IPV6MessageField(descriptor, ipv6_address));
}


Expand All @@ -143,7 +156,7 @@ void MessageDeserializer::Visit(
ola::network::MACAddress mac_address(m_data + m_offset);
m_offset += descriptor->MaxSize();
m_message_stack.top().push_back(
new ola::messaging::MACMessageField(descriptor, mac_address));
new ola::messaging::MACMessageField(descriptor, mac_address));
}


Expand All @@ -156,7 +169,7 @@ void MessageDeserializer::Visit(
ola::rdm::UID uid(m_data + m_offset);
m_offset += descriptor->MaxSize();
m_message_stack.top().push_back(
new ola::messaging::UIDMessageField(descriptor, uid));
new ola::messaging::UIDMessageField(descriptor, uid));
}


Expand All @@ -179,7 +192,7 @@ void MessageDeserializer::Visit(
ShortenString(&value);
m_offset += string_size;
m_message_stack.top().push_back(
new ola::messaging::StringMessageField(descriptor, value));
new ola::messaging::StringMessageField(descriptor, value));
}


Expand Down Expand Up @@ -226,7 +239,7 @@ void MessageDeserializer::Visit(
const ola::messaging::FieldDescriptorGroup *descriptor) {

unsigned int iterations = descriptor->FixedSize() ? descriptor->MinBlocks() :
m_variable_field_size;
m_variable_field_size;

for (unsigned int i = 0; i < iterations; ++i) {
vector<const MessageFieldInterface*> fields;
Expand Down Expand Up @@ -298,7 +311,7 @@ void MessageDeserializer::IntVisit(
}

m_message_stack.top().push_back(
new ola::messaging::BasicMessageField<int_type>(descriptor, value));
new ola::messaging::BasicMessageField<int_type>(descriptor, value));
}
} // namespace rdm
} // namespace ola
Loading

0 comments on commit 2a2ab67

Please sign in to comment.