From 25d8f8ddb3fe5493ef2847047c1e70283b0d8af1 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan <johnathan@corganlabs.com>
Date: Wed, 27 Feb 2013 13:21:07 -0800
Subject: blocks: added gr::blocks::tuntap_pdu

Linux only
---
 gnuradio-core/src/lib/io/gr_pdu.h                   | 13 +++++++------
 gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc |  8 ++++----
 gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc |  8 ++++----
 3 files changed, 15 insertions(+), 14 deletions(-)

(limited to 'gnuradio-core/src/lib/io')

diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h
index a5ae87db7f..53058ccb6c 100644
--- a/gnuradio-core/src/lib/io/gr_pdu.h
+++ b/gnuradio-core/src/lib/io/gr_pdu.h
@@ -23,17 +23,18 @@
 #ifndef GR_PDU_H
 #define GR_PDU_H
 
+#include <gr_core_api.h>
 #include <gr_complex.h>
 #include <gruel/pmt.h>
 
-#define pdu_port_id     pmt::mp("pdus")
-#define pdu_length_tag  pmt::mp("pdu_length")
+#define PDU_PORT_ID     pmt::mp("pdus")
+#define PDU_LENGTH_TAG  pmt::mp("pdu_length")
 
 enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex };
 
-size_t gr_pdu_itemsize(gr_pdu_vector_type type);
-bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v);
-pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items);
-gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector);
+GR_CORE_API size_t gr_pdu_itemsize(gr_pdu_vector_type type);
+GR_CORE_API bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v);
+GR_CORE_API pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items);
+GR_CORE_API gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector);
 
 #endif
diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
index 5c319dc39d..a702b66a2b 100644
--- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
+++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
@@ -49,7 +49,7 @@ gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t)
 		  gr_make_io_signature(1, 1, gr_pdu_itemsize(t))),
     d_vectortype(t), d_itemsize(gr_pdu_itemsize(t))
 {
-    message_port_register_in(pdu_port_id);
+    message_port_register_in(PDU_PORT_ID);
 }
 
 gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream()
@@ -77,8 +77,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items,
   if(noutput_items > 0){
 
     // grab a message if one exists
-    //pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) );
-    pmt::pmt_t msg( delete_head_blocking( pdu_port_id ) );
+    //pmt::pmt_t msg( delete_head_nowait( PDU_PORT_ID ) );
+    pmt::pmt_t msg( delete_head_blocking( PDU_PORT_ID ) );
     if(msg.get() == NULL ){
         return nout;
         }
@@ -99,7 +99,7 @@ gr_pdu_to_tagged_stream::work(int noutput_items,
     uint64_t offset = nitems_written(0) + nout;
 
     // add a tag for pdu length
-    add_item_tag(0, offset, pdu_length_tag, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias()));
+    add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias()));
 
     // if we recieved metadata add it as tags
     if( !pmt_eq(meta, pmt::PMT_NIL) ){
diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
index 8211b7672d..1b869edfab 100644
--- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
+++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
@@ -49,7 +49,7 @@ gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t)
     d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false),
     d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL)
 {
-  message_port_register_out(pdu_port_id);
+  message_port_register_out(PDU_PORT_ID);
 }
 
 gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu()
