Scribe.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU 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 General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #ifndef __SCRIBE_H_
00026 #define __SCRIBE_H_
00027 
00028 #include <map>
00029 #include <string>
00030 
00031 #include "BaseApp.h"
00032 #include "CommonMessages_m.h"
00033 #include "GlobalNodeList.h"
00034 #include "NodeHandle.h"
00035 
00036 #include "ScribeGroup.h"
00037 #include "ScribeMessage_m.h"
00038 
00039 // Output function for grouplist, needed for WATCH
00040 std::ostream& operator<< (std::ostream& o, std::map<OverlayKey, ScribeGroup> m )
00041 {
00042     for (std::map<OverlayKey, ScribeGroup>::iterator it = m.begin(); it != m.end(); ++it) {
00043         o << it->first << "\n";
00044         o << "  Parent: " << it->second.getParent() << "\n";
00045         o << "  Status: " << (it->second.getSubscription() ? "Subscriber\n" : "Forwarder\n");
00046         o << "  Children (" << it->second.numChildren() << "):\n";
00047         std::set<NodeHandle>::iterator iit = it->second.getChildrenBegin();
00048         for (int i = it->second.numChildren(); i > 0; --i) {
00049             o << "    " << *iit << "\n";
00050             ++iit;
00051         }
00052     }
00053     return o;
00054 }
00055 
00056 
00057 class Scribe : public BaseApp
00058 {
00059     private:
00060         typedef std::map<OverlayKey, ScribeGroup> GroupList;
00061         GroupList groupList;
00062         typedef std::multimap<NodeHandle, ScribeTimer*> ChildTimeoutList;
00063         ChildTimeoutList childTimeoutList;
00064 
00065         int childTimeout;
00066         int parentTimeout;
00067 
00068         ScribeTimer* subscriptionTimer;
00069 
00070         // statistics
00071         int numJoins;
00072         int numChildTimeout;
00073         int numParentTimeout;
00074         int numForward;
00075         int forwardBytes;
00076         int numReceived;
00077         int receivedBytes;
00078         int numHeartbeat;
00079         int heartbeatBytes;
00080         int numSubscriptionRefresh;
00081         int subscriptionRefreshBytes;
00082 
00083     public:
00084         Scribe( );
00085         ~Scribe( );
00086 
00087         // see BaseOverlay.h
00088         virtual void initializeApp( int stage );
00089 
00090         virtual void handleUpperMessage( cMessage *msg );
00091         virtual void handleReadyMessage( CompReadyMessage* msg );
00092 
00093         virtual void handleTimerEvent( cMessage *msg );
00094 
00095         virtual bool handleRpcCall( BaseCallMessage* msg );
00096         virtual void handleRpcResponse( BaseResponseMessage* msg,
00097                                         cPolymorphic* context,
00098                                         int rpcId, simtime_t rtt );
00099 
00100         virtual void forward(OverlayKey* key, cPacket** msg,
00101                 NodeHandle* nextHopNode);
00102 
00103         virtual void deliver(OverlayKey& key, cMessage* msg);
00104         virtual void update( const NodeHandle& node, bool joined );
00105 
00106         virtual void finishApp( );
00107 
00108     protected:
00112         void handleJoinResponse( ScribeJoinResponse* joinResponse );
00113 
00121         void handleJoinCall( ScribeJoinCall* joinMsg);
00122 
00129         void handlePublishCall( ScribePublishCall* publishCall );
00130 
00137         void handlePublishResponse( ScribePublishResponse* publishResponse );
00138 
00142         void handleJoinMessage( ScribeJoinCall* joinMsg, bool amIRoot);
00143 
00147         void handleLeaveMessage( ScribeLeaveMessage* leaveMsg );
00148 
00154         void subscribeToGroup( const OverlayKey& groupId );
00155 
00161         void leaveGroup( const OverlayKey& group );
00162 
00170         void startTimer( ScribeTimer* timer );
00171 
00175         void addChildToGroup( const NodeHandle& child, ScribeGroup& group );
00176 
00180         void removeChildFromGroup( const NodeHandle& child, ScribeGroup& group );
00181 
00188         void removeChildFromGroup( ScribeTimer* timer );
00189 
00193         void checkGroupEmpty( ScribeGroup& group );
00194 
00201         void refreshChildTimer( NodeHandle& child, OverlayKey& groupId );
00202 
00206         void deliverALMDataToGroup( ScribeDataMessage* dataMsg );
00207 
00214         void deliverALMDataToRoot( ALMMulticastMessage* mcastMsg );
00215 };
00216 
00217 #endif
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3