Skip to content

Commit

Permalink
feat(simulation): update sidecar.sh for ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Gezq committed Mar 19, 2024
1 parent 4b02103 commit 8fc18be
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions sgx_network_simulation/sidecar.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
#!/bin/bash
set -ex

FILE_PATH="/pod-data/listen_port"
while [ ! -s "$FILE_PATH" ]; do
echo "wait for $FILE_PATH ..."
LISTEN_PORT_PATH="/pod-data/listen_port"
while [ ! -s "$LISTEN_PORT_PATH" ]; do
echo "wait for $LISTEN_PORT_PATH ..."
sleep 1
done
WORKER_LISTEN_PORT=$(cat "$FILE_PATH")
WORKER_LISTEN_PORT=$(cat "$LISTEN_PORT_PATH")

PROXY_LOCAL_PORT_PATH="/pod-data/proxy_local_port"
while [ ! -s "$PROXY_LOCAL_PORT_PATH" ]; do
echo "wait for $PROXY_LOCAL_PORT_PATH ..."
sleep 1
done
PROXY_LOCAL_PORT=$(cat "$PROXY_LOCAL_PORT_PATH")

GRPC_SERVER_PORT=32001
if [ -n "$PORT0" ]; then
GRPC_SERVER_PORT=$PORT0
fi

TARGET_GRPC_PORT=32102
if [ -n "$PORT1" ]; then
TARGET_GRPC_PORT=$PORT1
fi

echo "# Forwards all traffic to nginx controller
server {
listen 32102 http2;
listen ${TARGET_GRPC_PORT} http2;
# No limits
client_max_body_size 0;
Expand All @@ -32,27 +49,18 @@ server {
}
" > nginx/sidecar.conf

if [ -z "$PORT0" ]; then
PORT0=32001
fi

if [ -z "$PORT2" ]; then
PORT2=32102
fi

sed -i "s/listen [0-9]* http2;/listen $PORT2 http2;/" nginx/sidecar.conf

rm -rf /etc/nginx/conf.d/*
cp nginx/sidecar.conf /etc/nginx/conf.d/
service nginx restart

# Server sidecar: grpc to tcp, 5001 is the server port of main container
echo "Starting server sidecar"
./grpc2tcp --grpc_server_port=$PORT0 \
./grpc2tcp --grpc_server_port=$GRPC_SERVER_PORT \
--target_tcp_address="localhost:$WORKER_LISTEN_PORT" &

echo "Starting client sidecar"
./tcp2grpc --tcp_server_port="$PROXY_LOCAL_PORT" \
--target_grpc_address="localhost:$PORT2" &
--target_grpc_address="localhost:$TARGET_GRPC_PORT" &

echo "===========Sidecar started!!============="

Expand Down

0 comments on commit 8fc18be

Please sign in to comment.