Skip to content

Commit

Permalink
Merge pull request #709 from srl-labs/auto-if-enable
Browse files Browse the repository at this point in the history
auto enabled sr linux interfaces
  • Loading branch information
hellt committed Dec 2, 2021
2 parents aaa3e06 + f5b6e1d commit c9188a2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx
MgmtIPv6Address: nodeDef.GetMgmtIPv6(),
Publish: c.Config.Topology.GetNodePublish(nodeName),
Sysctls: make(map[string]string),
Endpoints: make([]*types.Endpoint, 0),
Endpoints: make([]types.Endpoint, 0),
Sandbox: c.Config.Topology.GetNodeSandbox(nodeName),
Kernel: c.Config.Topology.GetNodeKernel(nodeName),
Runtime: c.Config.Topology.GetNodeRuntime(nodeName),
Expand Down Expand Up @@ -342,7 +342,7 @@ func (c *CLab) NewEndpoint(e string) *types.Endpoint {
c.m.Lock()
if n, ok := c.Nodes[nName]; ok {
endpoint.Node = n.Config()
n.Config().Endpoints = append(n.Config().Endpoints, endpoint)
n.Config().Endpoints = append(n.Config().Endpoints, *endpoint)
}
c.m.Unlock()
}
Expand Down
8 changes: 8 additions & 0 deletions docs/manual/kinds/srl.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ By default, `ixrd2` type will be used by containerlab.
Based on the provided type, containerlab will generate the topology file that will be mounted to the SR Linux container and make it boot in a chosen HW variant.
### Node configuration
SR Linux uses a `/etc/opt/srlinux/config.json` file to persist its configuration. By default, containerlab starts nodes of `srl` kind with a basic "default" config, and with the `startup-config` parameter, it is possible to provide a custom config file that will be used as a startup one.

#### Default node configuration
When a node is defined without the `startup-config` statement present, containerlab will make [additional configurations](https://github.com/srl-labs/containerlab/blob/master/nodes/srl/srl.go#L38) on top of the factory config:

Expand All @@ -90,6 +91,13 @@ topology:

The generated config will be saved by the path `clab-<lab_name>/<node-name>/config/config.json`. Using the example topology presented above, the exact path to the config will be `clab-srl_lab/srl1/config/config.json`.

Additional configurations that containerlab adds on top of the factory config:

* enabling interfaces (`admin-state enable`) referenced in the topology's `links` section
* enabling LLDP
* enabling gNMI/JSON-RPC
* creating tls server certificate

#### User defined startup config
It is possible to make SR Linux nodes boot up with a user-defined config instead of a built-in one. With a [`startup-config`](../nodes.md#startup-config) property of the node/kind a user sets the path to the local config file that will be used as a startup config.

Expand Down
14 changes: 13 additions & 1 deletion nodes/srl/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"time"

"github.com/google/shlex"
"github.com/hairyhenderson/gomplate/v3"
"github.com/hairyhenderson/gomplate/v3/data"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -48,6 +50,14 @@ set / system json-rpc-server admin-state enable network-instance mgmt http admin
set / system json-rpc-server admin-state enable network-instance mgmt https admin-state enable tls-profile clab-profile
set / system lldp admin-state enable
set / system aaa authentication idle-timeout 7200
{{/* enabling interfaces referenced as endpoints for a node (both e1-2 and e1-3-1 notations) */}}
{{- range $ep := .Endpoints }}
{{- $parts := ($ep.EndpointName | strings.ReplaceAll "e" "" | strings.Split "-") -}}
set / interface ethernet-{{index $parts 0}}/{{index $parts 1}} admin-state enable
{{- if eq (len $parts) 3 }}
set / interface ethernet-{{index $parts 0}}/{{index $parts 1}}/{{index $parts 2}} admin-state enable
{{- end }}
{{ end -}}
commit save`
)

Expand Down Expand Up @@ -80,7 +90,9 @@ var (
mgmtServerRdyCmd, _ = shlex.Split("sr_cli -d info from state system app-management application mgmt_server state | grep running")
commitCompleteCmd, _ = shlex.Split("sr_cli -d info from state system configuration commit 1 status | grep complete")

srlCfgTpl, _ = template.New("srl-tls-profile").Parse(srlConfigCmdsTpl)
srlCfgTpl, _ = template.New("srl-tls-profile").
Funcs(gomplate.CreateFuncs(context.Background(), new(data.Data))).
Parse(srlConfigCmdsTpl)
)

func init() {
Expand Down
10 changes: 10 additions & 0 deletions tests/02-basic-srl/01-two-srls.robot
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ Verify links in node srl2
Should Be Equal As Integers ${rc} 0
Should Contain ${output} state UP

Verify e1-1 interface have been admin enabled on srl1
[Documentation]
... This test cases ensures that e1-1 interface referenced in links section
... has been automatically admin enabled
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab --runtime ${runtime} exec -t ${CURDIR}/${lab-file-name} --label clab-node-name\=srl1 --cmd "sr_cli 'show interface ethernet-1/1'"
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} ethernet-1/1 is up

Verify srl2 accepted user-provided CLI config
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab --runtime ${runtime} exec -t ${CURDIR}/${lab-file-name} --label clab-node-name\=srl2 --cmd "sr_cli 'info /system information location'"
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type NodeConfig struct {
// container labels
Labels map[string]string
// Slice of pointers to local endpoints
Endpoints []*Endpoint
Endpoints []Endpoint
// Ignite sandbox and kernel imageNames
Sandbox, Kernel string
// Configured container runtime
Expand Down

0 comments on commit c9188a2

Please sign in to comment.