32 #include "dsr-passive-buff.h"
35 #include "ns3/ipv4-route.h"
36 #include "ns3/socket.h"
44 NS_OBJECT_ENSURE_REGISTERED (PassiveBuffer);
50 .AddConstructor<PassiveBuffer> ()
64 PassiveBuffer::GetSize ()
67 return m_passiveBuffer.size ();
71 PassiveBuffer::Enqueue (PassiveBuffEntry & entry)
74 for (std::vector<PassiveBuffEntry>::const_iterator i = m_passiveBuffer.begin (); i
75 != m_passiveBuffer.end (); ++i)
82 if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && (i->GetSource () == entry.GetSource ()) && (i->GetNextHop () == entry.GetNextHop ())
83 && (i->GetDestination () == entry.GetDestination ()) && (i->GetIdentification () == entry.GetIdentification ()) && (i->GetFragmentOffset () == entry.GetFragmentOffset ())
84 && (i->GetSegsLeft () == entry.GetSegsLeft () + 1))
90 entry.SetExpireTime (m_passiveBufferTimeout);
94 if (m_passiveBuffer.size () >= m_maxLen)
96 Drop (m_passiveBuffer.front (),
"Drop the most aged packet");
97 m_passiveBuffer.erase (m_passiveBuffer.begin ());
100 m_passiveBuffer.push_back (entry);
105 PassiveBuffer::AllEqual (PassiveBuffEntry & entry)
107 for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i
108 != m_passiveBuffer.end (); ++i)
115 if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ()) && (i->GetSource () == entry.GetSource ()) && (i->GetNextHop () == entry.GetNextHop ())
116 && (i->GetDestination () == entry.GetDestination ()) && (i->GetIdentification () == entry.GetIdentification ()) && (i->GetFragmentOffset () == entry.GetFragmentOffset ())
117 && (i->GetSegsLeft () == entry.GetSegsLeft () + 1))
119 m_passiveBuffer.erase (i);
127 PassiveBuffer::Dequeue (Ipv4Address dst, PassiveBuffEntry & entry)
133 for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i != m_passiveBuffer.end (); ++i)
135 if (i->GetDestination () == dst)
138 m_passiveBuffer.erase (i);
139 NS_LOG_DEBUG (
"Packet size while dequeuing " << entry.GetPacket ()->GetSize ());
147 PassiveBuffer::Find (Ipv4Address dst)
152 for (std::vector<PassiveBuffEntry>::const_iterator i = m_passiveBuffer.begin (); i
153 != m_passiveBuffer.end (); ++i)
155 if (i->GetDestination () == dst)
167 operator() (PassiveBuffEntry
const & e)
const
170 return (e.GetExpireTime () <
Seconds (0));
175 PassiveBuffer::Purge ()
180 NS_LOG_DEBUG (
"The passive buffer size " << m_passiveBuffer.size ());
182 for (std::vector<PassiveBuffEntry>::iterator i = m_passiveBuffer.begin (); i
183 != m_passiveBuffer.end (); ++i)
188 Drop (*i,
"Drop out-dated packet ");
191 m_passiveBuffer.erase (std::remove_if (m_passiveBuffer.begin (), m_passiveBuffer.end (), pred),
192 m_passiveBuffer.end ());
196 PassiveBuffer::Drop (PassiveBuffEntry en, std::string reason)
198 NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () <<
" " << en.GetDestination ());
205 PassiveBuffer::DropLink (PassiveBuffEntry en, std::string reason)
207 NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid () <<
" " << en.GetSource () <<
" " << en.GetNextHop ());
#define NS_LOG_COMPONENT_DEFINE(name)
static TypeId GetTypeId()
Get the type identificator.
#define NS_LOG_LOGIC(msg)
virtual ~PassiveBuffer()
Destructor.
PassiveBuffer()
Constructor.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#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)