marionnet.org — a virtual network laboratory

Driving Marionnet from a script or an AI

Translated from the French version, which is authoritative.

Since 2026, Marionnet can be driven by a program, not only by the mouse. A script can build the network of a lab, start it, wait until the machines are ready, have them run commands, and then check that the network is in the expected state. A conversational agent — an AI that can run commands, such as a command-line coding assistant — can do the same, starting from a lab statement written in plain language. Marionnet itself embeds no AI: you bring your own. Throughout, the Marionnet window stays on screen: you watch the network being built and the machines booting, and you can even use the mouse while the program is at work.

A few typical uses:

  • prepare a lab project without clicking, then rebuild it identically next year, or in several variants;
  • give students a project that starts by itself;
  • check with a single command that a network matches the lab statement (addresses, routes, connectivity), instead of opening every machine in turn;
  • have an AI build a lab and then check it, driving Marionnet on your behalf.

This guide presents the driven mode from the user’s point of view. Technical details, which only matter in particular cases, are folded into boxes that open with a click.


1. Starting Marionnet in driven mode

All it takes is one more option when you start Marionnet:

marionnet --control-socket /tmp/marionnet.sock

The file /tmp/marionnet.sock is the socket through which the driving program talks to Marionnet (a Unix socket: a special file through which two programs on the same machine talk to each other). Without this option the socket does not exist, so Marionnet cannot be driven: you decide, each time you start it, whether it accepts commands from outside.

Commands are then sent with mrnctl, the command that drives Marionnet, installed along with it (its full name is marionnet-ctl). Tell it once where the socket is:

export MARIONNET_CONTROL_SOCKET=/tmp/marionnet.sock

mrnctl new /tmp/lab1.mar
mrnctl add machine m1
mrnctl start m1

Each line is a command, which Marionnet carries out as if it came from the mouse: machine m1 appears on the network map, then boots, and its terminal opens.

Choosing the path, and what needs to be installed

The path must be absolute, and at most 107 bytes long (a limit of the system, not of Marionnet). If it is relative, too long, in a directory Marionnet cannot write into, or already in use by another running Marionnet, Marionnet refuses to start and says why. A script therefore fails on its first line rather than ten commands later.

mrnctl looks for the socket in its --socket=PATH option, otherwise in the variable MARIONNET_CONTROL_SOCKET, and nowhere else: it never goes looking for a Marionnet. It needs the socat program, and jq for its formatting options (--pretty, --query); Marionnet’s packages install both along with it.

Several copies of mrnctl may connect to the same Marionnet, up to eight at a time.

The TAB key completes commands, their options and, above all, the real names of the open project (components, ports, fields), which it asks the running Marionnet for:

$ mrnctl connect c2 s1:<TAB>
s1:port1  s1:port2  s1:port3  s1:port4

If you installed Marionnet from a package (.deb or .rpm) or with its installer, there is nothing to do: completion is installed with the software, and every terminal opened after the installation loads it by itself.

If TAB completes nothing

Completion is loaded by your distribution’s bash-completion package. Most desktop systems have it, but a minimal installation may not; if needed, install it, then open a new terminal:

# Debian, Ubuntu:
sudo apt install bash-completion

# Fedora, Rocky Linux, AlmaLinux:
sudo dnf install bash-completion

# openSUSE:
sudo zypper install bash-completion

If you run Marionnet from its sources without installing it, load completion by hand in each terminal (or once and for all in your ~/.bashrc), from the top of the source tree:

. bin/scripts/marionnet-completion.bash

When no Marionnet is running, completion of commands and options can rely on a snapshot of the vocabulary, taken once (the names of the project, of course, cannot be completed then):

mrnctl help > ~/.marionnet-grammar.json
export MARIONNET_CTL_GRAMMAR=~/.marionnet-grammar.json

Alone or together: who holds the controls?

