32 #include "dsr-rreq-table.h"
42 NS_OBJECT_ENSURE_REGISTERED (RreqTable);
48 .AddConstructor<RreqTable> ()
54 : m_linkStates (PROBABLE)
64 RreqTable::RemoveLeastExpire (std::map<Ipv4Address, RreqTableEntry > & rreqDstMap)
69 for (std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
70 rreqDstMap.begin (); i != rreqDstMap.end (); ++i)
74 if (rreqTableEntry.m_expire > max)
76 max = rreqTableEntry.m_expire;
80 rreqDstMap.erase (firstExpire);
84 RreqTable::FindAndUpdate (Ipv4Address dst)
87 std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
88 m_rreqDstMap.find (dst);
89 if (i == m_rreqDstMap.end ())
91 NS_LOG_LOGIC (
"The request table entry for " << dst <<
" not found");
95 if (m_rreqDstMap.size () >= m_requestTableSize)
97 RemoveLeastExpire (m_rreqDstMap);
98 NS_LOG_INFO (
"The request table size after erase " << (uint32_t)m_rreqDstMap.size ());
100 RreqTableEntry rreqTableEntry;
101 rreqTableEntry.m_reqNo = 1;
103 m_rreqDstMap [dst] = rreqTableEntry;
107 NS_LOG_LOGIC (
"Find the request table entry for " << dst <<
", increment the request count");
108 Ipv4Address dst = i->first;
109 RreqTableEntry rreqTableEntry = i->second;
110 rreqTableEntry.m_reqNo = rreqTableEntry.m_reqNo + 1;
112 m_rreqDstMap [dst] = rreqTableEntry;
117 RreqTable::RemoveRreqEntry (Ipv4Address dst)
120 std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
121 m_rreqDstMap.find (dst);
122 if (i == m_rreqDstMap.end ())
129 m_rreqDstMap.erase (dst);
134 RreqTable::GetRreqCnt (Ipv4Address dst)
137 std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
138 m_rreqDstMap.find (dst);
139 if (i == m_rreqDstMap.end ())
146 RreqTableEntry rreqTableEntry = i->second;
147 return rreqTableEntry.m_reqNo;
159 NS_LOG_LOGIC (
"The size of id cache " << m_rreqIdCache.size ());
160 std::map<Ipv4Address, uint32_t>::const_iterator i =
161 m_rreqIdCache.find (dst);
162 if (i == m_rreqIdCache.end ())
164 NS_LOG_LOGIC (
"No Request id for " << dst <<
" found, initialize it to 0");
165 m_rreqIdCache[dst] = 0;
170 NS_LOG_LOGIC (
"Request id for " << dst <<
" found in the cache");
171 uint32_t rreqId = m_rreqIdCache[dst];
172 if (rreqId >= m_maxRreqId)
174 NS_LOG_DEBUG (
"The request id increase past the max value, " << m_maxRreqId <<
" so reset it to 0");
176 m_rreqIdCache[dst] = rreqId;
181 m_rreqIdCache[dst] = rreqId;
183 NS_LOG_INFO (
"The Request id for " << dst <<
" is " << rreqId);
189 RreqTable::GetRreqSize ()
191 return m_rreqIdCache.size ();
202 if (m_linkStates == QUESTIONABLE)
206 m_linkStates = QUESTIONABLE;
213 for (std::vector<BlackList>::iterator i = m_blackList.begin ();
214 i != m_blackList.end (); ++i)
216 if (i->m_neighborAddress == neighbor)
227 NS_LOG_LOGIC (
"Add neighbor address in blacklist " << m_blackList.size ());
228 for (std::vector<BlackList>::iterator i = m_blackList.begin (); i != m_blackList.end (); ++i)
230 if (i->m_neighborAddress == neighbor)
232 NS_LOG_DEBUG (
"Update the blacklist list timeout if found the blacklist entry");
233 i->m_expireTime = std::max (blacklistTimeout +
Simulator::Now (), i->m_expireTime);
236 m_blackList.push_back (blackList);
244 RreqTable::PurgeNeighbor ()
249 m_blackList.erase (remove_if (m_blackList.begin (), m_blackList.end (),
258 rreqEntry.SetDestination (dst);
259 rreqEntry.SetIdentification (
id);
260 std::list<ReceivedRreqEntry> receivedRreqEntryList;
264 std::map<Ipv4Address, std::list<ReceivedRreqEntry> >::const_iterator i = m_sourceRreqMap.find (src);
265 if (i == m_sourceRreqMap.end ())
267 NS_LOG_LOGIC (
"The source request table entry for " << src <<
" not found");
269 receivedRreqEntryList.clear ();
270 receivedRreqEntryList.push_back (rreqEntry);
272 m_sourceRreqMap [src] = receivedRreqEntryList;
277 NS_LOG_LOGIC (
"Find the request table entry for " << src <<
", check if it is exact duplicate");
281 receivedRreqEntryList = i->second;
282 if (receivedRreqEntryList.size () >= m_requestIdSize)
284 receivedRreqEntryList.pop_front ();
288 for (std::list<ReceivedRreqEntry>::const_iterator j = receivedRreqEntryList.begin (); j != receivedRreqEntryList.end (); ++j)
296 receivedRreqEntryList.push_back (rreqEntry);
297 m_sourceRreqMap [src] = receivedRreqEntryList;
#define NS_LOG_FUNCTION(parameters)
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_LOG_FUNCTION_NOARGS()
static TypeId GetTypeId()
Get the type identificator.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for blacklistTimeout period) ...
virtual ~RreqTable()
Destructor.
#define NS_LOG_LOGIC(msg)
BlackList * FindUnidirectional(Ipv4Address neighbor)
Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for blacklistTimeout p...
Ipv4 addresses are stored in host order in this class.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id)
#define NS_LOG_DEBUG(msg)
a base class which provides memory management and object aggregation
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
uint32_t CheckUniqueRreqId(Ipv4Address dst)