Skip to content

Commit

Permalink
Merge branch 'master' of github.com:srl-labs/containerlab
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Apr 23, 2021
2 parents c3c5bec + cf6d53d commit 36efc0f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
27 changes: 25 additions & 2 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (c *CLab) NewEndpoint(e string) *Endpoint {
// split the string to get node name and endpoint name
split := strings.Split(e, ":")
if len(split) != 2 {
log.Fatalf("endpoint %s has wrong syntax", e)
log.Fatalf("endpoint %s has wrong syntax", e) // skipcq: GO-S0904
}
nName := split[0] // node name
epName := split[1] // endpoint name
Expand Down Expand Up @@ -641,7 +641,7 @@ func (c *CLab) NewEndpoint(e string) *Endpoint {
// stop the deployment if the matching node element was not found
// "host" node name is an exception, it may exist without a matching node
if endpoint.Node == nil {
log.Fatalf("Not all nodes are specified in the 'topology.nodes' section or the names don't match in the 'links.endpoints' section: %s", nName)
log.Fatalf("Not all nodes are specified in the 'topology.nodes' section or the names don't match in the 'links.endpoints' section: %s", nName) // skipcq: GO-S0904
}

// initialize the endpoint name based on the split function
Expand All @@ -660,6 +660,9 @@ func (c *CLab) CheckTopologyDefinition(ctx context.Context) error {
if err := c.verifyLinks(); err != nil {
return err
}
if err := c.verifyRootNetnsInterfaceUniqueness(); err != nil {
return err
}
if err := c.VerifyContainersUniqueness(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -790,6 +793,26 @@ func (c *CLab) verifyHostIfaces() error {
return nil
}

// verifyRootNetnsInterfaceUniqueness ensures that interafaces that appear in the root ns (bridge, ovs-bridge and host)
// are uniquely defined in the topology file
func (c *CLab) verifyRootNetnsInterfaceUniqueness() error {
rootNsIfaces := map[string]struct{}{}
for _, l := range c.Links {
endpoints := [2]*Endpoint{l.A, l.B}
for _, e := range endpoints {
if e.Node.Kind == "bridge" || e.Node.Kind == "ovs-bridge" || e.Node.Kind == "host" {
if _, ok := rootNsIfaces[e.EndpointName]; ok {
return fmt.Errorf(`interface %s defined for node %s has already been used in other bridges, ovs-bridges or host interfaces.
Make sure that nodes of these kinds use unique interface names`, e.EndpointName, e.Node.ShortName)
} else {
rootNsIfaces[e.EndpointName] = struct{}{}
}
}
}
}
return nil
}

// verifyVirtSupport checks if virtualization supported by vcpu if vrnetlab nodes are used
func (c *CLab) verifyVirtSupport() error {
virtNeeded := false
Expand Down
19 changes: 19 additions & 0 deletions clab/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,22 @@ func TestLablesInit(t *testing.T) {
})
}
}

func TestVerifyRootNetnsInterfaceUniqueness(t *testing.T) {

opts := []ClabOption{
WithTopoFile("test_data/topo7-dup-rootnetns.yml"),
}
c := NewContainerLab(opts...)

if err := c.ParseTopology(); err != nil {
t.Fatal(err)
}

err := c.verifyRootNetnsInterfaceUniqueness()
if err == nil {
t.Fatalf("expected duplicate rootns links error")
}
t.Logf("error: %v", err)

}
11 changes: 11 additions & 0 deletions clab/test_data/topo7-dup-rootnetns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: topo7

topology:
nodes:
br1:
kind: bridge
br2:
kind: bridge

links:
- endpoints: ["br1:eth1", "br2:eth1"]

0 comments on commit 36efc0f

Please sign in to comment.