diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8408df474e..296da8211b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -119,14 +119,14 @@ jobs: if: always() run: sha256sum ola-*.tar.gz - name: Upload source tree artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: always() with: name: ola-${{ matrix.id }}-source-tree path: ola-${{ matrix.id }}-source-tree.tar.gz - name: Upload built artifact if: matrix.task == 'distcheck' || matrix.task == 'dist' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ola-${{ matrix.id }}-dist path: | @@ -147,7 +147,7 @@ jobs: flag-name: ${{ matrix.id }} - name: Upload coverage artifacts if: always() && matrix.task == 'coverage' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ola-${{ matrix.id }}-coverage path: coverage/ @@ -165,7 +165,7 @@ jobs: - id: "distcheck-debian-stable-amd64-clang" steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-${{ matrix.id }}-source-tree path: . diff --git a/.github/workflows/debian.yml b/.github/workflows/debian.yml index 0ae5317ba0..7fff3d801f 100644 --- a/.github/workflows/debian.yml +++ b/.github/workflows/debian.yml @@ -53,7 +53,7 @@ jobs: shell: bash run: find . -type f -exec sha256sum {} \; working-directory: built - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: always() with: name: ola-built-debian-${{ matrix.image_tag }}-${{ matrix.architecture }} @@ -72,7 +72,7 @@ jobs: steps: - uses: actions/checkout@master - name: Download build artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-built-debian-${{ matrix.image_tag }}-${{ matrix.architecture }} path: built @@ -85,7 +85,7 @@ jobs: run: apt-get -y install autopkgtest - name: Test run: autopkgtest --output-dir=test-output built/*ges -- null - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: always() # Always upload the test output, even on failed tests with: name: ola-test-output-debian-${{ matrix.image_tag }}-${{ matrix.architecture }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 0c49e768a0..12d892fb4c 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -56,7 +56,7 @@ jobs: tar --exclude=ola-debian-stable-built-source-tree.tar.gz -cvzf ola-debian-stable-built-source-tree.tar.gz . - name: SHA256 artifact archive run: sha256sum ola-debian-stable-built-source-tree.tar.gz - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: ola-debian-stable-built-source-tree path: ola-debian-stable-built-source-tree.tar.gz @@ -67,7 +67,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . @@ -97,7 +97,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . @@ -123,7 +123,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . @@ -160,7 +160,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . @@ -197,7 +197,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . @@ -226,7 +226,7 @@ jobs: needs: build steps: - name: Download built source tree archive - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ola-debian-stable-built-source-tree path: . diff --git a/common/messaging/DescriptorTest.cpp b/common/messaging/DescriptorTest.cpp index 9c1bbcde44..37cce39c97 100644 --- a/common/messaging/DescriptorTest.cpp +++ b/common/messaging/DescriptorTest.cpp @@ -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; @@ -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()); diff --git a/common/messaging/MessagePrinter.cpp b/common/messaging/MessagePrinter.cpp index 07226b96fe..7123c15782 100644 --- a/common/messaging/MessagePrinter.cpp +++ b/common/messaging/MessagePrinter.cpp @@ -45,37 +45,44 @@ string MessagePrinter::AsString(const Message *message) { void GenericMessagePrinter::Visit(const BoolMessageField *message) { - Stream() << string(m_indent, ' ') << - TransformLabel(message->GetDescriptor()->Name()) << ": " - << (message->Value() ? "true" : "false") << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << ": " + << (message->Value() ? "true" : "false") << endl; } void GenericMessagePrinter::Visit(const IPV4MessageField *message) { - Stream() << string(m_indent, ' ') << - TransformLabel(message->GetDescriptor()->Name()) << ": " - << message->Value() << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << ": " + << message->Value() << endl; +} + + +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()) << ": " - << message->Value().ToString() << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << ": " + << message->Value().ToString() << endl; } void GenericMessagePrinter::Visit(const UIDMessageField *message) { - Stream() << string(m_indent, ' ') << - TransformLabel(message->GetDescriptor()->Name()) << ": " - << message->Value().ToString() << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << ": " + << message->Value().ToString() << endl; } void GenericMessagePrinter::Visit(const StringMessageField *message) { - Stream() << string(m_indent, ' ') << - TransformLabel(message->GetDescriptor()->Name()) << ": " - << EncodeString(message->Value()) << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << ": " + << EncodeString(message->Value()) << endl; } @@ -134,8 +141,8 @@ void GenericMessagePrinter::Visit(const BasicMessageField *message) { void GenericMessagePrinter::Visit(const GroupMessageField *message) { - Stream() << string(m_indent, ' ') << - TransformLabel(message->GetDescriptor()->Name()) << " {" << endl; + Stream() << string(m_indent, ' ') + << TransformLabel(message->GetDescriptor()->Name()) << " {" << endl; m_indent += m_indent_size; } @@ -178,8 +185,9 @@ void GenericMessagePrinter::AppendInt(const string &name, void GenericMessagePrinter::AppendMultiplier(int8_t multiplier) { - if (multiplier) + if (multiplier) { Stream() << " x 10 ^ " << static_cast(multiplier); + } } } // namespace messaging } // namespace ola diff --git a/common/messaging/MessagePrinterTest.cpp b/common/messaging/MessagePrinterTest.cpp index 0fdc2c2519..5484370aa0 100644 --- a/common/messaging/MessagePrinterTest.cpp +++ b/common/messaging/MessagePrinterTest.cpp @@ -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; @@ -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; @@ -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); @@ -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"))); @@ -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)); } diff --git a/common/messaging/SchemaPrinter.cpp b/common/messaging/SchemaPrinter.cpp index ba8258ef92..62b07146b2 100644 --- a/common/messaging/SchemaPrinter.cpp +++ b/common/messaging/SchemaPrinter.cpp @@ -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; } diff --git a/common/messaging/SchemaPrinterTest.cpp b/common/messaging/SchemaPrinterTest.cpp index dbbe83be67..0eda1f5a36 100644 --- a/common/messaging/SchemaPrinterTest.cpp +++ b/common/messaging/SchemaPrinterTest.cpp @@ -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; @@ -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"); @@ -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); @@ -104,7 +108,8 @@ 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\n" + "Device: UID\n"); OLA_ASSERT_EQ(expected, printer.AsString()); } diff --git a/common/rdm/DescriptorConsistencyChecker.cpp b/common/rdm/DescriptorConsistencyChecker.cpp index ed224e4955..e947d6d14e 100644 --- a/common/rdm/DescriptorConsistencyChecker.cpp +++ b/common/rdm/DescriptorConsistencyChecker.cpp @@ -41,6 +41,11 @@ void DescriptorConsistencyChecker::Visit( } +void DescriptorConsistencyChecker::Visit( + const ola::messaging::IPV6FieldDescriptor*) { +} + + void DescriptorConsistencyChecker::Visit( const ola::messaging::MACFieldDescriptor*) { } diff --git a/common/rdm/DescriptorConsistencyChecker.h b/common/rdm/DescriptorConsistencyChecker.h index 294debf3f3..a1ed804841 100644 --- a/common/rdm/DescriptorConsistencyChecker.h +++ b/common/rdm/DescriptorConsistencyChecker.h @@ -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*); diff --git a/common/rdm/GroupSizeCalculator.cpp b/common/rdm/GroupSizeCalculator.cpp index d4287b5725..18eb334a0f 100644 --- a/common/rdm/GroupSizeCalculator.cpp +++ b/common/rdm/GroupSizeCalculator.cpp @@ -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); @@ -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()++; diff --git a/common/rdm/GroupSizeCalculator.h b/common/rdm/GroupSizeCalculator.h index f2c8b4e8e4..c15ec07cda 100644 --- a/common/rdm/GroupSizeCalculator.h +++ b/common/rdm/GroupSizeCalculator.h @@ -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*); @@ -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*); diff --git a/common/rdm/GroupSizeCalculatorTest.cpp b/common/rdm/GroupSizeCalculatorTest.cpp index 02559f5074..c86dd1dc18 100644 --- a/common/rdm/GroupSizeCalculatorTest.cpp +++ b/common/rdm/GroupSizeCalculatorTest.cpp @@ -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; @@ -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( @@ -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)); } diff --git a/common/rdm/MessageDeserializer.cpp b/common/rdm/MessageDeserializer.cpp index 28480da6e5..a3e6ec3360 100644 --- a/common/rdm/MessageDeserializer.cpp +++ b/common/rdm/MessageDeserializer.cpp @@ -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++])); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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 fields; @@ -298,7 +311,7 @@ void MessageDeserializer::IntVisit( } m_message_stack.top().push_back( - new ola::messaging::BasicMessageField(descriptor, value)); + new ola::messaging::BasicMessageField(descriptor, value)); } } // namespace rdm } // namespace ola diff --git a/common/rdm/MessageDeserializerTest.cpp b/common/rdm/MessageDeserializerTest.cpp index b1660e5178..d674b2c2f8 100644 --- a/common/rdm/MessageDeserializerTest.cpp +++ b/common/rdm/MessageDeserializerTest.cpp @@ -34,7 +34,6 @@ using ola::messaging::BoolFieldDescriptor; -using ola::messaging::IPV4FieldDescriptor; using ola::messaging::Descriptor; using ola::messaging::FieldDescriptor; using ola::messaging::FieldDescriptorGroup; @@ -42,6 +41,7 @@ using ola::messaging::Int16FieldDescriptor; using ola::messaging::Int32FieldDescriptor; using ola::messaging::Int8FieldDescriptor; using ola::messaging::IPV4FieldDescriptor; +using ola::messaging::IPV6FieldDescriptor; using ola::messaging::MACFieldDescriptor; using ola::messaging::Message; using ola::messaging::GenericMessagePrinter; @@ -62,6 +62,7 @@ class MessageDeserializerTest: public CppUnit::TestFixture { CPPUNIT_TEST(testSimpleBigEndian); CPPUNIT_TEST(testSimpleLittleEndian); CPPUNIT_TEST(testIPV4); + CPPUNIT_TEST(testIPV6); CPPUNIT_TEST(testMAC); CPPUNIT_TEST(testString); CPPUNIT_TEST(testUID); @@ -75,6 +76,7 @@ class MessageDeserializerTest: public CppUnit::TestFixture { void testSimpleBigEndian(); void testSimpleLittleEndian(); void testIPV4(); + void testIPV6(); void testMAC(); void testString(); void testUID(); @@ -246,6 +248,32 @@ void MessageDeserializerTest::testIPV4() { } +/** + * Test IPV6 inflation. + */ +void MessageDeserializerTest::testIPV6() { + // build the descriptor + vector fields; + fields.push_back(new IPV6FieldDescriptor("Addressv6")); + Descriptor descriptor("Test Descriptor", fields); + + // now setup the data + const uint8_t big_endian_data[] = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 255, 255, 10, 0, 0, 1}; + + // now the correct amount & verify + auto_ptr message(m_deserializer.InflateMessage( + &descriptor, + big_endian_data, + sizeof(big_endian_data))); + OLA_ASSERT_NOT_NULL(message.get()); + OLA_ASSERT_EQ(1u, message->FieldCount()); + + const string expected = "Addressv6: ::ffff:10.0.0.1\n"; + OLA_ASSERT_EQ(expected, m_printer.AsString(message.get())); +} + + /** * Test MAC inflation. */ diff --git a/common/rdm/MessageSerializer.cpp b/common/rdm/MessageSerializer.cpp index 8fe5198d2f..8181157642 100644 --- a/common/rdm/MessageSerializer.cpp +++ b/common/rdm/MessageSerializer.cpp @@ -77,6 +77,15 @@ void MessageSerializer::Visit( } +void MessageSerializer::Visit( + const ola::messaging::IPV6MessageField *message) { + unsigned int size = message->GetDescriptor()->MaxSize(); + CheckForFreeSpace(size); + message->Value().Pack(m_data + m_offset, size); + m_offset += size; +} + + void MessageSerializer::Visit( const ola::messaging::MACMessageField *message) { unsigned int size = message->GetDescriptor()->MaxSize(); diff --git a/common/rdm/MessageSerializerTest.cpp b/common/rdm/MessageSerializerTest.cpp index 9d6163fa7d..2eca076471 100644 --- a/common/rdm/MessageSerializerTest.cpp +++ b/common/rdm/MessageSerializerTest.cpp @@ -41,6 +41,7 @@ using ola::messaging::Int16FieldDescriptor; using ola::messaging::Int32FieldDescriptor; using ola::messaging::Int8FieldDescriptor; using ola::messaging::IPV4FieldDescriptor; +using ola::messaging::IPV6FieldDescriptor; using ola::messaging::MACFieldDescriptor; using ola::messaging::Message; using ola::messaging::StringFieldDescriptor; @@ -111,6 +112,7 @@ void MessageSerializerTest::testSimple() { fields.push_back(new UInt32FieldDescriptor("uint32")); fields.push_back(new Int32FieldDescriptor("int32")); fields.push_back(new IPV4FieldDescriptor("ip")); + fields.push_back(new IPV6FieldDescriptor("ipv6")); fields.push_back(new MACFieldDescriptor("mac")); fields.push_back(new StringFieldDescriptor("string", 0, 32)); Descriptor descriptor("Test Descriptor", fields); @@ -125,6 +127,7 @@ void MessageSerializerTest::testSimple() { inputs.push_back("66000"); inputs.push_back("-66000"); inputs.push_back("10.0.0.1"); + inputs.push_back("::ffff:192.168.0.1"); inputs.push_back("01:23:45:67:89:ab"); inputs.push_back("foo"); @@ -137,12 +140,13 @@ void MessageSerializerTest::testSimple() { const uint8_t *data = serializer.SerializeMessage(message.get(), &packed_length); OLA_ASSERT_NOT_NULL(data); - OLA_ASSERT_EQ(28u, packed_length); + OLA_ASSERT_EQ(44u, packed_length); uint8_t expected[] = { 1, 1, 253, 1, 44, 254, 112, 0, 1, 1, 208, 255, 254, 254, 48, 10, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 168, 0, 1, 1, 35, 69, 103, 137, 171, 'f', 'o', 'o'}; diff --git a/common/rdm/PidStoreLoader.cpp b/common/rdm/PidStoreLoader.cpp index 70665f2852..adf5594e6b 100644 --- a/common/rdm/PidStoreLoader.cpp +++ b/common/rdm/PidStoreLoader.cpp @@ -478,6 +478,9 @@ const FieldDescriptor *PidStoreLoader::FieldToFieldDescriptor( case ola::rdm::pid::UID: descriptor = new ola::messaging::UIDFieldDescriptor(field.name()); break; + case ola::rdm::pid::IPV6: + descriptor = new ola::messaging::IPV6FieldDescriptor(field.name()); + break; default: OLA_WARN << "Unknown field type: " << field.type(); } diff --git a/common/rdm/Pids.proto b/common/rdm/Pids.proto index 841e1d7931..19010f7ad8 100644 --- a/common/rdm/Pids.proto +++ b/common/rdm/Pids.proto @@ -42,6 +42,7 @@ enum FieldType { IPV4 = 10; UID = 11; MAC = 12; + IPV6 = 13; } // A value which has a label applied diff --git a/common/rdm/StringMessageBuilder.cpp b/common/rdm/StringMessageBuilder.cpp index 63840d3198..da6fad314e 100644 --- a/common/rdm/StringMessageBuilder.cpp +++ b/common/rdm/StringMessageBuilder.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -127,8 +128,9 @@ const ola::messaging::Message *StringMessageBuilder::GetMessage( */ void StringMessageBuilder::Visit( const ola::messaging::BoolFieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } bool value = false; bool valid = false; @@ -170,8 +172,9 @@ void StringMessageBuilder::Visit( */ void StringMessageBuilder::Visit( const ola::messaging::IPV4FieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } string token = m_inputs[m_offset++]; ola::network::IPV4Address ip_address; @@ -185,13 +188,35 @@ void StringMessageBuilder::Visit( } +/** + * IPV6 Addresses + */ +void StringMessageBuilder::Visit( + const ola::messaging::IPV6FieldDescriptor *descriptor) { + if (StopParsing()) { + return; + } + + string token = m_inputs[m_offset++]; + ola::network::IPV6Address ipv6_address; + if (!ola::network::IPV6Address::FromString(token, &ipv6_address)) { + SetError(descriptor->Name()); + return; + } + + m_groups.top().push_back( + new ola::messaging::IPV6MessageField(descriptor, ipv6_address)); +} + + /** * MAC Addresses */ void StringMessageBuilder::Visit( const ola::messaging::MACFieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } string token = m_inputs[m_offset++]; ola::network::MACAddress mac_address; @@ -210,8 +235,9 @@ void StringMessageBuilder::Visit( */ void StringMessageBuilder::Visit( const ola::messaging::UIDFieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } string token = m_inputs[m_offset++]; auto_ptr uid(UID::FromString(token)); @@ -231,8 +257,9 @@ void StringMessageBuilder::Visit( */ void StringMessageBuilder::Visit( const ola::messaging::StringFieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } const string &token = m_inputs[m_offset++]; if (descriptor->MaxSize() != 0 && @@ -335,8 +362,9 @@ void StringMessageBuilder::SetError(const string &error) { template void StringMessageBuilder::VisitInt( const ola::messaging::IntegerFieldDescriptor *descriptor) { - if (StopParsing()) + if (StopParsing()) { return; + } type int_value; string input = m_inputs[m_offset++]; diff --git a/common/rdm/StringMessageBuilderTest.cpp b/common/rdm/StringMessageBuilderTest.cpp index de09265147..6ee21f16e8 100644 --- a/common/rdm/StringMessageBuilderTest.cpp +++ b/common/rdm/StringMessageBuilderTest.cpp @@ -38,6 +38,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; @@ -136,6 +137,7 @@ void StringBuilderTest::testSimpleBuilder() { fields.push_back(new BoolFieldDescriptor("bool5")); fields.push_back(new BoolFieldDescriptor("bool6")); fields.push_back(new IPV4FieldDescriptor("ip1")); + fields.push_back(new IPV6FieldDescriptor("ipv61")); fields.push_back(new MACFieldDescriptor("mac1")); fields.push_back(new UInt8FieldDescriptor("uint8")); fields.push_back(new UInt16FieldDescriptor("uint16")); @@ -156,6 +158,7 @@ void StringBuilderTest::testSimpleBuilder() { inputs.push_back("TRUE"); inputs.push_back("FALSE"); inputs.push_back("10.0.0.1"); + inputs.push_back("::ffff:192.168.0.1"); inputs.push_back("01:23:45:67:89:ab"); inputs.push_back("255"); inputs.push_back("300"); @@ -171,13 +174,14 @@ void StringBuilderTest::testSimpleBuilder() { // verify OLA_ASSERT_TRUE(message.get()); OLA_ASSERT_EQ(static_cast(fields.size()), - message->FieldCount()); + message->FieldCount()); string expected = ( "bool1: true\nbool2: false\nbool3: true\nbool4: false\nbool5: true\n" - "bool6: false\nip1: 10.0.0.1\nmac1: 01:23:45:67:89:ab\nuint8: 255\n" - "uint16: 300\nuint32: 66000\nint8: -128\nint16: -300\nint32: -66000\n" - "string: foo\nhex uint16: 1024\n"); + "bool6: false\nip1: 10.0.0.1\nipv61: ::ffff:192.168.0.1\n" + "mac1: 01:23:45:67:89:ab\nuint8: 255\nuint16: 300\nuint32: 66000\n" + "int8: -128\nint16: -300\nint32: -66000\nstring: foo\n" + "hex uint16: 1024\n"); OLA_ASSERT_EQ(expected, m_printer.AsString(message.get())); } diff --git a/common/rdm/VariableFieldSizeCalculator.cpp b/common/rdm/VariableFieldSizeCalculator.cpp index b054a38589..4ef46ba2d0 100644 --- a/common/rdm/VariableFieldSizeCalculator.cpp +++ b/common/rdm/VariableFieldSizeCalculator.cpp @@ -124,6 +124,12 @@ void VariableFieldSizeCalculator::Visit( } +void VariableFieldSizeCalculator::Visit( + const ola::messaging::IPV6FieldDescriptor *descriptor) { + m_fixed_size_sum += descriptor->MaxSize(); +} + + void VariableFieldSizeCalculator::Visit( const ola::messaging::MACFieldDescriptor *descriptor) { m_fixed_size_sum += descriptor->MaxSize(); diff --git a/common/rdm/VariableFieldSizeCalculator.h b/common/rdm/VariableFieldSizeCalculator.h index d6208b323c..4e224b0afa 100644 --- a/common/rdm/VariableFieldSizeCalculator.h +++ b/common/rdm/VariableFieldSizeCalculator.h @@ -63,6 +63,7 @@ class VariableFieldSizeCalculator 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*); diff --git a/data/rdm/pids.proto b/data/rdm/pids.proto index cebb8ef20e..50548ae6a0 100644 --- a/data/rdm/pids.proto +++ b/data/rdm/pids.proto @@ -4010,6 +4010,144 @@ pid { } set_sub_device_range: ROOT_OR_ALL_SUBDEVICE } +pid { + name: "COMPONENT_SCOPE" + value: 2048 + get_request { + field { + type: UINT16 + name: "scope_slot" + range { + min: 1 + max: 65535 + } + } + } + get_response { + field { + type: UINT16 + name: "scope_slot" + range { + min: 1 + max: 65535 + } + } + field { + type: STRING + name: "scope_string" + min_size: 63 + max_size: 63 + } + field { + type: UINT8 + name: "static_config_type" + label { + value: 0 + label: "No static config" + } + label { + value: 1 + label: "Static config IPv4" + } + label { + value: 1 + label: "Static config IPv6" + } + range { + min: 0 + max: 2 + } + } + field { + type: IPV4 + name: "static_broker_ipv4_address" + label { + value: 0 + label: "No static broker IPv4 address" + } + } + field { + type: IPV6 + name: "static_broker_ipv6_address" + label { + value: 0 + label: "No static broker IPv6 address" + } + } + field { + type: UINT16 + name: "static_broker_port" + label { + value: 0 + label: "No static broker port" + } + } + } + get_sub_device_range: ROOT_DEVICE + set_request { + field { + type: UINT16 + name: "scope_slot" + range { + min: 1 + max: 65535 + } + } + field { + type: STRING + name: "scope_string" + min_size: 63 + max_size: 63 + } + field { + type: UINT8 + name: "static_config_type" + label { + value: 0 + label: "No static config" + } + label { + value: 1 + label: "Static config IPv4" + } + label { + value: 1 + label: "Static config IPv6" + } + range { + min: 0 + max: 2 + } + } + field { + type: IPV4 + name: "static_broker_ipv4_address" + label { + value: 0 + label: "No static broker IPv4 address" + } + } + field { + type: IPV6 + name: "static_broker_ipv6_address" + label { + value: 0 + label: "No static broker IPv6 address" + } + } + field { + type: UINT16 + name: "static_broker_port" + label { + value: 0 + label: "No static broker port" + } + } + } + set_response { + } + set_sub_device_range: ROOT_DEVICE +} pid { name: "SEARCH_DOMAIN" value: 2049 @@ -4036,6 +4174,60 @@ pid { } set_sub_device_range: ROOT_DEVICE } +pid { + name: "TCP_COMMS_STATUS" + value: 2050 + get_request { + } + get_response { + field { + type: GROUP + name: "comms_statuses" + field { + type: STRING + name: "scope_string" + min_size: 63 + max_size: 63 + } + field { + type: IPV4 + name: "broker_ipv4_address" + label { + value: 0 + label: "No IPv4 Connection" + } + } + field { + type: IPV6 + name: "broker_ipv6_address" + label { + value: 0 + label: "No IPv6 Connection" + } + } + field { + type: UINT16 + name: "broker_port" + } + field { + type: UINT16 + name: "unhealthy_tcp_events" + } + } + } + get_sub_device_range: ROOT_DEVICE + set_request { + field { + type: STRING + name: "scope_string" + min_size: 63 + max_size: 63 + } + } + set_response { + } + set_sub_device_range: ROOT_DEVICE +} pid { name: "BROKER_STATUS" value: 2051 diff --git a/include/ola/messaging/Descriptor.h b/include/ola/messaging/Descriptor.h index 3f287141ea..f997a9a00d 100644 --- a/include/ola/messaging/Descriptor.h +++ b/include/ola/messaging/Descriptor.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -116,6 +117,25 @@ class IPV4FieldDescriptor: public FieldDescriptor { }; +/** + * A FieldDescriptor that represents a IPv6 Address + */ +class IPV6FieldDescriptor: public FieldDescriptor { + public: + explicit IPV6FieldDescriptor(const std::string &name) + : FieldDescriptor(name) { + } + + bool FixedSize() const { return true; } + bool LimitedSize() const { return true; } + unsigned int MaxSize() const { return ola::network::IPV6Address::LENGTH; } + + void Accept(FieldDescriptorVisitor *visitor) const { + visitor->Visit(this); + } +}; + + /** * A FieldDescriptor that represents a MAC Address */ diff --git a/include/ola/messaging/DescriptorVisitor.h b/include/ola/messaging/DescriptorVisitor.h index 43a64f572a..5b5820d588 100644 --- a/include/ola/messaging/DescriptorVisitor.h +++ b/include/ola/messaging/DescriptorVisitor.h @@ -30,6 +30,7 @@ namespace messaging { class BoolFieldDescriptor; class FieldDescriptorGroup; class IPV4FieldDescriptor; +class IPV6FieldDescriptor; class MACFieldDescriptor; class StringFieldDescriptor; class UIDFieldDescriptor; @@ -49,6 +50,7 @@ class FieldDescriptorVisitor { virtual void Visit(const BoolFieldDescriptor*) = 0; virtual void Visit(const IPV4FieldDescriptor*) = 0; + virtual void Visit(const IPV6FieldDescriptor*) = 0; virtual void Visit(const MACFieldDescriptor*) = 0; virtual void Visit(const UIDFieldDescriptor*) = 0; virtual void Visit(const StringFieldDescriptor*) = 0; diff --git a/include/ola/messaging/Message.h b/include/ola/messaging/Message.h index b8062f57c1..ecc56bd2a2 100644 --- a/include/ola/messaging/Message.h +++ b/include/ola/messaging/Message.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,32 @@ class IPV4MessageField: public MessageFieldInterface { }; +/** + * A MessageField that represents a IPv6 Address + */ +class IPV6MessageField: public MessageFieldInterface { + public: + IPV6MessageField(const IPV6FieldDescriptor *descriptor, + const ola::network::IPV6Address &value) + : m_descriptor(descriptor), + m_value(value) { + } + + const IPV6FieldDescriptor *GetDescriptor() const { + return m_descriptor; + } + const ola::network::IPV6Address& Value() const { return m_value; } + + void Accept(MessageVisitor *visitor) const { + visitor->Visit(this); + } + + private: + const IPV6FieldDescriptor *m_descriptor; + ola::network::IPV6Address m_value; +}; + + /** * A MessageField that represents a MAC Address */ diff --git a/include/ola/messaging/MessagePrinter.h b/include/ola/messaging/MessagePrinter.h index 0053d16618..2f2f363664 100644 --- a/include/ola/messaging/MessagePrinter.h +++ b/include/ola/messaging/MessagePrinter.h @@ -40,6 +40,7 @@ class MessagePrinter: public MessageVisitor { virtual void Visit(const BoolMessageField*) {} virtual void Visit(const IPV4MessageField*) {} + virtual void Visit(const IPV6MessageField*) {} virtual void Visit(const MACMessageField*) {} virtual void Visit(const UIDMessageField*) {} virtual void Visit(const StringMessageField*) {} @@ -78,6 +79,7 @@ class GenericMessagePrinter: public MessagePrinter { virtual void Visit(const BoolMessageField*); virtual void Visit(const IPV4MessageField*); + virtual void Visit(const IPV6MessageField*); virtual void Visit(const MACMessageField*); virtual void Visit(const UIDMessageField*); virtual void Visit(const StringMessageField*); diff --git a/include/ola/messaging/MessageVisitor.h b/include/ola/messaging/MessageVisitor.h index 00812f8e56..81b55ed965 100644 --- a/include/ola/messaging/MessageVisitor.h +++ b/include/ola/messaging/MessageVisitor.h @@ -30,6 +30,7 @@ namespace messaging { class BoolMessageField; class GroupMessageField; class IPV4MessageField; +class IPV6MessageField; class MACMessageField; class StringMessageField; class UIDMessageField; @@ -46,6 +47,7 @@ class MessageVisitor { virtual void Visit(const BoolMessageField*) = 0; virtual void Visit(const IPV4MessageField*) = 0; + virtual void Visit(const IPV6MessageField*) = 0; virtual void Visit(const MACMessageField*) = 0; virtual void Visit(const UIDMessageField*) = 0; virtual void Visit(const StringMessageField*) = 0; diff --git a/include/ola/messaging/SchemaPrinter.h b/include/ola/messaging/SchemaPrinter.h index 21feb46090..95aa7c9e6b 100644 --- a/include/ola/messaging/SchemaPrinter.h +++ b/include/ola/messaging/SchemaPrinter.h @@ -50,6 +50,7 @@ class SchemaPrinter: public FieldDescriptorVisitor { void Visit(const BoolFieldDescriptor*); void Visit(const IPV4FieldDescriptor*); + void Visit(const IPV6FieldDescriptor*); void Visit(const MACFieldDescriptor*); void Visit(const UIDFieldDescriptor*); void Visit(const StringFieldDescriptor*); diff --git a/include/ola/messaging/StringMessageBuilder.h b/include/ola/messaging/StringMessageBuilder.h index 4bb9011c4b..12b7273fd3 100644 --- a/include/ola/messaging/StringMessageBuilder.h +++ b/include/ola/messaging/StringMessageBuilder.h @@ -42,6 +42,7 @@ class StringMessageBuilder: public FieldDescriptorVisitor { void Visit(const BoolFieldDescriptor*); void Visit(const IPV4FieldDescriptor*); + void Visit(const IPV6FieldDescriptor*); void Visit(const MACFieldDescriptor*); void Visit(const UIDFieldDescriptor*); void Visit(const StringFieldDescriptor*); diff --git a/include/ola/rdm/MessageDeserializer.h b/include/ola/rdm/MessageDeserializer.h index 4d228125e2..5e320653af 100644 --- a/include/ola/rdm/MessageDeserializer.h +++ b/include/ola/rdm/MessageDeserializer.h @@ -57,6 +57,7 @@ class MessageDeserializer: 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*); diff --git a/include/ola/rdm/MessageSerializer.h b/include/ola/rdm/MessageSerializer.h index 821f2097ea..cf6f51f86e 100644 --- a/include/ola/rdm/MessageSerializer.h +++ b/include/ola/rdm/MessageSerializer.h @@ -48,6 +48,7 @@ class MessageSerializer: public ola::messaging::MessageVisitor { void Visit(const ola::messaging::BoolMessageField*); void Visit(const ola::messaging::IPV4MessageField*); + void Visit(const ola::messaging::IPV6MessageField*); void Visit(const ola::messaging::MACMessageField*); void Visit(const ola::messaging::UIDMessageField*); void Visit(const ola::messaging::StringMessageField*); diff --git a/include/ola/rdm/StringMessageBuilder.h b/include/ola/rdm/StringMessageBuilder.h index f66187e682..ed2bfbdc49 100644 --- a/include/ola/rdm/StringMessageBuilder.h +++ b/include/ola/rdm/StringMessageBuilder.h @@ -62,6 +62,7 @@ class StringMessageBuilder: 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*); diff --git a/python/ola/PidStore.py b/python/ola/PidStore.py index 38fb200562..f48db9656b 100644 --- a/python/ola/PidStore.py +++ b/python/ola/PidStore.py @@ -549,6 +549,29 @@ def Pack(self, args): return super(IntAtom, self).Pack(value) +class IPV6Atom(FixedSizeAtom): + """A sixteen-byte IPV6 address.""" + def __init__(self, name, **kwargs): + super(IPV6Atom, self).__init__(name, 'BBBBBBBBBBBBBBBB') + + def Unpack(self, data): + try: + return socket.inet_ntop(socket.AF_INET6, data) + except socket.error as e: + raise ArgsValidationError("Can't unpack data: %s" % e) + + def Pack(self, args): + # TODO(Peter): This currently allows some rather quirky values as per + # inet_pton, we may want to restrict that in future + format_string = self._FormatString() + try: + data = struct.pack(format_string, + socket.inet_pton(socket.AF_INET6, args[0])) + except socket.error as e: + raise ArgsValidationError("Can't pack data: %s" % e) + return data, 1 + + class MACAtom(FixedSizeAtom): """A MAC address.""" def __init__(self, name, **kwargs): @@ -1271,6 +1294,8 @@ def _FieldToAtom(self, field): return UInt32(field_name, **args) elif field.type == Pids_pb2.IPV4: return IPV4(field_name, **args) + elif field.type == Pids_pb2.IPV6: + return IPV6Atom(field_name, **args) elif field.type == Pids_pb2.MAC: return MACAtom(field_name, **args) elif field.type == Pids_pb2.UID: diff --git a/python/ola/PidStoreTest.py b/python/ola/PidStoreTest.py index 600f1dd389..e09226f1fd 100755 --- a/python/ola/PidStoreTest.py +++ b/python/ola/PidStoreTest.py @@ -174,6 +174,8 @@ def testCmp(self): g1getreq = PidStore.Group("grg", [PidStore.UInt16("ui16"), PidStore.Int32("i32")]) g1setreq = PidStore.Group("srg", [PidStore.MACAtom("mac"), + PidStore.IPV4("ipv4"), + PidStore.IPV6Atom("ipv6"), PidStore.Int8("i32")]) p1b = PidStore.Pid("base", 42, None, None, g1getreq, g1setreq)