link

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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 (*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 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 NewLink(sourceID, targetID, latency, bandwidth int) *Link

NewLink creates a Link with BufferedLinkHandler by default.

func NewLinkWithHandler

func NewLinkWithHandler(sourceID, targetID, latency, bandwidth int, handler LinkHandler) *Link

NewLinkWithHandler creates a new Link with a custom handler.

func (*Link) AdvanceTo

func (l *Link) AdvanceTo(targetCycle int) error

AdvanceTo progresses the link up to and including the target cycle. It executes cycles from l.currentCycle to targetCycle.

func (*Link) Bandwidth

func (l *Link) Bandwidth() int

Bandwidth returns the maximum packets per cycle.

func (*Link) CurrentCycle

func (l *Link) CurrentCycle() int

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

func (l *Link) GetVisualState() string

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) Latency

func (l *Link) Latency() int

Latency returns the configured delay in cycles.

func (*Link) PendingPacketCount

func (l *Link) PendingPacketCount() int

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

func (l *Link) SetTickHook(hook func(cycle int))

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

func (l *Link) SnapshotOccupancy() []int

SnapshotOccupancy reports the pending packet count per slot/offset.

func (*Link) SourceID

func (l *Link) SourceID() int

SourceID returns the ID of the upstream node.

func (*Link) TargetID

func (l *Link) TargetID() int

TargetID returns the ID of the downstream node.

func (*Link) Tick

func (l *Link) Tick(cycle int, targetCycle int) error

Tick processes a single cycle. Template: Receive -> handler.Process -> MarkDone

func (*Link) UpdateUpstreamReady

func (l *Link) UpdateUpstreamReady(cycle int, ready bool)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL