commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5481 - gnuradio/branches/developers/gnychis/inband/us


From: gnychis
Subject: [Commit-gnuradio] r5481 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Wed, 16 May 2007 15:45:48 -0600 (MDT)

Author: gnychis
Date: 2007-05-16 15:45:47 -0600 (Wed, 16 May 2007)
New Revision: 5481

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
Log:
Adding in functionality for testing USB packet creation process from m-block 
packets.

Testing simply checks if the correct number of USB packets are being created 
from visual inspection, as the xmit process really should only return T or F

Added code to the usrp server xmit code to check that the caller of the frame 
xmit on a specific channel actually "owns" the channel and that the channel is 
legitimate.

Needs functionality to check that the correct flags are set in the packets 
(burst on first packet, end of burst on last packet), but this should be done 
on a fake USRP as usrp_server should not be passing full USB packets back to 
the QA code.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   2007-05-16 21:31:51 UTC (rev 5480)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   2007-05-16 21:45:47 UTC (rev 5481)
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 
+#include <usrp_inband_usb_packet.h>
 #include <qa_inband_usrp_server.h>
 #include <cppunit/TestAssert.h>
 #include <stdio.h>
@@ -33,7 +34,10 @@
 #include <mb_class_registry.h>
 #include <vector>
 #include <iostream>
+#include <pmt.h>
 
+typedef usrp_inband_usb_packet transport_pkt;   // makes conversion to gigabit 
easy
+
 static pmt_t s_cmd_allocate_channel = pmt_intern("cmd-allocate-channel");
 static pmt_t s_response_allocate_channel = 
pmt_intern("response-allocate-channel");
 static pmt_t s_send_allocate_channel = pmt_intern("send-allocate-channel");
@@ -48,6 +52,8 @@
 static pmt_t s_response_nrx_chan = pmt_intern("response-nrx-chan");
 static pmt_t s_cmd_current_capacity_allocation  = 
pmt_intern("cmd-current-capacity-allocation");
 static pmt_t s_response_current_capacity_allocation  = 
pmt_intern("response-current-capacity-allocation");
+static pmt_t s_cmd_xmit_raw_frame  = pmt_intern("cmd-xmit-raw-frame");
+static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
 
 
 // 
----------------------------------------------------------------------------------------------
@@ -426,6 +432,144 @@
 
 // 
----------------------------------------------------------------------------------------------
 
