A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
candidate-queue.h
Go to the documentation of this file.
1/*
2 * Copyright 2007 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Craig Dowell (craigdo@ee.washington.edu)
7 */
8
9#ifndef CANDIDATE_QUEUE_H
10#define CANDIDATE_QUEUE_H
11
13
14#include "ns3/ipv4-address.h"
15#include "ns3/ipv6-address.h"
16
17#include <list>
18#include <stdint.h>
19
20namespace ns3
21{
22
23template <typename T>
24class SPFVertex;
25
26template <typename>
27class CandidateQueue;
28
29// Forward declaration of operator<<
30template <typename T>
31std::ostream& operator<<(std::ostream& os, const CandidateQueue<T>& q);
32
33/**
34 * @ingroup globalrouting
35 *
36 * @brief A Candidate Queue used in routing calculations.
37 *
38 * The CandidateQueue is used in the OSPF shortest path computations. It
39 * is a priority queue used to store candidates for the shortest path to a
40 * given network.
41 *
42 * The queue holds Shortest Path First Vertex pointers and orders them
43 * according to the lowest value of the field m_distanceFromRoot. Remaining
44 * vertices are ordered according to increasing distance. This implements a
45 * priority queue.
46 *
47 * Although a STL priority_queue almost does what we want, the requirement
48 * for a Find () operation, the dynamic nature of the data and the derived
49 * requirement for a Reorder () operation led us to implement this simple
50 * enhanced priority queue.
51 */
52template <typename T>
54{
55 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
56 "T must be either Ipv4Manager or Ipv6Manager when calling CandidateQueue");
57
58 /// Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol
59 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
60
61 /// Alias for Ipv4Manager and Ipv6Manager classes
62 using IpManager = typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
63
64 /// Alias for Ipv4 and Ipv6 classes
65 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
66
67 /// Alias for Ipv4Address and Ipv6Address classes
68 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
69
70 public:
71 /**
72 * @brief Create an empty SPF Candidate Queue.
73 *
74 * @see SPFVertex
75 */
77
78 /**
79 * @brief Destroy an SPF Candidate Queue and release any resources held
80 * by the contents.
81 *
82 * @see SPFVertex
83 */
84 virtual ~CandidateQueue();
85
86 // Delete copy constructor and assignment operator to avoid misuse
89
90 /**
91 * @brief Empty the Candidate Queue and release all of the resources
92 * associated with the Shortest Path First Vertex pointers in the queue.
93 *
94 * @see SPFVertex
95 */
96 void Clear();
97
98 /**
99 * @brief Push a Shortest Path First Vertex pointer onto the queue according
100 * to the priority scheme.
101 *
102 * On completion, the top of the queue will hold the Shortest Path First
103 * Vertex pointer that points to a vertex having lowest value of the field
104 * m_distanceFromRoot. Remaining vertices are ordered according to
105 * increasing distance.
106 *
107 * @see SPFVertex
108 * @param vNew The Shortest Path First Vertex to add to the queue.
109 */
110 void Push(SPFVertex<T>* vNew);
111
112 /**
113 * @brief Pop the Shortest Path First Vertex pointer at the top of the queue.
114 *
115 * The caller is given the responsibility for releasing the resources
116 * associated with the vertex.
117 *
118 * @see SPFVertex
119 * @see Top ()
120 * @returns The Shortest Path First Vertex pointer at the top of the queue.
121 */
122 SPFVertex<T>* Pop();
123
124 /**
125 * @brief Return the Shortest Path First Vertex pointer at the top of the
126 * queue.
127 *
128 * This method does not pop the SPFVertex* off of the queue, it simply
129 * returns the pointer.
130 *
131 * @see SPFVertex
132 * @see Pop ()
133 * @returns The Shortest Path First Vertex pointer at the top of the queue.
134 */
135 SPFVertex<T>* Top() const;
136
137 /**
138 * @brief Test the Candidate Queue to determine if it is empty.
139 *
140 * @returns True if the queue is empty, false otherwise.
141 */
142 bool Empty() const;
143
144 /**
145 * @brief Return the number of Shortest Path First Vertex pointers presently
146 * stored in the Candidate Queue.
147 *
148 * @see SPFVertex
149 * @returns The number of SPFVertex* pointers in the Candidate Queue.
150 */
151 uint32_t Size() const;
152
153 /**
154 * @brief Searches the Candidate Queue for a Shortest Path First Vertex
155 * pointer that points to a vertex having the given IP address.
156 *
157 * @see SPFVertex
158 * @param addr The IP address to search for.
159 * @returns The SPFVertex* pointer corresponding to the given IP address.
160 */
161 SPFVertex<T>* Find(const IpAddress addr) const;
162
163 /**
164 * @brief Reorders the Candidate Queue according to the priority scheme.
165 *
166 * On completion, the top of the queue will hold the Shortest Path First
167 * Vertex pointer that points to a vertex having lowest value of the field
168 * m_distanceFromRoot. Remaining vertices are ordered according to
169 * increasing distance.
170 *
171 * This method is provided in case the values of m_distanceFromRoot change
172 * during the routing calculations.
173 *
174 * @see SPFVertex
175 */
176 void Reorder();
177
178 private:
179 /**
180 * @brief return true if v1 < v2
181 *
182 * SPFVertex items are added into the queue according to the ordering
183 * defined by this method. If v1 should be popped before v2, this
184 * method return true; false otherwise
185 *
186 * @param v1 first operand
187 * @param v2 second operand
188 * @return True if v1 should be popped before v2; false otherwise
189 */
190 static bool CompareSPFVertex(const SPFVertex<T>* v1, const SPFVertex<T>* v2);
191
192 typedef std::list<SPFVertex<T>*> CandidateList_t; //!< container of SPFVertex pointers
193 CandidateList_t m_candidates; //!< SPFVertex candidates
194
195 /**
196 * @brief Stream insertion operator.
197 *
198 * @param os the reference to the output stream
199 * @param q the CandidateQueue
200 * @returns the reference to the output stream
201 */
202 friend std::ostream& operator<< <T>(std::ostream& os, const CandidateQueue& q);
203};
204
205} // namespace ns3
206
207#endif /* CANDIDATE_QUEUE_H */
uint32_t q
A Candidate Queue used in routing calculations.
void Push(SPFVertex< T > *vNew)
Push a Shortest Path First Vertex pointer onto the queue according to the priority scheme.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
CandidateList_t m_candidates
SPFVertex candidates.
SPFVertex< T > * Top() const
Return the Shortest Path First Vertex pointer at the top of the queue.
SPFVertex< T > * Find(const IpAddress addr) const
Searches the Candidate Queue for a Shortest Path First Vertex pointer that points to a vertex having ...
CandidateQueue()
Create an empty SPF Candidate Queue.
bool Empty() const
Test the Candidate Queue to determine if it is empty.
virtual ~CandidateQueue()
Destroy an SPF Candidate Queue and release any resources held by the contents.
SPFVertex< T > * Pop()
Pop the Shortest Path First Vertex pointer at the top of the queue.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
uint32_t Size() const
Return the number of Shortest Path First Vertex pointers presently stored in the Candidate Queue.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
CandidateQueue(const CandidateQueue &)=delete
void Clear()
Empty the Candidate Queue and release all of the resources associated with the Shortest Path First Ve...
CandidateQueue & operator=(const CandidateQueue &)=delete
void Reorder()
Reorders the Candidate Queue according to the priority scheme.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
std::list< SPFVertex< T > * > CandidateList_t
container of SPFVertex pointers
static bool CompareSPFVertex(const SPFVertex< T > *v1, const SPFVertex< T > *v2)
return true if v1 < v2
Vertex used in shortest path first (SPF) computations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148