Skip to content

Commit

Permalink
Merge pull request #2 from srl-wim/dut-map
Browse files Browse the repository at this point in the history
dut-config to map
  • Loading branch information
henderiw committed Aug 31, 2020
2 parents 7efc786 + 2bfb366 commit 5cedcbe
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 102 deletions.
Binary file modified bin/containerlab
Binary file not shown.
16 changes: 13 additions & 3 deletions labs/arista-topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions labs/fabric-topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 32 additions & 8 deletions labs/wan-topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
123 changes: 44 additions & 79 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions src/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5cedcbe

Please sign in to comment.