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 
00067     private:
00068 
00069         /*
00070          * Tracks data related to a single group
00071          */
00072         struct MulticastGroup {
00073             MulticastGroup() : size(0), sent(0), received(0) {}
00074 
00075             // Number of nodes in the group
00076             uint32_t size;
00077 
00078             // Number of messages that should have been received
00079             uint64_t sent;
00080 
00081             // Number of messages recieved total by all nodes
00082             uint64_t received;
00083 
00084         };
00085 
00086         typedef std::pair<int, OverlayKey> NodeGroupPair;
00087 
00088         typedef std::pair<int, long> NodeMessagePair;
00089 
00090         // Info about a specific group
00091         std::map<OverlayKey, MulticastGroup> groups;
00092 
00093         // When a node joined a given group
00094         std::map<NodeGroupPair, simtime_t> joinedAt;
00095 
00096         // When a node received a given message
00097         std::map<NodeMessagePair, simtime_t> receivedAt;
00098 
00099         // Periodically clean up the above map. Set to 0 to disable.
00100         cMessage* gcTimer;
00101 
00102         // How often to clean up
00103         double gcInterval;
00104 
00105         // How long data will be kept in the received cache
00106         double cacheMaxAge;
00107 
00108         friend std::ostream& operator<< (std::ostream& os, MessageObserver::MulticastGroup const & mg);
00109         friend std::ostream& operator<< (std::ostream& os, MessageObserver::NodeGroupPair const & ngp);
00110 };
00111 
00112 std::ostream& operator<< (std::ostream& os, MessageObserver::MulticastGroup const & mg);
00113 std::ostream& operator<< (std::ostream& os, MessageObserver::NodeGroupPair const & ngp);
00114 
00115 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3