@@ -70,7 +70,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items,
     get_tags_in_range(d_tags, 0, abs_N, abs_N+1);
     bool found_length_tag(false);
     for(d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++){
-      if( pmt::pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){
+      if( pmt::pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){
           if( (*d_tags_itr).offset != abs_N ){
               throw std::runtime_error("expected next pdu length tag on a different item...");
               }
@@ -91,7 +91,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items,
   // copy any tags in this range into our meta object
   get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy);
   for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++){
-    if( ! pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){
+    if( ! pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){
         d_pdu_meta = pmt_dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value);
         }
     }
@@ -127,7 +127,7 @@ void gr_tagged_stream_to_pdu::send_message(){
     }
 
     pmt::pmt_t msg = pmt::pmt_cons( d_pdu_meta, d_pdu_vector );
-    message_port_pub( pdu_port_id, msg );
+    message_port_pub( PDU_PORT_ID, msg );
 
     d_pdu_meta = pmt::PMT_NIL;
     d_pdu_vector = pmt::PMT_NIL;
-- 
cgit v1.2.3


From 6e988b777c6788cc7d434b869173ebcdcc2ce5e3 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan <johnathan@corganlabs.com>
Date: Wed, 27 Feb 2013 13:50:57 -0800
Subject: core: removed gr_tuntap_pdu

Replaced by gr::blocks:tuntap_pdu
---
 gnuradio-core/src/lib/io/CMakeLists.txt   |   1 -
 gnuradio-core/src/lib/io/gr_tuntap_pdu.cc | 145 ------------------------------
 gnuradio-core/src/lib/io/gr_tuntap_pdu.h  |  74 ---------------
 gnuradio-core/src/lib/io/gr_tuntap_pdu.i  |  30 -------
 gnuradio-core/src/lib/io/io.i             |   2 -
 grc/blocks/block_tree.xml                 |   1 -
 grc/blocks/gr_tuntap_pdu.xml              |  34 -------
 7 files changed, 287 deletions(-)
 delete mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.cc
 delete mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.h
 delete mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.i
 delete mode 100644 grc/blocks/gr_tuntap_pdu.xml

(limited to 'gnuradio-core/src/lib/io')

diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt
index 59ca06b5a2..23c019d63b 100644
--- a/gnuradio-core/src/lib/io/CMakeLists.txt
+++ b/gnuradio-core/src/lib/io/CMakeLists.txt
@@ -105,7 +105,6 @@ set(gr_core_io_triple_threats
     gr_wavfile_sink
     gr_tagged_file_sink
     gr_tagged_stream_to_pdu
-    gr_tuntap_pdu
     gr_socket_pdu
 )
 
diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc
deleted file mode 100644
index 8dd4b18a10..0000000000
--- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc
+++ /dev/null
@@ -1,145 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2012 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <gr_tuntap_pdu.h>
-#include <gr_io_signature.h>
-#include <cstdio>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdexcept>
-#include <string.h>
-#include <iostream>
-#include <gr_pdu.h>
-#include <boost/format.hpp>
-
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <arpa/inet.h>
-#include <linux/if.h>
-
-
-// public constructor that returns a shared_ptr
-
-gr_tuntap_pdu_sptr
-gr_make_tuntap_pdu (std::string dev, int MTU)
-{
-  return gnuradio::get_initial_sptr(new gr_tuntap_pdu(dev, MTU));
-}
-
-gr_tuntap_pdu::gr_tuntap_pdu (std::string dev, int MTU)
-    : gr_stream_pdu_base(MTU)
-{
-
-    // make the tuntap
-    char dev_cstr[1024];
-    memset(dev_cstr, 0x00, 1024);
-    strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size()));
-    d_fd = tun_alloc(dev_cstr);
-    if(d_fd <= 0){
-        throw std::runtime_error("TunTap make: tun_alloc failed (are you running as root?)");
-        }
-
-    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(pmt::mp("pdus"));
-    start_rxthread(pmt::mp("pdus"));
-    
-    // set up input message port
-    message_port_register_in(pmt::mp("pdus"));
-    set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_tuntap_pdu::send, this, _1));
-}
-
-
-int gr_tuntap_pdu::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 (*dev) {
-     /* 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 */
-     strncpy(ifr.ifr_name, dev, IFNAMSIZ);
-   }
-
-   /* 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;
-}
-
-#else //if not linux
-
-gr_block_sptr
-gr_make_tuntap_pdu(std::string dev, int MTU)
-{
-    gr_block_sptr rv;
-    throw std::runtime_error("tuntap only implemented on linux");
-    return rv;
-}
-
-#endif
diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h
deleted file mode 100644
index 18c83f42b2..0000000000
--- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2012 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDED_GR_TUNTAP_PDU_H
-#define INCLUDED_GR_TUNTAP_PDU_H
-
-#include <gr_core_api.h>
-#include <gr_sync_block.h>
-#include <gr_message.h>
-#include <gr_msg_queue.h>
-#include <gr_stream_pdu_base.h>
-
-#if (defined(linux) || defined(__linux) || defined(__linux__))
-
-#include <linux/if_tun.h>
-
-class gr_tuntap_pdu;
-typedef boost::shared_ptr<gr_tuntap_pdu> gr_tuntap_pdu_sptr;
-
-GR_CORE_API gr_tuntap_pdu_sptr gr_make_tuntap_pdu (std::string dev, int MTU=10000);
-
-/*!
- * \brief Gather received items into messages and insert into msgq
- * \ingroup sink_blk
- */
-class GR_CORE_API gr_tuntap_pdu : public gr_stream_pdu_base
-{
- private:
-  friend GR_CORE_API gr_tuntap_pdu_sptr
-  gr_make_tuntap_pdu(std::string dev, int MTU);
-  int tun_alloc(char* dev, int flags = IFF_TAP | IFF_NO_PI);
-  std::string d_dev;
- protected:
-  gr_tuntap_pdu (std::string dev, int MTU=10000);
-
- public:
-  ~gr_tuntap_pdu () {}
-
-};
-
-#else // if not linux
-
-class gr_tuntap_pdu
-{
-private:
-  gr_tuntap_pdu() {};
-public:
-  ~gr_tuntap_pdu() {};
-};
-
-GR_CORE_API gr_block_sptr gr_make_tuntap_pdu (std::string dev, int MTU=0);
-
-#endif
-
-#endif /* INCLUDED_GR_TUNTAP_PDU_H */
diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.i b/gnuradio-core/src/lib/io/gr_tuntap_pdu.i
deleted file mode 100644
index 589bbc3853..0000000000
--- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.i
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2005 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-GR_SWIG_BLOCK_MAGIC(gr,tuntap_pdu);
-
-%{
-#include <gr_tuntap_pdu.h>
-%}
-
-%include "gr_tuntap_pdu.h"
-
diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i
index e2de4eb976..33cc906e92 100644
--- a/gnuradio-core/src/lib/io/io.i
+++ b/gnuradio-core/src/lib/io/io.i
@@ -49,7 +49,6 @@
 #include <gr_tagged_stream_to_pdu.h>
 #include <gr_message_debug.h>
 #include <gr_pdu.h>
