00001 // 00002 // Copyright (C) 2008 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 00024 #ifndef __GLOBAL_DHT_TEST_MAP_H__ 00025 #define __GLOBAL_DHT_TEST_MAP_H__ 00026 00027 #include <map> 00028 00029 #include <omnetpp.h> 00030 00031 #include <OverlayKey.h> 00032 #include <BinaryValue.h> 00033 00034 class GlobalStatistics; 00035 00036 struct DHTEntry 00037 { 00038 BinaryValue value; 00039 simtime_t endtime; 00040 friend std::ostream& operator<<(std::ostream& Stream, const DHTEntry entry); 00041 }; 00042 00049 class GlobalDhtTestMap : public cSimpleModule 00050 { 00051 public: 00052 GlobalDhtTestMap(); 00053 ~GlobalDhtTestMap(); 00054 00055 /* 00056 * Insert a new key/value pair into global list of all currently 00057 * stored DHT records. 00058 * 00059 * @param key The key of the record 00060 * @param entry The value and TTL of the record 00061 */ 00062 void insertEntry(const OverlayKey& key, const DHTEntry& entry); 00063 00064 /* 00065 * Returns the value and TTL for a given key from the global 00066 * list of all currently stored DHT records. 00067 * 00068 * @param key The key of the record 00069 * @return The value and TTL of the record, NULL if no records was found 00070 */ 00071 const DHTEntry* findEntry(const OverlayKey& key); 00072 00073 /* 00074 * Erase the key/value pair with the given key from the global list of 00075 * all currently stored DHT records. 00076 * 00077 * @param key The key of the record 00078 */ 00079 void eraseEntry(const OverlayKey& key); 00080 00081 /* 00082 * Returns the key of a random currently stored DHT record from the global 00083 * list of all currently stored DHT records. 00084 * 00085 * @return The key of the record, OverlayKey::UNSPECIFIED_KEY if the 00086 * global list is empty 00087 */ 00088 const OverlayKey& getRandomKey(); 00089 00090 size_t size() { return dataMap.size(); }; 00091 uint32_t p2pnsNameCount; 00092 00093 private: 00094 void initialize(); 00095 void handleMessage(cMessage* msg); 00096 void finish(); 00097 00098 static const int TEST_MAP_INTERVAL = 10; 00100 GlobalStatistics* globalStatistics; 00101 std::map<OverlayKey, DHTEntry> dataMap; 00102 cMessage *periodicTimer; 00103 }; 00104 00105 #endif