types

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ParameterRuleModeDistribute distributes one parameter per object (default, legacy behavior)
	ParameterRuleModeDistribute = "distribute"
	// ParameterRuleModeAttach attaches multiple Values to one object
	ParameterRuleModeAttach = "attach"
)

ParameterRuleMode constants

View Source
const ChildConnectionsConfigHeader string = "connections" + NumberSeparator
View Source
const ChildGroupsConfigHeader string = "groups" + NumberSeparator
View Source
const ChildInterfacesConfigHeader string = "interfaces" + NumberSeparator
View Source
const ChildMembersConfigHeader string = "members" + NumberSeparator
View Source
const ChildNeighborsConfigHeader string = "neighbors" + NumberSeparator
View Source
const ChildNodesConfigHeader string = "nodes" + NumberSeparator
View Source
const ChildSegmentsConfigHeader string = "segments" + NumberSeparator
View Source
const ClassAll string = "all" // all objects
View Source
const ClassDefault string = "default" // all empty objects
View Source
const ClassTypeConnection string = "connection"
View Source
const ClassTypeGroup string = "group"
View Source
const ClassTypeInterface string = "interface"
View Source
const ClassTypeMemberClassNameAny = "any"
View Source
const ClassTypeMemberHeader string = "member"
View Source
const ClassTypeNeighborHeader string = "neighbor"
View Source
const ClassTypeNeighborLayerAny = "any"
View Source
const ClassTypeNetwork string = "network"
View Source
const ClassTypeNode string = "node"
View Source
const ClassTypeSegment string = "segment"
View Source
const ClassTypeValueHeader string = "value"
View Source
const ConfigTemplateStyleHierarchy string = "hierarchy" // ConfigTemplate.Style
View Source
const ConfigTemplateStyleSort string = "sort"
View Source
const DefaultConnectionPrefix string = "conn"
View Source
const DefaultFormatPhaseFormatName = "DefaultFormatPhaseFormat"

Default format names

View Source
const DefaultInterfacePrefix string = "net"
View Source
const DefaultMergePhaseFormatName = "DefaultMergePhaseFormat"
View Source
const DefaultNodePrefix string = "node"
View Source
const DefaultSegmentPrefix string = "seg"
View Source
const IPAddressReplacerFooter string = "addr"
View Source
const IPLoopbackReplacerFooter string = "loopback"

IP number replacer: [IPSpace]_[IPReplacerXX] const IPLoopbackReplacerFooter string = "loopback"

View Source
const IPNetworkReplacerFooter string = "net"
View Source
const IPPolicyTypeDefault string = "ip"
View Source
const IPPolicyTypeLoopback string = "loopback"
View Source
const IPPrefixLengthReplacerFooter string = "plen"
View Source
const IPProtocolReplacerFooter string = "protocol"
View Source
const MountSourcePathAbs string = "abs" // absolute path
View Source
const MountSourcePathLocal string = "local"
View Source
const NumberPrefixConnection string = "conn" + NumberSeparator
View Source
const NumberPrefixGroup string = "group" + NumberSeparator
View Source
const NumberPrefixMember string = "m" + NumberSeparator
View Source
const NumberPrefixNeighbor string = "n" + NumberSeparator
View Source
const NumberPrefixNode string = "node" + NumberSeparator
View Source
const NumberPrefixOppositeInterface string = "opp" + NumberSeparator
View Source
const NumberSeparator string = "_"

namespace related constants

View Source
const OutputAsis string = "command"
View Source
const OutputClab string = "clab"
View Source
const OutputTinet string = "tinet"
View Source
const PathSpecificationDefault string = "default" // search files from working directory
View Source
const PathSpecificationLocal string = "local" // search files from the directory with config file
View Source
const PlaceLabelPrefix string = "@"
View Source
const RelationalClassLabelSeparator string = "#"
View Source
const ReservedParamName string = "name"

Reserved parameter name for object name

View Source
const SelfConfigHeader string = "self" + NumberSeparator
View Source
const ValueLabelSeparator string = "="
View Source
const ValueReferencePrefix string = "values" + NumberSeparator

Value reference prefix for template parameters

View Source
const VirtualNodeClassName string = "virtual"

Special class names used by modules

Variables

View Source
var DefaultFormatPhaseFormat = &FormatStyle{
	Name:                DefaultFormatPhaseFormatName,
	FormatLineSeparator: "\n",
}

Default format definitions

View Source
var DefaultMergePhaseFormat = &FormatStyle{
	Name:                DefaultMergePhaseFormatName,
	MergeBlockSeparator: "\n",
}

Functions

func AllOutput

func AllOutput() []string

func CheckReservedParamName added in v0.7.0

func CheckReservedParamName(paramName string) string

CheckReservedParamName checks if a parameter name conflicts with reserved names or prefixes. Returns an error message if the name is reserved, or empty string if it's safe to use.

func ClassTypeMember

func ClassTypeMember(classType string, className string) string

func ClassTypeNeighbor

func ClassTypeNeighbor(layer string) string

func ClassTypeValue added in v0.7.0

func ClassTypeValue(paramRuleName string) string

ClassTypeValue returns the class type string for a Value with given param_rule name

func GetRelativeFilePath

func GetRelativeFilePath(path string, cfg *Config) string

func InitGloballNameSpace

func InitGloballNameSpace(nm *NetworkModel) (map[string]map[string]string, error)

func ReservedNames added in v0.7.0

func ReservedNames() []string

ReservedNames returns the list of reserved parameter names. These exact names are reserved for internal use.

func ReservedPrefixes added in v0.7.0

func ReservedPrefixes() []string

ReservedPrefixes returns the list of reserved parameter name prefixes. Parameters starting with these prefixes are reserved for internal use.

Types

type BlocksConfig added in v0.6.0

type BlocksConfig struct {
	Before []string `yaml:"before" mapstructure:"before"`
	After  []string `yaml:"after" mapstructure:"after"`
}

BlocksConfig defines config blocks to be merged before/after the template

type Config

type Config struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Modules         []string          `yaml:"module" mapstructure:"module"`
	GlobalSettings  GlobalSettings    `yaml:"global" mapstructure:"global"`
	FileDefinitions []*FileDefinition `yaml:"file" mapstructure:"file"`
	FormatStyles    []*FormatStyle    `yaml:"format,flow" mapstructure:"format,flow"`
	Layers          []*Layer          `yaml:"layer" mapstructure:"layer"`
	ManagementLayer ManagementLayer   `yaml:"mgmt_layer" mapstructure:"mgmt_layer"`
	ParameterRules  []*ParameterRule  `yaml:"param_rule,flow" mapstructure:"param_rule,flow"`

	NetworkClasses    []*NetworkClass    `yaml:"networkclass,flow" mapstructure:"network,flow"`
	NodeClasses       []*NodeClass       `yaml:"nodeclass,flow" mapstructure:"nodes,flow"`
	InterfaceClasses  []*InterfaceClass  `yaml:"interfaceclass,flow" mapstructure:"interfaces,flow"`
	ConnectionClasses []*ConnectionClass `yaml:"connectionclass,flow" mapstructure:"connections,flow"`
	GroupClasses      []*GroupClass      `yaml:"groupclass,flow" mapstructure:"group,flow"`
	SegmentClasses    []*SegmentClass    `yaml:"segmentclass,flow" mapstructure:"segments,flow"`

	LoadedModules              []Module           // reference to loaded modules, internal
	SorterConfigTemplateGroups mapset.Set[string] // list of sort-style config template groups
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

func LoadTemplates

func LoadTemplates(cfg *Config) (*Config, error)

func (*Config) AddConnectionClass

func (cfg *Config) AddConnectionClass(nc *ConnectionClass)

