utils/replay-simulation.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 15:40:25 -0700
changeset 2971 75780f899be3
parent 2834 1aab57845b07
child 2913 66dd24c80d75
permissions -rw-r--r--
output the initial value of the attributes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    21
#include "ns3/simulator.h"
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    22
#include "ns3/scheduler-list.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    23
#include "ns3/scheduler-map.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    24
#include "ns3/scheduler-heap.h"
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    25
#include "ns3/nstime.h"
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    26
#include "ns3/system-wall-clock-ms.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include <vector>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include <deque>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include <fstream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
#include <iostream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    32
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
class LogReader {
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
public:
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    36
  void ReadFromFilename (char const *filename);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    37
  void Run (void);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    38
  void PrintStats (void);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
private:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    40
  struct Command {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    41
      enum {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    42
          REMOVE = 100,
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    43
          INSERT,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    44
          INSERT_LATER,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    45
          INSERT_REMOVE
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    46
      } m_type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    47
      // uid at which this command is supposed to be executed.
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    48
      uint32_t m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    49
      union {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    50
          struct {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    51
            // time at which the event is supposed to expire
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    52
            uint64_t m_evNs;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    53
            uint32_t m_evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    54
          } insert;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    55
          struct {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    56
            // location in the array of events to remove where
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    57
            // to insert this event once it is inserted in 
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    58
            // the scheduler.
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    59
            uint32_t m_evLoc; 
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    60
            // time at which the event is supposed to expire
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    61
            uint64_t m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    62
          } insertRemove;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    63
      };
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    64
  };
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    65
  void ExecuteLogCommands (uint32_t uid);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    67
  typedef std::vector<struct Command> Commands;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    68
  typedef std::vector<struct Command>::iterator CommandsI;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    69
  typedef std::vector<EventId> RemoveEvents;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    70
  typedef std::vector<EventId>::iterator RemoveEventsI;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    71
  
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    73
  Commands m_commands;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    74
  CommandsI m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    75
  RemoveEvents m_removeEvents;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    76
  uint32_t m_uid;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
};
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
void
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    83
LogReader::ReadFromFilename (char const *filename)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    85
  std::ifstream log;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    86
  std::cout << "read log..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    87
  Removes removes;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    88
  log.open (filename);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    89
  while (!log.eof ()) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    90
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    91
      std::string type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    92
      log >> type;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    93
      if (type == "i") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    94
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    95
          uint32_t nowUid, evUid;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    96
          uint64_t nowNs, evNs;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
    97
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    98
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    99
          cmd.m_type = Command::INSERT;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   100
          cmd.m_uid = nowUid;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   101
          cmd.insert.m_evNs = evNs;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   102
          cmd.insert.m_evUid = evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   103
          m_commands.push_back (cmd);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   104
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   105
      else if (type == "r") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   106
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   107
          uint32_t nowUid, evUid;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   108
          uint64_t nowNs, evNs;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   109
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   110
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   111
          cmd.m_type = Command::REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   112
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   113
          m_commands.push_back (cmd);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   114
          removes.push_back (std::make_pair (nowUid, evUid));
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   115
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   116
      else if (type == "il") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   117
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   118
          uint32_t nowUid, evUid;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   119
          uint64_t nowNs, evNs;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   120
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   121
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   122
          cmd.m_type = Command::INSERT_LATER;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   123
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   124
          m_commands.push_back (cmd);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   125
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   126
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   127
  log.close ();
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   129
  std::cout << "gather insert/removes, commands="<<m_commands.size () 
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   130
            << ", removes=" << removes.size () << "..." << std::endl;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   131
  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   132
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   133
      if (i->m_type == Command::INSERT) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   134
        {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   135
          for (RemovesI j = removes.begin (); j != removes.end (); j++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   136
            {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   137
              if (j->second == i->insert.m_evUid) 
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   138
                {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   139
                  // this insert will be removed later.
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   140
                  uint64_t ns = i->insert.m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   141
                  uint32_t uid = i->m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   142
                  i->m_type = Command::INSERT_REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   143
                  i->m_uid = uid;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   144
                  i->insertRemove.m_evNs = ns;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   145
                  i->insertRemove.m_evLoc = j->first;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   146
                  break;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   147
                }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   148
            }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   149
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   150
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   151
  std::cout << "calculate remove locations..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   152
  // calculate the final insert/remove location.
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   153
  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   154
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   155
      if (i->m_type == Command::INSERT_REMOVE) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   156
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   157
          uint32_t loc = 0;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   158
          for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   159
            {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   160
              if (tmp->m_type == Command::REMOVE) 
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   161
                {
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   162
                  if (tmp->m_uid == i->insertRemove.m_evLoc) 
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   163
                    {
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   164
                      i->insertRemove.m_evLoc = loc;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   165
                      break;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   166
                    }
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   167
                  loc++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   168
                }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   169
            }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   170
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   171
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   174
LogReader::ExecuteLogCommands (uint32_t uid)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
{
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   176
  if (m_command == m_commands.end ()) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   177
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   178
      return;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   179
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   180
  //std::cout << "one event, uid=" <<m_uid<< std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   181
  struct Command cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   182
  //std::cout << "cmd uid=" <<cmd.m_uid<< std::endl;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   183
  while (cmd.m_uid == uid) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   184
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   185
      m_command++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   186
      switch (cmd.m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   187
      case Command::INSERT:
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   188
        //std::Cout << "exec insert now=" << Simulator::Now ().GetNanoSeconds ()
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   189
        //<< ", time=" << cmd.insert.m_evNs << std::endl;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   190
        Simulator::Schedule (NanoSeconds (cmd.insert.m_evNs) - Now (), 
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   191
                             &LogReader::ExecuteLogCommands, this, m_uid);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   192
        m_uid++;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   193
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   195
          //std::cout << "exec insert later" << std::endl;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   196
          Simulator::ScheduleNow (&LogReader::ExecuteLogCommands, this, m_uid);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   197
          m_uid++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   198
          break;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   199
      case Command::REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   200
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   201
          //std::cout << "exec remove" << std::endl;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   202
          EventId id = m_removeEvents.back ();
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   203
          m_removeEvents.pop_back ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   204
          Simulator::Remove (id);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   205
        } break;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   206
      case Command::INSERT_REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   207
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   208
          //std::cout << "exec insert remove" << std::endl;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   209
          EventId id = Simulator::Schedule (NanoSeconds (cmd.insertRemove.m_evNs) - Now (),
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   210
                                            &LogReader::ExecuteLogCommands, this, m_uid);
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 205
diff changeset
   211
          NS_ASSERT (id.GetUid () == m_uid);
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   212
          if (cmd.insertRemove.m_evLoc + 1 > m_removeEvents.size ())
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   213
            {
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   214
              uint32_t missing = cmd.insertRemove.m_evLoc + 1 - m_removeEvents.size ();
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   215
              m_removeEvents.insert (m_removeEvents.begin (),
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   216
                                     missing, id);
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   217
            }
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   218
          uint32_t index = m_removeEvents.size () - cmd.insertRemove.m_evLoc - 1;
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   219
          m_removeEvents[index] = id;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   220
          m_uid++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   221
        } break;
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   222
      default:
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 205
diff changeset
   223
        NS_ASSERT (false);
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   224
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   225
      }
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   226
      cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   227
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   231
LogReader::PrintStats (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   233
  uint32_t nInserts = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   234
  uint32_t nRemoves = 0;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   235
  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   236
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   237
      switch (i->m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   238
      case Command::INSERT:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   239
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   240
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   241
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   242
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   243
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   244
      case Command::INSERT_REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   245
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   246
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   247
      case Command::REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   248
          nRemoves++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   249
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   250
      }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   251
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   252
  std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   253
  std::cout << "run simulation..."<<std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   257
LogReader::Run (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
{
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   259
  m_uid = 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   260
  SystemWallClockMs time;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   261
  time.Start ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   262
  m_command = m_commands.begin ();
201
b7635c5d5bdf make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 197
diff changeset
   263
  ExecuteLogCommands (0);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   264
  Simulator::Run ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   265
  unsigned long long delta = time.End ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   266
  double delay = ((double)delta)/1000;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   267
  std::cout << "runtime="<<delay<<"s"<<std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   273
  char const *input = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   274
  uint32_t n = 1;
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   275
  bool is_map = false;
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   276
  bool is_list = false;
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   277
  bool is_heap = false;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   278
  while (argc > 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   279
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   280
      if (strcmp ("--list", argv[0]) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   281
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   282
          is_list = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   283
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   284
      else if (strcmp ("--heap", argv[0]) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   285
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   286
          is_heap = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   287
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   288
      else if (strcmp ("--map", argv[0]) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   289
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   290
          is_map = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   291
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   292
      else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   293
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   294
          n = atoi (argv[0]+strlen ("--n="));
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   295
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   296
      else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   297
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   298
          input = argv[0] + strlen ("--input=");
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   299
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   300
      else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   301
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   302
          char const *filename = argv[0] + strlen ("--log=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   303
          Simulator::EnableLogTo (filename);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   304
        }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   305
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   306
      argv++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   307
    }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   308
  if (input == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   309
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   310
      std::cerr << "need --input=[filename] option" << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   311
      return 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   312
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   313
  LogReader log;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   314
  log.ReadFromFilename (input);
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   315
  std::cout << "start runs..." << std::endl;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   316
  for (uint32_t i = 0; i < n; i++) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   317
    {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   318
      if (is_map)
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   319
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   320
          Simulator::SetScheduler (CreateObject<SchedulerMap> ());
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   321
        }
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   322
      else if (is_list)
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   323
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   324
          Simulator::SetScheduler (CreateObject<SchedulerList> ());
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   325
        }
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   326
      else if (is_heap)
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   327
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   328
          Simulator::SetScheduler (CreateObject<SchedulerHeap> ());
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   329
        }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   330
      log.Run ();
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   331
      Simulator::Destroy ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   332
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
}