/* * Check that the header set works */ void HeaderSetTest::testHeaderSet() { HeaderSet headers; RootHeader root_header; E131Header e131_header("e131", 1, 2, 6001); E133Header e133_header("foo", 1, 2050); DMPHeader dmp_header(false, false, NON_RANGE, ONE_BYTES); // test the root header component CID cid = CID::Generate(); root_header.SetCid(cid); headers.SetRootHeader(root_header); OLA_ASSERT(root_header == headers.GetRootHeader()); // test the E1.31 header component headers.SetE131Header(e131_header); OLA_ASSERT(e131_header == headers.GetE131Header()); // test the E1.33 header component headers.SetE133Header(e133_header); OLA_ASSERT(e133_header == headers.GetE133Header()); // test the DMP headers component headers.SetDMPHeader(dmp_header); OLA_ASSERT(dmp_header == headers.GetDMPHeader()); // test assign HeaderSet headers2 = headers; OLA_ASSERT(root_header == headers2.GetRootHeader()); OLA_ASSERT(e131_header == headers2.GetE131Header()); OLA_ASSERT(e133_header == headers2.GetE133Header()); OLA_ASSERT(dmp_header == headers2.GetDMPHeader()); OLA_ASSERT(headers2 == headers); // test copy HeaderSet headers3(headers); OLA_ASSERT(root_header == headers3.GetRootHeader()); OLA_ASSERT(e131_header == headers3.GetE131Header()); OLA_ASSERT(e133_header == headers3.GetE133Header()); OLA_ASSERT(dmp_header == headers3.GetDMPHeader()); OLA_ASSERT(headers3 == headers); }
/* * Verify a PDU is what we expected */ bool MockDMPInflator::HandlePDUData(uint32_t vector, HeaderSet &headers, const uint8_t *data, unsigned int pdu_len) { DMPHeader header = headers.GetDMPHeader(); CPPUNIT_ASSERT_EQUAL(expected_vector, vector); CPPUNIT_ASSERT_EQUAL(expected_virtual, header.IsVirtual()); CPPUNIT_ASSERT_EQUAL(expected_relative, header.IsRelative()); CPPUNIT_ASSERT(expected_type == header.Type()); CPPUNIT_ASSERT(expected_size == header.Size()); if (vector == DMP_GET_PROPERTY_VECTOR || vector == DMP_SET_PROPERTY_VECTOR) { unsigned int length = pdu_len; const BaseDMPAddress *addr = DecodeAddress(header.Size(), header.Type(), data, length); CPPUNIT_ASSERT(addr); CPPUNIT_ASSERT_EQUAL(expected_start, addr->Start()); CPPUNIT_ASSERT_EQUAL(expected_increment, addr->Increment()); CPPUNIT_ASSERT_EQUAL(expected_number, addr->Number()); delete addr; } return true; }
/* * Handle a DMP PDU for E1.31. */ bool DMPE131Inflator::HandlePDUData(uint32_t vector, const HeaderSet &headers, const uint8_t *data, unsigned int pdu_len) { if (vector != ola::acn::DMP_SET_PROPERTY_VECTOR) { OLA_INFO << "not a set property msg: " << vector; return true; } E131Header e131_header = headers.GetE131Header(); UniverseHandlers::iterator universe_iter = m_handlers.find(e131_header.Universe()); if (e131_header.PreviewData() && m_ignore_preview) { OLA_DEBUG << "Ignoring preview data"; return true; } if (universe_iter == m_handlers.end()) return true; DMPHeader dmp_header = headers.GetDMPHeader(); if (!dmp_header.IsVirtual() || dmp_header.IsRelative() || dmp_header.Size() != TWO_BYTES || dmp_header.Type() != RANGE_EQUAL) { OLA_INFO << "malformed E1.31 dmp header " << dmp_header.Header(); return true; } if (e131_header.Priority() > MAX_PRIORITY) { OLA_INFO << "Priority " << static_cast<int>(e131_header.Priority()) << " is greater than the max priority (" << static_cast<int>(MAX_PRIORITY) << "), ignoring data"; return true; } unsigned int available_length = pdu_len; std::auto_ptr<const BaseDMPAddress> address( DecodeAddress(dmp_header.Size(), dmp_header.Type(), data, &available_length)); if (!address.get()) { OLA_INFO << "DMP address parsing failed, the length is probably too small"; return true; } if (address->Increment() != 1) { OLA_INFO << "E1.31 DMP packet with increment " << address->Increment() << ", disarding"; return true; } unsigned int length_remaining = pdu_len - available_length; int start_code = -1; if (e131_header.UsingRev2()) start_code = static_cast<int>(address->Start()); else if (length_remaining && address->Number()) start_code = *(data + available_length); // The only time we want to continue processing a non-0 start code is if it // contains a Terminate message. if (start_code && !e131_header.StreamTerminated()) { OLA_INFO << "Skipping packet with non-0 start code: " << start_code; return true; } DmxBuffer *target_buffer; if (!TrackSourceIfRequired(&universe_iter->second, headers, &target_buffer)) { // no need to continue processing return true; } // Reaching here means that we actually have new data and we should merge. if (target_buffer && start_code == 0) { unsigned int channels = std::min(length_remaining, address->Number()); if (e131_header.UsingRev2()) target_buffer->Set(data + available_length, channels); else target_buffer->Set(data + available_length + 1, channels - 1); } if (universe_iter->second.priority) *universe_iter->second.priority = universe_iter->second.active_priority; // merge the sources switch (universe_iter->second.sources.size()) { case 0: universe_iter->second.buffer->Reset(); break; case 1: universe_iter->second.buffer->Set( universe_iter->second.sources[0].buffer); universe_iter->second.closure->Run(); break; default: // HTP Merge universe_iter->second.buffer->Reset(); std::vector<dmx_source>::const_iterator source_iter = universe_iter->second.sources.begin(); for (; source_iter != universe_iter->second.sources.end(); ++source_iter) universe_iter->second.buffer->HTPMerge(source_iter->buffer); universe_iter->second.closure->Run(); } return true; }