func (*Config) AddFileDefinition

func (cfg *Config) AddFileDefinition(filedef *FileDefinition)

func (*Config) AddFormatStyle added in v0.6.0

func (cfg *Config) AddFormatStyle(fmtstyle *FormatStyle)

func (*Config) AddInterfaceClass

func (cfg *Config) AddInterfaceClass(nc *InterfaceClass)

func (*Config) AddNetworkClass

func (cfg *Config) AddNetworkClass(nc *NetworkClass)

func (*Config) AddNodeClass

func (cfg *Config) AddNodeClass(nc *NodeClass)

func (*Config) AddParameterRule added in v0.7.0

func (cfg *Config) AddParameterRule(pr *ParameterRule)

func (*Config) ConnectionClassByName

func (cfg *Config) ConnectionClassByName(name string) (*ConnectionClass, bool)

func (*Config) DefaultConnectionLayer

func (cfg *Config) DefaultConnectionLayer() []string

func (*Config) FileDefinitionByName

func (cfg *Config) FileDefinitionByName(name string) (*FileDefinition, bool)

func (*Config) FormatStyleByName added in v0.6.0

func (cfg *Config) FormatStyleByName(name string) (*FormatStyle, bool)

func (*Config) GetValidConnectionClasses

func (cfg *Config) GetValidConnectionClasses(given []string) *ParsedLabels

func (*Config) GetValidGroupClasses

func (cfg *Config) GetValidGroupClasses(given []string) *ParsedLabels

func (*Config) GetValidInterfaceClasses

func (cfg *Config) GetValidInterfaceClasses(given []string) *ParsedLabels

func (*Config) GetValidNodeClasses

func (cfg *Config) GetValidNodeClasses(given []string) *ParsedLabels

func (*Config) GetValidSegmentClasses added in v0.5.0

func (cfg *Config) GetValidSegmentClasses(given []string) *ParsedLabels

func (*Config) GroupClassByName

func (cfg *Config) GroupClassByName(name string) (*GroupClass, bool)

func (*Config) HasManagementLayer

func (cfg *Config) HasManagementLayer() bool

func (*Config) InterfaceClassByName

func (cfg *Config) InterfaceClassByName(name string) (*InterfaceClass, bool)

func (*Config) LayerByName

func (cfg *Config) LayerByName(name string) (*Layer, bool)

func (*Config) MountSourcePath

func (cfg *Config) MountSourcePath(path string) (string, error)

func (*Config) NeighborClassesByName

func (cfg *Config) NeighborClassesByName(iface string, ipspace string) ([]*NeighborClass, bool)

func (*Config) NodeClassByName

func (cfg *Config) NodeClassByName(name string) (*NodeClass, bool)

func (*Config) ParameterRuleByName

func (cfg *Config) ParameterRuleByName(name string) (*ParameterRule, bool)

func (*Config) SegmentClassByName added in v0.5.0

func (cfg *Config) SegmentClassByName(name string) (*SegmentClass, bool)

type ConfigTemplate

type ConfigTemplate struct {
	// Config block aggregation styles
	// hierarchy (default): specify child config templates in the template description as parameter
	// sort: merge child config templates of SortTarget groups into the "sort" config templates
	Style     string `yaml:"style" mapstructure:"style"`
	SortGroup string `yaml:"sort_group" mapstructure:"sort_group"`
	// Target file definition name
	// Config templates with file will generate a file of generated text
	File string `yaml:"file" mapstructure:"file"`
	// Name is used by parent objects to specify as childs in templates
	// Config templates with name will form a parameter that can be embeded in other hierarchy templates
	Name string `yaml:"name" mapstructure:"name"`
	// Group is used for sort config templates
	// A sort config template will aggregate all config blocks generated in child (or grandchild) objects of the same group
	Group string `yaml:"group" mapstructure:"group"`
	// Priority is used to reorder config templates in sort style
	// Config blocks with smaller priority should be on the top of generated config files
	// Default is 0, so users should specify negative values to make a config block top of a file
	Priority int `yaml:"priority" mapstructure:"priority"`
	// Used for hierarchy config templates
	// Config template names on same object that need to be embeded
	// Required for ordering config template generation considering the dependency
	Depends []string `yaml:"depends" mapstructure:"depends"`
	// Blocks configuration for flexible config block merging
	Blocks BlocksConfig `yaml:"blocks" mapstructure:"blocks"`

	// Format specifications
	// NamespaceFormat: format applied when registering config blocks to namespace
	NamespaceFormat  string   `yaml:"namespace_format" mapstructure:"namespace_format"`
	NamespaceFormats []string `yaml:"namespace_formats" mapstructure:"namespace_formats"`
	// AssemblyFormat: format applied when assembling config blocks (Sort, blocks)
	AssemblyFormat  string   `yaml:"assembly_format" mapstructure:"assembly_format"`
	AssemblyFormats []string `yaml:"assembly_formats" mapstructure:"assembly_formats"`

	// Condition related fields
	// add config only for interfaces of nodes belongs to the nodeclass(es)
	// this option is valid only on InterfaceClass, ConnectionClass, and their NeighborClass
	NodeClass   string   `yaml:"node" mapstructure:"node"`
	NodeClasses []string `yaml:"nodes" mapstructure:"nodes"`
	// add config only if the neighbor node belongs to the nodeclass(es)
	// this option is valid only on NeighborClass
	NeighborNodeClass   string   `yaml:"neighbor_node" mapstructure:"neighbor_node"`
	NeighborNodeClasses []string `yaml:"neighbor_nodes" mapstructure:"neighbor_nodes"`
	// put empty file or namespace if conditions are not satisfied
	Empty bool `yaml:"empty" mapstructure:"empty"`
	// RequiredParams specifies parameters that must exist for this template to generate output
	// If any of the specified parameters are missing, the entire block is skipped
	RequiredParams []string `yaml:"required_params,flow" mapstructure:"required_params,flow"`

	// This option is valid only on InterfaceClass or ConnectionClass
	// If specified, add config only for included output (e.g., tinet only, clab only, etc)
	Platform []string `yaml:"platform,flow" mapstructure:"platform,flow"`
	// Style is used to iterpret the given config format. Style can be different on one file. As-is in default.
	//Style string `yaml:"style" mapstructure:"style"`
	Format  string   `yaml:"format" mapstructure:"format"`
	Formats []string `yaml:"formats" mapstructure:"formats"`
	// Priority is a value to be used for sorting config blocks. 0 in default.
	// Priority int `yaml:"priority" mapstructure:"priority"`
	// Load config template
	Template []string `yaml:"template" mapstructure:"template"`
	// Load config template from external file
	SourceFile string `yaml:"sourcefile" mapstructure:"sourcefile"`

	ParsedTemplate *template.Template
	// contains filtered or unexported fields
}

func (*ConfigTemplate) GetAssemblyFormats added in v0.6.0

func (ct *ConfigTemplate) GetAssemblyFormats() []string

GetAssemblyFormats returns formats to apply when assembling config blocks (Sort, blocks) Falls back to GetFormats() for backward compatibility, then to default format

func (*ConfigTemplate) GetClassInfo

func (ct *ConfigTemplate) GetClassInfo() (string, string)

func (*ConfigTemplate) GetFormats

func (ct *ConfigTemplate) GetFormats() []string

func (*ConfigTemplate) GetNamespaceFormats added in v0.6.0

func (ct *ConfigTemplate) GetNamespaceFormats() []string

GetNamespaceFormats returns formats to apply when registering config blocks to namespace Falls back to GetFormats() for backward compatibility, then to default format

func (*ConfigTemplate) HasRequiredParams added in v0.7.0

