src/simulator/realtime-simulator-impl.h
author Guillaume Seguin <guillaume@segu.in>
Thu Nov 12 13:19:35 2009 +0100 (2009-11-12)
changeset 5507 915abd2b907b
parent 4552 8d3801089629
child 5521 37c6c83d4252
permissions -rw-r--r--
Simulator::SetScheduler now takes an ObjectFactory
craigdo@3560
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
craigdo@3560
     2
/*
craigdo@3560
     3
 * Copyright (c) 2008 University of Washington
craigdo@3560
     4
 *
craigdo@3560
     5
 * This program is free software; you can redistribute it and/or modify
craigdo@3560
     6
 * it under the terms of the GNU General Public License version 2 as
craigdo@3560
     7
 * published by the Free Software Foundation;
craigdo@3560
     8
 *
craigdo@3560
     9
 * This program is distributed in the hope that it will be useful,
craigdo@3560
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
craigdo@3560
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
craigdo@3560
    12
 * GNU General Public License for more details.
craigdo@3560
    13
 *
craigdo@3560
    14
 * You should have received a copy of the GNU General Public License
craigdo@3560
    15
 * along with this program; if not, write to the Free Software
craigdo@3560
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
craigdo@3560
    17
 */
craigdo@3560
    18
craigdo@3560
    19
#ifndef REALTIME_SIMULATOR_IMPL_H
craigdo@3560
    20
#define REALTIME_SIMULATOR_IMPL_H
craigdo@3560
    21
craigdo@3560
    22
#include "simulator-impl.h"
craigdo@3560
    23
craigdo@3560
    24
#include "scheduler.h"
craigdo@3560
    25
#include "synchronizer.h"
craigdo@3560
    26
#include "event-impl.h"
craigdo@3560
    27
craigdo@3560
    28
#include "ns3/ptr.h"
craigdo@3560
    29
#include "ns3/assert.h"
craigdo@3560
    30
#include "ns3/log.h"
gjc@3650
    31
#include "ns3/system-mutex.h"
craigdo@3560
    32
craigdo@3560
    33
#include <list>
craigdo@3560
    34
craigdo@3560
    35
namespace ns3 {
craigdo@3560
    36
craigdo@3560
    37
class RealtimeSimulatorImpl : public SimulatorImpl
craigdo@3560
    38
{
craigdo@3560
    39
public:
craigdo@3560
    40
  static TypeId GetTypeId (void);
craigdo@3560
    41
craigdo@3560
    42
  /**
craigdo@3560
    43
   * Enumeration of the types of packets supported in the class.
craigdo@3560
    44
   *
craigdo@3560
    45
   */
craigdo@3560
    46
  enum SynchronizationMode {
craigdo@3560
    47
    SYNC_BEST_EFFORT, /** Make a best effort to keep synced to real-time */
craigdo@3560
    48
    SYNC_HARD_LIMIT, /** Keep to real-time within a tolerance or die trying */
craigdo@3560
    49
  };
craigdo@3560
    50
craigdo@3560
    51
  RealtimeSimulatorImpl ();
craigdo@3560
    52
  ~RealtimeSimulatorImpl ();
craigdo@3560
    53
mathieu@3808
    54
  virtual void Destroy ();
mathieu@3808
    55
  virtual bool IsFinished (void) const;
mathieu@3808
    56
  virtual Time Next (void) const;
mathieu@3808
    57
  virtual void Stop (void);
mathieu@3808
    58
  virtual EventId Schedule (Time const &time, EventImpl *event);
mathieu@3808
    59
  virtual EventId ScheduleNow (EventImpl *event);
mathieu@3808
    60
  virtual EventId ScheduleDestroy (EventImpl *event);
mathieu@3808
    61
  virtual void Remove (const EventId &ev);
mathieu@3808
    62
  virtual void Cancel (const EventId &ev);
mathieu@3808
    63
  virtual bool IsExpired (const EventId &ev) const;
mathieu@3808
    64
  virtual void Run (void);
mathieu@3808
    65
  virtual void RunOneEvent (void);
mathieu@3808
    66
  virtual Time Now (void) const;
mathieu@3808
    67
  virtual Time GetDelayLeft (const EventId &id) const;
mathieu@3808
    68
  virtual Time GetMaximumSimulationTime (void) const;
guillaume@5507
    69
  virtual void SetScheduler (ObjectFactory schedulerFactory);
mathieu@3809
    70
mathieu@3816
    71
  void ScheduleRealtime (Time const &time, EventImpl *event);
mathieu@3816
    72
  void ScheduleRealtimeNow (EventImpl *event);
craigdo@3801
    73
  Time RealtimeNow (void) const;
craigdo@3560
    74
craigdo@3560
    75
  void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode);
craigdo@3560
    76
  RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode (void) const;
craigdo@3560
    77
craigdo@3560
    78
  void SetHardLimit (Time limit);
craigdo@3560
    79
  Time GetHardLimit (void) const;
craigdo@3560
    80
craigdo@3560
    81
private:
craigdo@3560
    82
  bool Running (void) const;
craigdo@3560
    83
  bool Realtime (void) const;
craigdo@3560
    84
craigdo@3560
    85
  void ProcessOneEvent (void);
craigdo@3560
    86
  uint64_t NextTs (void) const;
craigdo@3560
    87
craigdo@3560
    88
  typedef std::list<EventId> DestroyEvents;
craigdo@3560
    89
  DestroyEvents m_destroyEvents;
craigdo@3560
    90
  bool m_stop;
craigdo@3560
    91
  bool m_running;
craigdo@3560
    92
craigdo@3560
    93
  // The following variables are protected using the m_mutex
craigdo@3560
    94
  Ptr<Scheduler> m_events;
craigdo@3560
    95
  int m_unscheduledEvents;
craigdo@3560
    96
  uint32_t m_uid;
craigdo@3560
    97
  uint32_t m_currentUid;
craigdo@3560
    98
  uint64_t m_currentTs;
craigdo@3560
    99
craigdo@3560
   100
  mutable SystemMutex m_mutex;
craigdo@3560
   101
craigdo@3560
   102
  Ptr<Synchronizer> m_synchronizer;
craigdo@3561
   103
craigdo@3560
   104
  /**
craigdo@3560
   105
   * The policy to use if the simulation cannot keep synchronized to real-time.
craigdo@3560
   106
   */
craigdo@3560
   107
  SynchronizationMode m_synchronizationMode;
craigdo@3560
   108
craigdo@3560
   109
  /**
craigdo@3560
   110
   * The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
craigdo@3560
   111
   */
craigdo@3560
   112
  Time m_hardLimit;
craigdo@3560
   113
};
craigdo@3560
   114
craigdo@3560
   115
} // namespace ns3
craigdo@3560
   116
craigdo@3560
   117
#endif /* REALTIME_SIMULATOR_IMPL_H */