diff --git a/DESERT_Addons/uwauv/Makefile.am b/DESERT_Addons/uwauv/Makefile.am new file mode 100644 index 00000000..dcdf5cad --- /dev/null +++ b/DESERT_Addons/uwauv/Makefile.am @@ -0,0 +1,51 @@ +# +# Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS ProvIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +AM_CXXFLAGS = -Wall -ggdb3 + +lib_LTLIBRARIES = libuwauv.la + +libuwauv_la_SOURCES = uwauv-module.cc uwauverror-module.cc uwauverror-simple-module.cc uwauvctr-module.cc uwauvctrer-module.cc uwauvctrer-simple-module.cc uwauv-packet.h initlib.cc + +libuwauv_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ +libuwauv_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ @DESERT_LDFLAGS_BUILD@ +libuwauv_la_LIBADD = @NS_LIBADD@ @NSMIRACLE_LIBADD@ @DESERT_LIBADD@ + +nodist_libuwauv_la_SOURCES = initTcl.cc + +BUILT_SOURCES = initTcl.cc + +CLEANFILES = initTcl.cc + +TCL_FILES = uwauv-init.tcl + +initTcl.cc: Makefile $(TCL_FILES) + cat $(VPATH)/$(TCL_FILES) | @TCL2CPP@ UwauvTclCode > initTcl.cc + +EXTRA_DIST = $(TCL_FILES) diff --git a/DESERT_Addons/uwauv/autogen.sh b/DESERT_Addons/uwauv/autogen.sh new file mode 100755 index 00000000..6a3c6be3 --- /dev/null +++ b/DESERT_Addons/uwauv/autogen.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright (c) 2013 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + + +aclocal -I m4 --force && libtoolize --force && automake --foreign --add-missing && autoconf diff --git a/DESERT_Addons/uwauv/configure.ac b/DESERT_Addons/uwauv/configure.ac new file mode 100644 index 00000000..58f6d911 --- /dev/null +++ b/DESERT_Addons/uwauv/configure.ac @@ -0,0 +1,69 @@ +# +# Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +AC_INIT(uwauv, 1.0.0) +AM_INIT_AUTOMAKE +AM_PROG_AR + +AC_CONFIG_MACRO_DIR([m4]) + +AC_PROG_CXX +AC_PROG_MAKE_SET + +AC_DISABLE_STATIC + +AC_LIBTOOL_WIN32_DLL +AC_PROG_LIBTOOL + +AC_PATH_NS_ALLINONE + +AC_ARG_WITH_NSMIRACLE + +AC_CHECK_NSMIRACLE([have_nsmiracle=yes],[have_nsmiracle=no]) +if test x$have_nsmiracle != xyes ; then + AC_MSG_ERROR([Could not find nsmiracle, is --with-nsmiracle set correctly?]) +fi + +AC_ARG_WITH_DESERT +AC_ARG_WITH_DESERT_BUILD + +AC_CHECK_DESERT([have_desert=yes],[have_desert=no]) +if test x$have_desert != xyes ; then + AC_MSG_ERROR([Could not find desert, is --with-desert set correctly?]) +fi + + +AC_DEFINE(CPP_NAMESPACE,std) + +AC_CONFIG_FILES([ + m4/Makefile + Makefile + ]) + +AC_OUTPUT diff --git a/DESERT_Addons/uwauv/initlib.cc b/DESERT_Addons/uwauv/initlib.cc new file mode 100644 index 00000000..8599dee8 --- /dev/null +++ b/DESERT_Addons/uwauv/initlib.cc @@ -0,0 +1,89 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * @file initlib.cc + * @author Alessia Ortile + * @version 1.0.0 + * + * \brief Provides the initialization of uwauv libraries. + * + * Provides the initialization of uwauv libraries. In addition, + * it provides both UWAUV monitoring and control packets header description. + * + */ + +#include +#include + +#include "uwauv-packet.h" +extern EmbeddedTcl UwauvTclCode; + +packet_t PT_UWAUV; +packet_t PT_UWAUV_CTR; +packet_t PT_UWAUV_ERROR; + +static class UwAUVMonPktClass : public PacketHeaderClass { +public: + + UwAUVMonPktClass() : PacketHeaderClass("PacketHeader/UWAUV", sizeof (hdr_uwAUV_monitoring)) { + this->bind(); + bind_offset(&hdr_uwAUV_monitoring::offset_); + } +} class_uwAUV_pkt; +/** + * Adds the header for hdr_uwAUV packets in ns2. + */ +static class UwAUVCtrPktClass : public PacketHeaderClass { +public: + + UwAUVCtrPktClass() : PacketHeaderClass("PacketHeader/UWAUVCtr", sizeof (hdr_uwAUV_ctr)) { + this->bind(); + bind_offset(&hdr_uwAUV_ctr::offset_); + } +} class_uwAUVCtr_pkt; + +static class UwAUVErrorPktClass : public PacketHeaderClass { +public: + + UwAUVErrorPktClass() : PacketHeaderClass("PacketHeader/UWAUVError", sizeof (hdr_uwAUV_error)) { + this->bind(); + bind_offset(&hdr_uwAUV_error::offset_); + } +} class_uwAUVError_pkt; + + + +extern "C" int Uwauv_Init() { + PT_UWAUV = p_info::addPacket("UWAUV"); + PT_UWAUV_CTR = p_info::addPacket("UWAUVCtr"); + PT_UWAUV_ERROR = p_info::addPacket("UWAUVError"); + UwauvTclCode.load(); + return 0; +} + diff --git a/DESERT_Addons/uwauv/m4/Makefile.am b/DESERT_Addons/uwauv/m4/Makefile.am new file mode 100755 index 00000000..e356c5e6 --- /dev/null +++ b/DESERT_Addons/uwauv/m4/Makefile.am @@ -0,0 +1,30 @@ +# +# Copyright (c) 2012 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +EXTRA_DIST = nsallinone.m4 nsmiracle.m4 desert.m4 + diff --git a/DESERT_Addons/uwauv/m4/desert.m4 b/DESERT_Addons/uwauv/m4/desert.m4 new file mode 100644 index 00000000..97c6b179 --- /dev/null +++ b/DESERT_Addons/uwauv/m4/desert.m4 @@ -0,0 +1,153 @@ +# +# Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + + +AC_DEFUN([AC_ARG_WITH_DESERT],[ + + DESERT_PATH='' + DESERT_CPPLAGS='' + DESERT_LDFLAGS='' + DESERT_LIBADD='' + + AC_ARG_WITH([desert], + [AS_HELP_STRING([--with-desert=], + [use desert installation in ])], + [ + if test "x$withval" != "xno" ; then + if test -d $withval ; then + DESERT_PATH="${withval}" + if test ! -d "${DESERT_PATH}" ; then + AC_MSG_ERROR([could not find ${withval}, is --with-desert=${withval} correct?]) + fi + + for dir in \ + application/uwcbr \ + network/uwip \ + transport/uwudp \ + mobility/uwsmposition \ + mobility/uwsmwpposition + do + echo "considering dir \"$dir\"" + DESERT_CPPFLAGS="$DESERT_CPPFLAGS -I${DESERT_PATH}/${dir}" + DESERT_LDFLAGS="$DESERT_LDFLAGS -L${DESERT_PATH}/${dir}" + done + + for lib in \ + uwcbr \ + uwip \ + uwudp \ + uwsmposition \ + uwsmwpposition + do + DESERT_LIBADD="$DESERT_LIBADD -l${lib}" + done + + DESERT_DISTCHECK_CONFIGURE_FLAGS="--with-desert=$withval" + AC_SUBST(DESERT_DISTCHECK_CONFIGURE_FLAGS) + + else + AC_MSG_ERROR([desert path $withval is not a directory]) + fi + fi + ]) + + AC_SUBST(DESERT_CPPFLAGS) + AC_SUBST(DESERT_LDFLAGS) + AC_SUBST(DESERT_LIBADD) +]) + +AC_DEFUN([AC_ARG_WITH_DESERT_BUILD],[ + + DESERT_PATH_BUILD='' + DESERT_LDFLAGS_BUILD='' + + AC_ARG_WITH([desert-build], + [AS_HELP_STRING([--with-desert-build=], + [use desert installation in ])], + [ + if test "x$withval" != "xno" ; then + if test -d $withval ; then + DESERT_PATH_BUILD="${withval}" + if test ! -d "${DESERT_PATH_BUILD}" ; then + AC_MSG_ERROR([could not find ${withval}, is --with-desert-build=${withval} correct?]) + fi + + for dir in \ + application/uwcbr \ + network/uwip \ + transport/uwudp \ + mobility/uwsmposition \ + mobility/uwsmwpposition + do + echo "considering dir \"$dir\"" + DESERT_LDFLAGS_BUILD="$DESERT_LDFLAGS_BUILD -L${DESERT_PATH_BUILD}/${dir}" + done + + else + AC_MSG_ERROR([desert path $withval is not a directory]) + fi + fi + ]) + + #AC_SUBST(DESERT_CPPFLAGS) + AC_SUBST(DESERT_LDFLAGS_BUILD) +]) + +AC_DEFUN([AC_CHECK_DESERT],[ + # temporarily add NS_CPPFLAGS and NSMIRACLE_CPPFLAGS to CPPFLAGS + BACKUP_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $NS_CPPFLAGS $NSMIRACLE_CPPFLAGS" + + AC_LANG_PUSH(C++) + + AC_MSG_CHECKING([for desert headers]) + + AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[ + #include + ClMessageTracer* t; + ]],[[ + ]] )], + [AC_MSG_RESULT([yes]) + found_desert=yes + [$1] + ], + [AC_MSG_RESULT([no]) + found_desert=no + [$2] + ]) + + + AM_CONDITIONAL([HAVE_DESERT], [test x$found_desert = xyes]) + + # Restoring to the initial value + CPPFLAGS="$BACKUP_CPPFLAGS" + + AC_LANG_POP(C++) +]) diff --git a/DESERT_Addons/uwauv/m4/nsallinone.m4 b/DESERT_Addons/uwauv/m4/nsallinone.m4 new file mode 100644 index 00000000..a4564f06 --- /dev/null +++ b/DESERT_Addons/uwauv/m4/nsallinone.m4 @@ -0,0 +1,189 @@ +# +# Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +AC_DEFUN([AC_PATH_NS_ALLINONE], [ + +NS_ALLINONE_PATH='' +NS_PATH='' +TCL_PATH='' +OTCL_PATH='' +NS_CPPFLAGS='' + +AC_ARG_WITH([ns-allinone], + [AS_HELP_STRING([--with-ns-allinone=], + [use ns-allinone installation in , where it is expected to find ns, tcl, otcl and tclcl subdirs])], + [ + if test ! -d $withval ; then + AC_MSG_ERROR([ns-allinone path $withval is not valid]) + else + + NS_ALLINONE_PATH=$withval + + NS_PATH=$NS_ALLINONE_PATH/`cd $NS_ALLINONE_PATH; ls -d ns-* | head -n 1` + TCL_PATH=$NS_ALLINONE_PATH/`cd $NS_ALLINONE_PATH; ls -d * | grep -e 'tcl[0-9].*' | head -n 1` + TCLCL_PATH=$NS_ALLINONE_PATH/`cd $NS_ALLINONE_PATH; ls -d tclcl-* | head -n 1` + OTCL_PATH=$NS_ALLINONE_PATH/`cd $NS_ALLINONE_PATH; ls -d otcl-* | head -n 1` + + NS_CPPFLAGS="-isystem $NS_ALLINONE_PATH/include -isystem $NS_PATH -isystem $TCLCL_PATH -isystem $OTCL_PATH" + + + NS_ALLINONE_DISTCHECK_CONFIGURE_FLAGS="--with-ns-allinone=$withval" + AC_SUBST(NS_ALLINONE_DISTCHECK_CONFIGURE_FLAGS) + + fi + ]) + + if test x$NS_ALLINONE_PATH = x ; then + AC_MSG_ERROR([you must specify ns-allinone installation path using --with-ns-allinone=PATH]) + fi + + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/mac" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/propagation" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/mobile" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/pcap" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/tcp" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/sctp" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/common" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/link" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/queue" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/trace" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/adc" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/apps" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/routing" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/tools" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/classifier" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/mcast" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/diffusion3/lib" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/diffusion3/lib/main" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/diffusion3/lib/nr" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/diffusion3/ns" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/diffusion3/filter_core" + NS_CPPFLAGS="$NS_CPPFLAGS -isystem $NS_PATH/asim" + + AC_SUBST(NS_CPPFLAGS) + AC_MSG_CHECKING([for NS_LDFLAGS and NS_LIBADD type]) + + system=`uname -s` + case $system in + CYGWIN*) + AC_MSG_RESULT([cygwin]) + echo "running cygwin" + NS_LDFLAGS=" -shared -no-undefined -L${NS_PATH} -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive " + NS_LIBADD=" -lns" + ;; + *) + AC_MSG_RESULT([none needed]) + # OK for linux, should be fine for unix in general + NS_LDFLAGS="" + NS_LIBADD="" + ;; + esac + + AC_SUBST(NS_LDFLAGS) + AC_SUBST(NS_LIBADD) + + + ######################################################## + # checking if ns-allinone path has been setup correctly + ######################################################## + + # temporarily add NS_CPPFLAGS to CPPFLAGS + BACKUP_CPPFLAGS=$CPPFLAGS + CPPFLAGS=$NS_CPPFLAGS + #BACKUP_CFLAGS=$CFLAGS + #CFLAGS=$NS_CPPFLAGS + + + dnl AC_CHECK_HEADERS([tcl.h],,AC_MSG_ERROR([could not find tcl.h])) + dnl AC_CHECK_HEADERS([otcl.h],,AC_MSG_ERROR([could not find otcl.h])) + + dnl AC_CHECK_HEADERS([tclcl.h],,AC_MSG_ERROR([could not find tclcl.h]) + dnl [ + dnl #if HAVE_TCL_H + dnl #include + dnl #endif + dnl ]) + + AC_LANG_PUSH(C++) + + AC_MSG_CHECKING([for ns-allinone installation]) + + AC_PREPROC_IFELSE( + [AC_LANG_PROGRAM([[ + #include + #include + #include + #include + Packet* p; + ]],[[ + p = new packet; + delete p; + ]] )], + [AC_MSG_RESULT([ok])], + [ + AC_MSG_RESULT([FAILED!]) + AC_MSG_ERROR([Could not find NS headers. Is --with-ns-allinone set correctly? ]) + ]) + + + AC_MSG_CHECKING([if ns-allinone installation has been patched for dynamic libraries]) + + AC_PREPROC_IFELSE( + [AC_LANG_PROGRAM([[ + #include + #include + #include + #include + ]],[[ + p_info::addPacket("TEST_PKT"); + ]] )], + [AC_MSG_RESULT([yes])], + [ + AC_MSG_RESULT([NO!]) + AC_MSG_ERROR([The ns-allinone installation in $NS_ALLINONE_PATH has not been patched for dynamic libraries. + Either patch it or change the --with-ns-allinone switch so that it refers to a patched version. ]) + ]) + + AC_LANG_POP(C++) + + # Restoring to the initial value + CPPFLAGS=$BACKUP_CPPFLAGS + #CFLAGS=$BACKUP_CFLAGS + + ## AC_ARG_VAR([TCLCL_PATH],[blah blah blah]) + ## AC_PATH_PROG([TCL2CPP],[tcl2c++],[none],[$PATH:$TCLCL_PATH]) + + AC_ARG_VAR([TCL2CPP],[tcl2c++ executable]) + AC_PATH_PROG([TCL2CPP],[tcl2c++],[none],[$PATH:$TCLCL_PATH]) + if test "x$TCL2CPP" = "xnone" ; then + AC_MSG_ERROR([could not find tcl2c++]) + fi +]) + diff --git a/DESERT_Addons/uwauv/m4/nsmiracle.m4 b/DESERT_Addons/uwauv/m4/nsmiracle.m4 new file mode 100644 index 00000000..e4eae27d --- /dev/null +++ b/DESERT_Addons/uwauv/m4/nsmiracle.m4 @@ -0,0 +1,189 @@ +# +# Copyright (c) 2014 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + + + + +AC_DEFUN([AC_ARG_WITH_NSMIRACLE],[ + NSMIRACLE_PATH='' + NSMIRACLE_CPPLAGS='' + NSMIRACLE_LDFLAGS='' + NSMIRACLE_LIBADD='' + + AC_ARG_WITH([nsmiracle], + [AS_HELP_STRING([--with-nsmiracle=], + [use nsmiracle installation in ])], + [ + if test "x$withval" != "xno" ; then + if test -d $withval ; then + NSMIRACLE_PATH="${withval}" + + if test ! -f "${NSMIRACLE_PATH}/nsmiracle/module.h" ; then + AC_MSG_WARN([could not find ${withval}/nsmiracle/module.h, is --with-nsmiracle=${withval} correct?]) + fi + + for dir in \ + nsmiracle \ + cbr \ + ip \ + link \ + mac802_11 \ + marq \ + mobility \ + mphy \ + mmac \ + phy802_11 \ + port \ + tcp \ + wirelessch \ + aodv \ + mll \ + routing \ + aodv \ + uwm + do + #echo "considering dir \"$dir\"" + NSMIRACLE_CPPFLAGS="$NSMIRACLE_CPPFLAGS -isystem${NSMIRACLE_PATH}/${dir}" + NSMIRACLE_LDFLAGS="$NSMIRACLE_LDFLAGS -L${NSMIRACLE_PATH}/${dir}" + + done + + for lib in \ + MiracleBasicMovement \ + miracletcp \ + MiracleWirelessCh \ + miraclecbr \ + MiracleIp \ + MiraclePhy802_11 \ + MiracleMac802_11 \ + miracleport \ + Miracle \ + mphy \ + marq \ + mmac \ + mll \ + miraclelink \ + MiracleRouting \ + MiracleAodv \ + UwmStd \ + UwmStdPhyBpskTracer + do + NSMIRACLE_LIBADD="$NSMIRACLE_LIBADD -l${lib}" + done + + NSMIRACLE_DISTCHECK_CONFIGURE_FLAGS="--with-nsmiracle=$withval" + AC_SUBST(NSMIRACLE_DISTCHECK_CONFIGURE_FLAGS) + + else + AC_MSG_WARN([nsmiracle path $withval is not a directory]) + fi + fi + ]) + + AC_SUBST(NSMIRACLE_CPPFLAGS) + AC_SUBST(NSMIRACLE_LDFLAGS) + AC_SUBST(NSMIRACLE_LIBADD) +]) + +AC_DEFUN([AC_CHECK_NSMIRACLE],[ + # if test "x$NS_CPPFLAGS" = x ; then + # true + # AC_MSG_ERROR([NS_CPPFLAGS is empty!]) + # fi + + # if test "x$NSMIRACLE_CPPFLAGS" = x ; then + # true + # AC_MSG_ERROR([NSMIRACLE_CPPFLAGS is empty!]) + # fi + + # temporarily add NS_CPPFLAGS and NSMIRACLE_CPPFLAGS to CPPFLAGS + BACKUP_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $NS_CPPFLAGS $NSMIRACLE_CPPFLAGS" + + AC_LANG_PUSH(C++) + + AC_MSG_CHECKING([for nsmiracle headers]) + + AC_PREPROC_IFELSE( + [AC_LANG_PROGRAM([[ + #include + ClMessageTracer* t; + ]],[[ + ]] )], + [ + AC_MSG_RESULT([yes]) + found_nsmiracle=yes + [$1] + ], + [ + AC_MSG_RESULT([no]) + found_nsmiracle=no + [$2] + AC_MSG_WARN([could not find nsmiracle]) + ]) + + AM_CONDITIONAL([HAVE_NSMIRACLE], [test x$found_nsmiracle = xyes]) + + # Restoring to the initial value + CPPFLAGS="$BACKUP_CPPFLAGS" + + AC_LANG_POP(C++) +]) + +# AC_DEFUN([AC_PATH_NSMIRACLE], [ +# AC_REQUIRE(AC_PATH_NS_ALLINONE) + +# ######################################################## +# # checking if ns-allinone path has been setup correctly +# ######################################################## + +# # temporarily add NS_CPPFLAGS and NSMIRACLE_CPPFLAGS to CPPFLAGS +# BACKUP_CPPFLAGS=$CPPFLAGS +# CPPFLAGS="$CPPFLAGS $NS_CPPFLAGS NSMIRACLE_CPPFLAGS" + +# AC_MSG_CHECKING([if programs can be compiled against ns-miracle headers]) +# AC_PREPROC_IFELSE( +# [AC_LANG_PROGRAM([[ +# #include +# ClMessageTracer* t; +# ]],[[ +# ]] )], +# [AC_MSG_RESULT([yes])], +# [ +# AC_MSG_RESULT([no]) +# AC_MSG_ERROR([could not compile a test program against ns-miracle headers. Is --with-ns-miracle set correctly? ]) +# ]) + +# # AC_CHECK_HEADERS([cltracer.h],,AC_MSG_ERROR([you must specify ns-miracle installation path using --with-ns-miracle=PATH])) + +# # Restoring to the initial value +# CPPFLAGS=$BACKUP_CPPFLAGS +# ]) +# +# diff --git a/DESERT_Addons/uwauv/uwauv-init.tcl b/DESERT_Addons/uwauv/uwauv-init.tcl new file mode 100644 index 00000000..532cb833 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-init.tcl @@ -0,0 +1,130 @@ +# +# Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# @file uwauv-defaults.tcl +# @author Alessia Ortile +# @version 1.0.0 + +PacketHeaderManager set tab_(PacketHeader/UWAUV) 1 +PacketHeaderManager set tab_(PacketHeader/UWAUVCtr) 1 +PacketHeaderManager set tab_(PacketHeader/UWAUVError) 1 + + +Module/UW/AUV set packetSize_ 500 +Module/UW/AUV set period_ 60 +Module/UW/AUV set destPort_ 0 +Module/UW/AUV set destAddr_ 0 +Module/UW/AUV set debug_ 0 +Module/UW/AUV set PoissonTraffic_ 1 +Module/UW/AUV set drop_out_of_order_ 1 +Module/UW/AUV set ackTimeout_ 10 +Module/UW/AUV set ackPriority_ 0 +Module/UW/AUV set drop_old_waypoints_ 0 +Module/UW/AUV set log_flag_ 0 + +Module/UW/AUV instproc init {args} { + $self next $args + $self settag "UW/AUV" +} + +Module/UW/AUV/CTR set packetSize_ 500 +Module/UW/AUV/CTR set period_ 60 +Module/UW/AUV/CTR set destPort_ 0 +Module/UW/AUV/CTR set destAddr_ 0 +Module/UW/AUV/CTR set debug_ 0 +Module/UW/AUV/CTR set PoissonTraffic_ 1 +Module/UW/AUV/CTR set drop_out_of_order_ 0 +Module/UW/AUV/CTR set adaptiveRTO_ 0 + +Module/UW/AUV/CTR instproc init {args} { + $self next $args + $self settag "UW/AUV/CTR" +} + +Module/UW/AUV/ERR set packetSize_ 500 +Module/UW/AUV/ERR set period_ 60 +Module/UW/AUV/ERR set destPort_ 0 +Module/UW/AUV/ERR set destAddr_ 0 +Module/UW/AUV/ERR set debug_ 0 +Module/UW/AUV/ERR set PoissonTraffic_ 1 +Module/UW/AUV/ERR set drop_out_of_order_ 1 +Module/UW/AUV/ERR set adaptiveRTO_ 0 + +Module/UW/AUV/ERR instproc init {args} { + $self next $args + $self settag "UW/AUV/ERR" +} + +Module/UW/AUV/CER set packetSize_ 100 +Module/UW/AUV/CER set period_ 60 +Module/UW/AUV/CER set destPort_ 0 +Module/UW/AUV/CER set destAddr_ 0 +Module/UW/AUV/CER set debug_ 0 +Module/UW/AUV/CER set PoissonTraffic_ 0 +Module/UW/AUV/CER set drop_out_of_order_ 1 +Module/UW/AUV/CER set adaptiveRTO_ 0 + +Module/UW/AUV/CER instproc init {args} { + $self next $args + $self settag "UW/AUV/CER" +} + +Module/UW/AUV/CES set packetSize_ 100 +Module/UW/AUV/CES set period_ 60 +Module/UW/AUV/CES set destPort_ 0 +Module/UW/AUV/CES set destAddr_ 0 +Module/UW/AUV/CES set debug_ 0 +Module/UW/AUV/CES set PoissonTraffic_ 0 +Module/UW/AUV/CES set drop_out_of_order_ 1 +Module/UW/AUV/CES set adaptiveRTO_ 0 + +Module/UW/AUV/CES instproc init {args} { + $self next $args + $self settag "UW/AUV/CES" +} + +Module/UW/AUV/ERS set packetSize_ 100 +Module/UW/AUV/ERS set period_ 60 +Module/UW/AUV/ERS set destPort_ 0 +Module/UW/AUV/ERS set destAddr_ 0 +Module/UW/AUV/ERS set debug_ 0 +Module/UW/AUV/ERS set PoissonTraffic_ 0 +Module/UW/AUV/ERS set drop_out_of_order_ 1 +Module/UW/AUV/ERS set adaptiveRTO_ 0 + +Module/UW/AUV/ERS instproc init {args} { + $self next $args + $self settag "UW/AUV/ERS" +} + + + +Position/UWSM set debug_ 0 +Position/UWSMWP set debug_ 0 + +PlugIn/PositionDB set debug_ 0 diff --git a/DESERT_Addons/uwauv/uwauv-module.cc b/DESERT_Addons/uwauv/uwauv-module.cc new file mode 100644 index 00000000..ab1b4d4c --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-module.cc @@ -0,0 +1,324 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauv-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUV class implementation. +* +*/ + +#include "uwauv-module.h" +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +int hdr_uwAUV_monitoring::offset_; /**< Offset used to access in + hdr_uwAUV packets header. */ +int hdr_uwAUV_ctr::offset_; /**< Offset used to access in hdr_uwAUV + packets header. */ + +/** +* Adds the header for hdr_uwAUV packets in ns2. +*/ +/** +* Adds the module for UwAUVModuleClass in ns2. +*/ + +/** + * Class that represents the binding with the tcl configuration script + */ +static class UwAUVModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVModuleClass() : TclClass("Module/UW/AUV") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVModule()); + } +} class_module_uwAUV; + +void UwAUVSendAckTimer::expire(Event *e) { + module->sendAck(); +} + +UwAUVModule::UwAUVModule() + : UwCbrModule() + , last_sn_confirmed(0) + , ack(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackTimer_(this) + , ackPriority(0) + , ackNotPgbk(0) + , drop_old_waypoints(0) + , log_on_file(0) + , out_file_stats(0) +{ + posit= new UWSMWPPosition(); + bind("ackTimeout_", (double*) &ackTimeout); + bind("ackPriority_", (int*) &ackPriority); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timeout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + +} + +UwAUVModule::UwAUVModule(UWSMWPPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , ack(0) + , ackPolicy(ACK_PIGGYBACK) + , ackTimeout(10) + , ackTimer_(this) + , ackPriority(0) + , ackNotPgbk(0) + , drop_old_waypoints(0) + , log_on_file(0) + , out_file_stats(0) +{ + posit = p; + bind("ackTimeout_", (double*) &ackTimeout); + bind("ackPriority_", (int*) &ackPriority); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + if (ackTimeout < 0) { + cerr << NOW << " Invalide ACK timout < 0, timeout set to 10 by defaults" + << std::endl; + ackTimeout = 10; + } + + +} + +UwAUVModule::~UwAUVModule() {} + +void UwAUVModule::setPosition(UWSMWPPosition* p){ + posit = p; +} + +int UwAUVModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAckNotPgbk") == 0) { + tcl.resultf("%d", ackNotPgbk); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + + } + if (strcasecmp(argv[1], "setAckPolicy") == 0) { + if (atof(argv[2]) == 1) { + ackPolicy = ACK_PIGGYBACK; + return TCL_OK; + } + if (atof(argv[2]) == 2) { + ackPolicy = ACK_IMMEDIATELY; + return TCL_OK; + } + if (atof(argv[2]) == 3) { + ackPolicy = ACK_PGBK_OR_TO; + return TCL_OK; + } else { + cerr<<"Policy not supported" << std::endl; + return TCL_ERROR; + } + } + if (strcasecmp(argv[1], "setAckTimeout") == 0) { + ackTimeout = atof(argv[2]); + return TCL_OK; + } + if (strcasecmp(argv[1], "setAckPriority") == 0) { + ackPriority = atof(argv[2]); + return TCL_OK; + } + } else if(argc == 5){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } + } else if(argc == 6){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVModule::initPkt(Packet* p) { + + hdr_uwAUV_monitoring* uwAUVh = hdr_uwAUV_monitoring::access(p); + + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + uwAUVh->x() = posit->getX(); + uwAUVh->y() = posit->getY(); + uwAUVh->z() = posit->getZ(); + + ack=0; + + if (debug_) + std::cout << NOW << " UwAUVModule::initPkt(Packet *p) AUV current " + << "position: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << ", Z = " << uwAUVh->z()<< std::endl; + + ackTimer_.force_cancel(); + UwCbrModule::initPkt(p); + + if (debug_) { + std::cout << NOW << " UwAUVModule::sending packet with priority " + << (int)uwcbrh->priority() << std::endl; + } + + priority_ = 0; +} + +void UwAUVModule::recv(Packet* p) { + + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); + + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { + + if (debug_) { + std::cout << NOW << " UwAUVModule::old waypoint with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + + posit->addDest(uwAUVh->x(),uwAUVh->y(),uwAUVh->z(),uwAUVh->speed()); + last_sn_confirmed = uwAUVh->sn(); + + } + + ack = last_sn_confirmed+1; + priority_ = (char) ackPriority; + + if (log_on_file == 1) { + out_file_stats.open("my_log_file.csv",std::ios_base::app); + out_file_stats << left << "time: " << NOW << ", positions AUV: x = " + << posit->getX() << ", y = " << posit->getY() + << ", z = " << posit->getZ() << std::endl; + out_file_stats.close(); + } + + + if (debug_) + std::cout << NOW << " UwAUVModule::recv(Packet *p) AUV received new " + << "way point: X = " << uwAUVh->x() << ", Y = " << uwAUVh->y() + << ", Z = " << uwAUVh->z()<< std::endl; + + UwCbrModule::recv(p); + + if (ackPolicy == ACK_IMMEDIATELY) { + sendAck(); + } + + if (ackPolicy == ACK_PGBK_OR_TO) { + ackTimer_.resched(ackTimeout); + } +} + +void UwAUVModule::sendAck() { + + ackNotPgbk++; + if (ackPriority == 0) { + UwCbrModule::sendPkt(); + if (debug_){ + if (ackPolicy == ACK_IMMEDIATELY) { + cout << NOW << " ACK sent immediately with standard priority " + << std::endl; + } else { + cout << NOW << " ACK timeout expired, ACK sent with standard " + << "priority " << std::endl; + } + } + } else { + UwCbrModule::sendPktHighPriority(); + if (debug_){ + if (ackPolicy == ACK_IMMEDIATELY) { + cout << NOW << " ACK sent immediately with high priority " + << std::endl; + } else { + cout << NOW << " ACK timeout expired, ACK sent with high priority" + << std::endl; + } + } + } + +} \ No newline at end of file diff --git a/DESERT_Addons/uwauv/uwauv-module.h b/DESERT_Addons/uwauv/uwauv-module.h new file mode 100644 index 00000000..2398a259 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-module.h @@ -0,0 +1,174 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauv-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +*/ + +#ifndef UWAUV_MODULE_H +#define UWAUV_MODULE_H +#include +#include +#include "uwsmwpposition.h" +#include +#include +#define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVModule; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVSendAckTimer : public TimerHandler +{ +public: + UwAUVSendAckTimer(UwAUVModule *m) : TimerHandler() { + module = m; + } +protected: + virtual void expire(Event *e); + UwAUVModule *module; +}; + +/** +* UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. +*/ +class UwAUVModule : public UwCbrModule { + friend class UwAUVSendAckTimer; +public: + + /** + * Default Constructor of UwAUVModule class. + */ + UwAUVModule(); + + /** + * Constructor with position setting of UwAUVModule class. + * + * @param UWSMWPPosition* p Pointer to the AUV position + */ + UwAUVModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVModule class. + */ + virtual ~UwAUVModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a monitoring data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + **/ + virtual void recv(Packet*); + + /** + * Sets the position of the AUV + * + * @param UWSMWPPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMWPPosition* getPosition() const { return posit; } + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_ctr packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + /** + * Sends ACK if ackTimeout expire; + * + */ + virtual void sendAck(); + +protected: + + enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; + + UWSMWPPosition* posit; /**< AUV position.*/ + int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ + int ack; /**< If not zero, contains the ACK to the last command Packete received.*/ + std::queue buffer; /**< Packets buffer.*/ + UWAUV_ACK_POLICY ackPolicy; /**< Flag to set the policy for ACK transimission, + ACK_PIGGYBACK: ACK is always sent in piggyback, + ACK_IMMEDIATELY: ACK is always sent immediately with a dedicated + packet after the reception of CTR packet + ACK_PGBK_OR_TO: ACK is sent in piggyback if a AUV packet is generated + before a ackTimeout otherwise ACK is sent with a + dedicated packet after the acKTimeout.*/ + double ackTimeout; /**< Timeout after which ACK is sent if ackPolicy = ACK_PGBK_OR_TO. */ + UwAUVSendAckTimer ackTimer_; /**< Timer to schedule ACK transmission.*/ + int ackPriority; /**< Flag to give higher priority to ACK or not.*/ + int ackNotPgbk; /**< Number of ACK not sent in piggyback when ackPolicy = 2. */ + int drop_old_waypoints; /**< Flag set to 1 to drop waypoints with sequence number + lower or equal than last_sn_confirmed.*/ + + + int log_on_file; /**< Flag to enable log file writing.*/ + std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ +}; + +#endif // UWAUV_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauv-packet.h b/DESERT_Addons/uwauv/uwauv-packet.h new file mode 100644 index 00000000..f7e2a2e1 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauv-packet.h @@ -0,0 +1,182 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +/** + * @file uwauv-packet.h + * @author Alessia Ortile + * @version 1.0.0 + * + * \brief Provides both UWAUV monitoring and control packets header description. + * + * Provides both UWAUV monitoring and control packets header description, in + * particular the header structure. + */ + + +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +extern packet_t PT_UWAUV_ERROR; +/** + * hdr_uwAUV_ctr describes UWAUV_ctr packets for controlling the AUV. + */ +typedef struct hdr_uwAUV_ctr { + float x_; + float y_; + float z_; + float speed_; + double sn_; /**< sequence number */ + + static int offset_; /**< Required by the PacketHeaderManager. */ + + /** + * Reference to the offset_ variable. + */ + inline static int& offset() { + return offset_; + } + + inline static struct hdr_uwAUV_ctr * access(const Packet * p) { + return (struct hdr_uwAUV_ctr*) p->access(offset_); + } + + inline float& x() { + return x_; + } + + inline float& y() { + return y_; + } + + inline float& z() { + return z_; + } + + inline float& speed() { + return speed_; + } + inline double& sn() { + return sn_; + } +} hdr_uwAUV_ctr; + +/** + * hdr_uwAUV_monitoring describes UWAUV_monitoring packets sent by the AUV + * to the base station for monitoring the AUV state. + */ +typedef struct hdr_uwAUV_monitoring { + float x_; + float y_; + float z_; + double ack_; /**< ack piggybacked of a ctr message. If =0 is not ack, if =b>0 is + cumulative ack untill b, if c<0 is cumulative ack untill c-1 and NACK c.*/ + + static int offset_; /**< Required by the PacketHeaderManager. */ + + /** + * Reference to the offset_ variable. + */ + inline static int& offset() { + return offset_; + } + + inline static struct hdr_uwAUV_monitoring * access(const Packet * p) { + return (struct hdr_uwAUV_monitoring*) p->access(offset_); + } + + inline float& x() { + return x_; + } + + inline float& y() { + return y_; + } + + inline float& z() { + return z_; + } + + inline double& ack() { + return ack_; + } + +} hdr_uwAUV_monitoring; + +/** + * hdr_uwAUV_error describes UWAUV_error packets sent by the AUV to the + * surface vehicle to signal a problem. + */ +typedef struct hdr_uwAUV_error { + float x_; + float y_; + float z_; + float speed_; + double ack_; /**< ack piggybacked of a ctr message. If =0 is not ack, if =b>0 is cumulative + ack untill b, if c<0 is cumulative ack untill c-1 and NACK c.*/ + double sn_; + float error_; + + + static int offset_; /**< Required by the PacketHeaderManager. */ + + /** + * Reference to the offset_ variable. + */ + inline static int& offset() { + return offset_; + } + + inline static struct hdr_uwAUV_error * access(const Packet * p) { + return (struct hdr_uwAUV_error*) p->access(offset_); + } + + inline float& x() { + return x_; + } + + inline float& y() { + return y_; + } + + inline float& z() { + return z_; + } + + inline double& ack() { + return ack_; + } + inline double& sn() { + return sn_; + } + inline float& speed() { + return speed_; + } + inline float& error() { + return error_; + } +} hdr_uwAUV_error; diff --git a/DESERT_Addons/uwauv/uwauvctr-module.cc b/DESERT_Addons/uwauv/uwauvctr-module.cc new file mode 100644 index 00000000..c411d00c --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctr-module.cc @@ -0,0 +1,262 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauvctr-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVCtr class implementation. +* +* Provides the UWAUVCtr class implementation. +*/ + +#include "uwauvctr-module.h" +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; + +/** +* Adds the module for UwAUVCtrModuleClass in ns2. +*/ + +/** +* Class that represents the binding with the tcl configuration script +*/ +static class UwAUVCtrModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVCtrModuleClass() : TclClass("Module/UW/AUV/CTR") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVCtrModule()); + } +} class_module_uwAUV_ctr; + +UwAUVCtrModule::UwAUVCtrModule(UWSMWPPosition* p) + : UwCbrModule() + , sn(0) + , adaptiveRTO(0) + , adaptiveRTO_parameter(0.5) +{ + posit=p; + speed=0.5; + bind("adaptiveRTO_", (int *) &adaptiveRTO); + bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); + + if (adaptiveRTO_parameter < 0) { + cerr << NOW << "Invalid adaptive RTO parameter < 0, set to 0.5 " + << "by default " << std::endl; + adaptiveRTO_parameter = 0.5; + } +} + +UwAUVCtrModule::UwAUVCtrModule() + : UwCbrModule() + , sn(0) + , adaptiveRTO(0) + , adaptiveRTO_parameter(0.5) +{ + + posit= new UWSMWPPosition(); + speed = 0.5; + bind("adaptiveRTO_", (int *) &adaptiveRTO); + bind("adaptiveRTO_parameter_", (double *) &adaptiveRTO_parameter); + + if (adaptiveRTO_parameter < 0) { + cerr << NOW << "Invalide adaptive RTO parameter < 0, set to 0.5 " + << "by default " << std::endl; + adaptiveRTO_parameter = 0.5; + + } + +} + +UwAUVCtrModule::~UwAUVCtrModule() {} + +int UwAUVCtrModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", this->getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", this->getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + + } else if (strcasecmp(argv[1], "setSpeed") == 0) { + speed = atof(argv[2]); + return TCL_OK; + } else if (strcasecmp(argv[1], "setAdaptiveRTOparameter") == 0) { + adaptiveRTO_parameter = atof(argv[2]); + return TCL_OK; + } + } else if(argc == 5){ + if (strcasecmp(argv[1], "sendPosition") == 0) { + newX = atof(argv[2]); + newY = atof(argv[3]); + newZ = atof(argv[4]); + this->reset_retx(); + this->transmit(); + tcl.resultf("%s", "position Setted"); + return TCL_OK; + } + } else if(argc == 6){ + if (strcasecmp(argv[1], "sendPosition") == 0) { + newX = atof(argv[2]); + newY = atof(argv[3]); + newZ = atof(argv[4]); + speed = atof(argv[5]); + this->reset_retx(); + this->transmit(); + tcl.resultf("%s", "position Setted"); + return TCL_OK; + } + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVCtrModule::transmit() { + sendPkt(); + + if (adaptiveRTO == 1 && rttsamples > 0) { + period_ = sumrtt/rttsamples + adaptiveRTO_parameter* sumrtt/rttsamples; + if (debug_) { + std::cout << NOW << " UwAUVCtrModule::RTO set to " << period_ + << std::endl; + } + } + + sendTmr_.resched(period_); +} + +void UwAUVCtrModule::start() {} + +void UwAUVCtrModule::setPosition(UWSMWPPosition* p){ + posit = p; +} + +void UwAUVCtrModule::initPkt(Packet* p) { + if(this->p == NULL){ + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); + uwAUVh -> x() = newX; + uwAUVh->y() = newY; + uwAUVh->z() = newZ; + uwAUVh->speed() = speed; + uwAUVh->sn() = ++sn; + this->p = p; + } else { + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); + uwAUVh->x() = newX; + uwAUVh->y() = newY; + uwAUVh->z() = newZ; + uwAUVh->speed() = speed; + uwAUVh->sn() = sn; + if (debug_) { + std::cout << NOW << " UwAUVCtrModule::initPkt(Packet *p) " + << "Retransmitting"<< std::endl; + } + } + + if (debug_) { + if (rttsamples > 0) { + std::cout << NOW << " RTT UwAUVCtr: " << sumrtt/rttsamples + << " s" << std::endl; + } + } + + UwCbrModule::initPkt(p); + if (debug_) { + hdr_uwAUV_ctr* uwAUVh = hdr_uwAUV_ctr::access(p); + std::cout << NOW << " UwAUVCtrModule::initPkt(Packet *p) setting new" + << " AUV way-point: X = "<< uwAUVh->x() <<", Y = " + << uwAUVh->y() << ", Z = " << uwAUVh->z()<< std::endl; + } +} + +void UwAUVCtrModule::recv(Packet* p) { + + hdr_uwAUV_monitoring* monitoring = hdr_uwAUV_monitoring::access(p); + x_auv = monitoring->x(); + y_auv = monitoring->y(); + z_auv = monitoring->z(); + + + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + hdr_cmn *ch = hdr_cmn::access(p); + + if(monitoring->ack() == sn + 1) { + sendTmr_.force_cancel(); + this->p = NULL; + } + + if(monitoring->ack() > 0 && debug_) + std::cout << NOW << " UwAUVCtrModule::recv(Packet *p) control ACK " + << "received " << monitoring->ack()<< std::endl; + else if((monitoring->ack())<0 && debug_) + std::cout << NOW << " UwAUVCtrModule::recv(Packet *p) control error " + <<"received"<< std::endl; + if (debug_ > 10) + std::cout << NOW << " UwAUVCtrModule::recv(Packet *p) AUV monitoring " + << "position: X = " << x_auv << ", Y = " << y_auv + << ", Z = " << z_auv << std::endl; + + UwCbrModule::recv(p); +} diff --git a/DESERT_Addons/uwauv/uwauvctr-module.h b/DESERT_Addons/uwauv/uwauvctr-module.h new file mode 100644 index 00000000..e92ea393 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctr-module.h @@ -0,0 +1,188 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/** +* @file uwauvctr-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUV. +* +*/ + +#ifndef UWAUV_CTR_MODULE_H +#define UWAUV_CTR_MODULE_H +#include +#include "uwauv-packet.h" +#include +#include "node-core.h" +#include +#define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVCtrModule; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVCtrSendTimer : public UwSendTimer { + public: + + /** + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ + UwAUVCtrSendTimer(UwAUVCtrModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + +/** +* UwAUVCtrModule class is used to manage UWAUVCtr packets and to collect statistics about them. +*/ +class UwAUVCtrModule : public UwCbrModule { +public: + + /** + * Constructor of UwAUVCtrModule class. + */ + UwAUVCtrModule(); + + /** + * Constructor of UwAUVCtrModule class with position setting. + */ + UwAUVCtrModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVCtrModule class. + */ + virtual ~UwAUVCtrModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a control data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + /** + * Set the position of the AUVCtr + * + * @param Position * p Pointer to the AUVCtr position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMWPPosition* getPosition() const { return posit;} + + /** + * Returns the last AUV position monitored + * + * @return the last AUV position monitored + */ + inline Position getMonitoredAUVPosition() { + Position monitored_p_auv; + monitored_p_auv.setX(x_auv); + monitored_p_auv.setY(y_auv); + monitored_p_auv.setZ(z_auv); + return monitored_p_auv; + } + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet* p); + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); + + /** + * Start the controller. + */ + virtual void start(); + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + + +protected: + + UWSMWPPosition* posit; /**< Controller position.*/ + float x_auv; /**< X of the last AUV position monitored.*/ + float y_auv; /**< Y of the last AUV position monitored.*/ + float z_auv; /**< Z of the last AUV position monitored.*/ + float newX; /**< X of the new position sent to the AUV.*/ + float newY; /**< Y of the new position sent to the AUV.*/ + float newZ; /**< Z of the new position sent to the AUV.*/ + float speed; /**< Moving speed sent to the AUV.*/ + int sn; /**< Sequence number of the last control packet sent.*/ + Packet* p; + int adaptiveRTO; /**< 1 if an adaptive RTO is used, 0 if a + constant RTO is used.*/ + double adaptiveRTO_parameter; /**< Parameter for the adaptive RTO.*/ + +}; + +#endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.cc b/DESERT_Addons/uwauv/uwauvctrer-module.cc new file mode 100644 index 00000000..e2c3870f --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-module.cc @@ -0,0 +1,624 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauvctrer-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVCtrEr class implementation. +* +* Provides the UWAUVCtrEr class implementation. +*/ + +#include "uwauvctrer-module.h" +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +extern packet_t PT_UWAUV_ERROR; + + +/** +* Class that represents the binding with the tcl configuration script +*/ +static class UwAUVCtrErModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVCtrErModuleClass() : TclClass("Module/UW/AUV/CER") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVCtrErModule()); + } +} class_module_uwAUV_error; + + +UwAUVCtrErModule::UwAUVCtrErModule(UWSMWPPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , speed(1.5) + , accuracy(0.001) +{ + posit=p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); + +} + +UwAUVCtrErModule::UwAUVCtrErModule() + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , speed(1.5) + , accuracy(0.001) + +{ + posit = new UWSMWPPosition(); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); + +} + +UwAUVCtrErModule::~UwAUVCtrErModule() {} + +int UwAUVCtrErModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", this->getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", this->getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + tcl.resultf("%d", this->getAUVErrorHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + } else if (strcasecmp(argv[1], "setSpeed") == 0) { + speed = atof(argv[2]); + return TCL_OK; + } + } + + return UwCbrModule::command(argc,argv); +} + + +void UwAUVCtrErModule::setPosition(UWSMWPPosition* p){ + + posit = p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + if (log_on_file == 1) { + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + } + +} + +void UwAUVCtrErModule::transmit() { + + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::Sending pkt with period: " << period + << std::endl; + } + + sendTmr_.resched(period); +} + +float UwAUVCtrErModule::getDistance(float x_s,float y_s,float x_d,float y_d){ + + float dx = x_s - x_d; + float dy = y_s - y_d; + return std::sqrt(dx*dx + dy*dy); + +} + +float UwAUVCtrErModule::getDistance(float x_s,float y_s,float z_s,float x_d,float y_d,float z_d){ + + float dx = x_s - x_d; + float dy = y_s - y_d; + float dz = z_s - z_d; + + return std::sqrt(dx*dx + dy*dy + dz*dz); + +} + +void UwAUVCtrErModule::initPkt(Packet* p) { + + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + + bool found = false; + uwAUVh->error() = 0; + + if (error_released){ + + uwAUVh->error() = -1; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + error_released = false; + this->p = p; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::initPkt(Packet *p) Error" + << "released"<< std::endl; + + + } else if (alarm_mode == 2 && active_alarm){ //I need to go there + + if (log_on_file == 1) { + + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + //If in the right position + if (getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0){ + + found = true; + alarm_mode = 3; + posit->setDest(x_err,y_err,-90,speed); + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "reached the surface destination"<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) start to dive" + << std::endl; + } + + + //if the right position + } else if(getDistance(x_sorg,y_sorg,x_err,y_err) < + getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg)){ + + found = true; + alarm_mode = 3; + posit->setDest(x_err,y_err,-90,speed); + + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) ASV has gone" + << "too far "<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) start to dive" + << std::endl; + } + } + + if(!found){ + uwAUVh->error() = 1; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_err; + uwAUVh->y() = y_err; + this->p = p; + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) ERROR ("<< x_err + << "," << y_err << ") still to solve" << std::endl; + } + } + } + + if(alarm_mode == 3 && active_alarm){ + + found = false; + + if (getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-90) == 0.0){ + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "in range"<< std::endl; + + }else if(getDistance(x_sorg,y_sorg,-1,x_err,y_err,-90) < + getDistance(posit->getX(),posit->getY(),posit->getZ(),x_sorg,y_sorg,-1)){ + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "in range (too far)"<< std::endl; + + } + + if (found){ + + uwAUVh->error() = -2; + alarm_mode = 0; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + this->p = p; + active_alarm = false; + + posit->setDest(x_err,y_err,-1,speed); + + + if (log_on_file == 1) { + + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << x_s<<","<sn() <= last_sn_confirmed) { + if (debug_) { + std::cout << NOW << " UwAUVCtrErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + } else { + if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule:: no error" << std::endl; + + } else { // error of some kind + + rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); + + int status = checkError(uwAUVh->error(),1,uwAUVh->x(), uwAUVh->y()); + + bool exists = false; + + if (!gray_queue.empty()){ + + int i=0; + for (const auto& vec : gray_queue) { + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + i++; + } + + if(exists){ + + if (debug_) + std::cout << NOW << " UwAUVCtrErModule::recv(Pakct p) gray_queue error" + << "value updated, old error("<< (gray_queue[i][2]/gray_queue[i][3]) << "),"; + + gray_queue[i][2] += uwAUVh->error(); + gray_queue[i][3] += 1; + + status = checkError(gray_queue[i][2],gray_queue[i][3], uwAUVh->x(), uwAUVh->y()); + + if (debug_) + std::cout << " updated error("<< (gray_queue[i][2]/gray_queue[i][3]) + << ")" << std::endl; + + } + } + + if (status == 1){ + + if(!exists){ + gray_queue.push_back({uwAUVh->x(), uwAUVh->y(), uwAUVh->error(),1}); + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) new error added" + << "to gray_queue, error = " << uwAUVh->error() << std::endl; + std::cout << NOW << " UwAUVCtrErrModule::recv(Pakct p) Next gray error" + << "= " << (gray_queue[0][2]/gray_queue[0][3]) << std::endl; + } + } + + + } else if(status == 2){ //status 2 + + //delete point in gray_queue + int i = 0; + if (!gray_queue.empty()){ + for (auto it = gray_queue.begin(); it != gray_queue.end(); ++it) { + if ((*it)[0]== uwAUVh->x() && (*it)[1] == uwAUVh->y()) { + gray_queue.erase(it); + break; + } + } + } + + if (!alarm_mode){ + + //check in the queue before + if (alarm_queue.empty()){ + + x_err = uwAUVh->x(); + y_err = uwAUVh->y(); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + posit->addDest(x_err,y_err,-1,speed); + alarm_mode = 2; + active_alarm = true; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV" + << "received new error(2): X = " << uwAUVh->x() << ", Y = " + << uwAUVh->y() << ", error = " << uwAUVh->error() << std::endl; + + if (log_on_file == 1) { + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< + posit->getY() << ","<< posit->getZ() << std::endl; + pos_log.close(); + + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << x_err <<","<addDest(x_err,y_err,-1,speed); + alarm_mode = 2; + active_alarm = true; + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + alarm_queue.erase(alarm_queue.begin()); + + }// otherwise wait another app to take care of it + + exists = false; + for (const auto& vec : alarm_queue) { + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + } + + if (!exists){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + if (log_on_file == 1) { + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<< + uwAUVh->y() << ", ON"<< std::endl; + err_log.close(); + } + } + + + + if (log_on_file == 1) { + + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< + posit->getY() << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p)" + << "SV add new error(2) in the queue: X = " << uwAUVh->x() + << ", Y = " << uwAUVh->y() << ", error = " << + uwAUVh->error() << std::endl; + + } + + } else { + + exists = false; + + for (const auto& vec : alarm_queue) { + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + } + + if (!exists){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + if (log_on_file == 1) { + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "R,"<< NOW << "," << uwAUVh->x() <<","<< + uwAUVh->y()<<", ON"<< std::endl; + err_log.close(); + } + } + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV" + << "add new error(2) in the queue: X = " << uwAUVh->x() << + ",Y = " << uwAUVh->y() << ", error = " << uwAUVh->error() + << std::endl; + + } + + } else { + + int i = 0; + for (auto it = gray_queue.begin(); it != gray_queue.end(); ++it) { + if ((*it)[0]== uwAUVh->x() && (*it)[1] == uwAUVh->y()) { + gray_queue.erase(it); + break; + } + } + + exists = false; + + for (const auto& vec : rcv_queue) { + //next error is associated to this app + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exists = true; + break; + } + } + + if(exists){ + + error_released = true; + x_s = uwAUVh->x(); + y_s = uwAUVh->y(); + + if (log_on_file == 1) { + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "G,"<< NOW << "," << x_s <<","<< y_s <<", OFF" + << std::endl; + err_log.close(); + } + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule:: After some tx" + <<"converged to no error" << std::endl; + } + + } + + } + + last_sn_confirmed = uwAUVh->sn(); + } + + UwCbrModule::recv(p); +} + +int UwAUVCtrErModule::checkError(double m, int n_pkt, float x, float y){ + + // prob of true error (t_e) greater than th_ne + double p_e = std::erfc((((th_ne - (m/n_pkt)) * std::sqrt(n_pkt)) / std::sqrt(2.0)) / sigma)/2; + //dev_status status; + int status; + if (p_e < accuracy){ //if p_e is small enough --> no error + //status = no_error; + status=0; + } else if (p_e > (1-accuracy)){ + // FOR SURE ERROR + //status = error; + status = 2; + } else { + //I NEED MORE DATA + //status = undetermined; + status=1; + } + + return status; +} + diff --git a/DESERT_Addons/uwauv/uwauvctrer-module.h b/DESERT_Addons/uwauv/uwauvctrer-module.h new file mode 100644 index 00000000..2f59e67a --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-module.h @@ -0,0 +1,244 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/** +* @file uwauvctrer-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVCtrEr. +* +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include "uwauv-packet.h" +#include "uwsmwpposition.h" +#include "node-core.h" +#include +#include +#define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVCtrErModule; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVErrorSendTimer : public UwSendTimer { + public: + + /** + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ + UwAUVErrorSendTimer(UwAUVCtrErModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + + +/** +* UwAUVCtrModule class is used to manage UWAUVCtr packets and to collect statistics about them. +*/ +class UwAUVCtrErModule : public UwCbrModule { +public: + + /** + * Constructor of UwAUVCtrModule class. + */ + UwAUVCtrErModule(); + + /** + * Constructor of UwAUVCtrModule class with position setting. + */ + UwAUVCtrErModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVCtrModule class. + */ + virtual ~UwAUVCtrErModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a control data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + /** + * Set the position of the AUVCtr + * + * @param Position * p Pointer to the AUVCtr position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMWPPosition* getPosition() const { return posit;} + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); + + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet* p); + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + /** + * Returns the size in byte of a hdr_uwAUV_error packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } + + /** + * Returns the distance (in a 2D space) between a starting point s and a destination point d. + * @param x_s x coordinate of point s + * @param y_s y coordinate of point s + * @param x_d x coordinate of point d + * @param y_d y coordinate of point d + * + * @return distance between s and d. + */ + float getDistance(float x_s,float y_s, float x_d, float y_d); + /** + * Returns the distance (in a 3D space) between a starting point s and a destination point d. + * @param x_s x coordinate of point s + * @param y_s y coordinate of point s + * @param z_s z coordinate of point s + * @param x_d x coordinate of point d + * @param y_d y coordinate of point d + * @param z_d z coordinate of point d + * + * @return distance between s and d. + */ + float getDistance(float x_s,float y_s, float z_s, float x_d, float y_d, float z_d); + +protected: + + UWSMWPPosition* posit; /**< Controller position.*/ + int last_sn_confirmed; /**< Sequence number of the last command Packete received.*/ + int sn; /**< Sequence number of the last control packet sent.*/ + int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number + lower or equal than last_sn_confirmed.*/ + int period; + + float x_err; /**< X of the last AUV position with an error.*/ + float y_err; /**< Y of the last AUV position with an error.*/ + + float x_s; /**< X of the last AUV position with an error that has been solved.*/ + float y_s; /**< Y of the last AUV position with an error that has been solved.*/ + + Packet* p; /**< Pointer to the packet that will be received*/ + int log_on_file; + float x_sorg; /**< X of the starting AUV position.*/ + float y_sorg; /**< Y of the starting AUV position.*/ + double speed; /**< speed of the AUV.*/ + + static int alarm_mode; /**< status of the error resolution mission + * 0 no error + * 2 SUV is mooving towards the error location + * 3 AUV is delving close to the depth of the error location.*/ + bool active_alarm; + bool error_released; /**< + * 0 no error + * 1 maybe an error --> wait more info + * 2 for sure an error -> go there + */ + static vector> alarm_queue; /**< list of the active errors*/ + static vector> gray_queue; /**< list of the errors which + the status is not determined yet*/ + +private: + + enum dev_status {no_error = 0, undetermined = 1, error=2}; /**< type of errors*/ + /** + * Return the status of an error based on the probability and the number of pkts rcv + * @param m probability of being an error + * @param n_pkt number of pkts received regarding the status of this error + * @param x x coordinate of the location of the error + * @param y y coordinate of the location of the error + */ + int checkError(double m, int n_pkt, float x, float y); + std::ofstream pos_log; + std::ofstream err_log; + std::ofstream t_err_log; + double sigma; /**< standard deviation */ + double th_ne; /**< if x < th_e NO error */ + double accuracy; /**< level of accuracy to achieve before defining the status of an error*/ + vector> rcv_queue; /**< list of error received*/ + +}; + +int UwAUVCtrErModule::alarm_mode = 0; +vector> UwAUVCtrErModule::alarm_queue = {}; +vector> UwAUVCtrErModule::gray_queue = {}; + + +#endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc new file mode 100644 index 00000000..e9f9a312 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.cc @@ -0,0 +1,469 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauvctrer-simple-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVCtrErSimple class implementation. +* +* Provides the UWAUVCtrErSimple class implementation. +*/ + +#include "uwauvctrer-simple-module.h" +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +extern packet_t PT_UWAUV_ERROR; +/** +* Class that represents the binding with the tcl configuration script +*/ +static class UwAUVCtrErSimpleModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVCtrErSimpleModuleClass() : TclClass("Module/UW/AUV/CES") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVCtrErSimpleModule()); + } +} class_module_uwAUV_error; + + +UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule(UWSMWPPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , speed(1.5) +{ + posit=p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); +} + +UwAUVCtrErSimpleModule::UwAUVCtrErSimpleModule() + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , speed(1.5) + +{ + posit= new UWSMWPPosition(); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + +} + +UwAUVCtrErSimpleModule::~UwAUVCtrErSimpleModule() {} + +int UwAUVCtrErSimpleModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", this->getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", this->getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + tcl.resultf("%d", this->getAUVErrorHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + } else if (strcasecmp(argv[1], "setSpeed") == 0) { + speed = atof(argv[2]); + return TCL_OK; + } + } + + return UwCbrModule::command(argc,argv); +} + +void UwAUVCtrErSimpleModule::setPosition(UWSMWPPosition* p){ + + posit = p; + x_sorg = posit->getX(); + y_sorg = posit->getY(); + +} + +void UwAUVCtrErSimpleModule::transmit() { + + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErSimpleModule::Sending pkt with period: " + << period << std::endl; + } + + sendTmr_.resched(period); +} + +float UwAUVCtrErSimpleModule::getDistance(float x_s,float y_s,float x_d,float y_d){ + + float dx = x_s - x_d; + float dy = y_s - y_d; + return std::sqrt(dx*dx + dy*dy); + +} + +float UwAUVCtrErSimpleModule::getDistance(float x_s,float y_s, float z_s, float x_d,float y_d, float z_d){ + + float dx = x_s - x_d; + float dy = y_s - y_d; + float dz = z_s - z_d; + + return std::sqrt(dx*dx + dy*dy + dz*dz); +} + +void UwAUVCtrErSimpleModule::initPkt(Packet* p) { + + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + bool found = false; + + uwAUVh->error() = 0; + + if ((alarm_mode == 1) & active_alarm){ + + if (log_on_file == 1) { + + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + //If in the right position + if ((getDistance(posit->getX(),posit->getY(),x_err,y_err) == 0.0)){ + + found = true; + alarm_mode = 2; + posit->setDest(x_err,y_err,-90,speed); + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "SV reached the surface destination"<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "SV starts to dive"<< std::endl; + } + + //if the right position + } else if((getDistance(x_sorg,y_sorg,x_err,y_err) < + getDistance(posit->getX(),posit->getY(),x_sorg,y_sorg))){ + + found = true; + alarm_mode = 2; + posit->setDest(x_err,y_err,-90,speed); + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p) SV" + << "has gone too far "<< std::endl; + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "SV starts to dive"<< std::endl; + } + } + + if (!found){ + + uwAUVh->error() = 1; + uwAUVh->sn() = sn; + uwAUVh->x() = x_err; + uwAUVh->y() = y_err; + this->p = p; + + if (debug_) { + std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p)" + << "ERROR ("<< x_err << "," << y_err << ") still to solve" + << std::endl; + } + + } + + } + if ((alarm_mode == 2) & active_alarm){ + + found =false; + + if ((getDistance(posit->getX(),posit->getY(),posit->getZ(),x_err,y_err,-90) == 0.0)){ + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "in range"<< std::endl; + } + + } else if((getDistance(x_sorg,y_sorg,-1,x_err,y_err,-90) < + getDistance(posit->getX(),posit->getY(),posit->getZ(),x_sorg,y_sorg,-1))){ + + found = true; + x_s = x_err; + y_s = y_err; + + if (debug_){ + std::cout << NOW << " UwAUVCtrErrModule::InitPkt(Packet *p)" + << "in range (too far)"<< std::endl; + } + } + + if (found) { + + uwAUVh->error() = -1; + alarm_mode = 0; + active_alarm = false; + uwAUVh->sn() = ++sn; + uwAUVh->x() = x_s; + uwAUVh->y() = y_s; + this->p = p; + + posit->setDest(x_err,y_err,-1,speed); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErSimpleModule::initPkt(Packet *p)" + << "ERROR ("<< x_err << "," << y_err << ") SOLVED" << std::endl; + } + + if (!alarm_queue.empty()){ //take care of the next error + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + + posit->addDest(x_err,y_err,-1,speed); + alarm_mode = 1; + active_alarm = true; + + alarm_queue.erase(alarm_queue.begin()); + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + if (debug_) { + std::cout << NOW << " UwAUVCtrErModule::initPkt(Packet *p) SV" + <<"picked a new error from the queue: X = " << x_err << "," + << "Y = " << y_err<< std::endl; + } + } + } + } + + UwCbrModule::initPkt(p); +} + +void UwAUVCtrErSimpleModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + bool exist = false; + + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { + if (debug_) { + std::cout << NOW << " UwAUVCtrErSimpleModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { + + if (uwAUVh->error() == 0){// AUV MARKED IT AS NO ERROR + + if (debug_) + std::cout << NOW << " UwAUVCtrErSimpleModule:: no error" + << std::endl; + + } else { // error + + if (!alarm_mode){ + + rcv_queue.push_back({uwAUVh->x(), uwAUVh->y()}); + + //check in the queue before + if (alarm_queue.empty()){ + + x_err = uwAUVh->x(); + y_err = uwAUVh->y(); + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + posit->addDest(x_err,y_err,-1,speed); + + alarm_mode = 1; + active_alarm = true; + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p)" + << "SV received new error(2): X = " << uwAUVh->x() << + ", Y = " << uwAUVh->y() << ", error = " << + uwAUVh->error() << std::endl; + + if (log_on_file == 1) { + + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< + posit->getY() << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + } else { + + exist=false; + + for (const auto& vec : rcv_queue) { + //next error is associated to this app + if (vec[0] == alarm_queue[0][0] && vec[1] == alarm_queue[0][1]) { + exist = true; + break; + } + } + + if(exist){ + + x_err = alarm_queue[0][0]; + y_err = alarm_queue[0][1]; + posit->addDest(x_err,y_err, -1,speed); + + alarm_mode = 1; + active_alarm = true; + + x_sorg = posit->getX(); + y_sorg = posit->getY(); + + alarm_queue.erase(alarm_queue.begin()); + } // otherwise wait another app to take care of it + + exist = false; + + for (const auto& vec : alarm_queue) { + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exist = true; + break; + } + } + + if (!exist){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + } + + if (log_on_file == 1) { + + pos_log.open("log/position_log.csv",std::ios_base::app); + pos_log << NOW << "," << posit->getX() << ","<< posit->getY() + << ","<< posit->getZ() << std::endl; + pos_log.close(); + + } + + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p)" + << "SV add new error(2) in the queue: X = " << uwAUVh->x() + << ", Y = " << uwAUVh->y() << ", error = " << + uwAUVh->error() << std::endl; + + } + + } else { + + exist = false; + + for (const auto& vec : alarm_queue) { + // Check if the coordinates are the same + if (vec[0] == uwAUVh->x() && vec[1] == uwAUVh->y()) { + exist = true; + break; + } + } + + if (!exist){ + alarm_queue.push_back({uwAUVh->x(),uwAUVh->y()}); + } + + if (debug_) + std::cout << NOW << " UwAUVCtrErrModule::recv(Packet *p) SV" + <<"add new error(2) in the queue: X = " << uwAUVh->x() << "," + << "Y = " << uwAUVh->y() << ", error = " << uwAUVh->error() + << std::endl; + + } + + } + + last_sn_confirmed = uwAUVh->sn(); + } + + UwCbrModule::recv(p); +} + + diff --git a/DESERT_Addons/uwauv/uwauvctrer-simple-module.h b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h new file mode 100644 index 00000000..6b48ba58 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauvctrer-simple-module.h @@ -0,0 +1,227 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/** +* @file uwauvctrer-b-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVCtrErSimple. +* +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include "uwauv-packet.h" +#include "uwsmwpposition.h" +#include "node-core.h" +#include +#include +#define UWAUV_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUV_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVCtrErSimpleModule; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVErrorSendTimer : public UwSendTimer { + public: + + /** + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ + UwAUVErrorSendTimer(UwAUVCtrErSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + + +/** +* UwAUVCtrModule class is used to manage UWAUVCtr packets and to collect statistics about them. +*/ +class UwAUVCtrErSimpleModule : public UwCbrModule { +public: + + /** + * Constructor of UwAUVCtrModule class. + */ + UwAUVCtrErSimpleModule(); + + /** + * Constructor of UwAUVCtrModule class with position setting. + */ + UwAUVCtrErSimpleModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVCtrModule class. + */ + virtual ~UwAUVCtrErSimpleModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a control data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Set the position of the AUVCtr + * + * @param Position * p Pointer to the AUVCtr position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUVCtr + * + * @return the current AUVCtr position + */ + inline UWSMWPPosition* getPosition() const { return posit;} + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); + + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet*); + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + /** + * Returns the size in byte of a hdr_uwAUV_error packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } + + /** + * Returns the distance (in a 2D space) between a starting point s and a destination point d. + * @param x_s x coordinate of point s + * @param y_s y coordinate of point s + * @param x_d x coordinate of point d + * @param y_d y coordinate of point d + * + * @return distance between s and d. + */ + float getDistance(float x_s,float y_s, float x_d, float y_d); + + /** + * Returns the distance (in a 3D space) between a starting point s and a destination point d. + * @param x_s x coordinate of point s + * @param y_s y coordinate of point s + * @param z_s z coordinate of point s + * @param x_d x coordinate of point d + * @param y_d y coordinate of point d + * @param z_d z coordinate of point d + * + * @return distance between s and d. + */ + float getDistance(float x_s,float y_s, float z_s, float x_d, float y_d, float z_d); + + + +protected: + + UWSMWPPosition* posit; /**< Controller position.*/ + int last_sn_confirmed; /**< Sequence number of the last command Packete received.*/ + int sn; /**< Sequence number of the last control packet sent.*/ + int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number + lower or equal than last_sn_confirmed.*/ + int period; + + float x_err; /**< X of the last AUV position with an error.*/ + float y_err; /**< Y of the last AUV position with an error.*/ + + float x_s; /**< X of the last AUV position with an error that has been solved.*/ + float y_s; /**< Y of the last AUV position with an error that has been solved.*/ + + Packet* p; /**< Pointer to the packet that will be received*/ + int log_on_file; + float x_sorg; /**< X of the starting AUV position.*/ + float y_sorg; /**< Y of the starting AUV position.*/ + double speed; /**< speed of the AUV.*/ + bool active_alarm; + + static int alarm_mode; /**< status of the error resolution mission + * 0 no error + * 2 SUV is mooving towards the error location + * 3 AUV is delving close to the depth of the error location.*/ + static vector> alarm_queue; /**< list of the active errors*/ + +private: + + std::ofstream pos_log; + std::ofstream err_log; + std::ofstream t_err_log; + vector> rcv_queue; /**< list of error received*/ + +}; + +int UwAUVCtrErSimpleModule::alarm_mode = 0; +vector> UwAUVCtrErSimpleModule::alarm_queue = {}; + +#endif // UWAUVCtr_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-module.cc b/DESERT_Addons/uwauv/uwauverror-module.cc new file mode 100644 index 00000000..64d9af37 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-module.cc @@ -0,0 +1,481 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauverror-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVError class implementation. +* +*/ + +#include "uwauverror-module.h" +#include +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +extern packet_t PT_UWAUV_ERROR; +int hdr_uwAUV_error::offset_; /**< Offset used to access in + hdr_uwAUVError packets header. */ +/** +* Adds the header for hdr_uwAUVError packets in ns2. +*/ + +/** + * Class that represents the binding with the tcl configuration script + */ +static class UwAUVErrorModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVErrorModuleClass() : TclClass("Module/UW/AUV/ERR") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVErrorModule()); + } +} class_module_uwAUV; + + + +UwAUVErrorModule::UwAUVErrorModule() + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , error_m(0) + , alarm_mode(0) + , speed(0.5) + , accuracy(0.001) +{ + + posit= new UWSMWPPosition(); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma ); + bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); + +} + +UwAUVErrorModule::UwAUVErrorModule(UWSMWPPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , error_m(0) + , alarm_mode(0) + , speed(0.5) + , accuracy(0.001) +{ + posit = p; + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("sigma_", (double*) &sigma); + bind("th_ne_", (double*) &th_ne ); + bind("accuracy_ne_", (double*) &accuracy ); + +} + +UwAUVErrorModule::~UwAUVErrorModule() {} + +void UwAUVErrorModule::setPosition(UWSMWPPosition* p){ + posit = p; +} + +int UwAUVErrorModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + tcl.resultf("%d", getAUVErrorHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + } + } else if(argc == 5){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } + } else if(argc == 6){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } + + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVErrorModule::transmit() { + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVErrorModule::Sending pkt with period: " << + period << std::endl; + } + sendTmr_.resched(period); +} + +void UwAUVErrorModule::initPkt(Packet* p) { + + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + + uwAUVh->error() = 0; + + if (alarm_mode != 2 ){ //if not in alarm mode + + if (alarm_mode == 1){ //gray zone + + error_m = getErrorMeasure(t_e); + + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "Gray Zone error, new measure: "<< error_m <<", true error: " + << t_e << std::endl; + } + + } else { + + error_m = getErrorMeasure(); + + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "New error, measure: "<< error_m <<", true error: "<< t_e + << std::endl; + } + + if(alarm_mode == 1){ // start error timer + + if (log_on_file == 1) { + + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "G,"<< NOW << "," << posit->getX() <<","<< + posit->getY() <<", ON"<< std::endl; + err_log.close(); + + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "ON,"<< NOW << "," << x_e <<","<< y_e << std::endl; + err_log.close(); + } + + } + } + + if (alarm_mode == 1){ + + x_e = posit->getX(); // Save error position + y_e = posit->getY(); + + //STOP + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); + posit->setAlarm(true); + + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = error_m; + this->p = p; + + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "ERROR ("<< x_e <<","<< y_e << "," << error_m <<")," + <<"alarm_mode = "<< alarm_mode<<", true error= "<< t_e + << std::endl; + } + + } else { + + if (debug_) { + std::cout << NOW << " UwAUVErroModule::initPkt(Packet *p) " + << "no error "<<" alarm_mode = " << alarm_mode << std::endl; + } + + } + + uwAUVh->sn() = ++sn; + + } else { + + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = error_m; + this->p = p; + uwAUVh->sn() = ++sn; + } + + + + UwCbrModule::initPkt(p); + + if (log_on_file == 1) { + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << ", " << posit->getSpeed()<< std::endl; + out_file_stats.close(); + } + +} + +void UwAUVErrorModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { + if (debug_) { + std::cout << NOW << " UwAUVErrModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + + } else { //packet in order + + /** + * error > 0 tx more data + * error > 1 stop tx, Ctr is coming + * error < 0 stop tx, there is no error + */ + + //Valid pkt refering to my error + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ + + if (uwAUVh->error() < 0 ){ + + posit->setAlarm(false); + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + + sendTmr_.force_cancel(); + sendTmr_.resched(period); + + if (log_on_file == 1) { + + err_log.open("log/error_log_t.csv",std::ios_base::app); + err_log << "W,"<< NOW << "," << x_e <<","<< y_e << + ",ON"<< std::endl; + err_log.close(); + + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "OFF,"<< NOW << "," << x_e <<","<< y_e + << std::endl; + err_log.close(); + + if (uwAUVh->error() == -1){ + + if(t_e <= th_ne){ + + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",tn" + << std::endl; + t_err_log.close(); + + } else { + + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",fn" + << std::endl; + t_err_log.close(); + + } + } + + } + + alarm_mode = 0; + + + if (debug_) { + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) error(" + << x_e <<","<< y_e <<") solved AUV can move again" + << "with speed=" << posit->getSpeed()<< std::endl; + } + + } else if (uwAUVh->error() >= 1 ){ + + alarm_mode = 2; + + if (log_on_file == 1) { + + if(t_e > th_ne){ + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",tp" + << std::endl; + t_err_log.close(); + + } else { + + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",fp" + << std::endl; + t_err_log.close(); + + } + + } + + if (debug_) + std::cout << NOW << " UwAUVErrModule::recv(Packet *p) for" + << "SURE there is an error ("<< x_e <<","<< y_e <<")" + << "STOP until ctr arrival"<< std::endl; + + } else {// ->error=0 + + alarm_mode = 1; + + if (debug_) + std::cout << NOW << " UwAUVErrModule::recv(Packet *p)" + << "MAYBE there is an error ("<< x_e <<","<< y_e <<")"<< + "continue tx"<< std::endl; + + } + } + + last_sn_confirmed = uwAUVh->sn(); + } + + UwCbrModule::recv(p); + + if (log_on_file == 1) { + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; + out_file_stats.close(); + } + +} + +double UwAUVErrorModule::getErrorMeasure(){ + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_real_distribution<> u_dis(0.0, 1.0); + + // Generate a random value from the uniform distribution + t_e = u_dis(gen); + + std::normal_distribution<> n_dis(0.0, sigma); + + // Generate a random value from the Gaussian distribution + double noise = n_dis(gen); + double m = t_e + noise; + + // Calculate the error probability + // prob of true error (t_e) greater than th_ne + double p_e = std::erfc(((th_ne - m) / std::sqrt(2.0)) / sigma)/2; + //if p_e is small enough --> no error, otherwise gray zone + if (p_e > accuracy){ + alarm_mode = 1; + } else { + if (t_e > th_ne){ + if (log_on_file == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",fn"<< std::endl; + t_err_log.close(); + } + } + } + + if (t_e > th_ne){ + + if (log_on_file == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",e"<< std::endl; + t_err_log.close(); + } + } + + + return m; + + +} + + +double UwAUVErrorModule::getErrorMeasure(double t_e){ + + std::random_device rd; + std::mt19937 gen(rd()); + + std::normal_distribution<> n_dis(0.0, sigma); + // Generate a random value from the Gaussian distribution + double noise = n_dis(gen); + + double m = t_e + noise; + + return m; + +} + + + diff --git a/DESERT_Addons/uwauv/uwauverror-module.h b/DESERT_Addons/uwauv/uwauverror-module.h new file mode 100644 index 00000000..fc47a6b8 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-module.h @@ -0,0 +1,205 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauv-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVError. +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include +#include "uwsmwpposition.h" +#include +#include +#define UWAUVError_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUVError_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUVError_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVErrorModule; + +/** +* UwAUVErrorSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVErrorSendTimer : public UwSendTimer { + public: + + /** + * Conscructor of UwAUVErrorSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ + UwAUVErrorSendTimer(UwAUVErrorModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + +/** +* UwAUVErrorModule class is used to manage UWAUV packets and to collect statistics about them. +*/ +class UwAUVErrorModule : public UwCbrModule { +public: + + /** + * Default Constructor of UwAUVErrorModule class. + */ + UwAUVErrorModule(); + + /** + * Constructor with position setting of UwAUVErrorModule class. + * + * @param UWSMWPPosition* p Pointer to the AUV position + */ + UwAUVErrorModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVErrorModule class. + */ + virtual ~UwAUVErrorModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a monitoring data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet* p); + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); + + /** + * Sets the position of the AUV + * + * @param UWSMWPPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMWPPosition* getPosition() const { return posit; } + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_ctr packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + /** + * Returns the size in byte of a hdr_uwAUV_error packet header. + * + * @return The size of a hdr_uwAUV_error packet header. + */ + static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } + + +protected: + + UWSMWPPosition* posit; /**< AUV position.*/ + int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ + int sn; + int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number + lower or equal than last_sn_confirmed.*/ + + + int log_on_file; /**< Flag to enable log file writing.*/ + Packet* p; /**< Pointer to the packet that will be received*/ + int period; + std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ + std::ofstream err_log; + std::ofstream t_err_log; + float x_e; /**< x coordinate error*/ + float y_e; /**< y coordinate error*/ + float error_m; /**< probability value of the error*/ + int alarm_mode; /**< error status + * 0 no error + * 1 maybe there is an error + * 2 error + */ + +private: + + double speed; /**< speed of the AUV*/ + /** + * Returns the probability of the presence of an error + * @return probability error + */ + virtual double getErrorMeasure(); + /** + * Returns the probability of the presence of an error given a previous measure + * @param t_e true error + * @return probability error + */ + virtual double getErrorMeasure(double t_e); + double t_e; /**< True error in that point*/ + double sigma; /**< standard deviation*/ + double th_ne; /**< if x < th_e NO error*/ + double accuracy; /**< level of accuracy to achieve before defining the status of an error*/ + +}; + +#endif // UWAUVError_MODULE_H diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.cc b/DESERT_Addons/uwauv/uwauverror-simple-module.cc new file mode 100644 index 00000000..b0985056 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.cc @@ -0,0 +1,351 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauverror-simple-module.cc +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWAUVErrorSimple class implementation. +* +*/ + +#include "uwauverror-simple-module.h" +#include +#include +#include +#include +extern packet_t PT_UWCBR; +extern packet_t PT_UWAUV; +extern packet_t PT_UWAUV_CTR; +extern packet_t PT_UWAUV_ERROR; + + +/** + * Class that represents the binding with the tcl configuration script + */ +static class UwAUVErrorSimpleModuleClass : public TclClass { +public: + + /** + * Constructor of the class + */ + UwAUVErrorSimpleModuleClass() : TclClass("Module/UW/AUV/ERS") { + } + + /** + * Creates the TCL object needed for the tcl language interpretation + * @return Pointer to an TclObject + */ + TclObject* create(int, const char*const*) { + return (new UwAUVErrorSimpleModule()); + } +} class_module_uwAUV; + + + +UwAUVErrorSimpleModule::UwAUVErrorSimpleModule() + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , error_p(0.001) + , alarm_mode(0) + , speed(0.5) + , accuracy(0.01) +{ + posit= new UWSMWPPosition(); + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma); + bind("accuracy_",(double*) &accuracy); + +} + +UwAUVErrorSimpleModule::UwAUVErrorSimpleModule(UWSMWPPosition* p) + : UwCbrModule() + , last_sn_confirmed(0) + , sn(0) + , drop_old_waypoints(1) + , log_on_file(0) + , period(60) + , error_p(0.01) + , alarm_mode(0) + , speed(0.5) + , accuracy(0.01) +{ + posit = p; + bind("drop_old_waypoints_", (int*) &drop_old_waypoints); + bind("log_on_file_", (int*) &log_on_file ); + bind("period_", (int*) &period ); + bind("error_p_", (int*) &error_p ); + bind("sigma_", (double*) &sigma); + bind("accuracy_",(double*) &accuracy); + +} + +UwAUVErrorSimpleModule::~UwAUVErrorSimpleModule() {} + +void UwAUVErrorSimpleModule::setPosition(UWSMWPPosition* p){ + posit = p; +} + +int UwAUVErrorSimpleModule::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2){ + if (strcasecmp(argv[1], "getAUVMonheadersize") == 0) { + tcl.resultf("%d", getAUVMonHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVctrheadersize") == 0) { + tcl.resultf("%d", getAUVCTRHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getAUVErrorheadersize") == 0) { + tcl.resultf("%d", getAUVErrorHeaderSize()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getX") == 0) { + tcl.resultf("%f", posit->getX()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getY") == 0) { + tcl.resultf("%f", posit->getY()); + return TCL_OK; + } else if(strcasecmp(argv[1], "getZ") == 0) { + tcl.resultf("%f", posit->getZ()); + return TCL_OK; + } + } else if(argc == 3){ + if (strcasecmp(argv[1], "setPosition") == 0) { + UWSMWPPosition* p = dynamic_cast (tcl.lookup(argv[2])); + if(p){ + posit=p; + tcl.resultf("%s", "position Setted\n"); + return TCL_OK; + } else { + tcl.resultf("%s", "Invalid position\n"); + return TCL_ERROR; + } + + } + } else if(argc == 5){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4])); + return TCL_OK; + } + } else if(argc == 6){ + if (strcasecmp(argv[1], "setDest") == 0) { + posit->setDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + posit->addDest(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5])); + return TCL_OK; + } + + } + return UwCbrModule::command(argc,argv); +} + +void UwAUVErrorSimpleModule::transmit() { + sendPkt(); + + if (debug_) { + std::cout << NOW << " UwAUVErrorSimpleModule::Sending pkt with period: " << period + << std::endl; + } + + + sendTmr_.resched(period); +} + +void UwAUVErrorSimpleModule::initPkt(Packet* p) { + + hdr_uwcbr *uwcbrh = HDR_UWCBR(p); + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + + uwAUVh->error() = 0; + + if (!alarm_mode){ + + std::random_device rd; + std::mt19937 generator(rd()); + std::uniform_real_distribution distrib(0.0, 1.0); + + double t_e = distrib(generator); //true error + + std::normal_distribution<> n_dis(0.0, sigma); + double noise = n_dis(generator); + + double m = t_e + noise; + + // prob of true error (t_e) greater than th_ne + double p_e = std::erfc((((1 - error_p) - m) / std::sqrt(2.0)) / sigma)/2; + if (t_e > (1-error_p)){ + if (log_on_file == 1) { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",e" << std::endl; + t_err_log.close(); + } + } + + if (p_e > accuracy){ //if p_e is small enough --> no error, otherwise error + + x_e = posit->getX(); + y_e = posit->getY(); + + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),0); + posit->setAlarm(true); + alarm_mode = true; + + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = 1; + uwAUVh->sn() = ++sn; + + if (log_on_file == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "ON,"<< NOW << "," << x_e <<","<< y_e << std::endl; + err_log.close(); + } + + if (log_on_file == 1) { + if(t_e > (1-error_p)){ + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",tp" << std::endl; + t_err_log.close(); + } else { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",fp" << std::endl; + t_err_log.close(); + } + } + } else { + + if (log_on_file == 1) { + if(t_e <= (1-error_p)){ + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",tn" << std::endl; + t_err_log.close(); + } else { + t_err_log.open("log/true_error_log.csv",std::ios_base::app); + t_err_log << NOW << "," << x_e <<","<< y_e <<",fn" << std::endl; + t_err_log.close(); + } + } + } + + + } else { + + uwAUVh->x() = x_e; + uwAUVh->y() = y_e; + uwAUVh->error() = 1; + this->p = p; + uwAUVh->sn() = ++sn; + } + + + UwCbrModule::initPkt(p); + + if (log_on_file == 1) { + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; + out_file_stats.close(); + } + +} + +void UwAUVErrorSimpleModule::recv(Packet* p) { + + hdr_uwAUV_error* uwAUVh = hdr_uwAUV_error::access(p); + + //obsolete packets + if (drop_old_waypoints == 1 && uwAUVh->sn() <= last_sn_confirmed) { + + if (debug_) { + std::cout << NOW << " UwAUVErrBModule::old error with sn " + << uwAUVh->sn() << " dropped " << std::endl; + } + } else { //packet in order + + //Valid pkt refering to my error + if (alarm_mode && uwAUVh->x() == x_e && uwAUVh->y() == y_e){ + + if (uwAUVh->error() < 0 ){ + + posit->setAlarm(false); + alarm_mode = 0; + posit->setDest(posit->getXdest(),posit->getYdest(),posit->getZdest(),speed); + + //wait an entire period before sending a new img + sendTmr_.force_cancel(); + sendTmr_.resched(period); + + if (log_on_file == 1) { + err_log.open("log/error_log.csv",std::ios_base::app); + err_log << "OFF,"<< NOW << "," << x_e <<","<< y_e << std::endl; + err_log.close(); + } + + if (debug_) { + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error(" + << x_e <<","<< y_e <<") solved AUV can move again with" + << "speed=" << posit->getSpeed()<< std::endl; + } + + } else if (uwAUVh->error() == 1 ){ + + alarm_mode = true; + + if (debug_) + std::cout << NOW << " UwAUVErrBModule::recv(Packet *p) error(" + << x_e <<","<< y_e <<") STOP until ctr arrival"<< std::endl; + + } + } + + last_sn_confirmed = uwAUVh->sn(); + } + + + UwCbrModule::recv(p); + + if (log_on_file == 1) { + out_file_stats.open("log/position_log_a.csv",std::ios_base::app); + out_file_stats << NOW << "," << posit->getX() << ","<< posit->getY() + << "," << posit->getZ() << ',' << posit->getSpeed() << std::endl; + out_file_stats.close(); + } + +} + diff --git a/DESERT_Addons/uwauv/uwauverror-simple-module.h b/DESERT_Addons/uwauv/uwauverror-simple-module.h new file mode 100644 index 00000000..a7af5a35 --- /dev/null +++ b/DESERT_Addons/uwauv/uwauverror-simple-module.h @@ -0,0 +1,191 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** +* @file uwauverror-b-module.h +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the definition of the class UWAUVErrorSimple. +*/ + +#ifndef UWAUVError_MODULE_H +#define UWAUVError_MODULE_H +#include +#include +#include "uwsmwpposition.h" +#include +#include +#define UWAUVError_DROP_REASON_UNKNOWN_TYPE "UKT" /**< Reason for a drop in a UWAUV module. */ +#define UWAUVError_DROP_REASON_OUT_OF_SEQUENCE "OOS" /**< Reason for a drop in a UWAUV module. */ +#define UWAUVError_DROP_REASON_DUPLICATED_PACKET "DPK" /**< Reason for a drop in a UWAUV module. */ + +class UwAUVErrorSimpleModule; + +/** +* UwSendTimer class is used to handle the scheduling period of UWAUV packets. +*/ +class UwAUVErrorSendTimer : public UwSendTimer { + public: + + /** + * Conscructor of UwSendTimer class + * @param UwAUVCtrModule *m pointer to an object of type UwAUVCtrModule + */ + UwAUVErrorSendTimer(UwAUVErrorSimpleModule *m) : UwSendTimer((UwCbrModule*)(m)){ + }; +}; + +/** +* UwAUVModule class is used to manage UWAUV packets and to collect statistics about them. +*/ +class UwAUVErrorSimpleModule : public UwCbrModule { +public: + + /** + * Default Constructor of UwAUVModule class. + */ + UwAUVErrorSimpleModule(); + + /** + * Constructor with position setting of UwAUVModule class. + * + * @param UWSMWPPosition* p Pointer to the AUV position + */ + UwAUVErrorSimpleModule(UWSMWPPosition* p); + + /** + * Destructor of UwAUVModule class. + */ + virtual ~UwAUVErrorSimpleModule(); + + /** + * TCL command interpreter. It implements the following OTcl methods: + * + * @param argc Number of arguments in argv. + * @param argv Array of strings which are the command parameters (Note that argv[0] is the name of the object). + * @return TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not. + * + **/ + virtual int command(int argc, const char*const* argv); + + /** + * Initializes a monitoring data packet passed as argument with the default values. + * + * @param Packet* Pointer to a packet already allocated to fill with the right values. + */ + virtual void initPkt(Packet* p) ; + + /** + * Performs the reception of packets from upper and lower layers. + * + * @param Packet* Pointer to the packet will be received. + */ + virtual void recv(Packet* p); + + /** + * Reset retransmissions + */ + inline void reset_retx() {p=NULL; sendTmr_.force_cancel();} + + + /** + * Creates and transmits a packet. + * + * @see UwCbrModule::sendPkt() + */ + virtual void transmit(); + + /** + * Sets the position of the AUV + * + * @param UWSMWPPosition * p Pointer to the AUV position + */ + virtual void setPosition(UWSMWPPosition* p); + + /** + * Returns the position of the AUV + * + * @return the current AUV position + */ + inline UWSMWPPosition* getPosition() const { return posit; } + + /** + * Returns the size in byte of a hdr_uwAUV_monitoring packet header. + * + * @return The size of a hdr_uwAUV_monitoring packet header. + */ + static inline int getAUVMonHeaderSize() { return sizeof(hdr_uwAUV_monitoring); } + + /** + * Returns the size in byte of a hdr_uwAUV_ctr packet header. + * + * @return The size of a hdr_uwAUV_ctr packet header. + */ + static inline int getAUVCTRHeaderSize() { return sizeof(hdr_uwAUV_ctr); } + + /** + * Returns the size in byte of a hdr_uwAUV_error packet header. + * + * @return The size of a hdr_uwAUV_error packet header. + */ + static inline int getAUVErrorHeaderSize() { return sizeof(hdr_uwAUV_error); } + + +protected: + + enum UWAUV_ACK_POLICY { ACK_PIGGYBACK, ACK_IMMEDIATELY, ACK_PGBK_OR_TO }; + + UWSMWPPosition* posit; /**< AUV position.*/ + int last_sn_confirmed;/**< Sequence number of the last command Packete received.*/ + int sn; + int drop_old_waypoints; /** < Flag set to 1 to drop waypoints with sequence number + lower or equal than last_sn_confirmed.*/ + + + int log_on_file; /**< Flag to enable log file writing.*/ + Packet* p; /** Pointer of the packet that will be received*/ + int period; + std::ofstream out_file_stats; /**< Output stream for the textual file of debug */ + std::ofstream err_log; + std::ofstream t_err_log; + float x_e; /**< x coordinate error*/ + float y_e; /**< x coordinate error*/ + int alarm_mode; /**< If true, an error is present and it is being solved*/ + +private: + + double speed; /** speed of the AUV*/ + double error_p; /** probability that an error could arise*/ + double sigma; /** variance of the error measurement*/ + double accuracy; /** accuracy level to obatain to define the error stauts*/ + + +}; + +#endif // UWAUVError_MODULE_H diff --git a/DESERT_Framework/.addon.list b/DESERT_Framework/.addon.list index bca470ed..16479c7a 100644 --- a/DESERT_Framework/.addon.list +++ b/DESERT_Framework/.addon.list @@ -7,6 +7,7 @@ packer_uwpolling packer_uwudp packer_uwufetch uwrov +uwauv uwtracker uwmulti_stack_controller uwmulti_traffic_control diff --git a/DESERT_Framework/DESERT/Makefile.am b/DESERT_Framework/DESERT/Makefile.am index 6414c9c2..099d5a23 100644 --- a/DESERT_Framework/DESERT/Makefile.am +++ b/DESERT_Framework/DESERT/Makefile.am @@ -87,6 +87,7 @@ SUBDIRS = m4 \ mobility/uwgmposition \ mobility/uwrandomlib \ mobility/uwsmposition \ + mobility/uwsmwpposition \ interference/uwinterference \ interference/uwinterferenceofdm \ propagation/uwoptical_propagation \ diff --git a/DESERT_Framework/DESERT/configure.ac b/DESERT_Framework/DESERT/configure.ac index a5f6e70f..486fe522 100644 --- a/DESERT_Framework/DESERT/configure.ac +++ b/DESERT_Framework/DESERT/configure.ac @@ -108,6 +108,7 @@ DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/mobility/uwdriftposition' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/mobility/uwgmposition' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/mobility/uwrandomlib' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/mobility/uwsmposition' +DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/mobility/uwsmwpposition' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/interference/uwinterference' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/interference/uwinterferenceofdm' DESERT_CPPFLAGS="$DESERT_CPPFLAGS "'-I$(top_srcdir)/propagation/uwoptical_propagation' @@ -193,6 +194,7 @@ AC_CONFIG_FILES([ mobility/uwgmposition/Makefile mobility/uwrandomlib/Makefile mobility/uwsmposition/Makefile + mobility/uwsmwpposition/Makefile interference/uwinterference/Makefile interference/uwinterferenceofdm/Makefile propagation/uwoptical_propagation/Makefile diff --git a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h index 57a63fe6..00dc1deb 100644 --- a/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h +++ b/DESERT_Framework/DESERT/mobility/uwsmposition/uwsmposition.h @@ -134,12 +134,12 @@ class UWSMPosition : public Position virtual void setY(double y); virtual void setZ(double z); -private: +protected: + /** * Method that updates both the position coordinates */ virtual void update(double now); - double trgTime_; /// time in which the TCL command setdest is invoked double lastUpdateTime_; /// time last updated of the coordinates was /// computed @@ -154,6 +154,8 @@ class UWSMPosition : public Position /// TCL command setdest is invoked) double speed_; /// speed of the node + +private: int debug_; }; diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am b/DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am new file mode 100644 index 00000000..93391e40 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/Makefile.am @@ -0,0 +1,59 @@ +# +# Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +AM_CXXFLAGS = -Wall -ggdb3 + +lib_LTLIBRARIES = libuwsmwpposition.la +check_PROGRAMS = + +SUBDIRS = + +TESTS = + +libuwsmwpposition_la_SOURCES = initlib.cpp\ + uwsmwpposition-default.tcl\ + uwsmwpposition.cpp + +libuwsmwpposition_la_CPPFLAGS = @NS_CPPFLAGS@ @NSMIRACLE_CPPFLAGS@ @DESERT_CPPFLAGS@ +libuwsmwpposition_la_LDFLAGS = @NS_LDFLAGS@ @NSMIRACLE_LDFLAGS@ @DESERT_LDFLAGS@ +libuwsmwpposition_la_LIBADD = @NS_LIBADD@ @NSMIRACLE_LIBADD@ @DESERT_LIBADD@ + +nodist_libuwsmwpposition_la_SOURCES = InitTcl.cc + + +BUILT_SOURCES = InitTcl.cc + +CLEANFILES = InitTcl.cc + +TCL_FILES = uwsmwpposition-default.tcl + +InitTcl.cc: Makefile $(TCL_FILES) + cat $(VPATH)/$(TCL_FILES) | @TCL2CPP@ UwSMWPPositionTclCode > InitTcl.cc + +EXTRA_DIST = $(TCL_FILES) diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp new file mode 100644 index 00000000..7c41e808 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/initlib.cpp @@ -0,0 +1,56 @@ +// +// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * @file mobility/uwsmwpposition/initlib.cpp + * @author Alessia Ortile + * @version 1.0.0 + * + * \brief Provides the initialization of uwsmwpposition libraries. + * + * Provides the initialization of uwsmwpposition libraries. + */ + +#include "uwsmwpposition.h" + +#include + +extern EmbeddedTcl UwSMWPPositionTclCode; + +extern "C" int +Uwsmwpposition_Init() +{ + UwSMWPPositionTclCode.load(); + return 0; +} + +extern "C" int +Cygsmposition_Init() +{ + Uwsmwpposition_Init(); +} diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl new file mode 100644 index 00000000..4aa8f51d --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition-default.tcl @@ -0,0 +1,33 @@ +# +# Copyright (c) 2017 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# @file uwsmwpposition-defaults.tcl +# @author Alessia Ortile +# @version 1.0.0 + +Position/UWSMWP set debug_ 0 diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp new file mode 100644 index 00000000..7dd60d89 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.cpp @@ -0,0 +1,430 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +/** +* @file uwsmwpposition.cpp +* @author Alessia Ortile +* @version 1.0.0 +* +* \brief Provides the UWSMWPPosition class implementation. +* +* Provides the UWSMWPPosition class implementation. +*/ + +#include +#include "uwsmwpposition.h" + +/* ====================================================================== + TCL Hooks for the simulator + ====================================================================== */ +static class UWSMWPPositionClass : public TclClass +{ +public: + UWSMWPPositionClass() + : TclClass("Position/UWSMWP") + { + } + TclObject * + create(int, const char *const *) + { + return (new UWSMWPPosition()); + } +} class_uwsmwpposition; + + +UWSMWPPosition::UWSMWPPosition() + : UWSMPosition() + , alarm_mode(false) +{ + bind("debug_", &debug_); +} + +UWSMWPPosition::~UWSMWPPosition() +{ +} + +int +UWSMWPPosition::command(int argc, const char *const *argv) +{ + Tcl &tcl = Tcl::instance(); + if (argc == 6) { + if (strcasecmp(argv[1], "setDest") == 0) { + if (debug_) + cerr << NOW << "UWSMWPPosition::command(setDest, " << argv[2] + << ", " << argv[3] << ", " << argv[4] << ", " << argv[5] + << ")" << endl; + setDest(atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5])); + return TCL_OK; + } else if (strcasecmp(argv[1], "addDest") == 0) { + if (debug_) + cerr << NOW << "UWSMWPPosition::command(addDest, " << argv[2] + << ", " << argv[3] << ", " << argv[4] << ", " << argv[5] + << ")" << endl; + addDest(atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5])); + return TCL_OK; + } + } else if (argc == 5) { + if (strcasecmp(argv[1], "setDest") == 0) { + if (debug_) + cerr << NOW << "UWSMWPPosition::command(setDest, " << argv[2] + << ", " << argv[3] << ", " << argv[4] << ")" << endl; + setDest(atof(argv[2]), atof(argv[3]), atof(argv[4])); + return TCL_OK; + }else if (strcasecmp(argv[1], "addDest") == 0) { + if (debug_) + cerr << NOW << "UWSMWPPosition::command(addDest, " << argv[2] + << ", " << argv[3] << ", " << argv[4] << ")" << endl; + addDest(atof(argv[2]), atof(argv[3]), atof(argv[4])); + return TCL_OK; + } + } else if (argc == 2) { + if (strcasecmp(argv[1], "update") == 0) { + double now = Scheduler::instance().clock(); + update(now); + return TCL_OK; + } + } + return Position::command(argc, argv); +} + +void +UWSMWPPosition::setDest( + double x_dest, double y_dest, double z_dest, double speed_setted) +{ + if (alarm_mode){ + + if (debug_) + cout << "Alarm_mode"<< alarm_mode <<", dest("<< x_dest <<","<< + y_dest <<","<< z_dest <<") not accepted"<< std::endl; + + }else{ + + if (!waypoints.empty()){ + + if (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && + waypoints[0][2] == z_dest){ + + if (debug_) + cout << "New dest next waypoint in the queue (" << + waypoints[0][0] << "," << waypoints[0][1] << "," + << waypoints[0][2] << ")"<< std::endl; + + + }else{ + + waypoints.insert(waypoints.begin(),{x_dest,y_dest,z_dest,speed_setted}); + if (debug_) + cout << "New destination (" << x_dest << "," << y_dest << + "," << z_dest << "), skip the queue"<< std::endl; + + + } + + }else{ + + waypoints.push_back({x_dest,y_dest,z_dest,speed_setted}); + } + + if (debug_) + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), last dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << "), new dest = (" + << x_dest << "," << y_dest << "," << z_dest << ")"<< std::endl; + + + + UWSMPosition::setdest(x_dest,y_dest,z_dest,speed_setted); + + if (debug_) + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << "), speed = " + << speed_setted << std::endl; + + } + +} + + +void +UWSMWPPosition::setDest(double x_dest, double y_dest, double z_dest) +{ + if (alarm_mode){ + if (debug_) + cout << "Alarm_mode " << alarm_mode << ", dest(" << x_dest << + "," << y_dest << "," << z_dest << ") not accepted" << std::endl; + + }else{ + + if (!waypoints.empty()){ + if (waypoints[0][0] == x_dest && waypoints[0][1] == y_dest && + waypoints[0][2] == z_dest){ + + if (debug_) + cout << "New dest next waypoint in the queue (" << waypoints[0][0] + << "," << waypoints[0][1] << "," << waypoints[0][2] << + ")"<< std::endl; + + }else{ + + waypoints.insert(waypoints.begin(),{x_dest,y_dest,z_dest}); + if (debug_) + cout << "New destination (" << x_dest << "," << y_dest << "," + << z_dest << "), skip the queue" << std::endl; + + + } + + }else{ + + waypoints.push_back({x_dest,y_dest,z_dest}); + } + + + UWSMPosition::setdest(x_dest,y_dest,z_dest); + + + if (debug_) + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" << + Xdest_ << "," << Ydest_ << "," << Zdest_ << ")"<< std::endl; + + } +} + +void +UWSMWPPosition::addDest( + double x_dest, double y_dest, double z_dest, double speed_setted) +{ + if (!waypoints.empty()){ + + bool exist = false; + + for (const auto& vec : waypoints) { + // Controlla se le coordinate corrispondono + if (vec[0] == x_dest && vec[1] == y_dest && vec[2] == z_dest) { + exist = true; + break; + } + } + + if (!exist){ + waypoints.push_back({x_dest,y_dest,z_dest, speed_setted}); + if (debug_) + cout << "New waypoint (" << x_dest << "," << y_dest << "," + << z_dest << ")\n"; + + } + + + }else{ + UWSMWPPosition::setDest(x_dest,y_dest,z_dest, speed_setted); + if (debug_) + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << ")\n"; + + } +} + +void +UWSMWPPosition::addDest( + double x_dest, double y_dest, double z_dest) +{ + + if (!waypoints.empty()){ + + bool exist = false; + + for (const auto& vec : waypoints) { + if (vec[0] == x_dest && vec[1] == y_dest && vec[2] == z_dest) { + exist = true; + break; + } + } + + if (!exist){ + waypoints.push_back({x_dest,y_dest,z_dest}); + if (debug_) + cout << "New waypoint (" << x_dest << "," << y_dest << "," + << z_dest << ")\n"; + + } + + + }else{ + + UWSMWPPosition::setDest(x_dest,y_dest,z_dest); + + if (debug_) + cout << "Pos (" << x_ << "," << y_ << "," << z_ << "), new dest(" + << Xdest_ << "," << Ydest_ << "," << Zdest_ << ")\n"; + + } + +} + +void +UWSMWPPosition::update(double now) +{ + if ((trgTime_ < 0.) || (now < lastUpdateTime_ + 1e-6)) + return; + + double gamma; + double theta; + double theta_den = sqrt(pow(Ydest_ - Ysorg_, 2.0) + + pow(Xdest_ - Xsorg_, 2.0) + pow(Zdest_ - Zsorg_, 2.0)); + + if (theta_den == 0) { + + x_ = Xsorg_; + y_ = Ysorg_; + z_ = Zsorg_; + + + if (!waypoints.empty()){ + + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ + && waypoints[0][2] == Zdest_){ + + if (debug_) + cout << "Last waypoints erased (" << waypoints[0][0] << "," + << waypoints[0][1] << "," << waypoints[0][2] << ")\n"; + + + waypoints.erase(waypoints.begin()); + + if (!waypoints.empty()){ + + if(waypoints[0].size()>3){ + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2],waypoints[0][3]); + }else{ + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2]); + } + + if (debug_) + cout << "New dest (" << Xdest_ << "," << Ydest_ << "," + << Zdest_ << ") from waypoints list\n"; + + } + } + + } + + + + } else { + + theta = acos((Zdest_ - Zsorg_) / theta_den); + + if (Xdest_ - Xsorg_ == 0.0) + gamma = pi / 2 * sgn(Ydest_ - Ysorg_); + + else + gamma = atan((Ydest_ - Ysorg_) / (Xdest_ - Xsorg_)); + + if ((Xdest_ - Xsorg_) < 0.0) + gamma += (Ysorg_ - Ydest_) >= 0.0 ? pi : -pi; + + + x_ = Xsorg_ + (speed_ * (now - trgTime_)) * sin(theta) * cos(gamma); + y_ = Ysorg_ + (speed_ * (now - trgTime_)) * sin(theta) * sin(gamma); + z_ = Zsorg_ + (speed_ * (now - trgTime_)) * cos(theta); + + double dist_dest_sorg = pow(Ydest_ - Ysorg_, 2.0) + pow(Xdest_ - Xsorg_, 2.0) + + pow(Zdest_ - Zsorg_, 2.0); + + double dist_pos_sorg = pow(x_ - Xsorg_, 2.0) + pow(y_ - Ysorg_, 2.0) + + pow(z_ - Zsorg_, 2.0); + + if ( dist_dest_sorg < dist_pos_sorg ){ + + x_ = Xdest_; + y_ = Ydest_; + z_ = Zdest_; + + + if (debug_) + cout << "Destination (" << Xdest_ << "," << Ydest_ << "," << + Zdest_ << ") reached\n"; + + + if (!waypoints.empty()){ + + if(waypoints[0][0] == Xdest_ && waypoints[0][1] == Ydest_ && + waypoints[0][2] == Zdest_){ + + if (debug_) + cout << "Last waypoints erased (" << waypoints[0][0] << + "," << waypoints[0][1] << "," << waypoints[0][2] << + ")\n"; + + waypoints.erase(waypoints.begin()); + + + if (!waypoints.empty()){ + + if (debug_) + cout << "Next dest (" << waypoints[0][0] << "," + << waypoints[0][1] << "," << waypoints[0][2] + << ")\n"; + + + if(waypoints[0].size()>3){ + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2],waypoints[0][3]); + }else{ + UWSMWPPosition::setDest(waypoints[0][0],waypoints[0][1], + waypoints[0][2]); + } + + if (debug_) + cout << "New dest (" << Xdest_ << "," << Ydest_ << "," << + Zdest_ << ") from waypoints list\n"; + + } + } + + } + + } + if (debug_) + cout << "New pos (" << x_ << "," << y_ << "," << z_ << "), dest(" << Xdest_ << + "," << Ydest_ << "," << Zdest_ << "), source(" << Xsorg_ << "," << Ysorg_ << + "," << Zsorg_ << "), speed " << speed_ << " sen(" << gamma << ")=" << + sin(gamma) << "\n"; + + } + + lastUpdateTime_ = now; +} + +void +UWSMWPPosition::setAlarm(bool alarm) +{ + alarm_mode = alarm; +} diff --git a/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h new file mode 100644 index 00000000..ead3e8e9 --- /dev/null +++ b/DESERT_Framework/DESERT/mobility/uwsmwpposition/uwsmwpposition.h @@ -0,0 +1,188 @@ +// +// Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. Neither the name of the University of Padova (SIGNET lab) nor the +// names of its contributors may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// + +/** + * @file uwsmwpposition.h + * @author Alessia Ortile + * @version 1.0.0 + * + * \brief Provides the definition of the class UWSMWPPosition. + * + * Provides the definition of the class UWSMWPPosition. + * This class implements the a simple movement behaviour: it is possible to + * define the direction and the speed of the linear movement thanks to a TCL + * command in which the user has to define the destination point an the + * speed of the movement required. Additionally, this class supports the + * addition of a list of waypoints to reach sequentially. + * NOTE: the destination point is used to define the direction od the node and + * when it is reached the node will proceed for the same direction + * + * @see NodeCore, Position + **/ + +#ifndef _UWSMEPOSITION_ +#define _UWSMEPOSITION_ + +#include +#include +#include + +#define sgn(x) (((x) == 0.0) ? 0.0 : ((x) / fabs(x))) +#define pi (4 * atan(1.0)) + +class UWSMWPPosition; + +class UWSMWPPosition : public UWSMPosition +{ +public: + /** + * Constructor + */ + UWSMWPPosition(); + /** + * Destructor + */ + virtual ~UWSMWPPosition(); + /** + + + /** + * TCL command interpreter + *
  • setDest <integer value>integer + *value>integer value>: + * set the movement pattern: the firts two values define the point to be + *reached (i.e., the + * direction of the movement) and the third value defines the speed to be + *used + * + *
  • addDest <integer value>integer + *value>integer value>: + * add a following checkpoint to the movement pattern: the firts two values define the point to be + *reached (i.e., the + * direction of the movement) and the third value defines the speed to be + *used + * +
  • setDest <integer value>integer + *value>integer value>integer value>: + * set the movement pattern: the firts three values define the point to be + *reached (i.e., the + * direction of the movement) and the fourth value defines the speed to be + *used + * +
  • addDest <integer value>integer + *value>integer value>integer value>: + * add a following checkpoint to the movement pattern: the firts three values define the point to be + *reached (i.e., the + * direction of the movement) and the fourth value defines the speed to be + *used + * + * Moreover it inherits all the OTcl method of Position + * + * + * @param argc number of arguments in argv + * @param argv array of strings which are the comand parameters (Note that + *argv[0] is the name of the object) + * + * @return TCL_OK or TCL_ERROR whether the command has been dispatched + *succesfully or no + * + **/ + virtual int command(int argc, const char *const *argv); + + + /** + * Updates the next destination to reach. + * + * @param x_dest The x-coordinate of the destination. + * @param y_dest The y-coordinate of the destination. + * @param z_dest The z-coordinate of the destination. + * @param speed The speed of the vehicle. + */ + virtual void setDest( + double x_dest, double y_dest, double z_dest, double speed); + + /** + * Adds a new waypoint to the queue of destinations. + * + * @param x_dest The x-coordinate of the waypoint. + * @param y_dest The y-coordinate of the waypoint. + * @param z_dest The z-coordinate of the waypoint. + * @param speed The speed of the vehicle. + */ + + virtual void addDest( + double x_dest, double y_dest, double z_dest, double speed); + + /** + * Updates the next destination to reach. + * + * @param x_dest The x-coordinate of the destination. + * @param y_dest The y-coordinate of the destination. + * @param z_dest The z-coordinate of the destination. + */ + + virtual void setDest(double x_dest, double y_dest, double z_dest); + + /** + * Adds a new waypoint to the queue of destinations. + * + * @param x_dest The x-coordinate of the waypoint. + * @param y_dest The y-coordinate of the waypoint. + * @param z_dest The z-coordinate of the waypoint. + * @param speed The speed of the vehicle. + */ + + virtual void addDest(double x_dest, double y_dest, double z_dest); + + /** + * Updates the state of the vehicle. If the alarm mode is set to true, + * new destinations cannot be set until it is turned off. + * + * @param alarmStatus status of the alarm mode. + */ + + virtual void setAlarm(bool alarmStatus); + + +protected: + /** + * Method that updates both the position coordinates + * @param now time + */ + virtual void update(double now); + +private: + + std::vector> waypoints; /**< queue of successive destination to reach*/ + bool alarm_mode; /**< statuse of the alarm mode, if true block all the application from updating the destination*/ + int debug_; +}; + + +#endif diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl new file mode 100644 index 00000000..9900a6a1 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv.tcl @@ -0,0 +1,172 @@ +set scr [info script] +proc createASV { id } { + + global ns asv_app asv_err position_asv node_asv udp_asv + global portnum_asv portnum2_asv ipr_asv ipif_asv + global channel channel_op propagation propagation_op data_mask data_mask_op + global phy_asv posdb_asv opt rvposx mll_asv mll_op_asv mac_asv + global mac_op_asv db_manager node_asv_coordinates + + set node_asv [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + + # TRAFFICO 2: CONTROL: ASV --> AUV + Module/UW/AUV/CTR set packetSize_ $opt(pktsize_monitoring) + Module/UW/AUV/CTR set period_ $opt(period) + Module/UW/AUV/CTR set PoissonTraffic_ 0 + Module/UW/AUV/CTR set traffic_type_ 2 + Module/UW/AUV/CTR set debug_ 0 + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set asv_app($id1) [new Module/UW/AUV/CTR] + } + + # TRAFFICO 3: ERROR: ASV --> AUV + Module/UW/AUV/CER set packetSize_ $opt(pktsize_monitoring) + Module/UW/AUV/CER set period_ $opt(period) + Module/UW/AUV/CER set PoissonTraffic_ 0 + Module/UW/AUV/CER set traffic_type_ 3 + Module/UW/AUV/CER set debug_ 0 + Module/UW/AUV/CER set log_on_file_ 1 + Module/UW/AUV/CER set sigma_ $opt(variance) + Module/UW/AUV/CER set th_ne_ [expr 1 - $opt(e_prob)] + Module/UW/AUV/CER set accuracy_ne_ $opt(accuracy) + Module/UW/AUV/CER set debug_ 0 + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set asv_err($id1) [new Module/UW/AUV/CER] + } + + set udp_asv [new Module/UW/UDP] + set ipr_asv [new Module/UW/StaticRouting] + set ipif_asv [new Module/UW/IP] + + Module/UW/MULTI_TRAFFIC_RANGE_CTR set check_to_period_ 5 + Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 + + set ctr_asv [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + set mll_asv [new Module/UW/MLL] + set mac_asv [new Module/UW/CSMA_ALOHA] + Module/UW/PHYSICAL set BitRate_ $opt(bitrate) + Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) + set phy_asv [new Module/UW/PHYSICAL] + $mll_asv setstackid 1 + + set mll_op_asv [new Module/UW/MLL] + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + set mac_op_asv [new Module/UW/CSMA_ALOHA] + Module/UW/OPTICAL/PHY set debug_ 0 + set phy_op_asv [new Module/UW/OPTICAL/PHY] + $mll_op_asv setstackid 2 + + #$node_asv addModule 8 $cbr_asv 0 "CBR1" + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_asv addModule 8 $cbr_asv($id1) 0 "CBR1" + $node_asv addModule 8 $asv_app($id1) 0 "CBR1" + $node_asv addModule 8 $asv_err($id1) 0 "CBR2" + } + #$node_asv addModule 8 $cbr3_asv 0 "CBR3" + $node_asv addModule 7 $udp_asv 0 "UDP1" + $node_asv addModule 6 $ipr_asv 0 "IPR1" + $node_asv addModule 5 $ipif_asv 2 "IPF1" + + $node_asv addModule 4 $ctr_asv 2 "CTR" + + $node_asv addModule 3 $mll_asv 2 "MLL_LF" + $node_asv addModule 2 $mac_asv 2 "MAC_LF" + $node_asv addModule 1 $phy_asv 0 "PHY_LF" + + $node_asv addModule 3 $mll_op_asv 2 "MLL_OP" + $node_asv addModule 2 $mac_op_asv 2 "MAC_OP" + $node_asv addModule 1 $phy_op_asv 0 "PHY_OP" + + #$node_asv setConnection $cbr_asv $udp_asv 0 + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_asv setConnection $cbr_asv($id1) $udp_asv 0 + $node_asv setConnection $asv_app($id1) $udp_asv 0 + $node_asv setConnection $asv_err($id1) $udp_asv 0 + } + #$node_asv setConnection $cbr3_asv $udp_asv 0 + $node_asv setConnection $udp_asv $ipr_asv 0 + $node_asv setConnection $ipr_asv $ipif_asv 2 + $node_asv setConnection $ipif_asv $ctr_asv 2 + + $node_asv setConnection $ctr_asv $mll_asv 2 + $node_asv setConnection $mll_asv $mac_asv 2 + $node_asv setConnection $mac_asv $phy_asv 2 + $node_asv addToChannel $channel $phy_asv 0 + + $node_asv setConnection $ctr_asv $mll_op_asv 2 + $node_asv setConnection $mll_op_asv $mac_op_asv 2 + $node_asv setConnection $mac_op_asv $phy_op_asv 2 + $node_asv addToChannel $channel_op $phy_op_asv 0 + + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #set portnum_asv($id1) [$udp_asv assignPort $cbr_asv($id1) ] + set portnum_asv($id1) [$udp_asv assignPort $asv_app($id1) ] + set portnum2_asv($id1) [$udp_asv assignPort $asv_err($id1) ] + } + #set portnum3_asv [$udp_asv assignPort $cbr3_asv ] + + if {$id > 254} { + puts "hostnum > 254!!! exiting" + exit + } + set tmp_ [expr $id + 1] + $ipif_asv addr $tmp_ + + set position_asv [new "Position/BM"] + $node_asv addPosition $position_asv + set posdb_asv [new "PlugIn/PositionDB"] + $node_asv addPlugin $posdb_asv 20 "PDB" + $posdb_asv addpos [$ipif_asv addr] $position_asv + + set interf_data [new "Module/UW/INTERFERENCE"] + $interf_data set maxinterval_ $opt(maxinterval_) + $interf_data set debug_ 0 + + set interf_data_op [new "MInterference/MIV"] + $interf_data_op set maxinterval_ $opt(maxinterval_) + $interf_data_op set debug_ 0 + + $phy_asv setPropagation $propagation + $phy_asv setSpectralMask $data_mask + $phy_asv setInterference $interf_data + + $phy_op_asv setPropagation $propagation_op + $phy_op_asv setSpectralMask $data_mask_op + $phy_op_asv setInterference $interf_data_op + # $phy_op_leader useLUT + + $mac_asv $opt(ack_mode) + $mac_asv setMacAddr $tmp_ + $mac_asv initialize + + + $mac_op_asv setMacAddr $tmp_ + $mac_op_asv $opt(ack_mode) + $mac_op_asv initialize + +# MONITORING TRAFFIC + $ctr_asv addRobustLowLayer 1 "MLL_LF" + $ctr_asv addFastLowLayer 1 "MLL_OP" + $ctr_asv addUpLayer 1 "IPF1" + $ctr_asv setBufferFeatures 1 1000 0 + +# CONTROL TRAFFIC + $ctr_asv addRobustLowLayer 2 "MLL_LF" + $ctr_asv addFastLowLayer 2 "MLL_OP" + $ctr_asv addUpLayer 2 "IPF1" + $ctr_asv setBufferFeatures 2 1000 0 + +# #ERROR TRAFFIC + $ctr_asv addRobustLowLayer 3 "MLL_LF" + $ctr_asv addFastLowLayer 3 "MLL_OP" + $ctr_asv addUpLayer 3 "IPF1" + $ctr_asv setBufferFeatures 3 1000 0 + +} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl new file mode 100644 index 00000000..06495440 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/asv_basic.tcl @@ -0,0 +1,167 @@ +set scr [info script] +proc createASV { id } { + + global ns asv_app asv_err position_asv node_asv udp_asv + global portnum_asv portnum2_asv ipr_asv ipif_asv + global channel channel_op propagation propagation_op data_mask data_mask_op + global phy_asv posdb_asv opt rvposx mll_asv mll_op_asv mac_asv + global mac_op_asv db_manager node_asv_coordinates + + set node_asv [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + + # TRAFFICO 2: CONTROL: ASV --> AUV + Module/UW/AUV/CTR set packetSize_ $opt(pktsize) + Module/UW/AUV/CTR set period_ 60 + Module/UW/AUV/CTR set PoissonTraffic_ 0 + Module/UW/AUV/CTR set traffic_type_ 2 + Module/UW/AUV/CTR set debug_ 0 + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set asv_app($id1) [new Module/UW/AUV/CTR] + } + + # TRAFFICO 3: ERROR: AUV --> ASV + Module/UW/AUV/CES set packetSize_ $opt(pktsize) + Module/UW/AUV/CES set period_ 60 + Module/UW/AUV/CES set PoissonTraffic_ 0 + Module/UW/AUV/CES set traffic_type_ 3 + Module/UW/AUV/CES set debug_ 0 + Module/UW/AUV/CES set log_on_file_ 1 + Module/UW/AUV/CES set errrop_ $opt(e_prob) + Module/UW/AUV/CES set sigma_ $opt(variance) + Module/UW/AUV/CES set accuracy_ $opt(accuracy) + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + set asv_err($id1) [new Module/UW/AUV/CES] + } + + set udp_asv [new Module/UW/UDP] + set ipr_asv [new Module/UW/StaticRouting] + set ipif_asv [new Module/UW/IP] + + Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 + set ctr_asv [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + set mll_asv [new Module/UW/MLL] + set mac_asv [new Module/UW/CSMA_ALOHA] + Module/UW/PHYSICAL set BitRate_ $opt(bitrate) + Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) + set phy_asv [new Module/UW/PHYSICAL] + $mll_asv setstackid 1 + + set mll_op_asv [new Module/UW/MLL] + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + set mac_op_asv [new Module/UW/CSMA_ALOHA] + set phy_op_asv [new Module/UW/OPTICAL/PHY] + + #$node_asv addModule 8 $cbr_asv 0 "CBR1" + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_asv addModule 8 $cbr_asv($id1) 0 "CBR1" + $node_asv addModule 8 $asv_app($id1) 0 "CBR1" + $node_asv addModule 8 $asv_err($id1) 0 "CBR2" + } + #$node_asv addModule 8 $cbr3_asv 0 "CBR3" + $node_asv addModule 7 $udp_asv 0 "UDP1" + $node_asv addModule 6 $ipr_asv 0 "IPR1" + $node_asv addModule 5 $ipif_asv 2 "IPF1" + + $node_asv addModule 4 $ctr_asv 2 "CTR" + + $node_asv addModule 3 $mll_asv 2 "MLL_LF" + $node_asv addModule 2 $mac_asv 2 "MAC_LF" + $node_asv addModule 1 $phy_asv 0 "PHY_LF" + + $node_asv addModule 3 $mll_op_asv 2 "MLL_OP" + $node_asv addModule 2 $mac_op_asv 2 "MAC_OP" + $node_asv addModule 1 $phy_op_asv 0 "PHY_OP" + + #$node_asv setConnection $cbr_asv $udp_asv 0 + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #$node_asv setConnection $cbr_asv($id1) $udp_asv 0 + $node_asv setConnection $asv_app($id1) $udp_asv 0 + $node_asv setConnection $asv_err($id1) $udp_asv 0 + } + #$node_asv setConnection $cbr3_asv $udp_asv 0 + $node_asv setConnection $udp_asv $ipr_asv 0 + $node_asv setConnection $ipr_asv $ipif_asv 2 + $node_asv setConnection $ipif_asv $ctr_asv 2 + + $node_asv setConnection $ctr_asv $mll_asv 2 + $node_asv setConnection $mll_asv $mac_asv 2 + $node_asv setConnection $mac_asv $phy_asv 2 + $node_asv addToChannel $channel $phy_asv 0 + + $node_asv setConnection $ctr_asv $mll_op_asv 2 + $node_asv setConnection $mll_op_asv $mac_op_asv 2 + $node_asv setConnection $mac_op_asv $phy_op_asv 2 + $node_asv addToChannel $channel_op $phy_op_asv 0 + + + + for {set id1 0} {$id1 <= $opt(n_auv)} {incr id1} { + #set portnum_asv($id1) [$udp_asv assignPort $cbr_asv($id1) ] + set portnum_asv($id1) [$udp_asv assignPort $asv_app($id1) ] + set portnum2_asv($id1) [$udp_asv assignPort $asv_err($id1) ] + } + #set portnum3_asv [$udp_asv assignPort $cbr3_asv ] + + if {$id > 254} { + puts "hostnum > 254!!! exiting" + exit + } + set tmp_ [expr $id + 1] + $ipif_asv addr $tmp_ + + set position_asv [new "Position/BM"] + $node_asv addPosition $position_asv + set posdb_asv [new "PlugIn/PositionDB"] + $node_asv addPlugin $posdb_asv 20 "PDB" + $posdb_asv addpos [$ipif_asv addr] $position_asv + + set interf_data [new "Module/UW/INTERFERENCE"] + $interf_data set maxinterval_ $opt(maxinterval_) + $interf_data set debug_ 0 + + set interf_data_op [new "MInterference/MIV"] + $interf_data_op set maxinterval_ $opt(maxinterval_) + $interf_data_op set debug_ 0 + + $phy_asv setPropagation $propagation + $phy_asv setSpectralMask $data_mask + $phy_asv setInterference $interf_data + + $phy_op_asv setPropagation $propagation_op + $phy_op_asv setSpectralMask $data_mask_op + $phy_op_asv setInterference $interf_data_op + # $phy_op_leader useLUT + + $mac_asv $opt(ack_mode) + $mac_asv setMacAddr $tmp_ + $mac_asv initialize + + + $mac_op_asv setMacAddr $tmp_ + $mac_op_asv $opt(ack_mode) + $mac_op_asv initialize + +# MONITORING TRAFFIC + $ctr_asv addRobustLowLayer 1 "MLL_LF" + $ctr_asv addFastLowLayer 1 "MLL_OP" + $ctr_asv addUpLayer 1 "IPF1" + $ctr_asv setBufferFeatures 1 1000 0 + +# CONTROL TRAFFIC + $ctr_asv addRobustLowLayer 2 "MLL_LF" + $ctr_asv addFastLowLayer 2 "MLL_OP" + $ctr_asv addUpLayer 2 "IPF1" + $ctr_asv setBufferFeatures 2 1000 0 + +# #ERROR TRAFFIC + $ctr_asv addRobustLowLayer 3 "MLL_LF" + $ctr_asv addFastLowLayer 3 "MLL_OP" + $ctr_asv addUpLayer 3 "IPF1" + $ctr_asv setBufferFeatures 3 1000 0 + +} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl new file mode 100644 index 00000000..b08d5eb0 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv.tcl @@ -0,0 +1,161 @@ +set scr [info script] +proc createAUV { id } { + + global ns auv_app auv_err position_auv node_auv udp portnum_auv portnum2_auv ipr_auv ipif_auv + global channel channel_op propagation propagation_op data_mask data_mask_op phy_auv posdb_auv opt rvposx mll_auv mll_op_auv mac_auv mac_op_auv + global db_manager node_auv_coordinates + + # TRAFFICO 1: MONITORING AUV --> ASV + set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + Module/UW/AUV set packetSize_ $opt(pktsize_monitoring) + Module/UW/AUV set period_ $opt(period) + Module/UW/AUV set PoissonTraffic_ 0 + Module/UW/AUV set traffic_type_ 1 + Module/UW/AUV set debug_ 0 + set auv_app($id) [new Module/UW/AUV] + + # TRAFFICO 3: ERROR AUV --> ASV + set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + Module/UW/AUV/ERR set packetSize_ $opt(pktsize) + Module/UW/AUV/ERR set period_ $opt(period) + Module/UW/AUV/ERR set PoissonTraffic_ 0 + Module/UW/AUV/ERR set traffic_type_ 3 + Module/UW/AUV/ERR set debug_ 0 + Module/UW/AUV/ERR set log_on_file_ 1 + Module/UW/AUV/ERR set sigma_ $opt(variance) + Module/UW/AUV/ERR set th_ne_ [expr 1 - $opt(e_prob)] + Module/UW/AUV/ERR set accuracy_ne_ $opt(accuracy) + + set auv_err($id) [new Module/UW/AUV/ERR] + + + set udp_auv($id) [new Module/UW/UDP] + set ipr_auv($id) [new Module/UW/StaticRouting] + set ipif_auv($id) [new Module/UW/IP] + + Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 + Module/UW/MULTI_TRAFFIC_RANGE_CTR set check_to_period_ 5 + + set ctr_auv($id) [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set debug_ 0 + + set mll_auv($id) [new Module/UW/MLL] + set mac_auv($id) [new Module/UW/CSMA_ALOHA] + Module/UW/PHYSICAL set BitRate_ $opt(bitrate) + Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) + set phy_auv($id) [new Module/UW/PHYSICAL] + $mll_auv($id) setstackid 1 + + set mll_op_auv($id) [new Module/UW/MLL] + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set debug_ 0 + Module/UW/OPTICAL/PHY set debug_ 0 + $mll_op_auv($id) setstackid 2 + set mac_op_auv($id) [new Module/UW/CSMA_ALOHA] + set phy_op_auv($id) [new Module/UW/OPTICAL/PHY] + + $node_auv($id) addModule 8 $auv_app($id) 0 "CBR1" + $node_auv($id) addModule 8 $auv_err($id) 0 "CBR2" + #$node_auv($id) addModule 8 $cbr3_auv($id) 0 "CBR3" + $node_auv($id) addModule 7 $udp_auv($id) 0 "UDP1" + $node_auv($id) addModule 6 $ipr_auv($id) 0 "IPR1" + $node_auv($id) addModule 5 $ipif_auv($id) 2 "IPF1" + + #$node_diver($id) addModule 7 $udp2_diver($id) 0 "UDP2" + #$node_diver($id) addModule 6 $ipr2_diver($id) 0 "IPR2" + #$node_diver($id) addModule 5 $ipif2_diver($id) 2 "IPF2" + + $node_auv($id) addModule 4 $ctr_auv($id) 2 "CTR" + + $node_auv($id) addModule 3 $mll_auv($id) 2 "MLL_LF" + $node_auv($id) addModule 2 $mac_auv($id) 2 "MAC_LF" + $node_auv($id) addModule 1 $phy_auv($id) 0 "PHY_LF" + + $node_auv($id) addModule 3 $mll_op_auv($id) 2 "MLL_OP" + $node_auv($id) addModule 2 $mac_op_auv($id) 2 "MAC_OP" + $node_auv($id) addModule 1 $phy_op_auv($id) 0 "PHY_OP" + + $node_auv($id) setConnection $auv_app($id) $udp_auv($id) 0 + $node_auv($id) setConnection $auv_err($id) $udp_auv($id) 0 + #$node_auv($id) setConnection $cbr3_auv($id) $udp_auv($id) 0 + $node_auv($id) setConnection $udp_auv($id) $ipr_auv($id) 0 + $node_auv($id) setConnection $ipr_auv($id) $ipif_auv($id) 2 + $node_auv($id) setConnection $ipif_auv($id) $ctr_auv($id) 2 + + $node_auv($id) setConnection $ctr_auv($id) $mll_auv($id) 2 + $node_auv($id) setConnection $mll_auv($id) $mac_auv($id) 2 + $node_auv($id) setConnection $mac_auv($id) $phy_auv($id) 2 + $node_auv($id) addToChannel $channel $phy_auv($id) 0 + + $node_auv($id) setConnection $ctr_auv($id) $mll_op_auv($id) 2 + $node_auv($id) setConnection $mll_op_auv($id) $mac_op_auv($id) 2 + $node_auv($id) setConnection $mac_op_auv($id) $phy_op_auv($id) 2 + $node_auv($id) addToChannel $channel_op $phy_op_auv($id) 0 + + set portnum_auv($id) [$udp_auv($id) assignPort $auv_app($id) ] + set portnum2_auv($id) [$udp_auv($id) assignPort $auv_err($id) ] + #set portnum3_auv($id) [$udp_auv($id) assignPort $cbr3_auv($id) ] + if {$id > 254} { + puts "hostnum > 254!!! exiting" + exit + } + set tmp_ [expr ($id) + 1] + $ipif_auv($id) addr $tmp_ + + set position_auv($id) [new "Position/BM"] ; #Position/BM (?) + $node_auv($id) addPosition $position_auv($id) + set posdb_auv($id) [new "PlugIn/PositionDB"] + $node_auv($id) addPlugin $posdb_auv($id) 20 "PDB" + $posdb_auv($id) addpos [$ipif_auv($id) addr] $position_auv($id) + + set interf_data($id) [new "Module/UW/INTERFERENCE"] + $interf_data($id) set maxinterval_ $opt(maxinterval_) + $interf_data($id) set debug_ 0 + + + set interf_data_op($id) [new "MInterference/MIV"] + $interf_data_op($id) set maxinterval_ $opt(maxinterval_) + $interf_data_op($id) set debug_ 0 + + $phy_auv($id) setPropagation $propagation + $phy_auv($id) setSpectralMask $data_mask + $phy_auv($id) setInterference $interf_data($id) + + $phy_op_auv($id) setPropagation $propagation_op + $phy_op_auv($id) setSpectralMask $data_mask_op + $phy_op_auv($id) setInterference $interf_data_op($id) + #$phy_hf_diver($id) setInterference $interf_data_hf($id) + + $mac_auv($id) setMacAddr $tmp_ + #$mac_auv($id) setSlotNumber [expr $id + 1] + $mac_auv($id) $opt(ack_mode) + $mac_auv($id) initialize + + $mac_op_auv($id) setMacAddr $tmp_ + $mac_op_auv($id) $opt(ack_mode) + $mac_op_auv($id) initialize + + #MONITORING + $ctr_auv($id) addRobustLowLayer 1 "MLL_LF" + $ctr_auv($id) addFastLowLayer 1 "MLL_OP" + $ctr_auv($id) addUpLayer 1 "IPF1" + $ctr_auv($id) setBufferFeatures 1 1000 0 + + #CONTROL + $ctr_auv($id) addRobustLowLayer 2 "MLL_LF" + $ctr_auv($id) addFastLowLayer 2 "MLL_OP" + $ctr_auv($id) addUpLayer 2 "IPF1" + $ctr_auv($id) setBufferFeatures 2 1000 0 + + #ERROR + $ctr_auv($id) addRobustLowLayer 3 "MLL_LF" + $ctr_auv($id) addFastLowLayer 3 "MLL_OP" + $ctr_auv($id) addUpLayer 3 "IPF1" + $ctr_auv($id) setBufferFeatures 3 1000 0 + +} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl new file mode 100644 index 00000000..16f83764 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/auv_basic.tcl @@ -0,0 +1,158 @@ +set scr [info script] +proc createAUV { id } { + + global ns auv_app auv_err position_auv node_auv udp portnum_auv portnum2_auv ipr_auv ipif_auv + global channel channel_op propagation propagation_op data_mask data_mask_op phy_auv posdb_auv opt rvposx mll_auv mll_op_auv mac_auv mac_op_auv + global db_manager node_auv_coordinates + + # TRAFFICO 1: MONITORING AUV --> ASV + set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + Module/UW/AUV set packetSize_ $opt(pktsize) + Module/UW/AUV set period_ $opt(period) + Module/UW/AUV set PoissonTraffic_ 0 + Module/UW/AUV set traffic_type_ 1 + Module/UW/AUV set debug_ 0 + set auv_app($id) [new Module/UW/AUV] + + # TRAFFICO 3: ERROR AUV --> ASV + set node_auv($id) [$ns create-M_Node $opt(tracefile) $opt(cltracefile)] + Module/UW/AUV/ERS set packetSize_ $opt(pktsize) + Module/UW/AUV/ERS set period_ $opt(period) + Module/UW/AUV/ERS set PoissonTraffic_ 0 + Module/UW/AUV/ERS set traffic_type_ 3 + Module/UW/AUV/ERS set debug_ 0 + Module/UW/AUV/ERS set log_on_file_ 1 + Module/UW/AUV/ERS set errrop_ $opt(e_prob) + Module/UW/AUV/ERS set sigma_ $opt(variance) + Module/UW/AUV/ERS set accuracy_ $opt(accuracy) + + set auv_err($id) [new Module/UW/AUV/ERS] + + + set udp_auv($id) [new Module/UW/UDP] + set ipr_auv($id) [new Module/UW/StaticRouting] + set ipif_auv($id) [new Module/UW/IP] + + Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 + set ctr_auv($id) [new Module/UW/MULTI_TRAFFIC_RANGE_CTR] + + + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set debug_ 0 + + set mll_auv($id) [new Module/UW/MLL] + set mac_auv($id) [new Module/UW/CSMA_ALOHA] + Module/UW/PHYSICAL set BitRate_ $opt(bitrate) + Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) + set phy_auv($id) [new Module/UW/PHYSICAL] + $mll_auv($id) setstackid 1 + + set mll_op_auv($id) [new Module/UW/MLL] + Module/UW/CSMA_ALOHA set listen_time_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set wait_costant_ [expr 1.0e-12] + Module/UW/CSMA_ALOHA set debug_ 0 + set mac_op_auv($id) [new Module/UW/CSMA_ALOHA] + Module/UW/OPTICAL/PHY set debug_ 0 + set phy_op_auv($id) [new Module/UW/OPTICAL/PHY] + + $node_auv($id) addModule 8 $auv_app($id) 0 "CBR1" + $node_auv($id) addModule 8 $auv_err($id) 0 "CBR2" + #$node_auv($id) addModule 8 $cbr3_auv($id) 0 "CBR3" + $node_auv($id) addModule 7 $udp_auv($id) 0 "UDP1" + $node_auv($id) addModule 6 $ipr_auv($id) 0 "IPR1" + $node_auv($id) addModule 5 $ipif_auv($id) 2 "IPF1" + + #$node_diver($id) addModule 7 $udp2_diver($id) 0 "UDP2" + #$node_diver($id) addModule 6 $ipr2_diver($id) 0 "IPR2" + #$node_diver($id) addModule 5 $ipif2_diver($id) 2 "IPF2" + + $node_auv($id) addModule 4 $ctr_auv($id) 2 "CTR" + + $node_auv($id) addModule 3 $mll_auv($id) 2 "MLL_LF" + $node_auv($id) addModule 2 $mac_auv($id) 2 "MAC_LF" + $node_auv($id) addModule 1 $phy_auv($id) 0 "PHY_LF" + + $node_auv($id) addModule 3 $mll_op_auv($id) 2 "MLL_OP" + $node_auv($id) addModule 2 $mac_op_auv($id) 2 "MAC_OP" + $node_auv($id) addModule 1 $phy_op_auv($id) 0 "PHY_OP" + + $node_auv($id) setConnection $auv_app($id) $udp_auv($id) 0 + $node_auv($id) setConnection $auv_err($id) $udp_auv($id) 0 + #$node_auv($id) setConnection $cbr3_auv($id) $udp_auv($id) 0 + $node_auv($id) setConnection $udp_auv($id) $ipr_auv($id) 0 + $node_auv($id) setConnection $ipr_auv($id) $ipif_auv($id) 2 + $node_auv($id) setConnection $ipif_auv($id) $ctr_auv($id) 2 + + $node_auv($id) setConnection $ctr_auv($id) $mll_auv($id) 2 + $node_auv($id) setConnection $mll_auv($id) $mac_auv($id) 2 + $node_auv($id) setConnection $mac_auv($id) $phy_auv($id) 2 + $node_auv($id) addToChannel $channel $phy_auv($id) 0 + + $node_auv($id) setConnection $ctr_auv($id) $mll_op_auv($id) 2 + $node_auv($id) setConnection $mll_op_auv($id) $mac_op_auv($id) 2 + $node_auv($id) setConnection $mac_op_auv($id) $phy_op_auv($id) 2 + $node_auv($id) addToChannel $channel_op $phy_op_auv($id) 0 + + set portnum_auv($id) [$udp_auv($id) assignPort $auv_app($id) ] + set portnum2_auv($id) [$udp_auv($id) assignPort $auv_err($id) ] + #set portnum3_auv($id) [$udp_auv($id) assignPort $cbr3_auv($id) ] + if {$id > 254} { + puts "hostnum > 254!!! exiting" + exit + } + set tmp_ [expr ($id) + 1] + $ipif_auv($id) addr $tmp_ + + set position_auv($id) [new "Position/BM"] ; #Position/BM (?) + $node_auv($id) addPosition $position_auv($id) + set posdb_auv($id) [new "PlugIn/PositionDB"] + $node_auv($id) addPlugin $posdb_auv($id) 20 "PDB" + $posdb_auv($id) addpos [$ipif_auv($id) addr] $position_auv($id) + + set interf_data($id) [new "Module/UW/INTERFERENCE"] + $interf_data($id) set maxinterval_ $opt(maxinterval_) + $interf_data($id) set debug_ 0 + + + set interf_data_op($id) [new "MInterference/MIV"] + $interf_data_op($id) set maxinterval_ $opt(maxinterval_) + $interf_data_op($id) set debug_ 0 + + $phy_auv($id) setPropagation $propagation + $phy_auv($id) setSpectralMask $data_mask + $phy_auv($id) setInterference $interf_data($id) + + $phy_op_auv($id) setPropagation $propagation_op + $phy_op_auv($id) setSpectralMask $data_mask_op + $phy_op_auv($id) setInterference $interf_data_op($id) + #$phy_hf_diver($id) setInterference $interf_data_hf($id) + + $mac_auv($id) setMacAddr $tmp_ + #$mac_auv($id) setSlotNumber [expr $id + 1] + $mac_auv($id) $opt(ack_mode) + $mac_auv($id) initialize + + $mac_op_auv($id) setMacAddr $tmp_ + $mac_op_auv($id) $opt(ack_mode) + $mac_op_auv($id) initialize + + #MONITORING + $ctr_auv($id) addRobustLowLayer 1 "MLL_LF" + $ctr_auv($id) addFastLowLayer 1 "MLL_OP" + $ctr_auv($id) addUpLayer 1 "IPF1" + $ctr_auv($id) setBufferFeatures 1 1000 0 + + #CONTROL + $ctr_auv($id) addRobustLowLayer 2 "MLL_LF" + $ctr_auv($id) addFastLowLayer 2 "MLL_OP" + $ctr_auv($id) addUpLayer 2 "IPF1" + $ctr_auv($id) setBufferFeatures 2 1000 0 + + #ERROR + $ctr_auv($id) addRobustLowLayer 3 "MLL_LF" + $ctr_auv($id) addFastLowLayer 3 "MLL_OP" + $ctr_auv($id) addUpLayer 3 "IPF1" + $ctr_auv($id) setBufferFeatures 3 1000 0 + +} \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py new file mode 100644 index 00000000..646da749 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp.py @@ -0,0 +1,190 @@ +import csv +import matplotlib.pyplot as plt +import math +import sys +import os + +def calculate_distance(point1, point2): + x1, y1 = point1 + x2, y2 = point2 + return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) + +def calculate_total_distance(positions): + total_distance = 0.0 + for i in range(len(positions) - 1): + distance = calculate_distance(positions[i], positions[i+1]) + total_distance += distance + return total_distance + +def plot_coordinates_log(file_path): + pos = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + pos.append((float(row[1]),float(row[2]))) + return pos + +def plot_auv_coordinates_log(file_path): + pos = [] + auv_1 = [] + auv_2 = [] + auv_3 = [] + auv_4 = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + if (float(row[1]) < 0 and float(row[2]) > 0): #1Q -> auv_1 + auv_1.append((float(row[1]),float(row[2]))) + elif (float(row[1]) > 0 and float(row[2]) > 0): #2Q -> auv_2 + auv_2.append((float(row[1]),float(row[2]))) + elif (float(row[1]) < 0 and float(row[2]) < 0): #3Q -> auv_3 + auv_3.append((float(row[1]),float(row[2]))) + else: #4Q -> auv_4 + auv_4.append((float(row[1]),float(row[2]))) + + return auv_1,auv_2,auv_3,auv_4 + +def tx_log(filename): + with open(filename, 'r') as file: + for line in file: + line = line.split(" ") + + return line + +def separate_rows(filename): + error_g_on = [] + error_g_off = [] + error_r_on = [] + error_r_off = [] + error_w = [] + + with open(filename, 'r') as file: + for line in file: + line = line.strip().split(',') + line[1] = float(line[1]) + line[2] = float(line[2]) + line[3] = float(line[3]) + + if line[0].strip() == 'G': + if line[4].strip() == 'ON': + error_g_on.append(line[1:]) + else: + error_g_off.append(line[1:]) + + elif line[0].strip() =='R': + if line[4].strip() == 'ON': + error_r_on.append(line[1:]) + else: + error_r_off.append(line[1:]) + else: + error_w.append(line[1:]) + + + return error_g_on,error_g_off, error_r_on,error_r_off, error_w + + +# Retrieve command line arguments +arguments = sys.argv[1:] + +log_error = "log/error_log_t.csv" +log_position = "log/position_log.csv" +log_position_a = "log/position_log_a.csv" +log_terror = "log/true_error_log.csv" + +difference = [] +error_g_on = [] +error_g_off = [] +error_r_on = [] +error_r_off = [] +error_w = [] +# Create a dictionary to store the positions from r_on as keys +time_w = {} +time_g = {} + +if os.path.exists(log_error): + error_g_on, error_g_off, error_r_on, error_r_off, error_w = separate_rows(log_error) + + # Iterate over r_on and store the time values for each position + for row in error_w: + time_w[(row[1], row[2])] = row[0] + + #for row in error_g_off: + # time_g[(row[2], row[3])] = row[1] + + # Iterate over r_off and compute the time difference for each position + for row in error_g_on: + position = (row[1], row[2]) + if position in time_w: + difference.append(time_w[position] - row[0]) + else: + difference.append(150000-row[0]) +else: + difference.append(0) + + +tp=0 +tn=0 +e=0 +fp=0 +fn=0 +big_dict={} + +if os.path.exists(log_terror): + with open(log_terror, 'r') as file: + for line in file: + line = line.strip() # Remove leading/trailing whitespaces + values = line.split(',') # Split the line by comma + + # Extract the values + if len(values) == 4: + value1 = float(values[0]) + value2 = float(values[1]) + value3 = float(values[2]) + value4 = values[3] + + if value4 == 'e': + e += 1 + elif (value2,value3) not in big_dict: + big_dict[value2,value3] = value4 + + + # Check if the second and third columns are equal + + for val in big_dict.values(): + if val == 'tp': + tp += 1 + elif val == 'fn': + fn+=1 + elif val == 'fp': + fp+=1 + elif val == 'tn': + tn+=1 + +total_distance = 0 +if os.path.exists(log_position): + pos_sv = plot_coordinates_log(log_position) + # Calculate the total distance traveled + total_distance = calculate_total_distance(pos_sv) + +if os.path.exists(log_position_a): + auv_1,auv_2,auv_3,auv_4 = plot_auv_coordinates_log(log_position_a) + x_1 = [a1[0] for a1 in auv_1] + y_1 = [a1[1] for a1 in auv_1] + x_2 = [a2[0] for a2 in auv_2] + y_2 = [a2[1] for a2 in auv_2] + x_3 = [a3[0] for a3 in auv_3] + y_3 = [a3[1] for a3 in auv_3] + x_4 = [a4[0] for a4 in auv_4] + y_4 = [a4[1] for a4 in auv_4] + + # Calculate the total distance traveled + total_distance_1 = calculate_total_distance(auv_1) + total_distance_2 = calculate_total_distance(auv_2) + total_distance_3 = calculate_total_distance(auv_3) + total_distance_4 = calculate_total_distance(auv_4) + +tx_data = tx_log('log.out') +print (arguments[0],';',arguments[1],';',arguments[2],';',arguments[3],';',sum(difference)/len(difference),';',total_distance,';',tp,';',fn,';',tn,';',fp,';',e,';',total_distance_1,';',total_distance_2,';',total_distance_3,';',total_distance_4,';',tx_data[0],';',tx_data[1],';',tx_data[2],';',tx_data[3],';',tx_data[4],';',tx_data[5],';',tx_data[6],';',tx_data[7],'\n') # time spent in error distance + + + diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py new file mode 100644 index 00000000..d081975d --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/metric_comp_4.py @@ -0,0 +1,188 @@ +import csv +import matplotlib.pyplot as plt +import math +import sys +import os + +def tx_log(filename): + with open(filename, 'r') as file: + for line in file: + line = line.split(" ") + + return line + +def calculate_distance(point1, point2): + x1, y1 = point1 + x2, y2 = point2 + return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) + +def calculate_total_distance(positions): + total_distance = 0.0 + for i in range(len(positions) - 1): + distance = calculate_distance(positions[i], positions[i+1]) + #print(distance) + total_distance += distance + return total_distance + +def plot_auv_coordinates_log(file_path): + pos = [] + auv_1 = [] + auv_2 = [] + auv_3 = [] + auv_4 = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + if (float(row[1]) < 0 and float(row[2]) > 0): #1Q -> auv_1 + auv_1.append((float(row[1]),float(row[2]))) + elif (float(row[1]) > 0 and float(row[2]) > 0): #2Q -> auv_2 + auv_2.append((float(row[1]),float(row[2]))) + elif (float(row[1]) < 0 and float(row[2]) < 0): #3Q -> auv_3 + auv_3.append((float(row[1]),float(row[2]))) + else: #4Q -> auv_3 + auv_4.append((float(row[1]),float(row[2]))) + + return auv_1,auv_2,auv_3,auv_4 + + +def plot_coordinates_log(file_path): + + pos = [] + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + pos.append((float(row[1]),float(row[2]))) + return pos + +def separate_rows(filename): + error_ON = [] + error_OFF = [] + + with open(filename, 'r') as file: + for line in file: + line = line.strip() + if line.startswith('ON'): + line_l = line.split(',') + line_l[1] = float(line_l[1]) + line_l[2] = float(line_l[2]) + line_l[3] = float(line_l[3]) + + error_ON.append(line_l[1:]) + else: + line_l = line.split(',') + line_l[1] = float(line_l[1]) + line_l[2] = float(line_l[2]) + line_l[3] = float(line_l[3]) + + error_OFF.append(line_l[1:]) + + return error_ON,error_OFF + + +# Retrieve command line arguments +arguments = sys.argv[1:] + +log_error = "log/error_log.csv" +log_position = "log/position_log.csv" +log_position_a = "log/position_log_a.csv" +log_terror = "log/true_error_log.csv" + +difference = [] +# Create a dictionary to store the positions from r_on as keys +time_e = {} +time_ne = {} + +if os.path.exists(log_error): + error_on, error_off = separate_rows(log_error) + + # Iterate over r_on and store the time values for each position + for row in error_on: + time_e[(row[1], row[2])] = row[0] + + for row in error_off: + time_ne[(row[1], row[2])] = row[0] + + # Iterate over r_off and compute the time difference for each position + for row in error_on: + position = (row[1], row[2]) + if position in time_ne: + difference.append(time_ne[position] -time_e[position]) + else: + difference.append(150000-time_e[position]) + +else: + difference.append(0) + + +tp=0 +tn=0 +e=0 +fp=0 +fn=0 +big_dict={} + +if os.path.exists(log_terror): + with open(log_terror, 'r') as file: + for line in file: + line = line.strip() # Remove leading/trailing whitespaces + values = line.split(',') # Split the line by comma + + # Extract the values + if len(values) == 4: + value1 = float(values[0]) + value2 = float(values[1]) + value3 = float(values[2]) + value4 = values[3] + + if value4 == 'e': + e += 1 + elif (value2,value3) not in big_dict: + big_dict[value2,value3] = value4 + + for val in big_dict.values(): + if val == 'tp': + tp += 1 + elif val == 'fn': + fn+=1 + elif val == 'fp': + fp+=1 + elif val == 'tn': + tn+=1 + + +total_distance = 0 +if os.path.exists(log_position): + pos_sv = plot_coordinates_log(log_position) + # Calculate the total distance traveled + total_distance = calculate_total_distance(pos_sv) + +if os.path.exists(log_position_a): + auv_1,auv_2,auv_3,auv_4 = plot_auv_coordinates_log(log_position_a) + x_1 = [a1[0] for a1 in auv_1] + y_1 = [a1[1] for a1 in auv_1] + x_2 = [a2[0] for a2 in auv_2] + y_2 = [a2[1] for a2 in auv_2] + x_3 = [a3[0] for a3 in auv_3] + y_3 = [a3[1] for a3 in auv_3] + x_4 = [a4[0] for a4 in auv_4] + y_4 = [a4[1] for a4 in auv_4] + + # Calculate the total distance traveled + total_distance_1 = calculate_total_distance(auv_1) + total_distance_2 = calculate_total_distance(auv_2) + total_distance_3 = calculate_total_distance(auv_3) + total_distance_4 = calculate_total_distance(auv_4) + +tx_data = tx_log('log.out') +print (arguments[0],';',arguments[1],';',arguments[2],';',arguments[3],';',sum(difference)/len(difference),';',total_distance,';',tp,';',fn,';',tn,';',fp,';',e,';',total_distance_1,';',total_distance_2,';',total_distance_3,';',total_distance_4,';',tx_data[0],';',tx_data[1],';',tx_data[2],';',tx_data[3],';',tx_data[4],';',tx_data[5],';',tx_data[6],';',tx_data[7],'\n') # time spent in error distance + +#print (arguments[0],';',arguments[1],';',arguments[2],';',arguments[3],';',0,';',0,';',tp,';',fn,';',tn,';',fp,';',e,'\n') # time spent in error distance + + +#acc_ #error_p #sigma #time #distance + to add false detection + false release + + + + + diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py new file mode 100644 index 00000000..7713d07c --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_coordinates.py @@ -0,0 +1,152 @@ +import csv +import matplotlib.pyplot as plt +import tikzplotlib + + +def plot_coordinates(file_path,x,y,t): + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + x.append(float(row[1]) + float(row[2])) + y.append(float(row[2])) + t.append(float(row[0])) + +def plot_coordinates_log(file_path): + pos = [] + auv_1 = [] + auv_2 = [] + auv_3 = [] + auv_4 = [] + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + if (float(row[1]) < 0 and float(row[2]) > 0): #1Q -> auv_1 + auv_1.append((float(row[1]),float(row[2]))) + elif (float(row[1]) > 0 and float(row[2]) > 0): #2Q -> auv_2 + auv_2.append((float(row[1]),float(row[2]))) + elif (float(row[1]) < 0 and float(row[2]) < 0): #3Q -> auv_3 + auv_3.append((float(row[1]),float(row[2]))) + else: #4Q -> auv_3 + auv_4.append((float(row[1]),float(row[2]))) + auv_1 = set(auv_1) + auv_2 = set(auv_2) + auv_3 = set(auv_3) + auv_4 = set(auv_4) + + return auv_1,auv_2,auv_3,auv_4 + + +def plot_movement_log(file_path,t,axis): + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + t.append(float(row[0])) + axis.append(float(row[1]) + float(row[2])) + + + + + +# Example usage +X_0 = [] +Y_0 = [] +Z_0 = [] +#file_path = 'test_uwauv0_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_0,Y_0,Z_0) + + +X_1 = [] +Y_1 = [] +Z_1 = [] +file_path = 'log/position_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +auv_1,auv_2,auv_3,auv_4 = plot_coordinates_log(file_path) +#file_path = 'test_uwauv1_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_1,Y_1,Z_1) + +X_s = [] +Y_s = [] +#file_path = 'test_uwsuv_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_s,Y_s,Z_s) +file_path = 'log/position_log.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates_log(file_path,X_s,Y_s) + +X_e = [] +Y_e = [] +file_path = 'error_log.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates_log(file_path,X_e,Y_e) + +X_e_c = [] +Y_e_c = [] +file_path = 'error_calling_log.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates_log(file_path,X_e_c,Y_e_c) + +X_0 = [] +Y_0 = [] +Z_0 = [] +file_path = 'test_uwauv0_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_0,Y_0,Z_0) + +X_1a = [] +Y_1a = [] +Z_1a = [] +#file_path = 'postion_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates_log(file_path,X_1a,Y_1a) +file_path = 'test_uwauv1_results.csv' # Replace with your file pathplot_coordinates(file_path) +#plot_coordinates(file_path,X_1a,Y_1a,Z_1a) + +x_1 = [a1[0] for a1 in auv_1] +y_1 = [a1[1] for a1 in auv_1] +x_2 = [a2[0] for a2 in auv_2] +y_2 = [a2[1] for a2 in auv_2] +x_3 = [a3[0] for a3 in auv_3] +y_3 = [a3[1] for a3 in auv_3] +x_4 = [a4[0] for a4 in auv_4] +y_4 = [a4[1] for a4 in auv_4] + + +x_1n=[] +y_1n=[] +x_2n=[] +y_2n=[] +x_3n=[] +y_3n=[] +x_4n=[] +y_4n=[] + +for i in range(0,len(x_1),5): + x_1n.append(x_1[i]) + y_1n.append(y_1[i]) + +for i in range(0,len(x_2),5): + x_2n.append(x_2[i]) + y_2n.append(y_2[i]) + +for i in range(0,len(x_3),5): + x_3n.append(x_3[i]) + y_3n.append(y_3[i]) + +for i in range(0,len(x_4),5): + x_4n.append(x_4[i]) + y_4n.append(y_4[i]) + +print(x_1n) +print(y_1n) +fig = plt.figure() +ax = plt.subplot() +ax.plot(x_1,y_1,'--',label='auv_1') +ax.plot(x_2,y_2,'--',label='auv_2') +ax.plot(x_3,y_3,'--',label='auv_3') +ax.plot(x_4,y_4,'--',label='auv_4') +ax.plot(0,0,marker='p',markersize='15',markerfacecolor='black',color='white',linewidth='2',label='asv') +#ax.plot(X_s, Y_s, 'g--',label='sv') +#ax.plot(X_e_c, Y_e_c, 'b^',label='error_called') +#ax.plot(X_e, Y_e, 'rx',label='error_Solved') +ax.set_xlabel('X') +ax.set_ylabel('Y') +ax.legend() +#ax.set_zlabel('Z') +#plt.show() +tikzplotlib.save('traj.tex') +plt.close() \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py new file mode 100644 index 00000000..3da621a9 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/plot_error_evolution.py @@ -0,0 +1,173 @@ +import csv +import matplotlib.pyplot as plt + +def plot_coordinates_log(file_path): + + x = [] + y = [] + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + x.append(float(row[1])) + y.append(float(row[2])) + return x,y + +def plot_movement_log(file_path): + + t=[] + axis = [] + + with open(file_path, 'r') as file: + reader = csv.reader(file) + for row in reader: + t.append(float(row[0])) + axis.append(float(row[1]) + float(row[2])) + return t,axis + +def separate_rows_s(filename): + error_g = [] + error_r = [] + error_w = [] + + with open(filename, 'r') as file: + for line in file: + line = line.strip() + if line.endswith('ON'): + line_l = line.split(',') + line_l[2] = float(line_l[2]) + float(line_l[3]) + line_l[-1] = 1 + else: + line_l = line.split(',') + line_l[2] = float(line_l[2]) + float(line_l[3]) + line_l[-1] = 0 + + if line.startswith('G'): + #print(line_l) + error_g.append(line_l) + elif line.startswith('R'): + error_r.append(line_l) + else: + error_w.append(line_l) + + return error_g, error_r, error_w + + return error_g, error_r + +def separate_rows(filename): + error_g = [] + error_r = [] + error_w = [] + + with open(filename, 'r') as file: + for line in file: + line = line.strip() + if line.endswith('ON'): + line_l = line.split(',') + #line_l[2] = float(line_l[2]) + float(line_l[3]) + line_l[-1] = 1 + else: + line_l = line.split(',') + #line_l[2] = float(line_l[2]) + float(line_l[3]) + line_l[-1] = 0 + + if line.startswith('G'): + #print(line_l) + error_g.append(line_l) + elif line.startswith('R'): + error_r.append(line_l) + else: + error_w.append(line_l) + + return error_g, error_r, error_w + + + + +log_error = "log/error_log_t.csv" +log_position = "log/position_log.csv" + +error_g, error_r, error_w = separate_rows_s(log_error) +error_g_on = [row for row in error_g if row[-1] == 1] +error_g_off = [row for row in error_g if row[-1] == 0] + +error_r_on = [row for row in error_r if row[-1] == 1] +error_r_off = [row for row in error_r if row[-1] == 0] + +r_on_t = [float(row[1]) for row in error_r_on] +r_off_t = [float(row[1]) for row in error_r_off] +r_on_ax= [float(row[2]) for row in error_r_on] +r_off_ax= [float(row[2]) for row in error_r_off] + +print(r_on_ax) + +g_on_t = [float(row[1]) for row in error_g_on] +g_off_t = [float(row[1]) for row in error_g_off] +g_on_ax= [float(row[2]) for row in error_g_on] +g_off_ax= [float(row[2]) for row in error_g_off] + +w_t = [float(row[1]) for row in error_w] +w_ax= [float(row[2]) for row in error_w] + +x_c, y_c = plot_coordinates_log(log_position) +t,axis = plot_movement_log(log_position) + +file_path = 'log/position_log_a.csv' # Replace with your file pathplot_coordinates(file_path) +x_a, y_a = plot_coordinates_log(file_path) +t_a, ax_a = plot_movement_log(file_path) + +fig = plt.figure() +ax = plt.subplot() +ax.plot(t, axis,'g--', label='sv') +ax.plot(t_a, ax_a,'m.', label='sv') +ax.plot(g_on_t, g_on_ax,'ko', label='g_error_on') +#ax.plot(g_off_t, g_off_ax,'kx', label='g_error_off') +ax.plot(r_on_t, r_on_ax,'ro', label='r_error_on') +#ax.plot(r_off_t,r_off_ax,'rx', label='r_error_off') +ax.plot(w_t,w_ax,'^',color='orange', label='error_off') + +ax.legend() +plt.show() + +error_g, error_r,error_w = separate_rows(log_error) +error_g_on = [row for row in error_g if row[-1] == 1] +error_g_off = [row for row in error_g if row[-1] == 0] + +error_r_on = [row for row in error_r if row[-1] == 1] +error_r_off = [row for row in error_r if row[-1] == 0] + +r_on_t = [float(row[1]) for row in error_r_on] +r_off_t = [float(row[1]) for row in error_r_off] +r_on_x= [float(row[2]) for row in error_r_on] +r_off_x= [float(row[2]) for row in error_r_off] +r_on_y= [float(row[3]) for row in error_r_on] +r_off_y= [float(row[3]) for row in error_r_off] + +g_on_t = [float(row[1]) for row in error_g_on] +g_off_t = [float(row[1]) for row in error_g_off] +g_on_x= [float(row[2]) for row in error_g_on] +g_off_x= [float(row[2]) for row in error_g_off] +g_on_y= [float(row[3]) for row in error_g_on] +g_off_y= [float(row[3]) for row in error_g_off] + + + +fig = plt.figure() +ax = plt.subplot() +ax.plot(x_c, y_c,t,'g--', label='sv') +ax.plot(x_a, y_a,t_a,'m.', label='sv') +ax.plot(g_on_x, g_on_y,g_on_t,'ko', label='g_error_on') +ax.plot(g_off_x, g_off_y,g_off_t,'kx', label='g_error_off') +ax.plot(r_on_x, r_on_y,'ro',r_on_t, label='r_error_on') +ax.plot(r_off_x,r_off_y,'rx',r_off_t, label='r_error_off') + + +ax.legend() +plt.show() + + + + + + + diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py new file mode 100644 index 00000000..9b142c2b --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/result_compute.py @@ -0,0 +1,428 @@ +import matplotlib.pyplot as plt +import numpy as np +from scipy import stats +import seaborn as sns +import pandas as pd +import tikzplotlib + +def compute_power(): + v = 1.5 + Pm= 16.3*(v**2) + #Pd = 0.5*a_dens*(v**3)*Cd*A #1/2*rho*v^3*C*A + return Pm#+Pd + +def compute_error(file_path,pkt_size): + d_1 = {} + d_2 = {} + d_3 = {} + d_4 = {} + m_t = {} + m_d ={} + m_tp={} + m_fp={} + m_tn={} + m_fn={} + acc=[] + pr = {} + rc = {} + e = {} + auv_e = {} + asv_e = {} + + with open(file_path, 'r') as file: + p=compute_power() + v=1.5 + t=pkt_size*8/4800 + #t=0.208 + + for row in file: + row = row.replace(',','.') + row = row.strip().split(';') + + if row != ['']: + if float(row[0]) not in m_t: + if float(row[10]): + m_t[float(row[0])]=[float(row[4])/float(row[10])] + d=float(row[5])/float(row[10]) + power = ((d/v)/3600)*(p/1000) + m_d[float(row[0])]=[power] + else: + m_t[float(row[0])]=[float(row[4])] + d=float(row[5]) + power = ((d/v)/3600)*(p/1000) + m_d[float(row[0])]=[power] + + d_1[float(row[0])]=[float(row[11])] + d_2[float(row[0])]=[float(row[12])] + d_3[float(row[0])]=[float(row[13])] + d_4[float(row[0])]=[float(row[14])] + + m_fn[float(row[0])]=[float(row[7])] + m_tn[float(row[0])]=[float(row[8])] + m_fp[float(row[0])]=[float(row[9])] + m_tp[float(row[0])]=[float(row[6])] + + e[float(row[0])]=[float(row[10])] + + + if float(row[10]): + if float(row[6])+float(row[9]): + pr[float(row[0])]=[float(row[6])/(float(row[6])+float(row[9]))] + if float(row[6])+float(row[7]) and float(row[6]): + rc[float(row[0])]=[float(row[6])/(float(row[6])+float(row[7]))] + + sent_u = float(row[15]) + sent_u_er = float(row[19]) + rcv_s = float(row[16]) + rcv_s_er = float(row[20]) + + + + sent_s = float(row[17]) + sent_s_er = float(row[21]) + rcv_u = float(row[18]) + rcv_u_er = float(row[22]) + + #asv_e[float(row[0])] = [sent_s] + #auv_e[float(row[0])] = [sent_u] + listen_time = 150000-(rcv_s_er)*(t)-(sent_s +rcv_s+sent_s_er)*0.008 + + asv_e[float(row[0])] = [(rcv_s_er * (t/3600) + rcv_s*0.008/3600) * 0.8/1000 + ((sent_s_er + sent_s)*0.008/3600)*60/1000 + (listen_time/3600)*0.01/1000] + listen_time = 150000-(sent_u_er +rcv_u_er)*(t) -(sent_u +rcv_u)*(0.008) + #auv_e[float(row[0])] = [rcv_s*(t/3600)*0.8/1000 + sent_u*(t/3600)*60/1000 + listen_time*0.01/1000]#*t*60 + rcv*t*0.8] + #auv_e[float(row[0])] = [sent_u_er + + + else: + e[float(row[0])].append(float(row[10])) + + d_1[float(row[0])].append(float(row[11])) + d_2[float(row[0])].append(float(row[12])) + d_3[float(row[0])].append(float(row[13])) + d_4[float(row[0])].append(float(row[14])) + + if float(row[10]): + m_t[float(row[0])].append(float(row[4])/float(row[10])) + d=float(row[5])/float(row[10]) + power=((d/v)/3600)*p/1000 + m_d[float(row[0])].append(((d/v)/3600)*(p/1000)) + else: + m_t[float(row[0])].append(float(row[4])) + d=float(row[5]) + power =((d/v)/3600)*(p/1000) + m_d[float(row[0])].append(power) + + m_fn[float(row[0])].append(float(row[7])) + m_tn[float(row[0])].append(float(row[8])) + m_fp[float(row[0])].append(float(row[9])) + m_tp[float(row[0])].append(float(row[6])) + + sent_u = float(row[15]) + rcv_u = float(row[16]) + sent_s = float(row[17]) + rcv_s = float(row[18]) + sent_u_er = float(row[19]) + + rcv_s_er = float(row[20]) + + + sent_s_er = float(row[21]) + + rcv_u_er = float(row[22]) + + #asv_e[float(row[0])] = [sent_s] + #auv_e[float(row[0])] = [sent_u] + listen_time = 150000-(rcv_s_er)*(t)-(sent_s +rcv_s+sent_s_er )*0.008 + + asv_e[float(row[0])].append((rcv_s_er * (t/3600) + rcv_s*0.008/3600) * 0.8/1000 + ((sent_s_er + sent_s)*0.008/3600)*60/1000 + (listen_time/3600)*0.01/1000) + listen_time = 150000-(sent_u_er +rcv_u_er)*(t) -(sent_u +rcv_u)*(0.008) + #auv_e[float(row[0])].append(rcv_s*(t/3600)*0.8/1000 + sent_u*(t/3600)*60/1000 + listen_time*0.01/1000) #*t*60 + rcv*t*0.8] + #auv_e[float(row[0])].append(sent_u_er)#*t*60 + rcv*t*0.8] + + #asv_e[float(row[0])].append(sent_s)#*t*60 + rcv*t*0.8) + #auv_e[float(row[0])].append(sent_u)#*t*60 + rcv*t*0.8) + + if float(row[10]): + if float(row[0]) in m_tp: + if float(row[6])+float(row[9]): + if float(row[0]) in pr: + pr[float(row[0])].append(float(row[6])/(float(row[6])+float(row[9]))) + else: + pr[float(row[0])]=[float(row[6])/(float(row[6])+float(row[9]))] + + if float(row[6]): + if float(row[6])+float(row[7]): + if float(row[0]) in rc : + rc[float(row[0])].append(float(row[6])/(float(row[6])+float(row[7]))) + else: + rc[float(row[0])]=[float(row[6])/(float(row[6])+float(row[7]))] + else: + m_tp[float(row[0])]=[float(row[6])] + if float(row[6])+float(row[9]): + pr[float(row[0])]=[float(row[6])/(float(row[6])+float(row[9]))] + if float(row[6])+float(row[7]) and float(row[6]): + rc[float(row[0])]=[float(row[6])/(float(row[6])+float(row[7]))] + + + acc.append(float(row[0])) + + return m_t,m_d,m_tp,m_fp,m_tn,m_fn,acc,pr,rc, d_1, d_2, d_3, d_4, asv_e, auv_e, e + + +file_path = "result.csv" + +m1_t,m1_d,m1_tp,m1_fp,m1_tn,m1_fn,acc1,pr1,rc1, d11,d12,d13,d14, asv_e, auv_e, e1 = compute_error(file_path,125) + +file_path = "result_2.csv" + +m2_t,m2_d,m2_tp,m2_fp,m2_tn,m2_fn,acc2,pr2,rc2,d21,d22,d23,d24,asv_e2, auv_e2, e2 = compute_error(file_path,5) + + +for key in acc1: + for j in range(len(d11[key])): + d11[key][j] = 0.25*(d12[key][j]+ d11[key][j]+d13[key][j]+d14[key][j]) + #d11[key][j] = (d12[key][j]+ d11[key][j]+d13[key][j]+d14[key][j]) + +for key in acc2: + for j in range(len(d21[key])): + d21[key][j] = 0.25*(d22[key][j]+ d21[key][j]+d23[key][j]+d24[key][j]) + #d21[key][j] = (d22[key][j]+ d21[key][j]+d23[key][j]+d24[key][j]) + +pr1 = {'Key':pr1.keys(), + 'Values':pr1.values()} +pr1 = pd.DataFrame(pr1) + +ax = plt.figure() +pr1 = pr1.explode('Values') +pr1 = pr1.reset_index(drop=True) +pr1.columns= ['Key','Values'] +sns.lineplot(data=pr1,x='Key',y='Values',marker='o',label='IER') + +pr2 = {'Key':pr2.keys(), + 'Values':pr2.values()} +pr2 = pd.DataFrame(pr2) + +pr2 = pr2.explode('Values') +pr2 = pr2.reset_index(drop=True) +pr2.columns= ['Key','Values'] +sns.lineplot(data=pr2,x='Key',y='Values',marker='^',markersize='8',label='SER') + +plt.ylim(bottom=0) +plt.xscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +#plt.show() +tikzplotlib.save('pr.tex') +plt.close() + + +rc1 = {'Key':rc1.keys(), + 'Values':rc1.values()} +rc1 = pd.DataFrame(rc1) + +ax = plt.figure() +rc1 = rc1.explode('Values') +rc1 = rc1.reset_index(drop=True) +rc1.columns= ['Key','Values'] +sns.lineplot(data=rc1,x='Key',y='Values',marker='o',label='IER') + +rc2 = {'Key':rc2.keys(), + 'Values':rc2.values()} +rc2 = pd.DataFrame(rc2) + +rc2 = rc2.explode('Values') +rc2 = rc2.reset_index(drop=True) +rc2.columns= ['Key','Values'] +sns.lineplot(data=rc2,x='Key',y='Values',marker='^',markersize='8',label='SER') + +plt.ylim(bottom=0) +plt.xscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +#plt.show() +tikzplotlib.save('rec.tex') +plt.close() + + +ax = plt.figure() +#plt.plot(m_d.keys(),mean_d,'o--',label='distance', color='#1f77b4') +#plt.errorbar(m_d.keys(),mean_d,yerr=ci_d,fmt='o',color='#1f77b4') +data = {'Key':m1_t.keys(), + 'Values':m1_d.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +data = {'Key':m2_t.keys(), + 'Values':m2_d.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + +plt.xscale('log') +#plt.yscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +plt.ylabel('kWh',rotation=0) +#plt.title('ASV\'s Distance Traveled') +#plt.title('ASV\'s Energy Consumption (movement) per Error') +#plt.show() +tikzplotlib.save('energy_mov.tex') +plt.close() + +ax = plt.figure() +#plt.plot(m_d.keys(),mean_d,'o--',label='distance', color='#1f77b4') +#plt.errorbar(m_d.keys(),mean_d,yerr=ci_d,fmt='o',color='#1f77b4') +data = {'Key':m1_t.keys(), + 'Values':asv_e.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +data = {'Key':m2_t.keys(), + 'Values':asv_e2.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + +plt.xscale('log') +#plt.yscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +plt.ylabel('kWh',rotation=0) +#plt.title('ASV\'s Distance Traveled') +#plt.ylim((50000,500000)) +#plt.ylim((10,100)) +#plt.title('ASV\'s Energy Consumption (total)') +#plt.show() +tikzplotlib.save('energy_tx.tex') +plt.close() + +#ax = plt.figure() +#plt.plot(m_d.keys(),mean_d,'o--',label='distance', color='#1f77b4') +#plt.errorbar(m_d.keys(),mean_d,yerr=ci_d,fmt='o',color='#1f77b4') +#data = {'Key':m1_t.keys(), +# 'Values':auv_e.values()} +#tp_df = pd.DataFrame(data) +#tp_df = tp_df.explode('Values') +#tp_df = tp_df.reset_index(drop=True) +#tp_df.columns= ['Key','Values'] +#sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +#data = {'Key':m2_t.keys(), +# 'Values':auv_e2.values()} +#tp_df = pd.DataFrame(data) +#tp_df = tp_df.explode('Values') +#tp_df = tp_df.reset_index(drop=True) +#tp_df.columns= ['Key','Values'] +#sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + +#plt.xscale('log') +#plt.yscale('log') +#plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +#plt.xlabel('$\epsilon$') +#plt.ylabel('kWh',rotation=0) +#plt.ylim(top=10800) +#plt.title('ASV\'s Distance Traveled') +#plt.ylim((10,100)) +#plt.title('AUV\'s Energy Consumption (tx)') +#plt.show() +#tikzplotlib.save('energy_tx.tex') +#plt.close() + + +ax = plt.figure() +#plt.plot(m_t.keys(),mean_t,'o--',label='time',color='#1f77b4') +#plt.errorbar(m_t.keys(),mean_t,yerr=ci_t,fmt='o', color='#1f77b4') +data = {'Key':m1_t.keys(), + 'Values':m1_t.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +data = {'Key':m2_t.keys(), + 'Values':m2_t.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') +plt.xscale('log') +#plt.yscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +plt.ylabel('Time') +#plt.title('Average Downtime per Error') +#plt.show() +tikzplotlib.save('time.tex') +plt.close() + +ax = plt.figure() + +data = {'Key':d11.keys(), + 'Values':d11.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +data = {'Key':d21.keys(), + 'Values':d21.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + + +plt.xscale('log') +plt.yscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +plt.ylabel('Distance') +#plt.title('AUV\'s Distance Covered') +plt.show() +#tikzplotlib.save('dist.tex') +plt.close() + + + +ax = plt.figure() + +data = {'Key':d11.keys(), + 'Values':m1_tp.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='o',label='IER') + +data = {'Key':d21.keys(), + 'Values':m2_tp.values()} +tp_df = pd.DataFrame(data) +tp_df = tp_df.explode('Values') +tp_df = tp_df.reset_index(drop=True) +tp_df.columns= ['Key','Values'] +sns.lineplot(data=tp_df,x='Key',y='Values',marker='^',markersize='8',label='SER') + + +plt.xscale('log') +plt.grid(True, linestyle='dashed', linewidth=0.5, color='gray',axis='y',which='both') +plt.xlabel('$\\theta$') +plt.ylabel('True Error') +#plt.title('AUV\'s Distance Covered') +plt.show() +#tikzplotlib.save('t_e.tex') +plt.close() + diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_banch.sh b/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_banch.sh new file mode 100755 index 00000000..13214462 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_banch.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +#rm result.csv + +# Iterate over the parameters and execute the command for each one +for rng in $(seq 36 1 37) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error_basic.tcl 0.001 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp_4.py 0.001 $2 $3 $rng >> result_2.csv + +done + +for rng in $(seq 36 1 37) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error_basic.tcl 0.01 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp_4.py 0.01 $2 $3 $rng >> result_2.csv + +done + +for rng in $(seq 36 1 37) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error_basic.tcl 0.05 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp_4.py 0.05 $2 $3 $rng >> result_2.csv + +done + + +for rng in $(seq 36 1 37) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error_basic.tcl 0.25 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp_4.py 0.25 $2 $3 $rng >> result_2.csv + +done + + +for rng in $(seq 27 1 31) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + + ns test_uwauv_error_basic.tcl 0.1 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp_4.py 0.1 $2 $3 $rng >> result_2.csv + +done + +python result_compute.py + diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_err.sh b/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_err.sh new file mode 100755 index 00000000..0cbea29e --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/sim_err.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +#rm result.csv +#Iterate over the parameters and execute the command for each one + +for rng in $(seq 29 1 32) +do + rm log/error_log.csv + rm log/error_log_t.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error.tcl 0.001 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp.py 0.001 $2 $3 $rng >> result.csv + +done + +for rng in $(seq 34 1 36) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error.tcl 0.01 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp.py 0.01 $2 $3 $rng >> result.csv +done + +for rng in $(seq 29 1 32) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error.tcl 0.05 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp.py 0.05 $2 $3 $rng >> result.csv +done + +for rng in $(seq 28 1 31) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error.tcl 0.1 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp.py 0.1 $2 $3 $rng >> result.csv + +done + + +for rng in $(seq 28 1 31) +do + rm log/error_log.csv + rm log/position_log.csv + rm log/position_log_a.csv + rm log/true_error_log.csv + rm log.out + + ns test_uwauv_error.tcl 0.25 $2 $3 $rng >> log.out + #ns test_uwauv_error.tcl 0.001 0.01 0.1 0 + python metric_comp.py 0.25 $2 $3 $rng >> result.csv + +done + +python result_compute.py \ No newline at end of file diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl new file mode 100644 index 00000000..feb551f8 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error.tcl @@ -0,0 +1,516 @@ +# +# Copyright (c) 2015 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Author: Alessia Ortile +# Version: 1.0.0 +# NOTE: tcl sample tested on Ubuntu 12.04, 64 bits OS +# +######################################################################################### +## +## NOTE: This script uses the PHY model "Module/MPhy/BPSK" of NS-Miracle in addPosition +## with the module "MInterference/MIV" for the computation of interference. +## These two modules is used in this script to demonstrate their compatibility with +## DESERT stack. +## If you decide to use Module/UW/PHYSICAL from DESERT, it is suggested to use also +## Module/UW/INTERFERENCE (which is an extension of the one coming from NS-Miracle) +## Anyways, it is possibile to use Module/UW/INTERFERENCE with Module/MPhy/BPSK whereas +## it is not possibile to use MInterference/MIV with Module/UW/INTERFERENCE for compatibility +## reasons +## +######################################################################################## +# ---------------------------------------------------------------------------------- +# This script simulates the behavior of n AUVs and 1 ASV. The AUVs follow a fixed trajectory +# to inspect an area and generate errors with a certain probability. The ASV and AUVs share +# information about the errors to collaboratively resolve them using the IER method. +# ---------------------------------------------------------------------------------- +# Stack +# AUV ASV +# +------------------------------+ +------------------------------+ +# | 7. UW/AUV | UW/AUV/ERR | | 7. UW/AUV | UW/AUV/CER | +# +------------------------------+ +------------------------------+ +# | 6. UW/UDP | | 6. UW/UDP | +# +------------------------------+ +------------------------------+ +# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | +# +------------------------------+ +------------------------------+ +# | 4. UW/IP | | 4. UW/IP | +# +------------------------------+ +------------------------------+ +# | 4. MULTI_TRAFFIC_RANGE | | 4. MULTI_TRAFFIC_RANGE | +# +------------------------------+ +------------------------------+ +# | 3. UW/MLL | | 3. UW/MLL | +# +------------------------------+ +------------------------------+ +# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | +# +------------------------------+ +------------------------------+ +# | 1. UW/PHYSICAL | UW/OPTICAL | | 1. UW/PHYSICAL | UW/OPTICAL | +# +------------------------------+ +------------------------------+ +# | | | | +# +------------------------------------------------------------------+ +# | UnderwaterChannel | +# +------------------------------------------------------------------+ +###################################### +# Flags to enable or disable options # +###################################### +set opt(trace_files) 0 +set opt(bash_parameters) 1 + +##################### +# Library Loading # +##################### +load libMiracle.so +load libMiracleBasicMovement.so +load libmphy.so +load libmmac.so +load libUwmStd.so +load libuwcsmaaloha.so +load libuwmmac_clmsgs.so +load libuwaloha.so +load libuwip.so +load libuwstaticrouting.so +load libuwmll.so +load libuwudp.so +load libuwcbr.so +load libuwtdma.so +load libuwsmposition.so +load libuwsmwpposition.so +load libuwinterference.so +load libUwmStd.so +load libUwmStdPhyBpskTracer.so +load libuwphy_clmsgs.so +load libuwstats_utilities.so +load libuwphysical.so +load libuwposbasedrt.so +load libuwflooding.so +load libuwinterference.so +load libuwphy_clmsgs.so +load libuwstats_utilities.so +load libuwphysical.so +load libuwoptical_propagation.so +load libuwoptical_channel.so +load libuwoptical_phy.so +load libuwmulti_traffic_control.so +load libuwauv.so + +############################# +# NS-Miracle initialization # +############################# +# You always need the following two lines to use the NS-Miracle simulator +set ns [new Simulator] +$ns use-Miracle + +################## +# Tcl variables # +################## +set opt(n_auv) 4 ;# Number of Nodes +set opt(starttime) 1 +set opt(stoptime) 150000;#150000 +set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] +set opt(rngstream) 1 + +set opt(maxinterval_) 20.0 +set opt(freq) 20000.0 +set opt(bw) 10000.0 +set opt(bitrate) 4800.0 +set opt(ack_mode) "setNoAckMode" + + +set opt(txpower) 175.0 +set opt(pktsize) 125 +set opt(pktsize_monitoring) 5 +set opt(period) 60 + +set opt(op_freq) 10000000 +set opt(op_bw) 100000 +set opt(bitrate_op) 1000000 +set opt(txpower_op) 50; #30 +set opt(acq_db_op) 10 +set opt(temperatura) 293.15 ; # in Kelvin +set opt(txArea) 0.000010 + # receveing area, it has to be the same for optical physical and propagation +set opt(rxArea) 0.0000011 ; +set opt(c) 0.4; #0.4 coastal water +set opt(theta) 1 +set opt(id) [expr 1.0e-9] +set opt(il) [expr 1.0e-6] +set opt(shuntRes) [expr 1.49e9] +set opt(sensitivity) 0.26 +set opt(LUTpath) "..dbs/optical_noise/LUT.txt" +set opt(rngstream) 13 + +set opt(accuracy) 0.001 +set opt(variance) 0.01 +set opt(e_prob) 0.01 + +#set opt(ctr_period) 60 + +if {$opt(bash_parameters)} { + if {$argc != 4} { + puts "The script requires 4 inputs:" + puts "- the first for accuracy" + puts "- the second for variance" + puts "- the third error probability" + puts "- the fourth for the rngstream" + puts "example: ns test_uwmultitraffic_auv.tcl 0.001 0.01 0.01 5" + puts "If you want to leave the default values, please set to 0" + puts "the value opt(bash_parameters) in the tcl script" + puts "Please try again." + return + } else { + set opt(accuracy) [lindex $argv 0] + set opt(variance) [lindex $argv 1] + set opt(e_prob) [lindex $argv 2] + set opt(rngstream) [lindex $argv 3]; + } +} + +set opt(waypoint_file) "../dbs/wp_path/rov_path_square.csv" + +#random generator +global defaultRNG +for {set k 0} {$k < $opt(rngstream)} {incr k} { + $defaultRNG next-substream +} + +if {$opt(trace_files)} { + set opt(tracefilename) "./test_uwcbr.tr" + set opt(tracefile) [open $opt(tracefilename) w] + set opt(cltracefilename) "./test_uwcbr.cltr" + set opt(cltracefile) [open $opt(tracefilename) w] +} else { + set opt(tracefilename) "/dev/null" + set opt(tracefile) [open $opt(tracefilename) w] + set opt(cltracefilename) "/dev/null" + set opt(cltracefile) [open $opt(cltracefilename) w] +} + +set channel [new Module/UnderwaterChannel] + +MPropagation/Underwater set shipping_ 1 +MPropagation/Underwater set windspeed_ 5 +MPropagation/Underwater set debug_ 0 +MPropagation/Underwater set practicalSpreading_ 1.5 + +set propagation [new MPropagation/Underwater] +set data_mask [new MSpectralMask/Rect] +$data_mask setFreq $opt(freq) +$data_mask setBandwidth $opt(bw) + +######################### +# Module Configuration # +######################### + +Module/UW/IP set debug_ 0 +Module/UW/UDP set debug_ 0 + +#TRAFFIC_CTR +Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 +Module/UW/MULTI_TRAFFIC_RANGE_CTR set check_to_period_ 5 + +Module/UW/CSMA_ALOHA set wait_costant_ 0.01 +Module/UW/CSMA_ALOHA set listen_time_ 0.01 + +# PHY + +Module/UW/PHYSICAL set BitRate_ $opt(bitrate) +Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) +Module/UW/PHYSICAL set MinTxSPL_dB_ 10 +Module/UW/PHYSICAL set AcquisitionThreshold_dB_ 5.0 +Module/UW/PHYSICAL set RxSnrPenalty_dB_ 0 +Module/UW/PHYSICAL set TxSPLMargin_dB_ 0 +Module/UW/PHYSICAL set MaxTxRange_ 50000 +Module/UW/PHYSICAL set PER_target_ 0 +Module/UW/PHYSICAL set CentralFreqOptimization_ 0 +Module/UW/PHYSICAL set BandwidthOptimization_ 0 +Module/UW/PHYSICAL set SPLOptimization_ 0 +Module/UW/PHYSICAL set debug_ 0 + + +# OPTICAL PHY + +Module/UW/OPTICAL/PHY set TxPower_ $opt(txpower_op) +Module/UW/OPTICAL/PHY set BitRate_ $opt(bitrate_op) +Module/UW/OPTICAL/PHY set AcquisitionThreshold_dB_ $opt(acq_db_op) +Module/UW/OPTICAL/PHY set Id_ $opt(id) +Module/UW/OPTICAL/PHY set Il_ $opt(il) +Module/UW/OPTICAL/PHY set R_ $opt(shuntRes) +Module/UW/OPTICAL/PHY set S_ $opt(sensitivity) +Module/UW/OPTICAL/PHY set T_ $opt(temperatura) +Module/UW/OPTICAL/PHY set Ar_ $opt(rxArea) +Module/UW/OPTICAL/PHY set debug_ 0 + +Module/UW/OPTICAL/Propagation set Ar_ $opt(rxArea) +Module/UW/OPTICAL/Propagation set At_ $opt(txArea) +Module/UW/OPTICAL/Propagation set c_ $opt(c) +Module/UW/OPTICAL/Propagation set theta_ $opt(theta) +Module/UW/OPTICAL/Propagation set debug_ 0 + +set propagation_op [new Module/UW/OPTICAL/Propagation] +$propagation_op setOmnidirectional +set channel_op [new Module/UW/Optical/Channel] +set data_mask_op [new MSpectralMask/Rect] +$data_mask_op setFreq $opt(op_freq) +$data_mask_op setBandwidth $opt(op_bw) + +################################ +# Procedure(s) to create node_leaders # +################################ + +source "auv.tcl" +source "asv.tcl" + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + createAUV $id1 +} +createASV $opt(n_auv) + +################################ +# Inter-node_leader module connection # +################################ + +proc connectNodes {id1} { + global ipif_asv ipr_asv portnum_asv portnum_auv portnum2_asv portnum2_auv + global asv_app asv_err + global ipif_auv auv_app auv_err + $asv_app($id1) set destAddr_ [$ipif_auv($id1) addr] + $asv_app($id1) set destPort_ $portnum_auv($id1) + + $asv_err($id1) set destAddr_ [$ipif_auv($id1) addr] + $asv_err($id1) set destPort_ $portnum2_auv($id1) + + + $auv_app($id1) set destAddr_ [$ipif_asv addr] + $auv_app($id1) set destPort_ $portnum_asv($id1) + + $auv_err($id1) set destAddr_ [$ipif_asv addr] + $auv_err($id1) set destPort_ $portnum2_asv($id1) +} + +# Setup flows + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + connectNodes $id1 +} + +# Fill ARP tables +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + + $mll_auv($id1) addentry [$ipif_asv addr] [$mac_asv addr] + $mll_op_auv($id1) addentry [$ipif_asv addr] [$mac_op_asv addr] + $mll_asv addentry [$ipif_auv($id1) addr] [$mac_auv($id1) addr] + $mll_op_asv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) addr] +} + +Position/UWSMWP debug_ 1 + +# Setup positions +set position_asv [new "Position/UWSMWP"] +$position_asv setX_ 0 +$position_asv setY_ 0 +$position_asv setZ_ -1 + +for {set id 0} {$id < $opt(n_auv)} {incr id} { + + $asv_app($id) setPosition $position_asv + $asv_err($id) setPosition $position_asv +} + +$position_auv(0) setX_ -1 +$position_auv(0) setY_ 1 + +$position_auv(1) setX_ 1 +$position_auv(1) setY_ -1 + +$position_auv(2) setX_ 1 +$position_auv(2) setY_ 1 + +$position_auv(3) setX_ -1 +$position_auv(3) setY_ -1 + +for {set id 0} {$id < $opt(n_auv)} {incr id} { + + set position_auv($id) [new "Position/UWSMWP"] + $position_auv($id) setZ_ -100 + + $auv_app($id) setPosition $position_auv($id) + $auv_err($id) setPosition $position_auv($id) + + #puts "x = [$position_auv($id) getX_]; y = [$position_auv($id) getY_]; z = [$position_auv($id) getZ_]" +} + + +# Setup routing table +for {set id 0} {$id < $opt(n_auv)} {incr id} { + $ipr_auv($id) addRoute [$ipif_asv addr] [$ipif_asv addr] + $ipr_asv addRoute [$ipif_auv($id) addr] [$ipif_auv($id) addr] +} + +##################### +# Start/Stop Timers # +##################### +# Set here the timers to start and/or stop modules (optional) +# e.g., + +set outfile [open "test_uwauv_results.csv" "w"] +close $outfile +set fp [open $opt(waypoint_file) r] +set file_data [read $fp] +set data [split $file_data "\n"] +foreach line $data { + if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { + $ns at $t "update_and_check $t" + $ns at $t "$asv_app(0) sendPosition [expr -$x] [expr $y] [expr $z]" + $ns at $t "$asv_app(1) sendPosition [expr $x] [expr -$y] [expr $z]" + $ns at $t "$asv_app(2) sendPosition [expr $x] [expr $y] [expr $z]" + $ns at $t "$asv_app(3) sendPosition [expr -$x] [expr -$y] [expr $z]" + #for {set id 0} {$id < $opt(n_auv)} {incr id} { + # $ns at $t "$asv_app($id) sendPosition [expr $x*($id*(2))-$x] [expr $y*($id*(-2))+$y] [expr $z]" + #} + } +} + +set min 0 +set max 100 + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + + set time_ [new RandomVariable/Uniform] + $time_ set min_ 0 + $time_ set max_ 100 + $time_ use-rng $defaultRNG + + $ns at [expr $opt(starttime) + [$time_ value]] "$asv_app($id1) start" + $ns at $opt(stoptime) "$asv_app($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_app($id1) start" + $ns at $opt(stoptime) "$auv_app($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_err($id1) start" + $ns at $opt(stoptime) "$auv_err($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$asv_err($id1) start" + $ns at $opt(stoptime) "$asv_err($id1) stop" + +} + +proc update_and_check {t} { + set outfile_auv [open "test_uwauv0_results.csv" "a"] + set outfile_auv1 [open "test_uwauv1_results.csv" "a"] + set outfile_asv [open "test_uwasv_results.csv" "a"] + global position_auv position_asv auv_app asv_app opt n_auv auv_err asv_err + for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + $position_auv($id1) update + puts $outfile_auv "positions AUV($id1): x = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" + } + + + $position_asv update + puts $outfile_asv "$t,[$asv_app(0) getX],[$asv_app(0) getY],[$asv_app(0) getZ]" + #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" + + close $outfile_auv + close $outfile_asv + + + +} +### + +################### +# Final Procedure # +################### +# Define here the procedure to call at the end of the simulation +proc finish {} { + global ns opt n_auv + global mac propagation phy_data channel db_manager propagation + global node_asv_coordinates + global ipr_asv ipif_asv udp_asv phy + global asv_app asv_err + global auv_app auv_err mac_auv + global node_asv_stats tmp_node_asv_stats ipif_auv ipif_asv + + set sum_asv_ctr_throughput 0 + set sum_asv_ctr_sent_pkts 0.0 + set sum_asv_ctr_rcv_pkts 0.0 + + set sum_auv_mon_throughput 0 + set sum_auv_mon_sent_pkts 0.0 + set sum_auv_mon_rcv_pkts 0.0 + + set sum_asv_err_throughput 0 + set sum_asv_err_sent_pkts 0.0 + set sum_asv_err_rcv_pkts 0.0 + + set sum_auv_err_throughput 0 + set sum_auv_err_sent_pkts 0.0 + set sum_auv_err_rcv_pkts 0.0 + + + for {set i 0} {$i < $opt(n_auv)} {incr i} { + set asv_ctr_thr [$asv_app($i) getthr] + set asv_ctr_sent_pkts [$asv_app($i) getsentpkts] + set asv_ctr_rcv_pkts [$asv_app($i) getrecvpkts] + + set auv_mon_thr [$auv_app($i) getthr] + set auv_mon_sent_pkts [$auv_app($i) getsentpkts] + set auv_mon_rcv_pkts [$auv_app($i) getrecvpkts] + + set asv_err_thr [$asv_err($i) getthr] + set asv_err_sent_pkts [$asv_err($i) getsentpkts] + set asv_err_rcv_pkts [$asv_err($i) getrecvpkts] + + set auv_err_thr [$auv_err($i) getthr] + set auv_err_sent_pkts [$auv_err($i) getsentpkts] + set auv_err_rcv_pkts [$auv_err($i) getrecvpkts] + + set sum_asv_ctr_throughput [expr $sum_asv_ctr_throughput + $asv_ctr_thr] + set sum_asv_ctr_sent_pkts [expr $sum_asv_ctr_sent_pkts + $asv_ctr_sent_pkts] + set sum_asv_ctr_rcv_pkts [expr $sum_asv_ctr_rcv_pkts + $asv_ctr_rcv_pkts] + + set sum_auv_mon_throughput [expr $sum_auv_mon_throughput + $auv_mon_thr] + set sum_auv_mon_sent_pkts [expr $sum_auv_mon_sent_pkts + $auv_mon_sent_pkts] + set sum_auv_mon_rcv_pkts [expr $sum_auv_mon_rcv_pkts + $auv_mon_rcv_pkts] + + set sum_asv_err_throughput [expr $sum_asv_err_throughput + $asv_err_thr] + set sum_asv_err_sent_pkts [expr $sum_asv_err_sent_pkts + $asv_err_sent_pkts] + set sum_asv_err_rcv_pkts [expr $sum_asv_err_rcv_pkts + $asv_err_rcv_pkts] + + set sum_auv_err_throughput [expr $sum_auv_err_throughput + $auv_err_thr] + set sum_auv_err_sent_pkts [expr $sum_auv_err_sent_pkts + $auv_err_sent_pkts] + set sum_auv_err_rcv_pkts [expr $sum_auv_err_rcv_pkts + $auv_err_rcv_pkts] + } + + puts "$sum_asv_ctr_sent_pkts $sum_asv_ctr_rcv_pkts $sum_auv_mon_sent_pkts $sum_auv_mon_rcv_pkts $sum_asv_err_sent_pkts $sum_asv_err_rcv_pkts $sum_auv_err_sent_pkts $sum_auv_err_rcv_pkts" + + + $ns flush-trace + close $opt(tracefile) +} + +################### +# start simulation +################### +$ns at [expr $opt(stoptime) + 250.0] "finish; $ns halt" +$ns run diff --git a/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl new file mode 100644 index 00000000..e330bf49 --- /dev/null +++ b/DESERT_Framework/DESERT/samples/desert_samples/AUV/test_uwauv_error_basic.tcl @@ -0,0 +1,514 @@ +# +# Copyright (c) 2023 Regents of the SIGNET lab, University of Padova. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University of Padova (SIGNET lab) nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Author: Alessia Ortile +# Version: 1.0.0 +# NOTE: tcl sample tested on Ubuntu 12.04, 64 bits OS +# +######################################################################################### +## +## NOTE: This script uses the PHY model "Module/MPhy/BPSK" of NS-Miracle in addPosition +## with the module "MInterference/MIV" for the computation of interference. +## These two modules is used in this script to demonstrate their compatibility with +## DESERT stack. +## If you decide to use Module/UW/PHYSICAL from DESERT, it is suggested to use also +## Module/UW/INTERFERENCE (which is an extension of the one coming from NS-Miracle) +## Anyways, it is possibile to use Module/UW/INTERFERENCE with Module/MPhy/BPSK whereas +## it is not possibile to use MInterference/MIV with Module/UW/INTERFERENCE for compatibility +## reasons +## +######################################################################################## +# ---------------------------------------------------------------------------------- +# This script simulates the behavior of 'n' AUVs and 1 ASV. The AUVs follow a fixed trajectory +# to inspect an area and generate errors with a certain probability. The ASV and AUVs share +# information about the errors to collaboratively resolve them using the SIR method. +# ---------------------------------------------------------------------------------- +# Stack +# AUV ASV +# +------------------------------+ +------------------------------+ +# | 7. UW/AUV | UW/AUV/ERR | | 7. UW/AUV | UW/AUV/CER | +# +------------------------------+ +------------------------------+ +# | 6. UW/UDP | | 6. UW/UDP | +# +------------------------------+ +------------------------------+ +# | 5. UW/STATICROUTING | | 5. UW/STATICROUTING | +# +------------------------------+ +------------------------------+ +# | 4. UW/IP | | 4. UW/IP | +# +------------------------------+ +------------------------------+ +# | 4. MULTI_TRAFFIC_RANGE | | 4. MULTI_TRAFFIC_RANGE | +# +------------------------------+ +------------------------------+ +# | 3. UW/MLL | | 3. UW/MLL | +# +------------------------------+ +------------------------------+ +# | 2. UW/CSMA_ALOHA | | 2. UW/CSMA_ALOHA | +# +------------------------------+ +------------------------------+ +# | 1. UW/PHYSICAL | UW/OPTICAL | | 1. UW/PHYSICAL | UW/OPTICAL | +# +------------------------------+ +------------------------------+ +# | | | | +# +------------------------------------------------------------------+ +# | UnderwaterChannel | +# +------------------------------------------------------------------+ +# Flags to enable or disable options # +###################################### +set opt(trace_files) 0 +set opt(bash_parameters) 1 + +##################### +# Library Loading # +##################### +load libMiracle.so +load libMiracleBasicMovement.so +load libmphy.so +load libmmac.so +load libUwmStd.so +load libuwcsmaaloha.so +load libuwmmac_clmsgs.so +load libuwaloha.so +load libuwip.so +load libuwstaticrouting.so +load libuwmll.so +load libuwudp.so +load libuwcbr.so +load libuwtdma.so +load libuwsmposition.so +load libuwsmwpposition.so +load libuwinterference.so +load libUwmStd.so +load libUwmStdPhyBpskTracer.so +load libuwphy_clmsgs.so +load libuwstats_utilities.so +load libuwphysical.so +load libuwposbasedrt.so +load libuwflooding.so +load libuwinterference.so +load libuwphy_clmsgs.so +load libuwstats_utilities.so +load libuwphysical.so +load libuwoptical_propagation.so +load libuwoptical_channel.so +load libuwoptical_phy.so +load libuwmulti_traffic_control.so +load libuwauv.so + +############################# +# NS-Miracle initialization # +############################# +# You always need the following two lines to use the NS-Miracle simulator +set ns [new Simulator] +$ns use-Miracle + +################## +# Tcl variables # +################## +set opt(n_auv) 4;#4 ;# Number of Nodes +set opt(starttime) 1 +set opt(stoptime) 150000 +set opt(txduration) [expr $opt(stoptime) - $opt(starttime)] +set opt(rngstream) 3 + +set opt(maxinterval_) 20.0 +set opt(freq) 20000.0 +set opt(bw) 10000.0 +set opt(bitrate) 4800.0 +set opt(ack_mode) "setNoAckMode" + +set opt(txpower) 175.0 +set opt(pktsize) 5 +set opt(period) 60 +set opt(accuracy) 0.001 +set opt(variance) 0.01 +set opt(e_prob) 0.01 + + +set opt(op_freq) 10000000 +set opt(op_bw) 100000 +set opt(bitrate_op) 1000000 +set opt(txpower_op) 50 +set opt(acq_db_op) 10 +set opt(temperatura) 293.15 ; # in Kelvin +set opt(txArea) 0.000010 +set opt(rxArea) 0.0000011 ; # receveing area, it has to be the same for optical physical and propagation +set opt(c) 0.4 ; # coastal water +set opt(theta) 1 +set opt(id) [expr 1.0e-9] +set opt(il) [expr 1.0e-6] +set opt(shuntRes) [expr 1.49e9] +set opt(sensitivity) 0.26 +set opt(LUTpath) "..dbs/optical_noise/LUT.txt" +set opt(rngstream) 13 + + +if {$opt(bash_parameters)} { + if {$argc != 4} { + puts "The script requires two inputs:" + puts "- the first for accuracy" + puts "- the second for variance" + puts "- the third for error probability" + puts "- the fourth for the rngstream" + puts "example: ns test_uwmultitraffic_auv.tcl 0.001 0.01 0.01 5" + puts "If you want to leave the default values, please set to 0" + puts "the value opt(bash_parameters) in the tcl script" + puts "Please try again." + return + } else { + set opt(accuracy) [lindex $argv 0] + set opt(variance) [lindex $argv 1] + set opt(e_prob) [lindex $argv 2] + set opt(rngstream) [lindex $argv 3]; + } +} + +set opt(waypoint_file) "../dbs/wp_path/rov_path_square.csv" + +#random generator +global defaultRNG +for {set k 0} {$k < $opt(rngstream)} {incr k} { + $defaultRNG next-substream +} + +if {$opt(trace_files)} { + set opt(tracefilename) "./test_uwcbr.tr" + set opt(tracefile) [open $opt(tracefilename) w] + set opt(cltracefilename) "./test_uwcbr.cltr" + set opt(cltracefile) [open $opt(tracefilename) w] +} else { + set opt(tracefilename) "/dev/null" + set opt(tracefile) [open $opt(tracefilename) w] + set opt(cltracefilename) "/dev/null" + set opt(cltracefile) [open $opt(cltracefilename) w] +} + + +MPropagation/Underwater set shipping_ 1 +MPropagation/Underwater set windspeed_ 5 +MPropagation/Underwater set debug_ 0 +MPropagation/Underwater set practicalSpreading_ 1.5 + +set propagation [new MPropagation/Underwater] +set channel [new Module/UnderwaterChannel] +set data_mask [new MSpectralMask/Rect] +$data_mask setFreq $opt(freq) +$data_mask setBandwidth $opt(bw) + +######################### +# Module Configuration # +######################### + +Module/UW/IP set debug_ 0 +Module/UW/UDP set debug_ 0 + +#TRAFFIC_CTR +Module/UW/MULTI_TRAFFIC_RANGE_CTR set debug_ 0 +Module/UW/MULTI_TRAFFIC_RANGE_CTR set check_to_period_ 50 + +Module/UW/CSMA_ALOHA set wait_costant_ 0.01 +Module/UW/CSMA_ALOHA set listen_time_ 0.01 + +# PHY + +Module/UW/PHYSICAL set BitRate_ $opt(bitrate) +Module/UW/PHYSICAL set MaxTxSPL_dB_ $opt(txpower) +Module/UW/PHYSICAL set MinTxSPL_dB_ 10 +Module/UW/PHYSICAL set AcquisitionThreshold_dB_ 5.0 +Module/UW/PHYSICAL set RxSnrPenalty_dB_ 0 +Module/UW/PHYSICAL set TxSPLMargin_dB_ 0 +Module/UW/PHYSICAL set MaxTxRange_ 50000 +Module/UW/PHYSICAL set PER_target_ 0 +Module/UW/PHYSICAL set CentralFreqOptimization_ 0 +Module/UW/PHYSICAL set BandwidthOptimization_ 0 +Module/UW/PHYSICAL set SPLOptimization_ 0 +Module/UW/PHYSICAL set debug_ 0 + + +# OPTICAL PHY + +Module/UW/OPTICAL/PHY set TxPower_ $opt(txpower_op) +Module/UW/OPTICAL/PHY set BitRate_ $opt(bitrate_op) +Module/UW/OPTICAL/PHY set AcquisitionThreshold_dB_ $opt(acq_db_op) +Module/UW/OPTICAL/PHY set Id_ $opt(id) +Module/UW/OPTICAL/PHY set Il_ $opt(il) +Module/UW/OPTICAL/PHY set R_ $opt(shuntRes) +Module/UW/OPTICAL/PHY set S_ $opt(sensitivity) +Module/UW/OPTICAL/PHY set T_ $opt(temperatura) +Module/UW/OPTICAL/PHY set Ar_ $opt(rxArea) +Module/UW/OPTICAL/PHY set debug_ 0 + +Module/UW/OPTICAL/Propagation set Ar_ $opt(rxArea) +Module/UW/OPTICAL/Propagation set At_ $opt(txArea) +Module/UW/OPTICAL/Propagation set c_ $opt(c) +Module/UW/OPTICAL/Propagation set theta_ $opt(theta) +Module/UW/OPTICAL/Propagation set debug_ 0 + +set propagation_op [new Module/UW/OPTICAL/Propagation] +$propagation_op setOmnidirectional +set channel_op [new Module/UW/Optical/Channel] +set data_mask_op [new MSpectralMask/Rect] +$data_mask_op setFreq $opt(op_freq) +$data_mask_op setBandwidth $opt(op_bw) + +################################ +# Procedure(s) to create node_leaders # +################################ + +source "auv_basic.tcl" +source "asv_basic.tcl" + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + createAUV $id1 +} +createASV $opt(n_auv) + +################################ +# Inter-node_leader module connection # +################################ + +proc connectNodes {id1} { + global ipif_asv ipr_asv portnum_asv portnum_auv portnum2_asv portnum2_auv + global asv_app asv_err + global ipif_auv auv_app auv_err + $asv_app($id1) set destAddr_ [$ipif_auv($id1) addr] + $asv_app($id1) set destPort_ $portnum_auv($id1) + + $asv_err($id1) set destAddr_ [$ipif_auv($id1) addr] + $asv_err($id1) set destPort_ $portnum2_auv($id1) + + + $auv_app($id1) set destAddr_ [$ipif_asv addr] + $auv_app($id1) set destPort_ $portnum_asv($id1) + + $auv_err($id1) set destAddr_ [$ipif_asv addr] + $auv_err($id1) set destPort_ $portnum2_asv($id1) +} + +# Setup flows + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + connectNodes $id1 +} + +# Fill ARP tables +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + + $mll_auv($id1) addentry [$ipif_asv addr] [$mac_asv addr] + $mll_op_auv($id1) addentry [$ipif_asv addr] [$mac_op_asv addr] + $mll_asv addentry [$ipif_auv($id1) addr] [$mac_auv($id1) addr] + $mll_op_asv addentry [$ipif_auv($id1) addr] [$mac_op_auv($id1) addr] +} + +Position/UWSMWP debug_ 1 + +# Setup positions +set position_asv [new "Position/UWSMWP"] +$position_asv setX_ 0 +$position_asv setY_ 0 +$position_asv setZ_ -1 + +for {set id 0} {$id < $opt(n_auv)} {incr id} { + + $asv_app($id) setPosition $position_asv + $asv_err($id) setPosition $position_asv +} + +$position_auv(0) setX_ -1 +$position_auv(0) setY_ 1 + +$position_auv(1) setX_ 1 +$position_auv(1) setY_ -1 + +$position_auv(2) setX_ 1 +$position_auv(2) setY_ 1 + +$position_auv(2) setX_ -1 +$position_auv(2) setY_ -1 + +for {set id 0} {$id < $opt(n_auv)} {incr id} { + + set position_auv($id) [new "Position/UWSMWP"] + $position_auv($id) setZ_ -100 + + $auv_app($id) setPosition $position_auv($id) + $auv_err($id) setPosition $position_auv($id) + + #puts "x = [$position_auv($id) getX_]; y = [$position_auv($id) getY_]; z = [$position_auv($id) getZ_]" +} + + +# Setup routing table +for {set id 0} {$id < $opt(n_auv)} {incr id} { + $ipr_auv($id) addRoute [$ipif_asv addr] [$ipif_asv addr] + $ipr_asv addRoute [$ipif_auv($id) addr] [$ipif_auv($id) addr] +} + +##################### +# Start/Stop Timers # +##################### +# Set here the timers to start and/or stop modules (optional) +# e.g., + +set outfile [open "test_uwauv_results.csv" "w"] +close $outfile +set fp [open $opt(waypoint_file) r] +set file_data [read $fp] +set data [split $file_data "\n"] +foreach line $data { + if {[regexp {^(.*),(.*),(.*),(.*)$} $line -> t x y z]} { + $ns at $t "update_and_check $t" + $ns at $t "$asv_app(0) sendPosition [expr -$x] [expr $y] [expr $z]" + $ns at $t "$asv_app(1) sendPosition [expr $x] [expr -$y] [expr $z]" + $ns at $t "$asv_app(2) sendPosition [expr $x] [expr $y] [expr $z]" + $ns at $t "$asv_app(3) sendPosition [expr -$x] [expr -$y] [expr $z]" + + #for {set id 0} {$id < $opt(n_auv)} {incr id} { + # $ns at $t "$asv_app($id) sendPosition [expr $x*($id*(2))-$x] [expr $y*($id*(-2))+$y] [expr $z]" + #} + } +} + +set min 0 +set max 100 + +for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + + set time_ [new RandomVariable/Uniform] + $time_ set min_ 0 + $time_ set max_ 100 + $time_ use-rng $defaultRNG + + $ns at [expr $opt(starttime) + [$time_ value]] "$asv_app($id1) start" + $ns at $opt(stoptime) "$asv_app($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_app($id1) start" + $ns at $opt(stoptime) "$auv_app($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$auv_err($id1) start" + $ns at $opt(stoptime) "$auv_err($id1) stop" + + $ns at [expr $opt(starttime) + [$time_ value]] "$asv_err($id1) start" + $ns at $opt(stoptime) "$asv_err($id1) stop" + +} + +proc update_and_check {t} { + + global ns + set outfile_auv [open "test_uwauv0_results.csv" "a"] + set outfile_auv1 [open "test_uwauv1_results.csv" "a"] + set outfile_asv [open "test_uwasv_results.csv" "a"] + global position_auv position_asv auv_app asv_app opt n_auv auv_err asv_err + for {set id1 0} {$id1 < $opt(n_auv)} {incr id1} { + $position_auv($id1) update + puts $outfile_auv "positions AUV($id1): x = [$auv_app($id1) getX], y = [$auv_app($id1) getY], z = [$auv_app($id1) getZ]" + } + + + + $position_asv update + puts $outfile_asv "$t,[$asv_app(0) getX],[$asv_app(0) getY],[$asv_app(0) getZ]" + #puts "positions AUV: x = [$applicationAUV getX], y = [$applicationAUV getY], z = [$applicationAUV getZ]" + + close $outfile_auv + close $outfile_asv +} +### + +################### +# Final Procedure # +################### +# Define here the procedure to call at the end of the simulation +proc finish {} { + global ns opt n_auv + global mac propagation phy_data channel db_manager propagation + global node_asv_coordinates + global ipr_asv ipif_asv udp_asv phy + global asv_app asv_err + global auv_app auv_err mac_auv + global node_asv_stats tmp_node_asv_stats ipif_auv ipif_asv + + set sum_asv_ctr_throughput 0 + set sum_asv_ctr_sent_pkts 0.0 + set sum_asv_ctr_rcv_pkts 0.0 + + set sum_auv_mon_throughput 0 + set sum_auv_mon_sent_pkts 0.0 + set sum_auv_mon_rcv_pkts 0.0 + + set sum_asv_err_throughput 0 + set sum_asv_err_sent_pkts 0.0 + set sum_asv_err_rcv_pkts 0.0 + + set sum_auv_err_throughput 0 + set sum_auv_err_sent_pkts 0.0 + set sum_auv_err_rcv_pkts 0.0 + + + for {set i 0} {$i < $opt(n_auv)} {incr i} { + set asv_ctr_thr [$asv_app($i) getthr] + set asv_ctr_sent_pkts [$auv_app($i) getsentpkts] + set asv_ctr_rcv_pkts [$asv_app($i) getrecvpkts] + + set auv_mon_thr [$auv_app($i) getthr] + set auv_mon_sent_pkts [$auv_app($i) getsentpkts] + set auv_mon_rcv_pkts [$auv_app($i) getrecvpkts] + + set asv_err_thr [$asv_err($i) getthr] + set asv_err_sent_pkts [$asv_err($i) getsentpkts] + set asv_err_rcv_pkts [$asv_err($i) getrecvpkts] + + set auv_err_thr [$auv_err($i) getthr] + set auv_err_sent_pkts [$auv_err($i) getsentpkts] + set auv_err_rcv_pkts [$auv_err($i) getrecvpkts] + + set sum_asv_ctr_throughput [expr $sum_asv_ctr_throughput + $asv_ctr_thr] + set sum_asv_ctr_sent_pkts [expr $sum_asv_ctr_sent_pkts + $asv_ctr_sent_pkts] + set sum_asv_ctr_rcv_pkts [expr $sum_asv_ctr_rcv_pkts + $asv_ctr_rcv_pkts] + + set sum_auv_mon_throughput [expr $sum_auv_mon_throughput + $auv_mon_thr] + set sum_auv_mon_sent_pkts [expr $sum_auv_mon_sent_pkts + $auv_mon_sent_pkts] + set sum_auv_mon_rcv_pkts [expr $sum_auv_mon_rcv_pkts + $auv_mon_rcv_pkts] + + set sum_asv_err_throughput [expr $sum_asv_err_throughput + $asv_err_thr] + set sum_asv_err_sent_pkts [expr $sum_asv_err_sent_pkts + $asv_err_sent_pkts] + set sum_asv_err_rcv_pkts [expr $sum_asv_err_rcv_pkts + $asv_err_rcv_pkts] + + set sum_auv_err_throughput [expr $sum_auv_err_throughput + $auv_err_thr] + set sum_auv_err_sent_pkts [expr $sum_auv_err_sent_pkts + $auv_err_sent_pkts] + set sum_auv_err_rcv_pkts [expr $sum_auv_err_rcv_pkts + $auv_err_rcv_pkts] + } + + set ipheadersize [$ipif_asv getipheadersize] + set udpheadersize [$udp_asv getudpheadersize] + set cbrheadersize [$asv_app(0) getcbrheadersize] + + puts "$sum_asv_ctr_sent_pkts $sum_asv_ctr_rcv_pkts $sum_auv_mon_sent_pkts $sum_auv_mon_rcv_pkts $sum_asv_err_sent_pkts $sum_asv_err_rcv_pkts $sum_auv_err_sent_pkts $sum_auv_err_rcv_pkts" + $ns flush-trace + close $opt(tracefile) +} + +################### +# start simulation +################### +$ns at [expr $opt(stoptime) + 250.0] "finish; $ns halt" +$ns run diff --git a/DESERT_Framework/DESERT/samples/desert_samples/dbs/wp_path/rov_path.csv b/DESERT_Framework/DESERT/samples/desert_samples/dbs/wp_path/rov_path.csv index a226e203..d0b43578 100644 --- a/DESERT_Framework/DESERT/samples/desert_samples/dbs/wp_path/rov_path.csv +++ b/DESERT_Framework/DESERT/samples/desert_samples/dbs/wp_path/rov_path.csv @@ -99,3 +99,66 @@ 2361.830056,-99.802673,-48.175367,-15.000000 2391.136904,-99.950656,-24.868989,-15.000000 2422.005942,-100.000000,-0.000000,-15.000000 +2622.000000,100.000000,0.000000,-15.000000 +2722.869038,99.950656,24.868989,-15.000000 +2842.175886,99.802673,48.175367,-15.000000 +3108.456727,99.556196,68.454711,-15.000000 +3310.438527,99.211470,84.432793,-15.000000 +3567.120561,98.768834,95.105652,-15.000000 +3597.848534,98.228725,99.802673,-15.000000 +3655.546516,97.591676,98.228725,-15.000000 +3819.327174,96.858316,90.482705,-15.000000 +3998.784111,96.029369,77.051324,-15.000000 +4231.080243,95.105652,58.778525,-15.000000 +4511.069869,94.088077,36.812455,-15.000000 +4811.374381,92.977649,12.533323,-15.000000 +5143.469840,91.775463,-12.533323,-15.000000 +5621.783364,90.482705,-36.812455,-15.000000 +5720.792869,89.100652,-58.778525,-15.000000 +5985.124700,87.630668,-77.051324,-15.000000 +6004.645964,86.074203,-90.482705,-15.000000 +6165.563985,84.432793,-98.228725,-15.000000 +6161.898941,82.708057,-99.802673,-15.000000 +6217.931330,80.901699,-95.105652,-15.000000 +6464.769580,79.015501,-84.432793,-15.000000 +6786.867937,77.051324,-68.454711,-15.000000 +7193.249651,75.011107,-48.175367,-15.000000 +7300.651730,72.896863,-24.868989,-15.000000 +7514.616625,70.710678,0.000000,-15.000000 +7814.587729,68.454711,24.868989,-15.000000 +8054.009642,66.131187,48.175367,-15.000000 +8202.429194,63.742399,68.454711,-15.000000 +8504.594276,61.290705,84.432793,-15.000000 +8599.558809,58.778525,95.105652,-15.000000 +8609.913047,56.208338,99.802673,-15.000000 +8606.974321,53.582679,98.228725,-15.000000 +8642.170380,50.904142,90.482705,-15.000000 +8734.876153,48.175367,77.051324,-15.000000 +9168.358661,45.399050,58.778525,-15.000000 +9626.505150,42.577929,36.812455,-15.000000 +10297.952518,39.714789,12.533323,-15.000000 +10668.186628,36.812455,-12.533323,-15.000000 +10910.642956,33.873792,-36.812455,-15.000000 +11226.809182,30.901699,-58.778525,-15.00000 +11551.327031,27.899111,-77.051324,-15.000000 +11771.095968,24.868989,-90.482705,-15.000000 +11885.422540,21.814324,-98.228725,-15.000000 +12004.878010,18.738131,-99.802673,-15.000000 +12097.502873,15.643447,-95.105652,-15.000000 +12223.619652,12.533323,-84.432793,-15.000000 +12446.899980,9.410831,-68.454711,-15.000000 +12712.419722,6.279052,-48.175367,-15.000000 +13001.936400,3.141076,-24.868989,-15.000000 +13333.002971,0.000000,-0.000000,-15.000000 +13664.069541,-3.141076,24.868989,-15.000000 +13993.586220,-6.279052,48.175367,-15.000000 +14220.105962,-9.410831,68.454711,-15.000000 +14442.386289,-12.533323,84.432793,-15.000000 +14559.503069,-15.643447,95.105652,-15.000000 +14671.127932,-18.738131,99.802673,-15.000000 +14780.583402,-21.814324,98.228725,-15.000000 +14914.909974,-24.868989,90.482705,-15.000000 +15134.678911,-27.899111,77.051324,-15.000000 +15359.196760,-30.901699,58.778525,-15.000000 +15607.362986,-33.873792,36.812455,-15.000000 +15957.819314,-36.812455,12.533323,-15.000000 \ No newline at end of file