Added deployment scripts

This commit is contained in:
Alberto Soutullo 2023-12-04 19:21:29 +01:00
parent 59a2cbb5e5
commit 6d58b0fd50
No known key found for this signature in database
GPG Key ID: A7CAC0D8343B0387
18 changed files with 3253 additions and 4 deletions

8
README.md Executable file → Normal file
View File

@ -3,10 +3,10 @@
**Python Version**: 3.11.5
### Main objectives
- [ ] Automatic deployment of any P2P utils
- [ ] Deployment of 10k Gossipsub / Waku relay nodes
- [ ] Bandwidth usage per node
- [ ] Log data for analysis
- [X] Automatic deployment of any P2P utils
- [X] Deployment of 10k Gossipsub / Waku relay nodes
- [X] Bandwidth usage per node
- [X] Log data for analysis
### Secondary objectives
- [ ] Add QoS parameter support to the 10k tool
- [ ] Run further Waku protocols:

View File

@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-app-configmap
namespace: 10k-namespace
data:
PEERS: "150"
CONNECTTO: "10"
PEERSPERPOD: "1"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,141 @@
#!/bin/bash
# Check if 'yq' is installed
if ! command -v yq &>/dev/null; then
echo "Error: 'yq' command not found. Please install it and make sure it's in your PATH."
exit 1
fi
read -p "Yaml template file: " YAML_FILE
if [ ! -f "$YAML_FILE" ]; then
echo "YAML file not found: $YAML_FILE"
exit 1
fi
read -p "Minute to run the node: " minute
read -p "Hour to run the node: " hour
read -p "Enter the new number of replicas (PODs): " NEW_REPLICAS
yq e ".spec.replicas = $NEW_REPLICAS" -i "$YAML_FILE"
MODIFIED_REPLICAS=$(yq e ".spec.replicas" "$YAML_FILE")
if [ "$MODIFIED_REPLICAS" -eq "$NEW_REPLICAS" ]; then
echo "Replicas in Yaml updated to $NEW_REPLICAS"
else
echo "Failed to update replicas in Yaml"
exit 1
fi
# Number of containers to add
read -p "Enter how many containers per POD: " num_containers
total_peers=$((NEW_REPLICAS*num_containers))
# Create a copy to append
cp "$YAML_FILE" "deploy.yaml"
# Loop to generate and append instances
for ((i=0; i<num_containers; i++)); do
cat <<EOF >> "deploy.yaml"
- name: container-$i
image: dst-test-node:local
ports:
- containerPort: 5000
args: ["$minute", "$hour"]
env:
- name: PEERNUMBER
value: "$i"
- name: PEERS
valueFrom:
configMapKeyRef:
name: my-app-configmap
key: PEERS
- name: CONNECTTO
valueFrom:
configMapKeyRef:
name: my-app-configmap
key: CONNECTTO
- name: PEERSPERPOD
valueFrom:
configMapKeyRef:
name: my-app-configmap
key: PEERSPERPOD
EOF
done
# Loop to generate and append instances
for ((i=0; i<$NEW_REPLICAS; i++)); do
cat <<EOF >> "deploy.yaml"
---
apiVersion: v1
kind: Service
metadata:
name: pod-$i
namespace: 10k-namespace
spec:
selector:
statefulset.kubernetes.io/pod-name: pod-$i
ports:
EOF
for ((port=5000; port<$((5000 + num_containers)); port++)); do
cat <<EOF >> "deploy.yaml"
- name: port-$port
protocol: TCP
port: $port
targetPort : $port
EOF
done
cat <<EOF >> "deploy.yaml"
type: ClusterIP
EOF
done
rm config-map.yaml
cat <<EOF >> "config-map.yaml"
apiVersion: v1
kind: ConfigMap
metadata:
name: my-app-configmap
namespace: 10k-namespace
data:
PEERS: "$total_peers"
CONNECTTO: "10"
PEERSPERPOD: "$num_containers"
EOF
rm network-policy.yaml
cat <<EOF >> "network-policy.yaml"
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: internal-policy
namespace: 10k-namespace
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: monitoring
egress:
- {}
EOF
sudo kubectl create namespace 10k-namespace
sudo kubectl apply -f config-map.yaml -n 10k-namespace
sudo kubectl apply -f network-policy.yaml
sudo kubectl apply -f deploy.yaml
echo "Done"

