Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
with:
key: ${{ inputs.toolchain }}
shared-key: ${{ inputs.cache-key }}
- uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2
- uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3
with:
tool: ${{ inputs.tools }}
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2
- uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3
with:
tool: mdbook@${{ env.MDBOOK_VERSION }}
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2
- uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3
with:
tool: cargo-deny@0.20.2
- run: cargo deny check advisories
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ thiserror = "2"
insta = { version = "1", features = ["glob"] }
proptest = "1"
# Checks that the example scenarios satisfy the generated schema
jsonschema = { version = "0.60", default-features = false }
jsonschema = { version = "0.61", default-features = false }

[workspace.lints.rust]
# A crate that needs `unsafe` (the engine, the bindings) overrides this in its own Cargo.toml and says why
Expand Down
8 changes: 7 additions & 1 deletion crates/netscenario-backend-kernel/tests/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ use netscenario_model::Scenario;
use support::{agent_exe, assert_nothing_left, backend, namespaces_available, work_dir};

fn scenario(link: &str, measure: &str) -> Scenario {
// Nothing to measure: the key is left out (an empty key is a null, and a null is not a mapping)
let measure = if measure.is_empty() {
String::new()
} else {
format!("measure:\n{measure}")
};
Scenario::from_yaml(
&format!(
"version: 0\nname: capture-test\nseed: 5\nduration: 3s\ntopology:\n nodes: [client, server]\n links:\n - id: access\n between: [client, server]\n{link}workloads:\n - {{ id: media, kind: udp-cbr, from: client, to: server, rate: 2mbit, packet-size: 1200b }}\nmeasure:\n{measure}"
"version: 0\nname: capture-test\nseed: 5\nduration: 3s\ntopology:\n nodes: [client, server]\n links:\n - id: access\n between: [client, server]\n{link}workloads:\n - {{ id: media, kind: udp-cbr, from: client, to: server, rate: 2mbit, packet-size: 1200b }}\n{measure}"
),
"capture-test.yaml",
)
Expand Down
17 changes: 16 additions & 1 deletion crates/netscenario-model/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,22 @@ fn clean_message(rendered: &str) -> (String, Option<String>) {
);
}
let text = text.trim();
(text.to_owned(), unknown_name_hint(text))
// A key without a value is a null, and since serde-saphyr 2.1 a null is neither a list nor a mapping
let empty_hint = match text {
"expected sequence start" => {
Some("a list is written `[]` when it is empty; or leave the key out")
}
"expected mapping start" => {
Some("a mapping is written `{}` when it is empty; or leave the key out")
}
_ => None,
};
(
text.to_owned(),
empty_hint
.map(str::to_owned)
.or_else(|| unknown_name_hint(text)),
)
}

/// For "unknown field `dealy`, expected one of delay, jitter" (or "unknown variant"): the name that was most
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/netscenario-model/tests/corpus.rs
expression: error.render()
input_file: scenarios/invalid/empty-list-key.yaml
---
error: expected sequence start
--> empty-list-key.yaml:13:9
|
12 | - { id: media, kind: udp-cbr, from: client, to: server, rate: 1mbit, packet-size: 1200b }
13 | timeline:
| ^
= help: a list is written `[]` when it is empty; or leave the key out
8 changes: 7 additions & 1 deletion crates/netscenario-model/tests/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use netscenario_model::{Direction, Edit, Impairments, Scenario};
const HEAD: &str = "version: 0\nname: t\nduration: 30s\ntopology:\n nodes: [a, b]\n links:\n - id: l\n between: [a, b]\n both: { delay: 10ms, rate: 8mbit, loss: { model: random, p: 1% } }\nworkloads:\n - { id: w, kind: udp-cbr, from: a, to: b, rate: 1mbit, packet-size: 1200b }\ntimeline:\n";

fn scenario(timeline: &str) -> Scenario {
Scenario::from_yaml(&format!("{HEAD}{timeline}"), "t.yaml")
// No events: the key is left out. An empty key is a null, and a null is not a list (it is written `[]`).
let head = if timeline.is_empty() {
HEAD.trim_end_matches("timeline:\n")
} else {
HEAD
};
Scenario::from_yaml(&format!("{head}{timeline}"), "t.yaml")
.unwrap_or_else(|error| panic!("{error}"))
}

Expand Down
1 change: 1 addition & 0 deletions docs/SCENARIO-FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is versioned with the line `version: 0`. **Version 0 is the series be
The format is YAML 1.2; JSON is accepted because it is a subset. In addition:

- One document per file, UTF-8, at most 4 MiB (the expanded form of a scenario with a trace or a table holds their packets or entries), nesting at most 32 levels deep. An empty file is an error.
- A key without a value is a null, and a null is neither a list nor a mapping: write `[]` or `{}` for an empty one, or leave the key out (`timeline:` with nothing after it is refused). Where a value may be cleared, `null` means that (see `set` below).
- Keys are unique inside a mapping.
- **Anchors, aliases, merge keys (`<<`) and tags are refused.** A scenario reads the same from top to bottom. Reuse is done on purpose with parameters, templates and includes ([below](#parameters-templates-and-includes)), and not through YAML features.
- Comments are free.
Expand Down
10 changes: 5 additions & 5 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions scenarios/invalid/empty-list-key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 0
name: t
duration: 10s
topology:
nodes: [client, server]
links:
- id: access
between: [client, server]
forward:
delay: 40ms
workloads:
- { id: media, kind: udp-cbr, from: client, to: server, rate: 1mbit, packet-size: 1200b }
timeline:
Loading