2010-03-03 07:56:19 +00:00
|
|
|
//
|
2013-07-15 22:44:42 +00:00
|
|
|
// Copyright 2010-2013 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2010-03-03 07:56:19 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2010-03-03 07:56:19 +00:00
|
|
|
//
|
|
|
|
|
|
2010-07-01 00:44:47 +00:00
|
|
|
#include <uhd/transport/vrt_if_packet.hpp>
|
2013-07-15 22:44:42 +00:00
|
|
|
#include <uhd/utils/byteswap.hpp>
|
|
|
|
|
#include <boost/format.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2010-06-30 05:55:45 +00:00
|
|
|
#include <cstdlib>
|
2013-07-15 22:44:42 +00:00
|
|
|
#include <iostream>
|
2010-03-03 07:56:19 +00:00
|
|
|
|
|
|
|
|
using namespace uhd::transport;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
static void pack_and_unpack(vrt::if_packet_info_t& if_packet_info_in)
|
|
|
|
|
{
|
|
|
|
|
if (if_packet_info_in.num_payload_bytes == 0) {
|
|
|
|
|
if_packet_info_in.num_payload_bytes =
|
|
|
|
|
if_packet_info_in.num_payload_words32 * sizeof(uint32_t);
|
2013-07-15 22:44:42 +00:00
|
|
|
}
|
2016-10-31 21:30:52 +00:00
|
|
|
uint32_t packet_buff[2048];
|
2010-03-03 07:56:19 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// pack metadata into a vrt header
|
|
|
|
|
vrt::if_hdr_pack_be(packet_buff, if_packet_info_in);
|
2013-07-15 22:44:42 +00:00
|
|
|
std::cout << std::endl;
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t i = 0; i < 5; i++) {
|
|
|
|
|
std::cout << boost::format("packet_buff[%u] = 0x%.8x") % i
|
|
|
|
|
% uhd::byteswap(packet_buff[i])
|
|
|
|
|
<< std::endl;
|
2013-07-15 22:44:42 +00:00
|
|
|
}
|
2010-03-03 07:56:19 +00:00
|
|
|
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info_out;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info_out.link_type = if_packet_info_in.link_type;
|
2010-06-30 05:55:45 +00:00
|
|
|
if_packet_info_out.num_packet_words32 = if_packet_info_in.num_packet_words32;
|
2010-03-03 07:56:19 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// unpack the vrt header back into metadata
|
|
|
|
|
vrt::if_hdr_unpack_be(packet_buff, if_packet_info_out);
|
2010-03-03 07:56:19 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// check the the unpacked metadata is the same
|
2010-06-30 05:55:45 +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);
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.has_sid, if_packet_info_out.has_sid);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (if_packet_info_in.has_sid and if_packet_info_out.has_sid) {
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.sid, if_packet_info_out.sid);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.has_cid, if_packet_info_out.has_cid);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (if_packet_info_in.has_cid and if_packet_info_out.has_cid) {
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.cid, if_packet_info_out.cid);
|
|
|
|
|
}
|
|
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.has_tsi, if_packet_info_out.has_tsi);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (if_packet_info_in.has_tsi and if_packet_info_out.has_tsi) {
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.tsi, if_packet_info_out.tsi);
|
|
|
|
|
}
|
|
|
|
|
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) {
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.tsf, if_packet_info_out.tsf);
|
|
|
|
|
}
|
|
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.has_tlr, if_packet_info_out.has_tlr);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (if_packet_info_in.has_tlr and if_packet_info_out.has_tlr) {
|
2010-06-30 05:55:45 +00:00
|
|
|
BOOST_CHECK_EQUAL(if_packet_info_in.tlr, if_packet_info_out.tlr);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-30 05:55:45 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Loopback test the vrt packer/unpacker with various packet info combos
|
|
|
|
|
* The trailer is not tested as it is not convenient to do so.
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_none)
|
|
|
|
|
{
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_count = 0;
|
|
|
|
|
if_packet_info.has_sid = false;
|
|
|
|
|
if_packet_info.has_cid = false;
|
|
|
|
|
if_packet_info.has_tsi = false;
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.has_tlr = false;
|
2010-06-30 05:55:45 +00:00
|
|
|
if_packet_info.num_payload_words32 = 0;
|
|
|
|
|
pack_and_unpack(if_packet_info);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_sid)
|
|
|
|
|
{
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_count = 1;
|
|
|
|
|
if_packet_info.has_sid = true;
|
|
|
|
|
if_packet_info.has_cid = false;
|
|
|
|
|
if_packet_info.has_tsi = false;
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.has_tlr = false;
|
|
|
|
|
if_packet_info.sid = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 11;
|
2010-06-30 05:55:45 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 19:02:08 +00:00
|
|
|
static const bool cid_enb = false;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_cid)
|
|
|
|
|
{
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_count = 2;
|
|
|
|
|
if_packet_info.has_sid = false;
|
|
|
|
|
if_packet_info.has_cid = cid_enb;
|
|
|
|
|
if_packet_info.has_tsi = false;
|
|
|
|
|
if_packet_info.has_tsf = false;
|
|
|
|
|
if_packet_info.has_tlr = false;
|
|
|
|
|
if_packet_info.cid = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 22;
|
2010-06-30 05:55:45 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_time)
|
|
|
|
|
{
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_count = 3;
|
|
|
|
|
if_packet_info.has_sid = false;
|
|
|
|
|
if_packet_info.has_cid = false;
|
|
|
|
|
if_packet_info.has_tsi = true;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.has_tlr = false;
|
|
|
|
|
if_packet_info.tsi = std::rand();
|
|
|
|
|
if_packet_info.tsf = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 33;
|
2010-06-30 05:55:45 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_all)
|
|
|
|
|
{
|
2010-06-30 05:55:45 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.packet_count = 4;
|
|
|
|
|
if_packet_info.has_sid = true;
|
|
|
|
|
if_packet_info.has_cid = cid_enb;
|
|
|
|
|
if_packet_info.has_tsi = true;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.has_tlr = false;
|
|
|
|
|
if_packet_info.sid = std::rand();
|
|
|
|
|
if_packet_info.cid = std::rand();
|
|
|
|
|
if_packet_info.tsi = std::rand();
|
|
|
|
|
if_packet_info.tsf = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 44;
|
|
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_vrlp)
|
|
|
|
|
{
|
2013-07-15 22:44:42 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_VRLP;
|
|
|
|
|
if_packet_info.packet_count = 3;
|
|
|
|
|
if_packet_info.has_sid = true;
|
|
|
|
|
if_packet_info.has_cid = false;
|
|
|
|
|
if_packet_info.has_tsi = false;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.has_tlr = true;
|
|
|
|
|
if_packet_info.tsi = std::rand();
|
|
|
|
|
if_packet_info.tsf = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 42;
|
|
|
|
|
pack_and_unpack(if_packet_info);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_with_chdr)
|
|
|
|
|
{
|
2013-07-15 22:44:42 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2019-01-14 18:35:25 +00:00
|
|
|
if_packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR;
|
|
|
|
|
if_packet_info.packet_count = 7;
|
|
|
|
|
if_packet_info.has_sid = true;
|
|
|
|
|
if_packet_info.has_cid = false;
|
|
|
|
|
if_packet_info.has_tsi = false;
|
|
|
|
|
if_packet_info.has_tsf = true;
|
|
|
|
|
if_packet_info.has_tlr = false; // tlr not suported in CHDR
|
|
|
|
|
if_packet_info.tsi = std::rand();
|
|
|
|
|
if_packet_info.tsf = std::rand();
|
2013-07-15 22:44:42 +00:00
|
|
|
if_packet_info.num_payload_words32 = 24;
|
2010-06-30 05:55:45 +00:00
|
|
|
pack_and_unpack(if_packet_info);
|
2010-03-03 07:56:19 +00:00
|
|
|
}
|