Skip to content

Commit

Permalink
Add scripts for emulating 17 campus network
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechou committed Aug 1, 2024
1 parent b83b7ab commit c3bfc35
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 8 deletions.
15 changes: 8 additions & 7 deletions full-emulation/15-real-networks/single-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ network="$2"
"${CONFGEN[@]}" --network "$toml" --devices >"$DEVICES_TXT"
"${CONFGEN[@]}" --network "$toml" --invariants >"$INVS_TXT"

startup &>/dev/null
mapfile -t invs <"$INVS_TXT"
for inv in "${invs[@]}"; do
set +e
# target_node,reachable,protocol,src_node,dst_ip
IFS=, read -r _ reachable _ src_node dst_ip <<<"$inv"
startup &>/dev/null
set +e
# Packet tests
msg "Test $src_node -> $dst_ip: $reachable"
docker exec -it "$src_node" hping3 "$dst_ip" -c 1 -i u100000 -n --icmp |
grep -e "packets received"
set -e
get_container_memories
cleanup &>/dev/null
# Save input files
mkdir -p "$RESULTS_DIR/$network"
mv "$CONF" "$BRIDGES_TXT" "$DEVICES_TXT" "$INVS_TXT" "$RESULTS_DIR/$network"
done
get_container_memories
cleanup &>/dev/null

# Save input files
mkdir -p "$RESULTS_DIR/$network"
mv "$CONF" "$BRIDGES_TXT" "$DEVICES_TXT" "$INVS_TXT" "$RESULTS_DIR/$network"
1 change: 1 addition & 0 deletions full-emulation/17-campus-network/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.clab.yml
64 changes: 64 additions & 0 deletions full-emulation/17-campus-network/confgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/python3

import argparse
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
from src.config import Config


def main():
parser = argparse.ArgumentParser(description="17-campus-network")
parser.add_argument(
"-n",
"--network",
type=str,
required=True,
action="store",
help="Input network toml file",
)
parser.add_argument(
"-b",
"--bridges",
default=False,
action="store_true",
help="Print out all L2 bridge names",
)
parser.add_argument(
"-d",
"--devices",
default=False,
action="store_true",
help="Print out all device names except bridges",
)
parser.add_argument(
"-i",
"--invariants",
default=False,
action="store_true",
help="Print out invariant parameters",
)
args = parser.parse_args()

lab_name = "campus_network"
config = Config()
config.deserialize_toml(args.network)
config.prefix_all_node_names("node_") # Prefix all node names with "node_"

if args.bridges:
for br in config.get_bridges():
print(br)
elif args.devices:
bridges = config.get_bridges()
for node in config.network.nodes:
if node.name not in bridges:
print(node.name)
elif args.invariants:
config.output_invariants()
else:
config.output_clab_yml(name=lab_name)


if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions full-emulation/17-campus-network/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
source "$SCRIPT_DIR/../common.sh"
cd "$SCRIPT_DIR"

EXAMPLE_DIR="$(realpath "$SCRIPT_DIR/../../examples/17-campus-network")"
for toml in "$EXAMPLE_DIR"/results/output.*/network.toml; do
network="$(basename "$(dirname "$toml")" | sed -e 's/output\.//' -e 's/\.[0-9]\+-procs.*//')"
mkdir -p "$RESULTS_DIR/$network"
msg "Testing $network ..."
/usr/bin/time bash "$SCRIPT_DIR/single-run.sh" "$toml" "$network" &>"$RESULTS_DIR/$network/out.log"
done

msg "Done"
33 changes: 33 additions & 0 deletions full-emulation/17-campus-network/single-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
source "$SCRIPT_DIR/../common.sh"
cd "$SCRIPT_DIR"

toml="$1"
network="$2"

# Prepare inputs: CONF, BRIDGES_TXT, DEVICES_TXT, INVS_TXT
"${CONFGEN[@]}" --network "$toml" >"$CONF"
"${CONFGEN[@]}" --network "$toml" --bridges >"$BRIDGES_TXT"
"${CONFGEN[@]}" --network "$toml" --devices >"$DEVICES_TXT"
"${CONFGEN[@]}" --network "$toml" --invariants >"$INVS_TXT"

startup &>/dev/null
mapfile -t invs <"$INVS_TXT"
for inv in "${invs[@]}"; do
set +e
# target_node,reachable,protocol,src_node,dst_ip
IFS=, read -r _ reachable _ src_node dst_ip <<<"$inv"
# Packet tests
msg "Test $src_node -> $dst_ip: $reachable"
docker exec -it "$src_node" hping3 "$dst_ip" -c 1 -i u100000 -n --icmp |
grep -e "packets received"
set -e
done
get_container_memories
cleanup &>/dev/null

# Save input files
mkdir -p "$RESULTS_DIR/$network"
mv "$CONF" "$BRIDGES_TXT" "$DEVICES_TXT" "$INVS_TXT" "$RESULTS_DIR/$network"
2 changes: 1 addition & 1 deletion full-emulation/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ delete_bridges() {

startup() {
create_bridges
sudo containerlab deploy -t "$CONF"
sudo containerlab deploy -t "$CONF" --reconfigure
}

get_container_memories() {
Expand Down

0 comments on commit c3bfc35

Please sign in to comment.