-#include <gr_tuntap_pdu.h>
 #include <gr_socket_pdu.h>
 %}
 
@@ -77,7 +76,6 @@
 %include "gr_tagged_stream_to_pdu.i"
 %include "gr_message_debug.i"
 %include "gr_pdu.i"
-%include "gr_tuntap_pdu.i"
 %include "gr_socket_pdu.i"
 
 
diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml
index 8ddcaac61d..4567a65781 100644
--- a/grc/blocks/block_tree.xml
+++ b/grc/blocks/block_tree.xml
@@ -39,7 +39,6 @@
         <block>gr_message_strobe</block>
         <block>gr_pdu_to_tagged_stream</block>
         <block>gr_tagged_stream_to_pdu</block>
-        <block>gr_tuntap_pdu</block>
         <block>gr_socket_pdu</block>
         <block>gr_random_pdu</block>
     </cat>
diff --git a/grc/blocks/gr_tuntap_pdu.xml b/grc/blocks/gr_tuntap_pdu.xml
deleted file mode 100644
index f169345afa..0000000000
--- a/grc/blocks/gr_tuntap_pdu.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0"?>
-<!--
-###################################################
-## Tuntap PDU Message source/sink
-###################################################
- -->
-<block>
-	<name>TunTap PDU</name>
-	<key>gr_tuntap_pdu</key>
-	<import>from gnuradio import gr</import>
-	<make>gr.tuntap_pdu($ifn, $mtu)</make>
-    <param>
-        <name>Interface Name</name>
-        <key>ifn</key>
-        <value>tun0</value>
-        <type>string</type>
-    </param>
-    <param>
-        <name>MTU</name>
-        <key>mtu</key>
-        <value>10000</value>
-        <type>int</type>
-    </param>
-	<sink>
-		<name>pdus</name>
-		<type>message</type>
-        <optional>1</optional>
-	</sink>
-	<source>
-		<name>pdus</name>
-		<type>message</type>
-        <optional>1</optional>
-	</source>
-</block>
-- 
cgit v1.2.3