summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorJacob Gilbert <jacob.gilbert@protonmail.com>2021-03-14 10:29:08 -0700
committermormj <34754695+mormj@users.noreply.github.com>2021-03-18 16:35:41 -0400
commit4a3fe8539ce0f0830db150d7c8b920d9c0828c0c (patch)
treee41709e4e7a4ac1a843895c55cf81490929418fc /gr-blocks/lib
parenta8a9913136a64da903f190493bdc117b5349625e (diff)
gr-blocks: remove pdu blocks
The following have been moved to the new gr::pdu module or to gr::network and are no longer needed in gr::blocks: - pdu (noblock) - pdu_filter block - pdu_remove block - pdu_set block - pdu_to_tagged_stream block - random_pdu block - socket_pdu block - stream_pdu_base (noblock) - tagged_stream_to_pdu block - tcp_connection (noblock) - tuntap_pdu block The digital and FEC modules had a large number of references to the PDU blocks that were moved from gr-blocks to gr-pdu, this updates these changes in example flowgraphs and a few python files. The usage-manual update will be propagated to the wiki so that future exports will remain up to date. Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/CMakeLists.txt11
-rw-r--r--gr-blocks/lib/pdu.cc82
-rw-r--r--gr-blocks/lib/pdu_filter_impl.cc59
-rw-r--r--gr-blocks/lib/pdu_filter_impl.h37
-rw-r--r--gr-blocks/lib/pdu_remove_impl.cc51
-rw-r--r--gr-blocks/lib/pdu_remove_impl.h33
-rw-r--r--gr-blocks/lib/pdu_set_impl.cc52
-rw-r--r--gr-blocks/lib/pdu_set_impl.h35
-rw-r--r--gr-blocks/lib/pdu_to_tagged_stream_impl.cc98
-rw-r--r--gr-blocks/lib/pdu_to_tagged_stream_impl.h41
-rw-r--r--gr-blocks/lib/random_pdu_impl.cc74
-rw-r--r--gr-blocks/lib/random_pdu_impl.h46
-rw-r--r--gr-blocks/lib/socket_pdu_impl.cc271
-rw-r--r--gr-blocks/lib/socket_pdu_impl.h68
-rw-r--r--gr-blocks/lib/stream_pdu_base.cc110
-rw-r--r--gr-blocks/lib/stream_pdu_base.h52
-rw-r--r--gr-blocks/lib/tagged_stream_to_pdu_impl.cc66
-rw-r--r--gr-blocks/lib/tagged_stream_to_pdu_impl.h38
-rw-r--r--gr-blocks/lib/tcp_connection.cc101
-rw-r--r--gr-blocks/lib/tcp_connection.h54
-rw-r--r--gr-blocks/lib/tuntap_pdu_impl.cc171
-rw-r--r--gr-blocks/lib/tuntap_pdu_impl.h41
22 files changed, 0 insertions, 1591 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index bfe3eaa91e..d9dd44692c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -115,14 +115,8 @@ set(BLOCKS_SOURCES
null_source_impl.cc
pack_k_bits_bb_impl.cc
patterned_interleaver_impl.cc
- pdu.cc
tag_debug_impl.cc
- pdu_filter_impl.cc
- pdu_set_impl.cc
- pdu_remove_impl.cc
- pdu_to_tagged_stream_impl.cc
peak_detector2_fb_impl.cc
- random_pdu_impl.cc
plateau_detector_fb_impl.cc
probe_rate_impl.cc
regenerate_bb_impl.cc
@@ -134,10 +128,8 @@ set(BLOCKS_SOURCES
short_to_char_impl.cc
short_to_float_impl.cc
skiphead_impl.cc
- socket_pdu_impl.cc
stream_demux_impl.cc
stream_mux_impl.cc
- stream_pdu_base.cc
stream_to_streams_impl.cc
stream_to_tagged_stream_impl.cc
stream_to_vector_impl.cc
@@ -146,16 +138,13 @@ set(BLOCKS_SOURCES
stretch_ff_impl.cc
tag_share_impl.cc
tagged_file_sink_impl.cc
- tagged_stream_to_pdu_impl.cc
tagged_stream_multiply_length_impl.cc
tags_strobe_impl.cc
test_tag_variable_rate_ff_impl.cc
threshold_ff_impl.cc
throttle_impl.cc
transcendental_impl.cc
- tcp_connection.cc
tcp_server_sink_impl.cc
- tuntap_pdu_impl.cc
tag_gate_impl.cc
tagged_stream_align_impl.cc
tagged_stream_mux_impl.cc
diff --git a/gr-blocks/lib/pdu.cc b/gr-blocks/lib/pdu.cc
deleted file mode 100644
index ec44a10e57..0000000000
--- a/gr-blocks/lib/pdu.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <gnuradio/blocks/pdu.h>
-
-namespace gr {
-namespace blocks {
-namespace pdu {
-
-const pmt::pmt_t pdu_port_id()
-{
- static const pmt::pmt_t pdu_port_id = pmt::mp("pdus");
- return pdu_port_id;
-}
-
-size_t itemsize(vector_type type)
-{
- switch (type) {
- case byte_t:
- return sizeof(char);
- case float_t:
- return sizeof(float);
- case complex_t:
- return sizeof(gr_complex);
- default:
- throw std::runtime_error("bad PDU type");
- }
-}
-
-bool type_matches(vector_type type, pmt::pmt_t v)
-{
- switch (type) {
- case byte_t:
- return pmt::is_u8vector(v);
- case float_t:
- return pmt::is_f32vector(v);
- case complex_t:
- return pmt::is_c32vector(v);
- default:
- throw std::runtime_error("bad PDU type");
- }
-}
-
-pmt::pmt_t make_pdu_vector(vector_type type, const uint8_t* buf, size_t items)
-{
- switch (type) {
- case byte_t:
- return pmt::init_u8vector(items, buf);
- case float_t:
- return pmt::init_f32vector(items, (const float*)buf);
- case complex_t:
- return pmt::init_c32vector(items, (const gr_complex*)buf);
- default:
- throw std::runtime_error("bad PDU type");
- }
-}
-
-vector_type type_from_pmt(pmt::pmt_t vector)
-{
- if (pmt::is_u8vector(vector))
- return byte_t;
- if (pmt::is_f32vector(vector))
- return float_t;
- if (pmt::is_c32vector(vector))
- return complex_t;
- throw std::runtime_error("bad PDU type");
-}
-
-} /* namespace pdu */
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/pdu_filter_impl.cc b/gr-blocks/lib/pdu_filter_impl.cc
deleted file mode 100644
index 686e7b678d..0000000000
--- a/gr-blocks/lib/pdu_filter_impl.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "pdu_filter_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-pdu_filter::sptr pdu_filter::make(pmt::pmt_t k, pmt::pmt_t v, bool invert)
-{
- return gnuradio::make_block_sptr<pdu_filter_impl>(k, v, invert);
-}
-
-pdu_filter_impl::pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert)
- : block("pdu_filter", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- d_k(k),
- d_v(v),
- d_invert(invert)
-{
- message_port_register_out(pdu::pdu_port_id());
- message_port_register_in(pdu::pdu_port_id());
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->handle_msg(msg); });
-}
-
-void pdu_filter_impl::handle_msg(pmt::pmt_t pdu)
-{
- pmt::pmt_t meta = pmt::car(pdu);
- bool output = d_invert;
-
- // check base type
- // key exists
- // value matches
- if (pmt::is_dict(meta) && dict_has_key(meta, d_k) &&
- pmt::eqv(pmt::dict_ref(meta, d_k, pmt::PMT_NIL), d_v)) {
- output = !d_invert;
- }
-
- // if all tests pass, propagate the pdu
- if (output) {
- message_port_pub(pdu::pdu_port_id(), pdu);
- }
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/pdu_filter_impl.h b/gr-blocks/lib/pdu_filter_impl.h
deleted file mode 100644
index 7d3d9e7acd..0000000000
--- a/gr-blocks/lib/pdu_filter_impl.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_PDU_FILTER_IMPL_H
-#define INCLUDED_BLOCKS_PDU_FILTER_IMPL_H
-
-#include <gnuradio/blocks/pdu_filter.h>
-
-namespace gr {
-namespace blocks {
-
-class pdu_filter_impl : public pdu_filter
-{
-private:
- pmt::pmt_t d_k;
- pmt::pmt_t d_v;
- bool d_invert;
-
-public:
- pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert);
- void handle_msg(pmt::pmt_t msg);
- void set_key(pmt::pmt_t key) override { d_k = key; };
- void set_val(pmt::pmt_t val) override { d_v = val; };
- void set_inversion(bool invert) override { d_invert = invert; };
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_PDU_FILTER_IMPL_H */
diff --git a/gr-blocks/lib/pdu_remove_impl.cc b/gr-blocks/lib/pdu_remove_impl.cc
deleted file mode 100644
index ded25b6d49..0000000000
--- a/gr-blocks/lib/pdu_remove_impl.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "pdu_remove_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-pdu_remove::sptr pdu_remove::make(pmt::pmt_t k)
-{
- return gnuradio::make_block_sptr<pdu_remove_impl>(k);
-}
-
-pdu_remove_impl::pdu_remove_impl(pmt::pmt_t k)
- : block("pdu_remove", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- d_k(k)
-{
- message_port_register_out(pdu::pdu_port_id());
- message_port_register_in(pdu::pdu_port_id());
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->handle_msg(msg); });
-}
-
-void pdu_remove_impl::handle_msg(pmt::pmt_t pdu)
-{
- // add the field and publish
- pmt::pmt_t meta = pmt::car(pdu);
- if (pmt::is_null(meta)) {
- meta = pmt::make_dict();
- } else if (!pmt::is_dict(meta)) {
- throw std::runtime_error("pdu_remove received non PDU input");
- }
- meta = pmt::dict_delete(meta, d_k);
- message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu)));
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/pdu_remove_impl.h b/gr-blocks/lib/pdu_remove_impl.h
deleted file mode 100644
index 74c77d6e45..0000000000
--- a/gr-blocks/lib/pdu_remove_impl.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_PDU_REMOVE_IMPL_H
-#define INCLUDED_BLOCKS_PDU_REMOVE_IMPL_H
-
-#include <gnuradio/blocks/pdu_remove.h>
-
-namespace gr {
-namespace blocks {
-
-class pdu_remove_impl : public pdu_remove
-{
-private:
- pmt::pmt_t d_k;
-
-public:
- pdu_remove_impl(pmt::pmt_t k);
- void handle_msg(pmt::pmt_t msg);
- void set_key(pmt::pmt_t key) override { d_k = key; };
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_PDU_REMOVE_IMPL_H */
diff --git a/gr-blocks/lib/pdu_set_impl.cc b/gr-blocks/lib/pdu_set_impl.cc
deleted file mode 100644
index 70a8487720..0000000000
--- a/gr-blocks/lib/pdu_set_impl.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "pdu_set_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-pdu_set::sptr pdu_set::make(pmt::pmt_t k, pmt::pmt_t v)
-{
- return gnuradio::make_block_sptr<pdu_set_impl>(k, v);
-}
-
-pdu_set_impl::pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v)
- : block("pdu_set", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- d_k(k),
- d_v(v)
-{
- message_port_register_out(pdu::pdu_port_id());
- message_port_register_in(pdu::pdu_port_id());
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->handle_msg(msg); });
-}
-
-void pdu_set_impl::handle_msg(pmt::pmt_t pdu)
-{
- // add the field and publish
- pmt::pmt_t meta = pmt::car(pdu);
- if (pmt::is_null(meta)) {
- meta = pmt::make_dict();
- } else if (!pmt::is_dict(meta)) {
- throw std::runtime_error("pdu_set received non PDU input");
- }
- meta = pmt::dict_add(meta, d_k, d_v);
- message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu)));
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/pdu_set_impl.h b/gr-blocks/lib/pdu_set_impl.h
deleted file mode 100644
index fbfae9dd03..0000000000
--- a/gr-blocks/lib/pdu_set_impl.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_PDU_SET_IMPL_H
-#define INCLUDED_BLOCKS_PDU_SET_IMPL_H
-
-#include <gnuradio/blocks/pdu_set.h>
-
-namespace gr {
-namespace blocks {
-
-class pdu_set_impl : public pdu_set
-{
-private:
- pmt::pmt_t d_k;
- pmt::pmt_t d_v;
-
-public:
- pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v);
- void handle_msg(pmt::pmt_t msg);
- void set_key(pmt::pmt_t key) override { d_k = key; };
- void set_val(pmt::pmt_t val) override { d_v = val; };
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_PDU_SET_IMPL_H */
diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc
deleted file mode 100644
index 26b86bee83..0000000000
--- a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "pdu_to_tagged_stream_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-pdu_to_tagged_stream::sptr pdu_to_tagged_stream::make(pdu::vector_type type,
- const std::string& tsb_tag_key)
-{
- return gnuradio::make_block_sptr<pdu_to_tagged_stream_impl>(type, tsb_tag_key);
-}
-
-pdu_to_tagged_stream_impl::pdu_to_tagged_stream_impl(pdu::vector_type type,
- const std::string& tsb_tag_key)
- : tagged_stream_block("pdu_to_tagged_stream",
- io_signature::make(0, 0, 0),
- io_signature::make(1, 1, pdu::itemsize(type)),
- tsb_tag_key),
- d_itemsize(pdu::itemsize(type)),
- d_curr_len(0)
-{
- message_port_register_in(pdu::pdu_port_id());
-}
-
-int pdu_to_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int&)
-{
- if (d_curr_len == 0) {
- pmt::pmt_t msg(delete_head_nowait(pdu::pdu_port_id()));
- if (msg.get() == NULL) {
- return 0;
- }
-
- if (!pmt::is_pair(msg))
- throw std::runtime_error("received a malformed pdu message");
-
- d_curr_meta = pmt::car(msg);
- d_curr_vect = pmt::cdr(msg);
- // do not assume the length of PMT is in items (e.g.: from socket_pdu)
- d_curr_len = pmt::blob_length(d_curr_vect) / d_itemsize;
- }
-
- return d_curr_len;
-}
-
-int pdu_to_tagged_stream_impl::work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star& input_items,
- gr_vector_void_star& output_items)
-{
- uint8_t* out = (uint8_t*)output_items[0];
-
- if (d_curr_len == 0) {
- return 0;
- }
-
- // work() should only be called if the current PDU fits entirely
- // into the output buffer.
- assert(noutput_items >= 0 && (unsigned int)noutput_items >= d_curr_len);
-
- // Copy vector output
- size_t nout = d_curr_len;
- size_t io(0);
- const uint8_t* ptr = (const uint8_t*)uniform_vector_elements(d_curr_vect, io);
- memcpy(out, ptr, d_curr_len * d_itemsize);
-
- // Copy tags
- if (!pmt::eq(d_curr_meta, pmt::PMT_NIL)) {
- pmt::pmt_t klist(pmt::dict_keys(d_curr_meta));
- for (size_t i = 0; i < pmt::length(klist); i++) {
- pmt::pmt_t k(pmt::nth(i, klist));
- pmt::pmt_t v(pmt::dict_ref(d_curr_meta, k, pmt::PMT_NIL));
- add_item_tag(0, nitems_written(0), k, v, alias_pmt());
- }
- }
-
- // Reset state
- d_curr_len = 0;
-
- return nout;
-} /* work() */
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.h b/gr-blocks/lib/pdu_to_tagged_stream_impl.h
deleted file mode 100644
index 0a389fb040..0000000000
--- a/gr-blocks/lib/pdu_to_tagged_stream_impl.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_PDU_TO_TAGGED_STREAM_IMPL_H
-#define INCLUDED_PDU_TO_TAGGED_STREAM_IMPL_H
-
-#include <gnuradio/blocks/pdu_to_tagged_stream.h>
-
-namespace gr {
-namespace blocks {
-
-class BLOCKS_API pdu_to_tagged_stream_impl : public pdu_to_tagged_stream
-{
- const size_t d_itemsize;
- pmt::pmt_t d_curr_meta;
- pmt::pmt_t d_curr_vect;
- size_t d_curr_len;
-
-public:
- pdu_to_tagged_stream_impl(pdu::vector_type type,
- const std::string& lengthtagname = "packet_len");
-
- int calculate_output_stream_length(const gr_vector_int& ninput_items) override;
-
- int work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star& input_items,
- gr_vector_void_star& output_items) override;
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_PDU_TO_TAGGED_STREAM_IMPL_H */
diff --git a/gr-blocks/lib/random_pdu_impl.cc b/gr-blocks/lib/random_pdu_impl.cc
deleted file mode 100644
index 2a8e1eb7f5..0000000000
--- a/gr-blocks/lib/random_pdu_impl.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "random_pdu_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-random_pdu::sptr
-random_pdu::make(int min_items, int max_items, unsigned char byte_mask, int length_modulo)
-{
- return gnuradio::make_block_sptr<random_pdu_impl>(
- min_items, max_items, byte_mask, length_modulo);
-}
-
-random_pdu_impl::random_pdu_impl(int min_items,
- int max_items,
- unsigned char byte_mask,
- int length_modulo)
- : block("random_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- d_urange(min_items, max_items),
- d_brange(0, 255),
- d_mask(byte_mask),
- d_length_modulo(length_modulo)
-{
- message_port_register_out(pdu::pdu_port_id());
- message_port_register_in(pmt::mp("generate"));
- set_msg_handler(pmt::mp("generate"),
- [this](pmt::pmt_t msg) { this->generate_pdu(msg); });
- if (length_modulo < 1)
- throw std::runtime_error("length_module must be >= 1");
- if (max_items < length_modulo)
- throw std::runtime_error("max_items must be >= to length_modulo");
-}
-
-bool random_pdu_impl::start()
-{
- output_random();
- return true;
-}
-
-void random_pdu_impl::output_random()
-{
- // pick a random vector length
- int len = d_urange(d_rng);
- len = std::max(d_length_modulo, len - len % d_length_modulo);
-
- // fill it with random bytes
- std::vector<unsigned char> vec(len);
- for (int i = 0; i < len; i++)
- vec[i] = ((unsigned char)d_brange(d_rng)) & d_mask;
-
- // send the vector
- pmt::pmt_t vecpmt(pmt::make_blob(&vec[0], len));
- pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL, vecpmt));
-
- message_port_pub(pdu::pdu_port_id(), pdu);
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/random_pdu_impl.h b/gr-blocks/lib/random_pdu_impl.h
deleted file mode 100644
index 7f0b87c90c..0000000000
--- a/gr-blocks/lib/random_pdu_impl.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H
-#define INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H
-
-#include <gnuradio/blocks/random_pdu.h>
-#include <boost/generator_iterator.hpp>
-
-#include <random>
-
-namespace gr {
-namespace blocks {
-
-class random_pdu_impl : public random_pdu
-{
-private:
- std::mt19937 d_rng;
- std::uniform_int_distribution<> d_urange;
- std::uniform_int_distribution<> d_brange;
- const unsigned char d_mask;
- const int d_length_modulo;
-
-public:
- random_pdu_impl(int min_items,
- int max_items,
- unsigned char byte_mask,
- int length_modulo);
-
- bool start() override;
- void output_random();
- void generate_pdu(pmt::pmt_t msg) { output_random(); }
- void generate_pdu() { output_random(); }
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H */
diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc
deleted file mode 100644
index f30e944d7b..0000000000
--- a/gr-blocks/lib/socket_pdu_impl.cc
+++ /dev/null
@@ -1,271 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013,2019 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "socket_pdu_impl.h"
-#include "tcp_connection.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-socket_pdu::sptr socket_pdu::make(std::string type,
- std::string addr,
- std::string port,
- int MTU /*= 10000*/,
- bool tcp_no_delay /*= false*/)
-{
- return gnuradio::make_block_sptr<socket_pdu_impl>(
- type, addr, port, MTU, tcp_no_delay);
-}
-
-socket_pdu_impl::socket_pdu_impl(std::string type,
- std::string addr,
- std::string port,
- int MTU /*= 10000*/,
- bool tcp_no_delay /*= false*/)
- : block("socket_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- d_tcp_no_delay(tcp_no_delay)
-{
- d_rxbuf.resize(MTU);
-
- message_port_register_in(pdu::pdu_port_id());
- message_port_register_out(pdu::pdu_port_id());
-
- if ((type == "TCP_SERVER") &&
- ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces
- int port_num = atoi(port.c_str());
- if (port_num == 0)
- throw std::invalid_argument(
- "gr::blocks:socket_pdu: invalid port for TCP_SERVER");
- d_tcp_endpoint =
- boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port_num);
- } else if ((type == "TCP_SERVER") || (type == "TCP_CLIENT")) {
- boost::asio::ip::tcp::resolver resolver(d_io_service);
- boost::asio::ip::tcp::resolver::query query(
- boost::asio::ip::tcp::v4(),
- addr,
- port,
- boost::asio::ip::resolver_query_base::passive);
- d_tcp_endpoint = *resolver.resolve(query);
- } else if ((type == "UDP_SERVER") &&
- ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces
- int port_num = atoi(port.c_str());
- if (port_num == 0)
- throw std::invalid_argument(
- "gr::blocks:socket_pdu: invalid port for UDP_SERVER");
- d_udp_endpoint =
- boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port_num);
- } else if ((type == "UDP_SERVER") || (type == "UDP_CLIENT")) {
- boost::asio::ip::udp::resolver resolver(d_io_service);
- boost::asio::ip::udp::resolver::query query(
- boost::asio::ip::udp::v4(),
- addr,
- port,
- boost::asio::ip::resolver_query_base::passive);
-
- if (type == "UDP_SERVER")
- d_udp_endpoint = *resolver.resolve(query);
- else
- d_udp_endpoint_other = *resolver.resolve(query);
- }
-
- if (type == "TCP_SERVER") {
- d_acceptor_tcp = std::make_shared<boost::asio::ip::tcp::acceptor>(d_io_service,
- d_tcp_endpoint);
- d_acceptor_tcp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
-
- start_tcp_accept();
-
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->tcp_server_send(msg); });
- } else if (type == "TCP_CLIENT") {
- boost::system::error_code error = boost::asio::error::host_not_found;
- d_tcp_socket = std::make_shared<boost::asio::ip::tcp::socket>(d_io_service);
- d_tcp_socket->connect(d_tcp_endpoint, error);
- if (error)
- throw boost::system::system_error(error);
- d_tcp_socket->set_option(boost::asio::ip::tcp::no_delay(d_tcp_no_delay));
-
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->tcp_client_send(msg); });
-
- d_tcp_socket->async_read_some(
- boost::asio::buffer(d_rxbuf),
- boost::bind(&socket_pdu_impl::handle_tcp_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- } else if (type == "UDP_SERVER") {
- d_udp_socket =
- std::make_shared<boost::asio::ip::udp::socket>(d_io_service, d_udp_endpoint);
- d_udp_socket->async_receive_from(
- boost::asio::buffer(d_rxbuf),
- d_udp_endpoint_other,
- boost::bind(&socket_pdu_impl::handle_udp_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
-
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->udp_send(msg); });
- } else if (type == "UDP_CLIENT") {
- d_udp_socket =
- std::make_shared<boost::asio::ip::udp::socket>(d_io_service, d_udp_endpoint);
- d_udp_socket->async_receive_from(
- boost::asio::buffer(d_rxbuf),
- d_udp_endpoint_other,
- boost::bind(&socket_pdu_impl::handle_udp_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
-
- set_msg_handler(pdu::pdu_port_id(),
- [this](pmt::pmt_t msg) { this->udp_send(msg); });
- } else
- throw std::runtime_error("gr::blocks:socket_pdu: unknown socket type");
-
- d_thread = gr::thread::thread(boost::bind(&socket_pdu_impl::run_io_service, this));
- d_started = true;
-}
-
-socket_pdu_impl::~socket_pdu_impl() { stop(); }
-
-bool socket_pdu_impl::stop()
-{
- if (d_started) {
- d_io_service.stop();
- d_thread.interrupt();
- d_thread.join();
- }
- d_started = false;
- return true;
-}
-
-void socket_pdu_impl::handle_tcp_read(const boost::system::error_code& error,
- size_t bytes_transferred)
-{
- if (!error) {
- pmt::pmt_t vector =
- pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]);
- pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
- message_port_pub(pdu::pdu_port_id(), pdu);
-
- d_tcp_socket->async_read_some(
- boost::asio::buffer(d_rxbuf),
- boost::bind(&socket_pdu_impl::handle_tcp_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- } else
- throw boost::system::system_error(error);
-}
-
-void socket_pdu_impl::start_tcp_accept()
-{
-#if (BOOST_VERSION >= 107000)
- tcp_connection::sptr new_connection =
- tcp_connection::make(d_io_service, d_rxbuf.size(), d_tcp_no_delay);
-#else
- tcp_connection::sptr new_connection = tcp_connection::make(
- d_acceptor_tcp->get_io_service(), d_rxbuf.size(), d_tcp_no_delay);
-#endif
-
- d_acceptor_tcp->async_accept(new_connection->socket(),
- boost::bind(&socket_pdu_impl::handle_tcp_accept,
- this,
- new_connection,
- boost::asio::placeholders::error));
-}
-
-void socket_pdu_impl::tcp_server_send(pmt::pmt_t msg)
-{
- pmt::pmt_t vector = pmt::cdr(msg);
- for (size_t i = 0; i < d_tcp_connections.size(); i++)
- d_tcp_connections[i]->send(vector);
-}
-
-void socket_pdu_impl::handle_tcp_accept(tcp_connection::sptr new_connection,
- const boost::system::error_code& error)
-{
- if (!error) {
- // Garbage collect closed sockets
- std::vector<tcp_connection::sptr>::iterator it = d_tcp_connections.begin();
- while (it != d_tcp_connections.end()) {
- if (!(**it).socket().is_open())
- it = d_tcp_connections.erase(it);
- else
- ++it;
- }
-
- new_connection->start(this);
- d_tcp_connections.push_back(new_connection);
- start_tcp_accept();
- } else
- std::cout << error << std::endl;
-}
-
-void socket_pdu_impl::tcp_client_send(pmt::pmt_t msg)
-{
- pmt::pmt_t vector = pmt::cdr(msg);
- size_t len = pmt::blob_length(vector);
- size_t offset = 0;
- std::vector<char> txbuf(std::min(len, d_rxbuf.size()));
- while (offset < len) {
- size_t send_len = std::min((len - offset), txbuf.size());
- memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len);
- offset += send_len;
- d_tcp_socket->send(boost::asio::buffer(txbuf, send_len));
- }
-}
-
-void socket_pdu_impl::udp_send(pmt::pmt_t msg)
-{
- if (d_udp_endpoint_other.address().to_string() == "0.0.0.0")
- return;
-
- pmt::pmt_t vector = pmt::cdr(msg);
- size_t len = pmt::blob_length(vector);
- size_t offset = 0;
- std::vector<char> txbuf(std::min(len, d_rxbuf.size()));
- while (offset < len) {
- size_t send_len = std::min((len - offset), txbuf.size());
- memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len);
- offset += send_len;
- d_udp_socket->send_to(boost::asio::buffer(txbuf, send_len), d_udp_endpoint_other);
- }
-}
-
-void socket_pdu_impl::handle_udp_read(const boost::system::error_code& error,
- size_t bytes_transferred)
-{
- if (!error) {
- pmt::pmt_t vector =
- pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]);
- pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
-
- message_port_pub(pdu::pdu_port_id(), pdu);
-
- d_udp_socket->async_receive_from(
- boost::asio::buffer(d_rxbuf),
- d_udp_endpoint_other,
- boost::bind(&socket_pdu_impl::handle_udp_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- }
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/socket_pdu_impl.h b/gr-blocks/lib/socket_pdu_impl.h
deleted file mode 100644
index d885c665c4..0000000000
--- a/gr-blocks/lib/socket_pdu_impl.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H
-#define INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H
-
-#include "tcp_connection.h"
-#include <gnuradio/blocks/socket_pdu.h>
-
-namespace gr {
-namespace blocks {
-
-class socket_pdu_impl : public socket_pdu
-{
-private:
- boost::asio::io_service d_io_service;
- std::vector<char> d_rxbuf;
- void run_io_service() { d_io_service.run(); }
- gr::thread::thread d_thread;
- bool d_started;
-
- // TCP specific
- boost::asio::ip::tcp::endpoint d_tcp_endpoint;
- std::vector<tcp_connection::sptr> d_tcp_connections;
- void handle_tcp_read(const boost::system::error_code& error,
- size_t bytes_transferred);
- const bool d_tcp_no_delay;
-
- // TCP server specific
- std::shared_ptr<boost::asio::ip::tcp::acceptor> d_acceptor_tcp;
- void start_tcp_accept();
- void tcp_server_send(pmt::pmt_t msg);
- void handle_tcp_accept(tcp_connection::sptr new_connection,
- const boost::system::error_code& error);
-
- // TCP client specific
- std::shared_ptr<boost::asio::ip::tcp::socket> d_tcp_socket;
- void tcp_client_send(pmt::pmt_t msg);
-
- // UDP specific
- boost::asio::ip::udp::endpoint d_udp_endpoint;
- boost::asio::ip::udp::endpoint d_udp_endpoint_other;
- std::shared_ptr<boost::asio::ip::udp::socket> d_udp_socket;
- void handle_udp_read(const boost::system::error_code& error,
- size_t bytes_transferred);
- void udp_send(pmt::pmt_t msg);
-
-public:
- socket_pdu_impl(std::string type,
- std::string addr,
- std::string port,
- int MTU = 10000,
- bool tcp_no_delay = false);
- ~socket_pdu_impl() override;
- bool stop() override;
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H */
diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc
deleted file mode 100644
index 97e99e8886..0000000000
--- a/gr-blocks/lib/stream_pdu_base.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef HAVE_IO_H
-#include <io.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-#include <winsock2.h>
-#endif
-
-#include "stream_pdu_base.h"
-#include <gnuradio/basic_block.h>
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/logger.h>
-#include <boost/format.hpp>
-
-static const long timeout_us = 100 * 1000; // 100ms
-
-namespace gr {
-namespace blocks {
-
-stream_pdu_base::stream_pdu_base(int MTU) : d_fd(-1), d_started(false), d_finished(false)
-{
- gr::configure_default_loggers(d_pdu_logger, d_pdu_debug_logger, "stream_pdu_base");
- // reserve space for rx buffer
- d_rxbuf.resize(MTU, 0);
-}
-
-stream_pdu_base::~stream_pdu_base() { stop_rxthread(); }
-
-void stream_pdu_base::start_rxthread(basic_block* blk, pmt::pmt_t port)
-{
- d_blk = blk;
- d_port = port;
- d_thread = gr::thread::thread(std::bind(&stream_pdu_base::run, this));
- d_started = true;
-}
-
-void stream_pdu_base::stop_rxthread()
-{
- d_finished = true;
-
- if (d_started) {
- d_thread.interrupt();
- d_thread.join();
- }
-}
-
-void stream_pdu_base::run()
-{
- while (!d_finished) {
- if (!wait_ready())
- continue;
-
- const int result = read(d_fd, &d_rxbuf[0], d_rxbuf.size());
- if (result <= 0)
- throw std::runtime_error("stream_pdu_base, bad socket read!");
-
- pmt::pmt_t vector = pmt::init_u8vector(result, &d_rxbuf[0]);
- pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
-
- d_blk->message_port_pub(d_port, pdu);
- }
-}
-
-bool stream_pdu_base::wait_ready()
-{
- // setup timeval for timeout
- timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = timeout_us;
-
- // setup rset for timeout
- fd_set rset;
- FD_ZERO(&rset);
- FD_SET(d_fd, &rset);
-
- // call select with timeout on receive socket
- return ::select(d_fd + 1, &rset, NULL, NULL, &tv) > 0;
-}
-
-void stream_pdu_base::send(pmt::pmt_t msg)
-{
- pmt::pmt_t vector = pmt::cdr(msg);
- size_t offset(0);
- size_t itemsize(pdu::itemsize(pdu::type_from_pmt(vector)));
- int len(pmt::length(vector) * itemsize);
-
- const int rv = write(d_fd, pmt::uniform_vector_elements(vector, offset), len);
- if (rv != len) {
- static auto msg = boost::format(
- "stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)");
- GR_LOG_WARN(d_pdu_logger, msg % d_fd % len % rv);
- }
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/stream_pdu_base.h b/gr-blocks/lib/stream_pdu_base.h
deleted file mode 100644
index 9ca1f32043..0000000000
--- a/gr-blocks/lib/stream_pdu_base.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_STREAM_PDU_BASE_H
-#define INCLUDED_STREAM_PDU_BASE_H
-
-#include <gnuradio/basic_block.h>
-#include <gnuradio/logger.h>
-#include <gnuradio/thread/thread.h>
-#include <pmt/pmt.h>
-
-class basic_block;
-
-namespace gr {
-namespace blocks {
-
-class stream_pdu_base
-{
-public:
- stream_pdu_base(int MTU = 10000);
- ~stream_pdu_base();
-
-protected:
- int d_fd;
- bool d_started;
- bool d_finished;
- std::vector<uint8_t> d_rxbuf;
- gr::thread::thread d_thread;
-
- pmt::pmt_t d_port;
- basic_block* d_blk;
-
- void run();
- void send(pmt::pmt_t msg);
- bool wait_ready();
- void start_rxthread(basic_block* blk, pmt::pmt_t rxport);
- void stop_rxthread();
-
- gr::logger_ptr d_pdu_logger, d_pdu_debug_logger;
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_STREAM_PDU_BASE_H */
diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc
deleted file mode 100644
index 2ca5e8e68f..0000000000
--- a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "tagged_stream_to_pdu_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-
-namespace gr {
-namespace blocks {
-
-tagged_stream_to_pdu::sptr tagged_stream_to_pdu::make(pdu::vector_type type,
- const std::string& lengthtagname)
-{
- return gnuradio::make_block_sptr<tagged_stream_to_pdu_impl>(type, lengthtagname);
-}
-
-tagged_stream_to_pdu_impl::tagged_stream_to_pdu_impl(pdu::vector_type type,
- const std::string& lengthtagname)
- : tagged_stream_block("tagged_stream_to_pdu",
- io_signature::make(1, 1, pdu::itemsize(type)),
- io_signature::make(0, 0, 0),
- lengthtagname),
- d_type(type),
- d_pdu_meta(pmt::PMT_NIL),
- d_pdu_vector(pmt::PMT_NIL)
-{
- message_port_register_out(pdu::pdu_port_id());
-}
-
-int tagged_stream_to_pdu_impl::work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star& input_items,
- gr_vector_void_star& output_items)
-{
- const uint8_t* in = (const uint8_t*)input_items[0];
-
- // Grab tags, throw them into dict
- get_tags_in_range(d_tags, 0, nitems_read(0), nitems_read(0) + ninput_items[0]);
- d_pdu_meta = pmt::make_dict();
- for (const auto& tag : d_tags) {
- d_pdu_meta = dict_add(d_pdu_meta, tag.key, tag.value);
- }
-
- // Grab data, throw into vector
- d_pdu_vector = pdu::make_pdu_vector(d_type, in, ninput_items[0]);
-
- // Send msg
- pmt::pmt_t msg = pmt::cons(d_pdu_meta, d_pdu_vector);
- message_port_pub(pdu::pdu_port_id(), msg);
-
- return ninput_items[0];
-}
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.h b/gr-blocks/lib/tagged_stream_to_pdu_impl.h
deleted file mode 100644
index 954a710200..0000000000
--- a/gr-blocks/lib/tagged_stream_to_pdu_impl.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_TAGGED_STREAM_TO_PDU_IMPL_H
-#define INCLUDED_TAGGED_STREAM_TO_PDU_IMPL_H
-
-#include <gnuradio/blocks/tagged_stream_to_pdu.h>
-
-namespace gr {
-namespace blocks {
-
-class BLOCKS_API tagged_stream_to_pdu_impl : public tagged_stream_to_pdu
-{
- const pdu::vector_type d_type;
- pmt::pmt_t d_pdu_meta;
- pmt::pmt_t d_pdu_vector;
- std::vector<tag_t> d_tags;
-
-public:
- tagged_stream_to_pdu_impl(pdu::vector_type type, const std::string& lengthtagname);
-
- int work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star& input_items,
- gr_vector_void_star& output_items) override;
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif
diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc
deleted file mode 100644
index 76f42614e9..0000000000
--- a/gr-blocks/lib/tcp_connection.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "tcp_connection.h"
-#include <gnuradio/basic_block.h>
-#include <gnuradio/blocks/pdu.h>
-
-namespace gr {
-namespace blocks {
-
-tcp_connection::sptr tcp_connection::make(boost::asio::io_service& io_service,
- int MTU /*= 10000*/,
- bool no_delay /*=false*/)
-{
- return sptr(new tcp_connection(io_service, MTU, no_delay));
-}
-
-tcp_connection::tcp_connection(boost::asio::io_service& io_service,
- int MTU /*= 10000*/,
- bool no_delay /*=false*/)
- : d_socket(io_service), d_buf(MTU), d_block(NULL), d_no_delay(no_delay)
-{
- try {
- d_socket.set_option(boost::asio::ip::tcp::no_delay(no_delay));
- } catch (...) {
- // Silently ignore failure (socket might be current in accept stage) and try again
- // in 'start'
- }
-}
-
-void tcp_connection::send(pmt::pmt_t vector)
-{
- size_t len = pmt::blob_length(vector);
-
- // Asio async_write() requires the buffer to remain valid until the handler is called.
- auto txbuf = std::make_shared<std::vector<char>>(len);
-
- size_t temp = 0;
- memcpy(txbuf->data(), pmt::uniform_vector_elements(vector, temp), len);
-
- size_t offset = 0;
- while (offset < len) {
- // Limit the size of each write() to the MTU.
- // FIXME: Note that this has the effect of breaking a large PDU into several
- // smaller PDUs, each containing <= MTU bytes. Is this the desired behavior?
- size_t send_len = std::min((len - offset), d_buf.size());
- boost::asio::async_write(
- d_socket,
- boost::asio::buffer(txbuf->data() + offset, send_len),
- [txbuf](const boost::system::error_code& error, size_t bytes_transferred) {});
- offset += send_len;
- }
-}
-
-void tcp_connection::start(gr::basic_block* block)
-{
- d_block = block;
- d_socket.set_option(boost::asio::ip::tcp::no_delay(d_no_delay));
- d_socket.async_read_some(boost::asio::buffer(d_buf),
- boost::bind(&tcp_connection::handle_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
-}
-
-void tcp_connection::handle_read(const boost::system::error_code& error,
- size_t bytes_transferred)
-{
- if (!error) {
- if (d_block) {
- pmt::pmt_t vector =
- pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]);
- pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
-
- d_block->message_port_pub(pdu::pdu_port_id(), pdu);
- }
-
- d_socket.async_read_some(
- boost::asio::buffer(d_buf),
- boost::bind(&tcp_connection::handle_read,
- this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- } else {
- d_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
- d_socket.close();
- }
-}
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/tcp_connection.h b/gr-blocks/lib/tcp_connection.h
deleted file mode 100644
index f97f8a605b..0000000000
--- a/gr-blocks/lib/tcp_connection.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_TCP_CONNECTION_H
-#define INCLUDED_TCP_CONNECTION_H
-
-#include <pmt/pmt.h>
-#include <boost/array.hpp>
-#include <boost/asio.hpp>
-#include <memory>
-
-namespace gr {
-
-class basic_block;
-
-namespace blocks {
-
-class tcp_connection
-{
-private:
- boost::asio::ip::tcp::socket d_socket;
- std::vector<char> d_buf;
- basic_block* d_block;
- bool d_no_delay;
-
- tcp_connection(boost::asio::io_service& io_service,
- int MTU = 10000,
- bool no_delay = false);
-
- void handle_read(const boost::system::error_code& error, size_t bytes_transferred);
-
-public:
- typedef std::shared_ptr<tcp_connection> sptr;
-
- static sptr
- make(boost::asio::io_service& io_service, int MTU = 10000, bool no_delay = false);
-
- boost::asio::ip::tcp::socket& socket() { return d_socket; };
-
- void start(gr::basic_block* block);
- void send(pmt::pmt_t vector);
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_TCP_CONNECTION_H */
diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc
deleted file mode 100644
index 048c33c392..0000000000
--- a/gr-blocks/lib/tuntap_pdu_impl.cc
+++ /dev/null
@@ -1,171 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "tuntap_pdu_impl.h"
-#include <gnuradio/blocks/pdu.h>
-#include <gnuradio/io_signature.h>
-#include <boost/format.hpp>
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-#include <arpa/inet.h>
-#include <linux/if.h>
-#include <sys/ioctl.h>
-#endif
-
-namespace gr {
-namespace blocks {
-
-tuntap_pdu::sptr tuntap_pdu::make(std::string dev, int MTU, bool istunflag)
-{
-#if (defined(linux) || defined(__linux) || defined(__linux__))
- return gnuradio::make_block_sptr<tuntap_pdu_impl>(dev, MTU, istunflag);
-#else
- throw std::runtime_error("tuntap_pdu not implemented on this platform");
-#endif
-}
-
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag)
- : block("tuntap_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
- stream_pdu_base(istunflag ? MTU : MTU + 14),
- d_dev(dev),
- d_istunflag(istunflag)
-{
- // make the tuntap
- char dev_cstr[IFNAMSIZ];
- memset(dev_cstr, 0x00, IFNAMSIZ);
- strncpy(dev_cstr, dev.c_str(), IFNAMSIZ);
- dev_cstr[IFNAMSIZ - 1] = '\0';
-
- bool istun = d_istunflag;
- if (istun) {
- d_fd = tun_alloc(dev_cstr, (IFF_TUN | IFF_NO_PI));
- } else {
- d_fd = tun_alloc(dev_cstr, (IFF_TAP | IFF_NO_PI));
- }
-
- if (d_fd <= 0)
- throw std::runtime_error(
- "gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)");
-
- int err = set_mtu(dev_cstr, MTU);
- if (err < 0) {
- std::ostringstream msg;
- msg << boost::format("failed to set MTU to %d. You should use ifconfig to set "
- "the MTU. E.g., `$ sudo ifconfig %s mtu %d`") %
- MTU % dev % MTU;
- GR_LOG_ERROR(d_logger, msg.str());
- }
-
-
- std::cout << boost::format("Allocated virtual ethernet interface: %s\n"
- "You must now use ifconfig to set its IP address. E.g.,\n"
- " $ sudo ifconfig %s 192.168.200.1\n"
- "Be sure to use a different address in the same subnet "
- "for each machine.\n") %
- dev % dev
- << std::endl;
-
- // set up output message port
- message_port_register_out(pdu::pdu_port_id());
- start_rxthread(this, pdu::pdu_port_id());
-
- // set up input message port
- message_port_register_in(pdu::pdu_port_id());
- set_msg_handler(pdu::pdu_port_id(), [this](pmt::pmt_t msg) { this->send(msg); });
-}
-
-int tuntap_pdu_impl::tun_alloc(char* dev, int flags)
-{
- struct ifreq ifr;
- int fd, err;
- const char* clonedev = "/dev/net/tun";
-
- /* Arguments taken by the function:
- *
- * char *dev: the name of an interface (or '\0'). MUST have enough
- * space to hold the interface name if '\0' is passed
- * int flags: interface flags (eg, IFF_TUN etc.)
- */
-
- /* open the clone device */
- if ((fd = open(clonedev, O_RDWR)) < 0)
- return fd;
-
- /* preparation of the struct ifr, of type "struct ifreq" */
- memset(&ifr, 0, sizeof(ifr));
-
- ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */
-
- /* if a device name was specified, put it in the structure; otherwise,
- * the kernel will try to allocate the "next" device of the
- * specified type
- */
- if (*dev)
- strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1);
-
- /* try to create the device */
- if ((err = ioctl(fd, TUNSETIFF, (void*)&ifr)) < 0) {
- close(fd);
- return err;
- }
-
- /* if the operation was successful, write back the name of the
- * interface to the variable "dev", so the caller can know
- * it. Note that the caller MUST reserve space in *dev (see calling
- * code below)
- */
- strcpy(dev, ifr.ifr_name);
-
- /* this is the special file descriptor that the caller will use to talk
- * with the virtual interface
- */
- return fd;
-}
-
-int tuntap_pdu_impl::set_mtu(const char* dev, int MTU)
-{
- struct ifreq ifr;
- int sfd, err;
-
- /* MTU must be set by passing a socket fd to ioctl;
- * create an arbitrary socket for this purpose
- */
- if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- return sfd;
-
- /* preparation of the struct ifr, of type "struct ifreq" */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ - 1] = '\0';
- ifr.ifr_addr.sa_family = AF_INET; /* address family */
- ifr.ifr_mtu = MTU;
-
- /* try to set MTU */
- if ((err = ioctl(sfd, SIOCSIFMTU, (void*)&ifr)) < 0) {
- close(sfd);
- return err;
- }
-
- close(sfd);
- return MTU;
-}
-#endif
-
-} /* namespace blocks */
-} /* namespace gr */
diff --git a/gr-blocks/lib/tuntap_pdu_impl.h b/gr-blocks/lib/tuntap_pdu_impl.h
deleted file mode 100644
index 86149443f9..0000000000
--- a/gr-blocks/lib/tuntap_pdu_impl.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H
-#define INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H
-
-#include "stream_pdu_base.h"
-#include <gnuradio/blocks/tuntap_pdu.h>
-
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-#include <linux/if_tun.h>
-#endif
-
-namespace gr {
-namespace blocks {
-
-class tuntap_pdu_impl : public tuntap_pdu, public stream_pdu_base
-{
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-private:
- const std::string d_dev;
- const bool d_istunflag;
- int tun_alloc(char* dev, int flags);
- int set_mtu(const char* dev, int MTU);
-
-public:
- tuntap_pdu_impl(std::string dev, int MTU, bool istunflag);
-#endif
-};
-
-} /* namespace blocks */
-} /* namespace gr */
-
-#endif /* INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H */