Building a Simple 2-Node Lab

In this tutorial, we’ll build a simple 2-node network running OSPF.

The easiest way to get started is to start a GitHub Codespace. It’s free but requires a valid GitHub account.

Alternatively, you could create a Ubuntu virtual machine on your laptop (Multipass seems to be the easiest way to get that done) and install netlab on it.

Whichever option you choose, I’m assuming you have it up and running and are facing a shell prompt.

Preparing the Network Device Container Images

We’ll use the FRRouting container from a public repository. It will be downloaded during lab startup. You can use the same approach for Nokia SR Linux or VyOS.

If you want to use the Arista cEOS container

Creating Lab Topology File

In an empty directory, create the lab topology file topology.yml.

---
provider: clab
defaults.device: frr
module: [ ospf ]

nodes: [ r1, r2 ]
links: [ r1, r2, r1-r2 ]

The networking lab specified in the above topology file:

  • Uses containerlab orchestration system with Docker containers.

  • Uses FRRouting containers as the default device

  • Uses OSPF as the routing protocol

  • Has two nodes (r1 and r2)

  • Has three links – a stub network connected to r1, another stub network connected to r2, and a link between r1 and r2.

To run the lab with other network devices, replace defaults.device value with:

Device

netlab device code

Arista cEOS

eos

Nokia SR Linux

srlinux

VyOS

vyos

Tip

Netlab supports numerous other network devices, but unfortunately, the vendors don’t make them available as pure containers, so running them in GitHub codespaces is impossible.

Starting the Lab

The easiest way to start the lab is to execute netlab up command which:

  • Creates clab.yml (containerlab configuration file), device configuration files, and Ansible inventory files;

  • Starts the devices with the containerlab deploy command

  • Configures the devices with netlab initial command.

Creating Configuration Files

netlab up executes netlab create to create:

  • containerlab configuration file

  • Device configuration snippets in the node_files directory

  • hosts.yml (Ansible inventory file)

  • host_vars directory (Ansible host variables)

  • group_vars directory (Ansible group variables)

  • ansible.cfg (Ansible configuration file).

Its printout looks similar to this one:

┌──────────────────────────────────────────────────────────────────────────────────┐
│ CREATING configuration files                                                     │
└──────────────────────────────────────────────────────────────────────────────────┘
[CONFIG]  r1: initial,ospf,hosts
[CONFIG]  r2: initial,ospf,hosts (shared)
Created provider configuration file: clab.yml
Created pickled transformed topology data into netlab.snapshot.pickle
Created group_vars for all
Created group_vars for modules
Created group_vars for frr
Created host_vars for r1, r2
Created minimized Ansible inventory hosts.yml
Created Ansible configuration file: ansible.cfg

Start the Virtual Devices

After creating the configuration files, netlab up creates the virtual networking infrastructure (if needed) and starts the lab with the containerlab deploy command:

┌──────────────────────────────────────────────────────────────────────────────────┐
│ STARTING clab nodes                                                              │
└──────────────────────────────────────────────────────────────────────────────────┘
[INFO]    Setting containerlab runtime to docker
provider clab: executing containerlab deploy --reconfigure -t clab.yml
06:29:16 INFO Containerlab started version=0.83.0
06:29:16 INFO Parsing & checking topology file=clab.yml
06:29:16 INFO Removing directory path=/home/pipi/net101/tools/X/clab-X
06:29:16 INFO Creating docker network name=netlab_mgmt IPv4 subnet=192.168.121.0/24 IPv6 subnet=fd00:df:1ab::/64 MTU=0
06:29:16 INFO Creating lab directory path=/home/pipi/net101/tools/X/clab-X
06:29:16 INFO Creating container name=r2
06:29:16 INFO Creating container name=r1
06:29:16 INFO Created link: r1:eth2 ▪┄┄▪ r2:eth2
06:29:17 INFO Executed command node=r2 command="sleep 1" stdout=""
06:29:17 INFO Executed command node=r1 command="sleep 1" stdout=""
06:29:17 INFO Adding host entries path=/etc/hosts
06:29:17 INFO Adding SSH config for nodes path=/etc/ssh/ssh_config.d/clab-X.conf
╭───────────┬──────────────────────────────┬─────────┬─────────────────╮
│    Name   │          Kind/Image          │  State  │  IPv4/6 Address │
├───────────┼──────────────────────────────┼─────────┼─────────────────┤
│ clab-X-r1 │ frr                          │ running │ 192.168.121.101 │
│           │ quay.io/frrouting/frr:10.7.1 │         │ fd00:df:1ab::2  │
├───────────┼──────────────────────────────┼─────────┼─────────────────┤
│ clab-X-r2 │ frr                          │ running │ 192.168.121.102 │
│           │ quay.io/frrouting/frr:10.7.1 │         │ fd00:df:1ab::3  │
╰───────────┴──────────────────────────────┴─────────┴─────────────────╯

