utils/replay-simulation.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 21 Mar 2008 13:41:16 -0700
changeset 2693 56e28e34e109
parent 2559 ab98bf436a17
child 2834 1aab57845b07
permissions -rw-r--r--
TypeId::GetAttributeListN -> TypeId::GetAttributeN
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
 * All rights reserved.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * 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
     7
 * 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
     8
 * published by the Free Software Foundation;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * 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
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    22
#include "ns3/simulator.h"
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    23
#include "ns3/scheduler-list.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    24
#include "ns3/scheduler-map.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
    25
#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
    26
#include "ns3/nstime.h"
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    27
#include "ns3/system-wall-clock-ms.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include <vector>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include <deque>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
#include <fstream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
#include <iostream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    33
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
class LogReader {
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
public:
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    37
  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
    38
  void Run (void);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    39
  void PrintStats (void);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
private:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    41
  struct Command {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    42
      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
    43
          REMOVE = 100,
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    44
          INSERT,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    45
          INSERT_LATER,
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    46
          INSERT_REMOVE
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    47
      } m_type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    48
      // 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
    49
      uint32_t m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    50
      union {
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
            // 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
    53
            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
    54
            uint32_t m_evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    55
          } insert;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    56
          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
    57
            // 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
    58
            // 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
    59
            // 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
    60
            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
    61
            // 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
    62
            uint64_t m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    63
          } insertRemove;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    64
      };
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    65
  };
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    66
  void ExecuteLogCommands (uint32_t uid);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
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
    68
  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
    69
  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
    70
  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
    71
  typedef std::vector<EventId>::iterator RemoveEventsI;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    72
  
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    74
  Commands m_commands;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    75
  CommandsI m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    76
  RemoveEvents m_removeEvents;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    77
  uint32_t m_uid;
12
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
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
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
    82
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
void
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    84
LogReader::ReadFromFilename (char const *filename)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    86
  std::ifstream log;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    87
  std::cout << "read log..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    88
  Removes removes;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    89
  log.open (filename);
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    90
  while (!log.eof ()) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    91
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    92
      std::string type;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    93
      log >> type;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    94
      if (type == "i") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    95
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    96
          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
    97
          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
    98
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    99
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   100
          cmd.m_type = Command::INSERT;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   101
          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
   102
          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
   103
          cmd.insert.m_evUid = evUid;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   104
          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
   105
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   106
      else if (type == "r") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   107
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   108
          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
   109
          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
   110
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   111
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   112
          cmd.m_type = Command::REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   113
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   114
          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
   115
          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
   116
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   117
      else if (type == "il") 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   118
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   119
          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
   120
          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
   121
          log >> nowUid >> nowNs >> evUid >> evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   122
          struct Command cmd;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   123
          cmd.m_type = Command::INSERT_LATER;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   124
          cmd.m_uid = nowUid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   125
          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
   126
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   127
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   128
  log.close ();
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
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
   130
  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
   131
            << ", 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
   132
  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
   133
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   134
      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
   135
        {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   136
          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
   137
            {
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
   138
              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
   139
                {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   140
                  // 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
   141
                  uint64_t ns = i->insert.m_evNs;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   142
                  uint32_t uid = i->m_uid;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   143
                  i->m_type = Command::INSERT_REMOVE;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   144
                  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
   145
                  i->insertRemove.m_evNs = ns;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   146
                  i->insertRemove.m_evLoc = j->first;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   147
                  break;
197
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
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   151
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   152
  std::cout << "calculate remove locations..." << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   153
  // 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
   154
  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
   155
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   156
      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
   157
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   158
          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
   159
          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
   160
            {
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
   161
              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
   162
                {
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
   163
                  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
   164
                    {
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
                      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
   166
                      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
   167
                    }
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
   168
                  loc++;
197
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
        }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   172
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   175
LogReader::ExecuteLogCommands (uint32_t uid)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
{
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   177
  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
   178
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   179
      return;
197
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
  //std::cout << "one event, uid=" <<m_uid<< std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   182
  struct Command cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   183
  //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
   184
  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
   185
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   186
      m_command++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   187
      switch (cmd.m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   188
      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
   189
        //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
   190
        //<< ", 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
   191
        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
   192
                             &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
   193
        m_uid++;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   194
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   195
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   196
          //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
   197
          Simulator::ScheduleNow (&LogReader::ExecuteLogCommands, this, m_uid);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   198
          m_uid++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   199
          break;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   200
      case Command::REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   201
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   202
          //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
   203
          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
   204
          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
   205
          Simulator::Remove (id);
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   206
        } break;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   207
      case Command::INSERT_REMOVE: 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   208
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   209
          //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
   210
          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
   211
                                            &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
   212
          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
   213
          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
   214
            {
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
              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
   216
              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
   217
                                     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
   218
            }
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
          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
   220
          m_removeEvents[index] = id;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   221
          m_uid++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   222
        } 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
   223
      default:
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 205
diff changeset
   224
        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
   225
        break;
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   226
      }
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   227
      cmd = *m_command;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   228
  }
12
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
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   232
LogReader::PrintStats (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   234
  uint32_t nInserts = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   235
  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
   236
  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
   237
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   238
      switch (i->m_type) {
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   239
      case Command::INSERT:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   240
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   241
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   242
      case Command::INSERT_LATER:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   243
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   244
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   245
      case Command::INSERT_REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   246
          nInserts++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   247
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   248
      case Command::REMOVE:
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   249
          nRemoves++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   250
          break;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   251
      }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   252
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   253
  std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   254
  std::cout << "run simulation..."<<std::endl;
12
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
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   258
LogReader::Run (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
{
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
   260
  m_uid = 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   261
  SystemWallClockMs time;
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   262
  time.Start ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   263
  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
   264
  ExecuteLogCommands (0);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   265
  Simulator::Run ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   266
  unsigned long long delta = time.End ();
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   267
  double delay = ((double)delta)/1000;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   268
  std::cout << "runtime="<<delay<<"s"<<std::endl;
12
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
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   274
  char const *input = 0;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   275
  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
   276
  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
   277
  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
   278
  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
   279
  while (argc > 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   280
    {
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   281
      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
   282
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   283
          is_list = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   284
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   285
      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
   286
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   287
          is_heap = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   288
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   289
      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
   290
        {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   291
          is_map = true;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   292
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   293
      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
   294
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   295
          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
   296
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   297
      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
   298
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   299
          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
   300
        } 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   301
      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
   302
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   303
          char const *filename = argv[0] + strlen ("--log=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   304
          Simulator::EnableLogTo (filename);
197
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
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   307
      argv++;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   308
    }
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   309
  if (input == 0) 
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   310
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   311
      std::cerr << "need --input=[filename] option" << std::endl;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   312
      return 1;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   313
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
   314
  LogReader log;
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   315
  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
   316
  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
   317
  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
   318
    {
205
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   319
      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
   320
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   321
          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
   322
        }
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   323
      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
   324
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   325
          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
   326
        }
681e44f1cf58 make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 201
diff changeset
   327
      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
   328
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   329
          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
   330
        }
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   331
      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
   332
      Simulator::Destroy ();
197
8346ab3528bf fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   333
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
}