func (ct *ConfigTemplate) HasRequiredParams(params map[string]string) bool

HasRequiredParams checks if all required parameters exist and are non-empty in the given params map. Returns true if RequiredParams is empty or all required parameters exist with non-empty values. Returns false if any required parameter is missing or has an empty value.

func (*ConfigTemplate) NeighborNodeClassCheck

func (ct *ConfigTemplate) NeighborNodeClassCheck(node *Node) bool

func (*ConfigTemplate) NodeClassCheck

func (ct *ConfigTemplate) NodeClassCheck(node *Node) bool

return true if conditions satisfied

func (*ConfigTemplate) String

func (ct *ConfigTemplate) String() string

type Connection

type Connection struct {
	Name   string
	Src    *Interface
	Dst    *Interface
	Layers mapset.Set[string]

	*ParsedLabels
	*NameSpace
	// contains filtered or unexported fields
}

func (Connection) AddMember added in v0.5.0

func (mr Connection) AddMember(m *Member)

func (Connection) AddMemberClass added in v0.5.0

func (mr Connection) AddMemberClass(mc *MemberClass)

func (Connection) AddValue added in v0.7.0

func (vr Connection) AddValue(v *Value)

AddValue adds a Value to the reference

func (Connection) AwareLayer added in v0.5.0

func (a Connection) AwareLayer(layer string) bool

func (*Connection) BuildRelativeNameSpace added in v0.5.0

func (conn *Connection) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Connection) ChildClasses

func (conn *Connection) ChildClasses() ([]string, error)

func (*Connection) Childs

func (conn *Connection) Childs(c string) ([]NameSpacer, error)

func (*Connection) ClassDefinition

func (conn *Connection) ClassDefinition(cfg *Config, cls string) (interface{}, error)

func (*Connection) DependClasses added in v0.5.0

func (conn *Connection) DependClasses() ([]string, error)

func (*Connection) Depends added in v0.5.0

func (conn *Connection) Depends(c string) ([]NameSpacer, error)

func (*Connection) GetConfigTemplates added in v0.5.0

func (conn *Connection) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (Connection) GetLayerPolicy added in v0.5.0

func (a Connection) GetLayerPolicy(layer string) *IPPolicy

func (Connection) GetMemberClasses added in v0.5.0

func (mr Connection) GetMemberClasses() []*MemberClass

func (Connection) GetMembers added in v0.5.0

func (mr Connection) GetMembers() []*Member

func (*Connection) GetPossibleConfigTemplates added in v0.5.0

func (conn *Connection) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (Connection) GetValues added in v0.7.0

func (vr Connection) GetValues() []*Value

GetValues returns all Values

func (Connection) GetValuesByParamRule added in v0.7.0

func (vr Connection) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*Connection) GivenIPNetwork

func (conn *Connection) GivenIPNetwork(layer Layerer) (string, bool)

func (*Connection) SetClasses

func (conn *Connection) SetClasses(cfg *Config, nm *NetworkModel) error

func (*Connection) SetLabels

func (conn *Connection) SetLabels(cfg *Config, labels []string, moduleLabels []string) error

func (*Connection) SortKey added in v0.7.0

func (conn *Connection) SortKey() string

func (*Connection) String

func (conn *Connection) String() string

func (*Connection) StringForMessage

func (conn *Connection) StringForMessage() string

type ConnectionClass

type ConnectionClass struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Virtual         bool              `yaml:"virtual" mapstructure:"virtual"`
	IPPolicy        []string          `yaml:"policy,flow" mapstructure:"policy,flow"`
	Layers          []string          `yaml:"layers,flow" mapstructure:"layers,flow"` // Connection is limited to specified layers
	Parameters      []string          `yaml:"params,flow" mapstructure:"params,flow"` // Parameter policies
	Values          map[string]string `yaml:"values" mapstructure:"values"`
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
	MemberClasses   []*MemberClass    `yaml:"classmembers,flow" mapstructure:"classmembers,flow"`

	// Connection naming
	Prefix string `yaml:"prefix" mapstructure:"prefix"` // prefix of connection auto-naming

	LabelOwnerClass
}

func (*ConnectionClass) GetGivenValues

func (cc *ConnectionClass) GetGivenValues() map[string]string

type FileDefinition

type FileDefinition struct {
	// Name is used as the filename of generated file.
	// If empty and NamePrefix/NameSuffix are specified, filename is generated as:
	//   {NamePrefix}{object_name}{NameSuffix}
	Name string `yaml:"name" mapstructure:"name"`
	// NamePrefix is prepended to the object name when Name is empty.
	NamePrefix string `yaml:"name_prefix" mapstructure:"name_prefix"`
	// NameSuffix is appended to the object name when Name is empty.
	NameSuffix string `yaml:"name_suffix" mapstructure:"name_suffix"`
	// Path is the path that the generated file is placed on the node.
	// If empty, the file is generated but not placed on the node.
	Path string `yaml:"path" mapstructure:"path"`
	// Format is used to determine the way to format lines in generated config text.
	Format  string   `yaml:"format" mapstructure:"format"`
	Formats []string `yaml:"formats,flow" mapstructure:"formats,flow"`
	// Scope specifies the scope of file creation.
	// Available values:
	//   - "network": File is created at network level (root directory)
	//   - "node": File is created for each node (node_name/file_name)
	//   - "" (empty): Defaults to "node" scope for backward compatibility
	// Examples:
	//   - Scope = "network": Creates "spec.yaml", "topo.yaml" at root
	//   - Scope = "node" or "": Creates "r1/frr.conf", "r2/frr.conf", etc.
	Scope string `yaml:"scope" mapstructure:"scope"`
	// Output specifies where the file is placed in the output directory.
	// Available values:
	//   - "root": File is placed at root directory
	//   - "node": File is placed in node subdirectory (node_name/file_name)
	//   - "" (empty): Defaults based on Scope (network->root, node->node)
	// This is useful for Kathara-style startup files that need to be at root
	// but are generated per-node (e.g., r1.startup, r2.startup).
	Output string `yaml:"output" mapstructure:"output"`
}

func (*FileDefinition) GetFileName added in v0.7.0

func (fd *FileDefinition) GetFileName(objectName string) string

GetFileName returns the output filename for this file definition. If NamePrefix or NameSuffix is specified, it generates filename as:

{NamePrefix}{objectName}{NameSuffix}

Otherwise, it returns Name directly. This allows Name to be used as an identifier for referencing, while NamePrefix/NameSuffix control the actual output filename.

func (*FileDefinition) GetFormats

func (fd *FileDefinition) GetFormats() []string

func (*FileDefinition) GetOutputLocation added in v0.7.0

func (fd *FileDefinition) GetOutputLocation() string

GetOutputLocation returns the effective output location. If Output is specified, it returns Output. If Output is empty, it returns the default based on Scope:

  • "network" -> "root"
  • "node" or "" -> "node"

type FileGenerator added in v0.6.0

type FileGenerator interface {
	// FilesToGenerate returns a list of file names that this object will generate based on its classes.
	FilesToGenerate(cfg *Config) []string
}

FileGenerator is an interface for objects that can generate files. Both NetworkModel and Node implement this interface.

type FormatStyle added in v0.6.0

