diff --git a/bin/containerlab b/bin/containerlab index dbd32fc21..dfd93506f 100755 Binary files a/bin/containerlab and b/bin/containerlab differ diff --git a/labs/arista-topo.yml b/labs/arista-topo.yml index bdc10ee72..ddcdfa851 100644 --- a/labs/arista-topo.yml +++ b/labs/arista-topo.yml @@ -14,9 +14,19 @@ CEOS_image: ceosimage64:4.24.2.1F CEOS_config: "" Duts: - wan1: ["srl", "bb", "ixr6", "srl_config/config.json"] - wan2: ["srl", "bb", "ixr6", "srl_config/config.json"] - wan3: ["ceos", "bb", "", ""] + wan1: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" + wan2: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" + wan3: + kind: "ceos" + group: "bb" Links: diff --git a/labs/fabric-topo.yml b/labs/fabric-topo.yml index bacb1e042..849f380e5 100644 --- a/labs/fabric-topo.yml +++ b/labs/fabric-topo.yml @@ -10,8 +10,16 @@ SRL_license: srl_config/license.key Client_image: henderiw/client-alpine:1.0.0 Duts: - wan1: ["srl", "bb", "ixr6", "srl_config/config.json"] - wan2: ["srl", "bb", "ixr6", "srl_config/config.json"] + wan1: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" + wan2: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" Links: diff --git a/labs/wan-topo.yml b/labs/wan-topo.yml index 6768fcae6..590a71d26 100644 --- a/labs/wan-topo.yml +++ b/labs/wan-topo.yml @@ -10,14 +10,38 @@ SRL_license: srl_config/license.key Client_image: henderiw/client-alpine:1.0.0 Duts: - wan1: ["srl", "bb", "ixr6", "srl_config/config.json"] - wan2: ["srl", "bb", "ixr6", "srl_config/config.json"] - wan3: ["srl", "pop1", "ixr6", "srl_config/config.json"] - wan4: ["srl", "pop2", "ixr6", "srl_config/config.json"] - client1: ["alpine", "pop1"] - client2: ["alpine", "pop1"] - client3: ["alpine", "pop2"] - client4: ["alpine", "pop2"] + wan1: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" + wan2: + kind: "srl" + group: "bb" + type: "ixr6" + config: "srl_config/config.json" + wan3: + kind: "srl" + group: "pop1" + type: "ixr6" + config: "srl_config/config.json" + wan4: + kind: "srl" + group: "pop2" + type: "ixr6" + config: "srl_config/config.json" + client1: + kind: "alpine" + group: "pop1" + client2: + kind: "alpine" + group: "pop1" + client3: + kind: "alpine" + group: "pop2" + client4: + kind: "alpine" + group: "pop2" Links: - endpoints: ["wan1:e1-1", "wan2:e1-1"] diff --git a/src/config.go b/src/config.go index c3299d5cc..cb93ffdda 100644 --- a/src/config.go +++ b/src/config.go @@ -18,16 +18,23 @@ type dockerInfo struct { Ipv6Gateway string `yaml:"ipv6_gateway"` } +type dutInfo struct { + Kind string `yaml:"kind"` + Group string `yaml:"group"` + Type string `yaml:"type"` + Config string `yaml:"config"` +} + type conf struct { - Prefix string `yaml:"Prefix"` - DockerInfo dockerInfo `yaml:"Docker_info"` - ClientImage string `yaml:"Client_image"` - SRLImage string `yaml:"SRL_image"` - SRLConfig string `yaml:"SRL_config"` - SRLLicense string `yaml:"SRL_license"` - CEOSImage string `yaml:"CEOS_image"` - CEOSConfig string `yaml:"CEOS_config"` - Duts map[string][]string `yaml:"Duts"` + Prefix string `yaml:"Prefix"` + DockerInfo dockerInfo `yaml:"Docker_info"` + ClientImage string `yaml:"Client_image"` + SRLImage string `yaml:"SRL_image"` + SRLConfig string `yaml:"SRL_config"` + SRLLicense string `yaml:"SRL_license"` + CEOSImage string `yaml:"CEOS_image"` + CEOSConfig string `yaml:"CEOS_config"` + Duts map[string]dutInfo `yaml:"Duts"` Links []struct { Endpoints []string `yaml:"endpoints"` } `yaml:"Links"` @@ -158,13 +165,13 @@ func parseTopology(t *conf) error { } // NewNode initializes a new node object -func NewNode(t *conf, dutName string, data []string, idx int) *Node { +func NewNode(t *conf, dutName string, dut dutInfo, idx int) *Node { // initialize a new node node := new(Node) node.Name = dutName node.Index = idx // normalize the data to lower case to compare - node.OS = strings.ToLower(data[0]) + node.OS = strings.ToLower(dut.Kind) switch node.OS { case "ceos": // initialize the global parameters with defaults, can be overwritten later @@ -184,25 +191,10 @@ func NewNode(t *conf, dutName string, data []string, idx int) *Node { "SKIP_ZEROTOUCH_BARRIER_IN_SYSDBINIT=1", "INTFTYPE=eth"} node.User = "root" - for i, d := range data { - switch i { - case 1: - // 2nd element in the string slice, should be the node group - if d != "" { - node.Group = d - } - case 2: - // 3rd element in the string slice, should be the node type - node.NodeType = d - case 3: - // 4th element in the string slice, should be config - // if there is a more specific config override the global config - if d != "" { - node.Config = d - } - default: - } - } + node.Group = dut.Group + node.NodeType = dut.Type + node.Config = dut.Config + node.Sysctls = make(map[string]string) node.Sysctls["net.ipv4.ip_forward"] = "0" node.Sysctls["net.ipv6.conf.all.disable_ipv6"] = "0" @@ -223,39 +215,23 @@ func NewNode(t *conf, dutName string, data []string, idx int) *Node { node.Env = []string{"SRLINUX=1"} node.User = "root" - for i, d := range data { - switch i { - case 1: - // 2nd element in the string slice, should be the node group - if d != "" { - node.Group = d - } - case 2: - // 3rd element in the string slice, should be the node type - node.NodeType = d - switch node.NodeType { - case "ixr6": - node.Topology = "srl_config/templates/topology-7250IXR6.yml" - case "ixr10": - node.Topology = "srl_config/templates/topology-7250IXR10.yml" - case "ixrd1": - node.Topology = "srl_config/templates/topology-7220IXD1.yml" - case "isrd2": - node.Topology = "srl_config/templates/topology-7220IXD2.yml" - case "ixrd3": - node.Topology = "srl_config/templates/topology-7220IXD3.yml" - default: - log.Error("wrong node type; should be ixr6, ixr10, ixrd1, ixrd2, ixrd3") - os.Exit(1) - } - case 3: - // 4th element in the string slice, should be config - // if there is a more specific config override the global config - if d != "" { - node.Config = d - } - default: - } + node.Group = dut.Group + node.NodeType = dut.Type + node.Config = dut.Config + + switch node.NodeType { + case "ixr6": + node.Topology = "srl_config/templates/topology-7250IXR6.yml" + case "ixr10": + node.Topology = "srl_config/templates/topology-7250IXR10.yml" + case "ixrd1": + node.Topology = "srl_config/templates/topology-7220IXD1.yml" + case "isrd2": + node.Topology = "srl_config/templates/topology-7220IXD2.yml" + case "ixrd3": + node.Topology = "srl_config/templates/topology-7220IXD3.yml" + default: + panic("wrong node type; should be ixr6, ixr10, ixrd1, ixrd2, ixrd3") } node.Sysctls = make(map[string]string) @@ -268,7 +244,7 @@ func NewNode(t *conf, dutName string, data []string, idx int) *Node { node.Mounts = make(map[string]volume) var v volume - labPath := Path + "/" + "lab" + "_" + Prefix + "/" + labPath := Path + "/" + "lab" + "-" + Prefix + "/" labDutPath := labPath + dutName + "/" v.Source = labPath + "license.key" v.Destination = "/opt/srlinux/etc/license.key" @@ -328,21 +304,10 @@ func NewNode(t *conf, dutName string, data []string, idx int) *Node { node.Image = t.ClientImage node.Cmd = "/bin/bash" - for i, d := range data { - switch i { - case 1: - // 2nd element in the string slice, should be group - // if there is a more specific config override the global config - if d != "" { - node.Group = d - } - case 2: - // 3rd element not used for now - case 3: - // 4th element not used for now - default: - } - } + node.Group = dut.Group + node.NodeType = dut.Type + node.Config = dut.Config + } return node } diff --git a/src/docker.go b/src/docker.go index 23ffe836d..a6c29a33c 100644 --- a/src/docker.go +++ b/src/docker.go @@ -82,9 +82,8 @@ func (d *Docker) createBridge() (err error) { if len(bridgeName) == 0 { if len(netCreateResponse.ID) < 12 { return fmt.Errorf("could not get bridge ID") - } else { - bridgeName = "br-" + netCreateResponse.ID[:12] } + bridgeName = "br-" + netCreateResponse.ID[:12] } log.Debugf("container network %s : bridge name: %s", DockerInfo.Bridge, bridgeName) log.Debug("Disable RPF check on the docker host part1") @@ -141,7 +140,7 @@ func (d *Docker) createContainer(name string, node *Node) (err error) { Sysctls: node.Sysctls, Privileged: true, NetworkMode: container.NetworkMode(DockerInfo.Bridge), - }, nil, "lab"+"_"+Prefix+"_"+name) + }, nil, "lab"+"-"+Prefix+"-"+name) if err != nil { return err } @@ -212,7 +211,7 @@ func (d *Docker) deleteContainer(name string, node *Node) (err error) { for _, container := range containers { for _, n := range container.Names { - if strings.Contains(n, "lab"+"_"+Prefix+"_"+name) { + if strings.Contains(n, "lab"+"-"+Prefix+"-"+name) { cid = container.ID break } diff --git a/src/file.go b/src/file.go index e4e94c96c..7ca9f0714 100644 --- a/src/file.go +++ b/src/file.go @@ -176,7 +176,7 @@ func createDirectory(path string, perm os.FileMode) { func createNodeDirStructure(node *Node, dut string) (err error) { // create lab directory - path := Path + "/" + "lab" + "_" + Prefix + path := Path + "/" + "lab" + "-" + Prefix switch node.OS { case "srl": diff --git a/src/main.go b/src/main.go index 87ad57df4..eabe78693 100644 --- a/src/main.go +++ b/src/main.go @@ -46,7 +46,7 @@ func main() { case "deploy": log.Info("Creating container lab: ", topo) // create lab directory - path := Path + "/" + "lab" + "_" + Prefix + path := Path + "/" + "lab" + "-" + Prefix createDirectory(path, 0755) log.Info("Creating docker bridge") diff --git a/src/netlink.go b/src/netlink.go index 12f3f4c6c..095a9d5bb 100644 --- a/src/netlink.go +++ b/src/netlink.go @@ -9,8 +9,8 @@ import ( func createVirtualWiring(id int, link *Link) (err error) { - nodeNameA := "lab" + "_" + Prefix + "_" + link.a.Node.Name - nodeNameB := "lab" + "_" + Prefix + "_" + link.b.Node.Name + nodeNameA := "lab" + "-" + Prefix + "-" + link.a.Node.Name + nodeNameB := "lab" + "-" + Prefix + "-" + link.b.Node.Name log.Debug("creating veth pair: ", nodeNameA, nodeNameB, link.a.EndpointName, link.b.EndpointName) createDirectory("/run/netns/", 0755) @@ -124,8 +124,8 @@ func createVirtualWiring(id int, link *Link) (err error) { func deleteVirtualWiring(id int, link *Link) (err error) { - nodeNameA := "lab" + "_" + Prefix + "_" + link.a.Node.Name - nodeNameB := "lab" + "_" + Prefix + "_" + link.b.Node.Name + nodeNameA := "lab" + "-" + Prefix + "-" + link.a.Node.Name + nodeNameB := "lab" + "-" + Prefix + "-" + link.b.Node.Name var cmd *exec.Cmd