commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 17/148: Began work on eth data transport cl


From: git
Subject: [Commit-gnuradio] [gnuradio] 17/148: Began work on eth data transport class. Switched send in transport to use iovecs. Pass mac addr into eth transports rather than re-parsing.
Date: Mon, 15 Aug 2016 00:47:20 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.

commit 2d8de39762a1279bc721c5f7d2339bfde0c1b001
Author: Josh Blum <address@hidden>
Date:   Wed Nov 4 15:55:55 2009 -0800

    Began work on eth data transport class.
    Switched send in transport to use iovecs.
    Pass mac addr into eth transports rather than re-parsing.
---
 usrp2/host/lib/Makefile.am                         |  2 +
 usrp2/host/lib/eth_ctrl_transport.cc               | 66 ++++++++--------------
 usrp2/host/lib/eth_ctrl_transport.h                |  6 +-
 usrp2/host/lib/eth_data_transport.cc               | 56 ++++++++++++++++++
 .../{eth_ctrl_transport.h => eth_data_transport.h} | 25 ++++----
 usrp2/host/lib/transport.cc                        |  2 +-
 usrp2/host/lib/transport.h                         |  7 ++-
 usrp2/host/lib/usrp2.cc                            | 32 ++++++++++-
 usrp2/host/lib/usrp2_impl.cc                       | 18 ++----
 9 files changed, 140 insertions(+), 74 deletions(-)

diff --git a/usrp2/host/lib/Makefile.am b/usrp2/host/lib/Makefile.am
index 614a7c6..5567192 100644
--- a/usrp2/host/lib/Makefile.am
+++ b/usrp2/host/lib/Makefile.am
@@ -37,6 +37,7 @@ libusrp2_la_SOURCES = \
        data_handler.cc \
        eth_buffer.cc \
        eth_ctrl_transport.cc \
+       eth_data_transport.cc \
        ethernet.cc \
        find.cc \
        open_usrp2_socket.cc \
@@ -59,6 +60,7 @@ noinst_HEADERS = \
        eth_buffer.h \
        eth_common.h \
        eth_ctrl_transport.h \
+       eth_data_transport.h \
        ethernet.h \
        open_usrp2_socket.h \
        pktfilter.h \
diff --git a/usrp2/host/lib/eth_ctrl_transport.cc 
b/usrp2/host/lib/eth_ctrl_transport.cc
index 09c383e..4d067d9 100644
--- a/usrp2/host/lib/eth_ctrl_transport.cc
+++ b/usrp2/host/lib/eth_ctrl_transport.cc
@@ -18,46 +18,15 @@
 
 #include "eth_ctrl_transport.h"
 