Marionnet sometimes opens a window by itself: the splash screen at startup, a warning, the summary of what was adapted in an old project, an error. What should happen to these windows depends on who is in front of the screen, and that is the first question to ask yourself.

  • The program drives alone. Nobody is there to read these windows or close them, and a window waiting for an answer would block everything. Marionnet therefore shows them for two seconds, then closes them itself, keeping what they said; the program reads it back with mrnctl notifications. This is the default: nothing needs to be added to the command line.

  • The program and a person drive together. For example, you build the network with a script, but then want to click around and explore it yourself; or you show Marionnet to students while a script puts it to work. The windows must then stay on screen as usual, which is what the --keep-dialogs option does:

    marionnet --control-socket /tmp/marionnet.sock --keep-dialogs
    

    The person then reads and closes the windows, and answers the questions Marionnet asks, even when a command from the program caused them; the program waits for the answer. On the other hand, mrnctl notifications no longer collects anything.

In both cases the person stays in control: nothing prevents clicking while a program drives, and Marionnet never answers on their behalf a question that they triggered themselves.

An AI falls into one of these two cases, depending on how it acts. An AI that runs commands sends its commands through mrnctl, exactly like a script: it takes the place of the program, and you choose whether to let it drive alone or to drive alongside it. But an AI that can see the screen and click can also take the place of the person, with no option at all, since Marionnet then treats it as an ordinary user. To teach an AI how to drive Marionnet, give it ../marionnet-driving-skill.md to read; that page was written for it, and explains how to build, run and check a lab with commands. Designing the lab is not its subject, although the AI can of course help you with that separately.

Changing how long the windows stay open

When the program drives alone, the option --dialog-timeout=N sets how long a window stays on screen before it closes; N is in milliseconds, 2000 by default. The delay is not zero, so that someone watching the screen (or a screenshot) can still see what happened.


2. A first driven network

Here, in full, is a network similar to the one in Getting started (two machines connected by a switch), this time built, started and saved by a script:

export MARIONNET_CONTROL_SOCKET=/tmp/marionnet.sock

# Start Marionnet, then wait until it answers:
marionnet --control-socket "$MARIONNET_CONTROL_SOCKET" &
until mrnctl status > /dev/null 2>&1; do sleep 0.5; done

# A project first, as with the mouse:
mrnctl new /tmp/demo.mar

# The components, then the cables and their two ends:
mrnctl add machine m1
mrnctl add machine m2
mrnctl add switch  s1 --ports=4
mrnctl connect c1 m1:eth0 s1:port1
mrnctl connect c2 m2:eth0 s1:port2

# The addresses:
mrnctl ifconfig-set m1 eth0 ipv4-address 10.0.0.1/24
mrnctl ifconfig-set m2 eth0 ipv4-address 10.0.0.2/24

# Start, then wait until the machines are running (see § 4):
mrnctl start m1
mrnctl start m2
mrnctl wait m1 --state=on --timeout=120
mrnctl wait m2 --state=on --timeout=120

# Stop before saving (see § 5), then quit:
mrnctl stop m1
mrnctl stop m2
mrnctl wait-all --state=off --timeout=180
mrnctl save-as /tmp/demo.mar
mrnctl quit

Line by line, this is what you would do with the mouse. Ports are named as in the interface: a machine numbers its network cards from 0 (eth0, eth1), a switch numbers its ports from 1 (port1, port2). Once saved, the project replays in a single line, the -r option starting all its components at once:

marionnet --control-socket /tmp/marionnet.sock -r /tmp/demo.mar

The examples/ directory holds complete scripts of this kind, ready to run.


3. What Marionnet answers

Every command gets a one-line answer. When the command is accepted, the answer starts with "ok":true; when it is refused, with "ok":false, followed by a code and a plain explanation — here, “m1” cannot start from state “on” (machine m1 is already running):

{"ok":false,"error":"forbidden_transition","detail":"…"}

A script does not even need to read the answer to know whether the command succeeded: like any Unix command, mrnctl returns 0 on success, so you can write mrnctl start m1 && echo started.

