Documentation
¶
Index ¶
- Constants
- func IPBase64(ip net.IP) string
- type BlockClock
- type BoundedNormalIntDistribution
- type Clock
- type Direction
- type Epoch
- type FixedRate
- type GenericPool
- type IP
- type IntDistribution
- type IntRange
- type Pool
- type Port
- type ProbabilityDistribution
- type Protocol
- type RandomGeneric
- type Rate
- type Session
- type SimulationSpan
- type TimeDistribution
- type UniformIntDistribution
- type UniformProbabilityDistribution
- type UniformRate
- type UniformTimeDistribution
- type UnitRange
- type WallClock
Examples ¶
Constants ¶
const ( PAUSED = false RUNNING = true )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BlockClock ¶
type BlockClock struct {
Done <-chan struct{}
// contains filtered or unexported fields
}
BlockClock - this simulation element waits until manually released.
This can be used to pause and resume a simulation.
func (*BlockClock) Pause ¶
func (s *BlockClock) Pause()
func (*BlockClock) Resume ¶
func (s *BlockClock) Resume()
func (*BlockClock) Run ¶
func (s *BlockClock) Run(simulation *Clock, ready chan<- struct{}, end <-chan struct{})
func (*BlockClock) Set ¶
func (s *BlockClock) Set(running bool)
type BoundedNormalIntDistribution ¶
Normal distribution of integers with bounds
Integers are generated based on µ and σ, but clipped to the range [min,max].
func (*BoundedNormalIntDistribution) Int ¶
func (r *BoundedNormalIntDistribution) Int() int
type Clock ¶
type Clock struct {
Span SimulationSpan
WindowSize time.Duration
Done <-chan struct{}
// contains filtered or unexported fields
}
Simulation Clock - used to receive simulation epochs so as to coordinate a complete simulation that spans many elements.
Each epoch defines a given window of simulation time. The simulation element must generate all its events for the given window, and then close the epoch.
Once all simulation elements have closed their epoch the clock will release the next window.
The simulation clock can also choose to tie the simulation clock to wall clock, should the simulation be expected to run at a realistic pace.
Similarly, the simulation clock can choose to only release epochs when other coordinating simulation instances have also concluded the epoch on their side. In this way we will be able to run a distributed simulation if needed.
func (*Clock) Attach ¶
Attach - used to register an element with the simulation clock.
Each simulation element attaches to the clock and is provided a session via which it coordinates with the clock and other elements. The simulation clock will publish an `Epoch` to each of the elements Attached at the start of the new epoch. Any elements that attach during a given epoch will only be enrolled into the next epoch.
All sessions must complete and close their respective `Epoch` before the simulation clock can proceed with generate an new `Epoch`.
type Direction ¶
type Direction bool
Direction designates the flow direction of a unidirectional flow from the point of view of the device processing the packet.
The direction is either egress (an uplink packet leaving the session device), or ingress (a downlink packet entering the session device).
type Epoch ¶
type Epoch struct {
// Log provides a logger to be used by a simulation element.
Log *log.Logger
// Tick is incremented each time a new epoch starts.
Tick int64
// The window of time spanning the entire simulation.
// (Note, it an unbounded simulation is indicated by a zero duration value.)
SimulationWindow SimulationSpan
// The window of time spanning this epoch in the simulation.
// (Note, is all epochs must have a finite non-zero duration value.)
EpochWindow SimulationSpan
// contains filtered or unexported fields
}
Simulation Epoch - defines a window in time for which the simulation element must generate simulation events. Once all events are generated the element must close the epoch.
type FixedRate ¶
type FixedRate struct {
OpsPerSecond float64
}
FixedRate defines a fixed number of operations per second.
type GenericPool ¶
type GenericPool[T comparable] struct { // The total number of available values set for the pool. // // Note, if zero, then the pool is unlimited. Limit int // Kind managed by the pool Kind string // contains filtered or unexported fields }
Provides access to a pool of values.
Values can be acquired or leased.
func (*GenericPool[T]) AcquireWithGenerator ¶
func (p *GenericPool[T]) AcquireWithGenerator(generator RandomGeneric[T]) (T, error)
Acquire provide a valid entry from the pool.
The pool will return an error if the size limit is reached. The pool will generate a new random value if needed. The pool will never issue the same value twice at the same time. The pool may reissue the same value if it was previously released.
Acquire is thread-safe.
func (*GenericPool[T]) Cap ¶
func (p *GenericPool[T]) Cap() int
func (*GenericPool[T]) Issued ¶
func (p *GenericPool[T]) Issued() int
Issued provides the number of unique values that are currently issued by the pool.
func (*GenericPool[T]) Release ¶
func (p *GenericPool[T]) Release(v T) error
Release previously acquired value back to the pool.
The pool will return an error the value was not previous issued.
Release is thread-safe.
func (*GenericPool[T]) Size ¶
func (p *GenericPool[T]) Size() int
type IntDistribution ¶
type IntDistribution interface {
// Number chosen from the distribution.
Int() int
}
type ProbabilityDistribution ¶
type ProbabilityDistribution interface {
// Probability chosen from the distribution over [0,1].
Probability() float64
}
type RandomGeneric ¶
type RandomGeneric[T comparable] func() T
type Rate ¶
type Rate interface {
// Number of operations per second chosen from the distribution.
Ops() float64
}
type Session ¶
type Session struct {
// Logger for simulation elements
Log *log.Logger
// E is the channel on which the clock sends epochs to the session.
E <-chan Epoch
// contains filtered or unexported fields
}
Simulation Session - provides a source of simulation epochs, and the mechanisms by which to coordinate with the rest of the simulation.
type SimulationSpan ¶
type SimulationSpan struct {
// The simulation time at the start of the window.
Start time.Time
// The size of the simulation window (zero if unbounded).
Duration time.Duration
}
SimulationSpan represents a span of time in the simulation.
Generally this will be interpreted as a half-open range [start, end).
func (*SimulationSpan) End ¶
func (s *SimulationSpan) End() time.Time
End the first point in time after the given span.
type TimeDistribution ¶
type UniformIntDistribution ¶
type UniformIntDistribution struct {
IntRange
}
Range defines the [min, max] value.
func (*UniformIntDistribution) Int ¶
func (r *UniformIntDistribution) Int() int
type UniformProbabilityDistribution ¶
Range defines subset of [0, 1).
func (*UniformProbabilityDistribution) Probability ¶
func (r *UniformProbabilityDistribution) Probability() float64
type UniformRate ¶
type UniformRate struct {
IntRange
}
Rate defines the [min, max) rate of operations per second.
func (*UniformRate) Ops ¶
func (r *UniformRate) Ops() int
type UniformTimeDistribution ¶
Range defines the [min, max) time range.
func (*UniformTimeDistribution) Duration ¶
func (r *UniformTimeDistribution) Duration() time.Duration
type WallClock ¶
type WallClock struct {
// Values greater than 1.0 will cause the simulation to run faster than wall-clock time if possible.
// Values less than 1.0 will cause the simulation to run slower than wall-clock time if possible.
// For convenience, a value of zero 0.0 will set the speed to 1.0.
Speed float64
}
WallClock - this simulation element always waits for a fraction of wall-clock time.
This can be used to speed up, or slow down your simulation.
Example ¶
// Po(X = λ) = \frac{λ^y·e^{-y}}{y!}
// With the expected value E(y) having a mean and variance of λ i.e. µ = σ² = λ
poisson := distuv.Poisson{
Lambda: 5.0,
Src: rand.NewPCG(1, 1),
}
fmt.Println("Generating 10 random numbers from a Poisson distribution (Lambda = 5.0):")
for i := range 10 {
// The Rand() method returns a random sample from the distribution.
sample := poisson.Rand()
fmt.Printf("Sample #%d: %d\n", i+1, int(sample))
}
Output: Generating 10 random numbers from a Poisson distribution (Lambda = 5.0): Sample #1: 4 Sample #2: 4 Sample #3: 7 Sample #4: 1 Sample #5: 7 Sample #6: 7 Sample #7: 7 Sample #8: 3 Sample #9: 2 Sample #10: 1