Skip to content

Commit

Permalink
Working client & controller images
Browse files Browse the repository at this point in the history
  • Loading branch information
stano45 committed Sep 2, 2024
1 parent 1d9bd0b commit 14fa955
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 8 deletions.
51 changes: 51 additions & 0 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1

ENV DEPS libreadline-dev \
valgrind \
libtool-bin \
libprotobuf-dev \
protobuf-compiler \
protobuf-compiler-grpc \
libgrpc-dev \
libgrpc++-dev \
git \
make \
automake \
build-essential \
g++ \
libtool \
pkg-config \
ca-certificates \
libboost-dev \
libboost-system-dev \
libboost-thread-dev

WORKDIR /app

COPY controller.py /app/
COPY node_manager.py /app/
COPY switch_controller.py /app/
COPY p4runtime_lib /app/p4runtime_lib
COPY requirements.txt /app/

RUN pip install --no-cache-dir -r requirements.txt && \
apt-get update && \
apt-get install -y --no-install-recommends $DEPS && \
git clone https://github.com/p4lang/PI.git && \
cd PI && \
git checkout 05cb92564af77ae4826565cbde84e3fd4960c6bd && \
git submodule update --init --recursive && \
./autogen.sh && \
./configure --with-proto --without-internal-rpc --without-cli --without-bmv2 && \
make -j2 && \
make install-strip && \
ldconfig && \
apt-get purge -y $DEPS && \
apt-get autoremove --purge -y && \
apt-get clean && \
rm -rf /app/PI /var/lib/apt/lists/* /tmp/* /var/tmp/*


ENTRYPOINT ["python3", "controller.py"]
8 changes: 5 additions & 3 deletions requirements.txt → controller/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
beautifulsoup4==4.12.3
blinker==1.8.2
click==8.1.7
Flask==3.0.3
grpcio==1.64.1
grpcio==1.66.1
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
protobuf==3.20.0
protobuf==5.28.0
scapy==2.5.0
Werkzeug==3.0.3
soupsieve==2.6
Werkzeug==3.0.4
13 changes: 13 additions & 0 deletions examples/container_migration_in_kubernetes/config/switches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"id": 0,
"name": "s1",
"addr": "0.0.0.0:50051",
"proto_dump_file": "/config/s1-p4runtime-requests.txt",
"runtime_file": "/config/s1-runtime.json",
"p4info_file_path": "/config/load_balance.p4.p4info.txt",
"bmv2_file_path": "/config/load_balance.json",
"master": true,
"lb_nodes": [{ "ip": "10.0.2.2", "mac": "08:00:00:00:02:02", "port": 2 }]
}
]
11 changes: 11 additions & 0 deletions examples/container_migration_in_kubernetes/http-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY main.py /app/

RUN pip install requests

CMD ["python3", "main.py"]
26 changes: 26 additions & 0 deletions examples/container_migration_in_kubernetes/http-client/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import os
import time

import requests


def main():
server_ip = os.getenv("SERVER_IP", "localhost")
server_port = os.getenv("SERVER_PORT", "12345")

server_url = f"http://{server_ip}:{server_port}"
print(f"Connecting to server at: {server_url}")
while True:
try:
response = requests.get(server_url)
print("Server Response:")
print(response.text)
except requests.exceptions.RequestException as e:
print(f"Error connecting to server: {e}")
time.sleep(5)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-client
labels:
app: http-client
spec:
replicas: 1
selector:
matchLabels:
app: http-client
template:
metadata:
labels:
app: http-client
spec:
containers:
- name: http-client
image: docker.io/skosorin/http-client
imagePullPolicy: IfNotPresent
resources:
requests:
memory: "128Mi"
cpu: "0.5"
limits:
memory: "256Mi"
cpu: "1"
env:
# P4 load balancer IP
- name: SERVER_IP
value: "10.0.1.10"
- name: SERVER_PORT
value: "12345"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: http-server
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app: http-server
Expand All @@ -16,7 +16,14 @@ spec:
spec:
containers:
- name: http-server
image: quay.io/radostin/http-server:latest
image: docker.io/skosorin/http-server
imagePullPolicy: IfNotPresent
ports:
- containerPort: 12345
resources:
requests:
memory: "128Mi"
cpu: "0.5"
limits:
memory: "256Mi"
cpu: "1"
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ spec:
- protocol: TCP
port: 12345
targetPort: 12345
nodePort: 30001 # Set a specific NodePort value
type: NodePort
type: ClusterIP
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ spec:
subPath: load_balance.json
- name: pcap-dir
mountPath: /pcaps
resources:
requests:
memory: "128Mi"
cpu: "0.5"
limits:
memory: "256Mi"
cpu: "1"
volumes:
- name: cni-bin
hostPath:
Expand Down
5 changes: 5 additions & 0 deletions examples/container_migration_in_kubernetes/rst.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo sysctl -w net.ipv4.ip_forward=1
sudo kubeadm reset -f
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --cri-socket=unix:///var/run/crio/crio.sock

Expand All @@ -10,4 +11,8 @@ kubectl taint nodes --all node-role.kubernetes.io/control-plane-

kubectl apply -f manifests/kube-router-daemonset.yaml

sleep 5
kubectl apply -f manifests/http-server-deployment.yaml
kubectl apply -f manifests/http-client-deployment.yaml

kubectl get pods --all-namespaces
2 changes: 1 addition & 1 deletion scripts/install_pi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sudo apt-get install -y \

pip3 install protobuf==3.20.0

git clone --depth 1 --branch main https://github.com/p4lang/PI.git
git clone https://github.com/p4lang/PI.git
cd PI
git checkout 05cb92564af77ae4826565cbde84e3fd4960c6bd
git submodule update --init --recursive
Expand Down

0 comments on commit 14fa955

Please sign in to comment.