type FormatStyle struct {
	Name string `yaml:"name" mapstructure:"name"`

	// Format Phase (block生成時の装飾)
	FormatLinePrefix    string `yaml:"format_lineprefix" mapstructure:"format_lineprefix"`
	FormatLineSuffix    string `yaml:"format_linesuffix" mapstructure:"format_linesuffix"`
	FormatLineSeparator string `yaml:"format_lineseparator" mapstructure:"format_lineseparator"`
	FormatBlockPrefix   string `yaml:"format_blockprefix" mapstructure:"format_blockprefix"`
	FormatBlockSuffix   string `yaml:"format_blocksuffix" mapstructure:"format_blocksuffix"`

	// Merge Phase (block結合時の処理)
	MergeBlockSeparator string `yaml:"merge_blockseparator" mapstructure:"merge_blockseparator"`
	MergeResultPrefix   string `yaml:"merge_resultprefix" mapstructure:"merge_resultprefix"`
	MergeResultSuffix   string `yaml:"merge_resultsuffix" mapstructure:"merge_resultsuffix"`
}

FormatStyle defines how to format configuration blocks Renamed from FileFormat to align with YAML `format:` section

func (*FormatStyle) GetFormatBlockPrefix added in v0.6.0

func (fs *FormatStyle) GetFormatBlockPrefix() string

func (*FormatStyle) GetFormatBlockSuffix added in v0.6.0

func (fs *FormatStyle) GetFormatBlockSuffix() string

func (*FormatStyle) GetFormatLinePrefix added in v0.6.0

func (fs *FormatStyle) GetFormatLinePrefix() string

Format Phase Getters

func (*FormatStyle) GetFormatLineSeparator added in v0.6.0

func (fs *FormatStyle) GetFormatLineSeparator() string

func (*FormatStyle) GetFormatLineSuffix added in v0.6.0

func (fs *FormatStyle) GetFormatLineSuffix() string

func (*FormatStyle) GetMergeBlockSeparator added in v0.6.0

func (fs *FormatStyle) GetMergeBlockSeparator() string

Merge Phase Getters

func (*FormatStyle) GetMergeResultPrefix added in v0.6.0

func (fs *FormatStyle) GetMergeResultPrefix() string

func (*FormatStyle) GetMergeResultSuffix added in v0.6.0

func (fs *FormatStyle) GetMergeResultSuffix() string

type GlobalSettings

type GlobalSettings struct {
	PathSpecification string `yaml:"path" mapstructure:"path"`
	MountSourcePath   string `yaml:"mountsourcepath" mapstructure:"mountsourcepath"`
	NodeAutoRename    bool   `yaml:"nodeautoname" mapstructure:"nodeautoname"`
}

type Group

type Group struct {
	Name  string
	Nodes []*Node

	*NameSpace
	*ParsedLabels
	// contains filtered or unexported fields
}

func (Group) AddValue added in v0.7.0

func (vr Group) AddValue(v *Value)

AddValue adds a Value to the reference

func (*Group) BuildRelativeNameSpace

func (g *Group) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Group) ChildClasses

func (g *Group) ChildClasses() ([]string, error)

func (*Group) Childs

func (g *Group) Childs(c string) ([]NameSpacer, error)

func (*Group) ClassDefinition

func (g *Group) ClassDefinition(cfg *Config, cls string) (interface{}, error)

func (*Group) DependClasses added in v0.5.0

func (g *Group) DependClasses() ([]string, error)

func (*Group) Depends added in v0.5.0

func (g *Group) Depends(c string) ([]NameSpacer, error)

func (*Group) GetConfigTemplates

func (g *Group) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (*Group) GetPossibleConfigTemplates

func (g *Group) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (Group) GetValues added in v0.7.0

func (vr Group) GetValues() []*Value

GetValues returns all Values

func (Group) GetValuesByParamRule added in v0.7.0

func (vr Group) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*Group) SetClasses

func (g *Group) SetClasses(cfg *Config, nm *NetworkModel) error

func (*Group) SetGroupRelativeParams

func (g *Group) SetGroupRelativeParams(ns NameSpacer, header string) error

Set relative parameters of the group to the group member namespacers

func (*Group) SetLabels

func (g *Group) SetLabels(cfg *Config, labels []string, moduleLabels []string) error

func (*Group) SortKey added in v0.7.0

func (g *Group) SortKey() string

func (*Group) StringForMessage

func (g *Group) StringForMessage() string

type GroupClass