Two simple rules avoid most rejections.

  • A program can only do what the graphical interface allows. A running machine can no more be removed by a command than with the mouse, and a machine that is already running cannot be started a second time. To find out what is allowed on a component at a given moment, just ask. For a machine that is switched off, for example:

    mrnctl can m1
    # {"ok":true,"name":"m1","kind":"machine","state":"off",
    #  "can":["set","del","start"],"beyond_gui":[]}
    

    The can field lists the actions allowed right now: modify the machine (set), remove it (del) or start it (start). Once it is running, it can no longer be removed, but it can be stopped (stop). The beyond_gui field marks, among the allowed actions, those that have no button in the interface, such as switching off a single machine abruptly (poweroff). Cables, on the other hand, can be modified and removed while the network is running, as in the graphical interface and for the same reason: you can unplug a real cable and plug it in elsewhere without switching anything off.

  • Ask Marionnet for the list of commands. mrnctl help gives every command with its syntax, and mrnctl help connect the syntax of one of them. The list grows from one version to the next, so the answer of the Marionnet you are driving is what counts; the next two boxes give a glimpse of it all the same.

Example: the commands of Marionnet 1.0.470 (November 2026)

Here is the syntax of every command, as returned on 4 November 2026 by this command:

mrnctl -q '.commands[].syntax' help

Long lines have been broken to fit the box, and the parts in square brackets are optional. This list does not depend on the open project: it was the same with no project and with the project of the next box. It does depend on the version of Marionnet, and a newer version may offer more.

help [<command>]
status
ls [--kind=<kind>] [--can=<action>]
can [<component>]
add <kind> <name> [--ports=<n>] [--<field>=<value>]…
del <component>
get <component> [<field>]
set <component> <field> <value>
rename <component> <new name>
connect <cable> <node>:<port> <node>:<port> [--crossover]
rc-get <component> [<field>|--field=<field>]
rc-set <component> [<one-line content>]
    [--from=<absolute path>] [--enable|--disable]
    [--select|--unselect] [--terminal|--no-terminal]
    [--field=<field>]
ifconfig [<node>]
defects [<node>]
history [<node>]
documents
ifconfig-set <node> <port> <field> [<value>]
    [--restart|--no-restart]
defects-set <node> <port> <inward|outward> <field> [<value>]
    [--restart|--no-restart]
defects-set <cable> <leftward|rightward> <field> [<value>]
history-start <cow file>
history-del <cow file> [--except]
history-set <cow file> <field> [<value>]
history-export <cow file> <variant name> [--force]
open <absolute path>
new <absolute path> [--save|--no-save]
save
save-as <absolute path>
close [--save|--no-save]
notifications [--since=<n>] [--clear]
log <component> [<file>|--file=<file>] [--tail=<n>]
switch-info <switch> [<table>|--table=<table>]
report <component> [--timeout=<s>]
exec <component> <command-line> [--timeout=<s>]
wait <component> (--state=on|off|sleeping | --ready)
    [--timeout=<s>]
wait-all --state=on|off|sleeping [--timeout=<s>]
quit
start <component>
stop <component>
suspend <component>
resume <component>
poweroff <component>
restart <component>
start-all
shutdown-all
poweroff-all
Example: what is allowed in a running project

What mrnctl can allows depends, by contrast, on the state of the project at the moment you ask. Here is its answer, laid out as a table, for a project of three machines connected to a switch by three cables, with m1, m2 and switch s1 running and m3 switched off (Marionnet 1.0.470, 4 November 2026):

Component State Allowed actions
m1, m2 (machines) running stop, suspend, poweroff, restart
m3 (machine) off set, del, start
s1 (switch) running stop, suspend, poweroff, restart
c1, c2 (cables of m1 and m2) plugged in, in use set, del, suspend
c3 (cable of m3) plugged in, idle set, del, suspend

A running machine can be neither modified nor removed, but it can be stopped, suspended, switched off abruptly or restarted; the last two actions are marked beyond_gui, because the graphical interface does not offer them for a single machine. A cable remains modifiable and removable whatever the state of the network, and suspend unplugs it. Note, finally, that the cable of m3 stays idle as long as m3 is off.

Error codes

The error field of a rejection is a stable code that a script can rely on:

