Skip to content

Commit

Permalink
Fix IPs in CR scripts, add makefile to each example
Browse files Browse the repository at this point in the history
  • Loading branch information
stano45 committed Jul 30, 2024
1 parent 5465a1f commit 77e8833
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 43 deletions.
32 changes: 6 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
SHELL := /bin/bash
EXAMPLES_PATH := ./examples

PROCESS_MIGRATION_PATH := $(EXAMPLES_PATH)/process_migration
CONTAINER_MIGRATION_PATH := $(EXAMPLES_PATH)/host_containers
SWITCH_CONTAINER_PATH := $(EXAMPLES_PATH)/switch_container

# Select the example to run
SELECTED_EXAMPLE := $(PROCESS_MIGRATION_PATH)

all: compile net control
all:

compile:
cd load_balancer && make
cd /home/p4/p4containerflow/load_balancer && make

net: clean
cd $(SELECTED_EXAMPLE) && ./build.sh
control_multi_switch:
cd /home/p4/p4containerflow/controller && sleep 2 && ./controller.py --multi_switch=True

control:
cd controller && sleep 2 && ./controller.py --multi_switch=True

migrate:
@if [ "${SOURCE}" = "" ] || [ "${TARGET}" = "" ]; then \
echo "Usage: make migrate SOURCE=x TARGET=y"; \
else \
cd $(SELECTED_EXAMPLE) && ./cr.sh ${SOURCE} ${TARGET}; \
fi

clean:
cd $(SELECTED_EXAMPLE) && ./teardown.sh
cd /home/p4/p4containerflow/controller && sleep 2 && ./controller.py

images:
cd tcp && make
cd /home/p4/p4containerflow/tcp && make

tcp-client:
sudo podman run -it --rm --replace --name tcp-client --pod h1-pod tcp-client
Expand Down
25 changes: 21 additions & 4 deletions examples/host_containers/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
all: h1 h2 h3 h4
include ../../Makefile

all: compile build control_multi_switch

terminals: h1 h2 h3 h4

build: teardown
./build.sh

teardown:
./teardown.sh

migrate:
@if [ "${SOURCE}" = "" ] || [ "${TARGET}" = "" ]; then \
echo "Usage: make migrate SOURCE=x TARGET=y"; \
else \
./cr.sh ${SOURCE} ${TARGET}; \
fi

h1:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h1" -hold -e "sudo podman rm -f tcp-client && sudo podman run --name tcp-client --pod h1-pod tcp-client" &

h2:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h2" -hold -e "sudo podman logs -f server2" &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h2" -hold -e "sudo podman logs -f h2" &

h3:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h3" -hold -e "sudo podman logs -f server3" &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h3" -hold -e "sudo podman logs -f h3" &

h4:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h4" -hold -e "sudo podman logs -f server4" &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h4" -hold -e "sudo podman logs -f h4" &
68 changes: 65 additions & 3 deletions examples/host_containers/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
BUILD_DIR=../../load_balancer/build
PCAP_DIR=../../load_balancer/pcaps
LOG_DIR=../../load_balancer/logs

NUM_HOSTS=4

Expand All @@ -16,9 +19,9 @@ for i in $(seq 1 $NUM_HOSTS); do
NET="h${i}-net"
POD="h${i}-pod"
CONTAINER="h${i}"
SUBNET="10.${i}.${i}.0/24"
GATEWAY="10.${i}.${i}.${i}0"
CONTAINER_IP="10.${i}.${i}.${i}"
SUBNET="10.0.${i}.0/24"
GATEWAY="10.0.${i}.${i}0"
CONTAINER_IP="10.0.${i}.${i}"
CONTAINER_MAC="08:00:00:00:0${i}:0${i}"
BRIDGE="h${i}-br"
VETH="h${i}-veth"
Expand Down Expand Up @@ -106,3 +109,62 @@ sudo sysctl -w net.ipv4.ip_forward=1

sudo podman kill h4
sudo podman rm -f h4

# Run switches
sudo simple_switch_grpc \
-i 1@s1-eth1 \
-i 2@s1-eth2 \
-i 3@s1-eth3 \
-i 4@s1-eth4 \
--pcap ${PCAP_DIR} \
--device-id 0 \
${BUILD_DIR}/load_balance.json \
--log-console \
--thrift-port 9090 \
-- \
--grpc-server-addr 0.0.0.0:50051 > ${LOG_DIR}/s1.log \
> ${LOG_DIR}/s1.log \
2>&1 & \
echo $!

sudo simple_switch_grpc \
-i 1@s2-eth1 \
-i 2@s2-eth2 \
--pcap ${PCAP_DIR} \
--device-id 1 \
${BUILD_DIR}/load_balance.json \
--log-console \
--thrift-port 9091 \
-- \
--grpc-server-addr 0.0.0.0:50052 > ${LOG_DIR}/s2.log \
> ${LOG_DIR}/s2.log \
2>&1 & \
echo $!

sudo simple_switch_grpc \
-i 1@s3-eth1 \
-i 2@s3-eth2 \
--pcap ${PCAP_DIR} \
--device-id 2 \
${BUILD_DIR}/load_balance.json \
--log-console \
--thrift-port 9092 \
-- \
--grpc-server-addr 0.0.0.0:50053 \
> ${LOG_DIR}/s3.log \
2>&1 & \
echo $!

