Module Clock

module Clock: sig .. end
This module creates an alarm-clock that schedule registered events. There are two modes of operation: realtime and not realtime.

When in realtime mode (the default), the clock will merely follow wall-clock. Then, scheduling an event in the future is equivalent to Unix.sleep for some time. This is not very interesting but is required whenever you plan to work with real network devices and outside world. On the other hand, if your simulated network does not communicates with the outside world, for instance because your objective is to build a pcap file, then you can use not realtime mode and then play your simulation at full speed (and full CPU), and produce a pcap file representing, say, the workload of a day in minutes, or conversely a very busy hour in several hours but with all packets and accurate timestamps.


val debug : bool
val realtime : bool Batteries.ref

Private Types


module Time: sig .. end
Time.t represents a given timestamp (ie.
module Interval: sig .. end
val printer : 'a BatIO.output -> Time.t -> unit

Current running time


module Map: Batteries.Map.Make(sig
type t = Clock.Time.t 
val compare : t -> t -> int
end)
type clock = {
   mutable now : Time.t;
   mutable events : (unit -> unit) Map.t;
}
A clock is a current timestamp and the set of future events.
val current : clock
We have only one clock so can run only one simulation at the same time.
val now : unit -> Time.t
Return the current simulation time.
val cond_lock : Mutex.t
val cond : Condition.t
val signal_me : unit -> unit
val epsilon : Interval.t
val at : Time.t -> ('a -> unit) -> 'a -> unit
at t f x will execute f x when simulation clock reaches time t.
val delay : Interval.t -> ('a -> unit) -> 'a -> unit
delay d f x will delay the execution of f x by the interval d.
val asap : ('a -> unit) -> 'a -> unit
val synch : unit -> unit
Synchronize internal clock with realtime clock. You must call this after real time passes (for instance after a blocking call). Otherwise, time jumps from one registered event to the next.
val next_event : unit -> unit
Will process the next event
val run : bool -> unit
run true will run forever while run false will return once no more events are waiting. If you chose no to run forever, beware that waiting for an answer from the outside world is _not_ a clock event. You should probably run forever whenever you communicate with the outside.