Skip to content

Commit

Permalink
Store information about NodeGeneration in registry.
Browse files Browse the repository at this point in the history
So far generate.go contained two lists indenpendent from the nodes, that would describe nodes that (1) can be generated and (b) what the interface naming convention would be for the node kind. This will introduce seperate fields in the NodeRegistry for this information, such that the information for this sort of node generation can be defined as part of the node definition
  • Loading branch information
steiler committed May 2, 2023
1 parent 26b2ee4 commit 88ed50d
Show file tree
Hide file tree
Showing 29 changed files with 263 additions and 88 deletions.
2 changes: 1 addition & 1 deletion clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func NewContainerLab(opts ...ClabOption) (*CLab, error) {
c.Reg = nodes.NewNodeRegistry()

// register all nodes
c.RegisterNodes()
RegisterNodes(c.Reg)

for _, opt := range opts {
err := opt(c)
Expand Down
2 changes: 1 addition & 1 deletion clab/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func PrepareVars(c *clab.CLab) map[string]*NodeConfig {
vars[vkRole] = nodeCfg.Kind
}

creds := c.Reg.Kind(nodeCfg.Kind).Credentials().Slice()
creds := c.Reg.Kind(nodeCfg.Kind).GetCredentials().Slice()

res[name] = &NodeConfig{
TargetNode: nodeCfg,
Expand Down
63 changes: 32 additions & 31 deletions clab/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package clab

import (
"github.com/srl-labs/containerlab/nodes"
border0 "github.com/srl-labs/containerlab/nodes/border0"
bridge "github.com/srl-labs/containerlab/nodes/bridge"
c8000 "github.com/srl-labs/containerlab/nodes/c8000"
Expand Down Expand Up @@ -38,35 +39,35 @@ import (
)

// RegisterNodes registers all the nodes/kinds supported by containerlab.
func (c *CLab) RegisterNodes() {
bridge.Register(c.Reg)
ceos.Register(c.Reg)
checkpoint_cloudguard.Register(c.Reg)
crpd.Register(c.Reg)
cvx.Register(c.Reg)
ext_container.Register(c.Reg)
host.Register(c.Reg)
ipinfusion_ocnos.Register(c.Reg)
keysight_ixiacone.Register(c.Reg)
linux.Register(c.Reg)
ovs.Register(c.Reg)
sonic.Register(c.Reg)
srl.Register(c.Reg)
vr_csr.Register(c.Reg)
vr_ftosv.Register(c.Reg)
vr_n9kv.Register(c.Reg)
vr_nxos.Register(c.Reg)
vr_pan.Register(c.Reg)
vr_ros.Register(c.Reg)
vr_sros.Register(c.Reg)
vr_veos.Register(c.Reg)
vr_vmx.Register(c.Reg)
vr_vsrx.Register(c.Reg)
vr_vqfx.Register(c.Reg)
vr_xrv.Register(c.Reg)
vr_xrv9k.Register(c.Reg)
xrd.Register(c.Reg)
rare.Register(c.Reg)
c8000.Register(c.Reg)
border0.Register(c.Reg)
func RegisterNodes(r *nodes.NodeRegistry) {
bridge.Register(r)
ceos.Register(r)
checkpoint_cloudguard.Register(r)
crpd.Register(r)
cvx.Register(r)
ext_container.Register(r)
host.Register(r)
ipinfusion_ocnos.Register(r)
keysight_ixiacone.Register(r)
linux.Register(r)
ovs.Register(r)
sonic.Register(r)
srl.Register(r)
vr_csr.Register(r)
vr_ftosv.Register(r)
vr_n9kv.Register(r)
vr_nxos.Register(r)
vr_pan.Register(r)
vr_ros.Register(r)
vr_sros.Register(r)
vr_veos.Register(r)
vr_vmx.Register(r)
vr_vsrx.Register(r)
vr_vqfx.Register(r)
vr_xrv.Register(r)
vr_xrv9k.Register(r)
xrd.Register(r)
rare.Register(r)
c8000.Register(r)
border0.Register(r)
}
47 changes: 22 additions & 25 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,12 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/nodes"
"github.com/srl-labs/containerlab/types"
"gopkg.in/yaml.v2"
)

var interfaceFormat = map[string]string{
"srl": "e1-%d",
"ceos": "eth%d",
"crpd": "eth%d",
"sonic-vs": "eth%d",
"linux": "eth%d",
"bridge": "veth%d",
"vr-sros": "eth%d",
"vr-vmx": "eth%d",
"vr-vsrx": "eth%d",
"vr-vqfx": "eth%d",
"vr-xrv9k": "eth%d",
"vr-veos": "eth%d",
"xrd": "eth%d",
"rare": "eth%d",
}

var supportedKinds = []string{
"srl", "ceos", "linux", "bridge", "sonic-vs", "crpd", "vr-sros",
"vr-vmx", "vr-vsrx", "vr-vqfx", "vr-xrv9k", "vr-veos", "xrd", "rare",
}

const (
defaultSRLType = "ixrd2"
defaultNodePrefix = "node"
defaultGroupPrefix = "tier"
)
Expand All @@ -61,6 +39,7 @@ var (
groupPrefix string
file string
deploy bool
reg *nodes.NodeRegistry
)

type nodesDef struct {
Expand Down Expand Up @@ -128,6 +107,21 @@ var generateCmd = &cobra.Command{
}

func init() {
// init a new NodeRegistry
reg = nodes.NewNodeRegistry()
// register all nodes
clab.RegisterNodes(reg)

generateNodesAttributes := reg.GetGenerateNodeAttributes()
supportedKinds := []string{}

// prepare list of generateable node kinds
for k, v := range generateNodesAttributes {
if v.IsGenerateable() {
supportedKinds = append(supportedKinds, k)
}
}

rootCmd.AddCommand(generateCmd)
generateCmd.Flags().StringVarP(&mgmtNetName, "network", "", "", "management network name")
generateCmd.Flags().IPNetVarP(&mgmtIPv4Subnet, "ipv4-subnet", "4", net.IPNet{}, "management network IPv4 subnet range")
Expand Down Expand Up @@ -191,6 +185,9 @@ func generateTopologyConfig(name, network, ipv4range, ipv6range string,
}
}
}

generateNodesAttributes := reg.GetGenerateNodeAttributes()

for i := 0; i < numStages-1; i++ {
interfaceOffset := uint(0)
if i > 0 {
Expand All @@ -216,8 +213,8 @@ func generateTopologyConfig(name, network, ipv4range, ipv6range string,
}
config.Topology.Links = append(config.Topology.Links, &types.LinkConfig{
Endpoints: []string{
node1 + ":" + fmt.Sprintf(interfaceFormat[nodes[i].kind], k+1+interfaceOffset),
node2 + ":" + fmt.Sprintf(interfaceFormat[nodes[i+1].kind], j+1),
node1 + ":" + fmt.Sprintf(generateNodesAttributes[nodes[i].kind].GetInterfaceFormat(), k+1+interfaceOffset),
node2 + ":" + fmt.Sprintf(generateNodesAttributes[nodes[i+1].kind].GetInterfaceFormat(), j+1),
},
})
}
Expand Down
9 changes: 8 additions & 1 deletion nodes/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ var kindnames = []string{"bridge"}
const (
iptCheckCmd = "-vL FORWARD -w 5"
iptAllowCmd = "-I FORWARD -i %s -j ACCEPT -w 5"

generateable = true
generateIfFornamt = "eth%d"
)

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {

generateNodeAttributes := nodes.NewGenerateNodeAttributes(generateable, generateIfFornamt)
nrea := nodes.NewNodeRegistryEntryAttributes(nil, generateNodeAttributes)

r.Register(kindnames, func() nodes.Node {
return new(bridge)
}, nil)
}, nrea)
}

type bridge struct {
Expand Down
3 changes: 2 additions & 1 deletion nodes/c8000/c8000.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const (

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {
nrea := nodes.NewNodeRegistryEntryAttributes(defaultCredentials, nil)
r.Register(kindnames, func() nodes.Node {
return new(c8000)
}, defaultCredentials)
}, nrea)
}

type c8000 struct {
Expand Down
8 changes: 7 additions & 1 deletion nodes/ceos/ceos.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

const (
ifWaitScriptContainerPath = "/mnt/flash/if-wait.sh"
generateable = true
generateIfFornamt = "eth%d"
)

var (
Expand All @@ -50,9 +52,13 @@ var (

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {

generateNodeAttributes := nodes.NewGenerateNodeAttributes(generateable, generateIfFornamt)
nrea := nodes.NewNodeRegistryEntryAttributes(nil, generateNodeAttributes)

r.Register(kindnames, func() nodes.Node {
return new(ceos)
}, nil)
}, nrea)
}

type ceos struct {
Expand Down
3 changes: 2 additions & 1 deletion nodes/checkpoint_cloudguard/checkpoint_cloudguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ var (

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {
nrea := nodes.NewNodeRegistryEntryAttributes(defaultCredentials, nil)
r.Register(kindnames, func() nodes.Node {
return new(CheckpointCloudguard)
}, defaultCredentials)
}, nrea)
}

type CheckpointCloudguard struct {
Expand Down
8 changes: 7 additions & 1 deletion nodes/crpd/crpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (

const (
licDir = "/config/license/safenet"

generateable = true
generateIfFornamt = "eth%d"
)

var (
Expand All @@ -38,9 +41,12 @@ var (

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {
generateNodeAttributes := nodes.NewGenerateNodeAttributes(generateable, generateIfFornamt)
nrea := nodes.NewNodeRegistryEntryAttributes(defaultCredentials, generateNodeAttributes)

r.Register(kindnames, func() nodes.Node {
return new(crpd)
}, defaultCredentials)
}, nrea)
}

type crpd struct {
Expand Down
8 changes: 7 additions & 1 deletion nodes/ipinfusion_ocnos/ipinfusion_ocnos.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ var (

const (
scrapliPlatformName = "ipinfusion_ocnos"
generateable = false
generateIfFornamt = ""
)

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {

generateNodeAttributes := nodes.NewGenerateNodeAttributes(generateable, generateIfFornamt)
nrea := nodes.NewNodeRegistryEntryAttributes(defaultCredentials, generateNodeAttributes)

r.Register(kindnames, func() nodes.Node {
return new(IPInfusionOcNOS)
}, defaultCredentials)
}, nrea)
}

type IPInfusionOcNOS struct {
Expand Down
10 changes: 9 additions & 1 deletion nodes/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ import (
"github.com/weaveworks/ignite/pkg/operations"
)

const (
generateable = true
generateIfFornamt = "eth%d"
)

var kindnames = []string{"linux"}

// Register registers the node in the NodeRegistry.
func Register(r *nodes.NodeRegistry) {
generateNodeAttributes := nodes.NewGenerateNodeAttributes(generateable, generateIfFornamt)
nrea := nodes.NewNodeRegistryEntryAttributes(nil, generateNodeAttributes)

r.Register(kindnames, func() nodes.Node {
return new(linux)
}, nil)
}, nrea)
}

type linux struct {
Expand Down
Loading

0 comments on commit 88ed50d

Please sign in to comment.