Starting Multiple Lab Instances

Using the default settings, you can run a single netlab lab on a server. This tutorial explains why that’s the case, how you can use the multilab plugin to run multiple lab instances (including multiple instances of the same lab topology) in parallel, and how you work with those lab instances.

AI-Generated Content

This documentation was written by AI and adjusted/edited by Ivan

Tip

This tutorial assumes you’re familiar with the lab startup process and the netlab status file described in Starting a Lab: Behind the Scenes.

Why Can’t I Start Two Labs?

Try to start a second lab while the first one is running, and you’ll get an error message similar to this one:

$ netlab up

It looks like the lab instance 'default' is already running in directory
/home/user/labs/ospf.

Please use 'netlab status --all' to check the status of labs running on this
machine. You can stop the other lab instance with:

netlab status -i default --cleanup

If you think your netlab status file is corrupt, use 'netlab status --reset' to
delete it.

Every lab started with the default settings uses the same lab instance identifier (default) and, even more importantly, the same server resources:

  • The management network (default IPv4 prefix: 192.168.121.0/24) and the management IP addresses of the lab devices

  • The name of the management network and the underlying Linux bridge

  • The Linux bridges used for multi-access links, and the names of VMs and containers (both are derived from the lab name, which is usually the name of the lab topology directory)

  • The TCP ports used by external tools, for example, the Graphite web server

netlab up checks the netlab status file and refuses to start another instance of the default lab while one is already running.

There’s another restriction you cannot work around: you can run a single lab in a directory. netlab up creates the netlab.lock file in the lab directory and refuses to start another lab in the same directory (more details). You can use the same lab topology file in multiple lab instances, and even use the path to the same topology file to start the labs, but each one must be started from a different directory.

Using the multilab Plugin

The multilab plugin uses a multilab ID (an integer between 1 and 200) to change the lab parameters that would otherwise overlap. For example, with the multilab ID set to 17, the plugin:

  • Sets the lab instance identifier to 17

  • Changes the lab name to ml-17, changing the names of VMs, containers, and Linux bridges

  • Changes the management network name to nl_mgmt_17 and its IPv4 prefix to 192.168.17.0/24

External tools also use the multilab ID; for example, the Graphite web server listens on port 8097 (8080 + 17).

Tip

The Behind the Scenes section of the plugin documentation describes all the parameters changed by the multilab plugin and how you can add your own.

Selecting the Multilab ID

You have to enable the multilab plugin and set the multilab ID (defaults.multilab.id) to start a lab instance. You can do that in the lab topology, in your user defaults, with environment variables, or with CLI arguments (more details), for example:

$ netlab up --plugin multilab -s defaults.multilab.id=17

Selecting unique multilab IDs is tedious. The multilab plugin can do it for you when you set defaults.multilab.auto_id (more details). These environment variables enable the multilab plugin and dynamic multilab IDs for every lab you start:

$ export NETLAB_PLUGIN=multilab
$ export NETLAB_MULTILAB_AUTO__ID=force

Starting Two Instances of the Same Lab

With the above environment variables set, you can start two copies of the same lab topology. Create two directories and start the lab from each one:

$ mkdir -p ~/labs/ospf-a ~/labs/ospf-b
$ cd ~/labs/ospf-a; netlab up ~/labs/ospf/topology.yml
...
$ cd ~/labs/ospf-b; netlab up ~/labs/ospf/topology.yml
...

netlab status –all displays both lab instances with their multilab IDs and directories:

$ netlab status --all
Active lab instance(s)

┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━┓
┃ id ┃ directory              ┃ status  ┃ providers ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━┩
│ 42 │ /home/user/labs/ospf-a │ started │ clab      │
│ 97 │ /home/user/labs/ospf-b │ started │ clab      │
└────┴────────────────────────┴─────────┴───────────┘

Tip

The multilab plugin reuses the multilab ID of a lab instance that is still recorded as running in the current directory (for example, after a failed lab startup). netlab restart gets a new multilab ID because netlab down removes the lab instance from the status file.

Working with Lab Instances

Every lab instance has its own directory with its own snapshot file, so the operational netlab commands work as usual when you execute them in the lab directory:

$ cd ~/labs/ospf-b
$ netlab connect r1

Alternatively, use the --instance option with the multilab ID to work with a lab instance from any directory:

$ netlab connect --instance 42 r1
$ netlab validate --instance 97
$ netlab down --instance 42

netlab status –cleanup shuts down a lab instance and removes its configuration files:

$ netlab status --instance 97 --cleanup

Sharing a Server with Other Users

Each user has their own netlab status file (~/.netlab/status.yaml). The multilab plugin uses it to find the multilab IDs already in use, and netlab up uses it to detect overlapping lab instances, so it does not know about the labs started by other users.

When multiple users run labs on the same server, use a single status file:

  • Set defaults.lab_status_file in the system defaults (for example, /etc/netlab/defaults.yml)[1].

  • Make sure all netlab users can write to the status file and its parent directory (more details).

Starting or stopping multiple labs at the same time can confuse Vagrant and (to a lesser extent) containerlab. Set defaults.multilab.lock to serialize the lab start/stop operations (more details).

Warning

The multilab plugin derives Linux interface names used to provide intra-lab connectivity from the lab name, and Linux doesn’t accept interface names longer than 15 characters. Read the interface name limitations before changing the lab name in the multilab parameters.