00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright 2007 University of Washington 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #include "ns3/log.h" 00020 #include "ns3/assert.h" 00021 #include "candidate-queue.h" 00022 #include "global-route-manager-impl.h" 00023 00024 NS_LOG_COMPONENT_DEFINE ("CandidateQueue"); 00025 00026 namespace ns3 { 00027 00028 CandidateQueue::CandidateQueue() 00029 : m_candidates () 00030 { 00031 NS_LOG_FUNCTION_NOARGS (); 00032 } 00033 00034 CandidateQueue::~CandidateQueue() 00035 { 00036 NS_LOG_FUNCTION_NOARGS (); 00037 Clear (); 00038 } 00039 00040 void 00041 CandidateQueue::Clear (void) 00042 { 00043 NS_LOG_FUNCTION_NOARGS (); 00044 while (!m_candidates.empty ()) 00045 { 00046 SPFVertex *p = Pop (); 00047 delete p; 00048 p = 0; 00049 } 00050 } 00051 00052 void 00053 CandidateQueue::Push (SPFVertex *vNew) 00054 { 00055 NS_LOG_FUNCTION (this << vNew); 00056 00057 CandidateList_t::iterator i = m_candidates.begin (); 00058 00059 for (; i != m_candidates.end (); i++) 00060 { 00061 SPFVertex *v = *i; 00062 if (vNew->GetDistanceFromRoot () < v->GetDistanceFromRoot ()) 00063 { 00064 break; 00065 } 00066 } 00067 m_candidates.insert(i, vNew); 00068 } 00069 00070 SPFVertex * 00071 CandidateQueue::Pop (void) 00072 { 00073 NS_LOG_FUNCTION_NOARGS (); 00074 if (m_candidates.empty ()) 00075 { 00076 return 0; 00077 } 00078 00079 SPFVertex *v = m_candidates.front (); 00080 m_candidates.pop_front (); 00081 return v; 00082 } 00083 00084 SPFVertex * 00085 CandidateQueue::Top (void) const 00086 { 00087 NS_LOG_FUNCTION_NOARGS (); 00088 if (m_candidates.empty ()) 00089 { 00090 return 0; 00091 } 00092 00093 return m_candidates.front (); 00094 } 00095 00096 bool 00097 CandidateQueue::Empty (void) const 00098 { 00099 NS_LOG_FUNCTION_NOARGS (); 00100 return m_candidates.empty (); 00101 } 00102 00103 uint32_t 00104 CandidateQueue::Size (void) const 00105 { 00106 NS_LOG_FUNCTION_NOARGS (); 00107 return m_candidates.size (); 00108 } 00109 00110 SPFVertex * 00111 CandidateQueue::Find (const Ipv4Address addr) const 00112 { 00113 NS_LOG_FUNCTION_NOARGS (); 00114 CandidateList_t::const_iterator i = m_candidates.begin (); 00115 00116 for (; i != m_candidates.end (); i++) 00117 { 00118 SPFVertex *v = *i; 00119 if (v->GetVertexId() == addr) 00120 { 00121 return v; 00122 } 00123 } 00124 00125 return 0; 00126 } 00127 00128 void 00129 CandidateQueue::Reorder (void) 00130 { 00131 NS_LOG_FUNCTION_NOARGS (); 00132 std::list<SPFVertex*> temp; 00133 00134 while (!m_candidates.empty ()) { 00135 SPFVertex *v = m_candidates.front (); 00136 m_candidates.pop_front (); 00137 temp.push_back(v); 00138 } 00139 00140 while (!temp.empty ()) { 00141 Push (temp.front ()); 00142 temp.pop_front (); 00143 } 00144 } 00145 00146 } // namespace ns3