type GroupClass struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Virtual         bool              `yaml:"virtual" mapstructure:"virtual"`
	Parameters      []string          `yaml:"params,flow" mapstructure:"params,flow"` // Parameter policies
	Values          map[string]string `yaml:"values" mapstructure:"values"`
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`

	LabelOwnerClass
}

func (*GroupClass) GetGivenValues

func (gc *GroupClass) GetGivenValues() map[string]string

type IPPolicy

type IPPolicy struct {
	Name string `yaml:"name" mapstructure:"name"`
	// type: ip (deafult), loopback, mgmt
	Type                string `yaml:"type" mapstructure:"type"`
	AddrRange           string `yaml:"range" mapstructure:"range"`
	DefaultPrefixLength int    `yaml:"prefix" mapstructure:"prefix"`
	// contains filtered or unexported fields
}

type Interface

type Interface struct {
	Name       string
	Node       *Node
	Virtual    bool
	Connection *Connection
	Opposite   *Interface
	Neighbors  map[string][]*Neighbor
	NamePrefix string

	*NameSpace
	*ParsedLabels
	// contains filtered or unexported fields
}

func (Interface) AddMember

func (mr Interface) AddMember(m *Member)

func (Interface) AddMemberClass

func (mr Interface) AddMemberClass(mc *MemberClass)

func (*Interface) AddNeighbor

func (iface *Interface) AddNeighbor(neighbor *Interface, layer string)

add Neighbor object only when the Interface has NeighborClasses of corresponding layer

func (Interface) AddValue added in v0.7.0

func (vr Interface) AddValue(v *Value)

AddValue adds a Value to the reference

func (Interface) AwareLayer

func (a Interface) AwareLayer(layer string) bool

func (*Interface) BuildRelativeNameSpace

func (iface *Interface) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Interface) ChildClasses

func (iface *Interface) ChildClasses() ([]string, error)

func (*Interface) Childs

func (iface *Interface) Childs(c string) ([]NameSpacer, error)

func (*Interface) ClassDefinition

func (iface *Interface) ClassDefinition(cfg *Config, cls string) (interface{}, error)

func (*Interface) DependClasses added in v0.5.0

func (iface *Interface) DependClasses() ([]string, error)

func (*Interface) Depends added in v0.5.0

func (iface *Interface) Depends(c string) ([]NameSpacer, error)

func (*Interface) GetConfigTemplates

func (iface *Interface) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (Interface) GetLayerPolicy

func (a Interface) GetLayerPolicy(layer string) *IPPolicy

func (Interface) GetMemberClasses

func (mr Interface) GetMemberClasses() []*MemberClass

func (Interface) GetMembers

func (mr Interface) GetMembers() []*Member

func (*Interface) GetPossibleConfigTemplates

func (iface *Interface) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (Interface) GetValues added in v0.7.0

func (vr Interface) GetValues() []*Value

GetValues returns all Values

func (Interface) GetValuesByParamRule added in v0.7.0

func (vr Interface) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*Interface) GivenIPAddress

func (iface *Interface) GivenIPAddress(layer Layerer) (string, bool)

func (*Interface) SetClasses

func (iface *Interface) SetClasses(cfg *Config, nm *NetworkModel) error

func (*Interface) SetLabels

func (iface *Interface) SetLabels(cfg *Config, labels []string, moduleLabels []string) error

func (*Interface) SortKey added in v0.7.0

func (iface *Interface) SortKey() string

func (*Interface) String

func (iface *Interface) String() string

func (*Interface) StringForMessage

func (iface *Interface) StringForMessage() string

type InterfaceClass

type InterfaceClass struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Virtual         bool              `yaml:"virtual" mapstructure:"virtual"`
	IPPolicy        []string          `yaml:"policy,flow" mapstructure:"policy,flow"`
	Layers          []string          `yaml:"layers,flow" mapstructure:"layers,flow"` // Interface connection is limited to specified layers
	Parameters      []string          `yaml:"params,flow" mapstructure:"params,flow"` // Parameter policies
	Values          map[string]string `yaml:"values" mapstructure:"values"`
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
	NeighborClasses []*NeighborClass  `yaml:"neighbors,flow" mapstructure:"neighbors,flow"`
	MemberClasses   []*MemberClass    `yaml:"classmembers,flow" mapstructure:"classmembers,flow"`

	Prefix string `yaml:"prefix" mapstructure:"prefix"` // prefix of auto-naming

	LabelOwnerClass
}

func (*InterfaceClass) GetGivenValues

func (ic *InterfaceClass) GetGivenValues() map[string]string

type LabelOwner

type LabelOwner interface {
	ClassLabels() []string
	RelationalClassLabels() []RelationalClassLabel
	PlaceLabels() []string
	ValueLabels() map[string]string
	MetaValueLabels() map[string]string
	SetLabels(cfg *Config, labels []string, moduleLabels []string) error
	AddClassLabels(labels ...string)

	HasClass(string) bool
	GetClasses() []ObjectClass

	SetVirtual(bool)
	IsVirtual() bool

	ClassDefinition(cfg *Config, cls string) (interface{}, error)

	ObjectInstance
}

LabelOwner includes Node, Interface, Connection, Group

type LabelOwnerClass

type LabelOwnerClass interface {
	GetGivenValues() map[string]string
}

type Layer

type Layer struct {
	Name string `yaml:"name" mapstructure:"name"`
	// If default_connect is true, ConnectionClasses without ipspaces field are considered as connected on this Layer
	DefaultConnect bool        `yaml:"default_connect" mapstructure:"default_connect"`
	Policies       []*IPPolicy `yaml:"policy" mapstructure:"policy"`

	Layerer

	IPPolicy       []*IPPolicy
	LoopbackPolicy []*IPPolicy
}

func (*Layer) IPAddressReplacer

func (layer *Layer) IPAddressReplacer() string

func (*Layer) IPLoopbackReplacer

func (layer *Layer) IPLoopbackReplacer() string

func (*Layer) IPNetworkReplacer

func (layer *Layer) IPNetworkReplacer() string

func (*Layer) IPPrefixLengthReplacer

func (layer *Layer) IPPrefixLengthReplacer() string

func (*Layer) IPProtocolReplacer

func (layer *Layer) IPProtocolReplacer() string

type Layerer

type Layerer interface {
	IPAddressReplacer() string
	IPNetworkReplacer() string
	IPPrefixLengthReplacer() string
}

type ManagementLayer

type ManagementLayer struct {
	Name      string `yaml:"name" mapstructure:"name"`
	AddrRange string `yaml:"range" mapstructure:"range"`
	// gateway is used only for management network or external network
	// the address is avoided in automated IPaddress assignment
	ExternalGateway string `yaml:"gateway" mapstructure:"gateway"`
	InterfaceName   string `yaml:"interface_name" mapstructure:"mgmt_name"`

	Layerer
}

func (*ManagementLayer) IPAddressReplacer

func (layer *ManagementLayer) IPAddressReplacer() string

func (*ManagementLayer) IPNetworkReplacer

func (layer *ManagementLayer) IPNetworkReplacer() string

func (*ManagementLayer) IPPrefixLengthReplacer

func (layer *ManagementLayer) IPPrefixLengthReplacer() string

type Member

type Member struct {
	ClassName string
	ClassType string
	Referrer  MemberReferrer
	Member    NameSpacer

	*NameSpace
}

func NewMember

func NewMember(cls string, classtype string, memberObject NameSpacer, referrer MemberReferrer) *Member

func (*Member) BuildRelativeNameSpace

func (m *Member) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Member) ChildClasses

func (m *Member) ChildClasses() ([]string, error)

func (*Member) Childs

func (m *Member) Childs(c string) ([]NameSpacer, error)

func (*Member) DependClasses added in v0.5.0

func (m *Member) DependClasses() ([]string, error)

func (*Member) Depends added in v0.5.0

func (m *Member) Depends(c string) ([]NameSpacer, error)

func (*Member) GetConfigTemplates

func (m *Member) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (*Member) GetPossibleConfigTemplates

func (m *Member) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (*Member) StringForMessage

func (m *Member) StringForMessage() string

type MemberClass

type MemberClass struct {
	NodeClass         string            `yaml:"node" mapstructure:"node"`
	NodeClasses       []string          `yaml:"nodes" mapstructure:"nodes"`
	InterfaceClass    string            `yaml:"interface" mapstructure:"interface"`
	InterfaceClasses  []string          `yaml:"interfaces" mapstructure:"interfaces"`
	ConnectionClass   string            `yaml:"connection" mapstructure:"connection"`
	ConnectionClasses []string          `yaml:"connections" mapstructure:"connections"`
	IncludeSelf       bool              `yaml:"include_self" mapstructure:"include_self"`
	ConfigTemplates   []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
}

func (*MemberClass) GetSpecifiedClasses

func (mc *MemberClass) GetSpecifiedClasses() (string, []string, error)

check MemberClass description and return (classtype, classnames)

type MemberReferrer

type MemberReferrer interface {
	LabelOwner
	NameSpacer
	ObjectInstance

	AddMemberClass(*MemberClass)
	GetMemberClasses() []*MemberClass
	AddMember(*Member)
	GetMembers() []*Member
}

classMemberReferer includes Node, Interface commented out because it currently does not have abstracted usage (explicitly addressed) Note: MemberClass is defined in config.go

type Module

type Module interface {
	UpdateConfig(cfg *Config) error
	AddModuleNodeClassLabel(label string)
	GetModuleNodeClassLabels() []string
	AddModuleInterfaceClassLabel(label string)
	GetModuleInterfaceClassLabels() []string
	AddModuleConnectionClassLabel(label string)
	GetModuleConnectionClassLabels() []string
	//SetClasses(cfg *Config, nm *NetworkModel) error
	GenerateParameters(cfg *Config, nm *NetworkModel) error
	CheckModuleRequirements(cfg *Config, nm *NetworkModel) error
}

type NameSpace

type NameSpace struct {
	// contains filtered or unexported fields
}

Namespace only implements parameter related methods, but does not provide top-down structure

func (*NameSpace) AddParam

func (ns *NameSpace) AddParam(k, v string)

func (*NameSpace) GetParamValue

func (ns *NameSpace) GetParamValue(key string) (string, error)

GetParamValue returns a parameter value from relative namespace

func (*NameSpace) GetParams

func (ns *NameSpace) GetParams() map[string]string

func (*NameSpace) GetRelativeParams

func (ns *NameSpace) GetRelativeParams() map[string]string

func (*NameSpace) HasParam

func (ns *NameSpace) HasParam(k string) bool

func (*NameSpace) HasRelativeParam

func (ns *NameSpace) HasRelativeParam(k string) bool

func (*NameSpace) IterateFlaggedParams

func (ns *NameSpace) IterateFlaggedParams() <-chan string

func (*NameSpace) SetRelativeParam

func (ns *NameSpace) SetRelativeParam(k, v string)

func (*NameSpace) SetRelativeParams

func (ns *NameSpace) SetRelativeParams(given map[string]string)

type NameSpacer

type NameSpacer interface {
	// Methods to trace top-down network model
	ChildClasses() ([]string, error)
	Childs(c string) ([]NameSpacer, error)
	// Methods for dependency graph processing
	DependClasses() ([]string, error)
	Depends(c string) ([]NameSpacer, error)

	IterateFlaggedParams() <-chan string
	AddParam(k, v string)
	HasParam(k string) bool

	// BuildRelativeNameSpace() error
	BuildRelativeNameSpace(globalParams map[string]map[string]string) error
	SetRelativeParam(k, v string)
	HasRelativeParam(k string) bool
	SetRelativeParams(map[string]string)
	GetParams() map[string]string
	GetRelativeParams() map[string]string
	GetParamValue(string) (string, error)

	GetConfigTemplates(cfg *Config) []*ConfigTemplate
	GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

	ObjectInstance
	// contains filtered or unexported methods
}

NameSpacer is an element of top-down network model A namespacer owns parameter namespace and generates configuration blocks Candidates: Network, Node, Interface, Segment, Neighbor, Member, Group

type Neighbor

type Neighbor struct {
	Self            *Interface
	Neighbor        *Interface
	Layer           string
	NeighborClasses []*NeighborClass

	*NameSpace
}

func (*Neighbor) BuildRelativeNameSpace

func (n *Neighbor) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Neighbor) ChildClasses

func (n *Neighbor) ChildClasses() ([]string, error)

func (*Neighbor) Childs

func (n *Neighbor) Childs(c string) ([]NameSpacer, error)

func (*Neighbor) DependClasses added in v0.5.0

func (n *Neighbor) DependClasses() ([]string, error)

func (*Neighbor) Depends added in v0.5.0

func (n *Neighbor) Depends(c string) ([]NameSpacer, error)

func (*Neighbor) GetConfigTemplates

func (n *Neighbor) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (*Neighbor) GetPossibleConfigTemplates

func (n *Neighbor) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (*Neighbor) StringForMessage

func (n *Neighbor) StringForMessage() string

type NeighborClass

type NeighborClass struct {
	Layer           string            `yaml:"layer" mapstructure:"layer"`
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
}

type NetworkClass

type NetworkClass struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Values          map[string]string `yaml:"values" mapstructure:"values"`
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`

	LabelOwnerClass
}

