Documentation
¶
Overview ¶
Package emu emulates UniFi devices (UAP/USW/UGW) against a real UniFi controller using the inform protocol.
Index ¶
Constants ¶
const DefaultKey = inform.DefaultKey
DefaultKey is the inform authkey of unadopted devices.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeviceSpec ¶
type DeviceSpec struct {
MAC string `json:"mac" yaml:"mac"`
Type string `json:"type" yaml:"type"`
Model string `json:"model" yaml:"model"`
ModelDisplay string `json:"modeldisplay" yaml:"modeldisplay"`
Version string `json:"version" yaml:"version"`
Name string `json:"name" yaml:"name"`
IP string `json:"ip" yaml:"ip"`
Ports int `json:"ports" yaml:"ports"` // overrides the profile port layout when > 0
// SSIDs opts the AP into emitting vaps. Empty by default: this
// controller build rejects default vaps with log noise until a
// setstate provisions real WLAN config (the setstate echo path
// overlays vap_table), so devices inform with an empty vap_table.
SSIDs []string `json:"ssids" yaml:"ssids"`
}
DeviceSpec describes one emulated device. Type, ModelDisplay and Version default from the model profile when empty; Name defaults to "UBNT". An explicit Type must equal the profile's: the profile drives the payload shape, so a mismatched Type would describe an incoherent device and is an error, not an override.
The json/yaml tags are the fleet-file contract (unifi-emu -devices, SIM_DEVICES); keep the two families identical so either format names the same keys.
func (*DeviceSpec) UnmarshalYAML ¶ added in v0.2.0
func (d *DeviceSpec) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML lets a fleet-list entry be a bare model string ("U7PRO") or a full mapping. A scalar becomes {Model: scalar}; a mapping decodes the known keys and rejects any other. JSON files parse through the same YAML decoder, so both formats get this behavior.
type DeviceState ¶
type DeviceState int
DeviceState is the adoption state of an emulated device.
const ( StatePending DeviceState = iota StateAdopting StateConnected )
func (DeviceState) String ¶
func (s DeviceState) String() string
type Emu ¶
type Emu struct {
// contains filtered or unexported fields
}
Emu is a fleet of emulated UniFi devices informing one controller.
func (*Emu) Add ¶
func (e *Emu) Add(specs ...DeviceSpec) error
Add validates specs and adds them to the fleet. MACs are normalized before keying, so the same device added twice errors however it was spelled. The first invalid spec aborts the call; earlier specs stay added. Add errors once Start has been called: a running fleet is fixed, and devices added after Start would never be launched.
func (*Emu) Start ¶
Start launches one inform goroutine per device, all tied to ctx. Start is one-shot: a second Start errors "emu: already started" even after Stop — that is intended, build a fresh fleet with New to restart. Starting an empty fleet errors rather than welding it shut: once started, Add rejects new devices.
func (*Emu) State ¶
func (e *Emu) State(mac string) (DeviceState, bool)
State reports the adoption state of one device, ok=false when mac is unknown to the fleet or unparseable.
type ModelProfile ¶
type ModelProfile struct {
Model string `json:"model"`
ModelDisplay string `json:"model_display"`
Type string `json:"type"` // "ugw", "usw", "uap"
Version string `json:"version"`
Ports []PortSpec `json:"ports"` // usw + ugw + uap (eth port)
Radios []RadioSpec `json:"radios"` // uap only
}
ModelProfile is the per-model shape the controller expects to see: identity strings plus the port/radio/SSID layout tables are built from.
func Profile ¶ added in v0.2.0
func Profile(model string) (ModelProfile, bool)
Profile returns the model profile for a known model. The bool is false for a model the generated registry does not contain. Read-only: callers must not mutate the returned slices.
type Option ¶
type Option func(*Emu)
Option customizes an Emu fleet.
func WithInformInterval ¶
WithInformInterval sets the inform interval every added device starts with. Controller responses can still retune it per device later.
type PortSpec ¶
type PortSpec struct {
IfName string `json:"ifname"`
Name string `json:"name"`
PortIdx int `json:"port_idx"`
Media string `json:"media"` // "GE", "SFP+"
PoECaps int `json:"poe_caps"`
IsUplink bool `json:"is_uplink"`
}
PortSpec is one switch/gateway/ethernet port in a model's layout.
type RadioSpec ¶
type RadioSpec struct {
Name string `json:"name"` // "wifi-ng", "wifi-na"
Radio string `json:"radio"` // "ng", "na"
Channel int `json:"-"` // derived at load time; not in model_profiles.json
HT string `json:"ht"` // "20", "40"
MinTxPower int `json:"min_txpower"`
MaxTxPower int `json:"max_txpower"`
NSS int `json:"nss"`
RadioCaps int `json:"radio_caps"`
AntennaGain int `json:"antenna_gain"`
}
RadioSpec is one wireless radio in an AP model's layout.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
modelgen
command
Command modelgen reduces an adopted UniFi simulation fleet (or a harvested controller hardware database bundle) to model_profiles.json, the model catalog the emulator embeds at build time.
|
Command modelgen reduces an adopted UniFi simulation fleet (or a harvested controller hardware database bundle) to model_profiles.json, the model catalog the emulator embeds at build time. |
|
unifi-emu
command
Command unifi-emu runs a fleet of emulated UniFi devices informing a real controller until interrupted.
|
Command unifi-emu runs a fleet of emulated UniFi devices informing a real controller until interrupted. |
|
Package inform implements the UniFi inform wire protocol: the TNBU binary packet, AES-128-CBC/GCM encryption, and zlib/snappy compression.
|
Package inform implements the UniFi inform wire protocol: the TNBU binary packet, AES-128-CBC/GCM encryption, and zlib/snappy compression. |