Skip to content

Commit

Permalink
link-labeling
Browse files Browse the repository at this point in the history
added labeling to links in the config file for the links such that later on the configuration can become easier
  • Loading branch information
henderiw committed Sep 9, 2020
1 parent 54de8de commit ef0885b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
51 changes: 39 additions & 12 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ type dutInfo struct {
License string `yaml:"license"`
}

type link struct {
Endpoints []string `yaml:"endpoints"`
Labels []map[string]string `yaml:"labels,omitempty"`
}

// Conf holds the configuration file input
type Conf struct {
Prefix string `yaml:"Prefix"`
DockerInfo dockerInfo `yaml:"Docker_info"`
Expand All @@ -36,9 +42,7 @@ type Conf struct {
KindDefaults map[string]dutInfo `yaml:"kind_defaults"`
DutSpecifics map[string]dutInfo `yaml:"dut_specifics"`
} `yaml:"Duts"`
Links []struct {
Endpoints []string `yaml:"endpoints"`
} `yaml:"Links"`
Links []link `yaml:"Links"`
ConfigPath string `yaml:"config_path"`
}

Expand Down Expand Up @@ -87,8 +91,12 @@ type Node struct {

// Link is a struct that contains the information of a link between 2 containers
type Link struct {
A *Endpoint
B *Endpoint
A *Endpoint
B *Endpoint
Kind string
Type string
Vlan string
Labels []map[string]string
}

// Endpoint is a sttruct that contains information of a link endpoint
Expand Down Expand Up @@ -162,8 +170,8 @@ func (c *cLab) ParseTopology() error {
idx++
}
for i, l := range c.Conf.Links {
// i represnts the endpoint integer and l provide the lik struct
c.Links[i] = c.NewLink(l.Endpoints)
// i represnts the endpoint integer and l provide the link struct
c.Links[i] = c.NewLink(l)
}
return nil
}
Expand Down Expand Up @@ -217,7 +225,7 @@ func (c *cLab) NewNode(dutName string, dut dutInfo, idx int) *Node {
baseConfigDir := "/etc/containerlab/templates/srl/"

srlTypes := map[string]string{
"ixr6": "topology-7250IXR6.yml",
"ixr6": "topology-7250IXR6.yml",
"ixr10": "topology-7250IXR10.yml",
"ixrd1": "topology-7220IXRD1.yml",
"ixrd2": "topology-7220IXRD2.yml",
Expand Down Expand Up @@ -276,12 +284,11 @@ func (c *cLab) NewNode(dutName string, dut dutInfo, idx int) *Node {
node.Group = c.groupInitialization(&dut, node.Kind)
node.NodeType = c.typeInitialization(&dut, node.Kind)


if filename, found := srlTypes[node.NodeType]; found {
node.Topology = baseConfigDir + filename
} else {
keys := make([]string, 0, len(srlTypes))
for key, _ := range srlTypes {
for key := range srlTypes {
keys = append(keys, key)
}
panic("wrong node type; should be " + strings.Join(keys, ", "))
Expand Down Expand Up @@ -363,11 +370,31 @@ func (c *cLab) NewNode(dutName string, dut dutInfo, idx int) *Node {
}

// NewLink initializes a new link object
func (c *cLab) NewLink(e []string) *Link {
func (c *cLab) NewLink(l link) *Link {
// initialize a new link
link := new(Link)
link.Kind = "wan"
link.Type = "p2p"
link.Vlan = "0"

for _, label := range l.Labels {
// Kind is either a backbone facing or customer facing interface
// wan is customer facing, client
if _, exists := label["kind"]; exists {
link.Kind = label["kind"]
}
// Type is either a lag or a p2p link
if _, exists := label["type"]; exists {
link.Type = label["type"]
}
// Vlan is a string which is 0 for untagged and >0 for tagged
if _, exists := label["vlan"]; exists {
link.Vlan = label["vlan"]
}
}
link.Labels = l.Labels

for i, d := range e {
for i, d := range l.Endpoints {
// i indicates the number and d presents the string, which need to be
// split in node and endpoint name
if i == 0 {
Expand Down
8 changes: 7 additions & 1 deletion lab-examples/wan-topo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Duts:

Links:
- endpoints: ["wan1:e1-1", "wan2:e1-1"]
labels: ["kind": "wan", "type": "lag", "vlan": "0"]
- endpoints: ["wan1:e1-2", "wan2:e1-2"]
labels: ["kind": "wan", "type": "lag", "vlan": "0"]
- endpoints: ["wan1:e1-3", "wan2:e1-3"]
- endpoints: ["wan1:e1-4", "wan2:e1-4"]
- endpoints: ["wan3:e1-1", "wan1:e1-5"]
Expand All @@ -49,6 +51,10 @@ Links:
- endpoints: ["wan4:e1-3", "wan2:e1-7"]
- endpoints: ["wan4:e1-4", "wan2:e1-8"]
- endpoints: ["client1:eth1", "wan3:e1-5"]
labels: ["kind": "lan", "type": "irb", "vlan": "10"]
- endpoints: ["client2:eth1", "wan3:e1-6"]
labels: ["kind": "lan", "type": "irb", "vlan": "10"]
- endpoints: ["client3:eth1", "wan4:e1-5"]
- endpoints: ["client4:eth1", "wan4:e1-6"]
labels: ["kind": "lan", "type": "irb", "vlan": "10"]
- endpoints: ["client4:eth1", "wan4:e1-6"]
labels: ["kind": "lan", "type": "irb", "vlan": "10"]

0 comments on commit ef0885b

Please sign in to comment.