-//FIXME this is the third instance of this function, find it a home
-static bool
-parse_mac_addr(const std::string &s, u2_mac_addr_t *p)
-{
-    p->addr[0] = 0x00;         // Matt's IAB
-    p->addr[1] = 0x50;
-    p->addr[2] = 0xC2;
-    p->addr[3] = 0x85;
-    p->addr[4] = 0x30;
-    p->addr[5] = 0x00;
-
-    int len = s.size();
-
-    switch (len){
-      
-    case 5:
-      return sscanf(s.c_str(), "%hhx:%hhx", &p->addr[4], &p->addr[5]) == 2;
-      
-    case 17:
-      return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-            &p->addr[0], &p->addr[1], &p->addr[2],
-            &p->addr[3], &p->addr[4], &p->addr[5]) == 6;
-    default:
-      return false;
-    }
-}
-
-
-usrp2::eth_ctrl_transport::eth_ctrl_transport(const std::string &ifc, props 
*p) : transport("ethernet control"){
+usrp2::eth_ctrl_transport::eth_ctrl_transport(const std::string &ifc, 
u2_mac_addr_t mac) : transport("ethernet control"), d_mac(mac){
 
     //create raw ethernet device
     d_eth_ctrl = new ethernet();
     if (!d_eth_ctrl->open(ifc, htons(U2_CTRL_ETHERTYPE)))
         throw std::runtime_error("Unable to open/register USRP2 control 
protocol");
 
-    //extract mac addr
-    parse_mac_addr(p->addr, &d_usrp_mac);
-
     //create and attach packet filter
-    d_pf_ctrl = pktfilter::make_ethertype_inbound_target(U2_CTRL_ETHERTYPE, 
(const unsigned char*)&(d_usrp_mac.addr));
+    d_pf_ctrl = pktfilter::make_ethertype_inbound_target(U2_CTRL_ETHERTYPE, 
(const unsigned char*)&(d_mac.addr));
     if (!d_pf_ctrl || !d_eth_ctrl->attach_pktfilter(d_pf_ctrl))
         throw std::runtime_error("Unable to attach packet filter for control 
packets.");
 }
@@ -76,25 +45,40 @@ typedef struct {
   u2_transport_hdr_t   thdr;
 } u2_eth_packet_only_t;
 
-int usrp2::eth_ctrl_transport::send(const void *buff, int len){
-    //return d_eth_ctrl->write_packet(buff, len);
+int usrp2::eth_ctrl_transport::sendv(const iovec *iov, size_t iovlen){
+    //create a new iov array with a space for ethernet header and padding
+    // and move the current iovs to the center of the new array
+    size_t all_iov_len = iovlen + 2;
+    iovec all_iov[all_iov_len];
+    for (size_t i = 0; i < iovlen; i++){
+        all_iov[i+1] = iov[i];
+    }
     //setup a new ethernet header
     u2_eth_packet_only_t hdr;
     hdr.ehdr.ethertype = htons(U2_CTRL_ETHERTYPE);
-    memcpy(&hdr.ehdr.dst, d_usrp_mac.addr, 6);
+    memcpy(&hdr.ehdr.dst, d_mac.addr, 6);
     memcpy(&hdr.ehdr.src, d_eth_ctrl->mac(), 6);
     hdr.thdr.flags = 0; // FIXME transport header values?
     hdr.thdr.seqno = 0;
     hdr.thdr.ack = 0;
-    //load the buffer with header and control data
-    uint8_t packet[len+sizeof(hdr)];
-    memcpy(packet, &hdr, sizeof(hdr));
-    memcpy(packet+sizeof(hdr), buff, len);
-    return d_eth_ctrl->write_packet(packet, len+sizeof(hdr));
+    //feed the first iov the header
+    all_iov[0].iov_base = &hdr;
+    all_iov[0].iov_len = sizeof(hdr);
+    //get number of bytes in current iovs
+    int num_bytes = 0;
+    for (size_t i = 0; i < all_iov_len-1; i++){
+        num_bytes += all_iov[i].iov_len;
+    }
+    //handle padding, must be at least 64 bytes
+    uint8_t padding[64];
+    all_iov[all_iov_len-1].iov_base = padding;
+    all_iov[all_iov_len-1].iov_len = (num_bytes < 64) ? (64 - num_bytes) : 0;
+    return d_eth_ctrl->write_packetv(all_iov, all_iov_len);
 }
 
 int usrp2::eth_ctrl_transport::recv(void **buff){
     int recv_len = d_eth_ctrl->read_packet_dont_block(d_buff, sizeof(d_buff));
+    //strip the ethernet headers from the buffer
     if (recv_len > sizeof(u2_eth_packet_only_t)){
         *buff = d_buff + sizeof(u2_eth_packet_only_t);
         return recv_len - sizeof(u2_eth_packet_only_t);
diff --git a/usrp2/host/lib/eth_ctrl_transport.h 
b/usrp2/host/lib/eth_ctrl_transport.h
index 461e70a..2a784e3 100644
--- a/usrp2/host/lib/eth_ctrl_transport.h
+++ b/usrp2/host/lib/eth_ctrl_transport.h
@@ -31,12 +31,12 @@ namespace usrp2{
         uint8_t              d_buff[1500]; //FIXME use MTU
         ethernet      *d_eth_ctrl;  // unbuffered control frames
         pktfilter     *d_pf_ctrl;
-        u2_mac_addr_t d_usrp_mac;
+        u2_mac_addr_t d_mac;
 
     public:
-        eth_ctrl_transport(const std::string &ifc, props *p);
+        eth_ctrl_transport(const std::string &ifc, u2_mac_addr_t mac);
         ~eth_ctrl_transport();
-        int send(const void *buff, int len);
+        int sendv(const iovec *iov, size_t iovlen);
         int recv(void **buff);
 };
 
diff --git a/usrp2/host/lib/eth_data_transport.cc 
b/usrp2/host/lib/eth_data_transport.cc
new file mode 100644
index 0000000..a781b6c
--- /dev/null
+++ b/usrp2/host/lib/eth_data_transport.cc
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "eth_data_transport.h"
+#include <gruel/inet.h>
+#include <gruel/realtime.h>
+#include <gruel/sys_pri.h>
+#include <iostream>
+
+usrp2::eth_data_transport::eth_data_transport(const std::string &ifc, 
u2_mac_addr_t mac, size_t rx_bufsize)
+ : transport("ethernet control"), d_mac(mac), d_tx_seqno(0){
+
+    //create raw ethernet device
+    d_eth_data = new eth_buffer(rx_bufsize);
+    if (!d_eth_data->open(ifc, htons(U2_DATA_ETHERTYPE)))
+        throw std::runtime_error("Unable to open/register USRP2 data 
protocol");
+
+    //create and attach packet filter
+    d_pf_data = pktfilter::make_ethertype_inbound_target(U2_DATA_ETHERTYPE, 
(const unsigned char*)&(d_mac.addr));
+    if (!d_pf_data || !d_eth_data->attach_pktfilter(d_pf_data))
+        throw std::runtime_error("Unable to attach packet filter for data 
packets.");
+}
+
+usrp2::eth_data_transport::~eth_data_transport(){
+    delete d_pf_data;
+    d_eth_data->close();
+    delete d_eth_data;
+}
+
+void usrp2::eth_data_transport::init(){
+    if (gruel::enable_realtime_scheduling(gruel::sys_pri::usrp2_backend()) != 
gruel::RT_OK)
+        std::cerr << "usrp2: failed to enable realtime scheduling" << 
std::endl;
+}
+
+int usrp2::eth_data_transport::sendv(const iovec *iov, size_t iovlen){
+   return 0;
+}
+
+int usrp2::eth_data_transport::recv(void **buff){
+    return 0;
+}
diff --git a/usrp2/host/lib/eth_ctrl_transport.h 
b/usrp2/host/lib/eth_data_transport.h
similarity index 61%
copy from usrp2/host/lib/eth_ctrl_transport.h
copy to usrp2/host/lib/eth_data_transport.h
index 461e70a..c624fa1 100644
--- a/usrp2/host/lib/eth_ctrl_transport.h
+++ b/usrp2/host/lib/eth_data_transport.h
@@ -16,31 +16,32 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef INCLUDED_ETH_CTRL_TRANSPORT_H
-#define INCLUDED_ETH_CTRL_TRANSPORT_H
+#ifndef INCLUDED_ETH_DATA_TRANSPORT_H
+#define INCLUDED_ETH_DATA_TRANSPORT_H
 
 #include "transport.h"
-#include "ethernet.h"
+#include "eth_buffer.h"
 #include "pktfilter.h"
 #include "usrp2_impl.h"
 
 namespace usrp2{
 
-    class eth_ctrl_transport: public transport{
+    class eth_data_transport: public transport{
     private:
-        uint8_t              d_buff[1500]; //FIXME use MTU
-        ethernet      *d_eth_ctrl;  // unbuffered control frames
-        pktfilter     *d_pf_ctrl;
-        u2_mac_addr_t d_usrp_mac;
+        eth_buffer    *d_eth_data;     // packet ring buffered data frames
+        pktfilter     *d_pf_data;
+        u2_mac_addr_t d_mac;
+        int           d_tx_seqno;
 
     public:
-        eth_ctrl_transport(const std::string &ifc, props *p);
-        ~eth_ctrl_transport();
-        int send(const void *buff, int len);
+        eth_data_transport(const std::string &ifc, u2_mac_addr_t mac, size_t 
rx_bufsize);
+        ~eth_data_transport();
+        int sendv(const iovec *iov, size_t iovlen);
         int recv(void **buff);
+        void init();
 };
 
 
 } // namespace usrp2
 
-#endif /* INCLUDED_ETH_CTRL_TRANSPORT_H */
+#endif /* INCLUDED_ETH_DATA_TRANSPORT_H */
diff --git a/usrp2/host/lib/transport.cc b/usrp2/host/lib/transport.cc
index 42e5cfb..25ca99b 100644
--- a/usrp2/host/lib/transport.cc
+++ b/usrp2/host/lib/transport.cc
@@ -72,7 +72,7 @@ void usrp2::transport::run(){
     }
 }
 
-int usrp2::transport::send(const void *buff, int len){
+int usrp2::transport::sendv(const iovec *iov, size_t iovlen){
     return -1; //NOP
 }
 
diff --git a/usrp2/host/lib/transport.h b/usrp2/host/lib/transport.h
index 0b6198a..113a0a9 100644
--- a/usrp2/host/lib/transport.h
+++ b/usrp2/host/lib/transport.h
@@ -21,6 +21,7 @@
 
 #include <boost/thread.hpp>
 #include <cstring>
+#include <sys/uio.h>
 
 namespace usrp2 {
 
@@ -62,11 +63,11 @@ namespace usrp2 {
     virtual void init();
     /*!
      * \brief send the contents of the buffer (override in a subclass)
-     * \param buff a pointer into memory
-     * \param len the length of the buffer in bytes
+     * \param iovec a list of iovecs
+     * \param iovlen the number of iovecs
      * \return the number of bytes sent, -1 for error
      */
-    virtual int send(const void *buff, int len);
+    virtual int sendv(const iovec *iov, size_t iovlen);
     /*!
      * \brief receive data into the buffer (override in a subclass)
      * \param buff a pointer to a pointer into memory
diff --git a/usrp2/host/lib/usrp2.cc b/usrp2/host/lib/usrp2.cc
index fafaa3c..218a2c3 100644
--- a/usrp2/host/lib/usrp2.cc
+++ b/usrp2/host/lib/usrp2.cc
@@ -31,6 +31,33 @@
 #include "eth_ctrl_transport.h"
 
 
+//FIXME this is the Nth instance of this function, find it a home
+static bool
+parse_mac_addr(const std::string &s, u2_mac_addr_t *p)
+{
+    p->addr[0] = 0x00;         // Matt's IAB
+    p->addr[1] = 0x50;
+    p->addr[2] = 0xC2;
+    p->addr[3] = 0x85;
+    p->addr[4] = 0x30;
+    p->addr[5] = 0x00;
+
+    int len = s.size();
+
+    switch (len){
+      
+    case 5:
+      return sscanf(s.c_str(), "%hhx:%hhx", &p->addr[4], &p->addr[5]) == 2;
+      
+    case 17:
+      return sscanf(s.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+            &p->addr[0], &p->addr[1], &p->addr[2],
+            &p->addr[3], &p->addr[4], &p->addr[5]) == 6;
+    default:
+      return false;
+    }
+}
+
 namespace usrp2 {
 
   // --- Table of weak pointers to usrps we know about ---
@@ -147,7 +174,10 @@ namespace usrp2 {
   // Private constructor.  Sole function is to create an impl.
   usrp2::usrp2(const std::string &ifc, props *p, size_t rx_bufsize)
   {
-    transport::sptr ctrl_transport(new eth_ctrl_transport(ifc, p));
+    u2_mac_addr_t mac;
+    parse_mac_addr(p->addr, &mac);
+    
+    transport::sptr ctrl_transport(new eth_ctrl_transport(ifc, mac));
     d_impl = std::auto_ptr<impl>(new usrp2::impl(ifc, p, rx_bufsize, 
ctrl_transport));
   }
   
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 91a309b..b4c32e6 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -316,20 +316,12 @@ namespace usrp2 {
 
 
   bool
-  usrp2::impl::transmit_cmd(void *cmd_, size_t len_)
+  usrp2::impl::transmit_cmd(void *cmd, size_t len)
   {
-    const void *cmd = cmd_;
-    int len = len_;
-    unsigned char tmp[64];
-
-    if (len_ < 64){            // pad to minimum ethernet frame size
-      memset(tmp, 0, sizeof(tmp));
-      memcpy(tmp, cmd_, len_);
-      cmd = tmp;
-      len = sizeof(tmp);
-    }
-
-    return d_ctrl_transport->send(cmd, len) >= 0;
+    iovec iov;
+    iov.iov_base = cmd;
+    iov.iov_len = len;
+    return d_ctrl_transport->sendv(&iov, 1) >= 0;
   }
 
   bool



reply via email to

[Prev in Thread] Current Thread [Next in Thread]