sudo simple_switch_grpc \
-i 1@s4-eth1 \
-i 2@s4-eth2 \
--pcap ${PCAP_DIR} \
--device-id 3 \
${BUILD_DIR}/load_balance.json \
--log-console \
--thrift-port 9093 \
-- \
--grpc-server-addr 0.0.0.0:50054 \
> ${LOG_DIR}/s4.log \
2>&1 & \
echo $!
4 changes: 2 additions & 2 deletions examples/host_containers/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CHECKPOINT_DIR=/tmp/checkpoints
CHECKPOINT_PATH=$CHECKPOINT_DIR/checkpoint.tar

SOURCE_HOST=h$SOURCE_IDX
SOURCE_IP=10.$SOURCE_IDX.$SOURCE_IDX.$SOURCE_IDX
SOURCE_IP=10.0.$SOURCE_IDX.$SOURCE_IDX

TARGET_HOST=h$TARGET_IDX
TARGET_IP=10.$TARGET_IDX.$TARGET_IDX.$TARGET_IDX
TARGET_IP=10.0.$TARGET_IDX.$TARGET_IDX
TARGET_MAC=08:00:00:00:0$TARGET_IDX:0$TARGET_IDX

sudo mkdir -p $CHECKPOINT_DIR
Expand Down
2 changes: 2 additions & 0 deletions examples/host_containers/teardown.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
NUM_HOSTS=4

sudo killall -s 9 simple_switch_grpc
sudo killall -s 9 xterm

for i in $(seq 1 $NUM_HOSTS); do
sudo podman container kill h${i}
Expand Down
22 changes: 20 additions & 2 deletions examples/process_migration/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
all: h1 h2 h3 h4
include ../../Makefile
SHELL := /bin/bash

all: compile build control_multi_switch

terminals: h1 h2 h3 h4

build: teardown
./build.sh

teardown:
./teardown.sh

migrate:
@if [ "${SOURCE}" = "" ] || [ "${TARGET}" = "" ]; then \
echo "Usage: make migrate SOURCE=x TARGET=y"; \
else \
./cr.sh ${SOURCE} ${TARGET}; \
fi

h1:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h1" -hold -e "sudo ip netns exec h1 /bin/bash" &
Expand All @@ -10,4 +28,4 @@ h3:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h3" -hold -e "sudo ip netns exec h3 /bin/bash" &

h4:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h4" -hold -e "sudo ip netns exec h4 /bin/bash" &
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h4" -hold -e "sudo ip netns exec h4 /bin/bash" &
4 changes: 2 additions & 2 deletions examples/process_migration/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CHECKPOINT_DIR=/tmp/checkpoints
CHECKPOINT_PATH=$CHECKPOINT_DIR/checkpoint.tar

SOURCE_HOST=h$SOURCE_IDX
SOURCE_IP=10.$SOURCE_IDX.$SOURCE_IDX.$SOURCE_IDX
SOURCE_IP=10.0.$SOURCE_IDX.$SOURCE_IDX

TARGET_HOST=h$TARGET_IDX
TARGET_IP=10.$TARGET_IDX.$TARGET_IDX.$TARGET_IDX
TARGET_IP=10.0.$TARGET_IDX.$TARGET_IDX
TARGET_MAC=08:00:00:00:0$TARGET_IDX:0$TARGET_IDX

# Creating checkpoint directory
Expand Down
1 change: 0 additions & 1 deletion examples/process_migration/kill_server.sh

This file was deleted.

30 changes: 30 additions & 0 deletions examples/switch_container/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include ../../Makefile

all: compile build control

terminals: h1 h2 h3 h4

build: teardown
./build.sh

teardown:
./teardown.sh

migrate:
@if [ "${SOURCE}" = "" ] || [ "${TARGET}" = "" ]; then \
echo "Usage: make migrate SOURCE=x TARGET=y"; \
else \
./cr.sh ${SOURCE} ${TARGET}; \
fi

h1:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h1" -hold -e "sudo podman rm -f tcp-client && sudo podman run --name tcp-client --pod h1-pod tcp-client" &

h2:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h2" -hold -e "sudo podman logs -f h2" &

h3:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h3" -hold -e "sudo podman logs -f h3" &

h4:
xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T "h4" -hold -e "sudo podman logs -f h4" &
4 changes: 2 additions & 2 deletions examples/switch_container/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CHECKPOINT_DIR=/tmp/checkpoints
CHECKPOINT_PATH=$CHECKPOINT_DIR/checkpoint.tar

SOURCE_HOST=h$SOURCE_IDX
SOURCE_IP=10.$SOURCE_IDX.$SOURCE_IDX.$SOURCE_IDX
SOURCE_IP=10.0.$SOURCE_IDX.$SOURCE_IDX

TARGET_HOST=h$TARGET_IDX
TARGET_IP=10.$TARGET_IDX.$TARGET_IDX.$TARGET_IDX
TARGET_IP=10.0.$TARGET_IDX.$TARGET_IDX
TARGET_MAC=08:00:00:00:0$TARGET_IDX:0$TARGET_IDX

# Creating checkpoint directory
Expand Down
2 changes: 1 addition & 1 deletion load_balancer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LOG_DIR = logs

all: compile

compile: dirs
compile: clean dirs
p4c-bm2-ss --p4v 16 --p4runtime-files $(BUILD_DIR)/load_balance.p4.p4info.txt -o $(BUILD_DIR)/load_balance.json load_balance.p4

dirs:
Expand Down

0 comments on commit 77e8833

Please sign in to comment.