containerlab creates the management network, the lab containers, and the links between them, and displays a table of lab containers with their management IP addresses.

Deploy Device Configurations

To configure the lab devices, netlab up runs netlab initial command, which uses a device-specific configuration deployment process. This is the printout you’d get when using FRRouting containers:

┌──────────────────────────────────────────────────────────────────────────────────┐
│ DEPLOYING initial device configurations                                          │
└──────────────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────────────┐
│ CONFIG Deploying device configurations                                           │
└──────────────────────────────────────────────────────────────────────────────────┘
[INFO]    Executing initial configuration for node r1
[INFO]    Executing initial configuration for node r2
[INFO]    Executing ospf configuration for node r2
[INFO]    Executing ospf configuration for node r1

Results of non-Ansible configuration deployments
====================================================================================================================================
r1               Script:   initial,ospf
r2               Script:   initial,ospf

The netlab up process should conclude with a [SUCCESS] Lab devices configured message.

Tip

If you want to start the lab without configuring the lab devices, use ‌netlab up --no-config.

If you want to inspect the deployed device configurations, execute netlab initial -v – the Ansible playbook will print out the device configurations before they are deployed – or netlab initial -o to create configuration snippets in the config directory.

Connecting to Network Devices

After starting the lab, you can use the netlab connect command to connect to network devices and inspect the OSPF neighbors and IP routing table:

$ netlab connect r1
Connecting to container clab-X-r1, starting bash
Use vtysh to connect to FRR daemon

r1(bash)#vtysh

Hello, this is FRRouting (version 10.0.1_git).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

r1# show ip route
Codes: K - kernel route, C - connected, L - local, S - static,
       R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,
       f - OpenFabric, t - Table-Direct,
       > - selected route, * - FIB route, q - queued, r - rejected, b - backup
       t - trapped, o - offload failure

O   10.0.0.1/32 [110/0] is directly connected, lo, weight 1, 00:03:29
L * 10.0.0.1/32 is directly connected, lo, 00:03:30
C>* 10.0.0.1/32 is directly connected, lo, 00:03:30
O>* 10.0.0.2/32 [110/10] via 10.1.0.2, eth2, weight 1, 00:03:19
O   10.1.0.0/30 [110/10] is directly connected, eth2, weight 1, 00:03:29
C>* 10.1.0.0/30 is directly connected, eth2, 00:03:30
L>* 10.1.0.1/32 is directly connected, eth2, 00:03:30
O   172.16.0.0/24 [110/10] is directly connected, eth1, weight 1, 00:03:29
C>* 172.16.0.0/24 is directly connected, eth1, 00:03:30
L>* 172.16.0.1/32 is directly connected, eth1, 00:03:30
O>* 172.16.1.0/24 [110/20] via 10.1.0.2, eth2, weight 1, 00:03:19

Cleanup

Destroy the lab with netlab down. To clean up the working directory, use netlab down --cleanup.

$ netlab down
┌──────────────────────────────────────────────────────────────────────────────────┐
│ CHECKING virtualization provider installation                                    │
└──────────────────────────────────────────────────────────────────────────────────┘
[SUCCESS] clab installed and working correctly

┌──────────────────────────────────────────────────────────────────────────────────┐
│ STOPPING clab nodes                                                              │
└──────────────────────────────────────────────────────────────────────────────────┘
[INFO]    Setting containerlab runtime to docker
provider clab: executing containerlab destroy --cleanup -t clab.yml
06:31:31 INFO Parsing & checking topology file=clab.yml
06:31:31 INFO Parsing & checking topology file=clab.yml
06:31:31 INFO Destroying lab name=X
06:31:31 INFO Removed container name=clab-X-r2
06:31:31 INFO Removed container name=clab-X-r1
06:31:31 INFO Removing host entries path=/etc/hosts
06:31:31 INFO Removing SSH config path=/etc/ssh/ssh_config.d/clab-X.conf

If you used a GitHub Codespace, don’t forget to shut it down.