src/simulator/default-simulator-impl.h
author Craig Dowell <craigdo@ee.washington.edu>
Fri, 18 Jul 2008 21:51:31 -0700
changeset 3470 21022872009d
child 3489 b5ef00370c70
permissions -rw-r--r--
make simulator implementation replaceable via global default value
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3470
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2005,2006 INRIA
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 *
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
 */
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#ifndef DEFAULT_SIMULATOR_IMPL_H
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#define DEFAULT_SIMULATOR_IMPL_H
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "simulator-impl.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "scheduler.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "event-impl.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "ns3/ptr.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
#include "ns3/assert.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
#include "ns3/log.h"
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#include <list>
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include <fstream>
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
namespace ns3 {
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
  class DefaultSimulatorImpl : public SimulatorImpl
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
{
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
public:
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  static TypeId GetTypeId (void);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  DefaultSimulatorImpl ();
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
  ~DefaultSimulatorImpl ();
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  void Destroy ();
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  void EnableLogTo (char const *filename);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  bool IsFinished (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  Time Next (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  void Stop (void);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  void Stop (Time const &time);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  EventId ScheduleNow (const Ptr<EventImpl> &event);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  EventId ScheduleDestroy (const Ptr<EventImpl> &event);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  void Remove (const EventId &ev);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  void Cancel (const EventId &ev);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  bool IsExpired (const EventId &ev) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  void Run (void);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  Time Now (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  Time GetDelayLeft (const EventId &id) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  Time GetMaximumSimulationTime (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  void SetScheduler (Ptr<Scheduler> scheduler);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  Ptr<Scheduler> GetScheduler (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
private:
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  void ProcessOneEvent (void);
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  uint64_t NextTs (void) const;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  typedef std::list<EventId> DestroyEvents;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  DestroyEvents m_destroyEvents;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  uint64_t m_stopAt;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  bool m_stop;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  Ptr<Scheduler> m_events;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  uint32_t m_uid;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  uint32_t m_currentUid;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  uint64_t m_currentTs;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  std::ofstream m_log;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  std::ifstream m_inputLog;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  bool m_logEnable;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  // number of events that have been inserted but not yet scheduled,
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  // not counting the "destroy" events; this is used for validation
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  int m_unscheduledEvents;
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
};
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
} // namespace ns3
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
21022872009d make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
#endif /* DEFAULT_SIMULATOR_IMPL_H */