-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for emulating 17 campus network
- Loading branch information
Showing
6 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.clab.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters