From ef0885b4e9cf236f72b68a6b9b339567007ec800 Mon Sep 17 00:00:00 2001 From: henderiw Date: Wed, 9 Sep 2020 15:46:35 +0200 Subject: [PATCH] link-labeling added labeling to links in the config file for the links such that later on the configuration can become easier --- clab/config.go | 51 ++++++++++++++++++++++++++++++--------- lab-examples/wan-topo.yml | 8 +++++- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/clab/config.go b/clab/config.go index 9c0e58767..c4963cfbe 100644 --- a/clab/config.go +++ b/clab/config.go @@ -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"` @@ -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"` } @@ -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 @@ -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 } @@ -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", @@ -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, ", ")) @@ -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 { diff --git a/lab-examples/wan-topo.yml b/lab-examples/wan-topo.yml index db6100e29..0a9c41261 100644 --- a/lab-examples/wan-topo.yml +++ b/lab-examples/wan-topo.yml @@ -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"] @@ -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"] \ No newline at end of file + labels: ["kind": "lan", "type": "irb", "vlan": "10"] + - endpoints: ["client4:eth1", "wan4:e1-6"] + labels: ["kind": "lan", "type": "irb", "vlan": "10"] \ No newline at end of file