Documentation
¶
Index ¶
- Constants
- Variables
- func DeriveGateway(cidr string) (string, error)
- func GenerateTAPName(instanceID string) string
- func GuestToGuestEnabled(n *Network) bool
- func NewUniqueMAC(used []string) (string, error)
- type AllocateRequest
- type Allocation
- type Manager
- type Metrics
- type Model
- type Network
- type NetworkConfig
Constants ¶
const DefaultDownloadBurstMultiplier = 4
DefaultDownloadBurstMultiplier is the default multiplier for the TBF burst bucket size. A larger bucket allows faster initial burst before settling to sustained rate. Configurable via DOWNLOAD_BURST_MULTIPLIER environment variable.
const DefaultUploadBurstMultiplier = 4
DefaultUploadBurstMultiplier is the default multiplier applied to guaranteed upload rate to calculate the burst ceiling. This allows VMs to burst above their guaranteed rate when other VMs are not using their full bandwidth allocation. Configurable via UPLOAD_BURST_MULTIPLIER environment variable.
const TAPPrefix = "hype-"
TAPPrefix is the prefix used for hypeman TAP devices
Variables ¶
var ( // ErrNotFound is returned when the default network is not found ErrNotFound = errors.New("network not found") // ErrNameExists is returned when an instance name already exists ErrNameExists = errors.New("instance name already exists") )
Functions ¶
func DeriveGateway ¶
DeriveGateway returns the first usable IP in a subnet (used as gateway). e.g., 10.100.0.0/16 -> 10.100.0.1
func GenerateTAPName ¶ added in v0.0.6
GenerateTAPName generates TAP device name from instance ID. Exported for use by other packages (e.g., vm_metrics).
func GuestToGuestEnabled ¶ added in v0.4.0
GuestToGuestEnabled reports whether direct VM-to-VM traffic is permitted on the given network. Hypeman provisions its default networks with per-TAP port isolation (Isolated=true), which blocks direct guest-to-guest traffic. The flag is read from the network rather than assumed so a non-isolated network is reported truthfully.
func NewUniqueMAC ¶ added in v0.4.0
NewUniqueMAC returns a locally administered MAC that is not in used. Callers that assign MACs outside the network allocator (macOS vmnet) use it so both paths share one uniqueness rule.
Types ¶
type AllocateRequest ¶
type AllocateRequest struct {
InstanceID string
InstanceName string
DownloadBps int64 // Download rate limit in bytes/sec (external→VM, TAP egress TBF)
UploadBps int64 // Upload rate limit in bytes/sec (VM→external, HTB class rate)
UploadCeilBps int64 // Upload ceiling in bytes/sec (HTB burst when bandwidth available, 0 = same as UploadBps)
}
AllocateRequest is the request to allocate network for an instance Always allocates from the default network
type Allocation ¶
type Allocation struct {
InstanceID string
InstanceName string
Network string
IP string
MAC string
TAPDevice string
Gateway string // Gateway IP for this network
Netmask string // Netmask in dotted decimal notation
DNS string // DNS server for guest configuration
State string // "running", "standby" (derived from CH or snapshot)
ClassID string // HTB class ID actually assigned (may differ from deriveClassID if collision occurred)
}
Allocation represents a network allocation for an instance
type Manager ¶
type Manager interface {
// Lifecycle
Initialize(ctx context.Context, runningInstanceIDs []string) error
// Instance allocation operations (called by instance manager)
CreateAllocation(ctx context.Context, req AllocateRequest) (*NetworkConfig, error)
RecreateAllocation(ctx context.Context, instanceID string, downloadBps, uploadBps int64) error
ReleaseAllocation(ctx context.Context, alloc *Allocation) error
// ReleaseByInstanceID is a best-effort cleanup fallback when the full Allocation
// can't be derived (e.g. metadata read failed). Deletes the TAP device using the
// deterministic name from the instance ID.
ReleaseByInstanceID(ctx context.Context, instanceID string) error
// SetupHTB initializes HTB qdisc on the bridge for upload fair sharing.
// Should be called during network initialization with the total network capacity.
SetupHTB(ctx context.Context, capacityBps int64) error
// Queries (derive from CH/snapshots)
GetAllocation(ctx context.Context, instanceID string) (*Allocation, error)
ListAllocations(ctx context.Context) ([]Allocation, error)
NameExists(ctx context.Context, name string, excludeInstanceID string) (bool, error)
// EffectiveDefaultNetwork returns the platform backend's default network.
// Before Initialize it returns the network the backend will create or attach;
// after Initialize it returns the backend state cached by the manager.
EffectiveDefaultNetwork() (*Network, error)
// CleanupOrphanedTAPs removes TAP devices not associated with any preserved
// instance. Pass minAge>0 to skip TAPs younger than that, which avoids racing
// against in-flight CreateAllocation calls whose metadata hasn't been persisted.
CleanupOrphanedTAPs(ctx context.Context, preserveInstanceIDs []string, minAge time.Duration) int
// CleanupOrphanedClasses removes bridge tc filters/classes not referenced by
// a live TAP's filter.
CleanupOrphanedClasses(ctx context.Context) int
// GetUploadBurstMultiplier returns the configured multiplier for upload burst ceiling.
GetUploadBurstMultiplier() int
// GetDownloadBurstMultiplier returns the configured multiplier for download burst bucket.
GetDownloadBurstMultiplier() int
}
Manager defines the interface for network management
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds the metrics instruments for network operations.
type Model ¶ added in v0.4.0
type Model string
Model identifies the guest networking model a host provides. Each platform backend returns its model from NetworkModel; API layers map it onto their own wire enums so this package stays free of API dependencies.
func NetworkModel ¶ added in v0.4.0
func NetworkModel() Model
NetworkModel identifies the guest networking model in use on this host. Linux hosts use a bridge with per-VM TAP devices.
type Network ¶
type Network struct {
Name string // "default", "internal"
Subnet string // "192.168.0.0/16"
Gateway string // "192.168.0.1"
Bridge string // "vmbr0" (derived from kernel)
Isolated bool // Bridge_slave isolation mode
Default bool // True for default network
CreatedAt time.Time
}
Network represents a virtual network for instances
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testsupport holds test-only helpers shared by the packages that bring up real hypeman networks in tests.
|
Package testsupport holds test-only helpers shared by the packages that bring up real hypeman networks in tests. |