22 #include "ns3/ipv4-address.h"
23 #include "ns3/nstime.h"
24 #include "ns3/inet-socket-address.h"
25 #include "ns3/inet6-socket-address.h"
26 #include "ns3/socket.h"
27 #include "ns3/simulator.h"
28 #include "ns3/socket-factory.h"
29 #include "ns3/packet.h"
30 #include "ns3/uinteger.h"
31 #include "ns3/string.h"
32 #include "seq-ts-header.h"
33 #include "udp-trace-client.h"
41 NS_OBJECT_ENSURE_REGISTERED (UdpTraceClient);
57 UdpTraceClient::GetTypeId (
void)
61 .AddConstructor<UdpTraceClient> ()
62 .AddAttribute (
"RemoteAddress",
63 "The destination Address of the outbound packets",
65 MakeAddressAccessor (&UdpTraceClient::m_peerAddress),
66 MakeAddressChecker ())
67 .AddAttribute (
"RemotePort",
68 "The destination port of the outbound packets",
70 MakeUintegerAccessor (&UdpTraceClient::m_peerPort),
71 MakeUintegerChecker<uint16_t> ())
72 .AddAttribute (
"MaxPacketSize",
73 "The maximum size of a packet.",
75 MakeUintegerAccessor (&UdpTraceClient::m_maxPacketSize),
76 MakeUintegerChecker<uint32_t> ())
77 .AddAttribute (
"TraceFilename",
78 "Name of file to load a trace from. By default, uses a hardcoded trace.",
93 m_maxPacketSize = 1400;
106 m_maxPacketSize = 1400;
107 if (traceFile != NULL)
113 UdpTraceClient::~UdpTraceClient ()
142 m_peerAddress = Address (ip);
156 LoadTrace (traceFile);
164 m_maxPacketSize = maxPacketSize;
171 return m_maxPacketSize;
183 UdpTraceClient::LoadTrace (std::string filename)
186 uint32_t time, index, prevTime = 0;
190 std::ifstream ifTraceFile;
191 ifTraceFile.open (filename.c_str (), std::ifstream::in);
193 if (!ifTraceFile.good ())
197 while (ifTraceFile.good ())
199 ifTraceFile >> index >> frameType >> time >> size;
200 if (frameType ==
'B')
202 entry.timeToSend = 0;
206 entry.timeToSend = time - prevTime;
209 entry.packetSize = size;
210 entry.frameType = frameType;
211 m_entries.push_back (entry);
213 ifTraceFile.close ();
218 UdpTraceClient::LoadDefaultTrace (
void)
221 uint32_t prevTime = 0;
222 for (uint32_t i = 0; i < (
sizeof (g_defaultEntries) /
sizeof (
struct TraceEntry)); i++)
224 struct TraceEntry entry = g_defaultEntries[i];
225 if (entry.frameType ==
'B')
227 entry.timeToSend = 0;
231 uint32_t tmp = entry.timeToSend;
232 entry.timeToSend -= prevTime;
235 m_entries.push_back (entry);
272 UdpTraceClient::SendPacket (uint32_t size)
279 packetSize = size - 12;
285 p = Create<Packet> (packetSize);
287 seqTs.SetSeq (m_sent);
290 std::stringstream addressString;
301 addressString << m_peerAddress;
304 if ((m_socket->
Send (p)) >= 0)
308 << addressString.str ());
312 NS_LOG_INFO (
"Error while sending " << size <<
" bytes to "
313 << addressString.str ());
318 UdpTraceClient::Send (
void)
324 struct TraceEntry *entry = &m_entries[m_currentEntry];
327 for (
int i = 0; i < entry->packetSize / m_maxPacketSize; i++)
329 SendPacket (m_maxPacketSize);
332 uint16_t sizetosend = entry->packetSize % m_maxPacketSize;
333 SendPacket (sizetosend);
336 m_currentEntry %= m_entries.size ();
337 entry = &m_entries[m_currentEntry];
339 while (entry->timeToSend == 0);
static bool IsMatchingType(const Address &address)
If the Address matches the type.
#define NS_LOG_FUNCTION(parameters)
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
hold variables of type string
#define NS_ASSERT(condition)
virtual void StartApplication(void)
Application specific startup code.
#define NS_LOG_COMPONENT_DEFINE(name)
static void Cancel(const EventId &id)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void StopApplication(void)
Application specific shutdown code.
UdpTraceClient()
creates a traceBasedStreamer application
void SetTraceFile(std::string filename)
set the trace file to be used by the application
a polymophic address class
The base class for all ns3 applications.
Hold an unsigned integer type.
uint16_t GetMaxPacketSize(void)
Ptr< Node > GetNode() const
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
static bool IsMatchingType(const Address &address)
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual void DoDispose(void)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void SetMaxPacketSize(uint16_t maxPacketSize)
Callback< R > MakeNullCallback(void)
Ipv4 addresses are stored in host order in this class.
hold objects of type ns3::Address
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
an identifier for simulation events.
void SetRemote(Address ip, uint16_t port)
set the destination IP address and port
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
static Ipv4Address ConvertFrom(const Address &address)
virtual void DoDispose(void)
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
bool IsExpired(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)
static TypeId LookupByName(std::string name)
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.