Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/applications/helper/udp-echo-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

namespace ns3 {

UdpEchoServerHelper::UdpEchoServerHelper (uint16_t port)
UdpEchoServerHelper::UdpEchoServerHelper (uint16_t port, uint64_t processing_time)
{
m_factory.SetTypeId (UdpEchoServer::GetTypeId ());
SetAttribute ("Port", UintegerValue (port));
SetAttribute ("ProcessingTime", UintegerValue (processing_time));
}

void
Expand Down
4 changes: 3 additions & 1 deletion src/applications/helper/udp-echo-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class UdpEchoServerHelper
* to set up simulations with echos.
*
* \param port The port the server will wait on for incoming packets
* \param processing_time The time in nanoseconds that the server will process
* each request for. Defaults to 0.
*/
UdpEchoServerHelper (uint16_t port);
UdpEchoServerHelper (uint16_t port, uint64_t processing_time = 0);

/**
* Record an attribute to be set in each Application after it is is created.
Expand Down
14 changes: 14 additions & 0 deletions src/applications/model/udp-echo-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ UdpEchoServer::GetTypeId (void)
UintegerValue (9),
MakeUintegerAccessor (&UdpEchoServer::m_port),
MakeUintegerChecker<uint16_t> ())
.AddAttribute ("ProcessingTime", "Processing time for each request.",
UintegerValue (0),
MakeUintegerAccessor (&UdpEchoServer::m_ptime),
MakeUintegerChecker<uint64_t> ())
;
return tid;
}
Expand All @@ -63,6 +67,7 @@ UdpEchoServer::~UdpEchoServer()
NS_LOG_FUNCTION (this);
m_socket = 0;
m_socket6 = 0;
m_ptime = 0;
}

void
Expand Down Expand Up @@ -168,6 +173,9 @@ UdpEchoServer::HandleRead (Ptr<Socket> socket)
Inet6SocketAddress::ConvertFrom (from).GetPort ());
}

// adding node's processing time
HandleProcessing();

packet->RemoveAllPacketTags ();
packet->RemoveAllByteTags ();

Expand All @@ -189,4 +197,10 @@ UdpEchoServer::HandleRead (Ptr<Socket> socket)
}
}

void
UdpEchoServer::HandleProcessing ()
{
Simulator::AddProcessingTime(m_ptime);
}

} // Namespace ns3
8 changes: 8 additions & 0 deletions src/applications/model/udp-echo-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@ class UdpEchoServer : public Application
*/
void HandleRead (Ptr<Socket> socket);

/**
* \brief Handle a packet processing.
*
* This function is called by lower layers.
*/
void HandleProcessing ();

uint16_t m_port; //!< Port on which we listen for incoming packets.
Ptr<Socket> m_socket; //!< IPv4 Socket
Ptr<Socket> m_socket6; //!< IPv6 Socket
Address m_local; //!< local multicast address
uint64_t m_ptime; //!< server node's request processing time
};

} // namespace ns3
Expand Down
6 changes: 6 additions & 0 deletions src/core/model/default-simulator-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ DefaultSimulatorImpl::Now (void) const
return TimeStep (m_currentTs);
}

void
DefaultSimulatorImpl::AddProcessingTime (uint64_t nanos)
{
m_currentTs += nanos;
}

Time
DefaultSimulatorImpl::GetDelayLeft (const EventId &id) const
{
Expand Down
1 change: 1 addition & 0 deletions src/core/model/default-simulator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DefaultSimulatorImpl : public SimulatorImpl
virtual bool IsExpired (const EventId &id) const;
virtual void Run (void);
virtual Time Now (void) const;
virtual void AddProcessingTime (uint64_t nanos);
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetScheduler (ObjectFactory schedulerFactory);
Expand Down
6 changes: 6 additions & 0 deletions src/core/model/realtime-simulator-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ RealtimeSimulatorImpl::Now (void) const
return TimeStep (m_currentTs);
}

void
RealtimeSimulatorImpl::AddProcessingTime (uint64_t nanos)
{
m_currentTs += nanos;
}

//
// Schedule an event for a _relative_ time in the future.
//
Expand Down
1 change: 1 addition & 0 deletions src/core/model/realtime-simulator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class RealtimeSimulatorImpl : public SimulatorImpl
virtual bool IsExpired (const EventId &ev) const;
virtual void Run (void);
virtual Time Now (void) const;
virtual void AddProcessingTime (uint64_t nanos);
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetScheduler (ObjectFactory schedulerFactory);
Expand Down
2 changes: 2 additions & 0 deletions src/core/model/simulator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class SimulatorImpl : public Object
virtual void Run (void) = 0;
/** \copydoc Simulator::Now */
virtual Time Now (void) const = 0;
/** \copydoc Simulator::AddProcessingTime */
virtual void AddProcessingTime (uint64_t nanos) = 0;
/** \copydoc Simulator::GetDelayLeft */
virtual Time GetDelayLeft (const EventId &id) const = 0;
/** \copydoc Simulator::GetMaximumSimulationTime */
Expand Down
6 changes: 6 additions & 0 deletions src/core/model/simulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ Simulator::Now (void)
return GetImpl ()->Now ();
}

void
Simulator::AddProcessingTime (uint64_t nanos)
{
GetImpl ()->AddProcessingTime (nanos);
}

Time
Simulator::GetDelayLeft (const EventId &id)
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/model/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,13 @@ class Simulator
*/
static Time Now (void);

/**
* Adds node's processing time to the current simulation virtual time.
*
* @param [in] number of nanoseconds of processing time.
*/
static void AddProcessingTime (uint64_t nanos);

/**
* Get the remaining time until this event will execute.
*
Expand Down
6 changes: 6 additions & 0 deletions src/mpi/model/distributed-simulator-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ DistributedSimulatorImpl::Now (void) const
return TimeStep (m_currentTs);
}

void
DistributedSimulatorImpl::AddProcessingTime (uint64_t nanos)
{
m_currentTs += nanos;
}

Time
DistributedSimulatorImpl::GetDelayLeft (const EventId &id) const
{
Expand Down
1 change: 1 addition & 0 deletions src/mpi/model/distributed-simulator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class DistributedSimulatorImpl : public SimulatorImpl
virtual bool IsExpired (const EventId &id) const;
virtual void Run (void);
virtual Time Now (void) const;
virtual void AddProcessingTime (uint64_t nanos);
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetMaximumLookAhead (const Time lookAhead);
Expand Down
6 changes: 6 additions & 0 deletions src/mpi/model/null-message-simulator-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ NullMessageSimulatorImpl::Now (void) const
return TimeStep (m_currentTs);
}

void
NullMessageSimulatorImpl::AddProcessingTime (uint64_t nanos)
{
m_currentTs += nanos;
}

Time
NullMessageSimulatorImpl::GetDelayLeft (const EventId &id) const
{
Expand Down
1 change: 1 addition & 0 deletions src/mpi/model/null-message-simulator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class NullMessageSimulatorImpl : public SimulatorImpl
virtual void Run (void);
virtual void RunOneEvent (void);
virtual Time Now (void) const;
virtual void AddProcessingTime (uint64_t nanos);
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetScheduler (ObjectFactory schedulerFactory);
Expand Down