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 __WRAPPERS_HARNESS_STATISTICS_H__ 00032 #define __WRAPPERS_HARNESS_STATISTICS_H__ 00033 00034 #include "config.h" 00035 00036 #include "dtn/Consumer.h" 00037 #include "dtn/ByteString.h" 00038 #include "Sequencer.h" 00039 #include <map> 00040 #include <set> 00041 00044 00046 class Stat 00047 { 00048 public : 00050 Stat() : m_n(0), m_s(0), m_w(0) {} 00052 ~Stat() {} 00053 00055 unsigned long n() const { return m_n; } 00057 unsigned long s() const { return m_s; } 00059 unsigned long w() const { return m_w; } 00060 00062 double mean() const; 00064 double var() const; 00066 double sigma() const; 00067 00069 void add( unsigned long val ); 00071 void reset(); 00072 00073 private : 00074 unsigned long m_n; 00075 unsigned long m_s; 00076 unsigned long m_w; 00077 }; 00078 00080 class UniqueStat 00081 { 00082 public : 00084 typedef std::map< DTN::ByteString , Sequencer > BundleMap; 00085 00087 UniqueStat(); 00089 virtual ~UniqueStat(); 00090 00092 void add( const DTN::Bundle& b ); 00094 void reset(); 00095 00097 const Stat& unique() const { return m_unique; } 00099 const Stat& duplicate() const { return m_duplicate; } 00100 00101 private : 00102 Stat m_unique; 00103 Stat m_duplicate; 00104 BundleMap m_seen; 00105 }; 00106 00108 class StatCollection 00109 { 00110 public : 00112 StatCollection() : m_exhausted(false) {} 00113 00115 const UniqueStat& originated() const { return m_originated; } 00117 const Stat& sent() const { return m_sent; } 00119 const Stat& received() const { return m_received; } 00121 const UniqueStat& delivered() const { return m_delivered; } 00123 const Stat& deliverHops() const { return m_deliverHops; } 00125 const Stat& dropped() const { return m_dropped; } 00127 const Stat& dropHops() const { return m_dropHops; } 00129 bool exhausted() const { return m_exhausted; } 00130 00132 void addOriginated( const DTN::Bundle& b ); 00134 void addSent( unsigned long int val ); 00136 void addReceived( unsigned long int val ); 00138 void addDelivered( const DTN::Bundle& b ); 00140 void addDropped( const DTN::Bundle& b ); 00142 void setExhausted() { m_exhausted = true; } 00143 00145 void reset(); 00146 00147 private : 00148 UniqueStat m_originated; 00149 Stat m_sent; 00150 Stat m_received; 00151 UniqueStat m_delivered; 00152 Stat m_deliverHops; 00153 Stat m_dropped; 00154 Stat m_dropHops; 00155 bool m_exhausted; 00156 }; 00157 00160 class Statistics : public DTN::Consumer 00161 { 00162 public : 00164 Statistics( DTN::Node* owner ); 00166 virtual ~Statistics(); 00167 00170 virtual void operator()( const DTN::Bundle& b ); 00171 00175 virtual void drop( const DTN::Bundle& b, const DTN::DropCause& c ); 00176 00179 virtual void custody( const DTN::Bundle& b ); 00180 00183 virtual void persistentStore( const DTN::Bundle& b ); 00184 00190 virtual void persistentRemove( const DTN::Bundle& b, bool cleanup=true ); 00191 00194 virtual void send( const DTN::Bundle& b ); 00195 00198 virtual void recv( const DTN::Bundle& b ); 00199 00202 virtual void exhausted( const DTN::Bundle& b ); 00203 00205 const StatCollection& since() const { return m_since; } 00206 00208 const StatCollection& total() const { return m_total; } 00209 00212 void reset() { m_since.reset(); } 00213 00216 void resetTotals() { m_since.reset(); m_total.reset(); } 00217 00220 virtual unsigned long int used() const; 00223 virtual unsigned long int capacity() const; 00224 00225 protected : 00230 void testOrigin( const DTN::Bundle& b ); 00231 00233 StatCollection m_total; 00235 StatCollection m_since; 00236 }; 00237 00239 00240 #endif /* __WRAPPERS_HARNESS_STATISTICS_H__ */
1.5.4