Code Meaning
unknown_command no command of that name (the answer lists the ones that exist)
bad_argument wrong number of arguments, unknown option, malformed value
no_active_project no project is open: open or create one first
unknown_node, unknown_port, unknown_field, unknown_direction, unknown_target, unknown_state, unknown_can what is named does not exist
forbidden_transition the graphical interface would forbid it too at this moment (see mrnctl can)
forbidden_in_exam_mode Marionnet was started with --exam, and the command would lose the student’s work
constraint_violated the value is refused by the same check as in the graphical interface
restart_choice_required the change requires restarting a running component: add --restart or --no-restart
unsaved_changes the project has been modified: add --save or --no-save
components_running a component is running, and the project cannot be saved in that state (see § 5)
timeout the delay expired (the answer says what was last observed)
internal a bug in Marionnet; the detail holds whatever could be captured
Exit codes of mrnctl, and formatting the answers
Code Meaning
0 Marionnet accepted the command
1 Marionnet answered, and refused
2 the error is on mrnctl’s side: no socket, missing tool, unknown option
3 nothing came back: Marionnet is gone, stuck, or was never there

The answer is a JSON object. By default mrnctl prints it as it is, on one line; --pretty indents it, and -q extracts part of it with a jq filter:

mrnctl --pretty status

# The name of each component:
mrnctl -q '.nodes[].name' ls

# true if m1 can be removed:
mrnctl -q '.can | index("del") != null' can m1

A command is a verb, then arguments, then options (--option=value). Since component names never contain spaces, only the last argument of a command that takes free text (a comment, a command) may contain any.


4. Waiting for a machine to be ready

Starting a machine means booting a real Linux kernel, which takes a few seconds. Yet mrnctl start m1 answers at once: its answer means that the command was accepted, not that the machine has finished booting. A script that went straight on would therefore be talking to a machine that is not there yet. There are two ways to wait, depending on what you need.

  • Wait until the machine is running, that is, until its process exists:

    mrnctl wait m1 --state=on --timeout=120
    

    The wait is short (under a second), but the machine’s system is not usable yet: a Debian needs about five more seconds.

  • Wait until the machine says it is ready. Marionnet cannot know when a machine is ready for the lab, that is, when it has done what is expected of it (setting its addresses, starting its services…): only its startup configuration knows (see § 6). So it is up to the startup configuration to say so, with its last line, by creating an agreed file (a marker file) in /mnt/hostfs, a directory that Marionnet mounts in every machine and watches from the host:

    echo ready > /mnt/hostfs/marionnet-guest-ready
    

    On the mrnctl side, all that remains is to wait for this marker file:

    mrnctl wait m1 --ready --timeout=300
    

    The file name must be copied exactly, since that is what Marionnet looks for. There is no need, however, to delete the file between sessions: Marionnet only takes into account the file written during the current boot. Finally, a machine with no startup configuration never writes this file, so --ready would wait until the delay runs out: in that case, stick to --state=on.

Passing a result in the marker file

Whatever the machine writes in the file comes back in the answer to wait --ready. Instead of the plain word ready, the startup configuration can therefore write a result, for instance that of a ping:

R="ping KO"
ping -c 3 10.0.0.2 > /dev/null && R="ping ok"
echo "$R" > /mnt/hostfs/marionnet-guest-ready

mrnctl then reads it in the answer:

mrnctl -q .line wait m1 --ready --timeout=300
# ping ok
Running two sessions in a row: wait until Marionnet has really ended

If your script quits Marionnet to start another one straight away, wait until the first has really ended: two sessions running at the same time compete for the same host resources. Yet mrnctl quit answers before Marionnet has finished stopping (the answer has to leave before the shutdown), and Marionnet outlives that answer by about half a second, together with its machines.

If your script started Marionnet itself, as in § 2, the simplest way is the shell’s wait, $! being the last process started in the background:

marionnet --control-socket "$MARIONNET_CONTROL_SOCKET" &
pid=$!
# … the session …
mrnctl quit
wait "$pid"

If Marionnet was started some other way (by hand, or by another script), the answer to quit gives the process number, which you only need to watch:

pid=$(mrnctl -q .pid quit)
while kill -0 "$pid" 2>/dev/null; do sleep 0.05; done

