refactor(deployment): Apply linter changes
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
@@ -4,32 +4,36 @@ WEDGE_PASS="Jony154977"
|
|||||||
USER_PASS="asdf1234"
|
USER_PASS="asdf1234"
|
||||||
|
|
||||||
run_script_via_ssh() {
|
run_script_via_ssh() {
|
||||||
local script_path="$1" # Path to the script to be copied
|
local script_path
|
||||||
local ssh_host="$2" # SSH host
|
local ssh_host
|
||||||
local pass=$3
|
local pass
|
||||||
local remote_path="/tmp/$(basename "$script_path")" # Destination path on the remote machine
|
local remote_path
|
||||||
|
|
||||||
|
script_path="$1"
|
||||||
|
ssh_host="$2"
|
||||||
|
pass=$3
|
||||||
|
remote_path="/tmp/$(basename "$script_path")"
|
||||||
|
|
||||||
# Copy the script to the remote host
|
# Copy the script to the remote host
|
||||||
scp "$script_path" "$ssh_host:$remote_path"
|
if ! scp "$script_path" "$ssh_host:$remote_path"; then
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
echo "Error: Failed to copy the script to the remote host."
|
echo "Error: Failed to copy the script to the remote host."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute the script on the remote host with sudo
|
# Execute the script on the remote host with sudo
|
||||||
ssh "$ssh_host" "echo $pass | sudo -S $remote_path"
|
if ! ssh "$ssh_host" "echo $pass | sudo -S $remote_path"; then
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
echo "Error: Failed to execute the script on the remote host."
|
echo "Error: Failed to execute the script on the remote host."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Script executed successfully on $ssh_host."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wedge_setup() {
|
wedge_setup() {
|
||||||
|
# Deploy switch program
|
||||||
scp -r ../l1switch/ ncs-wedge:/tmp/
|
scp -r ../l1switch/ ncs-wedge:/tmp/
|
||||||
run_script_via_ssh ./00-wedge_on_reboot.sh ncs-wedge $WEDGE_PASS
|
run_script_via_ssh ./00-wedge_on_reboot.sh ncs-wedge $WEDGE_PASS
|
||||||
run_script_via_ssh ./01-wedge_compile_code.sh ncs-wedge $WEDGE_PASS
|
run_script_via_ssh ./01-wedge_compile_code.sh ncs-wedge $WEDGE_PASS
|
||||||
|
|
||||||
|
# Deploy service for switch program
|
||||||
scp ./l1switch.service ncs-wedge:/tmp/l1switch.service
|
scp ./l1switch.service ncs-wedge:/tmp/l1switch.service
|
||||||
scp ./02-run_switch_program.sh ncs-wedge:/home/user/bf-sde-9.7.0/l1switch.sh
|
scp ./02-run_switch_program.sh ncs-wedge:/home/user/bf-sde-9.7.0/l1switch.sh
|
||||||
ssh ncs-wedge "echo $WEDGE_PASS | sudo -S mv /tmp/l1switch.service /etc/systemd/system/l1switch.service"
|
ssh ncs-wedge "echo $WEDGE_PASS | sudo -S mv /tmp/l1switch.service /etc/systemd/system/l1switch.service"
|
||||||
@@ -49,23 +53,24 @@ wedge_setup() {
|
|||||||
setup_node() {
|
setup_node() {
|
||||||
local nodeid="$1"
|
local nodeid="$1"
|
||||||
local node="ncs-node$nodeid"
|
local node="ncs-node$nodeid"
|
||||||
local node_script="./10-host_setup_node$nodeid.sh"
|
local node_setup_script="./10-host_setup_node$nodeid.sh"
|
||||||
|
|
||||||
scp "./30-add_namespaces.sh" "$node":
|
scp "./30-add_namespaces.sh" "$node":
|
||||||
scp "./31-configure_interfaces.sh" "$node":
|
scp "./31-configure_interfaces.sh" "$node":
|
||||||
scp "./32-setup_arp.sh" "$node":
|
scp "./32-setup_arp.sh" "$node":
|
||||||
|
|
||||||
run_script_via_ssh "$node_script" "$node" $USER_PASS
|
run_script_via_ssh "$node_setup_script" "$node" $USER_PASS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Setup
|
||||||
wedge_setup
|
wedge_setup
|
||||||
setup_node 1
|
setup_node 1
|
||||||
setup_node 2
|
setup_node 2
|
||||||
|
|
||||||
# read -p "YOU WILL NEED TO PRESS CTRL+C AT SOME POINT SINCE THE RECEIVER/SENDER WILL RUN INDEFINITELY. (Press any key to confirm.)" -n1 -s
|
# Traffic
|
||||||
|
|
||||||
TIMEOUT=30
|
TIMEOUT=30
|
||||||
ssh ncs-node1 "echo $USER_PASS | sudo -S timeout $TIMEOUT ip netns exec tb_node1_if0 python3 receiver.py 10.0.2.1 30123 30123" &
|
ssh ncs-node1 "echo $USER_PASS | sudo -S timeout $TIMEOUT ip netns exec tb_node1_if0 python3 receiver.py 10.0.2.1 30123 30123" &
|
||||||
ssh ncs-node2 "echo $USER_PASS | sudo -S timeout $TIMEOUT ip netns exec tb_node2_if0 python3 sender.py 10.0.1.1 30123 30123 100 128"
|
ssh ncs-node2 "echo $USER_PASS | sudo -S timeout $TIMEOUT ip netns exec tb_node2_if0 python3 sender.py 10.0.1.1 30123 30123 100 128"
|
||||||
|
|
||||||
|
# Get log
|
||||||
scp ncs-node1:timestamps_30123 .
|
scp ncs-node1:timestamps_30123 .
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ In this repository we're have scripts to setup a network testbed with
|
|||||||
You can run the script [./99-deployment.sh](./99-deployment.sh) for a sample
|
You can run the script [./99-deployment.sh](./99-deployment.sh) for a sample
|
||||||
deployment.
|
deployment.
|
||||||
|
|
||||||
|
Keep in mind that there should be no switch program running on the wedge,
|
||||||
|
as it will freeze up when you try to run two switch programs.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Hardware
|
- Hardware
|
||||||
|
|||||||
Reference in New Issue
Block a user