Documentation
¶
Overview ¶
Package network provides user-space port forwarding and network utilities.
Index ¶
- func CheckPortAvailable(port int) error
- func CheckPortsAvailable(ports []int) error
- type Conditioner
- func (c *Conditioner) AllRules() []LinkRule
- func (c *Conditioner) Degrade(a, b string, latency, jitter time.Duration, loss float64) error
- func (c *Conditioner) Delay(a, b string) time.Duration
- func (c *Conditioner) GetRule(a, b string) *LinkRule
- func (c *Conditioner) Heal(a, b string)
- func (c *Conditioner) Partition(a, b string)
- func (c *Conditioner) RemoveRule(a, b string)
- func (c *Conditioner) Reset()
- func (c *Conditioner) SetRule(rule LinkRule)
- func (c *Conditioner) ShouldDrop(a, b string) bool
- type Forwarder
- type L2Switch
- type LinkRule
- type PortForwardRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckPortAvailable ¶
CheckPortAvailable attempts to listen on the given TCP port to verify it is not already in use. Returns an error if the port is occupied.
func CheckPortsAvailable ¶
CheckPortsAvailable verifies a list of ports are all free.
Types ¶
type Conditioner ¶
type Conditioner struct {
// contains filtered or unexported fields
}
Conditioner manages network chaos rules between nodes.
func NewConditioner ¶
func NewConditioner() *Conditioner
NewConditioner creates a new network conditioner.
func (*Conditioner) AllRules ¶
func (c *Conditioner) AllRules() []LinkRule
AllRules returns a snapshot of all active rules.
func (*Conditioner) Delay ¶
func (c *Conditioner) Delay(a, b string) time.Duration
Delay returns how long a packet should be delayed on this link.
func (*Conditioner) GetRule ¶
func (c *Conditioner) GetRule(a, b string) *LinkRule
GetRule returns the rule for a node pair, or nil if none.
func (*Conditioner) Heal ¶
func (c *Conditioner) Heal(a, b string)
Heal removes a partition (and all conditions) between two nodes.
func (*Conditioner) Partition ¶
func (c *Conditioner) Partition(a, b string)
Partition creates a hard partition between two nodes.
func (*Conditioner) RemoveRule ¶
func (c *Conditioner) RemoveRule(a, b string)
RemoveRule removes any rule between two nodes.
func (*Conditioner) SetRule ¶
func (c *Conditioner) SetRule(rule LinkRule)
SetRule applies a network condition rule between two nodes.
func (*Conditioner) ShouldDrop ¶
func (c *Conditioner) ShouldDrop(a, b string) bool
ShouldDrop returns true if a packet on this link should be dropped.
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
Forwarder manages a set of user-space port forwards.
func NewForwarder ¶
func NewForwarder(rules []PortForwardRule) *Forwarder
NewForwarder creates a Forwarder for the given rules.
type L2Switch ¶
type L2Switch struct {
// contains filtered or unexported fields
}
L2Switch is a userspace virtual Ethernet switch. Each VM connects via a socketpair; the host connects via a TAP device.
func NewL2Switch ¶
func NewL2Switch(cond *Conditioner, tapName, cidr, gateway string) (*L2Switch, error)
NewL2Switch creates a new L2Switch backed by a TAP device named tapName with the given gateway address (e.g. "10.0.0.1") in cidr (e.g. "10.0.0.0/24"). Returns an error if the TAP device cannot be opened (e.g. missing CAP_NET_ADMIN).
func NewL2SwitchForCluster ¶
func NewL2SwitchForCluster(cond *Conditioner, tapName, cidr, gateway string) (*L2Switch, error)
NewL2SwitchForCluster creates an L2Switch for multi-node clusters. On Linux this is identical to NewL2Switch (TAP-backed).
func (*L2Switch) Close ¶
Close shuts down the switch (cancels reader goroutines, closes TAP, removes NAT rules).
func (*L2Switch) NewPort ¶
NewPort allocates a socketpair for a new VM. The QEMU-side *os.File is returned; the caller must add it to cmd.ExtraFiles and then close it in the parent after cmd.Start().
func (*L2Switch) RemovePort ¶
RemovePort closes the daemon side of a port and removes it from the switch.
type LinkRule ¶
type LinkRule struct {
NodeA string `json:"node_a"`
NodeB string `json:"node_b"`
Latency time.Duration `json:"latency"` // One-way added latency.
Jitter time.Duration `json:"jitter"` // Random +/- range around latency.
Loss float64 `json:"loss"` // Packet loss probability (0.0–1.0).
Down bool `json:"down"` // Hard partition — all packets dropped.
}
LinkRule describes network conditions between two nodes.