func (*NetworkClass) GetGivenValues

func (nc *NetworkClass) GetGivenValues() map[string]string

type NetworkModel

type NetworkModel struct {
	Name        string
	Nodes       []*Node
	Connections []*Connection
	Groups      []*Group
	Classes     []*NetworkClass

	*NameSpace

	NetworkSegments map[string][]*NetworkSegment
	// contains filtered or unexported fields
}

func NewNetworkModel

func NewNetworkModel() *NetworkModel

func (NetworkModel) AddValue added in v0.7.0

func (vr NetworkModel) AddValue(v *Value)

AddValue adds a Value to the reference

func (*NetworkModel) BuildRelativeNameSpace

func (nm *NetworkModel) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*NetworkModel) ChildClasses

func (nm *NetworkModel) ChildClasses() ([]string, error)

func (*NetworkModel) Childs

func (nm *NetworkModel) Childs(c string) ([]NameSpacer, error)

func (*NetworkModel) ConnectionClassMembers

func (nm *NetworkModel) ConnectionClassMembers(cls string) []NameSpacer

func (*NetworkModel) DependClasses added in v0.5.0

func (nm *NetworkModel) DependClasses() ([]string, error)

func (*NetworkModel) Depends added in v0.5.0

func (nm *NetworkModel) Depends(c string) ([]NameSpacer, error)

func (*NetworkModel) FilesToGenerate added in v0.6.0

func (nm *NetworkModel) FilesToGenerate(cfg *Config) []string

FilesToGenerate returns a list of file names that the network will generate based on its NetworkClasses.

func (*NetworkModel) GetConfigTemplates

func (nm *NetworkModel) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (*NetworkModel) GetPossibleConfigTemplates

func (nm *NetworkModel) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (NetworkModel) GetValues added in v0.7.0

func (vr NetworkModel) GetValues() []*Value

GetValues returns all Values

func (NetworkModel) GetValuesByParamRule added in v0.7.0

func (vr NetworkModel) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*NetworkModel) GroupByName

func (nm *NetworkModel) GroupByName(name string) (*Group, bool)

func (*NetworkModel) InterfaceClassMembers

func (nm *NetworkModel) InterfaceClassMembers(cls string) []NameSpacer

func (*NetworkModel) LabelOwners

func (nm *NetworkModel) LabelOwners() (result []LabelOwner)

func (*NetworkModel) MemberReferrers

func (nm *NetworkModel) MemberReferrers() (result []MemberReferrer)

func (*NetworkModel) NameSpacers

func (nm *NetworkModel) NameSpacers() (result []NameSpacer)

func (*NetworkModel) NewConnection

func (nm *NetworkModel) NewConnection(src *Interface, dst *Interface) *Connection

func (*NetworkModel) NewGroup

func (nm *NetworkModel) NewGroup(name string) *Group

func (*NetworkModel) NewNode

func (nm *NetworkModel) NewNode(name string) *Node

func (*NetworkModel) NodeByName

func (nm *NetworkModel) NodeByName(name string) (*Node, bool)

func (*NetworkModel) NodeClassMembers

func (nm *NetworkModel) NodeClassMembers(cls string) []NameSpacer

func (*NetworkModel) RenameNode

func (nm *NetworkModel) RenameNode(node *Node, oldName string, newName string)

func (*NetworkModel) SegmentClassMembers added in v0.5.0

func (nm *NetworkModel) SegmentClassMembers(cls string) []NameSpacer

func (*NetworkModel) SortKey added in v0.7.0

func (nm *NetworkModel) SortKey() string

func (*NetworkModel) StringForMessage

func (nm *NetworkModel) StringForMessage() string

func (*NetworkModel) ValueOwners added in v0.7.0

func (nm *NetworkModel) ValueOwners() (result []ValueOwner)

ValueOwners returns all objects that can have Values attached

type NetworkSegment added in v0.5.0

type NetworkSegment struct {
	Name        string // Auto-assigned name
	Layer       string
	Interfaces  []*Interface
	Connections []*Connection
	NamePrefix  string // Prefix for auto-naming

	*NameSpace
	*ParsedLabels
	// contains filtered or unexported fields
}

func NewNetworkSegment added in v0.5.0

func NewNetworkSegment() *NetworkSegment

func (NetworkSegment) AddMember added in v0.5.0

func (mr NetworkSegment) AddMember(m *Member)

func (NetworkSegment) AddMemberClass added in v0.5.0

func (mr NetworkSegment) AddMemberClass(mc *MemberClass)

func (NetworkSegment) AddValue added in v0.7.0

func (vr NetworkSegment) AddValue(v *Value)

AddValue adds a Value to the reference

func (*NetworkSegment) BuildRelativeNameSpace added in v0.5.0

func (seg *NetworkSegment) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*NetworkSegment) ChildClasses added in v0.5.0

func (seg *NetworkSegment) ChildClasses() ([]string, error)

func (*NetworkSegment) Childs added in v0.5.0

func (seg *NetworkSegment) Childs(c string) ([]NameSpacer, error)

func (*NetworkSegment) ClassDefinition added in v0.5.0

func (seg *NetworkSegment) ClassDefinition(cfg *Config, cls string) (interface{}, error)

func (*NetworkSegment) DependClasses added in v0.5.0

func (seg *NetworkSegment) DependClasses() ([]string, error)

func (*NetworkSegment) Depends added in v0.5.0

func (seg *NetworkSegment) Depends(c string) ([]NameSpacer, error)

func (*NetworkSegment) GetConfigTemplates added in v0.5.0

func (seg *NetworkSegment) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (NetworkSegment) GetMemberClasses added in v0.5.0

func (mr NetworkSegment) GetMemberClasses() []*MemberClass

