app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("not found")
)

Functions

func CleanMesh

func CleanMesh(networkID int, verbose bool) error

CleanMesh stops all runned containers of the given networkID and removes the associated Docker network.

Types

type App

type App struct {

	// Logger is the event logger.
	Logger *elog.Logger
	// Mesh is the state of the network.
	Mesh *Mesh
	// contains filtered or unexported fields
}

App manages the lifecycle of the application.

func NewApp

func NewApp(networkID int, defaults Defaults, opts *Options) (*App, error)

func (*App) Close

func (a *App) Close() error

func (*App) Start

func (a *App) Start(ctx context.Context) error

type Cmd

type Cmd struct {
	*exec.Cmd

	Out *bytes.Buffer
	Err *bytes.Buffer
	// contains filtered or unexported fields
}

Cmd is a basic struct that combine an exec.Cmd together with its stdout and stderr buffers.

func NewCmd

func NewCmd(verbose bool, bin string, args ...any) *Cmd

NewCmd creates a system command and set it to copy its output to stderr in case verbose is true.

func (*Cmd) Run

func (c *Cmd) Run() error

func (*Cmd) Wait

func (c *Cmd) Wait() error

type CostFunction

type CostFunction string
const (
	CostMinLatency   CostFunction = "cost_min_latency"
	CostMaxBandwidth CostFunction = "cost_max_bandwidth"
)

func (*CostFunction) UnmarshalText

func (f *CostFunction) UnmarshalText(val []byte) error

type Defaults

type Defaults struct {
	Bandwidth      float64      `json:"bandwidth,string"`
	DecayBandwidth bool         `json:"decay_bandwidth"`
	LatencyScale   float64      `json:"latency_scale,string"`
	MaxLatency     float64      `json:"max_latency,string"`
	MinBandwidth   float64      `json:"min_bandwidth,string"`
	Jitter         float64      `json:"jitter,string"`
	PacketLoss     float64      `json:"packet_loss,string"`
	CostFunction   CostFunction `json:"cost_function"` // Deprecated: this is currently unused
}

type Environer

type Environer interface {
	// Environ returns a list of environment variables like [os.Environ].
	Environ() []string
}

type Graph

type Graph interface {
	graph.WeightedUndirected
	WeightedEdges() graph.WeightedEdges
}

Graph is a minimal interface of a graph that can be used to override the state of the mesh using Mesh.SetState.

type Health

type Health struct {
	Peer Peer `json:"peer"`
	HealthData
}

func (*Health) String

func (h *Health) String() string

type HealthData

type HealthData struct {
	Bandwidth  int `json:"bandwidth"`   // in bits per second
	Latency    int `json:"latency"`     // in milliseconds
	Jitter     int `json:"jitter"`      // in milliseconds
	PacketLoss int `json:"packet_loss"` // in percentage
}

type LinkData

type LinkData struct {
	LinkID
	HealthData
	Overrides Overrides `json:"overrides,omitempty"`
}

LinkData is the structure used to (de)serialize the data of a link in JSON.

type LinkID

type LinkID struct {
	Source int64 `json:"source"`
	Target int64 `json:"target"`
}

type Listeners

type Listeners struct {
	// Updated is called after the mesh was modified with [Mesh.SetState]
	Updated func()
}

Listeners is a collection of functions that can be overriden and will be called upon certain events.

type Mesh

type Mesh struct {
	Autowired bool   // If the mesh should create links automatically
	Verbose   bool   // Set to true to output debug messages
	StartCmd  string // Command used by meshem to start a container

	Overrides map[LinkID]Overrides
	Listeners Listeners
	// contains filtered or unexported fields
}

Mesh contains the state of an emulated network and has methods to mutate it.

func NewMesh

func NewMesh(networkID int, defaults Defaults, verbose bool) (*Mesh, error)

NewMesh initializes a new Mesh structure.

func (*Mesh) AddServer

func (m *Mesh) AddServer(pos Position) error

func (*Mesh) Close

func (m *Mesh) Close() error

Close calls CleanMesh for this mesh's network.

func (*Mesh) Defaults

func (m *Mesh) Defaults() Defaults

func (*Mesh) DelLinkHealth

func (m *Mesh) DelLinkHealth(s1, s2 int, field string)

func (*Mesh) EncodeGraphML

func (m *Mesh) EncodeGraphML(w io.Writer) error

EncodeGraphML exports the data of the mesh into w in GraphML format. For now, it only contains the global topology, the link data is not included.

func (*Mesh) Host

func (m *Mesh) Host() string

func (*Mesh) Init

func (m *Mesh) Init(ctx context.Context, g Graph) error

func (*Mesh) MarshalJSON

func (m *Mesh) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface to create a custom JSON representation.

func (*Mesh) MoveServer

func (m *Mesh) MoveServer(id int, pos Position) error

func (*Mesh) NetworkID

func (m *Mesh) NetworkID() int

func (*Mesh) Path

func (m *Mesh) Path(fromID, toID int64) ([]int64, error)

func (*Mesh) PutLinkHealth

func (m *Mesh) PutLinkHealth(s1, s2 int, field string, value int)

func (*Mesh) SetDefaults

func (m *Mesh) SetDefaults(defaults *Defaults)

func (*Mesh) SetListeners added in v0.1.4

func (m *Mesh) SetListeners(l Listeners)

func (*Mesh) SetState

func (m *Mesh) SetState(g Graph)

type NodeData

type NodeData struct {
	ID int64 `json:"name"`
	Position
}

NodeData is the structure used to (de)serialize the data of a node in JSON.

type Options

type Options struct {
	Debug       bool
	DumpMetrics string
	DumpPackets string
	IDAttribute string
	Period      time.Duration
	Run         string
	Setup       string
	Start       string
	Teardown    string
	GraphmlDir  string
	LogEvents   string
}

type Overrides

type Overrides map[string]int

type Peer

type Peer struct {
	ID  int    `json:"id"`
	IP  string `json:"ip"`
	MAC string `json:"mac"`
}

func (*Peer) String

func (p *Peer) String() string

type Position

type Position struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

type Route

type Route struct {
	Dst  *Peer   `json:"dst"`
	Via  *Peer   `json:"via"`
	Cost float64 `json:"cost"`
}

func (*Route) String

func (r *Route) String() string

type Server

type Server struct {
	Position
	IP  string
	MAC string
	Up  atomic.Bool
	Cmd *Cmd
	// contains filtered or unexported fields
}

Server is a node in an emulated network, it is a proxy that controls the container through its topologiser.

func (*Server) ID

func (s *Server) ID() int64

ID implements [graph.Node] interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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