applications: UdpTraceClient reload traces when remote address is changed
This avoids to clear the trace entries without repopulating them with the currently selected trace file
This commit is contained in:
@@ -150,12 +150,12 @@ UdpTraceClient::SetRemote(const Address& addr)
|
||||
NS_LOG_FUNCTION(this << addr);
|
||||
if (!addr.IsInvalid())
|
||||
{
|
||||
m_entries.clear();
|
||||
m_peer = addr;
|
||||
if (m_peerPort)
|
||||
{
|
||||
SetPort(*m_peerPort);
|
||||
}
|
||||
LoadTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,14 +203,8 @@ void
|
||||
UdpTraceClient::SetTraceFile(const std::string& traceFile)
|
||||
{
|
||||
NS_LOG_FUNCTION(this << traceFile);
|
||||
if (traceFile.empty())
|
||||
{
|
||||
LoadDefaultTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadTrace(traceFile);
|
||||
}
|
||||
m_traceFile = traceFile;
|
||||
LoadTrace();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -228,30 +222,42 @@ UdpTraceClient::GetMaxPacketSize()
|
||||
}
|
||||
|
||||
void
|
||||
UdpTraceClient::LoadTrace(const std::string& filename)
|
||||
UdpTraceClient::LoadTrace()
|
||||
{
|
||||
NS_LOG_FUNCTION(this << filename);
|
||||
uint32_t time = 0;
|
||||
uint32_t index = 0;
|
||||
uint32_t oldIndex = 0;
|
||||
uint32_t size = 0;
|
||||
uint32_t prevTime = 0;
|
||||
char frameType;
|
||||
TraceEntry entry;
|
||||
std::ifstream ifTraceFile;
|
||||
ifTraceFile.open(filename, std::ifstream::in);
|
||||
NS_LOG_FUNCTION(this);
|
||||
m_entries.clear();
|
||||
m_currentEntry = 0;
|
||||
|
||||
if (m_traceFile.empty())
|
||||
{
|
||||
LoadDefaultTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream ifTraceFile;
|
||||
ifTraceFile.open(m_traceFile, std::ifstream::in);
|
||||
if (!ifTraceFile.good())
|
||||
{
|
||||
LoadDefaultTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t oldIndex = 0;
|
||||
uint32_t prevTime = 0;
|
||||
while (ifTraceFile.good())
|
||||
{
|
||||
uint32_t index = 0;
|
||||
char frameType;
|
||||
uint32_t time = 0;
|
||||
uint32_t size = 0;
|
||||
ifTraceFile >> index >> frameType >> time >> size;
|
||||
|
||||
if (index == oldIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TraceEntry entry{};
|
||||
if (frameType == 'B')
|
||||
{
|
||||
entry.timeToSend = 0;
|
||||
@@ -266,9 +272,9 @@ UdpTraceClient::LoadTrace(const std::string& filename)
|
||||
m_entries.push_back(entry);
|
||||
oldIndex = index;
|
||||
}
|
||||
|
||||
ifTraceFile.close();
|
||||
NS_ASSERT_MSG(prevTime != 0, "A trace file can not contain B frames only.");
|
||||
m_currentEntry = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -291,7 +297,6 @@ UdpTraceClient::LoadDefaultTrace()
|
||||
}
|
||||
m_entries.push_back(entry);
|
||||
}
|
||||
m_currentEntry = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -128,10 +128,9 @@ class UdpTraceClient : public Application
|
||||
Address GetRemote() const;
|
||||
|
||||
/**
|
||||
* \brief Load a trace file
|
||||
* \param filename the trace file path
|
||||
* \brief Load current trace file
|
||||
*/
|
||||
void LoadTrace(const std::string& filename);
|
||||
void LoadTrace();
|
||||
|
||||
/**
|
||||
* \brief Load the default trace
|
||||
@@ -174,6 +173,7 @@ class UdpTraceClient : public Application
|
||||
static TraceEntry g_defaultEntries[]; //!< Default trace to send
|
||||
uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
|
||||
bool m_traceLoop; //!< Loop through the trace file
|
||||
std::string m_traceFile; //!< The location of the trace file
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user