Latest addition to network testing and simulation: Containerlab
In this article

Until recently all existing virtual lab solutions were based on vendor appliances provided as virtual machines. Such an approach allowed us to emulate closely the real HW (some of those appliances had virtualized data planes as well - e.g. vEX, vMX). However this is not always the desired case. Sometimes we just want to check routing, some protocol behavior or other control plane features implemented on vendor appliances (to see the difference between management, control and user plane see Management vs. Control vs. Data Planes in a Network Device). In such scenarios the VM approach can be overkill. It is heavy in terms of memory and CPU and ZTP features are lacking (some vendors do not support ZTP on virtual appliances). In such cases one can use containers instead of VMs. Let’s take a look at the latest addition to virtual lab software, Containerlab.
Installation prerequisites are pretty straightforward: Linux / Windows / MAC OS (x86) (Windows users will need to install WSL on their machines) with Docker preinstalled. All other dependencies are handled during installation. After that step, immediately there will be two major differences visible between VM-based projects and Containerlab:
- No UI - all configuration (appliances, connections) is handled by a simple YAML file - however this makes automation a breeze,
- Concentrated on containers - however VMs are still fully supported by launching them inside a container,
- ZTP - all supported vendors have ZTP supported natively. All you need to do is to reference the config file within the YAML formatted lab definition or mount them directly in the container.
Example usage
Let’s now look at an example on how one can use Containerlab to build a network topology. In the following sections we will show what a config YAML file looks like, how to choose and prepare images (FRR in our example), how to structure the files into correct directories, and how to deploy the lab. Finally we will check if everything works as expected.
Example topology
To show how easy it is to use the Containerlab project, let's create a simple topology with it like the one in the diagram below:
As a first step, we need to define the topology:
1# cat blog.clab.yml2name: blog34topology:5 nodes:6 frr1:7 kind: linux8 image: quay.io/frrouting/frr:9.1.09 binds:10 - config/frr1/daemons:/etc/frr/daemons11 - config/frr1/frr.conf:/etc/frr/frr.conf12 frr2:13 kind: linux14 image: quay.io/frrouting/frr:9.1.015 binds:16 - config/frr2/daemons:/etc/frr/daemons17 - config/frr2/frr.conf:/etc/frr/frr.conf18 PC1:19 kind: linux20 image: praqma/network-multitool:latest21 exec:22 - ip addr add 192.168.1.10/24 dev eth123 - ip route add 192.168.0.0/16 via 192.168.1.124 - ip route add 10.0.0.0/8 via 192.168.1.125 PC2:26 kind: linux27 image: praqma/network-multitool:latest28 exec:29 - ip addr add 192.168.2.10/24 dev eth130 - ip route add 192.168.0.0/16 via 192.168.2.131 - ip route add 10.0.0.0/8 via 192.168.2.132 links:33 - endpoints: \["frr1:eth1", "frr2:eth1"]34 - endpoints: \["PC1:eth1", "frr1:eth2"]35 - endpoints: \["PC2:eth1", "frr2:eth2"]
Above we can see the definition of the nodes - we will use FRR container images as well as Linux to emulate the endpoints. As you can see, almost any Docker image can be used here. At the bottom there are links defined between FRRs and PCs (those are veth interfaces, so all communication is kept in the kernel, which is way faster than GNS3 or the EVE-NG approach). Each FRR comes with its own simple configuration:
FRR1
1# cat config/frr1/frr.conf2frr version 9.1_git3frr defaults traditional4hostname frr15no ipv6 forwarding6!7interface eth18ip address 10.10.1.1/309exit10!11interface eth212ip address 192.168.1.1/2413exit14!15interface lo16ip address 10.2.0.1/3217exit18!19router bgp 6500120no bgp ebgp-requires-policy21neighbor 10.10.1.2 remote-as 6500222!23address-family ipv4 unicast24 network 10.2.0.1/3225 network 192.168.1.0/2426exit-address-family27exit28!29end
FRR2
1# cat config/frr2/frr.conf2frr version 9.1_git3frr defaults traditional4hostname frr25no ipv6 forwarding6!7interface eth18ip address 10.10.1.2/309exit10!11interface eth212ip address 192.168.2.1/2413exit14!15interface lo16ip address 10.2.0.2/3217exit18!19router bgp 6500220no bgp ebgp-requires-policy21neighbor 10.10.1.1 remote-as 6500122!23address-family ipv4 unicast24 network 10.2.0.2/3225 network 192.168.2.0/2426exit-address-family27exit28!29end
FRR1 and FRR2
In the YAML file we are also referencing the config/frr1/daemons file (both FRRs use the same config here):
1# cat config/frr1/daemons2zebra=yes3bgpd=yes4ospfd=no5ospf6d=no6ripd=no7ripngd=no8isisd=no9pimd=no10ldpd=yes11nhrpd=no12eigrpd=no13babeld=no14sharpd=no15staticd=no16pbrd=no17bfdd=no18fabricd=no1920vtysh_enable=yes21zebra_options=" -s 90000000 --daemon -A 127.0.0.1"22bgpd_options=" --daemon -A 127.0.0.1"23ospfd_options=" --daemon -A 127.0.0.1"24ospf6d_options=" --daemon -A ::1"25ripd_options=" --daemon -A 127.0.0.1"26ripngd_options=" --daemon -A ::1"27isisd_options=" --daemon -A 127.0.0.1"28pimd_options=" --daemon -A 127.0.0.1"29ldpd_options=" --daemon -A 127.0.0.1"30nhrpd_options=" --daemon -A 127.0.0.1"31eigrpd_options=" --daemon -A 127.0.0.1"32babeld_options=" --daemon -A 127.0.0.1"33sharpd_options=" --daemon -A 127.0.0.1"34staticd_options=" --daemon -A 127.0.0.1"35pbrd_options=" --daemon -A 127.0.0.1"36bfdd_options=" --daemon -A 127.0.0.1"37fabricd_options=" --daemon -A 127.0.0.1"
With all of those files in place the directory and files structure should look like this:
1# tree2.3├── config4│ ├── frr15│ │ ├── daemons6│ │ └── frr.conf7│ └── frr28│ ├── daemons9│ └── frr.conf10└── blog.clab.yml11124 directories, 5 files
Now the last step - deploy the newly created topology. We need to execute a single command in the top level directory of our lab:
1# containerlab deploy2INFO[0000] Containerlab v0.48.4 started3INFO[0000] Parsing & checking topology file: sonic.clab.yml4INFO[0000] Creating docker network: Name="clab", IPv4Subnet="172.20.20.0/24", IPv6Subnet="2001:172:20:20::/64", MTU='ל'5INFO[0000] Creating lab directory: /[...]/clab-blog6INFO[0000] Creating container: "frr2"7INFO[0000] Creating container: "frr1"8INFO[0000] Creating container: "PC2"9INFO[0000] Creating container: "PC1"10INFO[0000] Creating link: PC2:eth1 frr2:eth211INFO[0000] Creating link: frr1:eth1 frr2:eth112INFO[0001] Creating link: PC1:eth1 frr1:eth213[...]
If everything went fine, we should now have a running lab that looks like this:
We can quickly verify if everything is working as intended. Let's check the BGP session between FRR1 and FRR2:
1# docker exec -it clab-blog-frr1 vtysh -c "show bgp summary"2\\\[...]3IPv4 Unicast Summary (VRF default):4BGP router identifier 10.2.0.1, local AS number 65001 vrf-id 05BGP table version 46RIB entries 7, using 672 bytes of memory7Peers 1, using 13 KiB of memory8910Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc 1110.10.1.2 4 65002 6 7 4 0 0 00:01:53 2 4 N/A1213Total number of neighbors 1
… so with the BGP session UP, communication between PC1 and PC2 should be possible:
1# docker exec -it clab-blog-PC1 ping -c 4 192.168.2.102PING 192.168.2.10 (192.168.2.10) 56(84) bytes of data.364 bytes from 192.168.2.10: icmp_seq=1 ttl=62 time=0.093 ms464 bytes from 192.168.2.10: icmp_seq=2 ttl=62 time=0.087 ms564 bytes from 192.168.2.10: icmp_seq=3 ttl=62 time=0.123 ms664 bytes from 192.168.2.10: icmp_seq=4 ttl=62 time=0.086 ms78--- 192.168.2.10 ping statistics ---94 packets transmitted, 4 received, 0% packet loss, time 3046ms10rtt min/avg/max/mdev = 0.086/0.097/0.123/0.015 ms
And indeed this is the case.
The last thing left for us to check is memory consumption:
1# docker stats2CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS36c5a8721aded clab-blog-frr2 0.11% 25.47MiB / 30.58GiB 0.08% 7.12kB / 946B 0B / 28.7kB 2243430f475ad8a clab-blog-frr1 0.06% 36.83MiB / 30.58GiB 0.12% 7.61kB / 806B 26.1MB / 32.8kB 225f88b7a52e578 clab-blog-PC1 0.00% 5.176MiB / 30.58GiB 0.02% 6.83kB / 806B 7.45MB / 8.19kB 2608421fb9199d clab-blog-PC2 0.00% 4.695MiB / 30.58GiB 0.01% 6.83kB / 806B 6.73MB / 8.19kB 2
A single FRR container takes as little as 30MB on average. So with 32GB RAM we should be able to deploy at least 500 nodes without any issue. Of course the FRR is not a vendor-specific appliance but it’s a very mature solution that is being used in enterprise products such as Nvidia Cumulus or SONiC so it can be easily used to emulate large environments. Even more, Containerlab can be easily extended by adding support for new appliances. At Codilime, we were able to add support for SONiC VM images. For the impatient, one can use a Dockerized version of SONiC for which Containerlab has native support. However such images have their own limitations but that is a story for another blog entry.
Summary
In this article we aimed at introducing you to the latest addition of the network lab project’s family, called Containerlab. While each solution has its own application (for comparison of different solutions see our article about Virtual Labs), we believe that Containerlab is the best solution for large-scale environments or environments that have to be fully automated (in terms of deployment and configuration). An example of such an environment would be CI/CD for automatic inventory (e.g. to quickly spawn a topology subject to LLDP map autodiscovery) or a test environment for network automation software (to quickly test proposed changes in the configuration of network devices before they go into production). As one can see, the possibilities here are endless. We also encourage you to check how building network automation solutions can ensure rapid, low-risk, scalable, and cost-effective network management.