+class qa_packets_top : public mb_mblock
+{
+  mb_port_sptr d_tx;
+  mb_port_sptr d_rx;
+  
+  long d_max_capacity;
+  long d_ntx_chan, d_nrx_chan;
+
+  long d_xmit_to_recv;
+  long d_xmit_recvd;
+
+  long d_tx_chan;
+
+ public:
+  qa_packets_top(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
+  ~qa_packets_top();
+  void initial_transition();
+  void handle_message(mb_message_sptr msg);
+
+ protected:
+  void send_packets();
+  void check_xmit(mb_message_sptr msg);
+  void check_allocation(mb_message_sptr msg);
+  void check_deallocation(mb_message_sptr msg);
+};
+
+qa_packets_top::qa_packets_top(mb_runtime *runtime, const std::string 
&instance_name, pmt_t user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
+{ 
+  d_xmit_recvd=0;
+  d_xmit_to_recv=0;
+
+  d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
+
+  // Test the TX side
+  define_component("server", "usrp_server", PMT_F);
+  connect("self", "tx0", "server", "tx0");
+}
+
+qa_packets_top::~qa_packets_top(){}
+
+void
+qa_packets_top::initial_transition()
+{
+  // need a channel to send on for testing, bytes don't matter right now
+  d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
+}
+
+void
+qa_packets_top::handle_message(mb_message_sptr msg)
+{
+  pmt_t data = msg->data();
+  if (pmt_eq(msg->port_id(), d_tx->port_symbol())) {
+    
+    if(pmt_eq(msg->signal(), s_response_allocate_channel)) {
+      check_allocation(msg);
+    }
+    else if(pmt_eq(msg->signal(), s_response_xmit_raw_frame)) {
+      check_xmit(msg);
+    }
+  }
+}
+
+void
+qa_packets_top::check_xmit(mb_message_sptr msg)
+{
+  pmt_t data = msg->data();
+
+  pmt_t invocation_handle = pmt_nth(0, data);
+  pmt_t status = pmt_nth(1, data);
+  
+  d_xmit_recvd++;
+
+  if(!pmt_eqv(status, PMT_T)) {
+    std::cout << "[qa_packets_top] Error response from raw frame xmit\n"; 
+    shutdown_all(PMT_F);
+  }
+
+  if(d_xmit_recvd==d_xmit_to_recv) {
+    std::cout << "[qa_packets_top] Received all expected xmit responses, 
shutting down\n";
+    shutdown_all(PMT_T);
+  }
+}
+
+void
+qa_packets_top::check_allocation(mb_message_sptr msg)
+{
+  pmt_t data = msg->data();
+
+  pmt_t invocation_handle = pmt_nth(0, data);
+  pmt_t status = pmt_nth(1, data);
+  pmt_t channel = pmt_nth(2, data);
+  
+  if(pmt_eqv(status, PMT_F)) {
+    std::cout << "[qa_packets_top] Unexpected error response when allocating 
channels\n";
+    shutdown_all(PMT_F);
+  } else {
+    std::cout << "[qa_packets_top] Received channel allocation for channel " 
<< pmt_to_long(channel) << "\n";
+    // store all of the allocate channel numbers
+    if(pmt_eq(msg->port_id(), d_tx->port_symbol()))
+      d_tx_chan = pmt_to_long(channel);
+
+    // after allocating some channel, start the TX test
+    send_packets();
+  }
+}
+
+void
+qa_packets_top::send_packets()
+{
+  // NOTE:  The invocation handle is used as the expected number of USB 
packets for visual examination
+  
+  // Test 1:  less than the payload size of a single USB packet
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(1), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(1, 0), pmt_from_long(0)));
+  d_xmit_to_recv++;
+
+  // Test 2: 1 packet, of exact size... since we are using 32-bit samples we 
divide by 4
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(1), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4, 
0), pmt_from_long(0)));
+  d_xmit_to_recv++;
+
+  // Test 3: 2 packets, a spill over of 1 sample into the second packet
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(2), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4+1, 
0), pmt_from_long(0)));
+  d_xmit_to_recv++;
+
+  // Test 4: 2 packets of exact payload size
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(2), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4*2, 
0), pmt_from_long(0)));
+  d_xmit_to_recv++;
+  
+  // Test 4: 2 full packets, and 1 packet with a single sample (which is 3)
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(3), 
pmt_from_long(d_tx_chan), 
pmt_make_u32vector(transport_pkt::max_payload()/4*2+1, 0), pmt_from_long(0)));
+  d_xmit_to_recv++;
+
+}
+
+REGISTER_MBLOCK_CLASS(qa_packets_top);
+
+// 
----------------------------------------------------------------------------------------------
+
 void 
 qa_inband_usrp_server::test_chan_allocation()
 {
@@ -449,7 +593,12 @@
 }
 
 void
-qa_inband_usrp_server::test_fragmentation()
+qa_inband_usrp_server::test_packets()
 {
-  
+  mb_runtime_sptr rt = mb_make_runtime();
+  pmt_t result = PMT_T;
+
+  rt->run("top", "qa_packets_top", PMT_F, &result);
+
+  CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
 }

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
    2007-05-16 21:31:51 UTC (rev 5480)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
    2007-05-16 21:45:47 UTC (rev 5481)
@@ -30,13 +30,13 @@
   CPPUNIT_TEST_SUITE(qa_inband_usrp_server);
   CPPUNIT_TEST(test_chan_allocation);
   CPPUNIT_TEST(test_chan_deallocation);
-  CPPUNIT_TEST(test_fragmentation);
+  CPPUNIT_TEST(test_packets);
   CPPUNIT_TEST_SUITE_END();
 
  private:
   void test_chan_allocation();
   void test_chan_deallocation();
-  void test_fragmentation();
+  void test_packets();
 };
 
 #endif /* INCLUDED_QA_INBAND_USRP_SERVER_H */

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-05-16 21:31:51 UTC (rev 5480)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-05-16 21:45:47 UTC (rev 5481)
@@ -188,7 +188,7 @@
   }
     
   if (pmt_eq(event, s_cmd_xmit_raw_frame)){
-    handle_cmd_xmit_raw_frame(data);
+    handle_cmd_xmit_raw_frame(port_id, data);
     return;
   }
 
@@ -351,44 +351,69 @@
 
 }
 
