--- a/src/dsr/model/dsr-rreq-table.cc Fri Jan 27 15:15:48 2012 -0800
+++ b/src/dsr/model/dsr-rreq-table.cc Sun May 06 20:52:24 2012 -0700
@@ -67,7 +67,7 @@
Ipv4Address firstExpire;
Time max = Seconds (0.0);
for (std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
- rreqDstMap.begin (); i != rreqDstMap.end (); ++i)
+ rreqDstMap.begin (); i != rreqDstMap.end (); ++i)
{
Ipv4Address dst = i->first;
RreqTableEntry rreqTableEntry = i->second;
@@ -83,33 +83,33 @@
void
RreqTable::FindAndUpdate (Ipv4Address dst)
{
- NS_LOG_LOGIC ("Find and update the route request entry for " << dst);
+ NS_LOG_FUNCTION (this << dst);
std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
m_rreqDstMap.find (dst);
if (i == m_rreqDstMap.end ())
{
- NS_LOG_DEBUG ("The request table entry not found");
+ NS_LOG_DEBUG ("The request table entry for " << dst << " not found");
/*
* Drop the most aged packet when buffer reaches to max
*/
if (m_rreqDstMap.size () >= m_requestTableSize)
{
RemoveLeastExpire (m_rreqDstMap);
- NS_LOG_DEBUG ("The request table size after erase ");
+ NS_LOG_DEBUG ("The request table size after erase " << (uint32_t)m_rreqDstMap.size ());
}
RreqTableEntry rreqTableEntry;
- rreqTableEntry.m_reqNo = 0;
- rreqTableEntry.m_expire = Simulator::Now ();
+ rreqTableEntry.m_reqNo = 1;
+ rreqTableEntry.m_expire = Simulator::Now();
m_rreqDstMap [dst] = rreqTableEntry;
}
else
{
- NS_LOG_DEBUG ("Find the request table entry, increment the request count");
+ NS_LOG_INFO ("Find the request table entry for " << dst << ", increment the request count");
Ipv4Address dst = i->first;
RreqTableEntry rreqTableEntry = i->second;
NS_LOG_DEBUG ("The request count before incrementing " << rreqTableEntry.m_reqNo);
rreqTableEntry.m_reqNo = (rreqTableEntry.m_reqNo + 1);
- rreqTableEntry.m_expire = Simulator::Now ();
+ rreqTableEntry.m_expire = Simulator::Now();
m_rreqDstMap [dst] = rreqTableEntry;
}
}
@@ -117,6 +117,7 @@
void
RreqTable::RemoveRreqEntry (Ipv4Address dst)
{
+ NS_LOG_FUNCTION (this << dst);
NS_LOG_DEBUG ("Remove rreq entry with index dst");
std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
m_rreqDstMap.find (dst);
@@ -131,16 +132,15 @@
}
}
-uint16_t
+uint32_t
RreqTable::GetRreqCnt (Ipv4Address dst)
{
- NS_LOG_DEBUG ("Get the request count for a certain dst");
+ NS_LOG_FUNCTION (this << dst);
std::map<Ipv4Address, RreqTableEntry >::const_iterator i =
m_rreqDstMap.find (dst);
if (i == m_rreqDstMap.end ())
{
NS_LOG_DEBUG ("The request table entry not found");
- FindAndUpdate (dst);
return 0;
}
else
@@ -153,140 +153,14 @@
// ----------------------------------------------------------------------------------------------------------
/**
- * This part takes care of the route request from a specific source
- * need to ignore future route requests from same source for same destination with same identification
- */
-bool
-RreqTable::FindSrc (Ipv4Address source, Ipv4Address target, uint16_t id)
-{
- Purge ();
- std::map<Ipv4Address, std::list<SourceRreqEntry> >::const_iterator i =
- m_rreqMap.find (source);
- if (i == m_rreqMap.end ())
- {
- NS_LOG_LOGIC ("No Request entry for " << source << " found");
- SourceRreqEntry sourceRreqEntry;
- sourceRreqEntry.m_dst = target;
- sourceRreqEntry.m_identification = id;
- sourceRreqEntry.m_expire = m_rreqEntryExpire + Simulator::Now ();
- NS_LOG_DEBUG ("The src rreq expire time " << sourceRreqEntry.m_expire);
- std::list<SourceRreqEntry> rqVector;
- rqVector.push_back (sourceRreqEntry);
- m_rreqMap[source] = rqVector;
- return false;
- }
- else
- {
- NS_LOG_LOGIC ("Request entry for " << source << " found in the cache");
- std::list<SourceRreqEntry> rqVector = i->second;
- for (std::list<SourceRreqEntry>::iterator j = rqVector.begin (); j != rqVector.end (); ++j)
- {
- SourceRreqEntry rreqEntry = *j;
- if ((rreqEntry.m_dst == target) && (rreqEntry.m_identification == id))
- {
- NS_LOG_DEBUG ("Found the request entry for source node with address " << source);
-// j = rqVector.erase (j);
-// rqVector.push_back(*j);
-// m_rreqMap[source] = rqVector;
- return true;
- }
- }
-
- SourceRreqEntry rreqEntry;
- rreqEntry.m_dst = target;
- rreqEntry.m_identification = id;
- rreqEntry.m_expire = m_rreqEntryExpire + Simulator::Now ();
- if (rqVector.size () >= m_requestIdSize)
- {
- // erase the first element when the size is larger than the request id size (default: 16)
- rqVector.pop_front ();
- }
- // May need to check the size of the entry
- rqVector.push_back (rreqEntry);
- m_rreqMap[source] = rqVector;
- return false;
- }
- return false;
-}
-
-void
-RreqTable::Purge ()
-{
- //Trying to purge the rreq table
- if (m_rreqMap.empty ())
- {
- NS_LOG_DEBUG ("The rreq table is empty");
- return;
- }
-
- for (std::map<Ipv4Address, std::list<SourceRreqEntry> >::iterator i =
- m_rreqMap.begin (); i != m_rreqMap.end (); )
- {
- // Loop of rreq table entry with the source entries
- std::map<Ipv4Address, std::list<SourceRreqEntry> >::iterator itmp = i;
- /*
- * The rreq table entries
- */
- Ipv4Address dst = i->first;
- std::list<SourceRreqEntry> rqVector = i->second;
- NS_LOG_DEBUG ("The rqVector size for " << dst << " is " << rqVector.size ());
- if (rqVector.size ())
- {
- for (std::list<SourceRreqEntry>::iterator j = rqVector.begin (); j != rqVector.end (); )
- {
- NS_LOG_DEBUG ("The expire time of every entry with expire time " << j->m_expire - Simulator::Now ());
- /*
- * First verify if the rreq table entry has expired or not
- */
- if (j->m_expire - Simulator::Now () <= Seconds (0))
- {
- /*
- * When the expire time has passed, erase the certain rreq table entry
- */
- NS_LOG_DEBUG ("Erase the expired rreq table entry for " << dst << " with expire time " << j->m_expire - Simulator::Now ());
- j = rqVector.erase (j);
- }
- else
- {
- ++j;
- }
- }
- NS_LOG_DEBUG ("The rreq table entry for " << dst << " " << rqVector.size ());
- if (rqVector.size ())
- {
- ++i;
- m_rreqMap.erase (itmp); // erase the entry first
- /*
- * Save the new rreq table entry along with the destination address in map
- */
- std::pair<std::map<Ipv4Address, std::list<SourceRreqEntry> >::iterator, bool> result =
- m_rreqMap.insert (std::make_pair (dst, rqVector));
- }
- else
- {
- ++i;
- m_rreqMap.erase (itmp);
- }
- }
- else
- {
- ++i;
- m_rreqMap.erase (itmp);
- }
- }
- return;
-}
-
-// ----------------------------------------------------------------------------------------------------------
-/**
* This part takes care of the route request ID initialized from a specific source to one destination
* Essentially a counter
*/
-uint16_t
+uint32_t
RreqTable::CheckUniqueRreqId (Ipv4Address dst)
{
NS_LOG_DEBUG ("The size of id cache " << m_rreqIdCache.size ());
- std::map<Ipv4Address, uint16_t>::const_iterator i =
+ std::map<Ipv4Address, uint32_t>::const_iterator i =
m_rreqIdCache.find (dst);
if (i == m_rreqIdCache.end ())
{
@@ -297,10 +171,10 @@
else
{
NS_LOG_LOGIC ("Request id for " << dst << " found in the cache");
- uint16_t rreqId = m_rreqIdCache[dst];
+ uint32_t rreqId = m_rreqIdCache[dst];
if (rreqId >= m_maxRreqId)
{
- NS_LOG_DEBUG ("The request id increase past the max value, so reset it to 0");
+ NS_LOG_DEBUG ("The request id increase past the max value, " << m_maxRreqId << " so reset it to 0");
rreqId = 0;
m_rreqIdCache[dst] = rreqId;
}
@@ -314,7 +188,7 @@
}
}
-uint16_t
+uint32_t
RreqTable::GetRreqSize ()
{
return m_rreqIdCache.size ();