5. Building and saving a lab

Section 2 showed the essentials. Here are the commands used most often, with their mouse equivalent:

Command Equivalent in the graphical interface
new, open, save, save-as, close, quit the entries of the Project menu
add machine m1, add switch s1 --ports=8… Add, in the palette
connect c1 m1:eth0 s1:port1 (--crossover for a crossover cable) adding a cable
set m1 memory 256, rename m1 pc1, del m1 Modify, Remove
start, stop, suspend, resume, start-all… the start and stop buttons
ifconfig-set, defects-set a cell of the Interfaces and Defects tabs

Two precautions are needed, and they are the same as in the graphical interface.

  • Marionnet never throws your work away unless told to. If the current project has been modified, new and close wait for you to say --save (save first) or --no-save (discard the changes), where the interface would ask you.
  • A running network cannot be saved, just as the interface greys out its saving entries while a machine is running. Stop the machines first, or use close --save, which stops everything, waits until everything has stopped, then saves (allow a few tens of seconds).
What Marionnet chooses, accepts or refuses when you add a component
  • A machine’s kernel is chosen for you. Like the Add window, add machine picks a kernel that suits the machine’s system: a machine added this way boots without further settings.
  • The distribution and kernel you ask for must be installed on the host. A distribution (the virtual machine’s root filesystem) that is not installed there, requested with the --distrib= option of add or with set m1 distrib, is refused, and the error lists the installed distributions; the same goes for a kernel this distribution does not provide. Marionnet thus never silently replaces what you asked for.
  • The number of ports follows the limits of the interface: 1 to 8 network cards for a machine, 4 to 16 ports for a hub, a switch, a router or a Gateway, 1 to 16 for a NAT bridge or a LAN bridge.
  • A refused addition leaves nothing behind: the name stays free, and the script can try again under the same name once the mistake is fixed.
  • A cable cannot be renamed, neither with the mouse nor with a command: to change its name, remove it, then connect a new one.
Why the machines must be stopped before saving

Besides the description of the network, the .mar file holds the disk of each machine (more precisely, what has changed with respect to the original image). Saving a running machine would mean copying a disk in the middle of a write, and reopening the project would then be like switching a machine back on after a power cut. Hence the rule, which is also that of the graphical interface.

close --save settles the matter, since it stops the machines, waits until they have stopped, then saves. This can take several tens of seconds, which the --timeout option does not bound: give the script time for the shutdown.

For the same reason, a .mar file is not something to make by hand. The description of the network is indeed written as text (see ../project-format-v3.md), but only Marionnet can produce the disks: build the network with commands, and save it with save-as.

Addresses and defects, cell by cell

These two tabs are read and written with two pairs of commands:

  • the Interfaces tab, with mrnctl ifconfig and mrnctl ifconfig-set;
  • the Defects tab, with mrnctl defects and mrnctl defects-set.

Writing is done one cell at a time, naming the column by a name given in the slugs field of the read answer:

mrnctl -q '.slugs[]' ifconfig m1
# mac-address
# mtu
# ipv4-address
# …

mrnctl ifconfig-set m1 eth0 ipv4-address 10.0.0.1/24
mrnctl defects-set  m1 eth0 inward loss 5 --no-restart
mrnctl defects-set  c1 rightward maximum-delay-ms 50

The value is checked exactly as in the graphical interface. When a change requires restarting a running machine, the interface would ask you whether to do it now; a script must answer in advance, with --restart or --no-restart. A plugged-in cable, on the other hand, takes its new defect on the fly, without any restart.


6. Putting the machines to work

Marionnet’s commands act on the network, seen from outside. For what happens inside a machine, there are two means.

  • The startup configuration — the feature the graphical interface offers under that name — is a small bash script that the machine runs at the end of its boot. It can configure the machine, play its part in the lab (run a ping, for instance), write results, and then announce that the machine is ready:

    mrnctl rc-set m1 --from=/tmp/scenario.sh --enable
    mrnctl start m1
    mrnctl wait  m1 --ready --timeout=300
    

    Since this script is read at boot time, it only takes effect at the machine’s next boot.

  • The exec command has a running machine execute a command, and returns its output:

    mrnctl exec m1 uname -r
    mrnctl -q .output exec m1 -- ping -c 1 -W 2 10.0.0.2
    

    The lone -- separates mrnctl’s options from those of the command: without it, an option such as --all would be taken by mrnctl for one of its own.