func (NetworkSegment) GetMembers added in v0.5.0

func (mr NetworkSegment) GetMembers() []*Member

func (*NetworkSegment) GetPossibleConfigTemplates added in v0.5.0

func (seg *NetworkSegment) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (NetworkSegment) GetValues added in v0.7.0

func (vr NetworkSegment) GetValues() []*Value

GetValues returns all Values

func (NetworkSegment) GetValuesByParamRule added in v0.7.0

func (vr NetworkSegment) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*NetworkSegment) SetClasses added in v0.5.1

func (seg *NetworkSegment) SetClasses(cfg *Config, nm *NetworkModel) error

func (*NetworkSegment) SetLabels added in v0.5.0

func (seg *NetworkSegment) SetLabels(cfg *Config, labels []string, moduleLabels []string) error

func (*NetworkSegment) SetSegmentLabelsFromRelationalLabels added in v0.5.0

func (seg *NetworkSegment) SetSegmentLabelsFromRelationalLabels(cfg *Config, layer *Layer) error

SetSegmentLabelsFromRelationalLabels sets segment class labels by collecting relational class labels from the segment's connections and interfaces. Unlike SetLabels, segments receive labels indirectly.

func (*NetworkSegment) SortKey added in v0.7.0

func (seg *NetworkSegment) SortKey() string

func (*NetworkSegment) String added in v0.5.1

func (seg *NetworkSegment) String() string

func (*NetworkSegment) StringForMessage added in v0.5.0

func (seg *NetworkSegment) StringForMessage() string

type Node

type Node struct {
	Name       string
	Interfaces []*Interface
	Groups     []*Group

	*NameSpace
	*ParsedLabels

	NamePrefix string
	// contains filtered or unexported fields
}

func (Node) AddMember

func (mr Node) AddMember(m *Member)

func (Node) AddMemberClass

func (mr Node) AddMemberClass(mc *MemberClass)

func (Node) AddValue added in v0.7.0

func (vr Node) AddValue(v *Value)

AddValue adds a Value to the reference

func (Node) AwareLayer

func (a Node) AwareLayer(layer string) bool

func (*Node) BuildRelativeNameSpace

func (n *Node) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

func (*Node) ChildClasses

func (n *Node) ChildClasses() ([]string, error)

func (*Node) Childs

func (n *Node) Childs(c string) ([]NameSpacer, error)

func (*Node) ClassDefinition

func (n *Node) ClassDefinition(cfg *Config, cls string) (interface{}, error)

func (*Node) CreateManagementInterface

func (n *Node) CreateManagementInterface(cfg *Config, name string) (*Interface, error)

func (*Node) DependClasses added in v0.5.0

func (n *Node) DependClasses() ([]string, error)

func (*Node) Depends added in v0.5.0

func (n *Node) Depends(c string) ([]NameSpacer, error)

func (*Node) FilesToGenerate added in v0.6.0

func (n *Node) FilesToGenerate(cfg *Config) []string

FilesToGenerate returns a list of file names that the node will generate based on its classes. It examines NodeClass ConfigTemplates.

func (*Node) GetConfigTemplates

func (n *Node) GetConfigTemplates(cfg *Config) []*ConfigTemplate

func (Node) GetLayerPolicy

func (a Node) GetLayerPolicy(layer string) *IPPolicy

func (*Node) GetManagementInterface

func (n *Node) GetManagementInterface() *Interface

func (Node) GetMemberClasses

func (mr Node) GetMemberClasses() []*MemberClass

func (Node) GetMembers

func (mr Node) GetMembers() []*Member

func (*Node) GetPossibleConfigTemplates

func (n *Node) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

func (Node) GetValues added in v0.7.0

func (vr Node) GetValues() []*Value

GetValues returns all Values

func (Node) GetValuesByParamRule added in v0.7.0

func (vr Node) GetValuesByParamRule(paramRuleName string) []*Value

GetValuesByParamRule returns Values generated by the specified param_rule

func (*Node) GivenIPLoopback

func (n *Node) GivenIPLoopback(layer *Layer) (string, bool)

func (*Node) HasAwareInterface

func (n *Node) HasAwareInterface(layer string) bool

func (*Node) InterfaceByName

func (n *Node) InterfaceByName(name string) (*Interface, bool)

func (*Node) NewInterface

func (n *Node) NewInterface(name string) *Interface

func (*Node) RenameInterface

func (n *Node) RenameInterface(iface *Interface, oldName string, newName string)

func (*Node) SetClasses

func (n *Node) SetClasses(cfg *Config, nm *NetworkModel) error

func (*Node) SetLabels

func (n *Node) SetLabels(cfg *Config, labels []string, moduleLabels []string) error

func (*Node) SortKey added in v0.7.0

func (n *Node) SortKey() string

func (*Node) String

func (n *Node) String() string

func (*Node) StringForMessage

func (n *Node) StringForMessage() string

type NodeClass

type NodeClass struct {
	// A virtual node have parameters, but no object nor configuration. It is considered only on parameter assignment.
	Name              string            `yaml:"name" mapstructure:"name"`
	Virtual           bool              `yaml:"virtual" mapstructure:"virtual"`
	IPPolicy          []string          `yaml:"policy,flow" mapstructure:"policy,flow"`
	Parameters        []string          `yaml:"params,flow" mapstructure:"params,flow"` // Parameter policies
	Values            map[string]string `yaml:"values" mapstructure:"values"`
	InterfaceIPPolicy []string          `yaml:"interface_policy,flow" mapstructure:"interface_policy,flow"`
	ConfigTemplates   []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
	MemberClasses     []*MemberClass    `yaml:"classmembers,flow" mapstructure:"classmembers,flow"`

	Prefix        string `yaml:"prefix" mapstructure:"prefix"`                           // prefix of auto-naming
	MgmtInterface string `yaml:"mgmt_interfaceclass" mapstructure:"mgmt_interfaceclass"` // InterfaceClass name for mgmt

	LabelOwnerClass
}

func (*NodeClass) GetGivenValues

func (nc *NodeClass) GetGivenValues() map[string]string

type ObjectClass

type ObjectClass interface{}

type ObjectInstance

type ObjectInstance interface {
	StringForMessage() string // just for debug messages
}

type ParameterGenerator added in v0.7.0

type ParameterGenerator interface {
	// GenerateValueParameters generates a list of parameter sets for creating Values
	// generatorName: the generator name after the module prefix (e.g., "filemounts" for "clab.filemounts")
	// target: the target object (Node, Interface, etc.)
	// cfg: the configuration
	// nm: the network model
	// Returns: a list of parameter maps, one per Value to be created
	GenerateValueParameters(
		generatorName string,
		target ValueOwner,
		cfg *Config,
		nm *NetworkModel,
	) ([]map[string]string, error)
}

ParameterGenerator is optionally implemented by modules that can generate Value parameter lists for attach mode param_rules with generator specification (e.g., "clab.filemounts")

type ParameterRule

