diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bd92907..a3a13c0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,10 @@ on: pull_request: types: [opened, synchronize, reopened] push: - branches: [develop, master] + branches: + - develop + - master + - "release/*" jobs: sonar: # sonar job is to setup and run sonar scan analysis on telematic cloud messaging code runs-on: ubuntu-latest diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c88db096..fe5ecef7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,4 +5,4 @@ on: jobs: docker: - uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main \ No newline at end of file + uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 172b8064..abdd8134 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -5,6 +5,8 @@ on: - "develop" - "master" - "release/*" + tags: + - "carma-system-*" jobs: dockerhub: diff --git a/co-simulation/bundle/src/assembly/resources/fed/ns3/ns3_installer.sh b/co-simulation/bundle/src/assembly/resources/fed/ns3/ns3_installer.sh index 090664c0..bad64962 100644 --- a/co-simulation/bundle/src/assembly/resources/fed/ns3/ns3_installer.sh +++ b/co-simulation/bundle/src/assembly/resources/fed/ns3/ns3_installer.sh @@ -45,8 +45,8 @@ arg_federate_file="" arg_integration_testing=false arg_make_parallel="" -required_programs=(python3.6 gcc unzip tar) -required_libraries=("libprotobuf-dev (or equal) 3.3.0" "libxml2-dev (or equal)" "libsqlite3-dev (or equal)") +required_programs=( python3.6 gcc unzip tar ) +required_libraries=( "libprotobuf-dev (or equal) 3.3.0" "libxml2-dev (or equal)" "libsqlite3-dev (or equal)" ) ####### configurable parameters ########## ns3_version="3.28" @@ -60,18 +60,17 @@ ns3_version_affix="ns-allinone-$ns3_version" ns3_version_affix_unified="ns-allinone" #deprecated, not used momentarily ns3_short_affix="ns-$ns3_version" ns3_short_affix_unified="ns3" -ns3_deploy_folder="ns3-deployed" #name to be used when ns3 is deployed (i.e. keep only binaries) -working_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ns3_deploy_folder="ns3-deployed" #name to be used when ns3 is deployed (i.e. keep only binaries) +working_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" federate_path="bin/fed/ns3" ns3_installation_path=${working_directory} -ns3_allinone_folder="${ns3_installation_path}/$ns3_version_affix" -ns3_simulator_folder="${ns3_allinone_folder}/$ns3_short_affix" #due to the ns3 tarball structure +ns3_simulator_folder="${ns3_installation_path}/$ns3_version_affix/$ns3_short_affix" #due to the ns3 tarball structure ns3_scratch="${ns3_simulator_folder}/scratch" +ns3_source="${ns3_simulator_folder}/src" ####### semi automatic parameters ######## -ns3_federate_url="https://github.com/usdot-fhwa-stol/ns3-federate.git" +ns3_federate_url="https://github.com/mosaic-addons/ns3-federate/archive/21.0.zip" ns3_url="http://www.nsnam.org/release/$ns3_version_affix.tar.bz2" -ns3_cv2x="https://github.com/usdot-fhwa-stol/ns-3_c-v2x" ###### more automatic parameters ######### ns3_federate_filename="$(basename "$ns3_federate_url")" @@ -81,66 +80,67 @@ temporary_files="" uninstall_files="license_gplv2.txt run.sh $ns3_short_affix $ns3_version_affix $ns3_short_affix_unified $ns3_version_affix_unified ${ns3_deploy_folder}" print_help() { - log "\nUsage: ns3_installer.sh [options]\n" - log "Options:\n" - log " -s --simulator \t\tThe script will not attempt to download NS3 but use the given argument." - log " -f --federate \tThe script will not attempt to download the federate archive but use the given argument." - 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 " -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 \t\t\tUse n threads for compilation " - log " -u --uninstall Remove the ns-3 federate" - log "\n" + log "\nUsage: ns3_installer.sh [options]\n" + log "Options:\n" + log " -s --simulator \t\tThe script will not attempt to download NS3 but use the given argument." + log " -f --federate \tThe script will not attempt to download the federate archive but use the given argument." + 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 " -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 \t\t\tUse n threads for compilation " + log " -u --uninstall Remove the ns-3 federate" + log "\n" } get_arguments() { - while [[ $# -ge 1 ]]; do + while [[ $# -ge 1 ]] + do key="$1" case $key in - -q | --quiet) - arg_quiet=true - ;; - -u | --uninstall) - arg_uninstall=true - ;; - -c | --no-clean-on-failure) - arg_fail_clean=false - ;; - -d | --no-deploy) - arg_deploy=false - ;; - -p | --gen-protobuf) - arg_regen_protobuf=true - ;; - -f | --federate) - arg_federate_file="$2" - ns3_federate_filename="$2" - shift #past argument - ;; - -s | --simulator) - arg_ns3_file="$2" - ns3_filename="$2" - shift # past argument - ;; - -it | --integration_testing) - arg_integration_testing=true - arg_quiet=true - ;; - -j | --parallel) - arg_make_parallel="-j $2" - shift # past argument - ;; - -h | --help) - arg_quiet=true - print_info - print_help - exit 1 - ;; - esac - shift - done + -q|--quiet) + arg_quiet=true + ;; + -u|--uninstall) + arg_uninstall=true + ;; + -c|--no-clean-on-failure) + arg_fail_clean=false + ;; + -d|--no-deploy) + arg_deploy=false + ;; + -p|--gen-protobuf) + arg_regen_protobuf=true + ;; + -f|--federate) + arg_federate_file="$2" + ns3_federate_filename="$2" + shift #past argument + ;; + -s|--simulator) + arg_ns3_file="$2" + ns3_filename="$2" + shift # past argument + ;; + -it|--integration_testing) + arg_integration_testing=true + arg_quiet=true + ;; + -j|--parallel) + arg_make_parallel="-j $2" + shift # past argument + ;; + -h|--help) + arg_quiet=true + print_info + print_help + exit 1 + ;; + esac + shift + done } #################### Printing functions ################## @@ -156,9 +156,9 @@ warn() { } fail() { - log "${bold}${red}\nERROR: $1\n${restore}" ${*:2} - clean_fail_files - exit 1 + log "${bold}${red}\nERROR: $1\n${restore}" ${*:2} + clean_fail_files + exit 1 } check_uninstall() { @@ -171,9 +171,9 @@ check_uninstall() { } print_usage() { - log "${bold}${cyan}[$(basename "$0")] -- A ns-3 installation script for MOSAIC${restore}" - log "\nUsage: $0 [arguments]" - fail "Argument \""$1"\" not known." + log "${bold}${cyan}[$(basename "$0")] -- A ns-3 installation script for MOSAIC${restore}" + log "\nUsage: $0 [arguments]" + fail "Argument \""$1"\" not known." } print_info() { @@ -195,7 +195,7 @@ print_success() { ################## Checking functions ################# has() { - return $(which $1 >/dev/null) + return $( which $1 >/dev/null ) } check_shell() { @@ -205,17 +205,18 @@ check_shell() { fi } -check_required_programs() { +check_required_programs() +{ for package in $1; do if ! has $package; then - fail ""$package" required, but it's not installed. Please install the package (sudo apt-get install for Ubuntu/Debian) and try again." + fail ""$package" required, but it's not installed. Please install the package (sudo apt-get install for Ubuntu/Debian) and try again."; fi done } check_directory() { cd "$working_directory" - federate_working_directory=$(echo "$working_directory" | rev | cut -c -${#federate_path} | rev) + federate_working_directory=`echo "$working_directory" | rev | cut -c -${#federate_path} | rev` if [ "$federate_working_directory" == "$federate_path" ]; then return else @@ -224,37 +225,37 @@ 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() { +ask_dependencies() +{ if $arg_integration_testing || $arg_quiet; then return fi - while [ true ]; do + while [ true ]; do log "Are the following dependencies installed on the system? \n" log "${bold}Libraries:${restore}" for lib in "${required_libraries[@]}"; do - log "${bold}${cyan} $lib ${restore}" + log "${bold}${cyan} $lib ${restore}" done log "\n${bold}Programs:${restore}" for prog in "${required_programs[@]}"; do - log "${bold}${cyan} $prog ${restore}" + log "${bold}${cyan} $prog ${restore}" done printf "\n[y/n] " read answer case $answer in - [Yy]*) break ;; - [Nn]*) - log "\n${red}Please install the required dependencies before proceeding with the installation process${restore}\n" - exit - ;; - *) echo "Allowed choices are yes or no" ;; + [Yy]* ) break;; + [Nn]* ) + log "\n${red}Please install the required dependencies before proceeding with the installation process${restore}\n" + exit;; + * ) echo "Allowed choices are yes or no";; esac - done + done; } ################### Downloading and installing ########## @@ -263,13 +264,13 @@ download() { if [ ! -f "$(basename "$1")" ]; then basen=$(basename "$1") if has wget; then - wget --no-check-certificate -q "$1" || fail "The download URL seems to have changed. File not found: "$1"" + wget --no-check-certificate -q "$1" || fail "The download URL seems to have changed. File not found: "$1""; temporary_files="$temporary_files $basen" elif has curl; then - curl -s -O "$1" || fail "The download URL seems to have changed. File not found: "$1"" + curl -s -O "$1" || fail "The download URL seems to have changed. File not found: "$1""; temporary_files="$temporary_files $basen" else - fail "Can't download "$1"." + fail "Can't download "$1"."; fi else warn "File $(basename "$1") already exists. Skipping download." @@ -283,6 +284,7 @@ download_premake5() { download "$premake5_autoconf_url" } + download_ns3() { if [ ! -z "$arg_ns3_file" ]; then log "NS3 given as argument" @@ -301,25 +303,8 @@ download_federate() { download "$ns3_federate_url" } -clone_ns3_federate(){ - log "Cloning NS3 federate from $ns3_federate_url..." - git clone $ns3_federate_url - - mv ns3-federate federate -} - -clone_ns3_cv2x() { - - if [ ! -d "$ns3_allinone_folder" ]; then - log "Folder $ns3_allinone_folder is not existing" - return - fi - log "Cloning NS3 from $ns3_cv2x..." - git clone $ns3_cv2x - mv ns-3_c-v2x $ns3_version_affix/$ns3_short_affix -} - -extract_ns3() { +extract_ns3() +{ if [ ! -d "$2/ns3_version_affix" ]; then arg1="$1" arg2="$2" @@ -329,116 +314,122 @@ extract_ns3() { fi } -extract_ns3_federate() { - arg1="$1" +extract_ns3_federate() +{ + arg1="$1" - if [ -d "./federate" ]; then - fail "Directory federate in "." already exists." - fi + if [ -d "./federate" ]; then + fail "Directory federate in "." already exists."; + fi - temporary_files="$temporary_files federate" + temporary_files="$temporary_files federate" - unzip --qq -o "$arg1" - # The archive should have contained the folder "ns3-federate-xxx". - # Rename it to "federate": - mv ns3-federate-* federate + unzip --qq -o "$arg1" + # The archive should have contained the folder "ns3-federate-xxx". + # Rename it to "federate": + mv ns3-federate-* federate } extract_premake() { - if [ ! -d "./federate" ]; then - fail "Directory federate doesn't exists." - fi - oldpwd=$(pwd) - cd federate - tar xvf ../$premake5_tar - unzip ../$premake5_autoconf_zip - cp premake-autoconf-master/api.lua . - cp premake-autoconf-master/autoconf.lua . - cp premake-autoconf-master/clang.lua . - cp premake-autoconf-master/gcc.lua . - cp premake-autoconf-master/msc.lua . - rm -fr premake-autoconf-master - cd "$oldpwd" + if [ ! -d "./federate" ]; then + fail "Directory federate doesn't exists." + fi + oldpwd=`pwd` + cd federate + tar xvf ../$premake5_tar + unzip ../$premake5_autoconf_zip + cp premake-autoconf-master/api.lua . + cp premake-autoconf-master/autoconf.lua . + cp premake-autoconf-master/clang.lua . + cp premake-autoconf-master/gcc.lua . + cp premake-autoconf-master/msc.lua . + rm -fr premake-autoconf-master + cd "$oldpwd" } -patch_ns3() { +patch_ns3() +{ ### copy the run file cp -f "./federate/run.sh" "$ns3_installation_path/run.sh" chmod +x "$ns3_installation_path/run.sh" } -build_ns3() { - current_dir=$(pwd) - log "BUILD ns3 version ${ns3_version}" - cd "${ns3_installation_path}/ns-allinone-${ns3_version}/${ns3_short_affix}" - # use waf to configure/build Fabian Eckermann NS-3 C-V2X - python3.6 -x waf configure - python3.6 -x waf build - - sudo cp -ar build/ns3 /usr/include/ - - log "Build ns3-federate" - cd ${current_dir}/federate - mv src/ClientServerChannel.h . - mv src/ClientServerChannel.cc . - if [ -f src/ClientServerChannelMessages.pb.h ]; then - rm src/ClientServerChannelMessages.pb.h - fi - if [ -f src/ClientServerChannelMessages.pb.cc ]; then - rm src/ClientServerChannelMessages.pb.cc - fi - - # adjust build instruction to cover scrambled files - sed -i -e "s|/usr/local|.|" premake5.lua - sed -i -e "s|\"/usr/include\"|\"../ns-allinone-${ns3_version}/ns-${ns3_version}/build\"|" premake5.lua - sed -i -e "s|\"/usr/lib\"|\"../ns-allinone-${ns3_version}/ns-${ns3_version}/build/lib\"|" premake5.lua - if [ "${arg_regen_protobuf}" == "true" ]; then - ./premake5 gmake --generate-protobuf --install - else - ./premake5 gmake --install - fi - - make config=debug clean - make -j1 config=debug # make is running targets in parallel, but we have to build 'prebuild'-target, target, - # and 'postbuild'-target sequentially +build_ns3() +{ + current_dir=`pwd` + 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.6 ./build.py --disable-netanim + sudo cp -ar ns-3.28/build/ns3 /usr/include/ + + log "Build ns3-federate" + cd ${current_dir}/federate + mv src/ClientServerChannel.h . + mv src/ClientServerChannel.cc . + if [ -f src/ClientServerChannelMessages.pb.h ]; then + rm src/ClientServerChannelMessages.pb.h + fi + if [ -f src/ClientServerChannelMessages.pb.cc ]; then + rm src/ClientServerChannelMessages.pb.cc + fi + + # adjust build instruction to cover scrambled files + sed -i -e "s|/usr/local|.|" premake5.lua + sed -i -e "s|\"/usr/include\"|\"../ns-allinone-${ns3_version}/ns-${ns3_version}/build\"|" premake5.lua + sed -i -e "s|\"/usr/lib\"|\"../ns-allinone-${ns3_version}/ns-${ns3_version}/build\"|" premake5.lua + if [ "${arg_regen_protobuf}" == "true" ]; then + ./premake5 gmake --generate-protobuf --install + else + ./premake5 gmake --install + fi + make config=debug clean + make -j1 config=debug # make is running targets in parallel, but we have to build 'prebuild'-target, target, + # and 'postbuild'-target sequentially } -deploy_ns3() { - if [ "$arg_deploy" == "true" ]; then - log "Deploying ns3 binaries" - cd "${ns3_installation_path}" +deploy_ns3() +{ + if [ "$arg_deploy" == "true" ]; then + log "Deploying ns3 binaries" + cd "${ns3_installation_path}" - mkdir -p "$ns3_deploy_folder/build/scratch/" + 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" - fi + rm -rf ${ns3_simulator_folder} + mv "${ns3_deploy_folder}" "${ns3_simulator_folder}" + + fi } -uninstall() { - cd "$working_directory" - warn "Uninstalling all ns-3 files" - rm -rf $uninstall_files +uninstall() +{ + cd "$working_directory" + warn "Uninstalling all ns-3 files" + rm -rf $uninstall_files } -clean_fail_files() { - if [ "$arg_fail_clean" = "true" ]; then - cd "$working_directory" - rm -rf $uninstall_files #2>/dev/null - clean_up - fi +clean_fail_files() +{ + if [ "$arg_fail_clean" = "true" ]; then + cd "$working_directory" + rm -rf $uninstall_files #2>/dev/null + clean_up + fi } -clean_up() { +clean_up() +{ cd "$working_directory" #remove temporary files if wanted @@ -446,28 +437,27 @@ clean_up() { return fi if [ "$arg_integration_testing" = false ]; then - while [ true ]; do + 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 fi case $answer in - [Yy]*) - rm -rf $temporary_files 2>/dev/null - break - ;; - [Nn]*) break ;; - *) echo "Allowed choices are yes or no" ;; + [Yy]* ) rm -rf $temporary_files 2>/dev/null + break;; + [Nn]* ) break;; + * ) echo "Allowed choices are yes or no";; esac - done + done; fi } + # Workaround for integration testing set_nslog() { - export NS_LOG="'*=level_all|prefix'" + export NS_LOG="'*=level_all|prefix'" } ################## ################# @@ -487,18 +477,17 @@ log "Preparing installation..." check_required_programs "${required_programs[*]}" check_directory -# download_federate - -download_premake5 +download_ns3 -clone_ns3_federate +download_federate -mkdir "${ns3_installation_path}/ns-allinone-${ns3_version}" +download_premake5 -clone_ns3_cv2x +log "Extracting "$ns3_filename"..." +extract_ns3 "$ns3_filename" . -# log "Extracting "$ns3_federate_filename"..." -# extract_ns3_federate "$ns3_federate_filename" +log "Extracting "$ns3_federate_filename"..." +extract_ns3_federate "$ns3_federate_filename" extract_premake diff --git a/co-simulation/bundle/src/assembly/resources/scenarios/Barnim/ns3/ns3_federate_config.xml b/co-simulation/bundle/src/assembly/resources/scenarios/Barnim/ns3/ns3_federate_config.xml index 6cf70119..61332733 100644 --- a/co-simulation/bundle/src/assembly/resources/scenarios/Barnim/ns3/ns3_federate_config.xml +++ b/co-simulation/bundle/src/assembly/resources/scenarios/Barnim/ns3/ns3_federate_config.xml @@ -73,13 +73,8 @@ - - + + diff --git a/co-simulation/bundle/src/assembly/resources/scenarios/Tiergarten/ns3/ns3_federate_config.xml b/co-simulation/bundle/src/assembly/resources/scenarios/Tiergarten/ns3/ns3_federate_config.xml index 33be2e34..6ec8707e 100644 --- a/co-simulation/bundle/src/assembly/resources/scenarios/Tiergarten/ns3/ns3_federate_config.xml +++ b/co-simulation/bundle/src/assembly/resources/scenarios/Tiergarten/ns3/ns3_federate_config.xml @@ -1,11 +1,5 @@ - - - - - - @@ -79,13 +73,8 @@ - - + + @@ -101,26 +90,4 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/co-simulation/bundle/src/assembly/resources/scenarios/Town04/ns3/ns3_federate_config.xml b/co-simulation/bundle/src/assembly/resources/scenarios/Town04/ns3/ns3_federate_config.xml index 20ef28e7..dc9b8d1d 100644 --- a/co-simulation/bundle/src/assembly/resources/scenarios/Town04/ns3/ns3_federate_config.xml +++ b/co-simulation/bundle/src/assembly/resources/scenarios/Town04/ns3/ns3_federate_config.xml @@ -1,11 +1,5 @@ - - - - - - @@ -18,13 +12,13 @@ - + - + @@ -38,7 +32,7 @@ - + @@ -79,13 +73,8 @@ - - + + @@ -101,26 +90,4 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/co-simulation/bundle/src/assembly/resources/scenarios/Town04_test/ns3/ns3_federate_config.xml b/co-simulation/bundle/src/assembly/resources/scenarios/Town04_test/ns3/ns3_federate_config.xml index 7705603d..61332733 100644 --- a/co-simulation/bundle/src/assembly/resources/scenarios/Town04_test/ns3/ns3_federate_config.xml +++ b/co-simulation/bundle/src/assembly/resources/scenarios/Town04_test/ns3/ns3_federate_config.xml @@ -1,11 +1,5 @@ - - - - - - @@ -80,14 +74,7 @@ - - - + diff --git a/co-simulation/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java b/co-simulation/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java index 56641010..040d2ab7 100644 --- a/co-simulation/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java +++ b/co-simulation/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java @@ -206,6 +206,12 @@ public abstract class AbstractSumoAmbassador extends AbstractFederateAmbassador */ protected boolean receivedSimulationStep = false; + /** + * First time when the sumo ambassador is called to progress to the next simulation step + * + */ + protected boolean firstAttemptToAdvanceToNextStep = true; + /** * CARLA federate is enabled */ @@ -1193,6 +1199,16 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder return; } + // A script to validate time synchronization of tools in CDASim currently relies on the following + // log line. TODO: This line is meant to be removed in the future upon completion of this work: + // https://github.com/usdot-fhwa-stol/carma-analytics-fotda/pull/43 + if (!receivedSimulationStep && firstAttemptToAdvanceToNextStep) + { + long millis = System.currentTimeMillis(); + log.info("Simulation Time: {} where current system time is: {} and nextTimeStep: {} and ambasador id: {}", (int) (time/1e6), millis, nextTimeStep, getId()); + firstAttemptToAdvanceToNextStep = false; + } + if (time > lastAdvanceTime) { // actually add vehicles in sumo, before we reach the next advance time flushNotYetAddedVehicles(lastAdvanceTime); @@ -1229,6 +1245,7 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder rti.triggerInteraction(simulationStepResult.getTrafficDetectorUpdates()); this.rti.triggerInteraction(simulationStepResult.getTrafficLightUpdates()); receivedSimulationStep = false; + firstAttemptToAdvanceToNextStep = true; } // System.out.println("Sumo request time advance at time: " + nextTimeStep); diff --git a/co-simulation/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/SequentialTimeManagement.java b/co-simulation/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/SequentialTimeManagement.java index a1a4df13..b76ab207 100644 --- a/co-simulation/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/SequentialTimeManagement.java +++ b/co-simulation/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/SequentialTimeManagement.java @@ -15,6 +15,9 @@ package org.eclipse.mosaic.rti.time; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.mosaic.rti.MosaicComponentParameters; import org.eclipse.mosaic.rti.api.ComponentProvider; import org.eclipse.mosaic.rti.api.FederateAmbassador; @@ -31,6 +34,26 @@ public class SequentialTimeManagement extends AbstractTimeManagement { private final int realtimeBrake; + // Debugging & Logging + HashMap loggingMap = new HashMap<>(); + + /** + * Prints log for time synchronization monitor script. Only meant to be printed for debugging purposes. + * Please see https://github.com/usdot-fhwa-stol/carma-analytics-fotda/pull/43 + * + * @param event FederateEvent requested by one of the ambassadaor + * @param startTime current system time when the event request was received + */ + + private void printTimeSyncDebugLogs(FederateEvent event, long startTime){ + if (!loggingMap.containsKey(event.getFederateId()) || + (loggingMap.containsKey(event.getFederateId()) && loggingMap.get(event.getFederateId()) != event.getRequestedTime())) + { + loggingMap.put(event.getFederateId(), event.getRequestedTime()); + this.logger.debug("Simulation Time: {} where current system time is: {} and requested from id: {}", (int) (event.getRequestedTime()/1e6), startTime, event.getFederateId()); + } + } + /** * Creates a new instance of the sequential time management. * @@ -87,6 +110,15 @@ public void runSimulation() throws InternalFederateException, IllegalValueExcept if (ambassador != null) { federation.getMonitor().onBeginActivity(event); long startTime = System.currentTimeMillis(); + + // A script to validate time synchronization of tools in CDASim currently relies on the following + // log line. TODO: This line is meant to be removed in the future upon completion of this work: + // https://github.com/usdot-fhwa-stol/carma-analytics-fotda/pull/43 + if (this.logger.isDebugEnabled()) + { + printTimeSyncDebugLogs(event, startTime); + } + ambassador.advanceTime(event.getRequestedTime()); federation.getMonitor().onEndActivity(event, System.currentTimeMillis() - startTime); diff --git a/docker/checkout.sh b/docker/checkout.sh index ad545521..06391349 100755 --- a/docker/checkout.sh +++ b/docker/checkout.sh @@ -39,6 +39,6 @@ if [[ "$BRANCH" = "develop" ]]; then git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ~/src/carma-msgs --branch $BRANCH --depth 1 git clone https://github.com/usdot-fhwa-stol/carma-utils.git ~/src/carma-utils --branch $BRANCH --depth 1 else - git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ${dir}/src/carma-msgs --branch develop --depth 1 - git clone https://github.com/usdot-fhwa-stol/carma-utils.git ${dir}/src/carma-utils --branch develop --depth 1 + git clone https://github.com/usdot-fhwa-stol/carma-msgs.git ${dir}/src/carma-msgs --branch carma-system-4.5.0 --depth 1 + git clone https://github.com/usdot-fhwa-stol/carma-utils.git ${dir}/src/carma-utils --branch carma-system-4.5.0 --depth 1 fi diff --git a/docker/install_dependencies.sh b/docker/install_dependencies.sh index 6866bc82..d48e826d 100755 --- a/docker/install_dependencies.sh +++ b/docker/install_dependencies.sh @@ -32,7 +32,7 @@ sudo apt-get install -y --allow-unauthenticated gcc-7 g++-7 python3.6 unzip tar python3.7-distutils x11-xserver-utils dconf-editor dbus-x11 libglvnd0 libgl1 \ libglx0 libegl1 libxext6 libx11-6 python3-dev \ build-essential pkg-config lbzip2 libprotobuf-dev protobuf-compiler patch rsync \ - wget vim nano xterm libprotobuf-dev git + wget vim nano xterm libprotobuf-dev sudo rm -rf /var/lib/apt/lists/* sudo apt-get clean