00001 // 00002 // Copyright (C) 2005 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 00019 #ifndef __INET_THRUPUTMETER_H 00020 #define __INET_THRUPUTMETER_H 00021 00022 #include <omnetpp.h> 00023 #include "INETDefs.h" 00024 00025 00029 // FIXME problem: if traffic suddenly stops, it'll show the last reading forever; 00030 // (output vector will be correct though); would need a timer to handle this situation 00031 class INET_API ThruputMeter : public cSimpleModule 00032 { 00033 protected: 00034 // config 00035 simtime_t startTime; // start time 00036 unsigned int batchSize; // number of packets in a batch 00037 simtime_t maxInterval; // max length of measurement interval (measurement ends 00038 // if either batchSize or maxInterval is reached, whichever 00039 // is reached first) 00040 00041 // global statistics 00042 unsigned long numPackets; 00043 unsigned long numBits; 00044 00045 // current measurement interval 00046 simtime_t intvlStartTime; 00047 simtime_t intvlLastPkTime; 00048 unsigned long intvlNumPackets; 00049 unsigned long intvlNumBits; 00050 00051 // statistics 00052 cOutVector bitpersecVector; 00053 cOutVector pkpersecVector; 00054 00055 protected: 00056 virtual void updateStats(simtime_t now, unsigned long bits); 00057 virtual void beginNewInterval(simtime_t now); 00058 00059 protected: 00060 virtual void initialize(); 00061 virtual void handleMessage(cMessage *msg); 00062 virtual void finish(); 00063 }; 00064 00065 #endif 00066