Skip to content

Commit

Permalink
Bug fix on the Send function scheduled message event time (#48)
Browse files Browse the repository at this point in the history
* Fixed bug affecting static source and filter applications causing incorrect synchronizations of sent messages.

* Restructuring and adding comment about the sending time being relative to ns-3 sim time.

Co-authored-by: Marinovici <[email protected]>
  • Loading branch information
laurmarinovici and Marinovici authored Dec 9, 2021
1 parent 3d494d1 commit cdceb94
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions model/helics-application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "ns3/helics.h"
#include "ns3/helics-application.h"
#include "ns3/helics-simulator-impl.h"
#include "helics/helics.hpp"

#include <algorithm>
Expand Down Expand Up @@ -315,9 +316,9 @@ HelicsApplication::DoFilter (std::unique_ptr<helics::Message> message)
}

void
HelicsApplication::Send (std::string dest, std::unique_ptr<helics::Message> message)
HelicsApplication::Send (std::string dest, helics::Time time, std::unique_ptr<helics::Message> message)
{
NS_LOG_FUNCTION (this << dest << message->to_string());
NS_LOG_FUNCTION (this << dest << time << message->to_string());

Ptr<Packet> p;

Expand Down Expand Up @@ -348,8 +349,10 @@ HelicsApplication::Send (std::string dest, std::unique_ptr<helics::Message> mess
// call to the trace sinks before the packet is actually sent,
// so that tags added to the packet can be sent as well
m_txTrace (p);

int delay_ns = (int) (m_rand_delay_ns->GetValue (m_jitterMinNs,m_jitterMaxNs) + 0.5);

int64_t jitter_ns = (int) (m_rand_delay_ns->GetValue (m_jitterMinNs, m_jitterMaxNs) + 0.5);
// Calculate the delay between when the event happens relative to current ns-3 simulation time
int64_t delay_ns = Time::FromDouble (time, Time::S).GetNanoSeconds() - Simulator::Now ().GetNanoSeconds () + jitter_ns;

if (Ipv4Address::IsMatchingType (m_localAddress))
{
Expand Down
2 changes: 1 addition & 1 deletion model/helics-application.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class HelicsApplication : public Application
/**
* \brief Packet creation based on HELICS data sent to dest.
*/
void Send (std::string dest, std::unique_ptr<helics::Message> message);
void Send (std::string dest, helics::Time time, std::unique_ptr<helics::Message> message);

/**
* \brief Receive a HELICS message.
Expand Down
2 changes: 1 addition & 1 deletion model/helics-filter-application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ HelicsFilterApplication::DoEndpoint (helics::Endpoint id, helics::Time time, std
{
NS_LOG_FUNCTION (this << id.getName() << time << message->to_string());

Send (message->original_dest, std::make_unique<helics::Message> (*message));
Send (message->original_dest, time, std::make_unique<helics::Message> (*message));
}

void
Expand Down
2 changes: 1 addition & 1 deletion model/helics-static-sink-application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ HelicsStaticSinkApplication::DoEndpoint (helics::Endpoint id, helics::Time time,
{
NS_LOG_FUNCTION (this << id.getName() << time << message->to_string());

Send(m_destination, std::move (message));
Send(m_destination, time, std::move (message));
}

void
Expand Down

0 comments on commit cdceb94

Please sign in to comment.