MessageObserver.h

Go to the documentation of this file.
00001 //
00002 // This program is free software; you can redistribute it and/or
00003 // modify it under the terms of the GNU General Public License
00004 // as published by the Free Software Foundation; either version 2
00005 // of the License, or (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License
00013 // along with this program; if not, write to the Free Software
00014 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015 //
00016 
00022 #ifndef __MESSAGEOBSERVER_H__
00023 #define __MESSAGEOBSERVER_H__
00024 
00025 #include <stdint.h>
00026 #include <time.h>
00027 #include <ostream>
00028 #include <omnetpp.h>
00029 #include "OverlayKey.h"
00030 
00031 class ALMTestTracedMessage;
00032 
00033 class MessageObserver : public cSimpleModule {
00034 
00035     public:
00036 
00037         MessageObserver();
00038         ~MessageObserver();
00039 
00040         void initialize();
00041 
00042         void finish();
00043 
00044         void handleMessage(cMessage* msg);
00045 
00049         void joinedGroup(int moduleId, OverlayKey groupId);
00050 
00054         void leftGroup(int moduleId, OverlayKey groupId);
00055 
00060         void sentMessage(ALMTestTracedMessage* msg);
00061 
00065         void receivedMessage(ALMTestTracedMessage* msg);
00066 
00070         void nodeDead(int moduleId);
00071 
00072     private:
00073 
00074         /*
00075          * Tracks data related to a single group
00076          */
00077         struct MulticastGroup {
00078             MulticastGroup() : size(0), sent(0), received(0) {}
00079 
00080             // Number of nodes in the group
00081             uint32_t size;
00082 
00083             // Number of messages that should have been received
00084             uint64_t sent;
00085 
00086             // Number of messages recieved total by all nodes
00087             uint64_t received;
00088 
00089         };
00090 
00091         simtime_t creationTime;
00092 
00093         typedef std::pair<int, OverlayKey> NodeGroupPair;
00094 
00095         typedef std::pair<int, long> NodeMessagePair;
00096 
00097         // Info about a specific group
00098         std::map<OverlayKey, MulticastGroup> groups;
00099 
00100         // When a node joined a given group
00101         std::map<NodeGroupPair, simtime_t> joinedAt;
00102 
00103         // When a node received a given message
00104         std::map<NodeMessagePair, simtime_t> receivedAt;
00105 
00106         // Periodically clean up the above map. Set to 0 to disable.
00107         cMessage* gcTimer;
00108 
00109         // How often to clean up
00110         double gcInterval;
00111 
00112         // How long data will be kept in the received cache
00113         double cacheMaxAge;
00114 
00115         // How many messages have been received by their sender (have looped)
00116         int numLooped;
00117 
00118         GlobalStatistics* globalStatistics;
00119 
00120         friend std::ostream& operator<< (std::ostream& os, MessageObserver::MulticastGroup const & mg);
00121         friend std::ostream& operator<< (std::ostream& os, MessageObserver::NodeGroupPair const & ngp);
00122 };
00123 
00124 std::ostream& operator<< (std::ostream& os, MessageObserver::MulticastGroup const & mg);
00125 std::ostream& operator<< (std::ostream& os, MessageObserver::NodeGroupPair const & ngp);
00126 
00127 #endif