OverSim
SearchMsgBookkeeping.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 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 #include "SearchMsgBookkeeping.h"
25 
26 
28 {
29  // virtual dectructor
30 }
31 
33 {
34  return messages.size();
35 }
36 
38 {
39  SearchMessageItem item;
40  item.searchKey = searchKey;
41  item.creationTime = simTime();
42  item.minDelay = 0;
43  item.maxDelay = 0;
44  item.minHopCount = 0;
45  item.maxHopCount = 0;
46  item.responseCount = 0;
47  messages[searchKey] = item;
48 }
49 
51 {
52  SearchBookkeepingListIterator it = messages.find(searchKey);
53 
54  if(it->first == searchKey)
55  messages.erase(it);
56 }
57 
58 bool SearchMsgBookkeeping::contains(const OverlayKey& searchKey) const
59 {
60  SearchBookkeepingListConstIterator it = messages.find(searchKey);
61  return (it != messages.end());
62 }
63 
65  uint32_t hopCount)
66 {
67  SearchBookkeepingListIterator it = messages.find(searchKey);
68  SearchMessageItem currentItem;
69 
70  if(it->first == searchKey) {
71  currentItem = it->second;
72  simtime_t currentTime = simTime();
73 
74  simtime_t delay = currentTime - currentItem.creationTime;
75 
76  // initialize first minDelay
77  if (currentItem.minDelay == 0)
78  currentItem.minDelay = delay;
79  // initialize first minHopCount
80  if (currentItem.minHopCount == 0)
81  currentItem.minHopCount = hopCount;
82 
83  if (delay < currentItem.minDelay)
84  currentItem.minDelay = delay;
85  if (delay > currentItem.maxDelay)
86  currentItem.maxDelay = delay;
87 
88  if (hopCount < currentItem.minHopCount)
89  currentItem.minHopCount = hopCount;
90  if (hopCount > currentItem.maxHopCount)
91  currentItem.maxHopCount = hopCount;
92 
93  currentItem.responseCount++;
94 
95  it->second = currentItem;
96  }
97 }
98 
100 {
101  SearchMessageItem currentItem;
102  GiaSearchStats temp = {0, 0, 0, 0, 0};
103 
104  uint32_t size = messages.size();
105 
106  if (size == 0) return temp;
107 
109  it != messages.end(); it++) {
110  currentItem = it->second;
111  temp.minDelay += (float)SIMTIME_DBL(currentItem.minDelay);
112  temp.maxDelay += (float)SIMTIME_DBL(currentItem.maxDelay);
113  temp.minHopCount += currentItem.minHopCount;
114  temp.maxHopCount += currentItem.maxHopCount;
115  temp.responseCount += currentItem.responseCount;
116  }
117 
118  temp.minDelay /= size;
119  temp.maxDelay /= size;
120  temp.minHopCount /= size;
121  temp.maxHopCount /= size;
122  temp.responseCount /= size;
123 
124  return temp;
125 }