Documentation
¶
Index ¶
- Constants
- Variables
- func IntToPublicIPv4(n int) net.IP
- func StaticLatency(duration time.Duration) func(*Packet) time.Duration
- type ConnStats
- type DropReason
- type LinkSettings
- type NodeBiDiLinkSettings
- type OnDrop
- type Packet
- type PacketReceiver
- type PerfectRouter
- type RateLink
- type Router
- type SimConn
- func (c *SimConn) Close() error
- func (c *SimConn) LocalAddr() net.Addr
- func (c *SimConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *SimConn) RecvPacket(p Packet)
- func (c *SimConn) SetDeadline(t time.Time) error
- func (c *SimConn) SetLocalAddr(addr net.Addr)
- func (c *SimConn) SetReadBuffer(n int) error
- func (c *SimConn) SetReadDeadline(t time.Time) error
- func (c *SimConn) SetUpPacketReceiver(r PacketReceiver)
- func (c *SimConn) SetWriteBuffer(n int) error
- func (c *SimConn) SetWriteDeadline(t time.Time) error
- func (c *SimConn) Stats() ConnStats
- func (c *SimConn) UnicastAddr() net.Addr
- func (c *SimConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type Simlink
- type Simnet
- type SimpleFirewallRouter
- func (r *SimpleFirewallRouter) AddNode(addr net.Addr, conn PacketReceiver)
- func (r *SimpleFirewallRouter) RecvPacket(p Packet)
- func (r *SimpleFirewallRouter) RemoveNode(addr net.Addr)
- func (r *SimpleFirewallRouter) SetAddrPubliclyReachable(addr net.Addr)
- func (r *SimpleFirewallRouter) String() string
- type VariableLatencyRouter
Constants ¶
const DefaultFlowBucketCount = 128
const Mibps = 1_000_000
Variables ¶
var ErrDeadlineExceeded = errors.New("deadline exceeded")
Functions ¶
func IntToPublicIPv4 ¶
Types ¶
type DropReason ¶ added in v0.0.4
type DropReason string
const ( DropReasonUnknownDestination DropReason = "unknown destination" DropReasonUnknownSource DropReason = "unknown source" DropReasonFirewalled DropReason = "Packet firewalled" )
type LinkSettings ¶
type LinkSettings struct {
// BitsPerSecond specifies the bandwidth limit in bits per second
BitsPerSecond int
// MTU (Maximum Transmission Unit) specifies the maximum packet size in bytes
MTU int
// FlowBucketCount sets the number of flow buckets for FQ-CoDel. If zero
// defaults to DefaultFlowBucketCount
FlowBucketCount int
}
LinkSettings defines the network characteristics for a simulated link direction
type NodeBiDiLinkSettings ¶
type NodeBiDiLinkSettings struct {
// Downlink configures the settings for incoming traffic to this node
Downlink LinkSettings
// Uplink configures the settings for outgoing traffic from this node
Uplink LinkSettings
}
NodeBiDiLinkSettings defines the bidirectional link settings for a network node. It specifies separate configurations for downlink (incoming) and uplink (outgoing) traffic, allowing asymmetric network conditions to be simulated.
type OnDrop ¶ added in v0.0.4
type OnDrop func(packet Packet, reason DropReason)
type PacketReceiver ¶
type PacketReceiver interface {
RecvPacket(p Packet)
}
type PerfectRouter ¶
type PerfectRouter struct {
OnDrop OnDrop
// contains filtered or unexported fields
}
PerfectRouter is a router that has no latency or jitter and can route to every node
func (*PerfectRouter) AddNode ¶
func (r *PerfectRouter) AddNode(addr net.Addr, conn PacketReceiver)
func (*PerfectRouter) RecvPacket ¶ added in v0.0.4
func (r *PerfectRouter) RecvPacket(p Packet)
func (*PerfectRouter) RemoveNode ¶
func (r *PerfectRouter) RemoveNode(addr net.Addr)
type RateLink ¶ added in v0.0.4
type RateLink struct {
*rate.Limiter
BitsPerSecond int
Receiver PacketReceiver
}
func NewRateLink ¶ added in v0.0.4
func NewRateLink(bandwidth int, burstSize int, receiver PacketReceiver) *RateLink
func (*RateLink) RecvPacket ¶ added in v0.0.4
type Router ¶
type Router interface {
PacketReceiver
AddNode(addr net.Addr, receiver PacketReceiver)
}
Router handles routing of packets between simulated connections. Implementations are responsible for delivering packets to their destinations.
type SimConn ¶
type SimConn struct {
// contains filtered or unexported fields
}
SimConn is a simulated network connection that implements net.PacketConn. It provides packet-based communication through a Router for testing and simulation purposes. All send/recv operations are handled through the Router's packet delivery mechanism.
func NewBlockingSimConn ¶
NewBlockingSimConn creates a new simulated connection that blocks if the receive buffer is full. Does not drop packets.
func NewSimConn ¶
NewSimConn creates a new simulated connection that drops packets if the receive buffer is full.
func (*SimConn) RecvPacket ¶
func (*SimConn) SetDeadline ¶
SetDeadline implements net.PacketConn
func (*SimConn) SetLocalAddr ¶
SetLocalAddr only changes what `.LocalAddr()` returns. Packets will still come From the initially configured addr.
func (*SimConn) SetReadBuffer ¶
SetReadBuffer only exists to quell the warning message from quic-go
func (*SimConn) SetReadDeadline ¶
SetReadDeadline implements net.PacketConn
func (*SimConn) SetUpPacketReceiver ¶ added in v0.0.4
func (c *SimConn) SetUpPacketReceiver(r PacketReceiver)
func (*SimConn) SetWriteBuffer ¶
SetReadBuffer only exists to quell the warning message from quic-go
func (*SimConn) SetWriteDeadline ¶
SetWriteDeadline implements net.PacketConn
func (*SimConn) UnicastAddr ¶
type Simlink ¶ added in v0.0.4
type Simlink struct {
// contains filtered or unexported fields
}
Simlink simulates a bidirectional network link with variable latency, bandwidth limiting, and CoDel-based bufferbloat mitigation
func NewSimlink ¶ added in v0.0.4
func NewSimlink(
closeSignal chan struct{},
linkSettings NodeBiDiLinkSettings,
upPacketReceiver PacketReceiver,
downPacketReceiver PacketReceiver,
) *Simlink
type Simnet ¶
type Simnet struct {
// LatencyFunc defines the latency added when routing a given packet.
// The latency is allowed to be dynamic and change packet to packet (which
// could lead to packet reordering).
//
// A simple use case can use `StaticLatency(duration)` to set a static
// latency for all packets.
//
// More complex use cases can define a latency map between endpoints and
// have this function return the expected latency.
LatencyFunc func(*Packet) time.Duration
// Optional, if unset will use the default slog logger.
Logger *slog.Logger
// contains filtered or unexported fields
}
Simnet is a simulated network that manages connections between nodes with configurable network conditions.
func (*Simnet) NewEndpoint ¶
func (n *Simnet) NewEndpoint(addr *net.UDPAddr, linkSettings NodeBiDiLinkSettings) *SimConn
type SimpleFirewallRouter ¶
type SimpleFirewallRouter struct {
OnDrop OnDrop
// contains filtered or unexported fields
}
func (*SimpleFirewallRouter) AddNode ¶
func (r *SimpleFirewallRouter) AddNode(addr net.Addr, conn PacketReceiver)
func (*SimpleFirewallRouter) RecvPacket ¶ added in v0.0.4
func (r *SimpleFirewallRouter) RecvPacket(p Packet)
func (*SimpleFirewallRouter) RemoveNode ¶
func (r *SimpleFirewallRouter) RemoveNode(addr net.Addr)
func (*SimpleFirewallRouter) SetAddrPubliclyReachable ¶
func (r *SimpleFirewallRouter) SetAddrPubliclyReachable(addr net.Addr)
func (*SimpleFirewallRouter) String ¶
func (r *SimpleFirewallRouter) String() string
type VariableLatencyRouter ¶ added in v0.0.4
type VariableLatencyRouter struct {
PerfectRouter
LatencyFunc func(packet *Packet) time.Duration
CloseSignal chan struct{}
// contains filtered or unexported fields
}
func (*VariableLatencyRouter) RecvPacket ¶ added in v0.0.4
func (r *VariableLatencyRouter) RecvPacket(p Packet)
func (*VariableLatencyRouter) Start ¶ added in v0.0.4
func (r *VariableLatencyRouter) Start(wg *sync.WaitGroup)