The simplest way to collect what a machine has produced is to have it write in /mnt/hostfs. This directory of the virtual machine is actually a directory of the host, which your script reads directly; mrnctl rc-get m1 gives its path, in the hostfs field.

An example of startup configuration
# The script m1 will run at the end of its boot,
# written here on the host:
cat > /tmp/scenario.sh <<'EOF'
ip addr add 10.0.0.1/24 dev eth0 2>/dev/null
ip link set eth0 up
ping -c 3 10.0.0.2 > /mnt/hostfs/ping.log 2>&1
echo "$?" > /mnt/hostfs/ping.status
# Last line: announce that the machine is ready.
echo ready > /mnt/hostfs/marionnet-guest-ready
EOF

# Hand it to m1, start m1, wait until it is ready:
mrnctl rc-set m1 --from=/tmp/scenario.sh --enable
mrnctl start m1
mrnctl wait  m1 --ready --timeout=300

# Read, from the host, what the machine wrote:
hostfs=$(mrnctl -q '.hostfs' rc-get m1)
cat "$hostfs/ping.log"

For a one-line script, the content can also be given directly in the command:

mrnctl rc-set m1 'echo hello'

Today, machines, switches and routers have a startup configuration; hubs, clouds and the components that reach the real network do not.

The routing daemons of a router

Besides its Unix configuration, a router has one configuration per routing daemon, just as its Modify window has one tab per protocol. Ask it which ones it has, then name one with --field=:

mrnctl -q '.available | join(" ")' rc-get r1
# rc_config_unix zebra rip ripng ospf bgp ospf6 isis

mrnctl rc-set r1 --from=/tmp/zebra.conf --field=zebra

# This daemon will not start:
mrnctl rc-set r1 --field=ospf --unselect

# Open zebra's CISCO-IOS-like terminal:
mrnctl rc-set r1 --field=zebra --terminal

Writing a daemon’s configuration ticks both its enabled box (your text is used) and its selected box (the daemon starts), because a configuration that is never used would be an unpleasant surprise; --unselect and the neighbouring options let you decide otherwise.

Quotes in exec

Suppose you want m1 to run the command sh -c 'exit 7', which should return code 7. Before reaching the machine, this command goes through your shell, which removes its own quotes: it must therefore be passed as a single argument, in double quotes.

# CORRECT: the machine gets  sh -c 'exit 7'  (code 7).
mrnctl exec m1 "sh -c 'exit 7'"

# WRONG: your shell removed the quotes,
# the machine gets  sh -c exit 7  (code 0).
mrnctl exec m1 -- sh -c 'exit 7'
What Marionnet keeps of each exec, and its limits

Every command run by exec is recorded, with its date and its exit code, in a journal of the machine of its own, the exec journal (see § 7): when marking, it is never mistaken for what the student typed.

Two limits also protect the script: the output returned is capped at 200 lines, and the --timeout=<s> option bounds how long the command may run. When the delay runs out, the command is stopped inside the machine, and the answer says so.


7. Finding out what happened

Marionnet knows what it built, and the machines know what happened inside them; both can be asked:

# The components and their state, then the addresses of m1:
mrnctl ls
mrnctl ifconfig m1

# What m1's startup configuration did:
mrnctl log m1

# What was typed in its terminal:
mrnctl log m1 commands

# Ask it for a report on its state, then read it:
mrnctl report m1
mrnctl log m1 report

The report needs some explanation. The journals are traces: they tell which commands were run, but not always the state that resulted. Suppose, for instance, that a machine’s startup configuration contains this line:

echo 1 > /proc/sys/net/ipv4/ip_forward

