class Neighbor
{
public:
// Constructor, other fields and methods
~Neighbor ()
{
if (m_event.IsRunning ())
{
Simulator::Cancel (m_event);
}
Simulator::Remove (m_event);
}
Time
GetExpireTime () const
{
return m_expire - Simulator::Now ();
}
void
SetExpireTime (Time exp)
{
m_expire = exp + Simulator::Now ();
}
template <typename MEM_PTR, typename OBJ_PTR>
bool
Schedule (Time delay, bool reset, MEM_PTR memPtr, OBJ_PTR objPtr)
{
if (m_event.IsRunning () == true && reset == false)
return false;
if (m_event.IsRunning () == true && reset == true)
Simulator::Cancel (m_event);
m_event = EventId (); // Tried with and without this line
m_event = Simulator::Schedule (delay, memPtr, objPtr, m_ip);
SetExpireTime (delay); // To store the time when it should be executed. This because sometimes it stops running.
return true;
}
private:
Ipv4Address m_ip;
EventId m_event;
Time m_expire;
};
class NeighborList
{
public:
// Constructor, other fields and methods
/*
* I made this method to reschedule every neighbor whose EventId stopped running.
*/
template <typename MEM_PTR, typename OBJ_PTR>
bool
ScheduleNeighbor (const Ipv4Address neighbor, Time delay,
MEM_PTR memPtr, OBJ_PTR objPtr)
{
for (std::vector<Neighbor>
::iterator it = m_list.begin ();
it != m_list.end (); ++it)
{
if (it->GetIpv4Address () == neighbor)
{
it->Schedule
(delay, true, memPtr, objPtr);
return true;
}
}
return false;
}
/*
* I made this method to reschedule every neighbor whose EventId stopped running.
*/
template <typename MEM_PTR, typename OBJ_PTR>
void
RescheduleFailed (MEM_PTR memPtr, OBJ_PTR objPtr)
{
for (std::vector<Neighbor>
::iterator it = m_list.begin ();
it != m_list.end (); ++it)
{
if (it->m_event.IsExpired () && Simulator::GetDelayLeft (it->m_event) <= Seconds (0))
{
if (it->GetExpireTime () > MilliSeconds (0))
{
it->ScheduleNeighborExpireTimer (it->GetExpireTime (), true, memPtr, objPtr);
}
else
{
it->ScheduleNeighborExpireTimer (MilliSeconds (100), true, memPtr, objPtr);
}
}
}
}
private:
Ipv4Address m_id;
std::vector<Neighbor>
m_list;
};