Documentation
¶
Index ¶
- type BufferedLinkHandler
- func (h *BufferedLinkHandler) AddToSlot(pkt ahead_port.PacketWithCycle, targetCycle int)
- func (h *BufferedLinkHandler) CanAcceptPacket(cycle int, targetCycle int) bool
- func (h *BufferedLinkHandler) CanSendPacket(cycle int, downstreamReady bool) bool
- func (h *BufferedLinkHandler) CheckSpace(cycle int) bool
- func (h *BufferedLinkHandler) ClearSlot(cycle int)
- func (h *BufferedLinkHandler) GetBandwidth() int
- func (h *BufferedLinkHandler) GetLatency() int
- func (h *BufferedLinkHandler) GetOccupancy(currentCycle int) []int
- func (h *BufferedLinkHandler) GetSlot(cycle int) []ahead_port.PacketWithCycle
- func (h *BufferedLinkHandler) GetSlots() [][]ahead_port.PacketWithCycle
- func (h *BufferedLinkHandler) GetTotalBackpressure() int
- func (h *BufferedLinkHandler) IncrementBackpressure()
- func (h *BufferedLinkHandler) Init(l *Link)
- func (h *BufferedLinkHandler) Process(l *Link, cycle int, targetCycle int, incoming []packet.Packet) error
- func (h *BufferedLinkHandler) Reset()
- func (h *BufferedLinkHandler) UpdateSlot(cycle int, packets []ahead_port.PacketWithCycle)
- type BufferlessLinkHandler
- type Link
- func (l *Link) AdvanceTo(targetCycle int) error
- func (l *Link) Bandwidth() int
- func (l *Link) CurrentCycle() int
- func (l *Link) GetHandler() LinkHandler
- func (l *Link) GetVisualState() string
- func (l *Link) Init()
- func (l *Link) Latency() int
- func (l *Link) PendingPacketCount() int
- func (l *Link) SetDownstreamPort(port ahead_port.InPort)
- func (l *Link) SetTickHook(hook func(cycle int))
- func (l *Link) SetUpstreamPort(port ahead_port.OutPort)
- func (l *Link) SnapshotOccupancy() []int
- func (l *Link) SourceID() int
- func (l *Link) TargetID() int
- func (l *Link) Tick(cycle int, targetCycle int) error
- func (l *Link) UpdateUpstreamReady(cycle int, ready bool)
- type LinkHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferedLinkHandler ¶
type BufferedLinkHandler struct {
// contains filtered or unexported fields
}
BufferedLinkHandler implements buffered flow control with backpressure.
Mechanism: - Ring buffer (slots) stores packets during transit (latency cycles) - Backpressure counter tracks accumulated delays when downstream is not ready - Bandwidth limit enforces maximum packets per slot
func NewBufferedLinkHandler ¶
func NewBufferedLinkHandler(latency, bandwidth int) *BufferedLinkHandler
NewBufferedLinkHandler creates a BufferedLinkHandler.
func (*BufferedLinkHandler) AddToSlot ¶
func (h *BufferedLinkHandler) AddToSlot(pkt ahead_port.PacketWithCycle, targetCycle int)
func (*BufferedLinkHandler) CanAcceptPacket ¶
func (h *BufferedLinkHandler) CanAcceptPacket(cycle int, targetCycle int) bool
func (*BufferedLinkHandler) CanSendPacket ¶
func (h *BufferedLinkHandler) CanSendPacket(cycle int, downstreamReady bool) bool
func (*BufferedLinkHandler) CheckSpace ¶
func (h *BufferedLinkHandler) CheckSpace(cycle int) bool
func (*BufferedLinkHandler) ClearSlot ¶
func (h *BufferedLinkHandler) ClearSlot(cycle int)
func (*BufferedLinkHandler) GetBandwidth ¶
func (h *BufferedLinkHandler) GetBandwidth() int
func (*BufferedLinkHandler) GetLatency ¶
func (h *BufferedLinkHandler) GetLatency() int
func (*BufferedLinkHandler) GetOccupancy ¶
func (h *BufferedLinkHandler) GetOccupancy(currentCycle int) []int
GetOccupancy returns the pending packet count per slot for buffered links.
func (*BufferedLinkHandler) GetSlot ¶
func (h *BufferedLinkHandler) GetSlot(cycle int) []ahead_port.PacketWithCycle
func (*BufferedLinkHandler) GetSlots ¶
func (h *BufferedLinkHandler) GetSlots() [][]ahead_port.PacketWithCycle
func (*BufferedLinkHandler) GetTotalBackpressure ¶
func (h *BufferedLinkHandler) GetTotalBackpressure() int
func (*BufferedLinkHandler) IncrementBackpressure ¶
func (h *BufferedLinkHandler) IncrementBackpressure()
func (*BufferedLinkHandler) Init ¶
func (h *BufferedLinkHandler) Init(l *Link)
ReadyDepth returns the number of cycles to pre-mark as ready for bootstrapping. For buffered links, we need to fill the pipeline (latency) plus one for cycle 0.
func (*BufferedLinkHandler) Process ¶
func (h *BufferedLinkHandler) Process(l *Link, cycle int, targetCycle int, incoming []packet.Packet) error
Process implements the LinkHandler interface for BufferedLinkHandler.
func (*BufferedLinkHandler) Reset ¶
func (h *BufferedLinkHandler) Reset()
Reset resets the handler state.
func (*BufferedLinkHandler) UpdateSlot ¶
func (h *BufferedLinkHandler) UpdateSlot(cycle int, packets []ahead_port.PacketWithCycle)
type BufferlessLinkHandler ¶
type BufferlessLinkHandler struct {
// contains filtered or unexported fields
}
BufferlessLinkHandler implements an always-ready flow control strategy without physical buffering. It attempts to send packets immediately. If downstream is busy, packets are kept in l.pendingPackets. BufferlessLinkHandler implements an always-ready flow control strategy without physical buffering. It attempts to send packets immediately. If downstream is busy, packets are kept in pending map.
func NewBufferlessLinkHandler ¶
func NewBufferlessLinkHandler() *BufferlessLinkHandler
NewBufferlessLinkHandler creates a BufferlessLinkHandler. NewBufferlessLinkHandler creates a BufferlessLinkHandler.
func (*BufferlessLinkHandler) GetOccupancy ¶
func (h *BufferlessLinkHandler) GetOccupancy(currentCycle int) []int
GetOccupancy returns the pending packets distribution relative to current cycle (handled by Link).
func (*BufferlessLinkHandler) Init ¶
func (h *BufferlessLinkHandler) Init(l *Link)
ReadyDepth returns the number of cycles to pre-mark as ready for bootstrapping. Bufferless links are always ready, but need at least cycle 0 to start.
func (*BufferlessLinkHandler) Process ¶
func (h *BufferlessLinkHandler) Process(l *Link, cycle int, targetCycle int, incoming []packet.Packet) error
Process implements the LinkHandler interface for BufferlessLinkHandler.
func (*BufferlessLinkHandler) Reset ¶
func (h *BufferlessLinkHandler) Reset()
Reset resets the handler state.
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link represents a directed edge in the topology. Link receives packets from upstream and forwards them to downstream with latency and bandwidth constraints.
func NewLinkWithHandler ¶
func NewLinkWithHandler(sourceID, targetID, latency, bandwidth int, handler LinkHandler) *Link
NewLinkWithHandler creates a new Link with a custom handler.
func (*Link) AdvanceTo ¶
AdvanceTo progresses the link up to and including the target cycle. It executes cycles from l.currentCycle to targetCycle.
func (*Link) CurrentCycle ¶
CurrentCycle returns the current simulation cycle of the link.
func (*Link) GetHandler ¶
func (l *Link) GetHandler() LinkHandler
GetHandler returns the handler for this link.
func (*Link) GetVisualState ¶
GetVisualState returns the visual representation of this link.
func (*Link) Init ¶
func (l *Link) Init()
Init initializes the link after being connected to the network.
func (*Link) PendingPacketCount ¶
PendingPacketCount returns the number of buffered packets. Note: This relies on SnapshotOccupancy now.
func (*Link) SetDownstreamPort ¶
func (l *Link) SetDownstreamPort(port ahead_port.InPort)
SetDownstreamPort sets the port for sending data to downstream.
func (*Link) SetTickHook ¶
SetTickHook registers a callback invoked after each successful Tick.
func (*Link) SetUpstreamPort ¶
func (l *Link) SetUpstreamPort(port ahead_port.OutPort)
SetUpstreamPort sets the port for receiving data from upstream.
func (*Link) SnapshotOccupancy ¶
SnapshotOccupancy reports the pending packet count per slot/offset.
func (*Link) UpdateUpstreamReady ¶
UpdateUpstreamReady updates the ready state of the upstream port for a specific cycle. This is useful for custom LinkHandlers to signal backpressure.
type LinkHandler ¶
type LinkHandler interface {
// Process handles data for the current cycle.
// It is responsible for:
// 1. Sending packets to downstream (via l.toDownstream)
// 2. Buffering packets that cannot be sent (via l.pendingPackets or internal state)
// 3. Updating the ready state for upstream (via l.fromUpstream.UpdateReady)
//
// Parameters:
// l: reference to the parent Link
// cycle: current simulation cycle
// targetCycle: the upper bound cycle for this run (inclusive).
// incoming: packets received from upstream in this cycle
Process(l *Link, cycle int, targetCycle int, incoming []packet.Packet) error
// Reset resets the handler state.
Reset()
// Init initializes the handler after being connected to the network.
// It handles bootstrapping tasks like initial ready signaling.
// If initialReady is specified on the link, it should be honored.
Init(l *Link)
// GetOccupancy returns the number of pending packets per future cycle offset.
// Index i corresponds to packets scheduled for (CurrentCycle + i).
GetOccupancy(currentCycle int) []int
}
LinkHandler defines the behavior for specific link types. It handles packet processing, flow control, and readiness signaling. This mirrors the NodeHandler pattern used in nodes.
func CreateLinkHandler ¶
func CreateLinkHandler(handlerType string, latency, bandwidth int) LinkHandler
CreateLinkHandler is a factory function that creates link handlers by type.
Supported handler types: - "buffered": BufferedLinkHandler with ring buffer and backpressure - "bufferless": BufferlessLinkHandler (always-ready, no physical buffering)
Parameters: - handlerType: type of link handler ("buffered", "bufferless") - latency: latency parameter (used by buffered, ignored by bufferless) - bandwidth: bandwidth parameter (used by buffered, ignored by bufferless)
Returns: - LinkHandler instance, or panic if handlerType is unknown