View File

@ -0,0 +1,18 @@
#!/bin/bash
# Define the range of pod numbers
pod_range=({0..149})
# Iterate through each pod in the range
for pod_number in "${pod_range[@]}"; do
# Formulate the pod name
pod_name="pod-$pod_number"
# Formulate the output filename based on pod and container
output_file="logs_${pod_name}.txt"
# Redirect logs to the file
sudo kubectl logs -n 10k-namespace -c "$container_name" "$pod_name" > "logs/$output_file"
echo "Logs for $pod_name saved to $output_file"
done

View File

@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: internal-policy
namespace: 10k-namespace
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: monitoring
egress:
- {}

View File

@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: pod
namespace: 10k-namespace
spec:
replicas: 150
podManagementPolicy: "Parallel"
selector:
matchLabels:
app: pod
template:
metadata:
labels:
app: pod
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: machine
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: pod
containers:

View File

@ -0,0 +1,89 @@
apiVersion: v1
kind: Pod
metadata:
name: bootstrap-1
namespace: zerotesting
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- metal-01.he-eu-hel1.vacdst.misc
containers:
- name: bootstrap-container-1
image: wakuorg/nwaku:wakunode_dst
ports:
- containerPort: 8545
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
command:
- sh
- -c
- /usr/bin/wakunode --relay=true --rpc-admin=true --keep-alive=true --max-connections=250 --discv5-discovery=true --discv5-enr-auto-update=True --log-level=INFO --rpc-address=0.0.0.0 --metrics-server=True --metrics-server-address=0.0.0.0 --nat=extip:$IP --pubsub-topic="/waku/2/kubetopic"
---
apiVersion: v1
kind: Pod
metadata:
name: bootstrap-2
namespace: zerotesting
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- metal-01.he-eu-fsn1.vacdst.misc
containers:
- name: bootstrap-container
image: wakuorg/nwaku:wakunode_dst
ports:
- containerPort: 8545
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
command:
- sh
- -c
- /usr/bin/wakunode --relay=true --rpc-admin=true --keep-alive=true --max-connections=250 --discv5-discovery=true --discv5-enr-auto-update=True --log-level=INFO --rpc-address=0.0.0.0 --metrics-server=True --metrics-server-address=0.0.0.0 --nat=extip:$IP --pubsub-topic="/waku/2/kubetopic"
---
apiVersion: v1
kind: Pod
metadata:
name: bootstrap-3
namespace: zerotesting
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- metal-02.he-eu-hel1.vacdst.misc
containers:
- name: bootstrap-container
image: wakuorg/nwaku:wakunode_dst
ports:
- containerPort: 8545
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
command:
- sh
- -c
- /usr/bin/wakunode --relay=true --rpc-admin=true --keep-alive=true --max-connections=250 --discv5-discovery=true --discv5-enr-auto-update=True --log-level=INFO --rpc-address=0.0.0.0 --metrics-server=True --metrics-server-address=0.0.0.0 --nat=extip:$IP --pubsub-topic="/waku/2/kubetopic"

View File