-void usrp_server::handle_cmd_xmit_raw_frame(pmt_t data) {
+void usrp_server::handle_cmd_xmit_raw_frame(pmt_t port_id, pmt_t data) {
 
   size_t n_bytes, psize;
   long max_payload_len = transport_pkt::max_payload();
+  pmt_t reply_data;
 
   pmt_t invocation_handle = pmt_nth(0, data);
   long channel = pmt_to_long(pmt_nth(1, data));
   const void *samples = pmt_uniform_vector_elements(pmt_nth(2, data), n_bytes);
   long timestamp = pmt_to_long(pmt_nth(3, data));
+  
+  long port;
+  
+  // Check that the channel number is valid, and that the caller is the owner
+  // of the channel to send the frame
+  if((port = tx_port_index(port_id)) != -1) {
+  
+    if(channel >= d_ntx_chan) {
+      reply_data = pmt_list2(invocation_handle, 
pmt_from_long(CHANNEL_INVALID));   // not a legit channel number
+      d_tx[port]->send(s_response_deallocate_channel, reply_data);
+      return;
+    }
 
-  // Determine the number of packets to allocate contiguous memory for 
bursting over the
-  // USB and get a pointer to the memory to be used in building the packets
-  long n_packets = static_cast<long>(std::ceil(n_bytes / 
(double)max_payload_len));
-  pmt_t v_packets = pmt_make_u8vector(sizeof(transport_pkt) * n_packets, 0);
+    if(d_chaninfo_tx[channel].owner != port_id) {
+      reply_data = pmt_list2(invocation_handle, 
pmt_from_long(PERMISSION_DENIED));   // not the owner of the port
+      d_tx[port]->send(s_response_deallocate_channel, reply_data);
+      return;
+    }
 
-  transport_pkt *pkts =
-    (transport_pkt *) pmt_u8vector_writeable_elements(v_packets, psize);
+    // Determine the number of packets to allocate contiguous memory for 
bursting over the
+    // USB and get a pointer to the memory to be used in building the packets
+    long n_packets = static_cast<long>(std::ceil(n_bytes / 
(double)max_payload_len));
+    pmt_t v_packets = pmt_make_u8vector(sizeof(transport_pkt) * n_packets, 0);
 
-  for(int n=0; n < n_packets; n++) {
+    transport_pkt *pkts =
+      (transport_pkt *) pmt_u8vector_writeable_elements(v_packets, psize);
 
-    long payload_len = std::min((long)(n_bytes-(n*max_payload_len)), 
(long)max_payload_len);
-  
-    if(n == 0) { // first packet gets start of burst flag and timestamp
-      pkts[n].set_header(pkts[n].FL_START_OF_BURST, channel, 0, payload_len);
-      pkts[n].set_timestamp(timestamp);
-    } else {
-      pkts[n].set_header(0, channel, 0, payload_len);
-      pkts[n].set_timestamp(0xffffffff);
+    for(int n=0; n < n_packets; n++) {
+
+      long payload_len = std::min((long)(n_bytes-(n*max_payload_len)), 
(long)max_payload_len);
+    
+      if(n == 0) { // first packet gets start of burst flag and timestamp
+        pkts[n].set_header(pkts[n].FL_START_OF_BURST, channel, 0, payload_len);
+        pkts[n].set_timestamp(timestamp);
+      } else {
+        pkts[n].set_header(0, channel, 0, payload_len);
+        pkts[n].set_timestamp(0xffffffff);
+      }
+
+      memcpy(pkts[n].payload(), (uint8_t *)samples+(max_payload_len * n), 
payload_len);
     }
 
-    memcpy(pkts[n].payload(), (uint8_t *)samples+(max_payload_len * n), 
payload_len);
-  }
+    pkts[n_packets-1].set_end_of_burst();   // set the last packet's end of 
burst
 
-  pkts[n_packets-1].set_end_of_burst();   // set the last packet's end of burst
+    // interface with the USRP to send the USB packet, since the memory is
+    // contiguous, this should be a serious of memory copies to the bus, each 
being
+    // USB_PKT_SIZE * MAX_PACKET_BURST bytes worth of data (given a full burst)
 
-  // interface with the USRP to send the USB packet, since the memory is
-  // contiguous, this should be a serious of memory copies to the bus, each 
being
-  // USB_PKT_SIZE * MAX_PACKET_BURST bytes worth of data (given a full burst)
+    std::cout << "[usrp_server] Received raw frame for invocation " << 
pmt_to_long(invocation_handle) << " --> " << n_packets << " packets\n";
+    
+    reply_data = pmt_list2(invocation_handle, PMT_T);
+    d_tx[port]->send(s_response_xmit_raw_frame, reply_data);
+  }
 }
 
 REGISTER_MBLOCK_CLASS(usrp_server);

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-05-16 21:31:51 UTC (rev 5480)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-05-16 21:45:47 UTC (rev 5481)
@@ -73,7 +73,7 @@
 private:
   void handle_cmd_allocate_channel(pmt_t port_id, pmt_t data);
   void handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data);
-  void handle_cmd_xmit_raw_frame(pmt_t data);
+  void handle_cmd_xmit_raw_frame(pmt_t port_id, pmt_t data);
   int rx_port_index(pmt_t port_id);
   int tx_port_index(pmt_t port_id);
   long current_capacity_allocation();





reply via email to

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