Files
go-ethereum/simulation/types.go
Rafael Matias 388d8ccd9f PoC: Network simulation framework (#1555)
* simv2: wip

* simulation: exec adapter start/stop

* simulation: add node status to exec adapter

* simulation: initial simulation code

* simulation: exec adapter, configure path to executable

* simulation: initial docker adapter

* simulation: wip kubernetes adapter

* simulation: kubernetes adapter proxy

* simulation: implement GetAll/StartAll/StopAll

* simulation: kuberentes adapter - set env vars and resource limits

* simulation: discovery test

* simulation: remove port definitions within docker adapter

* simulation: simplify wait for healthy loop

* simulation: get nat ip addr from interface

* simulation: pull docker images automatically

* simulation: NodeStatus -> NodeInfo

* simulation: move discovery test to example dir

* simulation: example snapshot usage

* simulation: add goclient specific simulation

* simulation: add peer connections to snapshot

* simulation: close rpc client

* simulation: don't export kubernetes proxy server

* simulation: merge simulation code

* simulation: don't export nodemap

* simulation: rename SimulationSnapshot -> Snapshot

* simulation: linting fixes

* simulation: add k8s available helper func

* simulation: vendor

* simulation: fix 'no non-test Go files' when building

* simulation: remove errors from interface methods where non were returned

* simulation: run getHealthInfo check in parallel
2019-07-24 17:00:13 +02:00

82 lines
2.5 KiB
Go

package simulation
import (
"io"
)
// Node is a node within a simulation
type Node interface {
Info() NodeInfo
// Start starts the node
Start() error
// Stop stops the node
Stop() error
// Snapshot returns a snapshot of the node
Snapshot() (NodeSnapshot, error)
}
// Adapter can handle Node creation
type Adapter interface {
// NewNode creates a new node based on the NodeConfig
NewNode(config NodeConfig) Node
// Snapshot returns a snapshot of the adapter
Snapshot() AdapterSnapshot
}
// NodeID is the node identifier within a simulation. This can be an arbitrary string.
type NodeID string
// NodeConfig is the configuration of a specific node
type NodeConfig struct {
// Arbitrary string used to identify a node
ID NodeID `json:"id"`
// Command line arguments
Args []string `json:"args"`
// Environment variables
Env []string `json:"env,omitempty"`
// Stdout and Stderr specify the nodes' standard output and error
Stdout io.Writer `json:"-"`
Stderr io.Writer `json:"-"`
}
// NodeInfo contains the nodes information and connections strings
type NodeInfo struct {
ID NodeID
Enode string
BzzAddr string
RPCListen string // RPC listener address. Should be a valid ipc or websocket path
HTTPListen string // HTTP listener address: e.g. http://localhost:8500
PprofListen string // PProf listener address: e.g http://localhost:6060
}
// Snapshot is a snapshot of a simulation. It contains snapshots of:
// - the default adapter that the simulation was initialized with
// - the list of nodes that were created within the simulation
// - the list of connections between nodes
type Snapshot struct {
DefaultAdapter *AdapterSnapshot `json:"defaultAdapter"`
Nodes []NodeSnapshot `json:"nodes"`
Connections []ConnectionSnapshot `json:"connections"`
}
// NodeSnapshot is a snapshot of the node, it contains the node configuration and an adapter snapshot
type NodeSnapshot struct {
Config NodeConfig `json:"config"`
Adapter *AdapterSnapshot `json:"adapter,omitempty"`
}
// ConnectionSnapshot is a snapshot of a connection between peers
type ConnectionSnapshot struct {
From string `json:"from"`
To string `json:"to"`
}
// AdapterSnapshot is a snapshot of the configuration of an adapter
// - The type can be an arbitrary strings, e.g. "exec", "docker", etc.
// - The config will depend on the type, as every adapter has different configuration options
type AdapterSnapshot struct {
Type string `json:"type"`
Config interface{} `json:"config"`
}