From bdc613c1df4493c0f63a31b59caa0b3784a4a61d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 12 Dec 2006 14:59:13 +0100 Subject: [PATCH] fix the Simulation event replayer: make it build --- SConstruct | 6 ++ utils/replay-simulation.cc | 176 ++++++++++++++++++++++--------------- 2 files changed, 110 insertions(+), 72 deletions(-) diff --git a/SConstruct b/SConstruct index 784b63739..090b6b764 100644 --- a/SConstruct +++ b/SConstruct @@ -157,6 +157,12 @@ bench_simu.set_executable() bench_simu.add_dep('simulator') bench_simu.add_source('bench-simulator.cc') +replay_simu = build.Ns3Module('replay-simulation', 'utils') +ns3.add(replay_simu) +replay_simu.set_executable() +replay_simu.add_dep('simulator') +replay_simu.add_source('replay-simulation.cc') + # samples sample_callback = build.Ns3Module('sample-callback', 'samples') diff --git a/utils/replay-simulation.cc b/utils/replay-simulation.cc index 25c597efc..be47ed59e 100644 --- a/utils/replay-simulation.cc +++ b/utils/replay-simulation.cc @@ -20,9 +20,8 @@ */ #include "ns3/simulator.h" -#include "ns3/event.h" -#include "ns3/event.tcc" -#include "ns3/wall-clock-ms.h" +#include "ns3/nstime.h" +#include "ns3/system-wall-clock-ms.h" #include #include #include @@ -32,9 +31,9 @@ using namespace ns3; class LogReader { public: - void readFrom_filename (char const *filename); - void run (void); - void printStats (void); + void ReadFromFilename (char const *filename); + void Run (void); + void PrintStats (void); private: struct Command { enum { @@ -60,11 +59,11 @@ private: } insertRemove; }; }; - void executeLogCommands (uint32_t uid); + void ExecuteLogCommands (uint32_t uid); typedef std::deque Commands; typedef std::deque::iterator CommandsI; - typedef std::deque RemoveEvents; + typedef std::deque RemoveEvents; Commands m_commands; @@ -77,16 +76,18 @@ typedef std::vector > Removes; typedef std::vector >::iterator RemovesI; void -LogReader::ReadFrom_filename (char const *filename) +LogReader::ReadFromFilename (char const *filename) { std::ifstream log; std::cout << "read log..." << std::endl; Removes removes; log.open (filename); - while (!log.eof ()) { + while (!log.eof ()) + { std::string type; log >> type; - if (type == "i") { + if (type == "i") + { uint32_t nowUid, evUid; uint64_t nowUs, evUs; log >> nowUid >> nowUs >> evUid >> evUs; @@ -95,7 +96,9 @@ LogReader::ReadFrom_filename (char const *filename) cmd.m_uid = nowUid; cmd.insert.m_evUs = evUs; m_commands.push_back (cmd); - } else if (type == "r") { + } + else if (type == "r") + { uint32_t nowUid, evUid; uint64_t nowUs, evUs; log >> nowUid >> nowUs >> evUid >> evUs; @@ -103,8 +106,10 @@ LogReader::ReadFrom_filename (char const *filename) cmd.m_type = Command::REMOVE; cmd.m_uid = nowUid; m_commands.push_back (cmd); - removes.push_back (std::Make_pair (nowUid, evUid)); - } else if (type == "il") { + removes.push_back (std::make_pair (nowUid, evUid)); + } + else if (type == "il") + { uint32_t nowUid, evUid; uint64_t nowUs, evUs; log >> nowUid >> nowUs >> evUid >> evUs; @@ -112,15 +117,19 @@ LogReader::ReadFrom_filename (char const *filename) cmd.m_type = Command::INSERT_LATER; cmd.m_uid = nowUid; m_commands.push_back (cmd); - } - } + } + } log.close (); std::cout << "gather insert removes..." << std::endl; - for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { - if (i->m_type == Command::INSERT) { - for (RemovesI j = removes.begin (); j != removes.end (); j++) { - if (j->second == i->m_uid) { + for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) + { + if (i->m_type == Command::INSERT) + { + for (RemovesI j = removes.begin (); j != removes.end (); j++) + { + if (j->second == i->m_uid) + { // this insert will be removed later. uint64_t us = i->insert.m_evUs; uint32_t uid = i->m_uid; @@ -129,63 +138,71 @@ LogReader::ReadFrom_filename (char const *filename) i->insertRemove.m_evUs = us; i->insertRemove.m_evLoc = j->first; break; - } - } - } - } + } + } + } + } std::cout << "calculate remove locations..." << std::endl; // calculate the final insert/remove location. - for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) { - if (i->m_type == Command::INSERT_REMOVE) { + for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) + { + if (i->m_type == Command::INSERT_REMOVE) + { uint32_t loc = 0; - for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) { + for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) + { if (tmp->m_type == Command::REMOVE && - tmp->m_uid == i->insertRemove.m_evLoc) { + tmp->m_uid == i->insertRemove.m_evLoc) + { i->insertRemove.m_evLoc = loc; break; - } + } loc++; - } - } - } + } + } + } } void LogReader::ExecuteLogCommands (uint32_t uid) { - if (m_command == m_commands.end ()) { + if (m_command == m_commands.end ()) + { return; - } + } //std::cout << "one event, uid=" <m_type) { case Command::INSERT: nInserts++; @@ -211,7 +229,7 @@ LogReader::PrintStats (void) nRemoves++; break; } - } + } std::cout << "inserts="< 0) { - if (strcmp ("--list", argv[0]) == 0) { + while (argc > 0) + { + if (strcmp ("--list", argv[0]) == 0) + { Simulator::SetLinkedList (); - } else if (strcmp ("--heap", argv[0]) == 0) { + } + else if (strcmp ("--heap", argv[0]) == 0) + { Simulator::SetBinaryHeap (); - } else if (strcmp ("--map", argv[0]) == 0) { + } + else if (strcmp ("--map", argv[0]) == 0) + { Simulator::SetStdMap (); - } else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) { + } + else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) + { n = atoi (argv[0]+strlen ("--n=")); - } else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) { + } + else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) + { input = argv[0] + strlen ("--input="); - } else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) { + } + else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) + { char const *filename = argv[0] + strlen ("--log="); Simulator::EnableLogTo (filename); - } + } argc--; argv++; - } - if (input == 0) { + } + if (input == 0) + { std::cerr << "need --input=[filename] option" << std::endl; return 1; - } + } LogReader log; - log.readFrom_filename (input); - for (uint32_t i = 0; i < n; i++) { - log.run (); - } + log.ReadFromFilename (input); + for (uint32_t i = 0; i < n; i++) + { + log.Run (); + } }