utils/replay-simulation.cc
author Craig Dowell <craigdo@ee.washington.edu>
Mon, 30 Jun 2008 13:46:33 -0700
changeset 3359 5768685f9fdb
parent 2913 66dd24c80d75
child 3365 6409d2460601
permissions -rw-r--r--
Added tag ns-3.1 for changeset 42504fb1f7be
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
2913
66dd24c80d75 bug 143: rename scheduler files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    21
#include "ns3/simulator-module.h"
66dd24c80d75 bug 143: rename scheduler files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    22
#include "ns3/core-module.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include <vector>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <deque>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include <fstream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include <iostream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    28
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
class LogReader {
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
public:
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    32
  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
    33
  void Run (void);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    34
  void PrintStats (void);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
private:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    36
  struct Command {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    37
      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
    38
          REMOVE = 100,
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    39
          INSERT,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    40
          INSERT_LATER,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    41
          INSERT_REMOVE
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    42
      } m_type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    43
      // 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
    44
      uint32_t m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    45
      union {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    46
          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
    47
            // 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
    48
            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
    49
            uint32_t m_evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    50
          } insert;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    51
          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
    52
            // 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
    53
            // 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
    54
            // 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
    55
            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
    56
            // 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
    57
            uint64_t m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    58
          } insertRemove;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    59
      };
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    60
  };
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    61
  void ExecuteLogCommands (uint32_t uid);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
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
    63
  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
    64
  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
    65
  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
    66
  typedef std::vector<EventId>::iterator RemoveEventsI;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    67
  
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    69
  Commands m_commands;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    70
  CommandsI m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    71
  RemoveEvents m_removeEvents;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    72
  uint32_t m_uid;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
};
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
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
    77
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
void
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    79
LogReader::ReadFromFilename (char const *filename)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    81
  std::ifstream log;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    82
  std::cout << "read log..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    83
  Removes removes;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    84
  log.open (filename);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    85
  while (!log.eof ()) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    86
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    87
      std::string type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    88
      log >> type;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    89
      if (type == "i") 
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
          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
    92
          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
    93
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    94
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    95
          cmd.m_type = Command::INSERT;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    96
          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
    97
          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
    98
          cmd.insert.m_evUid = evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    99
          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
   100
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   101
      else if (type == "r") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   102
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   103
          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
   104
          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
   105
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   106
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   107
          cmd.m_type = Command::REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   108
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   109
          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
   110
          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
   111
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   112
      else if (type == "il") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   113
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   114
          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
   115
          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
   116
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   117
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   118
          cmd.m_type = Command::INSERT_LATER;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   119
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   120
          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
   121
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   122
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   123
  log.close ();
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
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
   125
  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
   126
            << ", 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
   127
  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
   128
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   129
      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
   130
        {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   131
          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
   132
            {
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
   133
              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
   134
                {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   135
                  // 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
   136
                  uint64_t ns = i->insert.m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   137
                  uint32_t uid = i->m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   138
                  i->m_type = Command::INSERT_REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   139
                  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
   140
                  i->insertRemove.m_evNs = ns;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   141
                  i->insertRemove.m_evLoc = j->first;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   142
                  break;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   143
                }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   144
            }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   145
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   146
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   147
  std::cout << "calculate remove locations..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   148
  // 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
   149
  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
   150
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   151
      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
   152
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   153
          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
   154
          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
   155
            {
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
   156
              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
   157
                {
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
   158
                  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
   159
                    {
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
                      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
   161
                      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
   162
                    }
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
                  loc++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   164
                }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   165
            }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   166
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   167
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   170
LogReader::ExecuteLogCommands (uint32_t uid)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
{
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   172
  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
   173
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   174
      return;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   175
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   176
  //std::cout << "one event, uid=" <<m_uid<< std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   177
  struct Command cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   178
  //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
   179
  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
   180
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   181
      m_command++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   182
      switch (cmd.m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   183
      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
   184
        //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
   185
        //<< ", 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
   186
        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
   187
                             &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
   188
        m_uid++;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   189
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   190
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   191
          //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
   192
          Simulator::ScheduleNow (&LogReader::ExecuteLogCommands, this, m_uid);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   193
          m_uid++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   194
          break;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   195
      case Command::REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   196
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   197
          //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
   198
          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
   199
          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
   200
          Simulator::Remove (id);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   201
        } break;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   202
      case Command::INSERT_REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   203
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   204
          //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
   205
          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
   206
                                            &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
   207
          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
   208
          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
   209
            {
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
   210
              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
   211
              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
   212
                                     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
   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 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
   215
          m_removeEvents[index] = id;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   216
          m_uid++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   217
        } 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
   218
      default:
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 205
diff changeset
   219
        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
   220
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   221
      }
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   222
      cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   223
  }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   227
LogReader::PrintStats (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   229
  uint32_t nInserts = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   230
  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
   231
  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
   232
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   233
      switch (i->m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   234
      case Command::INSERT:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   235
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   236
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   237
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   238
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   239
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   240
      case Command::INSERT_REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   241
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   242
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   243
      case Command::REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   244
          nRemoves++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   245
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   246
      }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   247
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   248
  std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   249
  std::cout << "run simulation..."<<std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   253
LogReader::Run (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
{
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
   255
  m_uid = 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   256
  SystemWallClockMs time;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   257
  time.Start ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   258
  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
   259
  ExecuteLogCommands (0);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   260
  Simulator::Run ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   261
  unsigned long long delta = time.End ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   262
  double delay = ((double)delta)/1000;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   263
  std::cout << "runtime="<<delay<<"s"<<std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   269
  char const *input = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   270
  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
   271
  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
   272
  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
   273
  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
   274
  while (argc > 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   275
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   276
      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
   277
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   278
          is_list = true;
197
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
      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
   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_heap = 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 ("--map", 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_map = 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 (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
   289
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   290
          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
   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 ("--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
   293
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   294
          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
   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 ("--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
   297
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   298
          char const *filename = argv[0] + strlen ("--log=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   299
          Simulator::EnableLogTo (filename);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   300
        }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   301
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   302
      argv++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   303
    }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   304
  if (input == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   305
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   306
      std::cerr << "need --input=[filename] option" << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   307
      return 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   308
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   309
  LogReader log;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   310
  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
   311
  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
   312
  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
   313
    {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   314
      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
   315
        {
2913
66dd24c80d75 bug 143: rename scheduler files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   316
          Simulator::SetScheduler (CreateObject<MapScheduler> ());
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   317
        }
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   318
      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
   319
        {
2913
66dd24c80d75 bug 143: rename scheduler files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   320
          Simulator::SetScheduler (CreateObject<ListScheduler> ());
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_heap)
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   323
        {
2913
66dd24c80d75 bug 143: rename scheduler files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   324
          Simulator::SetScheduler (CreateObject<HeapScheduler> ());
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   325
        }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   326
      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
   327
      Simulator::Destroy ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   328
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
}