From 60cf898d7de46c41abcbf4df08a2002a2a568040 Mon Sep 17 00:00:00 2001 From: JP <21163267+jpke@users.noreply.github.com> Date: Fri, 22 Aug 2025 00:22:48 -0400 Subject: [PATCH 1/2] add instructions for how to run lab in mac arm with vagrant --- mac-arm/4node-part1.clab_arm.yml | 48 +++++++++++ mac-arm/Dockerfile | 9 ++ mac-arm/README.md | 41 +++++++++ mac-arm/capture_submission_arm.sh | 138 ++++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 mac-arm/4node-part1.clab_arm.yml create mode 100644 mac-arm/Dockerfile create mode 100755 mac-arm/capture_submission_arm.sh diff --git a/mac-arm/4node-part1.clab_arm.yml b/mac-arm/4node-part1.clab_arm.yml new file mode 100644 index 0000000..e40f439 --- /dev/null +++ b/mac-arm/4node-part1.clab_arm.yml @@ -0,0 +1,48 @@ +name: lab1-part1 + +topology: + nodes: + host1: + kind: linux + image: ubuntu_jammy:lab_1 + binds: + - lab-host1:/lab-folder + exec: + - chmod 777 /lab-folder + host2: + kind: linux + image: ubuntu_jammy:lab_1 + binds: + - lab-host2:/lab-folder + exec: + - chmod 777 /lab-folder + host3: + kind: linux + image: ubuntu_jammy:lab_1 + binds: + - lab-host3:/lab-folder + exec: + - chmod 777 /lab-folder + host4: + kind: linux + image: ubuntu_jammy:lab_1 + binds: + - lab-host4:/lab-folder + exec: + - chmod 777 /lab-folder + switch: + kind: linux + image: ubuntu_jammy:lab_1 + binds: + - lab-switch:/lab-folder + exec: + - chmod 777 /lab-folder + + links: + - endpoints: ["host1:eth1", "switch:eth1"] + - endpoints: ["host2:eth1", "switch:eth2"] + - endpoints: ["host3:eth1", "switch:eth3"] + - endpoints: ["host4:eth1", "switch:eth4"] + + + diff --git a/mac-arm/Dockerfile b/mac-arm/Dockerfile new file mode 100644 index 0000000..febbdfb --- /dev/null +++ b/mac-arm/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:jammy + +RUN apt update +RUN apt install -y tshark +RUN apt install -y net-tools iproute2 python3 python3-pip + +RUN pip3 install scapy + +# docker build . -t ubuntu_jammy:lab_1 \ No newline at end of file diff --git a/mac-arm/README.md b/mac-arm/README.md index 7a5ceab..4546c01 100644 --- a/mac-arm/README.md +++ b/mac-arm/README.md @@ -73,6 +73,47 @@ Once the above is completed, you can clone the git repo for a given demo/lab wit At this point you can bypass any Vagrant commands and can run the demo/lab as if you had already run `vagrant up` and connected to the VM via ssh. +# Alternative: Docker-based Approach + +As an alternative to the UTM approach above, you can use a Docker-based solution that may be simpler to set up: + +## Prerequisites +- Docker Desktop for Mac (with ARM support) +- Clone this repository to your local machine + +## Setup Steps + +1. **Build the Docker image**: Navigate to the `mac-arm` directory and build the custom Docker image: + ```bash + cd mac-arm + docker build -t npp-linux-arm . + ``` + +2. **Update Vagrantfile configuration**: Navigate to the root directory and update the Vagrantfile: + ```bash + cd .. + # Change the box configuration for better ARM compatibility + sed -i '' 's/config.vm.box = "ubuntu\/jammy64"/config.vm.box = "bento\/ubuntu-22.04"/' Vagrantfile + ``` + +3. **Copy ARM-specific configuration files**: + ```bash + cd mac-arm + # Copy the ARM-compatible containerlab configuration + cp 4node-part1.clab_arm.yml ../lab1/part1/4node-part1.clab.yml + + # Copy the ARM-compatible submission script + cp capture_submission_arm.sh ../lab1/part1/provided/capture_submission.sh + ``` + +4. **Navigate to the lab directory and run the lab**: + ```bash + cd ../lab1/part1 + # Follow the standard lab instructions from this point + ``` + +This Docker-based approach provides a more streamlined setup process compared to the UTM method, while still maintaining compatibility with Mac ARM architecture. + # License For all files in this repo, we follow the MIT license. See LICENSE file. diff --git a/mac-arm/capture_submission_arm.sh b/mac-arm/capture_submission_arm.sh new file mode 100755 index 0000000..ef9eb41 --- /dev/null +++ b/mac-arm/capture_submission_arm.sh @@ -0,0 +1,138 @@ +#!/usr/bin/bash + +# This needs to be run from the same directory as the containerlab yml file exits +# should be run as ./provided/capture_submission.sh + +# It will create a directory submission and a file submission.tgz +# The directories lab-host* need to exist, as does the directory provided (which will contain onepkt.py) + +# There needs to be a file ./do-lab.sh which contains all commands needed for the lab +# They should be a series of docker exec commands in a script (and other things if needed): + +# #!/usr/bin/bash +# # docker exec +# # example from change_mac_addrs.sh +# docker exec clab-lab1-part1-switch ip link set dev eth1 address aa:bb:cc:11:22:11 + + + +# if submission dir exists, stop here +if [ -d "./submission" ] || [ -f "submission.tgz" ] +then + echo "Submission exists. This script creates the submission directory and submission.tgz file. Please remove or move and re-run this script." + exit 1 +fi + + +if ! [ -f "./do-lab.sh" ]; then + echo "do-lab.sh does not exist. Please create and re-run this script." +fi + + +# check dirs (lab-host1, lab-host2, lab-host3, lab-host4, provided) +dirs=( lab-host1 lab-host2 lab-host3 lab-host4 provided) +for i in "${dirs[@]}" +do + if ! [ -d $i ]; then + echo "Directory $i does not exist. Exiting." + exit 2 + else + if [ -f $i/*.pcap ]; then + echo "Directory $i has a pcap file. Delete or move and re-run this script." + exit 3 + fi + fi +done + + +# Check if containerlab is running +# exit code of 0 if it is +# exit code of 1 if it is not +#sudo containerlab inspect 1> /dev/null 2> /dev/null +#if [ $? -eq 0 ]; then +# echo "Containerlab is already running. Please exit it with 'sudo containerlab destroy' then re-run this script" +# exit 3 +#fi + + +# containerlab deploy +sudo containerlab deploy +if [ $? -ne 0 ]; then + echo "Containerlab deploy failed. Check if it is running 'sudo containerlab inspect'. Check if the yaml file exits. Please correct then re-run this script" + exit 3 +fi + + +# Change mac addresses +chmod +x ./provided/change_mac_addrs.sh +./provided/change_mac_addrs.sh + + +# Execute Student provided script to configure per instructions of the lab +./do-lab.sh + + +# clear any existing pcap files in /tmp +docker exec clab-lab1-part1-host1 rm -f /tmp/h1.pcap +docker exec clab-lab1-part1-host2 rm -f /tmp/h2.pcap +docker exec clab-lab1-part1-host3 rm -f /tmp/h3.pcap +docker exec clab-lab1-part1-host4 rm -f /tmp/h4.pcap + +# start packet capture in background using /tmp then copy approach +docker exec clab-lab1-part1-host1 bash -c 'timeout 25 tshark -i eth1 -f "host 1.1.1.1" -w /tmp/h1.pcap; cp /tmp/h1.pcap /lab-folder/' & +pid1=$! +docker exec clab-lab1-part1-host2 bash -c 'timeout 25 tshark -i eth1 -f "host 1.1.1.1" -w /tmp/h2.pcap; cp /tmp/h2.pcap /lab-folder/' & +pid2=$! +docker exec clab-lab1-part1-host3 bash -c 'timeout 25 tshark -i eth1 -f "host 1.1.1.1" -w /tmp/h3.pcap; cp /tmp/h3.pcap /lab-folder/' & +pid3=$! +docker exec clab-lab1-part1-host4 bash -c 'timeout 25 tshark -i eth1 -f "host 1.1.1.1" -w /tmp/h4.pcap; cp /tmp/h4.pcap /lab-folder/' & +pid4=$! + +#echo $pid + + + +# copy ./provided/onepkt.py to each of lab-host1, lab-host2, etc... +cp ./provided/onepkt.py ./lab-host1 +cp ./provided/onepkt.py ./lab-host2 +cp ./provided/onepkt.py ./lab-host3 +cp ./provided/onepkt.py ./lab-host4 + + +# Packet tests +# host1 to host2 +docker exec clab-lab1-part1-host1 /lab-folder/onepkt.py host1 host2 test-pkt1 + +# host2 to host3 +docker exec clab-lab1-part1-host2 /lab-folder/onepkt.py host2 host3 test-pkt2 + +# host3 to host2 +docker exec clab-lab1-part1-host3 /lab-folder/onepkt.py host3 host2 test-pkt3 + +# host1 to host3 +docker exec clab-lab1-part1-host1 /lab-folder/onepkt.py host1 host3 test-pkt4 + +# host4 to all +docker exec clab-lab1-part1-host4 /lab-folder/onepkt.py host4 all_hosts test-pkt5 + +# Wait for tshark captures to complete (timeout handles stopping) +sleep 15s + +# Wait for background processes to finish copying files +wait $pid1 +wait $pid2 +wait $pid3 +wait $pid4 + +# Shut down the containerlab setup +sudo containerlab destroy + +mkdir submission +mv lab-host1/h1.pcap ./submission +mv lab-host2/h2.pcap ./submission +mv lab-host3/h3.pcap ./submission +mv lab-host4/h4.pcap ./submission +tar czf submission.tgz ./submission + + + From 0b744b10313de3c3be076fcebe234d8c444bb9c1 Mon Sep 17 00:00:00 2001 From: JP Earnest <21163267+jpke@users.noreply.github.com> Date: Fri, 22 Aug 2025 00:30:38 -0400 Subject: [PATCH 2/2] Update mac-arm README.md alt option docker build command --- mac-arm/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mac-arm/README.md b/mac-arm/README.md index 4546c01..b592aa5 100644 --- a/mac-arm/README.md +++ b/mac-arm/README.md @@ -86,7 +86,7 @@ As an alternative to the UTM approach above, you can use a Docker-based solution 1. **Build the Docker image**: Navigate to the `mac-arm` directory and build the custom Docker image: ```bash cd mac-arm - docker build -t npp-linux-arm . + docker build . -t ubuntu_jammy:lab_1 ``` 2. **Update Vagrantfile configuration**: Navigate to the root directory and update the Vagrantfile: