author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Tue, 15 Apr 2008 15:10:53 -0700 | |
changeset 2983 | e3a416fe9dd5 |
parent 2196 | fb01b99ce66d |
child 5858 | afb51c7f34c2 |
permissions | -rw-r--r-- |
1111 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1121
diff
changeset
|
3 |
* Copyright 2007 University of Washington |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1121
diff
changeset
|
4 |
* |
1111 | 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 |
||
1505 | 19 |
#include "ns3/log.h" |
1111 | 20 |
#include "ns3/assert.h" |
21 |
#include "candidate-queue.h" |
|
2196
fb01b99ce66d
Don't include the 'global-route-manager-impl.h' private header from the public header 'candidate-queue.h'.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1828
diff
changeset
|
22 |
#include "global-route-manager-impl.h" |
1111 | 23 |
|
1505 | 24 |
NS_LOG_COMPONENT_DEFINE ("CandidateQueue"); |
1111 | 25 |
|
26 |
namespace ns3 { |
|
27 |
||
28 |
CandidateQueue::CandidateQueue() |
|
29 |
: m_candidates () |
|
30 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
31 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 32 |
} |
33 |
||
34 |
CandidateQueue::~CandidateQueue() |
|
35 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
36 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 37 |
Clear (); |
38 |
} |
|
39 |
||
40 |
void |
|
41 |
CandidateQueue::Clear (void) |
|
42 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
43 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 44 |
while (!m_candidates.empty ()) |
45 |
{ |
|
46 |
SPFVertex *p = Pop (); |
|
47 |
delete p; |
|
48 |
p = 0; |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
void |
|
53 |
CandidateQueue::Push (SPFVertex *vNew) |
|
54 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
55 |
NS_LOG_FUNCTION (this << vNew); |
1111 | 56 |
|
57 |
CandidateList_t::iterator i = m_candidates.begin (); |
|
58 |
||
59 |
for (; i != m_candidates.end (); i++) |
|
60 |
{ |
|
61 |
SPFVertex *v = *i; |
|
62 |
if (vNew->GetDistanceFromRoot () < v->GetDistanceFromRoot ()) |
|
63 |
{ |
|
64 |
break; |
|
65 |
} |
|
66 |
} |
|
67 |
m_candidates.insert(i, vNew); |
|
68 |
} |
|
69 |
||
70 |
SPFVertex * |
|
71 |
CandidateQueue::Pop (void) |
|
72 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
73 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 74 |
if (m_candidates.empty ()) |
75 |
{ |
|
76 |
return 0; |
|
77 |
} |
|
78 |
||
79 |
SPFVertex *v = m_candidates.front (); |
|
80 |
m_candidates.pop_front (); |
|
81 |
return v; |
|
82 |
} |
|
83 |
||
84 |
SPFVertex * |
|
85 |
CandidateQueue::Top (void) const |
|
86 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
87 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 88 |
if (m_candidates.empty ()) |
89 |
{ |
|
90 |
return 0; |
|
91 |
} |
|
92 |
||
93 |
return m_candidates.front (); |
|
94 |
} |
|
95 |
||
96 |
bool |
|
97 |
CandidateQueue::Empty (void) const |
|
98 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
99 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 100 |
return m_candidates.empty (); |
101 |
} |
|
102 |
||
103 |
uint32_t |
|
104 |
CandidateQueue::Size (void) const |
|
105 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
106 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 107 |
return m_candidates.size (); |
108 |
} |
|
109 |
||
110 |
SPFVertex * |
|
111 |
CandidateQueue::Find (const Ipv4Address addr) const |
|
112 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
113 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 114 |
CandidateList_t::const_iterator i = m_candidates.begin (); |
115 |
||
116 |
for (; i != m_candidates.end (); i++) |
|
117 |
{ |
|
118 |
SPFVertex *v = *i; |
|
119 |
if (v->GetVertexId() == addr) |
|
120 |
{ |
|
121 |
return v; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
return 0; |
|
126 |
} |
|
127 |
||
128 |
void |
|
129 |
CandidateQueue::Reorder (void) |
|
130 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2196
diff
changeset
|
131 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 132 |
std::list<SPFVertex*> temp; |
133 |
||
134 |
while (!m_candidates.empty ()) { |
|
135 |
SPFVertex *v = m_candidates.front (); |
|
136 |
m_candidates.pop_front (); |
|
137 |
temp.push_back(v); |
|
138 |
} |
|
139 |
||
140 |
while (!temp.empty ()) { |
|
141 |
Push (temp.front ()); |
|
142 |
temp.pop_front (); |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
} // namespace ns3 |