connectivity

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package connectivity is the connectivity behavior: whether the host reaches an address, by ICMP ping.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"connectivity", "Whether the host reaches an address, by ICMP ping",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Networking),
	behavior.CLI,
	behavior.Platform(behavior.PlatformLinux, newLinux),
	behavior.Platform(behavior.PlatformDarwin, newDarwin),
	behavior.Runs("ping"),
	behavior.RunsOnPlatform(behavior.PlatformDarwin, "ping6"),
	behavior.Action("ping", Ping).
		ReadsNothing("a ping changes nothing on the host: its result is what the call answers").
		Describe("Ping an address from the host").
		Explain("Sends three ICMP echo requests from the host and reports how many came "+
			"back, and their round-trip times. A host that does not answer is 100% loss, "+
			"not an error. It changes nothing, so it reports changed: false. On Linux "+
			"the agent pings without root when net.ipv4.ping_group_range admits its group.").
		Example("A host that answers", PingInput{Address: "127.0.0.1"},
			PingResult{
				PacketsSent: 3, PacketsReceived: 3,
				MinRTT: "0.04ms", AvgRTT: "0.05ms", MaxRTT: "0.06ms",
			},
			behavior.OnPlatform(behavior.PlatformLinux),
			behavior.Prints(linuxPing, linuxOutput),
		).
		Example("A host that answers, on macOS", PingInput{Address: "127.0.0.1"},
			PingResult{
				PacketsSent: 3, PacketsReceived: 3,
				MinRTT: "0.08ms", AvgRTT: "0.14ms", MaxRTT: "0.17ms",
			},
			behavior.OnPlatform(behavior.PlatformDarwin),
			behavior.Prints(darwinPing, darwinOutput),
		).
		Example("A host that does not answer", PingInput{Address: "192.0.2.1"},
			PingResult{PacketsSent: 3, PacketLoss: 100},
			behavior.OnPlatform(behavior.PlatformLinux),
			behavior.Prints(linuxLost, linuxLostOutput),
		).
		Fails("A name, not an address", PingInput{Address: "example.com"}, "ip_or_fact"),
))

Behavior is the connectivity definition. The routes, the agent's dispatch, the CLI commands, the spec, the docs pages and the tests of every layer above the provider are built from it. osapi dsl behavior spec get lists every option.

Functions

This section is empty.

Types

type PingInput

type PingInput struct {
	Address string `` /* 149-byte string literal not displayed */
}

PingInput is ping's input: the address to ping from the host.

type PingResult

type PingResult struct {
	PacketsSent     int     `json:"packets_sent"      doc:"Number of packets sent"`
	PacketsReceived int     `json:"packets_received"  doc:"Number of packets received"`
	PacketLoss      float64 `json:"packet_loss"       doc:"Percentage of packet loss"`
	MinRTT          string  `json:"min_rtt,omitempty" doc:"Minimum round-trip time in milliseconds, with two decimals. Absent when no reply came back."`
	AvgRTT          string  `json:"avg_rtt,omitempty" doc:"Average round-trip time in milliseconds, with two decimals. Absent when no reply came back."`
	MaxRTT          string  `json:"max_rtt,omitempty" doc:"Maximum round-trip time in milliseconds, with two decimals. Absent when no reply came back."`
	Changed         bool    `json:"changed"           doc:"Always false: a ping changes nothing on the host"`
}

PingResult is ping's output: what came back of the three packets.

func Ping

func Ping(
	ctx context.Context,
	p Provider,
	in PingInput,
) (PingResult, error)

Ping pings the address from the host.

type Provider

type Provider interface {
	// Ping sends three packets to address and reports what came back. A
	// host that does not answer is a result with 100% loss, not an error.
	Ping(ctx context.Context, address string) (PingResult, error)
}

Provider is what each platform implements. linux.go and darwin.go each run the platform's ping, and mocks/ generates the double for the methods' tests.

Directories

Path Synopsis
Package mocks holds the generated double of the connectivity provider, for the methods' tests.
Package mocks holds the generated double of the connectivity provider, for the methods' tests.

Jump to

Keyboard shortcuts

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