Skip to content

Commit

Permalink
feat: add dev-option to ns3 installation script (#435)
Browse files Browse the repository at this point in the history
* refactor: tabs to spaces
* feat: provide dev mode where src files are not deleted
* feat: make available over CL args
  • Loading branch information
hoelger authored Nov 19, 2024
1 parent 4a4a335 commit bec61b5
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions bundle/src/assembly/resources/fed/ns3/ns3_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ arg_ns3_file=""
arg_federate_file=""
arg_integration_testing=false
arg_make_parallel=""
arg_dev=false

required_programs_display=( python3 gcc unzip tar protobuf-compiler )
required_programs_test=( python3 gcc unzip tar protoc )
Expand Down Expand Up @@ -88,10 +89,11 @@ print_help() {
log " -q --quiet\t\t\t\tThe script will not give any output but run silently instead."
log " -c --no-clean-on-failure\t\tDo not remove installation files when install fails."
log " -d --no-deploy\t\t\tDo not extract binary data from ns3 (useful for development)."
log " -k --keep-src\t\t\tSource code is not removed after installation."
log " -p --regen-protobuf\ŧ\tRegenerate Protobuf c++ source, when using a different version of protobuf 3."
log " -h --help\t\t\t\tPrint this help"
log " -j --parallel <n>\t\t\tUse n threads for compilation "
log " -u --uninstall Remove the ns-3 federate"
log " -u --uninstall Remove the ns-3 federate"
log "\n"
}

Expand All @@ -118,7 +120,7 @@ get_arguments() {
-f|--federate)
arg_federate_file="$2"
ns3_federate_filename="$2"
shift #past argument
shift # past argument
;;
-s|--simulator)
arg_ns3_file="$2"
Expand All @@ -129,6 +131,9 @@ get_arguments() {
arg_integration_testing=true
arg_quiet=true
;;
-k|--keep-src)
arg_dev=true
;;
-j|--parallel)
arg_make_parallel="-j $2"
shift # past argument
Expand Down Expand Up @@ -226,9 +231,9 @@ check_directory() {
}

check_nslog() {
if [[ ! $NS_LOG =~ .*level.* ]]; then
log "Logging probably not correctly initialized"
fi
if [[ ! $NS_LOG =~ .*level.* ]]; then
log "Logging probably not correctly initialized"
fi
}

ask_dependencies()
Expand Down Expand Up @@ -355,24 +360,28 @@ extract_premake() {
cd "$oldpwd"
}

patch_ns3()
copy_runfile()
{
### copy the run file
cp -f "./federate/run.sh" "$ns3_installation_path/run.sh"
chmod +x "$ns3_installation_path/run.sh"

if [ "$arg_dev" == "true" ]; then
sed -i -e 's|LD_LIBRARY_PATH=../ns-allinone-$ns3Version/ns-$ns3Version/build|LD_LIBRARY_PATH=../ns-allinone-$ns3Version/ns-$ns3Version/build/lib|' "$ns3_installation_path/run.sh"
fi
}

build_ns3()
{
current_dir=`pwd`
log "BUILD ns3 version ${ns3_version}"
log "Build ns3 version ${ns3_version}"
cd "${ns3_installation_path}/ns-allinone-${ns3_version}"

# ns-3 prior to 3.28.1 does not compile without warnings using g++ 10.2.0
CXXFLAGS="-Wno-error" python3 ./build.py --disable-netanim
}

build_ns3_federate()
{
log "Build ns3-federate"
cd ${current_dir}/federate
cd ${ns3_installation_path}/federate
mv src/ClientServerChannel.h .
mv src/ClientServerChannel.cc .

Expand Down Expand Up @@ -400,22 +409,27 @@ deploy_ns3()
{
if [ "$arg_deploy" == "true" ]; then
log "Deploying ns3 binaries"
cd "${ns3_installation_path}"

mkdir -p "$ns3_deploy_folder/build/scratch/"
if [ "$arg_dev" == "true" ]; then
# will copy 1.8GB instead of 470MB at beginning of each simulation run
cd "${ns3_installation_path}"
cp federate/bin/ns3-federate "$ns3_simulator_folder/build/scratch/mosaic_starter"
else
cd "${ns3_installation_path}"

mkdir -p "$ns3_deploy_folder/build/scratch/"

for i in $(find "${ns3_simulator_folder}/build/" -name "*.so"); do
cp "$i" "$ns3_deploy_folder/build/"
done

cp federate/bin/ns3-federate "$ns3_deploy_folder/build/scratch/mosaic_starter"
for i in $(find "${ns3_simulator_folder}/build/" -name "*.so"); do
cp "$i" "$ns3_deploy_folder/build/"
done

mkdir "${ns3_deploy_folder}/scratch"
cp federate/bin/ns3-federate "$ns3_deploy_folder/build/scratch/mosaic_starter"

rm -rf ${ns3_simulator_folder}
mv "${ns3_deploy_folder}" "${ns3_simulator_folder}"
mkdir "${ns3_deploy_folder}/scratch"

rm -rf ${ns3_simulator_folder}
mv "${ns3_deploy_folder}" "${ns3_simulator_folder}"
fi
fi
}

Expand Down Expand Up @@ -446,7 +460,7 @@ clean_up()
if [ "$arg_integration_testing" = false ]; then
while [ true ]; do
log "Do you want to remove the following files and folders? ${bold}${red} $temporary_files ${restore} \n[y/n] "
if $arg_quiet; then
if $arg_quiet; then
answer=Y
else
read answer
Expand All @@ -464,7 +478,7 @@ clean_up()

# Workaround for integration testing
set_nslog() {
export NS_LOG="'*=level_all|prefix'"
export NS_LOG="'*=level_all|prefix'"
}

################## #################
Expand Down Expand Up @@ -498,12 +512,13 @@ extract_ns3_federate

extract_premake

log "Applying patch for ns-3..."
patch_ns3
copy_runfile

log "Building ns-3..."
build_ns3
build_ns3_federate

log "Deploying ns-3..."
deploy_ns3

log "Set ns-3 debug-levels..."
Expand Down

0 comments on commit bec61b5

Please sign in to comment.