NamTracer.h

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 #ifndef __NAM_TRACE_NAM_TRACER_H__
00032 #define __NAM_TRACE_NAM_TRACER_H__
00033 
00034 #include "config.h"
00035 
00036 #include "pydtn/Tracer.h"
00037 #include "simlpy/Entity.h"
00038 #include "simlpy/Event.h"
00039 #include "dtn/ByteString.h"
00040 #include <map>
00041 #include <set>
00042 #include <ostream>
00043 
00046 
00047 class NamTracer;
00048 
00053 class NamTraceEvent : public Event
00054 {
00055    public :
00061       NamTraceEvent( Entity* source,
00062                      NamTracer* destination,
00063                      const Time& t ) :
00064          Event( source, t ),
00065          m_destination( destination )
00066       {}
00067 
00069       virtual ~NamTraceEvent() {}
00070 
00071       bool handle();
00072 
00073    private :
00074       NamTracer* m_destination;
00075 };
00076 
00078 class NamTracer : public Tracer, public Entity
00079 {
00080    public :
00082       typedef std::map< DTN::ByteString , int >  NodeIDMap;
00084       typedef std::set< const WrapNode* > NodeSet;
00086       typedef std::set< const WrapLink* > LinkSet;
00087 
00090       NamTracer( std::ostream& s );
00092       virtual ~NamTracer();
00093 
00096       void setQueueState( bool q ) { m_queueState = q; }
00097 
00100       void node( const WrapNode& wn );
00101 
00104       void link( const WrapLink& wl );
00105 
00109       void enqueue( const DTN::Bundle& b, const DTN::Node* n );
00110 
00114       void dequeue( const DTN::Bundle& b, const DTN::Node* n );
00115 
00119       void send( const DTN::Bundle& b, const DTN::Node* n );
00120 
00124       void receive( const DTN::Bundle& b, const DTN::Node* n );
00125 
00130       void drop( const DTN::Bundle& b,
00131                  const DTN::DropCause& c,
00132                  const DTN::Node* n );
00133 
00135       Entity* create() const { return 0; }
00137       void configure( const ArgList& args ) {}
00139       void emit( const ArgList& args ) {}
00141       bool handler( NamTraceEvent& event );
00143       std::string identifier() const { return "namtrace"; }
00144 
00145    protected :
00149       void traceNode( const WrapNode& wn, bool initial = false );
00150 
00154       void traceLink( const WrapLink& wl, bool initial = false );
00155 
00158       void traceBundle( const DTN::Bundle& b );
00159 
00164       int nodeID( const WrapNode& wn );
00165 
00170       int nodeID( const DTN::ByteString& addr );
00171 
00175       DTN::ByteString vQueue( const WrapNode& wn );
00176 
00180       DTN::ByteString vQueue( const DTN::ByteString& addr );
00181 
00187       double time( const Time& t );
00188 
00195       std::string stringify( const DTN::ByteString& b ) const;
00196 
00197    private :
00198       std::ostream&  m_stream;
00199       int            m_lastNode;
00200       NodeIDMap      m_nodes;
00201       bool           m_queueState;
00202       bool           m_tracing;
00203       bool           m_notified;
00204       NodeSet        m_nodeSet;
00205       LinkSet        m_linkSet;
00206 };
00207 
00209 
00210 #endif // __NAM_TRACE_NAM_TRACER_H__

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