Documentation ¶
Index ¶
- type Action
- type Event
- func Aggregate(events ...Event) []Event
- func NewDelayedEvent(action Action, delay time.Duration, now time.Time) Event
- func NewFixedEvent(action Action, time time.Time) Event
- func NewPeriodicEvent(action Action, period time.Duration, t time.Time) Event
- func NewRepeatEvent(action RepeatAction, t time.Time) Event
- type EventBuffer
- type EventQueue
- type IPPacket
- type Node
- type Packet
- type Queue
- type RawPacket
- type RepeatAction
- type SimulatePacket
- type TransferCallback
- type UDPPacket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is what to do of an event, time of the event is passed in, return following events of this event
type Event ¶
type Event interface { // Time when to act Time() time.Time // Action what to do Action() Action // HookBefore hook the event with the given action handled before the actual action HookBefore(action Action) // HookAfter hook the event with the given action handled after the actual action HookAfter(action Action) }
Event is an action to be acted at the exactly time point
func NewDelayedEvent ¶
NewDelayedEvent create an event with delay
func NewFixedEvent ¶
NewFixedEvent create an event at the time point
func NewPeriodicEvent ¶
NewPeriodicEvent create a periodic event, generate itself each time
func NewRepeatEvent ¶ added in v2.3.3
func NewRepeatEvent(action RepeatAction, t time.Time) Event
NewRepeatEvent create an event repeated after the return delay, if such delay is not negative
type EventBuffer ¶
type EventBuffer struct {
// contains filtered or unexported fields
}
EventBuffer is a thread-safe, lock-free buffer used to store simulated packets, implemented like a single link list
func (*EventBuffer) Insert ¶
func (b *EventBuffer) Insert(events ...Event)
Insert a simulated packet to the buffer, thread-safe
func (*EventBuffer) Reduce ¶
func (b *EventBuffer) Reduce(action func(event Event))
Reduce means clear the buffer and do an action on the event cleared, thread-safe
type EventQueue ¶ added in v2.2.0
type EventQueue struct {
// contains filtered or unexported fields
}
EventQueue is used to sort events according to the time of events
func NewEventQueue ¶ added in v2.2.0
func NewEventQueue(bucketSize time.Duration, maxBuckets int) *EventQueue
func (*EventQueue) Dequeue ¶ added in v2.2.0
func (q *EventQueue) Dequeue() Event
func (*EventQueue) Enqueue ¶ added in v2.2.0
func (q *EventQueue) Enqueue(event Event)
func (*EventQueue) IsEmpty ¶ added in v2.2.0
func (q *EventQueue) IsEmpty() bool
func (*EventQueue) Length ¶ added in v2.2.0
func (q *EventQueue) Length() int
func (*EventQueue) Peek ¶ added in v2.2.0
func (q *EventQueue) Peek() Event
type IPPacket ¶
type IPPacket struct { Version byte // 4bit HeaderSize byte // 4 bit ServiceType byte // 8 bit TotalSize uint16 // 16 bit Identifier uint16 // 16 bit Flags byte // 3 bit FragmentOffset uint16 // 13 bit TTL byte // 8 bit Protocol byte // 8 bit HeaderChecksum uint16 // 16 bit SourceAddress uint32 // 32 bit DestinationAddress uint32 // 32 bit Options []byte // vary Data Packet }
IPPacket is a packet for the ip protocol (ipv4) DO NOT USE NOW, need further support
type Node ¶
type Node interface { // Check whether the node can work correctly, usually called by network just before the simulation Check() // GetNext nodes of the node GetNext() []Node // SetNext nodes of the node, should not be used during simulation SetNext(nodes ...Node) // Transfer the given packet to somewhere at sometime the node decides // time calculation should use the given time as current time point // return the following events caused by the packet transfer Transfer(packet Packet, now time.Time) []Event // GetTransferCallback get the TransferCallback of the node GetTransferCallback() TransferCallback // SetTransferCallback set the TransferCallback of the node, should not be used during simulation SetTransferCallback(callback TransferCallback) }
Node indicates a simulated node in the network
type Queue ¶ added in v2.2.0
type Queue struct {
// contains filtered or unexported fields
}
Queue is a ring queue implemented in array/slice O(1) time complexity for enqueue/dequeue/random access O(n) space complexity, where n is the maximum count of elements in the queue at the same time
func (*Queue) Dequeue ¶ added in v2.2.0
func (q *Queue) Dequeue() interface{}
Dequeue remove and return element at the head of the queue, panic if empty
func (*Queue) Do ¶ added in v2.2.0
func (q *Queue) Do(action func(interface{}))
Do iterate the queue with the given action
func (*Queue) Enqueue ¶ added in v2.2.0
func (q *Queue) Enqueue(data interface{})
Enqueue insert the given element to the end of queue
type RepeatAction ¶ added in v2.3.3
RepeatAction is same to Action, but repeated after the return delay. if return delay is negative, no longer repeat
type SimulatePacket ¶ added in v2.2.1
func (*SimulatePacket) Size ¶ added in v2.2.1
func (p *SimulatePacket) Size() int
type TransferCallback ¶
TransferCallback called when a packet is transferred