author | Tom Henderson <tomh@tomh.org> |
Sun, 13 May 2012 10:47:11 -0700 | |
changeset 8756 | 9a34e618f40b |
parent 8752 | 2da1fab73114 |
child 9719 | 4031f7fdce5c |
permissions | -rw-r--r-- |
8752 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2011 Yufei Cheng |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
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 |
* Author: Yufei Cheng <yfcheng@ittc.ku.edu> |
|
19 |
* |
|
20 |
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
|
21 |
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
|
22 |
* Information and Telecommunication Technology Center (ITTC) |
|
23 |
* and Department of Electrical Engineering and Computer Science |
|
24 |
* The University of Kansas Lawrence, KS USA. |
|
25 |
* |
|
26 |
* Work supported in part by NSF FIND (Future Internet Design) Program |
|
27 |
* under grant CNS-0626918 (Postmodern Internet Architecture), |
|
28 |
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI), |
|
29 |
* US Department of Defense (DoD), and ITTC at The University of Kansas. |
|
30 |
*/ |
|
31 |
||
32 |
#include "dsr-network-queue.h" |
|
33 |
#include "ns3/test.h" |
|
34 |
#include <algorithm> |
|
35 |
#include <functional> |
|
36 |
#include <map> |
|
37 |
#include "ns3/log.h" |
|
38 |
#include "ns3/ipv4-route.h" |
|
39 |
#include "ns3/socket.h" |
|
40 |
||
41 |
NS_LOG_COMPONENT_DEFINE ("DsrNetworkQueue"); |
|
42 |
||
43 |
namespace ns3 { |
|
44 |
namespace dsr { |
|
45 |
||
46 |
NS_OBJECT_ENSURE_REGISTERED (DsrNetworkQueue); |
|
47 |
||
48 |
TypeId |
|
49 |
DsrNetworkQueue::GetTypeID (void) |
|
50 |
{ |
|
51 |
static TypeId tid = TypeId ("ns3::dsr::DsrNetworkQueue") |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
52 |
.SetParent<Object> () |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
53 |
.AddConstructor<DsrNetworkQueue> () |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
54 |
; |
8752 | 55 |
return tid; |
56 |
} |
|
57 |
||
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
58 |
DsrNetworkQueue::DsrNetworkQueue (uint32_t maxLen, Time maxDelay) |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
59 |
: m_size (0), |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
60 |
m_maxSize (maxLen), |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
61 |
m_maxDelay (maxDelay) |
8752 | 62 |
{ |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
63 |
NS_LOG_FUNCTION (this ); |
8752 | 64 |
} |
65 |
||
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
66 |
DsrNetworkQueue::DsrNetworkQueue () : m_size (0) |
8752 | 67 |
{ |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
68 |
NS_LOG_FUNCTION (this ); |
8752 | 69 |
} |
70 |
||
71 |
DsrNetworkQueue::~DsrNetworkQueue () |
|
72 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
73 |
NS_LOG_FUNCTION (this ); |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
74 |
Flush (); |
8752 | 75 |
} |
76 |
||
77 |
void |
|
78 |
DsrNetworkQueue::SetMaxNetworkSize (uint32_t maxSize) |
|
79 |
{ |
|
80 |
m_maxSize = maxSize; |
|
81 |
} |
|
82 |
||
83 |
void |
|
84 |
DsrNetworkQueue::SetMaxNetworkDelay (Time delay) |
|
85 |
{ |
|
86 |
m_maxDelay = delay; |
|
87 |
} |
|
88 |
||
89 |
uint32_t |
|
90 |
DsrNetworkQueue::GetMaxNetworkSize (void) const |
|
91 |
{ |
|
92 |
return m_maxSize; |
|
93 |
} |
|
94 |
||
95 |
Time |
|
96 |
DsrNetworkQueue::GetMaxNetworkDelay (void) const |
|
97 |
{ |
|
98 |
return m_maxDelay; |
|
99 |
} |
|
100 |
||
101 |
bool |
|
102 |
DsrNetworkQueue::Enqueue (DsrNetworkQueueEntry & entry) |
|
103 |
{ |
|
104 |
NS_LOG_FUNCTION (this << m_size << m_maxSize); |
|
105 |
if (m_size >= m_maxSize) |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
106 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
107 |
return false; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
108 |
} |
8752 | 109 |
Time now = Simulator::Now (); |
110 |
entry.SetInsertedTimeStamp (now); |
|
111 |
m_dsrNetworkQueue.push_back (entry); |
|
112 |
m_size++; |
|
113 |
NS_LOG_DEBUG ("The network queue size for now " << m_size); |
|
114 |
return true; |
|
115 |
} |
|
116 |
||
117 |
bool |
|
118 |
DsrNetworkQueue::Dequeue (DsrNetworkQueueEntry & entry) |
|
119 |
{ |
|
120 |
NS_LOG_FUNCTION (this); |
|
121 |
Cleanup (); |
|
122 |
std::vector<DsrNetworkQueueEntry>::iterator i = m_dsrNetworkQueue.begin (); |
|
123 |
if (i == m_dsrNetworkQueue.end ()) |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
124 |
{ |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
125 |
// no elements in array |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
126 |
NS_LOG_DEBUG ("Does not find the queued packet in the network queue"); |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
127 |
return false; |
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
128 |
} |
8752 | 129 |
entry = *i; |
130 |
m_dsrNetworkQueue.erase (i); |
|
131 |
m_size--; |
|
132 |
return true; |
|
133 |
} |
|
134 |
||
135 |
void |
|
136 |
DsrNetworkQueue::Cleanup (void) |
|
137 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
138 |
NS_LOG_FUNCTION (this); |
8752 | 139 |
if (m_dsrNetworkQueue.empty ()) |
140 |
{ |
|
141 |
return; |
|
142 |
} |
|
143 |
||
144 |
Time now = Simulator::Now (); |
|
145 |
uint32_t n = 0; |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
146 |
for (std::vector<DsrNetworkQueueEntry>::iterator i = m_dsrNetworkQueue.begin (); i != m_dsrNetworkQueue.end (); ) |
8752 | 147 |
{ |
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
148 |
if (i->GetInsertedTimeStamp () + m_maxDelay > now) |
8752 | 149 |
{ |
150 |
i++; |
|
151 |
} |
|
152 |
else |
|
153 |
{ |
|
154 |
i = m_dsrNetworkQueue.erase (i); |
|
155 |
n++; |
|
156 |
} |
|
157 |
} |
|
158 |
m_size -= n; |
|
159 |
} |
|
160 |
||
161 |
uint32_t |
|
162 |
DsrNetworkQueue::GetSize () |
|
163 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
164 |
NS_LOG_FUNCTION (this); |
8752 | 165 |
return m_size; |
166 |
} |
|
167 |
||
168 |
void |
|
169 |
DsrNetworkQueue::Flush (void) |
|
170 |
{ |
|
8756
9a34e618f40b
check-style.py run on src/dsr
Tom Henderson <tomh@tomh.org>
parents:
8752
diff
changeset
|
171 |
NS_LOG_FUNCTION (this); |
8752 | 172 |
m_dsrNetworkQueue.erase (m_dsrNetworkQueue.begin (), m_dsrNetworkQueue.end ()); |
173 |
m_size = 0; |
|
174 |
} |
|
175 |
||
176 |
} // namespace dsr |
|
177 |
} // namespace ns3 |