Fixes Click bug from using microsecond precision for scheduling click events
This commit is contained in:
@@ -256,11 +256,48 @@ Ipv4ClickRouting::GetClickInstanceFromSimNode (simclick_node_t *simnode)
|
||||
return m_clickInstanceFromSimNode[simnode];
|
||||
}
|
||||
|
||||
struct timeval
|
||||
Ipv4ClickRouting::GetTimevalFromNow () const
|
||||
{
|
||||
struct timeval curtime;
|
||||
uint64_t remainder = 0;
|
||||
|
||||
curtime.tv_sec = Simulator::Now ().GetSeconds ();
|
||||
curtime.tv_usec = Simulator::Now ().GetMicroSeconds () % 1000000;
|
||||
|
||||
switch (Simulator::Now ().GetResolution())
|
||||
{
|
||||
case Time::NS:
|
||||
remainder = Simulator::Now ().GetNanoSeconds () % 1000;
|
||||
break;
|
||||
case Time::PS:
|
||||
remainder = Simulator::Now ().GetPicoSeconds () % 1000000;
|
||||
break;
|
||||
case Time::FS:
|
||||
remainder = Simulator::Now ().GetFemtoSeconds () % 1000000000;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (remainder)
|
||||
{
|
||||
++curtime.tv_usec;
|
||||
if (curtime.tv_usec == 1000000)
|
||||
{
|
||||
++curtime.tv_sec;
|
||||
curtime.tv_usec = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return curtime;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4ClickRouting::RunClickEvent ()
|
||||
{
|
||||
m_simNode->curtime.tv_sec = Simulator::Now ().GetSeconds ();
|
||||
m_simNode->curtime.tv_usec = Simulator::Now ().GetMicroSeconds () % 1000000;
|
||||
m_simNode->curtime = GetTimevalFromNow ();
|
||||
|
||||
NS_LOG_DEBUG ("RunClickEvent at " << m_simNode->curtime.tv_sec << " " <<
|
||||
m_simNode->curtime.tv_usec << " " << Simulator::Now ());
|
||||
simclick_click_run (m_simNode);
|
||||
@@ -311,8 +348,7 @@ void
|
||||
Ipv4ClickRouting::SendPacketToClick (int ifid, int ptype, const unsigned char* data, int len)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << ifid);
|
||||
m_simNode->curtime.tv_sec = Simulator::Now ().GetSeconds ();
|
||||
m_simNode->curtime.tv_usec = Simulator::Now ().GetMicroSeconds () % 1000000;
|
||||
m_simNode->curtime = GetTimevalFromNow ();
|
||||
|
||||
// Since packets in ns-3 don't have global Packet ID's and Flow ID's, we
|
||||
// feed dummy values into pinfo. This avoids the need to make changes in the Click code
|
||||
|
||||
@@ -180,6 +180,11 @@ private:
|
||||
*/
|
||||
void AddSimNodeToClickMapping ();
|
||||
|
||||
/**
|
||||
* \brief Get current simulation time as a timeval
|
||||
*/
|
||||
struct timeval GetTimevalFromNow () const;
|
||||
|
||||
/**
|
||||
* \brief This method has to be scheduled everytime Click calls SIMCLICK_SCHEDULE
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user