Skip to content

Commit

Permalink
Merge pull request #379 from srl-labs/attach-to-mgmt
Browse files Browse the repository at this point in the history
allow additional attachments to mgmt network
  • Loading branch information
hellt authored Apr 12, 2021
2 parents 0beed7e + 1cd4bf3 commit ae56d53
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
15 changes: 12 additions & 3 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type Config struct {
// it is provided via docker network object
type mgmtNet struct {
Network string `yaml:"network,omitempty"` // docker network name
Bridge string // linux bridge backing the docker network
IPv4Subnet string `yaml:"ipv4_subnet,omitempty"`
IPv6Subnet string `yaml:"ipv6_subnet,omitempty"`
MTU string `yaml:"mtu,omitempty"`
Expand Down Expand Up @@ -612,15 +613,23 @@ func (c *CLab) NewEndpoint(e string) *Endpoint {
nName := split[0] // node name
epName := split[1] // endpoint name
// search the node pointer for a node name referenced in endpoint section
// if node name is not "host", since "host" is a special reference to host namespace
switch nName {
// "host" is a special reference to host namespace
// for which we create an special Node with kind "host"
if nName == "host" {
case "host":
endpoint.Node = &Node{
Kind: "host",
ShortName: "host",
NSPath: hostNSPath,
}
} else {
// mgmt-net is a special reference to a bridge of the docker network
// that is used as the management network
case "mgmt-net":
endpoint.Node = &Node{
Kind: "bridge",
ShortName: "mgmt-net",
}
default:
for name, n := range c.Nodes {
if name == split[0] {
endpoint.Node = n
Expand Down
1 change: 1 addition & 0 deletions clab/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (c *CLab) CreateDockerNet(ctx context.Context) (err error) {
default:
return err
}
c.Config.Mgmt.Bridge = bridgeName

log.Debugf("Docker network '%s', bridge name '%s'", c.Config.Mgmt.Network, bridgeName)

Expand Down
15 changes: 13 additions & 2 deletions clab/netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,23 @@ func (c *CLab) CreateVirtualWiring(l *Link) (err error) {
// set bridge name for endpoint that should be connect to linux bridge
switch {
case l.A.Node.Kind == "bridge":
vA.Bridge = l.A.Node.ShortName

// mgmt-net is a reserved node name that means
// connect this endpoint to docker management bridged network
if l.A.Node.ShortName != "mgmt-net" {
vA.Bridge = l.A.Node.ShortName
} else {
vA.Bridge = c.Config.Mgmt.Bridge
}
// veth endpoint destined to connect to the bridge in the host netns
// will not have a random name
ARndmName = l.A.EndpointName
case l.B.Node.Kind == "bridge":
vB.Bridge = l.B.Node.ShortName
if l.B.Node.ShortName != "mgmt-net" {
vB.Bridge = l.A.Node.ShortName
} else {
vB.Bridge = c.Config.Mgmt.Bridge
}
BRndmName = l.B.EndpointName
case l.A.Node.Kind == "ovs-bridge":
vA.OvsBridge = l.A.Node.ShortName
Expand Down
32 changes: 31 additions & 1 deletion docs/manual/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,34 @@ ip link
# SNIP
433: srl_e1-1@if434: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether b2:80:e9:60:c7:9d brd ff:ff:ff:ff:ff:ff link-netns clab-srl01-srl
```
```

### Additional connections to management network
By default every lab node will be connected to the docker network named `clab` which acts as a management network for the nodes.

In addition to that mandatory connection, users can attach additional interfaces to this management network. This might be needed, for example, when data interface of a node needs to talk to the nodes on the management network.

For such connections a special form of endpoint definition was created - `mgmt-net:$iface-name`.

```yaml
name: mgmt
topology:
nodes:
n1:
kind: srl
image: srlinux:21.3.1-410
license: license.key
links:
- endpoints:
- "n1:e1-1"
- "mgmt-net:n1-e1-1"
```

In the above example the node `n1` connects with its `e1-1` interface to the management network. This is done by specifying the endpoint with a reserved name `mgmt-net` and defining the name of the interface that should be used in that bridge (`nq-e1-1`).

By specifying `mgmt-net` name of the node in the endpoint definition we tell containerlab to find out which bridge is used by the management network of our lab and use this bridge as the attachment point for our veth pair.

This is best illustrated with the following diagram:

<div class="mxgraph" style="max-width:100%;border:1px solid transparent;margin:0 auto; display:block;" data-mxgraph="{&quot;page&quot;:14,&quot;zoom&quot;:1.5,&quot;highlight&quot;:&quot;#0000ff&quot;,&quot;nav&quot;:true,&quot;check-visible-state&quot;:true,&quot;resize&quot;:true,&quot;url&quot;:&quot;https://raw.githubusercontent.com/srl-labs/containerlab/diagrams/containerlab.drawio&quot;}"></div>

0 comments on commit ae56d53

Please sign in to comment.