DumpConsumer.cc

00001 // Copyright 2008 Michael Marsh, University of Maryland.
00002 //
00003 // This file is part of pydtn.
00004 //
00005 // pydtn is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // pydtn is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with pydtn.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // The views and conclusions contained in the software and documentation
00019 // are those of the authors and should not be interpreted as representing
00020 // official policies, either expressed or implied, of the University
00021 // of Maryland.
00022 //
00023 // pydtn extends and embeds the Python interpreter, which is
00024 // Copyright 2001-2006 Python Software Foundation, All Rights Reserved,
00025 // and is released under the PSF License Agreement.
00026 //
00027 // RANLUX random number generation uses the Boost library,
00028 // Copyright 1994-2006 by various authors (details in individual files),
00029 // which is released under the Boost Software License, Version 1.0.
00030 
00031 #include "simlpy/interpreter_defs.h"
00032 #include "simlpy/interpreter_hooks.h"
00033 
00034 #include "DumpConsumer.h"
00035 #include "dtn/Bundle.h"
00036 #include "dtn/Node.h"
00037 #include "simlpy/Clock.h"
00038 #include "simlpy/SimulationException.h"
00039 
00040 #include <iostream>
00041 #include <netinet/in.h>
00042 
00043 void
00044 DumpConsumer::operator()( const DTN::Bundle& b )
00045 {
00046    if ( 0 == m_owner ) return;
00047 
00048    if ( 0 == verbosity() ) return;
00049 
00050    const DTN::ByteString& addr = m_owner->addr();
00051    std::cout << "(t=" << Clock::time() << ") node";
00052    for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00053    {
00054       ::printf(" %02X",addr[i]);
00055    }
00056 
00057    if ( DTN::Bundle::kACK & b.type() )
00058    {
00059       std::cout << " received an ACK for " << ntohl(b.seqNum());
00060    }
00061    else if ( DTN::Bundle::kData & b.type() )
00062    {
00063       std::cout << " consuming data bundle "
00064                 << ntohl(b.seqNum())
00065                 << " from";
00066       const DTN::ByteString& saddr = b.source();
00067       for ( unsigned int i = 0 ; i < saddr.length() ; ++i )
00068       {
00069          ::printf(" %02X",saddr[i]);
00070       }
00071       std::cout << "\n";
00072       std::cout << "   " << b.payload().length() << " bytes\n";
00073       std::cout << "   ";
00074       for ( unsigned int i = 0 ; i < b.payload().length() ; ++i )
00075       {
00076          ::printf("%02X ",b.payload()[i]);
00077       }
00078    }
00079    else
00080    {
00081       std::cout << " UNKNOWN BUNDLE TYPE";
00082    }
00083 
00084    std::cout << std::endl;
00085 }
00086 
00087 void
00088 DumpConsumer::drop( const DTN::Bundle& b, const DTN::DropCause& c )
00089 {
00090    if ( 0 == m_owner ) return;
00091    if ( verbosity() > 0 )
00092    {
00093       const DTN::ByteString& addr = m_owner->addr();
00094       std::cout << "(t="
00095                 << Clock::time()
00096                 << ") dropping bundle of size " << b.size()
00097                 << " at node";
00098       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00099       {
00100          ::printf(" %02X",addr[i]);
00101       }
00102       if ( verbosity() >= 2 )
00103       {
00104          std::cout << " (" << dropCauseString(c) << ")";
00105       }
00106       std::cout << std::endl;
00107    }
00108 }
00109 
00110 void
00111 DumpConsumer::custody( const DTN::Bundle& b )
00112 {
00113    if ( 0 == m_owner ) return;
00114    if ( verbosity() > 0 )
00115    {
00116       const DTN::ByteString& addr = m_owner->addr();
00117       std::cout << "(t="
00118                 << Clock::time()
00119                 << ") accepting custody of bundle of size " << b.size()
00120                 << " at node";
00121       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00122       {
00123          ::printf(" %02X",addr[i]);
00124       }
00125       std::cout << std::endl;
00126    }
00127 }
00128 
00129 void
00130 DumpConsumer::persistentStore( const DTN::Bundle& b )
00131 {
00132    if ( 0 == m_owner ) return;
00133    if ( verbosity() > 0 )
00134    {
00135       const DTN::ByteString& addr = m_owner->addr();
00136       std::cout << "(t=" << Clock::time() << ") node";
00137       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00138       {
00139             ::printf(" %02X",addr[i]);
00140       }
00141       std::cout << " stored a bundle";
00142       if ( verbosity() > 1 )
00143       {
00144          std::cout <<", persistent store now " << m_owner->usedPersistentCap() << " bytes";
00145       }
00146       std::cout << std::endl;
00147    }
00148 }
00149 
00150 void
00151 DumpConsumer::persistentRemove( const DTN::Bundle& b, bool cleanup )
00152 {
00153    if ( 0 == m_owner ) return;
00154    if ( verbosity() > 0 )
00155    {
00156       const DTN::ByteString& addr = m_owner->addr();
00157       std::cout << "(t=" << Clock::time() << ") node";
00158       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00159       {
00160          ::printf(" %02X",addr[i]);
00161       }
00162       std::cout << " deleted a bundle";
00163       if ( verbosity() > 1 )
00164       {
00165          // Never clean the persistent store here.
00166          std::cout <<", persistent store now "
00167                    << m_owner->usedPersistentCap(false) << " bytes";
00168       }
00169       std::cout << std::endl;
00170    }
00171 }
00172 
00173 void
00174 DumpConsumer::send( const DTN::Bundle& b )
00175 {
00176    if ( 0 == m_owner ) return;
00177    if ( verbosity() > 0 )
00178    {
00179       const DTN::ByteString& addr = m_owner->addr();
00180       std::cout << "(t="
00181                 << Clock::time()
00182                 << ") sending "
00183                 << b.size()
00184                 << " bytes from ";
00185       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00186       {
00187          ::printf("%02X ",addr[i]);
00188       }
00189       std::cout << "to ";
00190       const DTN::ByteString& recv = b.recv();
00191       for ( unsigned int i = 0 ; i < recv.length() ; ++i )
00192       {
00193          ::printf("%02X ",recv[i]);
00194       }
00195       std::cout << std::endl;
00196    }
00197 }
00198 
00199 void
00200 DumpConsumer::recv( const DTN::Bundle& b )
00201 {
00202    if ( 0 == m_owner ) return;
00203    if ( verbosity() > 0 )
00204    {
00205       const DTN::ByteString& addr = m_owner->addr();
00206       unsigned int data_size = b.size();
00207       std::cout << "(t="
00208                 << Clock::time()
00209                 << ") received "
00210                 << data_size
00211                 << " bytes at ";
00212       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00213       {
00214          ::printf("%02X ",addr[i]);
00215       }
00216       std::cout <<"from ";
00217       const DTN::ByteString& sender = b.send();
00218       for ( unsigned int i = 0 ; i < sender.length() ; ++i )
00219       {
00220          ::printf("%02X ",sender[i]);
00221       }
00222       if ( verbosity() >= 2 )
00223       {
00224          if ( b.type() & DTN::Bundle::kBcast )
00225          {
00226             std::cout << " (broadcast)";
00227          }
00228       }
00229       std::cout << std::endl;
00230    }
00231 
00232 }
00233 
00234 void
00235 DumpConsumer::exhausted( const DTN::Bundle& b )
00236 {
00237    if ( 0 == m_owner ) return;
00238    if ( verbosity() > 0 )
00239    {
00240       const DTN::ByteString& addr = m_owner->addr();
00241       unsigned int data_size = b.size();
00242       std::cout << "(t="
00243                 << Clock::time()
00244                 << ") exhausted storage at ";
00245       for ( unsigned int i = 0 ; i < addr.length() ; ++i )
00246       {
00247          ::printf("%02X ",addr[i]);
00248       }
00249       std::cout << std::endl;
00250    }
00251 
00252 }
00253 
00254 std::string
00255 DumpConsumer::dropCauseString( const DTN::DropCause& c )
00256 {
00257    std::string retval = "unknown";
00258    if ( DTN::BitErrorDrop::inst.isType(c) )
00259    {
00260       retval = "bit error";
00261    }
00262    else if ( DTN::CustodyPolicyDrop::inst.isType(c) )
00263    {
00264       retval = "custody policy violation";
00265    }
00266    else if ( DTN::ExpiryDrop::inst.isType(c) )
00267    {
00268       retval = "bundle expired";
00269    }
00270    else if ( DTN::FullQueueDrop::inst.isType(c) )
00271    {
00272       retval = "queue is full";
00273    }
00274    else if ( DTN::LinkFailureDrop::inst.isType(c) )
00275    {
00276       retval = "link failed";
00277    }
00278    else if ( DTN::NoRouteDrop::inst.isType(c) )
00279    {
00280       retval = "no route found";
00281    }
00282    return retval;
00283 }

Generated on Mon Mar 24 11:15:46 2008 for Pydtn Simulator by  doxygen 1.5.4