Packet forwarding is then indeed enabled, but the startup configuration’s journal only keeps echo 1, because its trace does not record redirections. The report, by contrast, is a snapshot of the machine at a given moment (its real addresses, its routes, its neighbours, its firewall): that is what to rely on to know whether a machine is in the expected state.

Finally, the History tab can be driven too: mrnctl history m1 lists the disk states of a machine, and history-start restarts the machine from one of them, like the Start in this state entry of the interface, which lets you replay a lab from a known point.

The seven journals of a machine
Journal Written by Contents
rc_config the machine the trace of its startup configuration, its errors, and the command that failed (a switch has this journal too, written by Marionnet)
boot the machine what its boot did: kernel messages, failed services
commands the machine the commands typed, each with its date
report the machine, on request or at a clean shutdown the report described above
exec the machine the commands run by mrnctl exec, with their date and exit code
console Marionnet, on the host the machine’s console, from the first line (option --console-log)
terminal Marionnet, on the host the recording of the terminal, commands and output (option --terminal-log)

The last two only exist if Marionnet was started with the matching option, because recording a session without the user’s knowledge would be surveillance rather than teaching; --exam turns both on (see ../exam-mode.md). Note also that the first five are written in a directory the student can write into, whereas the console and the terminal, written by the host, are out of the student’s reach.

A journal outlives what it describes: a machine that is switched off still answers log. When a journal does not exist yet, the error says why (machine never started, boot not finished yet, option missing at startup). An answer carries at most 400 lines, and --tail=<n> chooses how many of the last ones.

What a switch knows right now

mrnctl switch-info s1 asks a running switch what it knows at this very moment: its ports, its table of MAC addresses, its VLANs, its spanning tree. This information is written nowhere and disappears with the switch; what it said at startup, on the other hand, stays in its journal (mrnctl log s1).


8. Writing the commands in a file

Instead of a shell script, a lab can be written as a plain list of commands, one per line, in a .mrn file:

cat > lab.mrn <<'EOF'
new /tmp/lab.mar
add machine m1
add machine m2
add switch s1 --ports=4
connect c1 m1:eth0 s1:port1
connect c2 m2:eth0 s1:port2
save-as /tmp/lab.mar
EOF

mrnctl -f lab.mrn

The file runs line by line and stops at the first rejected command (--keep-going carries on). Note that a failure in the middle of the file leaves the project in the state the previous lines put it in, since nothing is undone; hence the point of checking the file before sending it, which is what mrn-check does (it is installed with Marionnet, like the two tools below), without sending anything to Marionnet:

mrn-check lab.mrn
# lab.mrn: 9 request(s), no error

It reports unknown commands, ports that cannot exist (port0 on a switch), components used before being added, and ports already taken.

Finally, when a lab needs more than a list of commands (waiting for a machine, reading a result, repeating something on every machine), mrn2sh turns the file into an ordinary shell script, which you then complete by hand:

mrn2sh lab.mrn > lab.sh
Checking without a running Marionnet, and details of the translation

mrn-check asks the running Marionnet for its vocabulary. To check a file without Marionnet, take a snapshot of the vocabulary once, and take it again when Marionnet changes:

mrnctl help > grammar.json
mrn-check --grammar=grammar.json lab.mrn

The checks on names assume that the file builds the project itself, that is, that it starts with new. After an open, mrn-check does not know the project: it then only checks the syntax and the port names, and says so. Whatever can only be decided while running (may this machine start now?) is left to Marionnet.

mrn2sh refuses to translate a file that contains an error. The script it produces prints each command before sending it, keeps your comments, and accepts as argument another project file than the one named in the .mrn:

./lab.sh /tmp/other.mar

The translation is one-way: once you have edited the script, the script is the source, and regenerating it would overwrite it.


9. Checking a lab

A .mrn file says what a network is made of; a .mrv file says what must be true of it, one statement per line, and mrn-verify checks it against the running session:

cat > lab.mrv <<'EOF'
state m1 is on
cable c1 m1:eth0 s1:port1
journal m1 rc_config ok
report m1 says ~ net[.]ipv4[.]ip_forward *= *1
reaches m1 m2
EOF

