How to run SONiC VS in ContainerLab?

STORDIS-containerlab-sonic-banner-3200x1200.png

[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

  1. Update the package list:
sudo apt update
  1. Install ContainerLab. The option all also installs Docker:
curl -sL https://containerlab.dev/setup | sudo -E bash -s "all"
  1. Make sure that ContainerLab operates:
clab version

Output of 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

  1. Clone the vrnetlab repository. 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
  1. Extract the image from Step 2:
gunzip sonic-vs.img.gz
  1. Copy the image into the directory vrnetlab/sonic. The file name must be sonic-vs-<name>.qcow2. The <name> becomes the tag of the Docker image:
cp sonic-vs.img ~/vrnetlab/sonic/sonic-vs-community.qcow2
  1. In the directory vrnetlab/sonic, make the Docker image:
cd ~/vrnetlab/sonic
sudo make
  1. Make sure that the image exists. The name is vrnetlab/sonic_sonic-vs and the tag is community:
docker images | grep sonic

Output of docker images with the vrnetlab SONiC image


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

  1. Create a directory for your labs:
mkdir -p ~/labs && cd ~/labs
  1. Create the file sonic-lab.clab.yaml (for example with nano 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

  1. Show the nodes and their management addresses:
sudo clab inspect -t sonic-lab.clab.yaml
  1. 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.

Topology graph of the lab in a web browser

You can also use VS Code or VSCodium with the ContainerLab extension. It shows and visualizes all labs.

ContainerLab extension in VS Code with the lab topology


Step 8: Stop and remove the lab

sudo clab destroy -t sonic-lab.clab.yaml

Troubleshooting

Error when ContainerLab reads the YAML file

Make sure that the indentation uses spaces, as in Step 4. Use the topology generator to make a correct file.

The image is not found

The image in the YAML file must be the same as in docker images, also the tag (Step 3).

A node does not start

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?

ContainerLab documentation

 

For more free resources, visit: https://stordis.com/free-resources/

Comments 0

Articles in this section