OverSim
GlobalDhtTestMap.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __GLOBAL_DHT_TEST_MAP_H__
25 #define __GLOBAL_DHT_TEST_MAP_H__
26 
27 #include <map>
28 
29 #include <omnetpp.h>
30 
31 #include <OverlayKey.h>
32 #include <BinaryValue.h>
33 
34 class GlobalStatistics;
35 
36 struct DHTEntry
37 {
39  simtime_t endtime;
40  simtime_t insertiontime;
41  friend std::ostream& operator<<(std::ostream& Stream, const DHTEntry entry);
42 };
43 
50 class GlobalDhtTestMap : public cSimpleModule
51 {
52 public:
55 
56  /*
57  * Insert a new key/value pair into global list of all currently
58  * stored DHT records.
59  *
60  * @param key The key of the record
61  * @param entry The value and TTL of the record
62  */
63  void insertEntry(const OverlayKey& key, const DHTEntry& entry);
64 
65  /*
66  * Returns the value and TTL for a given key from the global
67  * list of all currently stored DHT records.
68  *
69  * @param key The key of the record
70  * @return The value and TTL of the record, NULL if no records was found
71  */
72  const DHTEntry* findEntry(const OverlayKey& key);
73 
74  /*
75  * Erase the key/value pair with the given key from the global list of
76  * all currently stored DHT records.
77  *
78  * @param key The key of the record
79  */
80  void eraseEntry(const OverlayKey& key);
81 
82  /*
83  * Returns the key of a random currently stored DHT record from the global
84  * list of all currently stored DHT records.
85  *
86  * @return The key of the record, OverlayKey::UNSPECIFIED_KEY if the
87  * global list is empty
88  */
89  const OverlayKey& getRandomKey();
90 
91  size_t size() { return dataMap.size(); };
92  uint32_t p2pnsNameCount;
93 
94 private:
95  void initialize();
96  void handleMessage(cMessage* msg);
97  void finish();
98 
99  static const int TEST_MAP_INTERVAL = 10;
102  std::map<OverlayKey, DHTEntry> dataMap;
103  cMessage *periodicTimer;
104 };
105 
106 #endif