2014-11-03 15:27:08 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2014 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2014-11-03 15:27:08 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2014-11-03 15:27:08 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhd/transport/chdr.hpp>
|
|
|
|
|
#include <uhd/utils/byteswap.hpp>
|
|
|
|
|
#include <boost/format.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2014-11-03 15:27:08 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using namespace uhd::transport::vrt;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
static void pack_and_unpack(if_packet_info_t& if_packet_info_in)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
// Temp buffer for packed packet
|
2016-10-31 21:30:52 +00:00
|
|
|
uint32_t packet_buff[2048] = {0};
|
2014-11-03 15:27:08 +00:00
|
|
|
|
|
|
|
|
// Check input (must not be lazy)
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_REQUIRE((if_packet_info_in.num_payload_words32 == 0
|
|
|
|
|
and if_packet_info_in.num_payload_bytes == 0)
|
|
|
|
|
or (if_packet_info_in.num_payload_words32 != 0
|
|
|
|
|
and if_packet_info_in.num_payload_bytes != 0));
|
2014-11-03 15:27:08 +00:00
|
|
|
if (if_packet_info_in.num_payload_words32) {
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_REQUIRE(if_packet_info_in.num_payload_bytes
|
|
|
|
|
<= 4 * if_packet_info_in.num_payload_words32);
|
|
|
|
|
BOOST_REQUIRE(if_packet_info_in.num_payload_bytes
|
|
|
|
|
> 4 * (if_packet_info_in.num_payload_words32 - 1));
|
2014-11-03 15:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// pack metadata into a vrt header
|
|
|
|
|
chdr::if_hdr_pack_be(packet_buff, if_packet_info_in);
|
2014-11-03 15:27:08 +00:00
|
|
|
std::cout << std::endl;
|
2016-10-31 21:30:52 +00:00
|
|
|
uint32_t header_bits = (uhd::ntohx(packet_buff[0]) >> 28);
|
2015-03-27 17:55:48 +00:00
|
|
|
std::cout << boost::format("header bits = 0b%d%d%d%d") % ((header_bits & 8) > 0)
|
2019-01-14 18:35:25 +00:00
|
|
|
% ((header_bits & 4) > 0) % ((header_bits & 2) > 0)
|
|
|
|
|
% ((header_bits & 1) > 0)
|
|
|
|
|
<< std::endl;
|
|
|
|
|
for (size_t i = 0; i < 5; i++) {
|
|
|
|
|
std::cout << boost::format("packet_buff[%u] = 0x%08x") % i
|
|
|
|
|
% uhd::ntohx(packet_buff[i])
|
|
|
|
|
<< std::endl;
|
2014-11-03 15:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if_packet_info_t if_packet_info_out;
|
|
|
|
|
// Must be set a-priori as per contract
|
|
|
|
|
if_packet_info_out.num_packet_words32 = if_packet_info_in.num_packet_words32;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// unpack the vrt header back into metadata
|
|
|
|
|
chdr::if_hdr_unpack_be(packet_buff, if_packet_info_out);
|
2014-11-03 15:27:08 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// check the the unpacked metadata is the same
|
2014-11-03 15:27:08 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.packet_count, if_packet_info_out.packet_count);
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_CHECK_EQUAL(
|
|
|
|
|
if_packet_info_in.num_header_words32, if_packet_info_out.num_header_words32);
|
|
|
|
|
BOOST_CHECK_EQUAL(
|
|
|
|
|
if_packet_info_in.num_payload_words32, if_packet_info_out.num_payload_words32);
|
2014-11-03 15:27:08 +00:00
|
|
|
BOOST_CHECK(if_packet_info_out.has_sid);
|
|
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.sid, if_packet_info_out.sid);
|
|
|
|
|
BOOST_CHECK(if_packet_info_out.has_sid);
|
|
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.has_tsf, if_packet_info_out.has_tsf);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (if_packet_info_in.has_tsf and if_packet_info_out.has_tsf) {
|
2014-11-03 15:27:08 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.tsf, if_packet_info_out.tsf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_DATA;
|
|
|
|
|
if_packet_info.eob = false;
|
|
|
|
|
if_packet_info.packet_count = 7;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.tsf = 0x1234567890ABCDEFull;
|
|
|
|
|
if_packet_info.sid = 0xAABBCCDD;
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info.num_payload_words32 = 24;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.num_payload_bytes = 95;
|
2014-11-03 15:27:08 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr_fc)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_FC;
|
|
|
|
|
if_packet_info.eob = false;
|
|
|
|
|
if_packet_info.packet_count = 19;
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.tsf = 0x1234567890ABCDEFull;
|
|
|
|
|
if_packet_info.sid = 0xAABBCCDD;
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info.num_payload_words32 = 4;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.num_payload_bytes = 16;
|
2014-11-03 15:27:08 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr_cmd)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_CMD;
|
|
|
|
|
if_packet_info.packet_count = 19;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.tsf = 0x1234567890ABCDEFull;
|
|
|
|
|
if_packet_info.sid = 0xAABBCCDD;
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info.num_payload_words32 = 4;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.num_payload_bytes = 16;
|
2014-11-03 15:27:08 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr_resp)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_RESP;
|
|
|
|
|
if_packet_info.packet_count = 123;
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.tsf = 0x1234567890ABCDEFull;
|
|
|
|
|
if_packet_info.sid = 0xAABBCCDD;
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info.num_payload_words32 = 4;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.num_payload_bytes = 16;
|
2014-11-03 15:27:08 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr_err)
|
|
|
|
|
{
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_ERROR;
|
|
|
|
|
if_packet_info.packet_count = 1928;
|
|
|
|
|
if_packet_info.eob = false;
|
|
|
|
|
if_packet_info.error = false; // Needs to be set explicitly
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.tsf = 0x1234567890ABCDEFull;
|
|
|
|
|
if_packet_info.sid = 0xAABBCCDD;
|
2014-11-03 15:27:08 +00:00
|
|
|
if_packet_info.num_payload_words32 = 4;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.num_payload_bytes = 16;
|
2014-11-03 15:27:08 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|