type ParameterRule struct {
	Name string `yaml:"name" mapstructure:"name"`
	// Mode: "distribute" (default) or "attach"
	// distribute: N objects get 1 parameter each (legacy behavior)
	// attach: 1 object gets N Values attached
	Mode string `yaml:"mode" mapstructure:"mode"`
	// object (in default) or segment
	Assign string `yaml:"assign" mapstructure:"assign"`
	// layer is used only when the assign option is "segment"
	Layer string `yaml:"layer" mapstructure:"layer"`
	// integer (in default) or file
	Type string `yaml:"type" mapstructure:"type"`
	// for type integer
	Max    int    `yaml:"max" mapstructure:"max"`
	Min    int    `yaml:"min" mapstructure:"min"`
	Header string `yaml:"header" mapstructure:"header"`
	Footer string `yaml:"footer" mapstructure:"footer"`
	// for type file
	SourceFile string `yaml:"sourcefile" mapstructure:"soucefile"`

	// === attach mode fields ===
	// Source defines how to generate Value list (for attach mode)
	Source *ParameterRuleSource `yaml:"source" mapstructure:"source"`
	// Generator specifies a module-provided generator (e.g., "clab.bindmounts")
	Generator string `yaml:"generator" mapstructure:"generator"`
	// ParamFormat defines how to format source values into Value parameters
	ParamFormat map[string]string `yaml:"param_format" mapstructure:"param_format"`
	// ConfigTemplates defines config blocks for Values
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
	// Sort specifies ordering: "asc", "desc", or empty (preserve generation order)
	Sort string `yaml:"sort" mapstructure:"sort"`
}

func (*ParameterRule) GetMode added in v0.7.0

func (pr *ParameterRule) GetMode() string

GetMode returns the mode, defaulting to "distribute" if not specified

func (*ParameterRule) IsAttachMode added in v0.7.0

func (pr *ParameterRule) IsAttachMode() bool

IsAttachMode returns true if this rule uses attach mode

type ParameterRuleSource added in v0.7.0

type ParameterRuleSource struct {
	// Type specifies the source type: range, sequence, list, file
	Type string `yaml:"type" mapstructure:"type"`
	// Start is used for range type
	Start int `yaml:"start" mapstructure:"start"`
	// End is used for range type
	End int `yaml:"end" mapstructure:"end"`
	// Values is used for list type (inline values)
	Values []map[string]interface{} `yaml:"values" mapstructure:"values"`
	// File is used for file type
	File string `yaml:"file" mapstructure:"file"`
	// Format specifies the file format: yaml, json, csv, text (default: auto-detect from extension)
	Format string `yaml:"format" mapstructure:"format"`
}

ParameterRuleSource defines the source for generating Value lists

type ParsedLabels

type ParsedLabels struct {
	Classes []ObjectClass
	// contains filtered or unexported fields
}

func (*ParsedLabels) AddClassLabels added in v0.5.0

func (l *ParsedLabels) AddClassLabels(labels ...string)

func (*ParsedLabels) ClassLabels

func (l *ParsedLabels) ClassLabels() []string

func (*ParsedLabels) GetClasses

func (l *ParsedLabels) GetClasses() []ObjectClass

func (*ParsedLabels) HasClass

func (l *ParsedLabels) HasClass(name string) bool

func (*ParsedLabels) IsVirtual

func (l *ParsedLabels) IsVirtual() bool

func (*ParsedLabels) MetaValueLabels

func (l *ParsedLabels) MetaValueLabels() map[string]string

func (*ParsedLabels) PlaceLabels

func (l *ParsedLabels) PlaceLabels() []string

func (*ParsedLabels) RelationalClassLabels added in v0.5.0

func (l *ParsedLabels) RelationalClassLabels() []RelationalClassLabel

func (*ParsedLabels) SetVirtual

func (l *ParsedLabels) SetVirtual(flag bool)

func (*ParsedLabels) ValueLabels

func (l *ParsedLabels) ValueLabels() map[string]string

type RelationalClassLabel added in v0.5.0

type RelationalClassLabel struct {
	ClassType string
	Name      string
}

type SegmentClass added in v0.5.0

type SegmentClass struct {
	Name            string            `yaml:"name" mapstructure:"name"`
	Layer           string            `yaml:"layer" mapstructure:"layer"`
	Parameters      []string          `yaml:"params,flow" mapstructure:"params,flow"` // Parameter policies
	ConfigTemplates []*ConfigTemplate `yaml:"config,flow" mapstructure:"config,flow"`
	Prefix          string            `yaml:"prefix" mapstructure:"prefix"` // prefix of segment auto-naming
}

type StandardModule

type StandardModule struct {
	NodeClassLabels       []string
	InterfaceClassLabels  []string
	ConnectionClassLabels []string
}

func NewStandardModule

func NewStandardModule() *StandardModule

func (*StandardModule) AddModuleConnectionClassLabel

func (m *StandardModule) AddModuleConnectionClassLabel(label string)

func (*StandardModule) AddModuleInterfaceClassLabel

func (m *StandardModule) AddModuleInterfaceClassLabel(label string)

func (*StandardModule) AddModuleNodeClassLabel

func (m *StandardModule) AddModuleNodeClassLabel(label string)

func (*StandardModule) GetModuleConnectionClassLabels

func (m *StandardModule) GetModuleConnectionClassLabels() []string

func (*StandardModule) GetModuleInterfaceClassLabels

func (m *StandardModule) GetModuleInterfaceClassLabels() []string

func (*StandardModule) GetModuleNodeClassLabels

func (m *StandardModule) GetModuleNodeClassLabels() []string

type Value added in v0.7.0

type Value struct {
	// ParamRuleName is the name of the param_rule that generated this Value
	ParamRuleName string
	// Owner is the parent object that owns this Value
	Owner ValueOwner
	// Index is the position in the Value list (0, 1, 2, ...)
	Index int

	*NameSpace
}

Value represents a virtual object that holds a set of related parameters. Unlike Node, Interface, etc., Value has no corresponding object in the DOT file. Values are dynamically generated by param_rule with mode: attach.

func NewValue added in v0.7.0

func NewValue(paramRuleName string, owner ValueOwner, index int) *Value

NewValue creates a new Value with the given parameters

func (*Value) BuildRelativeNameSpace added in v0.7.0

func (v *Value) BuildRelativeNameSpace(globalParams map[string]map[string]string) error

BuildRelativeNameSpace builds the relative namespace for template rendering

func (*Value) ChildClasses added in v0.7.0

func (v *Value) ChildClasses() ([]string, error)

ChildClasses returns an empty list (Value is a leaf object)

func (*Value) Childs added in v0.7.0

func (v *Value) Childs(c string) ([]NameSpacer, error)

Childs returns nil (Value has no children)

func (*Value) DependClasses added in v0.7.0

func (v *Value) DependClasses() ([]string, error)

DependClasses returns an empty list (Value has no dependencies)

func (*Value) Depends added in v0.7.0

func (v *Value) Depends(c string) ([]NameSpacer, error)

Depends returns nil (Value has no dependencies)

func (*Value) GetConfigTemplates added in v0.7.0

func (v *Value) GetConfigTemplates(cfg *Config) []*ConfigTemplate

GetConfigTemplates returns config templates from the param_rule that generated this Value

func (*Value) GetPossibleConfigTemplates added in v0.7.0

func (v *Value) GetPossibleConfigTemplates(cfg *Config) []*ConfigTemplate

GetPossibleConfigTemplates returns the same as GetConfigTemplates for Value

func (*Value) StringForMessage added in v0.7.0

func (v *Value) StringForMessage() string

StringForMessage returns a string representation for debug messages

type ValueOwner added in v0.7.0

type ValueOwner interface {
	NameSpacer

	// SortKey returns a string key for deterministic sorting of objects.
	// Used to ensure stable parameter assignment order regardless of map iteration order.
	SortKey() string
	// AddValue adds a Value to this owner
	AddValue(v *Value)
	// GetValues returns all Values attached to this owner
	GetValues() []*Value
	// GetValuesByParamRule returns Values generated by the specified param_rule
	GetValuesByParamRule(paramRuleName string) []*Value
}

ValueOwner is an interface for objects that can have Values attached. Values are virtual objects generated by param_rule with mode: attach. Implemented by: NetworkModel, Node, Interface, Connection, Group, NetworkSegment

Jump to

Keyboard shortcuts

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