Skip to content
Open
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
48 changes: 48 additions & 0 deletions mac-arm/4node-part1.clab_arm.yml
Original file line number Diff line number Diff line change
@@ -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"]



9 changes: 9 additions & 0 deletions mac-arm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions mac-arm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ubuntu_jammy:lab_1
```

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.
138 changes: 138 additions & 0 deletions mac-arm/capture_submission_arm.sh
Original file line number Diff line number Diff line change
@@ -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 <container name> <command to run in container>
# # 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