1
0
Fork 0

transport EPI owns the root block

This commit is contained in:
Kevin Matz 2021-08-13 17:19:16 -04:00
parent 0c96f9a69c
commit 13cba79652
5 changed files with 87 additions and 77 deletions

View File

@ -58,28 +58,13 @@ Appliance::Appliance(UUID::uuid cid)
*/
void Appliance::UdpPayloadReceiver(PDU::Stream stream)
{
// read the EPI 17 UDP preamble
RLP::UDP::preamble_t preamble;
preamble.iStream(stream);
auto transport = RLP::UDP::transport();
transport.iStream(stream);
// Implementations shall check the ACN Packet Identifier and preamble size.
if (!preamble)
stream->setstate(std::ios_base::failbit);
// Implementations shall compute the size and position of the PDU block from
// the preamble size and postamble size provided. ... ignoring any extra
// octets in the preamble or postamble.
for(int i = RLP::UDP::PREAMBLE_MINIMUM_SIZE; i < preamble.length; i++)
stream->readType<uint8_t>();
if (!stream->good())
return;
auto block = PDU::Block<RLP::Pdu>();
block.readBlock(stream);
if (stream->fail())
return;
for(auto const &root : *block.pdu) {
for(auto const &root : *transport.root.pdu) {
RlpReceiver(root);
}
}
@ -93,23 +78,15 @@ void Appliance::UdpPayloadReceiver(PDU::Stream stream)
*/
void Appliance::TcpPacketReceiver(PDU::Stream stream)
{
// verify the TCP preamble
RLP::TCP::preamble_t preamble(stream);
auto transport = RLP::TCP::transport();
transport.iStream(stream);
// implementations shall check the ACN Packet Identifier. If the ACN Packet
// Identifier is not correct the receiver shall close the connection.
if (!preamble)
stream->setstate(std::ios_base::failbit);
if (!stream->good())
return;
auto block = PDU::Block<RLP::Pdu>();
block.readBlock(stream);
if (stream->fail())
return;
for(auto const &root : *block.pdu)
for(auto const &root : *transport.root.pdu) {
RlpReceiver(root);
}
}

View File

@ -33,30 +33,43 @@ namespace TCP {
* @brief preamble_t::preamble_t
* @param stream
*/
preamble_t::preamble_t(PDU::Stream stream)
transport::transport(bool filled)
: PDU::pdu_stream_object()
{
if (!filled)
return;
memcpy(acn_id, ACN_PACKET_IDENTIFIER, sizeof(acn_id));
}
/**
* @brief transport::iStream
* @param stream
*/
void transport::iStream(PDU::Stream stream)
{
// 2. Preamble Format: The ACN Packet Identifier shall be the text string
// “ASC-E1.17\0\0\0” encoded in [ASCII].
stream->read(acn_id, sizeof(acn_id));
if (stream->gcount() != 12)
stream->setstate(std::ios_base::failbit);
if (memcmp(acn_id, ACN_PACKET_IDENTIFIER, 12)) {
stream->setstate(std::ios_base::failbit);
return;
}
length = stream->readType<decltype(length)>();
root.readBlock(stream);
}
/**
* @brief preamble_t::operator bool
* is preamble_t valid ACN EPI 33?
*
* Validate compliance with ACN EPI 33. ACN Root Layer Protocol Operation on
* TCP: 4.2. Reception
* @brief transport::oStream
*/
preamble_t::operator bool ()
void transport::oStream(PDU::Stream) const
{
// 2. Preamble Format: The ACN Packet Identifier shall be the text string
// “ASC-E1.17\0\0\0” encoded in [ASCII].
if (memcmp(acn_id, ACN_PACKET_IDENTIFIER, 12))
return false;
return true;
}

View File

@ -36,11 +36,20 @@ namespace TCP {
/**
* @brief 3. Frame Preamble Format
*/
struct preamble_t {
struct transport
: public PDU::pdu_stream_object
{
transport(bool filled = false);
uint8_t acn_id[12]; // 3.1 Packet Identifier
uint32_t length; // 3.2 PDU Block Size
preamble_t(PDU::Stream);
operator bool();
PDU::Block<RLP::Pdu> root;
size_t streamSize() const override { return sizeof(acn_id) + 4 +
root.streamSize(); }
void iStream(PDU::Stream) override;
void oStream(PDU::Stream) const override;
};

View File

@ -30,35 +30,18 @@ namespace RLP {
namespace UDP {
/**
* @brief preamble_t::fill
* @brief preamble::preamble
* @param filled
*/
void preamble_t::fill()
transport::transport(bool filled)
: PDU::pdu_stream_object()
{
length = sizeof(length) + sizeof(postamble_size) + sizeof(acn_id);
postamble_size = 0; //!< 3. The postamble field shall be empty.
memcpy(acn_id, ACN_PACKET_IDENTIFIER, sizeof(acn_id));
}
if (!filled)
return;
/**
* @brief preamble_t::operator bool
*
* Validate compliance with ACN EPI 17: ACN Root Layer Protocol
* on UDP: 4.2. Reception
*/
preamble_t::operator bool ()
{
// 2. Preamble Format: The preamble size includes both size fields so the
// minimum value for preamble size is 16 (octets).
if (length < PREAMBLE_MINIMUM_SIZE)
return false;
// 2. Preamble Format: The ACN Packet Identifier shall be the text string
// “ASC-E1.17\0\0\0” encoded in [ASCII].
if (memcmp(acn_id, ACN_PACKET_IDENTIFIER, 12)) // memcmp returns 0 if matched
return false;
return true;
length = sizeof(length) + sizeof(postamble_size) + sizeof(acn_id);
postamble_size = 0; //!< 3. The postamble field shall be empty.
memcpy(acn_id, ACN_PACKET_IDENTIFIER, sizeof(acn_id));
}
@ -66,13 +49,34 @@ preamble_t::operator bool ()
* @brief preamble_t::iStream
* @param stream
*/
void preamble_t::iStream(PDU::Stream stream)
void transport::iStream(PDU::Stream stream)
{
*stream >> length;
// 2. Preamble Format: The preamble size includes both size fields so the
// minimum value for preamble size is 16 (octets).
if (length < PREAMBLE_MINIMUM_SIZE) {
return;
}
*stream >> postamble_size;
// 2. Preamble Format: The ACN Packet Identifier shall be the text string
// “ASC-E1.17\0\0\0” encoded in [ASCII].
stream->read(acn_id, sizeof(acn_id));
if (stream->gcount() != sizeof(acn_id))
stream->setstate(std::ios_base::failbit);
if (memcmp(acn_id, ACN_PACKET_IDENTIFIER, 12) != 0) { // memcmp returns 0 if matched
stream->setstate(std::ios_base::failbit);
return;
}
// Implementations shall compute the size and position of the PDU block from
// the preamble size and postamble size provided. ... ignoring any extra
// octets in the preamble or postamble.
for(int i = PREAMBLE_MINIMUM_SIZE; i < length; i++)
stream->readType<uint8_t>();
root.readBlock(stream);
}
@ -80,11 +84,13 @@ void preamble_t::iStream(PDU::Stream stream)
* @brief preamble_t::oStream
* @param stream
*/
void preamble_t::oStream(PDU::Stream stream) const
void transport::oStream(PDU::Stream stream) const
{
*stream << length;
*stream << postamble_size;
stream->write(acn_id, sizeof(acn_id));
for ( auto& pdu : *root.pdu )
pdu->oStream(stream);
}
} // UDP

View File

@ -52,13 +52,18 @@ static const uint8_t PREAMBLE_MINIMUM_SIZE = 16;
/**
* @brief 2. Preamble Format
*/
struct preamble_t : public PDU::pdu_stream_object {
struct transport
: public PDU::pdu_stream_object {
transport(bool filled = false);
uint16_t length = 0;
uint16_t postamble_size = 0;
uint8_t acn_id[12];
void fill();
operator bool();
size_t streamSize() const override { return PREAMBLE_MINIMUM_SIZE; }
PDU::Block<RLP::Pdu> root;
size_t streamSize() const override { return PREAMBLE_MINIMUM_SIZE +
root.streamSize(); }
void iStream(PDU::Stream) override;
void oStream(PDU::Stream) const override;
};