[stordis-toc]
Introduction
ContainerLab is an open-source tool that starts network labs from a simple YAML file. It starts the devices (routers, switches) as containers and connects them with virtual links.
This guide shows how to make a ContainerLab image from the SONiC Virtual Switch (SONiC VS) image with vrnetlab, and how to start a lab with three SONiC switches.
Prerequisites
| Item | Requirement |
|---|---|
| Operating system | Linux (Ubuntu 22.04/24.04 or Debian recommended), or Windows with WSL2 |
| CPU | 4 cores or more, with hardware virtualization (KVM). Each SONiC VS node is a VM in a container. |
| RAM | 8 GB minimum, 16 GB or more for more SONiC nodes |
| Disk | 60 GB free or more |
| Access | sudo rights |
Step 1: Install ContainerLab and Docker
- Update the package list:
sudo apt update
- Install ContainerLab. The option
allalso installs Docker:
curl -sL https://containerlab.dev/setup | sudo -E bash -s "all"
- Make sure that ContainerLab operates:
clab version
clab is a short name for containerlab.
Step 2: Download the SONiC VS image
Download the pre-built community image sonic-vs.img.gz. Refer to Where to download the SONiC Virtual Switch (VS) community pre-built image?
Step 3: Make the ContainerLab image with vrnetlab
- Clone the
vrnetlabrepository. It contains the tools to run VM-based network operating systems in ContainerLab:
sudo apt install -y git git clone https://github.com/srl-labs/vrnetlab.git cd vrnetlab/sonic
- Extract the image from Step 2:
gunzip sonic-vs.img.gz
- Copy the image into the directory
vrnetlab/sonic. The file name must besonic-vs-<name>.qcow2. The<name>becomes the tag of the Docker image:
cp sonic-vs.img ~/vrnetlab/sonic/sonic-vs-community.qcow2
- In the directory
vrnetlab/sonic, make the Docker image:
cd ~/vrnetlab/sonic sudo make
- Make sure that the image exists. The name is
vrnetlab/sonic_sonic-vsand the tag iscommunity:
docker images | grep sonic
Topology generator
Select the number of switches and the link layout. The generator makes the topology file for Step 4. The generator operates only in your browser.
The topology generator needs JavaScript. Use the example file in Step 4.
Step 4: Create the topology file
- Create a directory for your labs:
mkdir -p ~/labs && cd ~/labs
- Create the file
sonic-lab.clab.yaml(for example withnano sonic-lab.clab.yaml) and paste this example: three switches in a ring. Or use the file from the generator above.
name: sonic-lab
mgmt:
network: sonic-lab-mgmt
ipv4-subnet: 172.20.20.0/24
topology:
nodes:
sw1:
kind: sonic-vm
image: vrnetlab/sonic_sonic-vs:community
sw2:
kind: sonic-vm
image: vrnetlab/sonic_sonic-vs:community
sw3:
kind: sonic-vm
image: vrnetlab/sonic_sonic-vs:community
links:
- endpoints: ["sw1:eth1", "sw2:eth1"]
- endpoints: ["sw2:eth2", "sw3:eth1"]
- endpoints: ["sw3:eth2", "sw1:eth2"]NOTE
YAML uses spaces for the structure. Do not use tabs, and keep the indentation as in the example. The management subnet must not be used in your network.
In the sonic-vm kind, eth1 is Ethernet0 on the switch, eth2 is Ethernet4, eth3 is Ethernet8, and so on. eth0 is the management interface.
Step 5: Deploy the lab
sudo clab deploy -t sonic-lab.clab.yaml
The start of the SONiC VMs can take some minutes.
Step 6: Connect to the switches
- Show the nodes and their management addresses:
sudo clab inspect -t sonic-lab.clab.yaml
- Connect to a switch with SSH. The name is
clab-<lab name>-<node>:
ssh admin@clab-sonic-lab-sw1
The default user is admin with the password admin.
Step 7: Show the topology graph
sudo clab graph -t sonic-lab.clab.yaml
In a web browser, open http://127.0.0.1:50080.
You can also use VS Code or VSCodium with the ContainerLab extension. It shows and visualizes all labs.
Step 8: Stop and remove the lab
sudo clab destroy -t sonic-lab.clab.yaml
Troubleshooting
Make sure that the indentation uses spaces, as in Step 4. Use the topology generator to make a correct file.
The image in the YAML file must be the same as in docker images, also the tag (Step 3).
Make sure that KVM is available (ls /dev/kvm) and show the log of the node:
sudo docker logs -f clab-sonic-lab-sw1
Procedure completion
Congratulations!
You have successfully deployed a SONiC lab in ContainerLab. Now you can simulate, test and validate network configurations quickly.
Happy networking!
Useful links:
Where to download the SONiC Virtual Switch (VS) community pre-built image?
How to build the community version of SONiC Virtual Switch (SONiC VS) image?
For more free resources, visit: https://stordis.com/free-resources/
Comments 0
Comments
Please sign in to leave a comment.