mrn-verify lab.mrv
# PASS  state m1 is on
# PASS  cable c1 m1:eth0 s1:port1
# …

Each line gets one of three verdicts: PASS if the statement is true, FAIL if it is false, and SKIP when Marionnet offers no way of knowing — for instance a ping towards a machine that is switched off, whose address cannot be read. Note that reaches m1 m2 runs a ping from m1 to the address of m2, read from m2’s report: a firewall that blocks ICMP therefore gives FAIL, just as a ping typed by hand would fail. This third verdict matters: a checker that answered FAIL in that case would penalise a student for a limit of the tool. The --strict option, however, counts a SKIP as a failure. The possible statements (nine forms) are listed by mrn-verify --help, and checking changes nothing in the project. Finally, a pattern preceded by ~, as in the report line of the example, is an extended regular expression (that of grep -E); without ~, the pattern is a plain string.

The nine forms of statement (Marionnet 1.0.470)

As given by mrn-verify --help:

state <component> is on|off|sleeping
field <component> <field> is <value>
cable <cable> <node>:<port> <node>:<port>
switch <switch> <table> has <key>=<value> [<key>=<value>]…
journal <component> <journal> contains|lacks <pattern>
journal <component> <journal> ok
documents <component> has <pattern>
report <component> says|lacks <pattern>
reaches <component> <component>|<address>
The trace and the state: two statements that look alike
journal m1 rc_config contains ip_forward
report  m1 says     ~ net[.]ipv4[.]ip_forward *= *1

The first reads the trace of the startup configuration, the second the report. On the machine of the example in § 7, whose configuration enables packet forwarding through a redirection, the first fails, since the trace only contains echo 1, whereas the second passes. A marking scheme should therefore rely on the trace to prove that a command was run, and on the report to prove its effect, that is, the state the machine is actually in.

For a script or an AI: exit codes and JSON output

mrn-verify returns 0 if everything holds, 1 if a statement is false (or if the file contains an error), and 2 if nothing could be checked. --json gives one object per statement, with its line and its reason. Like mrn-check, it can check the file itself outside a session (--grammar=grammar.json), and then says in advance what will not be checkable. Finally, --refresh=never reads the last report of each machine instead of asking for a new one, which suits the marking of a session that is over.


10. When it does not work

What you see What to do
Marionnet refuses to start (--control-socket: …) the path is relative, too long, or already used by another Marionnet: the message says which
no control socket say where the socket is (export MARIONNET_CONTROL_SOCKET=…)
not a unix socket the path is wrong, or Marionnet was started without --control-socket
no answer from … Marionnet is gone, or a window is waiting for an answer on screen (with --keep-dialogs, the person has to close it)
no_active_project create or open a project first
unsaved_changes add --save or --no-save
components_running when saving stop the machines first, or use close --save
forbidden_transition the graphical interface would forbid it too: ask mrnctl can <component>
restart_choice_required add --restart or --no-restart
timeout on wait … --ready the machine did not write the agreed file: check that its startup configuration is enabled (--enable) and that it really booted
late answer to a long command raise its --timeout=; mrnctl sets its own wait from that value

11. Going further

  • mrnctl help gives every command, always up to date.
  • mrnctl --help, mrn-check --help and mrn-verify --help give the options of each tool.
  • examples/ holds complete scripts, ready to run.
  • ../teacher-guide.md presents driving seen from a classroom (preparing a lab, running the session, marking), with a complete lab in ../labs/session-7/.
  • ../exam-mode.md describes the exam mode.
  • ../marionnet-driving-skill.md is the guide to give an AI so that it drives Marionnet, that is, builds, checks and marks a lab with commands.
For developers

In the Marionnet sources:

  • docs/pilotage-par-script.md: the design of the control channel, its rationale and the journal of how it was built (in French);
  • docs/journalisation-profonde.md: the design of the journals (in French);
  • bin/scripts/marionnet-ctl.sh: mrnctl itself.

This guide describes the shape of the control channel and its lasting rules. It copies neither the list of commands nor their options, which the running Marionnet publishes itself through help: in case of disagreement, help is right.