@ -0,0 +1,178 @@
#!/bin/bash
# Check if 'yq' is installed
if ! command -v yq &>/dev/null; then
echo "Error: 'yq' command not found. Please install it and make sure it's in your PATH."
exit 1
fi
read -p "Enter the new number of replicas (PODs): " pods
yq e ".spec.replicas = $pods" -i "template.yaml"
modified_pods=$(yq e ".spec.replicas" "template.yaml")
if [ "$modified_pods" -eq "$pods" ]; then
echo "Replicas in Yaml updated to $pods"
else
echo "Failed to update replicas in Yaml"
exit 1
fi
# Number of containers to add
read -p "Enter how many containers per POD: " num_containers
total_peers=$((pods*num_containers))
# Create a copy to append
cp "template.yaml" "deploy.yaml"
# Loop to generate and append instances
for ((i=0; i<num_containers; i++)); do
cat <<EOF >> "deploy.yaml"
- name: container-$i
image: wakuorg/nwaku:wakunode_dst
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENR1
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR1
- name: ENR2
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR2
- name: ENR3
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR3
command:
- sh
- -c
- /usr/bin/wakunode --relay=true --rpc-admin=true --max-connections=250 --rpc-address=0.0.0.0 --rest=true --rest-admin=true --rest-private=true --rest-address=0.0.0.0 --discv5-discovery=true --discv5-enr-auto-update=True --log-level=INFO --rpc-address=0.0.0.0 --metrics-server=True --metrics-server-address=0.0.0.0 --discv5-bootstrap-node=\$ENR1 --discv5-bootstrap-node=\$ENR2 --discv5-bootstrap-node=\$ENR3 --nat=extip:\${IP} --pubsub-topic="/waku/2/kubetopic" --ports-shift=$i
EOF
done
sudo kubectl -n zerotesting delete networkpolicy zerotesting-policy
sudo kubectl create namespace zerotesting
sudo kubectl apply -f bootstrap.yaml
echo "Sleeping 10 seconds to let bootstrap to set up..."
sleep 10
echo "Getting bootstrap ips..."
pod_ips=()
ip_1=$(sudo kubectl get pod bootstrap-1 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_1")
echo $ip_1
ip_2=$(sudo kubectl get pod bootstrap-2 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_2")
echo $ip_2
ip_3=$(sudo kubectl get pod bootstrap-3 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_3")
echo $ip_3
if [ -z "$pod_ips" ]; then
echo "Error: Unable to retrieve pod IP."
exit 1
fi
config_map_yaml="apiVersion: v1
kind: ConfigMap
metadata:
name: pod-enr-config
namespace: zerotesting
data:"
index=1
for pod_ip in "${pod_ips[@]}"; do
enr=$(wget -O - --post-data='{"jsonrpc":"2.0","method":"get_waku_v2_debug_v1_info","params":[],"id":1}' --header='Content-Type:application/json' $pod_ip:8545 2> /dev/null | sed 's/.*"enrUri":"\([^"]*\)".*/\1/')
echo $enr
if [ -z "$enr" ]; then
echo "Error: Unable to retrieve bootstrap ENR."
exit 1
fi
config_map_yaml+="\n ENR$index: \"$enr\""
((index++))
done
echo -e "$config_map_yaml" > config-map.yaml
sudo kubectl delete -f config-map.yaml -n zerotesting
sudo kubectl apply -f config-map.yaml
echo "Adding services to yaml"
# Loop to generate and append instances
for ((i=0; i<pods; i++)); do
cat <<EOF >> "deploy.yaml"
---
apiVersion: v1
kind: Service
metadata:
name: nodes-$i
namespace: zerotesting
spec:
selector:
statefulset.kubernetes.io/pod-name: nodes-$i
ports:
EOF
for ((port=8645; port<$((8645 + num_containers)); port++)); do
cat <<EOF >> "deploy.yaml"
- name: port-$port
protocol: TCP
port: $port
targetPort : $port
EOF
done
cat <<EOF >> "deploy.yaml"
type: ClusterIP
EOF
done
sudo kubectl apply -f network-policy.yaml
echo "Deploying nodes..."
sudo kubectl apply -f deploy.yaml
echo "Waiting 30 seconds to deploy publisher..."
sleep 30
rm publisher.yaml
cat <<EOF >> "publisher.yaml"
apiVersion: v1
kind: Pod
metadata:
name: publisher
namespace: zerotesting
spec:
containers:
- name: publisher-container
image: publisher:local
volumeMounts:
- name: data-volume
mountPath: /publisher
command:
- sh
- -c
- python /publisher/traffic.py --multiple-nodes=http://nodes-[0..$pods]:8645 --msg-size-kbytes=10 --delay-seconds=1 -cpp $num_containers
volumes:
- name: data-volume
hostPath:
path: /home/alber/10k/waku/publisher_script
EOF
echo "Deploying publisher"
sudo kubectl apply -f publisher.yaml
echo "Done"

View File

@ -0,0 +1,197 @@
#!/bin/bash
# Check if 'yq' is installed
if ! command -v yq &>/dev/null; then
echo "Error: 'yq' command not found. Please install it and make sure it's in your PATH."
exit 1
fi
read -p "Enter the number of batches: " batches
read -p "Enter the new number of replicas (PODs) per batch: " pods
yq e ".spec.replicas = $pods" -i "template.yaml"
modified_pods=$(yq e ".spec.replicas" "template.yaml")
if [ "$modified_pods" -eq "$pods" ]; then
echo "Replicas in Yaml updated to $pods"
else
echo "Failed to update replicas in Yaml"
exit 1
fi
# Number of containers to add
read -p "Enter how many containers per POD: " num_containers
total_peers=$((pods*num_containers))
# Create a copy to append
cp "template.yaml" "deploy-batch-0.yaml"
# Loop to generate and append instances
for ((i=0; i<num_containers; i++)); do
cat <<EOF >> "deploy-batch-0.yaml"
- name: container-$i
image: wakuorg/nwaku:wakunode_dst
env:
- name: IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: ENR1
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR1
- name: ENR2
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR2
- name: ENR3
valueFrom:
configMapKeyRef:
name: pod-enr-config
key: ENR3
command:
- sh
- -c
- /usr/bin/wakunode --relay=true --rpc-admin=true --max-connections=250 --rpc-address=0.0.0.0 --rest=true --rest-admin=true --rest-private=true --rest-address=0.0.0.0 --discv5-discovery=true --discv5-enr-auto-update=True --log-level=INFO --rpc-address=0.0.0.0 --metrics-server=True --metrics-server-address=0.0.0.0 --discv5-bootstrap-node=\$ENR1 --discv5-bootstrap-node=\$ENR2 --discv5-bootstrap-node=\$ENR3 --nat=extip:\${IP} --pubsub-topic="/waku/2/kubetopic" --ports-shift=$i
EOF
done
for ((i=1; i<batches; i++)); do
cp "deploy-batch-0.yaml" "deploy-batch-$i.yaml"
yq e '.metadata.name = "nodes-'$i'"' -i "deploy-batch-$i.yaml"
yq e '.spec.selector.matchLabels.app = "nodes-'$i'"' -i "deploy-batch-$i.yaml"
yq e '.spec.template.metadata.labels.app = "nodes-'$i'"' -i "deploy-batch-$i.yaml"
yq e '.spec.template.spec.topologySpreadConstraints[0].labelSelector.matchLabels.type = "nodes-'$i'"' -i "deploy-batch-$i.yaml"
done
sudo kubectl -n zerotesting delete networkpolicy zerotesting-policy
sudo kubectl create namespace zerotesting
sudo kubectl apply -f bootstrap.yaml
echo "Sleeping 10 seconds to let bootstrap to set up..."
sleep 10
echo "Getting bootstrap ips..."
pod_ips=()
ip_1=$(sudo kubectl get pod bootstrap-1 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_1")
echo $ip_1
ip_2=$(sudo kubectl get pod bootstrap-2 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_2")
echo $ip_2
ip_3=$(sudo kubectl get pod bootstrap-3 -n zerotesting -o jsonpath='{.status.podIP}')
pod_ips+=("$ip_3")
echo $ip_3
if [ -z "$pod_ips" ]; then
echo "Error: Unable to retrieve pod IP."
exit 1
fi
config_map_yaml="apiVersion: v1
kind: ConfigMap
metadata:
name: pod-enr-config
namespace: zerotesting
data:"
index=1
for pod_ip in "${pod_ips[@]}"; do
enr=$(wget -O - --post-data='{"jsonrpc":"2.0","method":"get_waku_v2_debug_v1_info","params":[],"id":1}' --header='Content-Type:application/json' $pod_ip:8545 2> /dev/null | sed 's/.*"enrUri":"\([^"]*\)".*/\1/')
echo $enr
if [ -z "$enr" ]; then
echo "Error: Unable to retrieve bootstrap ENR."
exit 1
fi
config_map_yaml+="\n ENR$index: \"$enr\""
((index++))
done
echo -e "$config_map_yaml" > config-map.yaml
sudo kubectl delete -f config-map.yaml -n zerotesting
sudo kubectl apply -f config-map.yaml
echo "Adding services to yaml"
# Loop to generate and append instances
for ((j=0; j<batches; j++)); do
for ((i=0; i<pods; i++)); do
cat <<EOF >> "services.yaml"
apiVersion: v1
kind: Service
metadata:
name: nodes-$((i + pods*j))
namespace: zerotesting
spec:
selector:
statefulset.kubernetes.io/pod-name: nodes-$j-$i
ports:
EOF
for ((port=8645; port<$((8645 + num_containers)); port++)); do
cat <<EOF >> "services.yaml"
- name: port-$port
protocol: TCP
port: $port
targetPort : $port
EOF
done
cat <<EOF >> "services.yaml"
type: ClusterIP
---
EOF
done
done
sudo kubectl apply -f network-policy.yaml
echo "Deploying nodes..."
for ((i=0; i<batches; i++)); do
sudo kubectl apply -f deploy-batch-$i.yaml
echo "Waiting 60 seconds for next batch..."
sleep 60
done
echo "Creating services..."
sudo kubectl apply -f services.yaml
echo "Waiting 30 seconds to deploy publisher..."
sleep 30
rm publisher.yaml
cat <<EOF >> "publisher.yaml"
apiVersion: v1
kind: Pod
metadata:
name: publisher
namespace: zerotesting
spec:
containers:
- name: publisher-container
image: publisher:local
volumeMounts:
- name: data-volume
mountPath: /publisher
command:
- sh
- -c
- python /publisher/traffic.py --multiple-nodes=http://nodes-[0..$pods]:8645 --msg-size-kbytes=10 --delay-seconds=1 -cpp $num_containers
volumes:
- name: data-volume
hostPath:
path: /home/alber/10k/waku/publisher_script
EOF
echo "Deploying publisher"
sudo kubectl apply -f publisher.yaml
echo "Done"

View File

@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: zerotesting-policy
namespace: zerotesting
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: monitoring
egress:
- {}

View File

@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: publisher
namespace: zerotesting
spec:
containers:
- name: publisher-container
image: publisher:local
volumeMounts:
- name: data-volume
mountPath: /publisher
command:
- sh
- -c
- python /publisher/traffic.py --multiple-nodes=http://nodes-[0..1000]:8645 --msg-size-kbytes=10 --delay-seconds=1 -cpp 1
volumes:
- name: data-volume
hostPath:
path: /home/alber/10k/waku/publisher_script

View File

@ -0,0 +1,3 @@
FROM python:3.9.18-alpine3.18
RUN pip install requests argparse aiohttp

View File

@ -0,0 +1,103 @@
import time
import os
import base64
import urllib.parse
import argparse
import aiohttp
import asyncio
async def send_waku_msg(node_address, kbytes, pubsub_topic, content_topic):
# TODO dirty trick .replace("=", "")
base64_payload = (base64.b64encode(os.urandom(kbytes*1000)).decode('ascii')).replace("=", "")
print("size message kBytes", len(base64_payload) *(3/4)/1000, "KBytes")
body = {
"payload": base64_payload,
"contentTopic": content_topic,
"version": 1, # You can adjust the version as needed
#"timestamp": int(time.time())
}
encoded_pubsub_topic = urllib.parse.quote(pubsub_topic, safe='')
url = f"{node_address}/relay/v1/messages/{encoded_pubsub_topic}"
headers = {'content-type': 'application/json'}
print('Waku REST API: %s PubSubTopic: %s, ContentTopic: %s' % (url, pubsub_topic, content_topic))
s_time = time.time()
response = None
try:
async with aiohttp.ClientSession() as session:
async with session.post(url, json=body, headers=headers) as response:
response_text = await response.text()
elapsed_ms = (time.time() - s_time) * 1000
print('Response from %s: status:%s content:%s [%.4f ms.]' % (
node_address, response.status, response_text, elapsed_ms))
except Exception as e:
print(f"Error sending request: {e}")
async def main(nodes):
for node in nodes:
await send_waku_msg(node, args.msg_size_kbytes, args.pubsub_topic, args.content_topic)
print(f"Message sent to {node} at {time.strftime('%H:%M:%S')}")
await asyncio.sleep(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
# these flags are mutually exclusive, one or the other, never at once
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-sn', '--single-node', type=str,
help='example: http://waku-simulator_nwaku_1:8645')
group.add_argument('-mn', '--multiple-nodes', type=str,
help='example: http://waku-simulator_nwaku_[1..10]:8645')
# rest of arguments
parser.add_argument('-c', '--content-topic', type=str, help='content topic', default="kubekube")
parser.add_argument('-p', '--pubsub-topic', type=str, help='pubsub topic',
default="/waku/2/kubetopic")
parser.add_argument('-s', '--msg-size-kbytes', type=int, help='message size in kBytes',
default=10)
parser.add_argument('-d', '--delay-seconds', type=int, help='delay in second between messages')
parser.add_argument('-cpp', '--containers-per-pod', type=int,
help='number of containers in pod', default=1)
args = parser.parse_args()
print(args)
if args.single_node != None:
print("Injecting traffic to single node REST API:", args.single_node)
# this simply converts from http://url_[1..5]:port to
# [http://url_1:port
nodes = []
if args.multiple_nodes:
range_nodes = args.multiple_nodes.split(":")[1].split("-")[1]
port_nodes = args.multiple_nodes.split(":")[-1]
node_placeholder = args.multiple_nodes.replace(range_nodes, "{placeholder}")
node_placeholder = node_placeholder.replace(port_nodes, "{port}")
clean_range = range_nodes.replace("[", "").replace("]", "")
start = int(clean_range.split("..")[0])
end = int(clean_range.split("..")[1])
print("Injecting traffic to multiple nodes REST APIs")
for i in range(start, end):
for j in range(0, args.containers_per_pod):
nodes.append(node_placeholder.replace("{placeholder}", str(i)).replace("{port}",
str(8645 + j)))
for node in nodes:
print(node)
# Run the asynchronous main function within an event loop
loop = asyncio.get_event_loop()
while True:
try:
loop.run_until_complete(main(nodes))
except KeyboardInterrupt:
break

View File

@ -0,0 +1,100 @@
import time
import os
import base64
import urllib.parse
import argparse
import aiohttp
import asyncio
async def send_waku_msg(node_address, kbytes, pubsub_topic, content_topic):
# TODO dirty trick .replace("=", "")
base64_payload = (base64.b64encode(os.urandom(kbytes*1000)).decode('ascii')).replace("=", "")
print("size message kBytes", len(base64_payload) *(3/4)/1000, "KBytes")
body = {
"payload": base64_payload,
"contentTopic": content_topic,
"version": 1, # You can adjust the version as needed
#"timestamp": int(time.time())
}
encoded_pubsub_topic = urllib.parse.quote(pubsub_topic, safe='')
url = f"{node_address}/relay/v1/messages/{encoded_pubsub_topic}"
headers = {'content-type': 'application/json'}
print('Waku REST API: %s PubSubTopic: %s, ContentTopic: %s' % (url, pubsub_topic, content_topic))
s_time = time.time()
response = None
try:
async with aiohttp.ClientSession() as session:
async with session.post(url, json=body, headers=headers) as response:
response_text = await response.text()
elapsed_ms = (time.time() - s_time) * 1000
print('Response from %s: status:%s content:%s [%.4f ms.]' % (
node_address, response.status, response_text, elapsed_ms))
except Exception as e:
print(f"Error sending request: {e}")
async def main(nodes, args):
background_tasks = set()
while True:
for node in nodes:
task = asyncio.create_task(send_waku_msg(node, args.msg_size_kbytes, args.pubsub_topic, args.content_topic))
print(f"Message sent to {node} at {time.strftime('%H:%M:%S')}")
background_tasks.add(task)
task.add_done_callback(background_tasks.discard)
await asyncio.sleep(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
# these flags are mutually exclusive, one or the other, never at once
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-sn', '--single-node', type=str,
help='example: http://waku-simulator_nwaku_1:8645')
group.add_argument('-mn', '--multiple-nodes', type=str,
help='example: http://waku-simulator_nwaku_[1..10]:8645')
# rest of arguments
parser.add_argument('-c', '--content-topic', type=str, help='content topic', default="kubekube")
parser.add_argument('-p', '--pubsub-topic', type=str, help='pubsub topic',
default="/waku/2/kubetopic")
parser.add_argument('-s', '--msg-size-kbytes', type=int, help='message size in kBytes',
default=10)
parser.add_argument('-d', '--delay-seconds', type=int, help='delay in second between messages')
parser.add_argument('-cpp', '--containers-per-pod', type=int,
help='number of containers in pod', default=1)
args = parser.parse_args()
print(args)
if args.single_node != None:
print("Injecting traffic to single node REST API:", args.single_node)
# this simply converts from http://url_[1..5]:port to
# [http://url_1:port
nodes = []
if args.multiple_nodes:
range_nodes = args.multiple_nodes.split(":")[1].split("-")[1]
port_nodes = args.multiple_nodes.split(":")[-1]
node_placeholder = args.multiple_nodes.replace(range_nodes, "{placeholder}")
node_placeholder = node_placeholder.replace(port_nodes, "{port}")
clean_range = range_nodes.replace("[", "").replace("]", "")
start = int(clean_range.split("..")[0])
end = int(clean_range.split("..")[1])
print("Injecting traffic to multiple nodes REST APIs")
for i in range(start, end):
for j in range(0, args.containers_per_pod):
nodes.append(node_placeholder.replace("{placeholder}", str(i)).replace("{port}",
str(8645 + j)))
for node in nodes:
print(node)
asyncio.run(main(nodes, args))

View File

@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nodes
namespace: zerotesting
spec:
replicas: 1000
podManagementPolicy: "Parallel"
selector:
matchLabels:
app: nodes
template:
metadata:
labels:
app: nodes
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: nodes
containers:

12
deployment/prepare_env.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
ulimit -n $(ulimit -n -H)
ulimit -u $(ulimit -u -H)
sudo sysctl -w net.ipv4.neigh.default.gc_thresh1=65536
sudo sysctl -w net.ipv4.neigh.default.gc_thresh2=114688
sudo sysctl -w net.ipv4.neigh.default.gc_thresh3=131072
sudo sysctl fs.inotify.max_user_instances=1048576
sudo sysctl -w vm.max_map_count=262144
echo 11000 > /proc/sys/kernel/pty/max

0
requirements.txt Executable file → Normal file
View File